Advertisement
Guest User

Untitled

a guest
May 10th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1.  
  2. #include <windows.h>
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7. // I manually enter pid at this time for this experimental code.
  8. int pid = 5428;
  9.  
  10. HANDLE process_handle = OpenProcess(
  11. PROCESS_ALL_ACCESS,
  12. FALSE,
  13. pid);
  14.  
  15.  
  16. // the values whose address are to be found by this code.
  17. int Val = 12345;
  18.  
  19. char* p = NULL;
  20. int* q;
  21. int v;
  22.  
  23. DWORD dwStart = 0, i;
  24. SIZE_T lpRead;
  25. SYSTEM_INFO si;
  26. MEMORY_BASIC_INFORMATION mbi;
  27. DWORD MinAddr, MaxAddr;
  28. DWORD lpBase;
  29. DWORD Size = sizeof(int);
  30.  
  31. // Get Application Min And Max Value
  32. GetSystemInfo(&si);
  33. MinAddr = (DWORD)si.lpMinimumApplicationAddress;
  34. MaxAddr = (DWORD)si.lpMaximumApplicationAddress;
  35. // printf("MinAddr : %p\n", MinAddr);
  36. // printf("MaxAddr : %p\n", MaxAddr);
  37. dwStart = MinAddr;
  38.  
  39. puts("Begin");
  40.  
  41. while(1){
  42. if (VirtualQueryEx( process_handle,(void *)dwStart,&mbi,sizeof(MEMORY_BASIC_INFORMATION) == 0))
  43. {
  44. printf("VirtualQueryEx failed.");
  45. }
  46.  
  47.  
  48.  
  49. if(dwStart + mbi.RegionSize < dwStart)
  50. {
  51. //printf("Break. \n");
  52. break;
  53.  
  54. }
  55.  
  56. //printf("This region has the size of: %p \n", (int)mbi.RegionSize);
  57.  
  58. if(mbi.State != MEM_COMMIT) {
  59. dwStart+=mbi.RegionSize;
  60. //printf("Continue. \n");
  61. continue;
  62.  
  63. }
  64.  
  65.  
  66.  
  67. for(i=dwStart; i<dwStart+mbi.RegionSize; i+= Size) // i+= Size
  68. {
  69. //printf("It got to readprocess memory. \n");
  70.  
  71. if(ReadProcessMemory(process_handle, (LPVOID)i, &v, Size, NULL) != 0) // &lpRead
  72. {
  73. printf("Val = %d \n", Val);
  74. if (v==Val)
  75. {
  76. //Address[AddCnt++] = i;
  77. //printf("Found one: %p\n",i);
  78. printf("Found one.");
  79. }
  80. }
  81. else
  82. {
  83. printf("ReadProcessMemory has an error. \n");
  84. }
  85. }
  86.  
  87. dwStart+=mbi.RegionSize;
  88. }
  89.  
  90. puts("End");
  91.  
  92. system("pause");
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement