GithubHelp home page GithubHelp logo

lua_asm's Introduction

lua_asm

在lua里用keystnoe 即时将文本编译成机器码 并执行的项目

项目只配置了 vs2019的Resele|Debug x86|win32 编译配置

如果需要其他版本 可以 https://github.com/keystone-engine/keystone 从该项目里重新编译keystone.lib

例子

local asm = require 'asm'

--std call 
local std_code = [[
    mov eax, [esp + 0x4] 
    mov edx, [esp + 0x8]
    add eax, edx
    
    jmp pos   //支持重定位 以及跳转
    
    add eax, 1 
pos:  
    ret  0x8
]]

local std_add = asm.to_binary(std_code, '(II)I', 'std_code_name', '__stdcall')

print('run asm ', std_add(100, 200))

print('memory address', std_add:get_address())

local code = std_add:get_code()

local s = {}
for i = 1, #code do 
    local byte = code:sub(i, i):byte()
    s[#s + 1] = string.format("%02x ", byte)
end 
print('code', table.concat(s))

输出内容

run asm         300
memory address  40304640
code    8b 44 24 04 8b 54 24 08 01 d0 eb 03 83 c0 01 c2 08 00

也可以看tests/test_ffi.lua里面 用ffi 的方式执行汇编机器码。

to_binary 返回的 对象跟可执行内存 被lua gc管理释放 当不存在任何引用时会被回收, 如果取内存地址做相关操作记得将对象保持引用 避免野指针崩溃

lua_asm's People

Contributors

w4454962 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.