Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- using std::cout;
- using std::endl;
- #define FILENAME "gibrish.bin"
- HANDLE WINAPI Mutex;
- int main(void)
- {
- WCHAR param[4];
- LPWSTR pParam = param;
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- HANDLE hFile;
- HANDLE hMapFile;
- LPSTR pBuf;
- CHAR file_name[] = FILENAME;
- LPCSTR pFileName = file_name;
- SYSTEM_INFO sys_info;
- GetSystemInfo(&sys_info);
- int mem_buffer_size = sys_info.dwAllocationGranularity;
- hFile = CreateFile(
- pFileName, // file name
- (GENERIC_READ | GENERIC_WRITE), // access type
- FILE_SHARE_WRITE, // other processes can share
- NULL, // security
- OPEN_EXISTING, // open only if file exists
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- hMapFile = CreateFileMapping(
- INVALID_HANDLE_VALUE,
- NULL, // default security
- PAGE_READWRITE, // readwrite access
- 0, // maximum object size (high-order DWORD)
- mem_buffer_size, // maximum object size (low-order DWORD)
- // 0 means map the whole file
- "mapObj");
- pBuf = (LPSTR)MapViewOfFile(
- hMapFile, // handle to map object
- FILE_MAP_ALL_ACCESS, // read/write permission
- 0, // start point (upper word)
- 0, // start point (lower word)
- mem_buffer_size); // how many bytes to read
- swprintf_s(param, 4, L" %d", 2);
- ZeroMemory(&si, sizeof(si));
- si.cb = sizeof(si);
- ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
- if (!CreateProcessA(
- "Process2.exe",
- NULL,
- NULL,
- NULL,
- TRUE,
- 0,
- NULL,
- NULL,
- &si,
- &pi))
- {
- std::cerr << GetLastError();
- return 1;
- }
- WaitForSingleObject(pi.hProcess, INFINITE);
- UnmapViewOfFile(pBuf);
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- CloseHandle(hMapFile);
- CloseHandle(hFile);
- system("pause");
- return 0;
- }
- #pragma comment(lib, "user32.lib")
- #include <iostream>
- #include <Windows.h>
- using std::cout;
- using std::endl;
- int main(void)
- {
- HANDLE hMapFile;
- LPSTR pBuf;
- SYSTEM_INFO sys_info;
- GetSystemInfo(&sys_info);
- int mem_buffer_size = sys_info.dwAllocationGranularity;
- hMapFile = OpenFileMapping(
- FILE_MAP_ALL_ACCESS,
- FALSE,
- "mapObj"
- );
- pBuf = (LPSTR)MapViewOfFile(
- hMapFile,
- FILE_MAP_ALL_ACCESS,
- 0,
- 0,
- mem_buffer_size
- );
- pBuf[0] = 'Z';
- cout << pBuf[0] << endl;
- UnmapViewOfFile(pBuf);
- CloseHandle(hMapFile);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement