小编jos*_*max的帖子

在Windows上的"用户空间"中"捕获"进程自己的sysenter调用

我正在Windows中运行一个运行时非本机二进制转换器,到目前为止,我已经能够通过使用一个使用丑陋的hack来"捕获"操作系统二进制文件的中断(即INT 0x99) Windows SEH处理无效中断; 但只是因为系统调用向量与Windows中的不同,允许我通过执行以下操作来捕获这些"软"异常:

static int __stdcall handler_cb(EXCEPTION_POINTERS* pes, ...)
{

    if (pes->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION)
        return EXCEPTION_CONTINUE_SEARCH;

    char* instruct = (char*) pes->ContextRecord->Eip;

    if (!instruct)
        handle_invalid_instruction(instruct);   

    switch (instruct[0])
    {
        case 0xcd: // INT
        {
            if (instruct[1] != 0x99) // INT 0x99
                handle_invalid_instruction(instruct);
            handle_syscall_translation();
            ...
        }
        ...
        default:
            halt_and_catch_fire();
    }
    return EXCEPTION_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

哪个工作得相当好(但很慢),问题是Windows首先尝试处理指令/中断,对于使用sysenter/sysexit而不是int 0x99的非本机二进制文件,非本机二进制文件中的一些systenter指令实际上是有效的NT内核调用,这意味着我的处理程序永远不会被调用,更糟糕的是; "主机"操作系统的状态也受到了损害.有没有办法在Windows中"捕获"sysenter指令?我该怎么做呢?

c windows interrupt system-calls interrupt-handling

5
推荐指数
1
解决办法
225
查看次数

标签 统计

c ×1

interrupt ×1

interrupt-handling ×1

system-calls ×1

windows ×1