Хидеры

Тема в разделе "WASM.WIN32", создана пользователем RamMerLabs, 11 авг 2007.

  1. RamMerLabs

    RamMerLabs Well-Known Member

    Публикаций:
    0
    Регистрация:
    11 сен 2006
    Сообщения:
    1.426
    Доброго времени суток!

    Так получилось, что я остался без SDK и DDK, но срочно нужно скомпилить следующий сорс:

    Код (Text):
    1. #define WIN32_LEAN_AND_MEAN
    2. #include "ntdll.h"
    3. #include <tlhelp32.h>
    4. #include <stdlib.h>
    5. #include <stdio.h>
    6. struct ENTRIES {
    7.  ULONG Offset;
    8.  ULONG Count;
    9.  ULONG Index;
    10.  ENTRIES() : Offset(0), Count(0), Index(0) {}
    11.  ENTRIES(ULONG m, ULONG n) : Offset(m), Count(n), Index(0) {}
    12. };
    13. enum EntryType {
    14.  ProcessType,
    15.  ThreadType,
    16.  ModuleType,
    17.  HeapType,
    18.  MaxType
    19. };
    20.  
    21. NT::PSYSTEM_PROCESSES GetProcessesAndThreads()
    22. {
    23.  ULONG n = 0x100;
    24.  NT::PSYSTEM_PROCESSES sp = new NT::SYSTEM_PROCESSES[n];
    25.  while (NT::ZwQuerySystemInformation(NT::SystemProcessesAndThreadsInformation, sp, n * sizeof *sp, 0) == STATUS_INFO_LENGTH_MISMATCH)
    26.   delete [] sp, sp = new NT::SYSTEM_PROCESSES[n = n * 2];
    27.  return sp;
    28. }
    29.  
    30. NT::PDEBUG_BUFFER GetModulesAndHeaps(ULONG pid, ULONG mask)
    31. {
    32.  NT::PDEBUG_BUFFER db = NT::RtlCreateQueryDebugBuffer(0, FALSE);
    33.  NT::RtlQueryProcessDebugInformation(pid, mask, db);
    34.  return db;
    35. }
    36.  
    37. ULONG ProcessCount(NT::PSYSTEM_PROCESSES sp)
    38. {
    39.  ULONG n = 0;
    40.  bool done = false;
    41.  for (NT::PSYSTEM_PROCESSES p = sp; !done; p = NT::PSYSTEM_PROCESSES(PCHAR(p) + p->NextEntryDelta))
    42.   n++, done = p->NextEntryDelta == 0;
    43.  return n;
    44. }
    45.  
    46. ULONG ThreadCount(NT::PSYSTEM_PROCESSES sp)
    47. {
    48.  ULONG n = 0;
    49.  bool done = false;
    50.  for (NT::PSYSTEM_PROCESSES p = sp; !done; p = NT::PSYSTEM_PROCESSES(PCHAR(p) + p->NextEntryDelta))
    51.   n += p->ThreadCount, done = p->NextEntryDelta == 0;
    52.  return n;
    53. }
    54.  
    55. ULONG ModuleCount(NT::PDEBUG_BUFFER db)
    56. {
    57.  return db->ModuleInformation ? *PULONG(db->ModuleInformation) : 0;
    58. }
    59.  
    60. ULONG HeapCount(NT::PDEBUG_BUFFER db)
    61. {
    62.  return db->HeapInformation ? *PULONG(db->HeapInformation) : 0;
    63. }
    64.  
    65. VOID AddProcesses(PPROCESSENTRY32 pe, NT::PSYSTEM_PROCESSES sp)
    66. {
    67.  bool done = false;
    68.  for (NT::PSYSTEM_PROCESSES p = sp; !done; p = NT::PSYSTEM_PROCESSES(PCHAR(p) + p->NextEntryDelta)) {
    69.   pe->dwSize = sizeof *pe;
    70.   pe->cntUsage = 0;
    71.   pe->th32ProcessID = p->ProcessId;
    72.   pe->th32DefaultHeapID = 0;
    73.   pe->th32ModuleID = 0;
    74.   pe->cntThreads = p->ThreadCount;
    75.   pe->th32ParentProcessID = p->InheritedFromProcessId;
    76.   pe->pcPriClassBase = p->BasePriority;
    77.   pe->dwFlags = 0;
    78.   sprintf(pe->szExeFile, “%.*ls”,
    79.   p->ProcessName.Length / 2, p->ProcessName.Buffer);
    80.   pe++;
    81.   done = p->NextEntryDelta == 0;
    82.  }
    83. }
    84.  
    85. VOID AddThreads(PTHREADENTRY32 te, NT::PSYSTEM_PROCESSES sp)
    86. {
    87.  bool done = false;
    88.  for (NT::PSYSTEM_PROCESSES p = sp; !done; p = NT::PSYSTEM_PROCESSES(PCHAR(p) + p->NextEntryDelta)) {
    89.   for (ULONG i = 0; i < p->ThreadCount; i++) {
    90.    te->dwSize = sizeof *te;
    91.    te->cntUsage = 0;
    92.    te->th32ThreadID = DWORD(p->Threads[i].ClientId.UniqueThread);
    93.    te->th32OwnerProcessID = p->ProcessId;
    94.    te->tpBasePri = p->Threads[i].BasePriority;
    95.    te->tpDeltaPri = p->Threads[i].Priority - p->Threads[i].BasePriority;
    96.    te->dwFlags = 0;
    97.    te++;
    98.   }
    99.   done = p->NextEntryDelta == 0;
    100.  }
    101. }
    102.  
    103. VOID AddModules(PMODULEENTRY32 me, NT::PDEBUG_BUFFER db, ULONG pid)
    104. {
    105.  ULONG n = ModuleCount(db);
    106.  NT::PDEBUG_MODULE_INFORMATION p = NT::PDEBUG_MODULE_INFORMATION(PULONG(db->ModuleInformation) + 1);
    107.  for (ULONG i = 0; i < n; i++) {
    108.   me->dwSize = sizeof *me;
    109.   me->th32ModuleID = 0;
    110.   me->th32ProcessID = pid;
    111.   me->GlblcntUsage = p[i].LoadCount;
    112.   me->ProccntUsage = p[i].LoadCount;
    113.   me->modBaseAddr = PBYTE(p[i].Base);
    114.   me->modBaseSize = p[i].Size;
    115.   me->hModule = HMODULE(p[i].Base);
    116.   sprintf(me->szModule, “%s”, p[i].ImageName + p[i].ModuleNameOffset);
    117.   sprintf(me->szExePath, “%s”, p[i].ImageName);
    118.   me++;
    119.  }
    120. }
    121.  
    122. VOID AddHeaps(PHEAPLIST32 hl, NT::PDEBUG_BUFFER db, ULONG pid)
    123. {
    124.  ULONG n = HeapCount(db);
    125.  NT::PDEBUG_HEAP_INFORMATION p = NT::PDEBUG_HEAP_INFORMATION(PULONG(db->HeapInformation) + 1);
    126.  for (ULONG i = 0; i < n; i++) {
    127.   hl->dwSize = sizeof *hl;
    128.   hl->th32ProcessID = pid;
    129.   hl->th32HeapID = p[i].Base;
    130.   hl->dwFlags = p[i].Flags;
    131.   hl++;
    132.  }
    133. }
    134.  
    135. template<class T>
    136.  
    137. BOOL GetEntry(HANDLE hSnapshot, T entry, bool first, EntryType type)
    138. {
    139.  ENTRIES *entries = (ENTRIES*)MapViewOfFile(hSnapshot, FILE_MAP_WRITE, 0, 0, 0);
    140.  if (entries == 0) return FALSE;
    141.  BOOL rv = TRUE;
    142.  entries[type].Index = first ? 0 : entries[type].Index + 1;
    143.  if (entries[type].Index >= entries[type].Count)
    144.   SetLastError(ERROR_NO_MORE_FILES), rv = FALSE;
    145.  if (entry->dwSize < sizeof *entry)
    146.   SetLastError(ERROR_INSUFFICIENT_BUFFER), rv = FALSE;
    147.  if (rv)
    148.   *entry = T(PCHAR(entries) + entries[type].Offset)[entries[type].Index];
    149.  UnmapViewOfFile(entries);
    150.  return rv;
    151. }
    152.  
    153. HANDLE WINAPI CreateToolhelp32Snapshot(DWORD flags, DWORD pid)
    154. {
    155.  if (pid == 0) pid = GetCurrentProcessId();
    156.  ULONG mask = ((flags & TH32CS_SNAPMODULE) ? PDI_MODULES : 0) | ((flags & TH32CS_SNAPHEAPLIST) ? PDI_HEAPS : 0);
    157.  NT::PDEBUG_BUFFER db = (flags & (TH32CS_SNAPMODULE | TH32CS_SNAPHEAPLIST)) ? GetModulesAndHeaps(pid, mask) : 0;
    158.  NT::PSYSTEM_PROCESSES sp = (flags & (TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD)) ? GetProcessesAndThreads() : 0;
    159.  ENTRIES entries[MaxType];
    160.  ULONG n = sizeof entries;
    161.  if (flags & TH32CS_SNAPPROCESS) {
    162.   entries[ProcessType] = ENTRIES(n, ProcessCount(sp));
    163.   n += entries[ProcessType].Count * sizeof (PROCESSENTRY32);
    164.  }
    165.  if (flags & TH32CS_SNAPTHREAD) {
    166.   entries[ThreadType] = ENTRIES(n, ThreadCount(sp));
    167.   n += entries[ThreadType].Count * sizeof (THREADENTRY32);
    168.  }
    169.  if (flags & TH32CS_SNAPMODULE) {
    170.   entries[ModuleType] = ENTRIES(n, ModuleCount(db));
    171.   n += entries[ModuleType].Count * sizeof (MODULEENTRY32);
    172.  }
    173.  if (flags & TH32CS_SNAPHEAPLIST) {
    174.   entries[HeapType] = ENTRIES(n, HeapCount(db));
    175.   n += entries[HeapType].Count * sizeof (HEAPLIST32);
    176.  }
    177.  SECURITY_ATTRIBUTES sa = {sizeof sa, 0, (flags & TH32CS_INHERIT) != 0};
    178.  HANDLE hMap = CreateFileMapping(HANDLE(0xFFFFFFFF), &sa, PAGE_READWRITE | SEC_COMMIT, 0, n, 0);
    179.  ENTRIES *p = (ENTRIES*)MapViewOfFile(hMap, FILE_MAP_WRITE, 0, 0, 0);
    180.  for (int i = 0; i < MaxType; i++) p[i] = entries[i];
    181.  if (flags & TH32CS_SNAPPROCESS)
    182.   AddProcesses(PPROCESSENTRY32(PCHAR(p) + entries[ProcessType].Offset), sp);
    183.  if (flags & TH32CS_SNAPTHREAD)
    184.   AddThreads(PTHREADENTRY32(PCHAR(p) + entries[ThreadType].Offset), sp);
    185.  if (flags & TH32CS_SNAPMODULE)
    186.   AddModules(PMODULEENTRY32(PCHAR(p) + entries[ModuleType].Offset), db, pid);
    187.  if (flags & TH32CS_SNAPHEAPLIST)
    188.   AddHeaps(PHEAPLIST32(PCHAR(p) + entries[HeapType].Offset), db, pid);
    189.  UnmapViewOfFile(p);
    190.  if (sp) delete [] sp;
    191.  if (db) NT::RtlDestroyQueryDebugBuffer(db);
    192.  return hMap;
    193. }
    194.  
    195. BOOL WINAPI Process32First(HANDLE hSnapshot, PPROCESSENTRY32 pe)
    196. {
    197.  return GetEntry(hSnapshot, pe, true, ProcessType);
    198. }
    199.  
    200. BOOL WINAPI Process32Next(HANDLE hSnapshot, PPROCESSENTRY32 pe)
    201. {
    202. return GetEntry(hSnapshot, pe, false, ProcessType);
    203. }
    204.  
    205. BOOL WINAPI Thread32First(HANDLE hSnapshot, PTHREADENTRY32 te)
    206. {
    207.  return GetEntry(hSnapshot, te, true, ThreadType);
    208. }
    209.  
    210. BOOL WINAPI Thread32Next(HANDLE hSnapshot, PTHREADENTRY32 te)
    211. {
    212.  return GetEntry(hSnapshot, te, false, ThreadType);
    213. }
    214.  
    215. BOOL WINAPI Module32First(HANDLE hSnapshot, PMODULEENTRY32 me)
    216. {
    217.  return GetEntry(hSnapshot, me, true, ModuleType);
    218. }
    219.  
    220. BOOL WINAPI Module32Next(HANDLE hSnapshot, PMODULEENTRY32 me)
    221. {
    222.  return GetEntry(hSnapshot, me, false, ModuleType);
    223. }
    224.  
    225. BOOL WINAPI Heap32ListFirst(HANDLE hSnapshot, PHEAPLIST32 hl)
    226. {
    227.  return GetEntry(hSnapshot, hl, true, HeapType);
    228. }
    229. BOOL WINAPI Heap32ListNext(HANDLE hSnapshot, PHEAPLIST32 hl)
    230. {
    231.  return GetEntry(hSnapshot, hl, false, HeapType);
    232. }
    233.  
    234. BOOL APIENTRY DllMain(HANDLE hModule, DWORD reason, LPVOID lpRes)
    235. {
    236.  return 1;
    237. }
    (это из Неббета)

    не мог бы кто-нибудь залить хидеры ntdll.h и входящте в него? или просто предоставить декларации констант, структур и функций, упоминающихся в этом коде.

    Заранее благодарю!
     
  2. y4eNick

    y4eNick New Member

    Публикаций:
    0
    Регистрация:
    17 фев 2007
    Сообщения:
    37
    Не знаю, подойдёт ли это.