zoukankan      html  css  js  c++  java
  • c++ 使用asmjit

    1. 下载源码

    在github下载源码放在"desctop/asmjit-master"

    2. 使用cmake生成构建系统

    > Desktopasmjit-master> cmake CMakeLists.txt
    

    3. 使用vs2019编译

    使用vs2019打开"asmjit.sln",使用release x64打包

    打包后会将"asmjit.dll"和"asmjit.lib"输出到"desctop/asmjit-master/Release"

    4. 在项目中使用asmjit

    1. 设置"asmjit"头文件位置,通常是"Desktopasmjit-mastersrc"

    1. 设置"asmjit.lib"位置

    1. 设置"asmjit.dll"位置

    5. 拷贝官网demo到main.cpp,然后运行

    MessageBoxA Example

    #include <iostream>
    #include <Windows.h>
    #include <asmjit/asmjit.h>
    
    using namespace asmjit;
    
    typedef int (*Func)(void);
    
    int main(int argc, char* argv[]) {
      JitRuntime rt;
    
      CodeHolder code;
      code.init(rt.environment());
      x86::Assembler a(&code);
      
      a.push(x86::rbp);
      a.mov(x86::rbp, x86::rsp);
      
      a.sub(x86::rsp, 32);
      a.mov(x86::rcx, 0);
      a.mov(x86::rdx, "body");
      a.mov(x86::r8, "title");
      a.mov(x86::r9, 3);
      a.call(MessageBoxA);
      a.add(x86::rsp, 32);
    
      a.mov(x86::rsp, x86::rbp);
      a.pop(x86::rbp);
      a.ret();
    
      Func fn;
      Error err = rt.add(&fn, &code);
      if (err) return 1;
      printf("%d
    ", fn());
    
      rt.release(fn);
      return 0;
    }
    

    如果你要同时编译asmjit和asmtk,将两个放在同级目录,asmtk的cmakelist会去"../asmjit/"找asmjit的cmakelist

  • 相关阅读:
    js开发笔记
    安全相关开发笔记
    常用.NET库使用总结
    Windows使用总结
    .NET Web开发笔记
    Unity插件使用总结
    WinForm开发笔记
    C#开发笔记
    iTunes使用总结
    Mac使用总结
  • 原文地址:https://www.cnblogs.com/ajanuw/p/14424368.html
Copyright © 2011-2022 走看看