Advertisement
ya_makaron

export table

Apr 27th, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. DWORD get_code_cave(DWORD mem)
  9. {
  10.     DWORD counter = 0;
  11.     for (DWORD i = (DWORD)GetModuleHandleA("Kernel32.dll") + 0x1000; ; i++)
  12.     {
  13.         byte byte_buf;
  14.         if (ReadProcessMemory(GetCurrentProcess(), (void*)i, &byte_buf, 1, 0))
  15.         {
  16.             if (byte_buf == 0x0)
  17.                 counter++;
  18.             else counter = 0;
  19.  
  20.             if (counter == mem)
  21.                 return i - counter + 1;
  22.         }
  23.     }
  24.     return 0;
  25. }
  26.  
  27. int main()
  28. {
  29.     DWORD dll_addr = (DWORD)GetModuleHandleA("ntdll.dll");
  30.     DWORD p = dll_addr + *(DWORD*)(dll_addr + 0x3C);
  31.     DWORD *pDATA_DIRECTORY = (DWORD*)(p + 0x78);
  32.     DWORD pExport = pDATA_DIRECTORY[0] + dll_addr;
  33.     DWORD xExport = pDATA_DIRECTORY[1];
  34.     DWORD nameRVA = *(DWORD*)(pExport + 0xC) + dll_addr;
  35.     DWORD ordinalBASE = *(DWORD*)(pExport + 0x10);
  36.     DWORD addressTableEntries = *(DWORD*)(pExport + 0x14);
  37.     DWORD numberOfNamePointers = *(DWORD*)(pExport + 0x18);
  38.     DWORD *exportAddressTableRVA = (DWORD*)(*(DWORD*)(pExport + 0x1C) + dll_addr);
  39.     DWORD *namePointerRVA = (DWORD*)(*(DWORD*)(pExport + 0x20) + dll_addr);
  40.     WORD *ordinalTableRVA = (WORD*)(*(DWORD*)(pExport + 0x24) + dll_addr);
  41.     DWORD f_index, f_address, ordinal;
  42.     char *pForward;
  43.  
  44.     //cout << addressTableEntries << endl;
  45.     //cout << numberOfNamePointers << endl;
  46.  
  47.     for (DWORD i = 0; i < addressTableEntries && i < numberOfNamePointers; i++)
  48.     {
  49.         f_index = ordinalTableRVA[i];
  50.         f_address = exportAddressTableRVA[f_index] + dll_addr;
  51.         if (f_address == dll_addr) continue;
  52.         ordinal = f_index + ordinalBASE;
  53.         if (f_address > pExport && f_address < (pExport + xExport))
  54.             pForward = (char*)f_address;
  55.         else pForward = 0;
  56.  
  57.         printf("%s [%d/%d] 0x%X %s\n", (char*)(namePointerRVA[i] + dll_addr), ordinal, i, f_address, pForward);
  58.     }
  59.  
  60.     printf("place: 0x%X", get_code_cave(0x30));
  61.  
  62.     _getch();
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement