Created
October 15, 2020 16:30
-
-
Save iljavs/344cf5d9559df55a0fe91e166e64b3d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ProcGet.cpp : This file contains the 'main' function. Program execution begins and ends there. | |
// | |
#include <Windows.h> | |
#include <stdio.h> | |
#include <psapi.h> | |
#define IOCTL_OPEN_PROCESS CTL_CODE(FILE_DEVICE_UNKNOWN , 1, METHOD_NEITHER, FILE_ANY_ACCESS) | |
int main(int argc, char **argv) { | |
HANDLE f; | |
if (argc < 2) { | |
printf("need to specify a pid\n"); | |
exit(0); | |
} | |
f = CreateFile(L"\\\\.\\ProcReveal", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); | |
if (f == INVALID_HANDLE_VALUE) { | |
printf("CreateFile() failed\n"); | |
exit(0); | |
} | |
DWORD pid = atoi(argv[1]); | |
HANDLE in = (HANDLE) pid; | |
HANDLE out = INVALID_HANDLE_VALUE; | |
DWORD bytes = 0; | |
BOOL r = DeviceIoControl(f, IOCTL_OPEN_PROCESS, &in, sizeof(in), &out, sizeof(out), &bytes, NULL); | |
printf("r: %u\n", r); | |
printf("out handle: %u\n", out); | |
// ... | |
if (r != TRUE) { | |
printf("DeviceIoControl() didn't return true, likely some error .... \n"); | |
CloseHandle(f); | |
return 0; | |
} | |
HMODULE hMods[1024]; | |
DWORD cbNeeded; | |
unsigned int i; | |
if (EnumProcessModules(out, hMods, sizeof(hMods), &cbNeeded)) { | |
for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) { | |
WCHAR szModName[MAX_PATH]; | |
if (GetModuleFileNameExW(out, hMods[i], szModName, sizeof(szModName) / sizeof(szModName[0]))) { | |
printf("module name: %S (0x%08X)\n", szModName, hMods[i]); | |
} | |
else { | |
printf("GetModuleFileNameExW() failed\n"); | |
} | |
} | |
} | |
else { | |
printf("EnumProcessModules() failed, maybe buffer is too small?\n"); | |
} | |
printf("done\n"); | |
CloseHandle(out); | |
CloseHandle(f); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment