How to convert inline assembler to .asm file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • togikan
    New Member
    • Jul 2010
    • 5

    How to convert inline assembler to .asm file

    Hi all,

    I'm having a problem converting an inline assembler function to .asm file. I need seperate inline assembler code because in x64 architecture doesn't have support for inline assembly. Here is the code(and attached as a txt file IsVM.txt at the bottom),

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

    using namespace std;


    int filter(int code)
    {
    if (code == EXCEPTION_PRIV_ INSTRUCTION)
    {
    return EXCEPTION_EXECU TE_HANDLER;
    }
    else
    {
    return EXCEPTION_CONTI NUE_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(filter (GetExceptionCo de()))
    {
    rc = false;
    }

    return rc;
    }

    int main()
    {
    if(IsInsideVMWa re())
    cout << "You are in a VMware.." << endl;
    else
    cout << "You are in a native system.."<< endl;
    system("PAUSE") ;
    return 0;
    }
    Any idea how to convert and link to my cpp file? Thanks from now.

    T H K
    Attached Files
    Last edited by togikan; Jul 30 '10, 01:17 PM. Reason: added whole code
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Can you not have IsInsideVMWare( ) in its own file an link to it by using a function prototype in the C++ file?

    You just need the asm as a file in the project or you could pre-compile into a library that you add as a project linker dependency. You would still use the function prototype in the C++ code.

    Comment

    Working...