gpt4 book ai didi

c++ - 使用 IDebugControl::Disassemble 查看子程序的指令

转载 作者:可可西里 更新时间:2023-11-01 10:44:34 28 4
gpt4 key购买 nike

所以我正在尝试使用 Windows API (DbgEng.h/.lib)“反汇编”函数来查看模块中某个函数(我知道它已导出)的指令。但是....它返回了一个意外错误。

IDebugClient* clt;
IDebugControl* ctrl;

void InitializeInterfaces(void)
{
HRESULT status;

if ((status = DebugCreate(__uuidof(IDebugClient), (void**)&clt)) != S_OK) {
Utils::add_log("IDebugClient DebugCreate failed: 0x%X\n", status);
}

clt->AttachProcess(NULL, GetProcessId(GetCurrentProcess()), DEBUG_ATTACH_NONINVASIVE | DEBUG_ATTACH_NONINVASIVE_NO_SUSPEND);

if ((status = clt->QueryInterface(__uuidof(IDebugControl), (void**)&ctrl)) != S_OK) {
Utils::add_log("IDebugControl QueryInterface failed: 0x%X\n", status);
}
}

void print_bytes(const void *object, size_t size, const char* funcname)
{
size_t i;
Utils::add_log("|%s function bytes| ", funcname);

for (i = 0; i < size; i++)
{
Utils::add_log_raw("%02x ", ((const unsigned char *)object)[i] & 0xff);
}

Utils::add_log_raw("\n");
}

void main()
{
InitializeInterfaces();

ULONG64 bc = (ULONG64)GetProcAddress(GetModuleHandleA("lua_shared.dll"), "luaL_loadbufferx");

PSTR buff;
HRESULT size = ctrl->Disassemble(bc, DEBUG_DISASM_EFFECTIVE_ADDRESS, (PSTR)&buff, 16, NULL, NULL);

//error catching incase the disassemble fails (which it does fuck -___-)
if (size == S_OK) {
Utils::add_log("%s", buff);
}
else if (size == S_FALSE) {
Utils::add_log("[error] buffer too small to recieve proccess instructions");
}
else {
Utils::add_log("IDebugControl process disassemble failed: 0x%X\n", size);
}

//troubleshooting
Utils::add_log_raw("\nTROUBLESHOOTING INFO\n");
Utils::add_log("|bc function pointer| 0x%p\n", bc);
print_bytes((const void*)bc, sizeof bc, "bc");
}

这是我正在使用的当前代码,这是它输出的内容:

[04:09:56] IDebugControl process disassemble failed: 0x8000FFFF

TROUBLESHOOTING INFO

[04:09:56] |bc function pointer| 0x640FE750

[04:09:56] |bc function bytes| 55 8b ec 83 e4 f8 83 ec

任何人都知道我缺少什么导致它抛出该错误? 0x8000FFFF 相当于 E_UNEXPECTED 枚举。函数指针有效,字节看起来没问题,我迷路了。

提前致谢。

最佳答案

我遇到了完全相同的问题。为我修复它的只是加载一个 IDebugSymbols 接口(interface)。例如:

IDebugClient* clt;
IDebugControl* ctrl;
IDebugSymbols* symbols;

void InitializeInterfaces(void)
{
HRESULT status;

if ((status = DebugCreate(__uuidof(IDebugClient), (void**)&clt)) != S_OK) {
Utils::add_log("IDebugClient DebugCreate failed: 0x%X\n", status);
}

clt->AttachProcess(NULL, GetProcessId(GetCurrentProcess()), DEBUG_ATTACH_NONINVASIVE | DEBUG_ATTACH_NONINVASIVE_NO_SUSPEND);

if ((status = clt->QueryInterface(__uuidof(IDebugControl), (void**)&ctrl)) != S_OK) {
Utils::add_log("IDebugControl QueryInterface failed: 0x%X\n", status);
}

if ((status = clt->QueryInterface(__uuidof(IDebugSymbols), (void**)&symbols)) != S_OK) {
Utils::add_log("IDebugSymbols QueryInterface failed: 0x%X\n", status);
}

一旦我这样做了,反汇编工作就很好了。 (我还使用与您使用的完全相同的标志进行了进程内附加,这是值得的。)

不知道为什么这个小花絮没有记录在 MSDN 上。我只是想根据本文中引用的一些伪代码尝试一下:https://www.gamedev.net/blog/909/entry-2254516-leveraging-windows-built-in-disassembler/

关于c++ - 使用 IDebugControl::Disassemble 查看子程序的指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31686186/

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