作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在尝试使用 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);
}
最佳答案
您只是覆盖了 a0
的本地指针值,而您应该覆盖它的内容。
试试这个:
wcsncpy(a0, L"ABCDE", *a1);
*a1 = wcslen(a0);
正如 Remy Lebeau 指出的那样:您对原始 GetComputerNameW()
的调用将修改 *a1
的值,因此您可以先复制它的值。
无论如何,由于您是自己生成名称,所以我认为没有理由调用原始的 GetComputerNameW()
。
关于c++ - 绕行 GetComputerNameW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34212725/
您好,我正在尝试使用 Microsoft 绕道拦截 GetComputerNameW,但这似乎不可能。我已经设法绕过 GetVolumeInforation 但这个似乎有所不同。我正在尝试将计算机名称
我一直在网上搜索这个问题,我觉得这很奇怪。在我的程序中,我通过以下代码获取计算机的名称: TCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1]; memset
我是一名优秀的程序员,十分优秀!