#!/usr/local/bin/lua51 ASM_REG8 = 0 ASM_REG16 = 1 ASM_REG32 = 2 ASM_REG64 = 3 ASM_MEM16 = 6 ASM_MEM32 = 6 ASM_MEM64 = 7 ASM_IMM8 = 8 ASM_IMM16 = 9 ASM_IMM32 = 10 ASM_IMM64 = 11 ASM_SREG = 12 ASM_REL32 = 15 ASM_IMM16_IMM16 = 16 -- For absolute jumps and calls -- SREG: ES = 0, CS = 1, SS = 2, DS = 3, FS = 4, GS = 5 local map = { ------------------------------------------------------------------------------------ -- MOV ------------------------------------------------------------------------------------ { mnemonic = "mov", operands = { ASM_REG8, ASM_REG8 }, opcode = "0h88 /r" }, { mnemonic = "mov", operands = { ASM_REG8, ASM_IMM8 }, opcode = "0hB0 + rb ib" }, { mnemonic = "mov", operands = { ASM_REG32, ASM_REG32 }, opcode = "0h89 /r" }, { mnemonic = "mov", operands = { ASM_REG32, ASM_IMM32 }, opcode = "0hB8 + rd id" }, { mnemonic = "mov", operands = { ASM_REG64, ASM_REG64 }, opcode = "REX.W + 0h89 /r" }, { mnemonic = "mov", operands = { ASM_REG64, ASM_IMM64 }, opcode = "REX.W + 0hB8 + rd io" }, { mnemonic = "mov", operands = { ASM_CR0, ASM_REG64 }, opcode = "0h0F 0h22 /r" }, { mnemonic = "mov", operands = { ASM_REG64, ASM_CR0 }, opcode = "0h0F 0h20 /r" }, { mnemonic = "mov", operands = { ASM_MEM16, ASM_IMM16 }, opcode = "0h66 0hC7 /0 iw" }, { mnemonic = "mov", operands = { ASM_MEM32, ASM_IMM32 }, opcode = "0hC7 /0 id" }, { mnemonic = "mov", operands = { ASM_MEM64, ASM_IMM32 }, opcode = "REX.W + 0hC7 /0 id" }, ------------------------------------------------------------------------------------ -- CMP ------------------------------------------------------------------------------------ { mnemonic = "cmp", operands = { ASM_REG8, ASM_REG8 }, opcode = "0h38 /r" }, { mnemonic = "cmp", operands = { ASM_REG8, ASM_IMM8 }, opcode = "0h80 /7 ib" }, { mnemonic = "cmp", operands = { ASM_REG32, ASM_IMM32 }, opcode = "0h81 /7 id" }, ------------------------------------------------------------------------------------ -- ADD ------------------------------------------------------------------------------------ { mnemonic = "add", operands = { ASM_REG32, ASM_IMM32 }, opcode = "0h81 /0 id" }, ------------------------------------------------------------------------------------ -- AND ------------------------------------------------------------------------------------ { mnemonic = "and", operands = { ASM_REG32, ASM_IMM32 }, opcode = "0h81 /4 id" }, ------------------------------------------------------------------------------------ -- XOR ------------------------------------------------------------------------------------ { mnemonic = "xor", operands = { ASM_REG32, ASM_REG32 }, opcode = "0h31 /r" }, { mnemonic = "xor", operands = { ASM_REG64, ASM_REG64 }, opcode = "REX.W + 0h31 /r" }, ------------------------------------------------------------------------------------ -- OR ------------------------------------------------------------------------------------ { mnemonic = "or", operands = { ASM_REG8, ASM_IMM8 }, opcode = "0h80 /1 ib" }, { mnemonic = "or", operands = { ASM_REG32, ASM_IMM32 }, opcode = "0h81 /1 id" }, ------------------------------------------------------------------------------------ -- LGDT ------------------------------------------------------------------------------------ { mnemonic = "lgdt", operands = { ASM_MEM64 }, opcode = "0h0F 0h01 /2" }, ------------------------------------------------------------------------------------ -- TEST ------------------------------------------------------------------------------------ { mnemonic = "test", operands = { ASM_REG8, ASM_REG8 }, opcode = "0h84 /r" }, { mnemonic = "test", operands = { ASM_REG32, ASM_IMM32 }, opcode = "0hF7 /0 id" }, ------------------------------------------------------------------------------------ -- INC ------------------------------------------------------------------------------------ { mnemonic = "inc", operands = { ASM_REG8 }, opcode = "0hFE /0" }, { mnemonic = "inc", operands = { ASM_REG32 }, opcode = "0hFF /0" }, { mnemonic = "inc", operands = { ASM_REG64 }, opcode = "REX.W + 0hFF /0" }, ------------------------------------------------------------------------------------ -- DEC ------------------------------------------------------------------------------------ { mnemonic = "dec", operands = { ASM_REG32 }, opcode = "0hFF /1" }, ------------------------------------------------------------------------------------ -- JMP ------------------------------------------------------------------------------------ { mnemonic = "jmp", operands = { ASM_REL32 }, opcode = "0hE9 cd" }, { mnemonic = "jmp", operands = { ASM_REG64 }, opcode = "0hFF /4" }, ------------------------------------------------------------------------------------ -- JNZ ------------------------------------------------------------------------------------ { mnemonic = "jnz", operands = { ASM_REL32 }, opcode = "0h0F 0h85 cd" }, ------------------------------------------------------------------------------------ -- JZ ------------------------------------------------------------------------------------ { mnemonic = "jz", operands = { ASM_REL32 }, opcode = "0h0F 0h84 cd" }, ------------------------------------------------------------------------------------ -- JC ------------------------------------------------------------------------------------ { mnemonic = "jc", operands = { ASM_REL32 }, opcode = "0h0F 0h82 cd" }, ------------------------------------------------------------------------------------ -- JNC ------------------------------------------------------------------------------------ { mnemonic = "jnc", operands = { ASM_REL32 }, opcode = "0h0F 0h83 cd" }, ------------------------------------------------------------------------------------ -- CALL ------------------------------------------------------------------------------------ { mnemonic = "call", operands = { ASM_REL32 }, opcode = "0hE8 cd" }, ------------------------------------------------------------------------------------ -- HLT ------------------------------------------------------------------------------------ { mnemonic = "hlt", operands = { }, opcode = "0hF4" }, ------------------------------------------------------------------------------------ -- CLI ------------------------------------------------------------------------------------ { mnemonic = "cli", operands = { }, opcode = "0hFA" }, ------------------------------------------------------------------------------------ -- RET ------------------------------------------------------------------------------------ { mnemonic = "ret", operands = { }, opcode = "0hC3" }, ------------------------------------------------------------------------------------ -- STI ------------------------------------------------------------------------------------ { mnemonic = "sti", operands = { }, opcode = "0hFB" }, ------------------------------------------------------------------------------------ -- CLD ------------------------------------------------------------------------------------ { mnemonic = "cld", operands = { }, opcode = "0hFC" }, ------------------------------------------------------------------------------------ -- PUSH ------------------------------------------------------------------------------------ { mnemonic = "push", operands = { ASM_IMM8 }, opcode = "0h50 + rd" }, ------------------------------------------------------------------------------------ -- INT ------------------------------------------------------------------------------------ { mnemonic = "int", operands = { ASM_IMM8 }, opcode = "0hCD ib" }, ------------------------------------------------------------------------------------ -- REP MOVSD ------------------------------------------------------------------------------------ { mnemonic = "rep_movsd", operands = { }, opcode = "0hF3 0hA5" }, ------------------------------------------------------------------------------------ -- REP STOSD ------------------------------------------------------------------------------------ { mnemonic = "rep_stosd", operands = { }, opcode = "0hF3 0hAB" }, ------------------------------------------------------------------------------------ -- CPUID ------------------------------------------------------------------------------------ { mnemonic = "cpuid", operands = { }, opcode = "0h0F 0hA2" }, ------------------------------------------------------------------------------------ -- RDMSR ------------------------------------------------------------------------------------ { mnemonic = "rdmsr", operands = { }, opcode = "0h0F 0h32" }, ------------------------------------------------------------------------------------ -- WRMSR ------------------------------------------------------------------------------------ { mnemonic = "wrmsr", operands = { }, opcode = "0h0F 0h30" }, } map.matches = function(match) for i = 1, #map do local dmap = map[i] if dmap.mnemonic == match.mnemonic then if #dmap.operands == #match.operands then local it_matches = true for j = 1, #dmap.operands do if dmap.operands[j] ~= match.operands[j] then it_matches = false end end if it_matches == true then return dmap end end end end return nil end return map