Advertisement
waliedassar

MemoryBasicVlmInformation (Extract SizeOfImage From Kernel)

Sep 9th, 2012
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. //http://waleedassar.blogspot.com - (@waleedassar)
  2. //This code shows how to extract the "SizeOfImage" value of a process directly from the kernel.
  3. //The "SizeOfImage" value has always been used by anti-dumping trick to defeat dumping tools.
  4. //Useful if you are trying to design your dumping tool.
  5. #include "stdafx.h"
  6. #include "windows.h"
  7.  
  8. #pragma data_seg("walied4")
  9. int x=1;
  10. #pragma data_seg()
  11.  
  12. #define MemoryBasicVlmInformation 0x3
  13.  
  14. struct MEMORY_BASIC_VLM_INFORMATION
  15. {
  16.     unsigned long ImageBase;
  17.     unsigned long blah[0x2];
  18.     unsigned long SizeOfImage;
  19. };
  20.  
  21. extern "C"
  22. {
  23.     int __stdcall ZwQueryVirtualMemory(HANDLE,void*,int,void*,int,unsigned long*);
  24. }
  25.  
  26. int main(int argc, char* argv[])
  27. {
  28.     unsigned long out=0;
  29.     MEMORY_BASIC_VLM_INFORMATION MBVI={0};
  30.     ZwQueryVirtualMemory(GetCurrentProcess(),&x /*anywhere withing the PE range*/,MemoryBasicVlmInformation,&MBVI,sizeof(MBVI),&out);
  31.     unsigned long szImage=MBVI.SizeOfImage;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement