Module ludis86
Udis86 C disassembler bindings for Lua.
"Udis86 is an easy-to-use, minimalistic disassembler library (libudis86) for the x86 class of instruction set architectures." This bindings were former part of Lua code injection framework: mmBBQ
Overview
The project contains a standard Makefile that is used to build shared Lua libraries for Windows and Linux. The contained C code part of the bindings can as well be integrated or hard-linked into a Lua project
Source
The GitHub project site is: here
git clone https://github.com/willsteel/ludis86.git
Makefile targets
make all # Build lib and doc make doc # Just build the docs make test # run 'test.lua'
Usage
-- initialize udis to a specific address local ludis86 = require("ludis86") ud = ludis86.init_addr_intel32(0x401000) -- your address here :D -- disassemble and print instructions while ud:dis() > 0 do print(string.format("+%04X %016s %016s", ud:off(), ud:hex(), ud:asm())) end
Notice
2013 (c) by Michael Schmoock michael@willigens.de License: Free-BSD
C-Function API mapping
// Following code is taken from the file: ludis86.c // API mapping { "ud_init", ud_init_C }, { "ud_set_mode", ud_set_mode_C }, { "ud_set_pc", ud_set_pc_C }, { "ud_set_input_hook", ud_set_input_hook_C }, { "ud_set_input_buffer", ud_set_input_buffer_C }, { "ud_set_input_file", ud_set_input_file_C }, { "ud_set_vendor", ud_set_vendor_C }, { "ud_set_syntax", ud_set_syntax_C }, { "ud_input_skip", ud_input_skip_C }, { "ud_input_end", ud_input_end_C }, { "ud_decode", ud_decode_C }, { "ud_disassemble", ud_disassemble_C }, { "ud_translate_intel", ud_translate_intel_C }, { "ud_translate_att", ud_translate_att_C }, { "ud_insn_asm", ud_insn_asm_C }, { "ud_insn_ptr", ud_insn_ptr_C }, { "ud_insn_off", ud_insn_off_C }, { "ud_insn_hex", ud_insn_hex_C }, { "ud_insn_len", ud_insn_len_C }, { "ud_lookup_mnemonic", ud_lookup_mnemonic_C }, // shorthandles { "new", ud_init }, { "dis", ud_disassemble_C }, { "asm", ud_insn_asm_C }, { "off", ud_insn_off_C }, { "hex", ud_insn_hex_C }, { "skip", ud_input_skip_C }, { "len", ud_insn_len_C }, { "ptr", ud_insn_ptr_C }, { "pc", ud_set_pc_C },
Functions
init_file_intel32 (filename, offset, len, pc) | initialiszes the disassembler to a file using intel syntax and 32bit. |
init_file_intel64 (filename, offset, len, pc) | initialiszes the disassembler to a file using intel syntax and 64bit. |
print (ud) | disassemble and printf anything |
intel32 (ud) | sets syntax to intel 32bit |
intel64 (ud) | sets syntax to intel 64bit |
init_buf_intel32 (buf, len, pc) | initializes the disassembler to a string buffer using intel syntax and 32bit. |
init_buf_intel64 (buf, len, pc) | initializes the disassembler to a string buffer using intel syntax and 64bit. |
init_addr_intel32 (addr, len) | initializes the disassembler to an address using intel syntax and 32bit. |
init_addr_intel64 (addr, len) | initializes the disassembler to an address using intel syntax and 64bit. |
Functions
- init_file_intel32 (filename, offset, len, pc)
-
initialiszes the disassembler to a file using intel syntax and 32bit.
Parameters:
- filename the path to an assembly file
- offset OPTIONAL the offset where to start disassembly
- len OPTIONAL the number if bytes to disassemlbe
- pc OPTIONAL the programm counter to use
- init_file_intel64 (filename, offset, len, pc)
-
initialiszes the disassembler to a file using intel syntax and 64bit.
Parameters:
- filename the path to an assembly file
- offset OPTIONAL the offset where to start disassembly
- len OPTIONAL the number if bytes to disassemlbe
- pc OPTIONAL the programm counter to use
- print (ud)
-
disassemble and printf anything
Parameters:
- ud initialized udis86 object
- intel32 (ud)
-
sets syntax to intel 32bit
Parameters:
- ud initialized udis86 object
- intel64 (ud)
-
sets syntax to intel 64bit
Parameters:
- ud initialized udis86 object
- init_buf_intel32 (buf, len, pc)
-
initializes the disassembler to a string buffer using intel syntax and 32bit.
Parameters:
- buf the string buffer
- len OPTIONAL the length to use. max and default: #buf
- pc OPTIONAL the programm counter to use
- init_buf_intel64 (buf, len, pc)
-
initializes the disassembler to a string buffer using intel syntax and 64bit.
Parameters:
- buf the string buffer
- len OPTIONAL the length to use. max and default: #buf
- pc OPTIONAL the programm counter to use
- init_addr_intel32 (addr, len)
-
initializes the disassembler to an address using intel syntax and 32bit.
Parameters:
- addr the address to disassemble. can be userdata cdata or number
- len OPTIONAL the maximum number of bytes to read
- init_addr_intel64 (addr, len)
-
initializes the disassembler to an address using intel syntax and 64bit.
Parameters:
- addr the address to disassemble. can be userdata cdata or number
- len OPTIONAL the maximum number of bytes to read