0

我在将内联汇编程序函数转换为 .asm 文件时遇到问题。我需要单独的内联汇编代码,因为在 x64 架构中不支持内联汇编。这是代码,

#include <windows.h>
#include <string>
#include <iostream>
#include <tlhelp32.h>

using namespace std;


    int filter(int code)
    {
        if (code == EXCEPTION_PRIV_INSTRUCTION)
        {
            return EXCEPTION_EXECUTE_HANDLER;
        }
        else
        {
            return EXCEPTION_CONTINUE_SEARCH;
        }
    }

    bool IsInsideVMWare(void)
    {
      bool rc = true;

      __try
      {
        __asm
        {
          push   edx
          push   ecx
          push   ebx

          mov    eax, 'VMXh'
          mov    ebx, 0 // any value but not the MAGIC VALUE
          mov    ecx, 10 // get VMWare version
          mov    edx, 'VX' // port number

          in     eax, dx // read port
                         // on return EAX returns the VERSION
          cmp    ebx, 'VMXh' // is it a reply from VMWare?
          setz   [rc] // set return value

          pop    ebx
          pop    ecx
          pop    edx
        }
      }
      __except(GetExceptionCode())
      {
        rc = false;
      }

      return rc;
    }

int main()
{
    if(IsInsideVMWare())
        cout << "You are in a VMware.." << endl;
    else
        cout << "You are in a native system.."<< endl;
    system("PAUSE");
    return 0;
}

知道如何转换并链接到我的 cpp 文件吗?从现在开始感谢。

THK

4

2 回答 2

0

最好的选择可能是将列出的内联汇编器移动到单独的 C 源文件中的单独函数中,然后将新的源文件编译到汇编器中(记住在您的头文件中您将需要使用extern "C" { ... }. 然后,您可以获取汇编器输出并将其修改为 64 位。

在生成的汇编程序文件中,您会发现有用于将符号添加到重定位表的汇编程序指令。您还将看到创建和清除堆栈所需的代码。这将根据调用约定而有所不同。如果没有有关您打算使用的汇编程序的更多详细信息,我无法提供更多详细信息。

于 2010-07-30T12:18:29.460 回答
0

我认为链接器不会接受将 32 位代码与 64 位代码链接在一起。

于 2010-07-30T13:15:48.340 回答