Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3.  
  4. using std::cout;
  5. using std::endl;
  6.  
  7. #define FILENAME "gibrish.bin"
  8. HANDLE WINAPI Mutex;
  9.  
  10. int main(void)
  11. {
  12. WCHAR param[4];
  13. LPWSTR pParam = param;
  14. STARTUPINFO si;
  15. PROCESS_INFORMATION pi;
  16.  
  17. HANDLE hFile;
  18. HANDLE hMapFile;
  19. LPSTR pBuf;
  20. CHAR file_name[] = FILENAME;
  21. LPCSTR pFileName = file_name;
  22.  
  23. SYSTEM_INFO sys_info;
  24. GetSystemInfo(&sys_info);
  25. int mem_buffer_size = sys_info.dwAllocationGranularity;
  26.  
  27. hFile = CreateFile(
  28. pFileName, // file name
  29. (GENERIC_READ | GENERIC_WRITE), // access type
  30. FILE_SHARE_WRITE, // other processes can share
  31. NULL, // security
  32. OPEN_EXISTING, // open only if file exists
  33. FILE_ATTRIBUTE_NORMAL,
  34. NULL);
  35.  
  36. hMapFile = CreateFileMapping(
  37. INVALID_HANDLE_VALUE,
  38. NULL, // default security
  39. PAGE_READWRITE, // readwrite access
  40. 0, // maximum object size (high-order DWORD)
  41. mem_buffer_size, // maximum object size (low-order DWORD)
  42. // 0 means map the whole file
  43. "mapObj");
  44.  
  45. pBuf = (LPSTR)MapViewOfFile(
  46. hMapFile, // handle to map object
  47. FILE_MAP_ALL_ACCESS, // read/write permission
  48. 0, // start point (upper word)
  49. 0, // start point (lower word)
  50. mem_buffer_size); // how many bytes to read
  51.  
  52.  
  53. swprintf_s(param, 4, L" %d", 2);
  54. ZeroMemory(&si, sizeof(si));
  55. si.cb = sizeof(si);
  56. ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
  57.  
  58. if (!CreateProcessA(
  59. "Process2.exe",
  60. NULL,
  61. NULL,
  62. NULL,
  63. TRUE,
  64. 0,
  65. NULL,
  66. NULL,
  67. &si,
  68. &pi))
  69. {
  70. std::cerr << GetLastError();
  71. return 1;
  72. }
  73.  
  74. WaitForSingleObject(pi.hProcess, INFINITE);
  75.  
  76. UnmapViewOfFile(pBuf);
  77.  
  78. CloseHandle(pi.hProcess);
  79. CloseHandle(pi.hThread);
  80.  
  81.  
  82. CloseHandle(hMapFile);
  83. CloseHandle(hFile);
  84.  
  85. system("pause");
  86. return 0;
  87. }
  88.  
  89. #pragma comment(lib, "user32.lib")
  90. #include <iostream>
  91. #include <Windows.h>
  92.  
  93. using std::cout;
  94. using std::endl;
  95.  
  96.  
  97. int main(void)
  98. {
  99. HANDLE hMapFile;
  100. LPSTR pBuf;
  101.  
  102. SYSTEM_INFO sys_info;
  103. GetSystemInfo(&sys_info);
  104. int mem_buffer_size = sys_info.dwAllocationGranularity;
  105.  
  106.  
  107. hMapFile = OpenFileMapping(
  108. FILE_MAP_ALL_ACCESS,
  109. FALSE,
  110. "mapObj"
  111. );
  112.  
  113. pBuf = (LPSTR)MapViewOfFile(
  114. hMapFile,
  115. FILE_MAP_ALL_ACCESS,
  116. 0,
  117. 0,
  118. mem_buffer_size
  119. );
  120.  
  121. pBuf[0] = 'Z';
  122. cout << pBuf[0] << endl;
  123.  
  124. UnmapViewOfFile(pBuf);
  125. CloseHandle(hMapFile);
  126. system("pause");
  127. return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement