【发布时间】:2015-12-10 22:14:53
【问题描述】:
您好,我正在尝试使用 Microsoft 绕道拦截 GetComputerNameW,但似乎不可能。我已经设法绕过 GetVolumeInforation,但这似乎有所不同。 我正在尝试将计算机名称从 DKKKK 更改为 ABCDE。
结果不走弯路
绕道而行的结果
我错过了什么?
#include <detours.h>
#pragma comment(lib,"detours.lib")
HMODULE hLib = GetModuleHandle(L"Kernel32.dll");
typedef BOOL (WINAPI *CPNMPtr)(LPWSTR lpBuffer,LPDWORD &lpnSize);
CPNMPtr pCPNM = (CPNMPtr)GetProcAddress(hLib, "GetComputerNameW");
BOOL WINAPI MyGetComputerNameW(LPWSTR a0, LPDWORD a1)
{
BOOL rv = 0;
rv = pCPNM(a0, a1);
wchar_t* wcBuff = L"ABCDE";
a0 = wcBuff;
printf("GetComputerNameW(%ls,) -> %p\n", a0, rv);
return rv;
}
int _tmain(int argc, _TCHAR* argv[])
{
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)pCPNM, MyGetComputerNameW);
DetourTransactionCommit();
WCHAR wzComputerName[MAX_COMPUTERNAME_LENGTH+1];
DWORD dwSize = sizeof(wzComputerName)/sizeof(wzComputerName[0]);
if (GetComputerName(wzComputerName, &dwSize))
printf ("GetComputerName returned %S of length %u\n", wzComputerName, dwSize);
}
【问题讨论】: