Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <strsafe.h>
  4. #include <winternl.h>
  5. #include <wingdi.h>
  6. #include <Psapi.h>
  7.  
  8. typedef enum { L_DEBUG, L_INFO, L_WARN, L_ERROR } LEVEL, *PLEVEL;
  9. #define MAX_LOG_MESSAGE 1024
  10. void hexdump(void *mem, unsigned int len);
  11. BOOL LogMessage(LEVEL Level, LPCTSTR Format, ...);
  12. #pragma comment(lib, "psapi.lib")
  13. #pragma comment(lib,"user32.lib")
  14. #pragma comment(lib,"Gdi32.lib")
  15. #pragma comment(lib, "ntdll.lib")
  16.  
  17. typedef DWORD (NTAPI *_NtUserSetWindowFNID)
  18. (
  19. HWND,
  20. LONG
  21. );
  22. _NtUserSetWindowFNID NtUserSetWindowFNID ;
  23. LONG MenuWindowProc;
  24. static LRESULT CALLBACK
  25. xxWindowHookProc(INT code, WPARAM wParam, LPARAM lParam){
  26. PCWPSTRUCT pcwp=(PCWPSTRUCT)lParam;
  27.  
  28. HWND hTarget=NULL;
  29. if (pcwp->message == WM_NCCREATE)
  30. {
  31. if (hTarget == NULL)
  32. {
  33. hTarget = pcwp->hwnd;
  34. SetWindowLongPtrA(pcwp->hwnd, GWLP_WNDPROC, MenuWindowProc);
  35. for (int i=0; i <400;++i){
  36. SetWindowLongPtrA(hTarget, i, 0x22);
  37. }
  38. }
  39. }
  40.  
  41. return CallNextHookEx(0,code,wParam,lParam);
  42.  
  43. }
  44.  
  45. void Stage0()
  46. {
  47. HMODULE user32 = LoadLibraryA("user32.dll");
  48. MenuWindowProc=(LONG)(GetProcAddress(user32,"MenuWindowProcW"));
  49. LogMessage(L_INFO,"MenuWindowProc %x",MenuWindowProc);
  50.  
  51. WNDCLASSA cls;
  52. cls.style=0;
  53. cls.lpfnWndProc=DefWindowProcW;
  54. cls.cbWndExtra=0x1000;
  55. cls.cbClsExtra=0;
  56. cls.hInstance=GetModuleHandleA(NULL);
  57. cls.hIcon = NULL;
  58. cls.hCursor = LoadCursor(0, IDC_ARROW);
  59. cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  60. cls.lpszMenuName = NULL;
  61. cls.lpszClassName = "MyWinClass";
  62. if (RegisterClassA(&cls)==NULL){
  63. LogMessage(L_ERROR,"FAILED");
  64. return ;
  65. }
  66. SetWindowsHookExA(WH_CALLWNDPROC,xxWindowHookProc,GetModuleHandleA(NULL), GetCurrentThreadId());
  67.  
  68. HWND h=CreateWindowExA(0,"MyWinClass","MyWindow",0,0,0,100,100,NULL,NULL,GetModuleHandleA(NULL),NULL);
  69. LogMessage(L_INFO,"Hwnd %x",h);
  70.  
  71. DestroyWindow(h);
  72. }
  73. void main()
  74. {
  75. LogMessage(L_INFO,TEXT("Stage 0: test"));
  76. Stage0();
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. #ifndef HEXDUMP_COLS
  85. #define HEXDUMP_COLS 16
  86. #endif
  87.  
  88. void hexdump(void *mem, unsigned int len)
  89. {
  90. unsigned int i, j;
  91.  
  92. for(i = 0; i < len + ((len % HEXDUMP_COLS) ? (HEXDUMP_COLS - len % HEXDUMP_COLS) : 0); i++)
  93. {
  94. /* print offset */
  95. if(i % HEXDUMP_COLS == 0)
  96. {
  97. printf("0x%06x: ", i);
  98. }
  99.  
  100. /* print hex data */
  101. if(i < len)
  102. {
  103. printf("%02x ", 0xFF & ((char*)mem)[i]);
  104. }
  105. else /* end of block, just aligning for ASCII dump */
  106. {
  107. printf(" ");
  108. }
  109.  
  110. /* print ASCII dump */
  111. if(i % HEXDUMP_COLS == (HEXDUMP_COLS - 1))
  112. {
  113. for(j = i - (HEXDUMP_COLS - 1); j <= i; j++)
  114. {
  115. if(j >= len) /* end of block, not really printing */
  116. {
  117. putchar(' ');
  118. }
  119. else if(isprint(((char*)mem)[j])) /* printable char */
  120. {
  121. putchar(0xFF & ((char*)mem)[j]);
  122. }
  123. else /* other char */
  124. {
  125. putchar('.');
  126. }
  127. }
  128. putchar('\n');
  129. }
  130. }
  131. }
  132. BOOL LogMessage(LEVEL Level, LPCTSTR Format, ...)
  133. {
  134. TCHAR Buffer[MAX_LOG_MESSAGE] = { 0 };
  135. va_list Args;
  136.  
  137. va_start(Args, Format);
  138. StringCchVPrintf(Buffer, MAX_LOG_MESSAGE, Format, Args);
  139. va_end(Args);
  140.  
  141. switch (Level) {
  142. case L_DEBUG: _ftprintf(stdout, TEXT("[?] %s\n"), Buffer); break;
  143. case L_INFO: _ftprintf(stdout, TEXT("[+] %s\n"), Buffer); break;
  144. case L_WARN: _ftprintf(stderr, TEXT("[*] %s\n"), Buffer); break;
  145. case L_ERROR: _ftprintf(stderr, TEXT("[!] %s\n"), Buffer); break;
  146. }
  147.  
  148. fflush(stdout);
  149. fflush(stderr);
  150.  
  151. return TRUE;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement