├── README.md ├── kernelmode ├── windows10 │ └── vidsch_sync.c └── windows7 │ ├── kequerylogicalprocessorrelationship.c │ └── object.c ├── latexp-2003 ├── nt52sp1_psapi.c └── setprocessdeppolicy.c ├── windows10 ├── bcrypthash_aio.c ├── highdpi.c ├── mem_map.c └── wow64.c ├── windows7 ├── basesetlastnterror.c ├── context_xstate_um.c ├── exception.c ├── findfirstfileexw_wrapper.c ├── getlogicalprocessorninformationex.c ├── groupaffinity_pre7.c ├── numa.c ├── oleapi.c ├── pbkdf2_bcrypt.c ├── power.c ├── proccount.c └── stringordinal.c └── windows8 ├── api-ms-win-core-com-l1-1-0 ├── api-ms-win-core-com-l1-1-0.sln ├── api-ms-win-core-com-l1-1-0.suo └── api-ms-win-core-com-l1-1-0 │ ├── api-ms-win-core-com-l1-1-0.def │ ├── api-ms-win-core-com-l1-1-0.vcproj │ ├── dllmain.c │ ├── resource.h │ ├── version.aps │ └── version.rc ├── api-ms-win-shcore-scaling-l1-1-1 ├── api-ms-win-shcore-scaling-l1-1-1.sln ├── api-ms-win-shcore-scaling-l1-1-1.suo └── api-ms-win-shcore-scaling-l1-1-1 │ ├── api-ms-win-shcore-scaling-l1-1-1.def │ ├── api-ms-win-shcore-scaling-l1-1-1.vcproj │ ├── dllmain.cpp │ ├── resource.h │ ├── verinfo.aps │ └── verinfo.rc ├── createfile2.c ├── getcurrentthreadstacklimits.c ├── mtausage.c ├── pointingdeviceapi.c ├── setdefaultdlldirectories.c └── systemtime.c /README.md: -------------------------------------------------------------------------------- 1 | # win32-api-reversals 2 | Windows API function reversals from post-Server 2003 RTM. 3 | 4 | Reverse engineered Windows API functions introduced after Server 2003 RTM or alternative implementations that provide additional flexibillity not provided by 5 | MS implementations (such as GetVersionEx), or adapt to differences in underlying kernel mode capability (for example: processor group-related functions on pre-Windows 7 OSes). 6 | -------------------------------------------------------------------------------- /kernelmode/windows10/vidsch_sync.c: -------------------------------------------------------------------------------- 1 | NTSTATUS VIDSCHAPI VidSchCreateSyncObject(VIDSCH_GLOBAL *pVidSchGlobal, DXGSYNCOBJECT* pDxgSyncObject, D3DDI_SYNCHRONIZATIONOBJECTINFO2* pObjectInfo, 2 | VIDSCH_CROSS_ADAPTER_SYNC_OBJECT_INFO *pCrossAdapterInfo, VIDMM_PAGING_QUEUE, *pPagingQueue, 3 | VIDSCH_SYNC_OBJECT **ppVidSchSyncObject, VIDMM_MONITORED_FENCE_STORAGE *pMonitoredFenceStorage) 4 | /* 5 | This is the backbone of the Direct3D kernel mode synchronization object initialization (second-generation). This is based on an early Windows 10 implementation. 6 | */ 7 | { 8 | ULONG NumberOfBytes; 9 | ULONG InitialFenceValue; 10 | NTSTATUS Status; 11 | VIDSCH_SYNC_OBJECT_CROSS_ADAPTER *vsoca; 12 | 13 | if(!pVidSchGlobal || !pDxgSyncObject || !pObjectInfo || !pCrossAdapterInfo || !pPagingQueue || !ppVidSchSyncObject || !pMonitoredFenceStorage) 14 | return STATUS_INVALID_PARAMETER; 15 | 16 | *ppVidSchSyncObject = 0; 17 | if((pObjectInfo->Flags.Value & CrossAdapter) != 0) // WDDM 1.3 and up, bit 2 18 | NumberOfBytes = sizeof(VIDSCH_SYNC_OBJECT_CROSS_ADAPTER); 19 | else 20 | NumberOfBytes = sizeof(VIDSCH_SYNC_OBJECT); 21 | 22 | vsoca = ExAllocatePoolWithTag(NonPagedPool, NumberOfBytes, "osiV"); // NonPagedPoolNx starting with Windows 8 23 | 24 | if(!vsoca) 25 | return STATUS_NO_MEMORY; 26 | 27 | vsoca->pVidSchGlobal = pVidSchGlobal; 28 | vsoca->AllocTag = "osiV"; 29 | vsoca->pSyncObject = pDxgSyncObject; 30 | vsoca->Reference = 0; 31 | vsoca->UnorderedWaiter = 0; 32 | vsoca->Sharable = pObjectInfo->Flags.Value & Shared; 33 | vsoca->DeferredWaits = (pObjectInfo->Flags.Value & D3DDDI_SYNCHRONIZATIONOBJECT_FLAGS_RESERVED0) != 0; // I guess this reserved flag can now be called DeferredWaits 34 | vsoca->CrossAdapter = (pObjectInfo->Flags.Value & CrossAdapter) != 0; 35 | if(pObjectInfo->Type == D3DDDI_SYNCHRONIZATION_MUTEX) 36 | { 37 | vsoca->Type = MutexObject; 38 | vsoca->Unorderable = FALSE; 39 | if(pObjectInfo->SynchronizationMutex.InitialState) 40 | { 41 | vsoca->FenceData.InitialFenceValue = 0; 42 | vsoca->FenceData.QueuedFenceValue = 0; 43 | goto BuildLinkedList; 44 | } 45 | vsoca->FenceData.InitialFenceValue = -1; 46 | vsoca->FenceData.QueuedFenceValue = -1; 47 | goto BuildLinkedList; 48 | } 49 | if(Type == D3DDI_SEMAPHORE) 50 | { 51 | if(pObjectInfo->Semaphore.InitialCount > pObjectInfo->SynchronizationMutex.InitialState) 52 | { 53 | ExFreePoolWithTag(vsoca, 0); 54 | return STATUS_INVALID_PARAMETER; 55 | } 56 | vsoca->Type = SemaphoreObject; 57 | vsoca->Unorderable = FALSE; 58 | vsoca->SemaphoreData.Count = pObjectInfo->Semaphore.InitialCount; 59 | vsoca->SemaphoreData.QueuedCount = pObjectInfo->Semaphore.InitialCount; 60 | vsoca->SemaphoreData.MaxCount = pObjectInfo->Semaphore.MaxCount; 61 | goto BuildLinkedList; 62 | } 63 | if(Type == D3DDDI_FENCE) 64 | { 65 | vsoca->Unorderable = TRUE; 66 | vsoca->Type = FenceObject; 67 | vsoca->FenceData.CurrentFenceValue = pObjectInfo->Fence.FenceValue; 68 | vsoca->FenceData.InitialFenceValue = pObjectInfo->Fence.FenceValue; 69 | vsoca->FenceData.QueuedFenceValue = pObjectInfo->Fence.FenceValue; 70 | goto BuildLinkedList; 71 | } 72 | if(Type != D3DDDI_CPU_NOTIFICATION) 73 | { 74 | if(Type != D3DDDI_MONITORED_FENCE) 75 | { 76 | ExFreePoolWithTag(vsoca, 0); 77 | return STATUS_INVALID_PARAMETER; 78 | } 79 | vsoca->Unorderable = TRUE; 80 | vsoca->Type = MonitoredFenceObject; 81 | if(pMonitoredFenceStorage) 82 | { 83 | vsoca->FenceData.InitialFenceValue = pMonitoredFenceStorage->FenceStoragePage; 84 | vsoca->FenceData.QueuedFenceValue = pMonitoredFenceStorage->FenceKernelAddress; 85 | vsoca->FenceData.CurrentFenceValue = pMonitoredFenceStorage->OffsetInBytes; 86 | vsoca->MonitoredFenceData.QueuedFenceValue = pMonitoredFenceStorage->QueuedFenceValue; 87 | } 88 | else 89 | { 90 | Status = AllocateFenceStorageSlot(&vsoca->MonitoredFenceData, vsoca->Sharable != FALSE, 91 | pDxgSyncObject == 0, pObjectInfo->Fence.FenceValue 92 | pVidSchGlobal->DriverSupports64BitAtomics != 0); 93 | if(Status < STATUS_SUCCESS) 94 | { 95 | ExFreePoolWithTag(vsoca, 0); 96 | return Status; 97 | } 98 | } 99 | vsoca->MonitoredFenceData.pPagingQueue = pMonitoredFenceStorage->pPagingQueue; 100 | vsoca->Is64Bit = pDxgSyncObject->m_Is64Bit; 101 | goto BuildLinkedList; 102 | } 103 | if(vsoca->Sharable) 104 | { 105 | ExFreePoolWithTag(vsoca, 0); 106 | return STATUS_INVALID_PARAMETER; 107 | } 108 | 109 | vsoca->Unorderable = FALSE; 110 | vsoca->Type = CpuNotificationObject; 111 | Status = ObReferenceObjectByHandle(pObjectInfo->Fence.FenceValue, 0x1F0003, *ExEventObjectType, 1, &InitialFenceValue, NULL); 112 | if(Status < STATUS_SUCCESS) 113 | { 114 | ExFreePoolWithTag(vsoca, 0); 115 | return Status; 116 | } 117 | vsoca->FenceData.InitialFenceValue = InitialFenceValue; 118 | 119 | BuildLinkedList: 120 | vsoca->QueuePacketWaitingListHead.Blink = &vsoca->QueuePacketWaitingListHead; 121 | vsoca->QueuePacketWaitingListHead.Flink = &vsoca->QueuePacketWaitingListHead; 122 | vsoca->QueuePacketUnorderedWaitingListHead.Blink = &vsoca->QueuePacketUnorderedWaitingListHead; 123 | vsoca->QueuePacketUnorderedWaitingListHead.Flink = &vsoca->QueuePacketUnorderedWaitingListHead; 124 | if ( vsoca->CrossAdapter ) 125 | { 126 | vsoca->pCrossAdapterSyncObjectInfo = pCrossAdapterInfo; 127 | vsoca->pfnPostSignalCrossAdapter = VidSchPostSignalCrossAdapter; 128 | VidSchiAddSyncObjectToCrossAdapterInfo(vsoca); 129 | } 130 | *ppVidSchSyncObject = vsoca; 131 | return STATUS_SUCCESS; 132 | } 133 | 134 | BOOLEAN VIDSCHAPI VidSchIsSyncObjectSignaled(VIDSCH_SYNC_OBJECT_CROSS_ADAPTER *pVidSchSyncObject) // VIDSCH_SYNC_OBJECT is also accepted 135 | { 136 | BOOLEAN IsSignaled; 137 | PKLOCK_QUEUE_HANDLE LockHandle; 138 | PVOID QueuedOwner; 139 | ULONG64 CurrentFenceValue; 140 | 141 | if(pVidSchSyncObject) 142 | { 143 | KeAcquireInStackQueuedSpinLock(&pVidSchSyncObject->pVidSchGlobal->SchedulerSpinLock, LockHandle); 144 | IsSignaled = TRUE; 145 | if(!pVidSchSyncObject->CrossAdapter) 146 | { 147 | QueuedFenceValue = pVidSchSyncObject->MutexData.QueuedFenceValue; 148 | CurrentFenceValue = pVidSchSyncObject->FenceData.CurrentFenceValue; 149 | } 150 | else 151 | { 152 | QueuedFenceValue = pVidSchSyncObject->pCrossAdapterSyncObjectInfo->CrossAdapterQueuedFenceValue; 153 | CurrentFenceValue = pVidSchSyncObject->pCrossAdapterSyncObjectInfo->CrossAdapterCurrentFenceValue; 154 | } 155 | if(pVidSchSyncObject->Type != FenceObject || QueuedFenceValue > CurrentFenceValue) 156 | { 157 | IsSignaled = FALSE; 158 | } 159 | 160 | KeReleaseInStackQueuedSpinLock(LockHandle); 161 | return IsSignaled; 162 | 163 | } 164 | else 165 | return FALSE; 166 | } 167 | 168 | NTSTATUS VidSchDestroySyncObject(VIDSCH_SYNC_OBJECT *pVidSchSyncObject) 169 | { 170 | if(pVidSchSyncObject) 171 | { 172 | if(pVidSchSyncObject->Reference > 1) 173 | VidSchTimeoutSyncObject(pVidSchSyncObject); 174 | VidSchiReleaseSyncObjectReference(pVidSchSyncObject); 175 | return STATUS_SUCCESS; 176 | } 177 | else 178 | return STATUS_INVALID_PARAMETER; 179 | } -------------------------------------------------------------------------------- /kernelmode/windows7/kequerylogicalprocessorrelationship.c: -------------------------------------------------------------------------------- 1 | /* 2 | I will implement this function by reading from KiProcessorBlock. 3 | For each struct, these are the values that will be used: 4 | RelationProcessorPackage: (I will have a struct per CPU package and divide KeNumberProcessors by the value of the PackageProcessorSet bitmask to determine the number of packages in a 5 | Flags = 0; "all-CPU" situation of course) 6 | EfficiencyClass = 0; 7 | GroupCount = 1; 8 | GroupMask(GROUP_AFFINITY) is: 9 | Mask = KeActiveProcessors.Bitmap (KeQueryActiveProcessors); 10 | Group = 0; 11 | RelationProcessorCore is the same except for Flags. (as many of these structs as there are logical processors) 12 | Flags = LTP_PC_SMT if LogicalProcessorsPerCore > 1, else 0 13 | RelationNumaNode: 14 | NodeNumber = expressed by the index value of KeNumberNodes[] - one struct per node 15 | GroupCount = 1; 16 | GroupMask = same as above 17 | RelationCache: 18 | Use _CACHE_DESCRIPTOR struct to obtain the values; there are 5 structs allocated in the block, presumably for levels L1 to theoretical L5. I assume that CacheCount keeps track of those. 19 | One per cache level. 20 | RelationGroup: 21 | Very simple. 22 | 23 | To calculate the number of structs needed per logical processor, I think it will go like this: 24 | ProcessorPackage 25 | + ProcessorCore 26 | + NumaNode 27 | + Cache*CacheCount 28 | + Group 29 | = 5 to 7 30 | 31 | Actually for a !ProcessorNumber situation, I think you only need a limited amount of ProcessorPackages and NumaNodes (and one Group). 32 | So: 33 | # of actual CPU packages 34 | + # of logical processors 35 | + # of NUMA nodes 36 | + # of actual CPU packages * CacheCount 37 | + Group 38 | 39 | To avoid wasting CPU time, the necessary buffer size can be calculated in advance. Once the requirement is satisfied, the function can be executed. 40 | 41 | Other notes: 42 | (PVOID)KeNumberNodes = &KeNumberProcessors + 1; 43 | (PVOID*)KiProcessorBlock = &KeNumberProcessors + 0x638; 44 | KiProcessorBlock->ParentNode = offset 0x37C0 45 | KiProcessorBlock->LogicalProcessorsPerCore = offset 0x63F 46 | CACHE_DESCRIPTOR KiProcessorBlock->Cache = offset 0x3A38 47 | KiProcessorBlock->CacheCount = offset 0x3A74 48 | ParentNode->NodeNumber = offset 0x54 (could be less with Vista) 49 | KiProcessorBlock->PackageProcessorSet = offset 0x3B08 50 | 51 | */ 52 | 53 | NTSTATUS NTAPI KeQueryLogicalProcessorRelationshipNew(PPROCESSOR_NUMBER ProcessorNumber, LOGICAL_PROCESSOR_RELATIONSHIP RelationshipType, 54 | PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX Information, PULONG Length) 55 | { 56 | NTSTATUS Status = STATUS_SUCCESS; 57 | KAFFINITY ProcessorMask; 58 | PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX Iterator; 59 | ULONG ProcessorsInPackage = 0; 60 | ULONG NumberOfPackages; 61 | ULONG RequiredLength = 0; 62 | ULONG i; 63 | PVOID* KeNumberNodesPtr; 64 | CCHAR KeNumberNodes; 65 | KPRCB* KiProcessorBlock; 66 | CACHE_DESCRIPTOR* CPUCache; 67 | CHAR CacheCount; 68 | KAFFINITY ProcessorPackageAffinity; 69 | 70 | if(!Length) 71 | return STATUS_INVALID_PARAMETER; 72 | 73 | if(ProcessorNumber) 74 | { 75 | if(ProcessorNumber->Number > KeNumberProcessors - 1) 76 | return STATUS_INVALID_PARAMETER; 77 | } 78 | 79 | KeNumberNodesPtr = &KeNumberProcessors + 1; 80 | KeNumberNodes = (CCHAR)*KeNumberNodesPtr; 81 | 82 | KiProcessorBlock = &KeNumberProcessors + 0x638; 83 | 84 | ProcessorPackageAffinity = KiProcessorBlock[0].PackageProcessorSet; 85 | 86 | if(ProcessorNumber) 87 | { 88 | CacheCount = KiProcessorBlock[ProcessorNumber->Number].CacheCount; 89 | CPUCache = &KiProcessorBlock[ProcessorNumber->Number].Cache; 90 | 91 | 92 | if(RelationshipType == RelationAll || RelationshipType == RelationProcessorPackage) 93 | RequiredLength += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 94 | if(RelationshipType == RelationAll || RelationshipType == RelationProcessorCore) 95 | RequiredLength += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 96 | if(RelationshipType == RelationAll || RelationshipType == RelationNumaNode) 97 | RequiredLength += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); // To determine the NUMA node a processor belongs to, use KNODE* KiProcessorBlock->ParentNode 98 | if(RelationshipType == RelationAll || RelationshipType == RelationGroup) // ^ from there, you can grab ParentNode->NodeNumber 99 | RequiredLength += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 100 | if(RelationshipType == RelationAll || RelationshipType == RelationCache) 101 | RequiredLength += CacheCount*sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 102 | 103 | if(RequiredLength > *Length) 104 | { 105 | *Length = RequiredLength; 106 | return STATUS_INFO_LENGTH_MISMATCH; 107 | } 108 | 109 | *Length = RequiredLength; 110 | } 111 | else 112 | { 113 | CacheCount = KiProcessorBlock[0].CacheCount; 114 | CPUCache = &KiProcessorBlock[0].Cache; 115 | 116 | for(i = 0; i < 64; i++) 117 | { 118 | if((ProcessorPackageAffinity >> i) & 1) 119 | ++ProcessorsInPackage; 120 | } 121 | 122 | NumberOfPackages = ProcessorsInPackage / KeNumberProcessors; 123 | 124 | if(RelationshipType == RelationAll || RelationshipType == RelationProcessorPackage) 125 | RequiredLength += NumberOfPackages*sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 126 | if(RelationshipType == RelationAll || RelationshipType == RelationProcessorCore) 127 | RequiredLength += KeNumberProcessors*sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 128 | if(RelationshipType == RelationAll || RelationshipType == RelationNumaNode) 129 | RequiredLength += KeNumberNodes*sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 130 | if(RelationshipType == RelationAll || RelationshipType == RelationGroup) 131 | RequiredLength += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 132 | if(RelationshipType == RelationAll || RelationshipType == RelationCache) 133 | RequiredLength += CacheCount*sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 134 | 135 | if(RequiredLength > *Length) 136 | { 137 | *Length = RequiredLength; 138 | return STATUS_INFO_LENGTH_MISMATCH; 139 | } 140 | 141 | *Length = RequiredLength; 142 | } 143 | 144 | if(!RequiredLength) 145 | return STATUS_SUCCESS; // Hypervisors seem to not expose cache information to guests, and perhaps that is true for some other categories. 146 | 147 | ProcessorMask = KeQueryActiveProcessors(); 148 | 149 | Iterator = Information; 150 | 151 | if(ProcessorNumber) 152 | { 153 | if(RelationshipType == RelationAll || RelationshipType == RelationProcessorPackage) 154 | { 155 | Iterator->Relationship = RelationProcessorPackage; 156 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 157 | Iterator->Processor.Flags = 0; 158 | Iterator->Processor.EfficiencyClass = 0; 159 | Iterator->Processor.GroupCount = 1; 160 | Iterator->Processor.GroupMask->Group = 0; 161 | Iterator->Processor.GroupMask->Mask = ProcessorMask; 162 | Iterator++; 163 | } 164 | if(RelationshipType == RelationAll || RelationshipType == RelationProcessorCore) 165 | { 166 | Iterator->Relationship = RelationProcessorCore; 167 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 168 | Iterator->Processor.Flags = KiProcessorBlock[ProcessorNumber->Number].LogicalProcessorsPerCore > 1; 169 | Iterator->Processor.EfficiencyClass = 0; 170 | Iterator->Processor.GroupCount = 1; 171 | Iterator->Processor.GroupMask->Group = 0; 172 | Iterator->Processor.GroupMask->Mask = ProcessorMask; 173 | Iterator++; 174 | } 175 | if(RelationshipType == RelationAll || RelationshipType == RelationNumaNode) 176 | { 177 | Iterator->Relationship = RelationNumaNode; 178 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 179 | Iterator->NumaNode.NodeNumber = KiProcessorBlock[ProcessorNumber->Number].ParentNode->NodeNumber; 180 | Iterator->NumaNode.GroupMask.Group = 0; 181 | Iterator->NumaNode.GroupMask.Mask = ProcessorMask; 182 | Iterator->NumaNode.GroupCount = 1; 183 | Iterator++; 184 | } 185 | if(RelationshipType == RelationAll || RelationshipType == RelationCache) 186 | { 187 | for(i = 0; i < KiProcessorBlock[ProcessorNumber->Number].CacheCount; i++) 188 | { 189 | Iterator->Relationship = RelationCache; 190 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 191 | Iterator->Cache.Level = KiProcessorBlock[ProcessorNumber->Number].Cache.Level; 192 | Iterator->Cache.Associativity = KiProcessorBlock[ProcessorNumber->Number].Cache.Associativity; 193 | Iterator->Cache.LineSize = KiProcessorBlock[ProcessorNumber->Number].Cache.LineSize; 194 | Iterator->Cache.CacheSize = KiProcessorBlock[ProcessorNumber->Number].Cache.Size; 195 | Iterator->Cache.Type = KiProcessorBlock[ProcessorNumber->Number].Cache.Type; 196 | Iterator->Cache.GroupCount = 1; 197 | Iterator->Cache.GroupMask.Group = 0; 198 | Iterator->Cache.GroupMask.Mask = ProcessorMask; 199 | 200 | Iterator++; 201 | } 202 | } 203 | if(RelationshipType == RelationAll || RelationshipType == RelationGroup) 204 | { 205 | Iterator->Relationship = RelationGroup; 206 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 207 | Iterator->Group.MaximumGroupCount = 1; 208 | Iterator->Group.ActiveGroupCount = 1; 209 | Iterator->Group.GroupInfo->ActiveProcessorCount = KeNumberProcessors; 210 | Iterator->Group.GroupInfo->ActiveProcessorMask = ProcessorMask; 211 | Iterator->Group.GroupInfo->MaximumProcessorCount = KeQueryMaximumProcessorCount(); 212 | } 213 | } 214 | else 215 | { 216 | if(RelationshipType == RelationAll || RelationshipType == RelationProcessorPackage) 217 | { 218 | for(i = 0; i < NumberOfPackages; i++) 219 | { 220 | Iterator->Relationship = RelationProcessorPackage; 221 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 222 | Iterator->Processor.Flags = 0; 223 | Iterator->Processor.EfficiencyClass = 0; 224 | Iterator->Processor.GroupCount = 1; 225 | Iterator->Processor.GroupMask->Group = 0; 226 | Iterator->Processor.GroupMask->Mask = ProcessorMask; 227 | Iterator++; 228 | } 229 | } 230 | if(RelationshipType == RelationAll || RelationshipType == RelationProcessorCore) 231 | { 232 | for(i = 0; i < KeNumberProcessors; i++) 233 | { 234 | Iterator->Relationship = RelationProcessorCore; 235 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 236 | Iterator->Processor.Flags = KiProcessorBlock[0].LogicalProcessorsPerCore > 1; 237 | Iterator->Processor.EfficiencyClass = 0; 238 | Iterator->Processor.GroupCount = 1; 239 | Iterator->Processor.GroupMask->Group = 0; 240 | Iterator->Processor.GroupMask->Mask = ProcessorMask; 241 | Iterator++; 242 | } 243 | } 244 | if(RelationshipType == RelationAll || RelationshipType == RelationNumaNode) 245 | { 246 | for(i = 0; i < KeNumberNodes; i++) 247 | { 248 | Iterator->Relationship = RelationNumaNode; 249 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 250 | Iterator->NumaNode.NodeNumber = KiProcessorBlock[0].ParentNode->NodeNumber; 251 | Iterator->NumaNode.GroupMask.Group = 0; 252 | Iterator->NumaNode.GroupMask.Mask = ProcessorMask; 253 | Iterator->NumaNode.GroupCount = 1; 254 | Iterator++; 255 | } 256 | } 257 | if(RelationshipType == RelationAll || RelationshipType == RelationCache) 258 | { 259 | for(i = 0; i < KiProcessorBlock[0].CacheCount; i++) 260 | { 261 | Iterator->Relationship = RelationCache; 262 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 263 | Iterator->Cache.Level = KiProcessorBlock[0].Cache.Level; 264 | Iterator->Cache.Associativity = KiProcessorBlock[0].Cache.Associativity; 265 | Iterator->Cache.LineSize = KiProcessorBlock[0].Cache.LineSize; 266 | Iterator->Cache.CacheSize = KiProcessorBlock[0].Cache.Size; 267 | Iterator->Cache.Type = KiProcessorBlock[0].Cache.Type; 268 | Iterator->Cache.GroupCount = 1; 269 | Iterator->Cache.GroupMask.Group = 0; 270 | Iterator->Cache.GroupMask.Mask = ProcessorMask; 271 | 272 | Iterator++; 273 | } 274 | } 275 | if(RelationshipType == RelationAll || RelationshipType == RelationGroup) 276 | { 277 | Iterator->Relationship = RelationGroup; 278 | Iterator->Size = sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX); 279 | Iterator->Group.MaximumGroupCount = 1; 280 | Iterator->Group.ActiveGroupCount = 1; 281 | Iterator->Group.GroupInfo->ActiveProcessorCount = KeNumberProcessors; 282 | Iterator->Group.GroupInfo->ActiveProcessorMask = ProcessorMask; 283 | Iterator->Group.GroupInfo->MaximumProcessorCount = KeQueryMaximumProcessorCount(); 284 | } 285 | } 286 | 287 | return Status; 288 | } 289 | -------------------------------------------------------------------------------- /kernelmode/windows7/object.c: -------------------------------------------------------------------------------- 1 | OBJECT_TYPE* NTAPI ObGetObjectType(PVOID Object) 2 | { 3 | return OBJECT_TO_OBJECT_TYPE(Object)->Type; 4 | } -------------------------------------------------------------------------------- /latexp-2003/nt52sp1_psapi.c: -------------------------------------------------------------------------------- 1 | /* win32 - November 9 2021 2 | Windows Server 2003 SP1 introduced two new PSAPI functions to complement the 25 available as of Server 2003 RTM. 3 | This was the last meaningful update to PSAPI. Windows 7 introduced PSAPI_VERSION_2, which did not 4 | involve any upgrades to the API, but moved the code into kernel32.dll and stuck "K32" onto each 5 | function's exported name. psapi.dll became a stub directing to the newly moved code. 6 | 7 | The following is reversals of 2003 SP1's new PSAPI functions: QueryWorkingSetEx and GetWsChangesEx. */ 8 | 9 | BOOL WINAPI QueryWorkingSetEx(HANDLE hProcess, PVOID pv, DWORD cb) 10 | { 11 | NTSTATUS Status; 12 | 13 | Status = NtQueryVirtualMemory(hProcess, NULL, MemoryWorkingSetExList, pv, cb, NULL); // This class seems to have been introduced with XP/2003, 0x4. 14 | if ( Status >= 0 ) 15 | return TRUE; 16 | SetLastError(RtlNtStatusToDosError(Status)); 17 | 18 | return FALSE; 19 | } 20 | 21 | BOOL WINAPI GetWsChangesEx( 22 | HANDLE hProcess, 23 | PPSAPI_WS_WATCH_INFORMATION_EX lpWatchInfoEx, 24 | PDWORD cb 25 | ) 26 | 27 | { 28 | NTSTATUS Status; 29 | 30 | Status = NtQueryInformationProcess(hProcess, ProcessWorkingSetWatchEx, lpWatchInfoEx, *cb, cb); //class is number 0x2A 31 | if ( Status >= 0 ) //Also new to XP/2003. 32 | return TRUE; 33 | RtlSetLastWin32Error(RtlNtStatusToDosError(Status)); 34 | return FALSE; 35 | } 36 | -------------------------------------------------------------------------------- /latexp-2003/setprocessdeppolicy.c: -------------------------------------------------------------------------------- 1 | /* win32 - November 9 2021 2 | Reversal of SetProcessDEPPolicy, Vista version. 3 | Unsure if NtSetInformationProcess will succeed on XP < SP2 and 2003 < SP1, as they do not know what DEP is. 4 | However, 2003 SP1/SP2 do know what DEP is while not having that function. So it may work as intended 5 | on those platforms. 6 | 7 | On non-x86 platforms, SetProcessDEPPolicy is a stub that returns STATUS_NOT_SUPPORTED. It may be useful 8 | on the OS revisions that do not recognize DEP as well. 9 | */ 10 | 11 | #ifdef WX86 12 | 13 | BOOL WINAPI SetProcessDEPPolicy(DWORD dwFlags) 14 | { 15 | DWORD dwFlagscpy; 16 | NTSTATUS Status; 17 | 18 | dwFlagscpy = dwFlags; 19 | if ( (dwFlags & 0xFFFFFFFC) != 0 ) //check that only bits 0 and 1 are set 20 | { 21 | BaseSetLastNTError(STATUS_INVALID_PARAMETER); 22 | return FALSE; 23 | } 24 | if ( (dwFlags & PROCESS_DEP_ENABLE) != 0 ) 25 | { 26 | dwFlags = 9; 27 | if ( (dwFlagscpy & PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION) != 0 ) 28 | dwFlags = 13; 29 | } 30 | else 31 | { 32 | if ( (dwFlags & PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION) != 0 ) 33 | { 34 | BaseSetLastNTError(STATUS_INVALID_PARAMETER_MIX); 35 | return FALSE; 36 | } 37 | dwFlags = 2; // Set DEP to be disabled for the process 38 | } 39 | Status = NtSetInformationProcess((HANDLE)-1, ProcessExecuteFlags, (PVOID)&dwFlags,(ULONG) 4); //class 0x22 40 | if ( Status < 0 ) 41 | { 42 | BaseSetLastNTError(Status); 43 | return FALSE; 44 | } 45 | return TRUE; 46 | } 47 | 48 | #else 49 | 50 | BOOL WINAPI SetProcessDEPPolicy(DWORD dwFlags) 51 | { 52 | BaseSetLastNTError(STATUS_NOT_SUPPORTED); 53 | return FALSE; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /windows10/bcrypthash_aio.c: -------------------------------------------------------------------------------- 1 | NTSTATUS BCryptHash(BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbSecret, ULONG cbSecret, PUCHAR pbInput, 2 | ULONG cbInput, PUCHAR pbOutput, ULONG cbOutput) 3 | { 4 | BCRYPT_HASH_HANDLE hHash; 5 | NTSTATUS Status; 6 | PUCHAR pbHashObject; 7 | ULONG cbHashObject; 8 | ULONG ResultLength; 9 | 10 | BCryptGetProperty(hAlgorithm, L"ObjectLength", NULL, 0, &ResultLength, 0); 11 | 12 | cbHashObject = ResultLength; 13 | 14 | pbHashObject = (PUCHAR)RtlAllocateHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, cbHashObject); 15 | 16 | if(!pbHashObject) 17 | return STATUS_NO_MEMORY; 18 | 19 | Status = BCryptGetProperty(hAlgorithm, L"ObjectLength", pbHashObject, cbHashObject, &ResultLength, 0); 20 | 21 | if(Status < STATUS_SUCCESS) 22 | goto ReturnAndDeallocate; 23 | 24 | Status = BCryptCreateHash(hAlgorithm, &hHash, pbHashObject, cbHashObject, pbSecret, cbSecret, 0); 25 | 26 | if(Status < STATUS_SUCCESS) 27 | goto ReturnAndDeallocate; 28 | 29 | Status = BCryptHashData(hHash, pbInput, cbInput, 0); 30 | 31 | if(Status < STATUS_SUCCESS) 32 | goto DestroyAndReturn; 33 | 34 | Status = BCryptFinishHash(hHash, pbOutput, cbOutput, 0); 35 | 36 | if(Status < STATUS_SUCCESS) 37 | goto DestroyAndReturn; 38 | 39 | DestroyAndReturn: 40 | BCryptDestroyHash(hHash); 41 | ReturnAndDeallocate: 42 | RtlFreeHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, pbHashObject); 43 | return Status; 44 | 45 | } -------------------------------------------------------------------------------- /windows10/highdpi.c: -------------------------------------------------------------------------------- 1 | BOOL WINAPI AdjustWindowRectExForDpi(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi) 2 | { 3 | if(!AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle)) 4 | return FALSE; 5 | else 6 | { 7 | lpRect->left *= dpi/96; 8 | lpRect->top *= dpi/96; 9 | lpRect->right *= dpi/96; 10 | lpRect->bottom *= dpi/96; 11 | 12 | return TRUE; 13 | } 14 | } 15 | 16 | UINT WINAPI GetDpiForWindow(HWND hwnd) 17 | { 18 | HDC hDC; 19 | int result; 20 | if(IsProcessDPIAware()) 21 | { 22 | hDC = GetDC(hwnd); 23 | if(!hwnd) 24 | return 0; 25 | result = GetDeviceCaps(hDC, LOGPIXELSX); 26 | ReleaseDC(hwnd, hDC); 27 | return result; 28 | } 29 | else 30 | return 96; 31 | } 32 | 33 | int WINAPI GetSystemMetricsForDpi(int nIndex, UINT dpi) 34 | { 35 | int result; 36 | 37 | result = GetSystemMetrics(nIndex); 38 | 39 | switch(nIndex) 40 | { 41 | case SM_CXBORDER: 42 | case SM_CXMAXTRACK: 43 | case SM_CXMIN: 44 | case SM_CXMINTRACK: 45 | case SM_CYMAXTRACK: 46 | case SM_CYMIN: 47 | case SM_CYMINTRACK: 48 | case SM_CXICON: 49 | case SM_CXICONSPACING: 50 | case SM_CXSMICON: 51 | case SM_CYICON: 52 | case SM_CYICONSPACING: 53 | case SM_CYSMICON: 54 | return result * (dpi/96); 55 | 56 | default: 57 | return result; 58 | } 59 | } 60 | 61 | DPI_AWARENESS WINAPI GetAwarenessFromDpiAwarenessContext(DPI_AWARENESS_CONTEXT value) 62 | { 63 | if(value > DPI_AWARENESS_CONTEXT_UNAWARE || value < DPI_AWARENESS_CONTEXT_SYSTEM_AWARE) 64 | return DPI_AWARENESS_INVALID; 65 | else if (value == DPI_AWARENESS_CONTEXT_UNAWARE) 66 | return DPI_AWARENESS_UNAWARE; 67 | else 68 | return DPI_AWARENESS_SYSTEM_AWARE; 69 | } 70 | 71 | DPI_AWARENESS_CONTEXT WINAPI GetWindowDpiAwarenessContext(HWND hwnd) 72 | { 73 | if(IsProcessDPIAware()) 74 | return DPI_AWARENESS_CONTEXT_SYSTEM_AWARE; 75 | else 76 | return DPI_AWARENESS_CONTEXT_UNAWARE; 77 | } 78 | 79 | 80 | BOOL WINAPI EnableNonClientDpiScaling(HWND hwnd) 81 | { 82 | SetLastError(ERROR_NOT_SUPPORTED); 83 | return FALSE; 84 | } 85 | 86 | BOOL WINAPI SystemParametersInfoForDpi(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi) 87 | { 88 | LOGFONTW* logfont; 89 | ICONMETRICSW* iconmetrics; 90 | NONCLIENTMETRICSW* nonclientmetrics; 91 | 92 | if(!SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni)) 93 | return FALSE; 94 | else 95 | { 96 | if(uiAction == SPI_GETICONTITLELOGFONT) 97 | { 98 | logfont = (LOGFONTW*) pvParam; 99 | 100 | logfont->lfHeight *= dpi/96; 101 | logfont->lfWidth *= dpi/96; 102 | return TRUE; 103 | } 104 | 105 | if(uiAction == SPI_GETICONMETRICS) 106 | { 107 | iconmetrics = (ICONMETRICSW*) pvParam; 108 | 109 | iconmetrics->iHorzSpacing *= dpi/96; 110 | iconmetrics->iVertSpacing *= dpi/96; 111 | return TRUE; 112 | } 113 | 114 | if(uiAction == SPI_GETNONCLIENTMETRICS) 115 | { 116 | nonclientmetrics = (NONCLIENTMETRICSW*) pvParam; 117 | 118 | nonclientmetrics->iBorderWidth *= dpi/96; 119 | nonclientmetrics->iScrollWidth *= dpi/96; 120 | nonclientmetrics->iScrollHeight *= dpi/96; 121 | nonclientmetrics->iCaptionWidth *= dpi/96; 122 | nonclientmetrics->iCaptionHeight *= dpi/96; 123 | 124 | nonclientmetrics->iSmCaptionWidth *= dpi/96; 125 | nonclientmetrics->iSmCaptionHeight *= dpi/96; 126 | nonclientmetrics->iMenuWidth *= dpi/96; 127 | nonclientmetrics->iMenuHeight *= dpi/96; 128 | nonclientmetrics->iPaddedBorderWidth *= dpi/96; 129 | return TRUE; 130 | } 131 | } 132 | } 133 | 134 | -------------------------------------------------------------------------------- /windows10/mem_map.c: -------------------------------------------------------------------------------- 1 | // The two following functions are exported from api-ms-win-core-memory-l1-1-6.dll 2 | 3 | PVOID VirtualAlloc2_New(HANDLE Process, PVOID BaseAddress, SIZE_T Size, ULONG AllocationType, 4 | ULONG PageProtection, MEM_EXTENDED_PARAMETER* ExtendedParameters, ULONG ParameterCount) 5 | /* 6 | This set of functions makes use of *Ex variants of NtAllocateVirtualMemory/NtMapViewOfSection/NtUnmapViewOfSection introduced 7 | in Windows 10, allowing them to take advantage of new features such as specifying the NUMA node from which to allocate memory, 8 | "placeholders" and bounds on where allocated memory can be located. 9 | 10 | These features aren't particularly necessary for now, so we are using the older variants of these functions instead of 11 | potentially modifying the OS' memory management. 12 | */ 13 | { 14 | NTSTATUS Status; 15 | PVOID NewAddress = BaseAddress; 16 | SIZE_T RegionSize = Size; 17 | 18 | if(AllocationType & MEM_RESERVE_PLACEHOLDER) 19 | { 20 | AllocationType ^= MEM_RESERVE_PLACEHOLDER; 21 | AllocationType |= MEM_RESERVE; 22 | } 23 | 24 | if(AllocationType & MEM_REPLACE_PLACEHOLDER) 25 | { 26 | AllocationType ^= MEM_REPLACE_PLACEHOLDER; 27 | } 28 | 29 | if(AllocationType & MEM_RESET_UNDO) 30 | { 31 | AllocationType ^= MEM_RESET_UNDO; 32 | } 33 | 34 | Status = NtAllocateVirtualMemory(Process, &NewAddress, NULL, &RegionSize, AllocationType, PageProtection); 35 | 36 | 37 | if(Status < STATUS_SUCCESS) 38 | { 39 | BaseSetLastNTError(Status); 40 | return FALSE; 41 | } 42 | 43 | return NewAddress; 44 | 45 | 46 | } 47 | 48 | PVOID MapViewOfFile3_New(HANDLE FileMapping, HANDLE Process, PVOID BaseAddress, ULONG64 Offset, SIZE_T ViewSize, ULONG AllocationType, 49 | ULONG PageProtection, MEM_EXTENDED_PARAMETER* ExtendedParameters, ULONG ParameterCount) 50 | { 51 | NTSTATUS Status; 52 | PVOID NewAddress = BaseAddress; 53 | SIZE_T RegionSize = ViewSize; 54 | 55 | if(AllocationType & MEM_REPLACE_PLACEHOLDER) 56 | { 57 | AllocationType ^= MEM_REPLACE_PLACEHOLDER; 58 | } 59 | 60 | Status = NtMapViewOfSection(FileMapping, Process, &NewAddress, NULL, NULL, Offset, &RegionSize, 0, AllocationType, PageProtection); 61 | 62 | if(Status < STATUS_SUCCESS) 63 | { 64 | BaseSetLastNTError(Status); 65 | return FALSE; 66 | } 67 | 68 | return NewAddress; 69 | 70 | } 71 | 72 | 73 | BOOL UnmapViewOfFile2_New(HANDLE Process, PVOID BaseAddress, ULONG UnmapFlags) 74 | { 75 | NTSTATUS Status; 76 | 77 | Status = NtUnmapViewOfSection(Process, BaseAddress); 78 | 79 | if(Status < STATUS_SUCCESS) 80 | { 81 | BaseSetLastNTError(Status); 82 | return FALSE; 83 | } 84 | 85 | return TRUE; 86 | 87 | } -------------------------------------------------------------------------------- /windows10/wow64.c: -------------------------------------------------------------------------------- 1 | BOOL WINAPI IsWow64Process2(HANDLE hProcess, PUSHORT pProcessMachine, PUSHORT pNativeMachine) 2 | /* 3 | An enhanced version of IsWow64Process() introduced with Windows 10 1511. 4 | Not only does it determine if the process is running under WOW64, but it also determines the 5 | WOW64 and native platforms. 6 | */ 7 | { 8 | BOOL Wow64Process; 9 | 10 | if(!pProcessMachine) 11 | { 12 | SetLastError(ERROR_INVALID_PARAMETER); 13 | return FALSE; 14 | } 15 | 16 | if(!IsWow64Process(hProcess, &Wow64Process)) 17 | { 18 | return FALSE; 19 | } 20 | 21 | if(!Wow64Process) 22 | { 23 | *pProcessMachine = IMAGE_FILE_MACHINE_UNKNOWN; 24 | } 25 | else 26 | { 27 | #ifdef _X86_ || _AMD64_ || _IA64_ 28 | *pProcessMachine = IMAGE_FILE_MACHINE_I386; 29 | #elif _ARM64_ || _ARM_ 30 | *pProcessMachine = IMAGE_FILE_MACHINE_ARM; 31 | #endif 32 | // No other Windows architecture has WOW64. 33 | 34 | } 35 | 36 | if(pNativeMachine) 37 | { 38 | #ifdef _X86_ 39 | *pNativeMachine = IMAGE_FILE_MACHINE_I386; 40 | #elif _AMD64_ 41 | *pNativeMachine = IMAGE_FILE_MACHINE_AMD64; 42 | #elif _ARM_ 43 | *pNativeMachine = IMAGE_FILE_MACHINE_ARM; 44 | #elif _ARM64_ 45 | *pNativeMachine = IMAGE_FILE_MACHINE_ARM64; 46 | #endif 47 | } 48 | 49 | return TRUE; 50 | } -------------------------------------------------------------------------------- /windows7/basesetlastnterror.c: -------------------------------------------------------------------------------- 1 | /* win32 - November 9 2021 2 | This has been in NT forever, but was only exported starting with Windows 7. 3 | And I think I have encountered applications that do call it, albeit they are rare. */ 4 | 5 | ULONG BaseSetLastNTError(NTSTATUS Status) // Export names are case-sensitive. And the standard is to type "Nt" instead of "NT". This is an exception. 6 | { 7 | ULONG DosError; 8 | 9 | DosError = RtlNtStatusToDosError(Status); 10 | 11 | SetLastError(DosError); 12 | 13 | return DosError; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /windows7/context_xstate_um.c: -------------------------------------------------------------------------------- 1 | /* 2 | The following three functions were introduced in Windows 7 SP1 and are required by .NET Core 5. 3 | 4 | They are tailored for cases where AVX support is unavailable and the OS does not have context switching 5 | support for the expanded AVX/AVX512 registers; I plan on providing an emulator for these cases in the future, 6 | provided that usage of AVX instructions goes mainstream. 7 | 8 | These functions assume the usage of native contexts. 9 | */ 10 | 11 | BOOL WINAPI InitializeContext(PVOID Buffer, DWORD ContextFlags, PCONTEXT *Context, PDWORD ContextLength) 12 | /* 13 | This function only exists because the size of the CONTEXT_XSTATE area can vary depending on the 14 | type of CPU features available/enabled. There is no variability in a pre-XState/AVX context, so it simply 15 | initializes a regular context. 16 | */ 17 | { 18 | PCONTEXT ctxint; 19 | if(!Buffer || *ContextLength < sizeof(CONTEXT)) 20 | { 21 | SetLastError(ERROR_INSUFFICIENT_BUFFER); 22 | *ContextLength = sizeof(CONTEXT); 23 | return FALSE; 24 | } 25 | 26 | Buffer = (PVOID)ctxint; 27 | 28 | RtlZeroMemory(ctxint, sizeof(CONTEXT)); 29 | 30 | *Context = (PCONTEXT)Buffer; 31 | 32 | ctxint->ContextFlags = ContextFlags; 33 | 34 | return TRUE; 35 | } 36 | 37 | DWORD64 WINAPI GetEnabledXStateFeatures() 38 | { 39 | DWORD64 XState = 0; 40 | 41 | XState = 3; // bits 0 and 1 represent X87 and SSE respectively, which all AMD64 CPUs support. 42 | 43 | return XState; 44 | } 45 | 46 | BOOL WINAPI SetXStateFeaturesMask(PCONTEXT Context, DWORD64 FeatureMask) 47 | // AMD64 version of the function. I don't see the need to modify it for other archs for the purpose of the extended kernel yet. 48 | { 49 | if(!(Context->ContextFlags & CONTEXT_AMD64)) 50 | { 51 | SetLastError(ERROR_INVALID_PARAMETER); 52 | return FALSE; 53 | } 54 | 55 | if(FeatureMask & 3) 56 | Context->ContextFlags |= CONTEXT_FLOATING_POINT; 57 | 58 | return TRUE; 59 | } -------------------------------------------------------------------------------- /windows7/exception.c: -------------------------------------------------------------------------------- 1 | void WINAPI RaiseFailFastException(PEXCEPTION_RECORD pExceptionRecord, PCONTEXT pContextRecord, DWORD dwFlags) 2 | /* 3 | win32 - March 4 2021 4 | API function introduced with Windows 7. Well-documented, except for dwFlags = 2, which I'll call 5 | FAIL_FAST_DO_NOT_RAISE_HARD_ERROR. 6 | 7 | It's the only thing that keeps even VS2022 compiler/linker components from running on vanilla Vista. 8 | */ 9 | { 10 | PEXCEPTION_RECORD p_ExceptionRecord; 11 | NTSTATUS Status; 12 | PULONG Response; 13 | _EXCEPTION_RECORD ExceptionRecord; 14 | _CONTEXT ContextRecord; 15 | PVOID retaddr; 16 | 17 | p_ExceptionRecord = pExceptionRecord; 18 | if ( pExceptionRecord ) 19 | { 20 | pExceptionRecord->ExceptionFlags |= EXCEPTION_NONCONTINUABLE; 21 | if ( (dwFlags & FAIL_FAST_GENERATE_EXCEPTION_ADDRESS) != 0 ) 22 | pExceptionRecord->ExceptionAddress = retaddr; 23 | } 24 | else 25 | { 26 | memset(&ExceptionRecord, 0, sizeof(ExceptionRecord)); 27 | p_ExceptionRecord = &ExceptionRecord; 28 | ExceptionRecord.ExceptionAddress = retaddr; 29 | ExceptionRecord.ExceptionCode = STATUS_FAIL_FAST_EXCEPTION; 30 | ExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE; 31 | } 32 | if ( !pContextRecord ) 33 | { 34 | memset(&ContextRecord, 0, sizeof(ContextRecord)); 35 | RtlCaptureContext(&ContextRecord); 36 | } 37 | if ( SignalStartWerSvc() < STATUS_SUCCESS || (Status = WaitForWerSvc(), Status < STATUS_SUCCESS) || Status == STATUS_TIMEOUT /*|| 0x7FFE02F0 & 1) == 0*/ || RtlReportException(NULL, NULL, 0x100) == STATUS_NOT_SUPPORTED) 38 | { // ^ Not exactly sure how to point to SharedUserData, 39 | if ( (dwFlags & 2) == 0 ) // but if that is true, exception handling is basically turned off. 40 | NtRaiseHardError(p_ExceptionRecord->ExceptionCode | 0x10000000, 0, 0, 0, 1, Response); // The RtlReportException() call does the same thing, and will return either that or STATUS_INVALID_PARAMETER. 41 | TerminateProcess((HANDLE)-1, p_ExceptionRecord->ExceptionCode); 42 | } 43 | else 44 | { 45 | NtRaiseException(p_ExceptionRecord, &ContextRecord, 0); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /windows7/findfirstfileexw_wrapper.c: -------------------------------------------------------------------------------- 1 | HANDLE WINAPI FindFirstFileExW_Wrapper(LPCWSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, LPVOID lpFindFileData, 2 | FINDEX_SEARCH_OPS fSearchOp, LPVOID lpSearchFilter, DWORD dwAdditionalFlags) 3 | /* 4 | Windows 7 (and Windows 10 RS4) added some new enums/flags to both FINDEX_INFO_LEVELS and dwAdditionalFlags. 5 | FindFirstFileExW is designed to fail if flags not recognized by the function are used; for Vista and below, 6 | that caused problems with Chromium browsers when legacy fallback code was removed in June 2017. 7 | 8 | The FindFirstFileExW calls used the new flags and enums, causing them to fail, resulting in severely hampered functionality: 9 | extensions refused to install; temporary directories not being removed; cookies not being stored. 10 | 11 | Luckily, some of the new flags can be ignored while others result in structs with less data than before. The only real change here 12 | is to recognize the FindExInfoBasic level of FINDEX_INFO_LEVELS. The resulting WIN32_FIND_DATA struct is the same as with 13 | FindExInfoStandard, but with the short file name removed. 14 | */ 15 | { 16 | HANDLE SearchHandle; 17 | 18 | if((dwAdditionalFlags & 0xFFFFFFF8) != 0 || fInfoLevelId > FindExInfoBasic) 19 | { 20 | RtlSetLastWin32Error(ERROR_INVALID_PARAMETER); 21 | return (HANDLE) -1; 22 | } 23 | 24 | if(dwAdditionalFlags & FIND_FIRST_EX_CASE_SENSITIVE) 25 | dwAdditionalFlags = FIND_FIRST_EX_CASE_SENSITIVE; 26 | else 27 | dwAdditionalFlags = 0; 28 | 29 | SearchHandle = FindFirstFileExW(lpFileName, FindExInfoStandard, lpFindFileData, fSearchOp, lpSearchFilter, dwAdditionalFlags); 30 | 31 | if(fInfoLevelId == FindExInfoBasic) 32 | { 33 | LPWIN32_FIND_DATAW Win32FileData = (LPWIN32_FIND_DATAW) lpFindFileData; 34 | Win32FileData->cAlternateFileName[0] = NULL; 35 | } 36 | 37 | return SearchHandle; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /windows7/getlogicalprocessorninformationex.c: -------------------------------------------------------------------------------- 1 | BOOL GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP RelationshipType, PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX Buffer, PDWORD ReturnedLength) 2 | /* 3 | A tough cookie of a function, which builds on the XP SP3/2003 SP1 function GetLogicalProcessorInformation. That function returns a struct with information 4 | on either of the following: 5 | -Cache 6 | -NUMA nodes 7 | -Processor cores 8 | -Physical processor packages 9 | 10 | GetLogicalProcessorInformationEx does the same thing, but also returns information on processor groups and does not return all possible information if requested. 11 | */ 12 | { 13 | PSYSTEM_LOGICAL_PROCESSOR_INFORMATION BufferClassic; 14 | PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Ptr; 15 | PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX NewBuffer; 16 | SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX Temp; 17 | SYSTEM_INFO SysInfo; 18 | DWORD ReturnedLengthClassic; 19 | DWORD RequiredLength_All; 20 | DWORD RequiredLength; 21 | DWORD NewOffset; 22 | DWORD Offset; 23 | #ifdef _X86_ 24 | long ActiveProcessorMask; 25 | #else 26 | __int64 ActiveProcessorMask; 27 | #endif 28 | BOOL StructisCopied; 29 | BOOL BufferTooSmall = FALSE; 30 | 31 | if(!ReturnedLength || RelationshipType < 0 || (RelationshipType > 7 && RelationshipType != RelationAll)) 32 | { 33 | RtlSetLastWin32Error(ERROR_INVALID_PARAMETER); 34 | return FALSE; 35 | } 36 | if(Buffer == NULL) 37 | { 38 | BufferTooSmall = TRUE; 39 | } 40 | 41 | BufferClassic = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)RtlAllocateHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, sizeof(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)); 42 | ReturnedLengthClassic = 0; 43 | while(!GetLogicalProcessorInformation(BufferClassic, &ReturnedLengthClassic)) 44 | { 45 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) 46 | { 47 | RtlFreeHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, BufferClassic); 48 | 49 | BufferClassic = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)RtlAllocateHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, ReturnedLengthClassic); 50 | 51 | } 52 | else 53 | return FALSE; // a lost cause; the first error is the only anticipated error. ERROR_NOACCESS is also possible, but shouldn't based on the way I've set it up. 54 | 55 | 56 | } 57 | 58 | GetSystemInfo(&SysInfo); 59 | 60 | ActiveProcessorMask = SysInfo.dwActiveProcessorMask; 61 | 62 | Ptr = BufferClassic; 63 | 64 | NewBuffer = Buffer; 65 | 66 | Offset = 0; 67 | RequiredLength_All = 0; 68 | RequiredLength = 0; 69 | NewOffset = 0; 70 | 71 | 72 | 73 | while (Offset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= ReturnedLengthClassic) 74 | { 75 | StructisCopied = FALSE; 76 | switch(Ptr->Relationship) 77 | { 78 | case RelationNumaNode: 79 | if(RelationshipType == RelationNumaNode || RelationshipType == RelationAll) 80 | { 81 | StructisCopied = TRUE; 82 | Temp.Relationship = RelationNumaNode; 83 | #ifdef _X86_ 84 | Temp.Size = 76; 85 | RequiredLength = 76; 86 | RequiredLength_All += 76; 87 | #else 88 | Temp.Size = 80; 89 | RequiredLength = 80; 90 | RequiredLength_All += 80; 91 | #endif 92 | Temp.NumaNode.NodeNumber = Ptr->NumaNode.NodeNumber; 93 | Temp.NumaNode.GroupMask.Mask = (KAFFINITY) ActiveProcessorMask; 94 | Temp.NumaNode.GroupMask.Group = 0; 95 | if(RequiredLength_All > *ReturnedLength || BufferTooSmall) 96 | BufferTooSmall = TRUE; 97 | else 98 | *NewBuffer = Temp; 99 | } 100 | break; 101 | case RelationProcessorCore: 102 | case RelationProcessorPackage: 103 | if(RelationshipType == RelationProcessorCore || RelationshipType == RelationAll || RelationshipType == RelationProcessorPackage) 104 | { 105 | StructisCopied = TRUE; 106 | if(Ptr->Relationship == RelationProcessorCore) 107 | Temp.Relationship = RelationProcessorCore; 108 | else 109 | Temp.Relationship = RelationProcessorPackage; 110 | #ifdef _X86_ 111 | Temp.Size = 76; 112 | RequiredLength = 76; 113 | RequiredLength_All += 76; 114 | #else 115 | Temp.Size = 80; 116 | RequiredLength = 80; 117 | RequiredLength_All += 80; 118 | #endif 119 | Temp.Processor.Flags = Ptr->ProcessorCore.Flags; 120 | Temp.Processor.EfficiencyClass = 0; 121 | Temp.Processor.GroupCount = 1; 122 | Temp.Processor.GroupMask->Mask =(KAFFINITY) ActiveProcessorMask; 123 | Temp.Processor.GroupMask->Group = 0; 124 | if(RequiredLength_All > *ReturnedLength || BufferTooSmall) 125 | BufferTooSmall = TRUE; 126 | else 127 | *NewBuffer = Temp; 128 | } 129 | break; 130 | case RelationCache: 131 | if(RelationshipType == RelationCache || RelationshipType == RelationAll) 132 | { 133 | StructisCopied = TRUE; 134 | Temp.Relationship = RelationCache; 135 | Temp.Cache.Level = Ptr->Cache.Level; 136 | #ifdef _X86_ 137 | Temp.Size = 76; //52 138 | RequiredLength = 76; 139 | RequiredLength_All += 76; 140 | #else 141 | Temp.Size = 80; 142 | RequiredLength = 80; 143 | RequiredLength_All += 80; 144 | #endif 145 | Temp.Cache.Associativity = Ptr->Cache.Associativity; 146 | Temp.Cache.LineSize = Ptr->Cache.LineSize; 147 | Temp.Cache.CacheSize = Ptr->Cache.Size; 148 | Temp.Cache.Type = Ptr->Cache.Type; 149 | Temp.Cache.GroupCount = 1; 150 | Temp.Cache.GroupMask.Mask = (KAFFINITY) ActiveProcessorMask; 151 | Temp.Cache.GroupMask.Group = 0; 152 | if(RequiredLength_All > *ReturnedLength || BufferTooSmall) 153 | BufferTooSmall = TRUE; 154 | else 155 | *NewBuffer = Temp; 156 | 157 | } 158 | break; 159 | 160 | } 161 | 162 | Offset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); 163 | NewOffset = RequiredLength + Offset; 164 | RequiredLength = 0; // to make sure it doesn't advance the SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX pointer 165 | // if a SYSTEM_LOGICAL_PROCESSOR_INFORMATION struct contains irrelevant information 166 | if (StructisCopied && !BufferTooSmall) 167 | NewBuffer++; 168 | Ptr++; 169 | } 170 | RtlFreeHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, BufferClassic); 171 | if(RelationshipType == RelationGroup || RelationshipType == RelationAll) 172 | { 173 | Temp.Relationship = RelationGroup; 174 | #ifdef _X86_ 175 | Temp.Size = 76; 176 | RequiredLength = 76; 177 | RequiredLength_All += 76; 178 | #else 179 | Temp.Size = 80; 180 | RequiredLength = 80; 181 | RequiredLength_All += 80; 182 | #endif 183 | Temp.Group.MaximumGroupCount = 1; 184 | Temp.Group.ActiveGroupCount = 1; 185 | Temp.Group.GroupInfo->MaximumProcessorCount = SysInfo.dwNumberOfProcessors; 186 | Temp.Group.GroupInfo->ActiveProcessorCount = SysInfo.dwNumberOfProcessors; 187 | Temp.Group.GroupInfo->ActiveProcessorMask = (KAFFINITY) ActiveProcessorMask; 188 | if(RequiredLength_All > *ReturnedLength || BufferTooSmall) 189 | BufferTooSmall = TRUE; 190 | else 191 | *NewBuffer = Temp; 192 | } 193 | 194 | 195 | 196 | *ReturnedLength = RequiredLength_All; 197 | if(BufferTooSmall) 198 | { 199 | RtlSetLastWin32Error(ERROR_INSUFFICIENT_BUFFER); 200 | return FALSE; 201 | } 202 | 203 | return TRUE; 204 | 205 | 206 | 207 | 208 | } 209 | -------------------------------------------------------------------------------- /windows7/groupaffinity_pre7.c: -------------------------------------------------------------------------------- 1 | BOOL GetProcessGroupAffinity(HANDLE hProcess, PUSHORT GroupCount, PUSHORT GroupArray) 2 | // Technically, all CPUs before Windows 7 were in group 0, so the function implementations are changed to reflect this reality. 3 | { 4 | _PROCESS_INFORMATION ProcessInfo; 5 | NTSTATUS Status; 6 | *GroupCount = 1; 7 | if(!GroupCount) 8 | { 9 | SetLastError(ERROR_INSUFFICIENT_BUFFER); 10 | return FALSE; 11 | } 12 | 13 | Status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &ProcessInfo, sizeof(_PROCESS_INFORMATION), NULL); 14 | // Like GetProcessId(hProcess) but with fewer steps 15 | if(Status < 0) 16 | { 17 | BaseSetLastNTError(Status); 18 | return FALSE; 19 | } 20 | 21 | GroupArray[0] = 1; 22 | 23 | return TRUE; 24 | 25 | } 26 | 27 | BOOL SetThreadGroupAffinity(HANDLE hThread, const GROUP_AFFINITY *GroupAffinity, PGROUP_AFFINITY PreviousGroupAffinity) 28 | // Well, process affinity is supposed to match thread group affinity at least in basic cases. 29 | // That is why I rely on process affinity for obtaining the previous group affinity. 30 | { 31 | DWORD_PTR ProcessAffinityMask; 32 | DWORD_PTR SystemAffinityMask; 33 | DWORD Pid; 34 | HANDLE hProcess; 35 | 36 | if(PreviousGroupAffinity) 37 | { 38 | Pid = GetProcessIdOfThread(hThread); 39 | hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, Pid); 40 | if(!hProcess) 41 | return FALSE; 42 | 43 | GetProcessAffinityMask(hProcess, &ProcessAffinityMask, &SystemAffinityMask); 44 | PreviousGroupAffinity->Mask = ProcessAffinityMask; 45 | CloseHandle(hProcess); 46 | } 47 | 48 | return SetThreadAffinityMask(hThread, GroupAffinity->Mask); 49 | } 50 | 51 | BOOL GetThreadGroupAffinity(HANDLE hThread, PGROUP_AFFINITY GroupAffinity) 52 | // This is basically the same procedure as above, with regards to obtaining the "previous" affinity 53 | { 54 | DWORD_PTR ProcessAffinityMask; 55 | DWORD_PTR SystemAffinityMask; 56 | DWORD Pid; 57 | HANDLE hProcess; 58 | 59 | Pid = GetProcessIdOfThread(hThread); 60 | hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, Pid); 61 | if(!hProcess) 62 | return FALSE; 63 | 64 | if(!GetProcessAffinityMask(hProcess, &ProcessAffinityMask, &SystemAffinityMask)) 65 | return FALSE; 66 | GroupAffinity->Mask = ProcessAffinityMask; 67 | GroupAffinity->Group = 0; 68 | CloseHandle(hProcess); 69 | 70 | return TRUE; 71 | } 72 | 73 | BOOL GetThreadIdealProcessorEx(HANDLE hThread, PPROCESSOR_NUMBER lpIdealProcessor) 74 | // SetThreadIdealProcessor returns the "previous" or current IdealProcessor value. 75 | { 76 | lpIdealProcessor->Number = SetThreadIdealProcessor(hThread, MAXIMUM_PROCESSORS); 77 | lpIdealProcessor->Group = 0; 78 | 79 | if(lpIdealProcessor->Number == -1) 80 | return FALSE; 81 | else 82 | return TRUE; 83 | } 84 | 85 | BOOL SetThreadIdealProcessorEx(HANDLE hThread, PPROCESSOR_NUMBER lpIdealProcessor, 86 | PPROCESSOR_NUMBER lpPreviousIdealProcessor) 87 | { 88 | lpPreviousIdealProcessor->Number = SetThreadIdealProcessor(hThread, lpIdealProcessor->Number); 89 | lpPreviousIdealProcessor->Group = 0; 90 | lpIdealProcessor->Group = 0; 91 | 92 | if(lpPreviousIdealProcessor->Number == -1) 93 | return FALSE; 94 | else 95 | return TRUE; 96 | } 97 | -------------------------------------------------------------------------------- /windows7/numa.c: -------------------------------------------------------------------------------- 1 | BOOL WINAPI GetNumaProcesorNodeEx(PPROCESSOR_NUMBER Processor, PUSHORT NodeNumber) 2 | { 3 | if(!Processor) 4 | { 5 | SetLastError(ERROR_INVALID_PARAMETER); 6 | return FALSE; 7 | } 8 | return GetNumaProcessorNode(Processor->Number, (PUCHAR)NodeNumber); 9 | } 10 | 11 | BOOL WINAPI GetNumaNodeProcessorMaskEx(UCHAR Node, PGROUP_AFFINITY ProcessorMask) 12 | { 13 | if(!ProcessorMask) 14 | { 15 | SetLastError(ERROR_INVALID_PARAMETER); 16 | return FALSE; 17 | } 18 | return GetNumaNodeProcessorMask(Node, &ProcessorMask->Mask); 19 | } 20 | -------------------------------------------------------------------------------- /windows7/oleapi.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | BOOLEAN g_cMTAInits; // Global variables within ole32 itself 4 | DWORD gdwMainThreadId; 5 | 6 | HRESULT WINAPI CoGetApartmentType(APTTYPE *pAptType, APTTYPEQUALIFIER *pAptQualifier) 7 | /* 8 | win32 - March 7 2021 9 | An important OLE function introduced in Windows 7, but should be usable in NT 4 and above. 10 | */ 11 | { 12 | HRESULT Status; 13 | BOOLEAN MTAInit; 14 | SOleTlsData* ReservedForOle; 15 | DWORD CurrentThreadId; 16 | DWORD OleFlags; 17 | APTTYPE AptTypeTemp; 18 | APTTYPEQUALIFIER AptQualifierTemp; 19 | TEB *CurrentThreadInfo; 20 | 21 | Status = S_OK; 22 | if ( !pAptType || !pAptQualifier ) 23 | return E_INVALIDARG; 24 | *pAptType = APTTYPE_CURRENT; 25 | *pAptQualifier = APTTYPEQUALIFIER_NONE; 26 | MTAInit = FALSE; 27 | CurrentThreadInfo = NtCurrentTeb(); 28 | ReservedForOle = (SOleTlsData*) CurrentThreadInfo->ReservedForOle; 29 | if ( g_cMTAInits ) 30 | MTAInit = TRUE; 31 | // The following is a GetCurrentThreadId() replacement. 32 | // NtCurrentTeb()->UniqueThread.ClientId or NtCurrentTeb() + 48h (AMD64) or NtCurrentTeb() + 24h (X86) 33 | CurrentThreadId = (DWORD)CurrentThreadInfo->UniqueThread.ClientId; 34 | 35 | if ( !ReservedForOle ) 36 | { 37 | if ( MTAInit ) 38 | goto ImplicitMTA; 39 | return CO_E_NOTINITIALIZED; 40 | } 41 | OleFlags = ReservedForOle->dwFlags; 42 | if ( (OleFlags & 0x800) == 0 ) 43 | { 44 | if ( (OleFlags & 0x80) != 0 ) 45 | { 46 | AptTypeTemp = APTTYPE_STA; 47 | if ( CurrentThreadId == gdwMainThreadId ) 48 | AptTypeTemp = APTTYPE_MAINSTA; 49 | *pAptType = AptTypeTemp; 50 | if ( (OleFlags & 0x400000) != 0 ) 51 | *pAptQualifier = APTTYPEQUALIFIER_APPLICATION_STA; 52 | 53 | if ( (OleFlags & 0x40000000) != 0 ) 54 | *pAptQualifier = APTTYPEQUALIFIER_RESERVED_1; 55 | return Status; 56 | } 57 | if ( (OleFlags & 0x1100) != 0 ) 58 | { 59 | *pAptType = APTTYPE_MTA; 60 | return Status; 61 | } 62 | if ( MTAInit ) 63 | { 64 | ImplicitMTA: 65 | *pAptType = APTTYPE_MTA; 66 | *pAptQualifier = APTTYPEQUALIFIER_IMPLICIT_MTA; 67 | return Status; 68 | } 69 | return CO_E_NOTINITIALIZED; 70 | } 71 | AptQualifierTemp = APTTYPEQUALIFIER_NA_ON_MTA; 72 | *pAptType = APTTYPE_NA; 73 | if ( (OleFlags & 0x80) != 0 ) 74 | { 75 | AptQualifierTemp = APTTYPEQUALIFIER_NA_ON_STA; 76 | if ( CurrentThreadId == gdwMainThreadId ) 77 | AptQualifierTemp = APTTYPEQUALIFIER_NA_ON_MAINSTA; 78 | *pAptQualifier = AptQualifierTemp; 79 | return Status; 80 | } 81 | if ( (OleFlags & 0x1100) != 0 ) 82 | { 83 | *pAptQualifier = AptQualifierTemp; 84 | return Status; 85 | } 86 | if ( MTAInit ) 87 | { 88 | *pAptQualifier = APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA; 89 | return Status; 90 | } 91 | return E_FAIL; 92 | } 93 | -------------------------------------------------------------------------------- /windows7/pbkdf2_bcrypt.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2008 Damien Bergamini 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * This code has been adapted for the Windows Vista Extended Kernel. It is based off OpenBSD's implementation of PBKDF2. 19 | */ 20 | 21 | #define SIZE_MAX 0xFFFFFFFF 22 | 23 | 24 | NTSTATUS BCryptDeriveKeyPBKDF2(BCRYPT_ALG_HANDLE hPrf, const char *pbPassword, size_t cbPassword, const uint8_t *pbSalt, 25 | size_t cbSalt, uint8_t *pbDerivedKey, size_t cbDerivedKey, ULONGLONG cIterations) 26 | { 27 | UCHAR* aSalt, *obuf; // Update this, use variable digest length obtained from BCryptGetProperty call 28 | UCHAR* d1, *d2; 29 | ULONG i, j; 30 | ULONG count, ResultLength; 31 | size_t r; 32 | DWORD DigestLength; 33 | BCRYPT_HASH_HANDLE hHash; 34 | NTSTATUS Status = STATUS_SUCCESS; 35 | 36 | if (cIterations < 1 || cbDerivedKey == 0 || !hPrf) 37 | return STATUS_INVALID_PARAMETER; 38 | if (cbSalt == 0 || cbSalt > SIZE_MAX - 4) 39 | return STATUS_INVALID_PARAMETER; 40 | 41 | Status = BCryptGetProperty(hPrf, L"HashDigestLength", (PUCHAR)&DigestLength, sizeof(DWORD), &ResultLength, 0); 42 | if(Status < STATUS_SUCCESS) 43 | return Status; 44 | 45 | 46 | if ((aSalt = (PUCHAR)RtlAllocateHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, cbSalt + 4)) == NULL) 47 | return STATUS_NO_MEMORY; 48 | 49 | if ((obuf = (PUCHAR)RtlAllocateHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, DigestLength)) == NULL) 50 | { 51 | BCryptFree(aSalt); // undocumented function exported from BCrypt - basically a wrapper for RtlFreeHeap with flags = 0 and PEB heap 52 | return STATUS_NO_MEMORY; 53 | } 54 | 55 | if ((d1 = (PUCHAR)RtlAllocateHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, DigestLength)) == NULL) 56 | { 57 | BCryptFree(aSalt); 58 | BCryptFree(obuf); 59 | return STATUS_NO_MEMORY; 60 | } 61 | 62 | if ((d2 = (PUCHAR)RtlAllocateHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, DigestLength)) == NULL) 63 | { 64 | BCryptFree(aSalt); 65 | BCryptFree(obuf); 66 | BCryptFree(d1); 67 | return STATUS_NO_MEMORY; 68 | } 69 | 70 | memcpy(aSalt, pbSalt, cbSalt); 71 | 72 | for (count = 1; cbDerivedKey > 0; count++) { 73 | aSalt[cbSalt + 0] = (count >> 24) & 0xff; 74 | aSalt[cbSalt + 1] = (count >> 16) & 0xff; 75 | aSalt[cbSalt + 2] = (count >> 8) & 0xff; 76 | aSalt[cbSalt + 3] = count & 0xff; 77 | Status = BCryptHash(hPrf, (PUCHAR)pbPassword, cbPassword, aSalt, cbSalt + 4, d1, DigestLength); 78 | if (Status < STATUS_SUCCESS) 79 | goto FreeMemory; 80 | memcpy(obuf, d1, DigestLength); 81 | 82 | for (i = 1; i < cIterations; i++) { 83 | Status = BCryptHash(hPrf, (PUCHAR)pbPassword, cbPassword, d1, DigestLength, d2, DigestLength); 84 | if (Status < STATUS_SUCCESS) 85 | goto FreeMemory; 86 | memcpy(d1, d2, DigestLength); 87 | for (j = 0; j < DigestLength; j++) 88 | obuf[j] ^= d1[j]; 89 | } 90 | 91 | r = min(cbDerivedKey, DigestLength); 92 | memcpy(pbDerivedKey, obuf, r); 93 | pbDerivedKey += r; 94 | cbDerivedKey -= r; 95 | }; 96 | 97 | FreeMemory: 98 | memset(aSalt, 0, cbSalt + 4); 99 | BCryptFree(aSalt); 100 | memset(d1, 0, DigestLength); 101 | BCryptFree(d1); 102 | memset(d2, 0, DigestLength); 103 | BCryptFree(d2); 104 | memset(obuf, 0, DigestLength); 105 | BCryptFree(obuf); 106 | 107 | return Status; 108 | } 109 | -------------------------------------------------------------------------------- /windows7/power.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | HANDLE g_hkPower = 0; 4 | 5 | BOOL WINAPI Implementation_PowerClearRequest( 6 | HANDLE PowerRequest, 7 | POWER_REQUEST_TYPE RequestType 8 | ) 9 | { 10 | LONG dwQuantity; 11 | DWORD dwSize; 12 | switch (RequestType) 13 | { 14 | case PowerRequestDisplayRequired: 15 | SetThreadExecutionState(SetThreadExecutionState(ES_CONTINUOUS) & ~ES_DISPLAY_REQUIRED); 16 | WaitForSingleObject(MutexRegistry, INFINITE); 17 | RegQueryValueExA(g_hkPower, "NumberActiveWakeLocks", NULL, NULL, &dwQuantity, &dwSize); 18 | --dwQuantity; 19 | if (dwQuantity < 0) 20 | dwQuantity = 0; 21 | RegSetValueExA(g_hkPower, "NumberActiveWakeLocks", NULL, REG_DWORD, &dwQuantity, 4); 22 | if (!dwQuantity) 23 | SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, 1, NULL, SPIF_SENDCHANGE); 24 | ReleaseMutex(MutexRegistry); 25 | return TRUE; 26 | case PowerRequestSystemRequired: 27 | SetThreadExecutionState(SetThreadExecutionState(ES_CONTINUOUS) & ~ES_SYSTEM_REQUIRED); 28 | return TRUE; 29 | case PowerRequestAwayModeRequired: 30 | SetThreadExecutionState(SetThreadExecutionState(ES_CONTINUOUS) & ~ES_AWAYMODE_REQUIRED); 31 | return TRUE; 32 | case PowerRequestExecutionRequired: 33 | SetThreadExecutionState(SetThreadExecutionState(ES_CONTINUOUS) & ~ES_SYSTEM_REQUIRED); 34 | return TRUE; 35 | } 36 | SetLastError(ERROR_INVALID_PARAMETER); 37 | return FALSE; 38 | } 39 | HANDLE WINAPI Implementation_PowerCreateRequest( 40 | PREASON_CONTEXT Context 41 | ) 42 | { 43 | DWORD dwQuantity, dwSize; 44 | WaitForSingleObject(MutexRegistry, INFINITE); 45 | 46 | if (!g_hkPower) 47 | RegCreateKeyA(HKEY_LOCAL_MACHINE, "Software\\Progwrp", &g_hkPower); 48 | if (RegQueryValueExA(g_hkPower, "NumberActiveWakeLocks", NULL, NULL, &dwQuantity, &dwSize) != ERROR_SUCCESS) 49 | { 50 | dwQuantity = 0; 51 | RegSetValueExA(g_hkPower, "NumberActiveWakeLocks", 0, REG_DWORD, &dwQuantity, 4); 52 | } 53 | 54 | ReleaseMutex(MutexRegistry); 55 | return CreateSemaphoreA(NULL, 0, 1, NULL); 56 | } 57 | BOOL WINAPI Implementation_PowerSetRequest( 58 | HANDLE PowerRequest, 59 | POWER_REQUEST_TYPE RequestType 60 | ) 61 | { 62 | LONG dwQuantity; 63 | DWORD dwSize; 64 | ULONG PreviousRequest; 65 | switch (RequestType) 66 | { 67 | case PowerRequestDisplayRequired: 68 | PreviousRequest = SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); 69 | // MS documentation says that this function has no effect on screensavers, while 70 | // some GLFW code and issues claim otherwise, but that code has mostly Windows 10 in mind. 71 | // On XP, this was insufficient. So I am also calling SystemParametersInfo to 72 | // disable the screensaver. 73 | SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | PreviousRequest); 74 | WaitForSingleObject(MutexRegistry, INFINITE); 75 | RegQueryValueExA(g_hkPower, "NumberActiveWakeLocks", NULL, NULL, &dwQuantity, &dwSize); 76 | ++dwQuantity; 77 | RegSetValueExA(g_hkPower, "NumberActiveWakeLocks", NULL, REG_DWORD, &dwQuantity, 4); 78 | if (dwQuantity > 0) 79 | SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, 0, NULL, SPIF_SENDCHANGE); 80 | ReleaseMutex(MutexRegistry); 81 | return TRUE; 82 | case PowerRequestSystemRequired: 83 | PreviousRequest = SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED); 84 | SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | PreviousRequest); 85 | return TRUE; 86 | case PowerRequestAwayModeRequired: 87 | PreviousRequest = SetThreadExecutionState(ES_CONTINUOUS | ES_AWAYMODE_REQUIRED); 88 | SetThreadExecutionState(ES_CONTINUOUS | ES_AWAYMODE_REQUIRED | PreviousRequest); 89 | return TRUE; 90 | case PowerRequestExecutionRequired: 91 | PreviousRequest = SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED); 92 | SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | PreviousRequest); 93 | return TRUE; 94 | } 95 | SetLastError(ERROR_INVALID_PARAMETER); 96 | return FALSE; 97 | } 98 | -------------------------------------------------------------------------------- /windows7/proccount.c: -------------------------------------------------------------------------------- 1 | DWORD WINAPI GetMaximumProcessorCount(WORD GroupNumber) 2 | /* 3 | Some of this may seem a little odd, but I found when testing the functions on Vista systems that had 4 | hyperthreading disabled in BIOS, that the output was "switched around". 5 | 6 | GetMaximumProcessorCount seems like it should have used the variable ntoskrnl!KeNumberProcessors which is placed in the 7 | SYSTEM_BASIC_INFORMATION struct at member NumberOfProcessors (KeQueryMaximumProcessorCount returns KeNumberProcessors as well). 8 | 9 | GetActiveProcessorCount should have used the affinity mask at member ActiveProcessorsAffinityMask (ntoskrnl!KeActiveProcessors) 10 | 11 | But the resulting output was as follows (on a 6C/12T system with HT disabled): 12 | GetMaximumProcessorCount returns 6 (logical processors) 13 | GetActiveProcessorCount returns 12 (logical processors) 14 | 15 | Not good. CPU-Z will not load with these results. 16 | 17 | The functions were swapped around, and provided satisfactory results for CPU-Z (and presumably other 18 | hardware verification software). And most importantly the results now reflect what 19 | you would get with the official functions, but with lower overhead. 20 | */ 21 | { 22 | DWORD MaximumProcessorCount; 23 | NTSTATUS Status; 24 | INT i; 25 | SYSTEM_BASIC_INFORMATION sysbasic; 26 | if(GroupNumber != 0 && GroupNumber != ALL_PROCESSOR_GROUPS) 27 | return 0; 28 | else 29 | { 30 | Status = NtQuerySystemInformation(SystemBasicInformation, &sysbasic, sizeof(SYSTEM_BASIC_INFORMATION), NULL); 31 | if (Status < 0) 32 | { 33 | BaseSetLastNTError(Status); 34 | return 0; 35 | } 36 | 37 | MaximumProcessorCount = 0; 38 | 39 | #ifdef _X86_ 40 | for(i = 0; i < 32; i++) // Maximum of 32 processors on x86 Windows; 41 | #else 42 | for(i = 0; i < 64; i++) 43 | #endif 44 | if(sysbasic.ActiveProcessorsAffinityMask & 1 << i) 45 | ++MaximumProcessorCount; 46 | 47 | return MaximumProcessorCount; 48 | } 49 | } 50 | 51 | DWORD WINAPI GetActiveProcessorCount(WORD GroupNumber) 52 | { 53 | NTSTATUS Status; 54 | SYSTEM_BASIC_INFORMATION sysbasic; 55 | if(GroupNumber != 0 && GroupNumber != ALL_PROCESSOR_GROUPS) 56 | { 57 | return 0; 58 | } 59 | else 60 | { 61 | Status = NtQuerySystemInformation(SystemBasicInformation, &sysbasic, sizeof(SYSTEM_BASIC_INFORMATION), NULL); 62 | if (Status < 0) 63 | { 64 | BaseSetLastNTError(Status); 65 | return 0; 66 | } 67 | return sysbasic.NumberOfProcessors; 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /windows7/stringordinal.c: -------------------------------------------------------------------------------- 1 | int WINAPI FindStringOrdinalS(DWORD dwFindStringOrdinalFlags, LPCWSTR lpStringSource, int cchSource, LPCWSTR lpStringValue, 2 | int cchValue, BOOL bIgnoreCase) 3 | { 4 | WCHAR* SourceCopy; 5 | WCHAR* ValueCopy; 6 | int i; 7 | int j; 8 | int k; 9 | int returnIndex; 10 | 11 | RtlSetLastWin32Error(ERROR_SUCCESS); 12 | 13 | if(!lpStringSource || !lpStringValue || cchSource < -1 || cchValue < -1) 14 | { 15 | RtlSetLastWin32Error(ERROR_INVALID_PARAMETER); 16 | return -1; 17 | } 18 | 19 | if((dwFindStringOrdinalFlags == FIND_FROMSTART && 20 | dwFindStringOrdinalFlags == FIND_FROMEND) || 21 | (dwFindStringOrdinalFlags == FIND_FROMSTART && 22 | dwFindStringOrdinalFlags == FIND_STARTSWITH) || 23 | (dwFindStringOrdinalFlags == FIND_FROMSTART && 24 | dwFindStringOrdinalFlags == FIND_ENDSWITH) || 25 | (dwFindStringOrdinalFlags == FIND_FROMEND && 26 | dwFindStringOrdinalFlags == FIND_STARTSWITH) || 27 | (dwFindStringOrdinalFlags == FIND_FROMEND && 28 | dwFindStringOrdinalFlags == FIND_ENDSWITH) || 29 | (dwFindStringOrdinalFlags == FIND_STARTSWITH && 30 | dwFindStringOrdinalFlags == FIND_ENDSWITH) || 31 | !bIgnoreCase && bIgnoreCase || 32 | (dwFindStringOrdinalFlags & 0xFF0FFFFF) != 0) 33 | { 34 | RtlSetLastWin32Error(ERROR_INVALID_FLAGS); 35 | return -1; 36 | } 37 | 38 | if(cchSource == -1) 39 | cchSource = wcslen(lpStringSource); // In the original function it is NlsStrLenW() 40 | if(cchValue == -1) 41 | cchValue = wcslen(lpStringValue); 42 | 43 | 44 | SourceCopy = (WCHAR*)RtlAllocateHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, HEAP_ZERO_MEMORY, sizeof(WCHAR)*cchSource); // Possibly replace with RtlAllocateHeap() 45 | ValueCopy = (WCHAR*)RtlAllocateHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, HEAP_ZERO_MEMORY, sizeof(WCHAR)*cchValue); 46 | 47 | if(!SourceCopy || !ValueCopy) 48 | { 49 | RtlSetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY); 50 | return -1; 51 | } 52 | 53 | for(i = 0; i < cchSource; i++) 54 | SourceCopy[i] = lpStringSource[i]; 55 | 56 | for(i = 0; i < cchValue; i++) 57 | ValueCopy[i] = lpStringValue[i]; 58 | 59 | if(bIgnoreCase) // This changes all upper case characters to lower case 60 | { 61 | for(i = 0; i < cchSource; i++) 62 | { 63 | if(SourceCopy[i] >= 'A' && SourceCopy[i] <= 'Z') 64 | SourceCopy[i] += 32; 65 | } 66 | for(i = 0; i < cchValue; i++) 67 | { 68 | if(ValueCopy[i] >= 'A' && ValueCopy[i] <= 'Z') 69 | ValueCopy[i] += 32; 70 | } 71 | 72 | } 73 | 74 | returnIndex = -1; 75 | 76 | if(dwFindStringOrdinalFlags == FIND_FROMSTART) 77 | { 78 | for(i = 0; i < cchSource; i++) 79 | { 80 | if (SourceCopy[i] == ValueCopy[0] && ((cchSource - i) >= cchValue)) 81 | { 82 | returnIndex = i; 83 | j = i; 84 | for(k = 1; k < cchValue; k++) 85 | { 86 | ++j; 87 | if(SourceCopy[j] != ValueCopy[k]) 88 | { 89 | returnIndex = -1; 90 | break; 91 | } 92 | } 93 | if(k == cchValue) 94 | break; 95 | } 96 | } 97 | } 98 | 99 | if(dwFindStringOrdinalFlags == FIND_FROMEND) 100 | { 101 | for(i = cchSource - 1; i >= 0; i--) 102 | { 103 | if (SourceCopy[i] == ValueCopy[0] && ((i + 1) >= cchValue)) 104 | { 105 | returnIndex = i; 106 | j = i; 107 | for(k = 1; k < cchValue; k++) 108 | { 109 | --j; 110 | if(SourceCopy[j] != ValueCopy[k]) 111 | { 112 | returnIndex = -1; 113 | break; 114 | } 115 | } 116 | if(k == cchValue) 117 | break; 118 | } 119 | } 120 | } 121 | 122 | if(dwFindStringOrdinalFlags == FIND_STARTSWITH) 123 | { 124 | if(SourceCopy[0] != ValueCopy[0]) 125 | return -1; 126 | else 127 | { 128 | returnIndex = 0; 129 | 130 | for(i = 1; i < cchValue; i++) 131 | { 132 | if(SourceCopy[i] != ValueCopy[i]) 133 | { 134 | returnIndex = -1; 135 | break; 136 | } 137 | } 138 | } 139 | } 140 | 141 | if(dwFindStringOrdinalFlags == FIND_ENDSWITH) 142 | { 143 | if(SourceCopy[cchSource - cchValue] != ValueCopy[0]) 144 | return -1; 145 | else 146 | { 147 | returnIndex = cchSource - cchValue; 148 | j = 0; 149 | 150 | for(i = cchSource - cchValue + 1; i < cchSource; i++) 151 | { 152 | ++j; 153 | 154 | if(SourceCopy[i] != ValueCopy[j]) 155 | { 156 | returnIndex = -1; 157 | break; 158 | } 159 | } 160 | } 161 | } 162 | 163 | RtlFreeHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, SourceCopy); 164 | RtlFreeHeap(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessHeap, 0, ValueCopy); 165 | 166 | return returnIndex; 167 | } -------------------------------------------------------------------------------- /windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "api-ms-win-core-com-l1-1-0", "api-ms-win-core-com-l1-1-0\api-ms-win-core-com-l1-1-0.vcproj", "{153921DD-ED49-4B9A-90F4-EE44B217F306}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {153921DD-ED49-4B9A-90F4-EE44B217F306}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {153921DD-ED49-4B9A-90F4-EE44B217F306}.Debug|Win32.Build.0 = Debug|Win32 16 | {153921DD-ED49-4B9A-90F4-EE44B217F306}.Debug|x64.ActiveCfg = Debug|x64 17 | {153921DD-ED49-4B9A-90F4-EE44B217F306}.Debug|x64.Build.0 = Debug|x64 18 | {153921DD-ED49-4B9A-90F4-EE44B217F306}.Release|Win32.ActiveCfg = Release|Win32 19 | {153921DD-ED49-4B9A-90F4-EE44B217F306}.Release|Win32.Build.0 = Release|Win32 20 | {153921DD-ED49-4B9A-90F4-EE44B217F306}.Release|x64.ActiveCfg = Release|x64 21 | {153921DD-ED49-4B9A-90F4-EE44B217F306}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/win32ss/win32-api-reversals/f380a0c9e7a8ae07f4afa514884b60510c75ccf4/windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0.suo -------------------------------------------------------------------------------- /windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0.def: -------------------------------------------------------------------------------- 1 | LIBRARY "api-ms-win-core-com-l1-1-0" 2 | EXPORTS 3 | CLSIDFromProgID=ole32.CLSIDFromProgID 4 | CLSIDFromString=ole32.CLSIDFromString 5 | CoAddRefServerProcess=ole32.CoAddRefServerProcess 6 | CoAllowUnmarshalerCLSID=ole32.CoAllowUnmarshalerCLSID 7 | CoCancelCall=ole32.CoCancelCall 8 | CoCopyProxy=ole32.CoCopyProxy 9 | CoCreateFreeThreadedMarshaler=ole32.CoCreateFreeThreadedMarshaler 10 | CoCreateGuid=ole32.CoCreateGuid 11 | CoCreateInstance=ole32.CoCreateInstance 12 | CoCreateInstanceEx=ole32.CoCreateInstanceEx 13 | CoCreateInstanceFromApp=ole32.CoCreateInstanceFromApp 14 | CoDecodeProxy=ole32.CoDecodeProxy 15 | CoDecrementMTAUsage=ole32.CoDecrementMTAUsage 16 | CoDisableCallCancellation=ole32.CoDisableCallCancellation 17 | CoDisconnectContext=ole32.CoDisconnectContext 18 | CoDisconnectObject=ole32.CoDisconnectObject 19 | CoEnableCallCancellation=ole32.CoEnableCallCancellation 20 | CoFreeUnusedLibraries=ole32.CoFreeUnusedLibraries 21 | CoFreeUnusedLibrariesEx=ole32.CoFreeUnusedLibrariesEx 22 | CoGetApartmentType=ole32.CoGetApartmentType 23 | CoGetCallContext=ole32.CoGetCallContext 24 | CoGetCallerTID=ole32.CoGetCallerTID 25 | CoGetCancelObject=ole32.CoGetCancelObject 26 | CoGetClassObject=ole32.CoGetClassObject 27 | 28 | CoGetContextToken=ole32.CoGetContextToken 29 | CoGetCurrentLogicalThreadId=ole32.CoGetCurrentLogicalThreadId 30 | CoGetCurrentProcess=ole32.CoGetCurrentProcess 31 | CoGetDefaultContext=ole32.CoGetDefaultContext 32 | CoGetInterfaceAndReleaseStream=ole32.CoGetInterfaceAndReleaseStream 33 | CoGetMalloc=ole32.CoGetMalloc 34 | CoGetMarshalSizeMax=ole32.CoGetMarshalSizeMax 35 | CoGetObjectContext=ole32.CoGetObjectContext 36 | CoGetPSClsid=ole32.CoGetPSClsid 37 | CoGetStandardMarshal=ole32.CoGetStandardMarshal 38 | CoGetStdMarshalEx=ole32.CoGetStdMarshalEx 39 | CoGetTreatAsClass=ole32.CoGetTreatAsClass 40 | CoImpersonateClient=ole32.CoImpersonateClient 41 | CoIncrementMTAUsage=ole32.CoIncrementMTAUsage 42 | CoInitializeEx=ole32.CoInitializeEx 43 | CoInitializeSecurity=ole32.CoInitializeSecurity 44 | 45 | CoInvalidateRemoteMachineBindings=ole32.CoInvalidateRemoteMachineBindings 46 | CoIsHandlerConnected=ole32.CoIsHandlerConnected 47 | CoLockObjectExternal=ole32.CoLockObjectExternal 48 | CoMarshalHresult=ole32.CoMarshalHresult 49 | CoMarshalInterThreadInterfaceInStream=ole32.CoMarshalInterThreadInterfaceInStream 50 | CoMarshalInterface=ole32.CoMarshalInterface 51 | CoQueryAuthenticationServices=ole32.CoQueryAuthenticationServices 52 | CoQueryClientBlanket=ole32.CoQueryClientBlanket 53 | CoQueryProxyBlanket=ole32.CoQueryProxyBlanket 54 | CoRegisterClassObject=ole32.CoRegisterClassObject 55 | CoRegisterPSClsid=ole32.CoRegisterPSClsid 56 | CoRegisterSurrogate=ole32.CoRegisterSurrogate 57 | 58 | CoReleaseMarshalData=ole32.CoReleaseMarshalData 59 | CoReleaseServerProcess=ole32.CoReleaseServerProcess 60 | CoResumeClassObjects=ole32.CoResumeClassObjects 61 | CoRevertToSelf=ole32.CoRevertToSelf 62 | CoRevokeClassObject=ole32.CoRevokeClassObject 63 | CoSetCancelObject=ole32.CoSetCancelObject 64 | CoSetProxyBlanket=ole32.CoSetProxyBlanket 65 | CoSuspendClassObjects=ole32.CoSuspendClassObjects 66 | CoSwitchCallContext=ole32.CoSwitchCallContext 67 | CoTaskMemAlloc=ole32.CoTaskMemAlloc 68 | CoTaskMemFree=ole32.CoTaskMemFree 69 | CoTaskMemRealloc=ole32.CoTaskMemRealloc 70 | CoTestCancel=ole32.CoTestCancel 71 | CoUninitialize=ole32.CoUninitialize 72 | CoUnmarshalHresult=ole32.CoUnmarshalHresult 73 | CoUnmarshalInterface=ole32.CoUnmarshalInterface 74 | CoWaitForMultipleHandles=ole32.CoWaitForMultipleHandles 75 | CoWaitForMultipleObjects=ole32.CoWaitForMultipleObjects 76 | CreateStreamOnHGlobal=ole32.CreateStreamOnHGlobal 77 | FreePropVariantArray=ole32.FreePropVariantArray 78 | GetHGlobalFromStream=ole32.GetHGlobalFromStream 79 | IIDFromString=ole32.IIDFromString 80 | ProgIDFromCLSID=ole32.ProgIDFromCLSID 81 | PropVariantClear=ole32.PropVariantClear 82 | PropVariantCopy=ole32.PropVariantCopy 83 | 84 | StringFromCLSID=ole32.StringFromCLSID 85 | StringFromGUID2=ole32.StringFromGUID2 86 | StringFromIID=ole32.StringFromIID -------------------------------------------------------------------------------- /windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | 22 | 29 | 32 | 35 | 38 | 41 | 44 | 55 | 58 | 61 | 64 | 72 | 75 | 78 | 81 | 84 | 87 | 90 | 93 | 94 | 102 | 105 | 108 | 111 | 114 | 117 | 129 | 132 | 135 | 138 | 150 | 153 | 156 | 159 | 162 | 165 | 168 | 171 | 172 | 179 | 182 | 185 | 188 | 191 | 195 | 206 | 209 | 212 | 215 | 223 | 226 | 229 | 232 | 235 | 238 | 241 | 244 | 245 | 253 | 256 | 259 | 262 | 265 | 269 | 281 | 284 | 287 | 290 | 302 | 305 | 308 | 311 | 314 | 317 | 320 | 323 | 324 | 325 | 326 | 327 | 328 | 333 | 336 | 337 | 340 | 343 | 348 | 349 | 352 | 357 | 358 | 361 | 366 | 367 | 370 | 375 | 376 | 377 | 378 | 383 | 386 | 387 | 388 | 393 | 396 | 397 | 398 | 401 | 402 | 403 | 404 | 405 | 406 | -------------------------------------------------------------------------------- /windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0/dllmain.c: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include 3 | 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by version.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0/version.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/win32ss/win32-api-reversals/f380a0c9e7a8ae07f4afa514884b60510c75ccf4/windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0/version.aps -------------------------------------------------------------------------------- /windows8/api-ms-win-core-com-l1-1-0/api-ms-win-core-com-l1-1-0/version.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (Canada) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENC) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_CAN 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""afxres.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Version 53 | // 54 | 55 | VS_VERSION_INFO VERSIONINFO 56 | FILEVERSION 6,0,6004,4006 57 | PRODUCTVERSION 6,0,6004,4006 58 | FILEFLAGSMASK 0x17L 59 | #ifdef _DEBUG 60 | FILEFLAGS 0x1L 61 | #else 62 | FILEFLAGS 0x0L 63 | #endif 64 | FILEOS 0x4L 65 | FILETYPE 0x2L 66 | FILESUBTYPE 0x0L 67 | BEGIN 68 | BLOCK "StringFileInfo" 69 | BEGIN 70 | BLOCK "100904b0" 71 | BEGIN 72 | VALUE "FileDescription", "OLE32 Wrapper for Windows 7 and Below" 73 | VALUE "FileVersion", "6.0.6004.4006" 74 | VALUE "InternalName", "api-ms-win-core-com-l1-1-0.dll" 75 | VALUE "LegalCopyright", "Copyright (C) 2022 win32" 76 | VALUE "OriginalFilename", "api-ms-win-core-com-l1-1-0.dll" 77 | VALUE "ProductName", "Windows Vista Extended Kernel" 78 | VALUE "ProductVersion", "6.0.6004.4006" 79 | END 80 | END 81 | BLOCK "VarFileInfo" 82 | BEGIN 83 | VALUE "Translation", 0x1009, 1200 84 | END 85 | END 86 | 87 | #endif // English (Canada) resources 88 | ///////////////////////////////////////////////////////////////////////////// 89 | 90 | 91 | 92 | #ifndef APSTUDIO_INVOKED 93 | ///////////////////////////////////////////////////////////////////////////// 94 | // 95 | // Generated from the TEXTINCLUDE 3 resource. 96 | // 97 | 98 | 99 | ///////////////////////////////////////////////////////////////////////////// 100 | #endif // not APSTUDIO_INVOKED 101 | 102 | -------------------------------------------------------------------------------- /windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "api-ms-win-shcore-scaling-l1-1-1", "api-ms-win-shcore-scaling-l1-1-1\api-ms-win-shcore-scaling-l1-1-1.vcproj", "{A05A0812-8A29-4CBA-9E79-D31053B3A75E}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {A05A0812-8A29-4CBA-9E79-D31053B3A75E}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {A05A0812-8A29-4CBA-9E79-D31053B3A75E}.Debug|Win32.Build.0 = Debug|Win32 14 | {A05A0812-8A29-4CBA-9E79-D31053B3A75E}.Release|Win32.ActiveCfg = Release|Win32 15 | {A05A0812-8A29-4CBA-9E79-D31053B3A75E}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/win32ss/win32-api-reversals/f380a0c9e7a8ae07f4afa514884b60510c75ccf4/windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1.suo -------------------------------------------------------------------------------- /windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1.def: -------------------------------------------------------------------------------- 1 | LIBRARY "api-ms-win-shcore-scaling-l1-1-1" 2 | 3 | EXPORTS 4 | GetScaleFactorForMonitor 5 | -------------------------------------------------------------------------------- /windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 26 | 29 | 32 | 35 | 38 | 41 | 52 | 55 | 58 | 61 | 69 | 72 | 75 | 78 | 81 | 84 | 87 | 90 | 91 | 99 | 102 | 105 | 108 | 111 | 114 | 125 | 128 | 131 | 134 | 144 | 147 | 150 | 153 | 156 | 159 | 162 | 165 | 166 | 167 | 168 | 169 | 170 | 175 | 178 | 179 | 182 | 185 | 190 | 191 | 194 | 199 | 200 | 201 | 202 | 207 | 210 | 211 | 212 | 217 | 220 | 221 | 222 | 225 | 226 | 227 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include 3 | #include 4 | 5 | BOOL APIENTRY DllMain( HMODULE hModule, 6 | DWORD ul_reason_for_call, 7 | LPVOID lpReserved 8 | ) 9 | { 10 | switch (ul_reason_for_call) 11 | { 12 | case DLL_PROCESS_ATTACH: 13 | case DLL_THREAD_ATTACH: 14 | case DLL_THREAD_DETACH: 15 | case DLL_PROCESS_DETACH: 16 | break; 17 | } 18 | return TRUE; 19 | } 20 | 21 | HRESULT WINAPI GetScaleFactorForMonitor 22 | ( IN HMONITOR hMon, 23 | OUT DEVICE_SCALE_FACTOR *pScale) 24 | { 25 | HDC hDC; 26 | INT index; 27 | hDC = GetDC(NULL); 28 | index = GetDeviceCaps(hDC, LOGPIXELSX); 29 | *pScale = (DEVICE_SCALE_FACTOR)((96/index) * 100); 30 | return S_OK; 31 | } 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by verinfo.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1/verinfo.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/win32ss/win32-api-reversals/f380a0c9e7a8ae07f4afa514884b60510c75ccf4/windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1/verinfo.aps -------------------------------------------------------------------------------- /windows8/api-ms-win-shcore-scaling-l1-1-1/api-ms-win-shcore-scaling-l1-1-1/verinfo.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (Canada) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENC) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_CAN 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""afxres.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Version 53 | // 54 | 55 | VS_VERSION_INFO VERSIONINFO 56 | FILEVERSION 6,0,6004,4006 57 | PRODUCTVERSION 6,0,6004,4006 58 | FILEFLAGSMASK 0x17L 59 | #ifdef _DEBUG 60 | FILEFLAGS 0x1L 61 | #else 62 | FILEFLAGS 0x0L 63 | #endif 64 | FILEOS 0x4L 65 | FILETYPE 0x2L 66 | FILESUBTYPE 0x0L 67 | BEGIN 68 | BLOCK "StringFileInfo" 69 | BEGIN 70 | BLOCK "100904b0" 71 | BEGIN 72 | VALUE "FileDescription", "api-ms-win-shcore-scaling-l1-1-1.dll Stub" 73 | VALUE "FileVersion", "6, 0, 6004, 4006" 74 | VALUE "InternalName", "api-ms-win-shcore-scaling-l1-1-1.dll" 75 | VALUE "LegalCopyright", "win32" 76 | VALUE "OriginalFilename", "api-ms-win-shcore-scaling-l1-1-1.dll" 77 | VALUE "ProductName", "Vista Extended Kernel-derived API Stubs" 78 | VALUE "ProductVersion", "6, 0, 6004, 4006" 79 | END 80 | END 81 | BLOCK "VarFileInfo" 82 | BEGIN 83 | VALUE "Translation", 0x1009, 1200 84 | END 85 | END 86 | 87 | #endif // English (Canada) resources 88 | ///////////////////////////////////////////////////////////////////////////// 89 | 90 | 91 | 92 | #ifndef APSTUDIO_INVOKED 93 | ///////////////////////////////////////////////////////////////////////////// 94 | // 95 | // Generated from the TEXTINCLUDE 3 resource. 96 | // 97 | 98 | 99 | ///////////////////////////////////////////////////////////////////////////// 100 | #endif // not APSTUDIO_INVOKED 101 | 102 | -------------------------------------------------------------------------------- /windows8/createfile2.c: -------------------------------------------------------------------------------- 1 | HANDLE CreateFile2(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, LPCREATEFILE2_EXTENDED_PARAMETERS pCreateExParams) 2 | /* 3 | win32 - March 17 2022 4 | Tonight, I noticed UserBenchmark calling this function from Windows 8, even though I spoofed it to Windows 7. So this might be useful on those OSes too. 5 | 6 | I'm not sure what the point is of this function; the documentation page only lists changes specific to UWP, and a few extra flags which CreateFileW may be 7 | able to use on later OSes. 8 | 9 | */ 10 | { 11 | if(!pCreateExParams) 12 | return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL); 13 | 14 | return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, pCreateExParams->lpSecurityAttributes, dwCreationDisposition, pCreateExParams->dwFileAttributes | pCreateExParams->dwFileFlags | pCreateExParams->dwSecurityQosFlags, pCreateExParams->hTemplateFile); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /windows8/getcurrentthreadstacklimits.c: -------------------------------------------------------------------------------- 1 | void WINAPI GetCurrentThreadStackLimits(PULONG_PTR LowLimit, PULONG_PTR HighLimit) 2 | // used by latest TBB runtime. 3 | { 4 | *LowLimit = NtCurrentTeb()->DeallocationStack; 5 | *HighLimit = NtCurrentTeb()->NtTib.StackBase; 6 | } -------------------------------------------------------------------------------- /windows8/mtausage.c: -------------------------------------------------------------------------------- 1 | typedef struct _MTA_USAGE_INCREMENTOR 2 | { 3 | ULONG ulTime; 4 | DWORD dwThreadId; 5 | }MTA_USAGE_INCREMENTOR, *PMTA_USAGE_INCREMENTOR; // This struct came from the public symbol for combase. 6 | // Very little information or none at all is stripped from the symbol, including TEB data. 7 | 8 | DWORD MTAThreadToRemove = 0; 9 | 10 | void CreateMTAUsageThread() 11 | // Suggestion to self: implement mutex object and use WaitForSingleObject instead. 12 | // But this does not seem necessary at this time. 13 | { 14 | DWORD Tid; 15 | CoInitializeEx(NULL, 0); 16 | Tid = GetCurrentThreadId(); 17 | while(MTAThreadToRemove != Tid) 18 | Sleep(1); // Sleep(0) is equivalent to taking your CPU hostage when it is unnecessary 19 | MTAThreadToRemove = 0; 20 | CoUninitialize(); 21 | } 22 | 23 | HRESULT WINAPI CoIncrementMTAUsage(CO_MTA_USAGE_COOKIE *pCookie) 24 | /* 25 | My earlier drafts of this function did not create a thread, but used internal functions and incremented 26 | a global value in ole32.dll. Those are not suitable for wrappers. 27 | 28 | As the main intent of this function is to keep MTA alive when no MTA threads are running, the function 29 | creates a thread that initializes a MTA then suspends immediately. The thread is resumed by a calloc 30 | to CoDecrementMTAUsage. 31 | */ 32 | { 33 | PMTA_USAGE_INCREMENTOR MTAIncrementor; 34 | DWORD ThreadId; 35 | MTAIncrementor = CoTaskMemAlloc(sizeof(MTA_USAGE_INCREMENTOR)); 36 | CreateThread(NULL, 0, CreateMTAUsageThread, 0, 0, &ThreadId); 37 | MTAIncrementor->dwThreadId = ThreadId; 38 | MTAIncrementor->ulTime = GetTickCount(); 39 | 40 | *pCookie = MTAIncrementor; 41 | 42 | return S_OK; 43 | } 44 | 45 | HRESULT WINAPI CoDecrementMTAUsageAlt(CO_MTA_USAGE_COOKIE *pCookie) 46 | { 47 | PMTA_USAGE_INCREMENTOR MTAIncrementor; 48 | if(pCookie) 49 | { 50 | MTAIncrementor = *pCookie; 51 | MTAThreadToRemove = MTAIncrementor->dwThreadId; 52 | 53 | CoTaskMemFree(*pCookie); 54 | return S_OK; 55 | } 56 | else 57 | return E_INVALIDARG; 58 | } 59 | -------------------------------------------------------------------------------- /windows8/pointingdeviceapi.c: -------------------------------------------------------------------------------- 1 | BOOL WINAPI GetPointerType(UINT32 pointerId, POINTER_INPUT_TYPE *pointerType) 2 | /* 3 | It seems that pointerIds are registered in a kernel mode struct that 4 | Vista likely does not have. 5 | */ 6 | { 7 | if(!pointerType || !pointerId || pointerId > 0xFF) 8 | { 9 | SetLastError(ERROR_INVALID_PARAMETER); 10 | return FALSE; 11 | } 12 | 13 | if(pointerId == 1) 14 | *pointerType = PT_MOUSE; 15 | 16 | return TRUE; 17 | } 18 | 19 | BOOL WINAPI GetPointerFrameTouchInfo(UINT32 pointerId, UINT32 *pointerCount, POINTER_TOUCH_INFO *touchInfo) 20 | { 21 | SetLastError(ERROR_DATATYPE_MISMATCH); 22 | return FALSE; 23 | } 24 | 25 | BOOL WINAPI GetPointerFrameTouchInfoHistory(UINT32 pointerId, UINT32 *entriesCount, UINT32 *pointerCount, POINTER_TOUCH_INFO *touchInfo) 26 | { 27 | SetLastError(ERROR_DATATYPE_MISMATCH); 28 | return FALSE; 29 | } 30 | 31 | BOOL WINAPI GetPointerPenInfo(UINT32 pointerId, POINTER_PEN_INFO *penInfo) 32 | { 33 | SetLastError(ERROR_DATATYPE_MISMATCH); 34 | return FALSE; 35 | } 36 | 37 | BOOL WINAPI GetPointerPenInfoHistory(UINT32 pointerId, UINT32 *entriesCount, POINTER_PEN_INFO *penInfo) 38 | { 39 | SetLastError(ERROR_DATATYPE_MISMATCH); 40 | return FALSE; 41 | } 42 | 43 | BOOL SkipPointerFrameMessages(UINT32 pointerId) 44 | { 45 | return TRUE; 46 | } 47 | 48 | BOOL GetPointerDeviceRects(HANDLE device, RECT *pointerDeviceRect, RECT *displayRect) 49 | { 50 | if(!device || !pointerDeviceRect || !displayRect) 51 | { 52 | SetLastError(ERROR_INVALID_PARAMETER); 53 | return FALSE; 54 | } 55 | 56 | pointerDeviceRect->top = GetSystemMetrics(SM_YVIRTUALSCREEN); 57 | pointerDeviceRect->left = GetSystemMetrics(SM_XVIRTUALSCREEN); 58 | pointerDeviceRect->right = GetSystemMetrics(SM_CXVIRTUALSCREEN); 59 | pointerDeviceRect->bottom = GetSystemMetrics(SM_CYVIRTUALSCREEN); 60 | 61 | displayRect = pointerDeviceRect; 62 | 63 | return TRUE; 64 | } -------------------------------------------------------------------------------- /windows8/setdefaultdlldirectories.c: -------------------------------------------------------------------------------- 1 | /* win32 - November 16 2021 2 | A function implemented in Windows 8, but was added to Windows Vista and 7 in a security update in 2013. 3 | Used by applications to restrict the possible range of directories from which they can load DLLs. 4 | Windows Vista's implementation has an indirect bug where loading of UXTHEME can be blocked entirely, 5 | giving applications such as VLC a completely unthemed appearance, even affecting its common control dialogs. 6 | 7 | Later implementations move the guts of this function to ntdll, where LdrLoadDll evaluates the BaseDefaultDllDirectories variable instead. */ 8 | 9 | 10 | BOOL WINAPI SetDefaultDllDirectories(DWORD DirectoryFlags) 11 | { 12 | 13 | if ( !DirectoryFlags || (DirectoryFlags & 0xFFFFE0FF) != 0 ) 14 | { 15 | BaseSetLastNTError(E_INVALID_ARGS); 16 | return FALSE; 17 | } 18 | else 19 | { 20 | if ( (DirectoryFlags & LOAD_LIBRARY_SEARCH_APPLICATION_DIR) != 0 21 | && (DirectoryFlags & LOAD_LIBRARY_SEARCH_USER_DIRS) != 0 22 | && (DirectoryFlags & LOAD_LIBRARY_SEARCH_SYSTEM32) != 0 23 | && (DirectoryFlags & 0x100) == 0 ) /* This value is undocumented. But upon evaluation of LoadLibraryExW, it seems to be 24 | a secondary method of enforcing the flag LOAD_WITH_ALTERED_SEARCH_PATH if 25 | it is not set in LoadLibraryExW. */ 26 | { 27 | DirectoryFlags = LOAD_LIBRARY_SEARCH_DEFAULT_DIRS; 28 | } 29 | BaseDefaultDllDirectories = DirectoryFlags; // BaseDefaultDllDirectories is a global variable read by LoadLibraryExW 30 | return TRUE; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /windows8/systemtime.c: -------------------------------------------------------------------------------- 1 | void WINAPI GetSystemTimePreciseAsFileTime(LPFILETIME lpSystemTimeAsFileTime) 2 | { 3 | LARGE_INTEGER Time; 4 | LARGE_INTEGER Time2; 5 | 6 | GetSystemTimeAsFileTime(lpSystemTimeAsFileTime); 7 | 8 | QueryPerformanceCounter(&Time); 9 | 10 | QueryPerformanceCounter(&Time2); 11 | 12 | lpSystemTimeAsFileTime->dwLowDateTime += (Time2.u.LowPart - Time.u.LowPart); 13 | lpSystemTimeAsFileTime->dwHighDateTime += (Time2.u.HighPart - Time.u.HighPart); 14 | } --------------------------------------------------------------------------------