Advertisement
Guest User

ASLRTest.cpp

a guest
Nov 2nd, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. // ASLRTest.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include <Windows.h>
  7.  
  8. DWORD heapAdr=0x12345678;
  9.  
  10. int _tmain(int argc, _TCHAR* argv[])
  11. {
  12.     FILE* fpLog;
  13.     BOOL newFile=FALSE;
  14.     char stackBuf[512];
  15.     static char staticHeapBuf[512];
  16.     char* crtHeap;
  17.     char* virtualAllocHeap;
  18.     char* heapAllocHeap;
  19.     char* heapAllocSecondHeap;
  20.     HANDLE hHeap;
  21.  
  22.     fpLog=fopen("aslr.log", "r");
  23.     if(!fpLog)
  24.         newFile=TRUE;
  25.     else
  26.         fclose(fpLog);
  27.  
  28.     fpLog=fopen("aslr.log", "a");
  29.     if(!fpLog)
  30.     {
  31.         printf("Error opening aslr.log for appending.\n");
  32.         return 1;
  33.     }
  34.    
  35.     if(newFile)
  36.         fprintf(fpLog, "Stack;Static Heap;C Runtime Heap(malloc);Heap (VirtualAlloc);Heap (HeapAlloc default heap);Heap (HeapAlloc additional Heap)\n");
  37.    
  38.     crtHeap=(char*) malloc(4096);
  39.     virtualAllocHeap=(char*) VirtualAlloc(NULL, 4096, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
  40.     heapAllocHeap=(char*) HeapAlloc(GetProcessHeap(), 0, 4096);
  41.     hHeap=HeapCreate(0, 4096, 32768);
  42.     heapAllocSecondHeap=(char*) HeapAlloc(hHeap, 0, 4096);
  43.  
  44.     // Write adresses to log
  45.     fprintf(fpLog, "0x%x;0x%x;0x%x;0x%x;0x%x;0x%x\n", &stackBuf[0], &staticHeapBuf[0], crtHeap, virtualAllocHeap, heapAllocHeap, heapAllocSecondHeap);
  46.  
  47.     fclose(fpLog);
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement