gpt4 book ai didi

c++ - 绕行 GetComputerNameW

转载 作者:行者123 更新时间:2023-11-27 22:54:52 30 4
gpt4 key购买 nike

您好,我正在尝试使用 Microsoft 绕道拦截 GetComputerNameW,但这似乎不可能。我已经设法绕过 GetVolumeInforation 但这个似乎有所不同。我正在尝试将计算机名称从 DKKKK 更改为 ABCDE。

不走弯路的结果

Image without detours attached

附上弯路的结果

Image with detours

我错过了什么?

#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);
}

最佳答案

您只是覆盖了 a0 的本地指针值,而您应该覆盖它的内容。

试试这个:

wcsncpy(a0, L"ABCDE", *a1);
*a1 = wcslen(a0);

正如 Remy Lebeau 指出的那样:您对原始 GetComputerNameW() 的调用将修改 *a1 的值,因此您可以先复制它的值。

无论如何,由于您是自己生成名称,所以我认为没有理由调用原始的 GetComputerNameW()

关于c++ - 绕行 GetComputerNameW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34212725/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com