Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
FinalPathName
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Jun 7, 2024
1 parent 1929b4c commit a8c8722
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ include_directories(AFTER .)

# v2xker32.dll
add_library(v2xker32 SHARED v2xker32/v2xker32.c v2xker32/v2xker32.def)
target_link_libraries(v2xker32 kernel32 advapi32 winmm psapi WonFileID WonFinalPathName)
target_link_libraries(v2xker32 kernel32 advapi32 winmm psapi WonFileID WonFinalPathName shlwapi)
set_target_properties(v2xker32 PROPERTIES PREFIX "")
set_target_properties(v2xker32 PROPERTIES OUTPUT_NAME "v2xker32")

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ You can check the IAT by `dumpbin /imports` of Visual Studio Command Prompt.
- 2024-06-07 ver.0.8.6
- Fixed v2xadv32 hooking.
- Supported SetFileInformationByHandle, GetFileInformationByHandleEx, and OpenFileById.
- Supported GetFinalPathNameByHandleA/W.

## How to build?

Expand Down
1 change: 1 addition & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ You can check the IAT by dumpbin /imports of Visual Studio Command Prompt.
- 2024-06-07 ver.0.8.6
- Fixed v2xadv32 hooking.
- Supported SetFileInformationByHandle, GetFileInformationByHandleEx, and OpenFileById.
- Supported GetFinalPathNameByHandleA/W.

## WARNING!

Expand Down
1 change: 1 addition & 0 deletions READMEJP.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Visual Studio コマンドプロンプトの dumpbin /imports で IAT をチェ
- 2024-06-07 ver.0.8.6
- v2xadv32 のフックを修正。
- SetFileInformationByHandle、GetFileInformationByHandleEx および OpenFileById のサポート。
- GetFinalPathNameByHandleA/W のサポート。

## 警告

Expand Down
2 changes: 2 additions & 0 deletions supported.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ kernel32.CreateEventExW
kernel32.SetFileInformationByHandle
kernel32.GetFileInformationByHandleEx
kernel32.OpenFileById
kernel32.GetFinalPathNameByHandleA
kernel32.GetFinalPathNameByHandleW
41 changes: 41 additions & 0 deletions v2xker32/v2xker32.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <strsafe.h>
#include <psapi.h>
#include "WonFileID.h"
#include "WonFinalPathName.h"

typedef struct tagSRWLOCK_FOR_XP
{
Expand Down Expand Up @@ -110,6 +111,20 @@ FN_SetFileInformationByHandle s_pSetFileInformationByHandle;
FN_GetFileInformationByHandleEx s_pGetFileInformationByHandleEx;
FN_OpenFileById s_pOpenFileById;

typedef DWORD (WINAPI *FN_GetFinalPathNameByHandleA)(
HANDLE hFile,
LPSTR lpszFilePath,
DWORD cchFilePath,
DWORD dwFlags);
typedef DWORD (WINAPI *FN_GetFinalPathNameByHandleW)(
HANDLE hFile,
LPWSTR lpszFilePath,
DWORD cchFilePath,
DWORD dwFlags);

FN_GetFinalPathNameByHandleA s_pGetFinalPathNameByHandleA;
FN_GetFinalPathNameByHandleW s_pGetFinalPathNameByHandleW;

BOOL WINAPI
IsWow64ProcessForXP(HANDLE hProcess, PBOOL Wow64Process)
{
Expand Down Expand Up @@ -706,6 +721,30 @@ OpenFileByIdForXP(
dwFlagsAndAttributes);
}

DWORD WINAPI GetFinalPathNameByHandleAForXP(
HANDLE hFile,
LPSTR lpszFilePath,
DWORD cchFilePath,
DWORD dwFlags)
{
if (s_pGetFinalPathNameByHandleA && DO_FALLBACK)
return s_pGetFinalPathNameByHandleA(hFile, lpszFilePath, cchFilePath, dwFlags);

return WonGetFinalPathNameByHandleA(hFile, lpszFilePath, cchFilePath, dwFlags);
}

DWORD WINAPI GetFinalPathNameByHandleWForXP(
HANDLE hFile,
LPWSTR lpszFilePath,
DWORD cchFilePath,
DWORD dwFlags)
{
if (s_pGetFinalPathNameByHandleW && DO_FALLBACK)
return s_pGetFinalPathNameByHandleW(hFile, lpszFilePath, cchFilePath, dwFlags);

return WonGetFinalPathNameByHandleW(hFile, lpszFilePath, cchFilePath, dwFlags);
}

#define GETPROC(fn) s_p##fn = (FN_##fn)GetProcAddress(s_hKernel32, #fn)

BOOL WINAPI
Expand Down Expand Up @@ -744,6 +783,8 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
GETPROC(SetFileInformationByHandle);
GETPROC(GetFileInformationByHandleEx);
GETPROC(OpenFileById);
GETPROC(GetFinalPathNameByHandleA);
GETPROC(GetFinalPathNameByHandleW);
break;
case DLL_PROCESS_DETACH:
FreeLibrary(s_hKernel32);
Expand Down
2 changes: 2 additions & 0 deletions v2xker32/v2xker32.def
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ EXPORTS
SetFileInformationByHandle = SetFileInformationByHandleForXP
GetFileInformationByHandleEx = GetFileInformationByHandleExForXP
OpenFileById = OpenFileByIdForXP
GetFinalPathNameByHandleA = GetFinalPathNameByHandleAForXP
GetFinalPathNameByHandleW = GetFinalPathNameByHandleWForXP

; kernel32 --> advapi32
CreateProcessAsUserA = advapi32.CreateProcessAsUserA
Expand Down
4 changes: 3 additions & 1 deletion vista2xp/JustDoIt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ bool do_kernel32(codereverse::ExeImage& image, size_t i, char *name)
lstrcmpA(symbol.pszName, "CreateEventExW") == 0 ||
lstrcmpA(symbol.pszName, "SetFileInformationByHandle") == 0 ||
lstrcmpA(symbol.pszName, "GetFileInformationByHandleEx") == 0 ||
lstrcmpA(symbol.pszName, "OpenFileById") == 0)
lstrcmpA(symbol.pszName, "OpenFileById") == 0 ||
lstrcmpA(symbol.pszName, "GetFinalPathNameByHandleA") == 0 ||
lstrcmpA(symbol.pszName, "GetFinalPathNameByHandleW") == 0)
{
if (lstrcmpiA(name, "kernel32") == 0)
StringCbCopyA(const_cast<char *>(name), sizeof("v2xker32"), "v2xker32");
Expand Down

0 comments on commit a8c8722

Please sign in to comment.