python-x86-obfuscator icon indicating copy to clipboard operation
python-x86-obfuscator copied to clipboard

capstone instead of distorm3

Open b3mb4m opened this issue 8 years ago • 4 comments

Read it, http://www.capstone-engine.org/BHUSA2014-capstone.pdf

import distorm3
from capstone import *
from binascii import hexlify

print distorm3.Decode(0, "\x41", distorm3.Decode32Bits)

md = Cs(CS_ARCH_X86, CS_MODE_32)
for i in md.disasm("\x41", 0x00):
    `print [(i.address, i.size, (i.mnemonic+" "+i.op_str), hexlify(i.bytes))]

  //distorm3 :  [(0L, 1L, 'INC ECX', '41')]
  //capstone :  [(0L, 1, u'inc ecx', '41')]

Ref : https://github.com/aquynh/capstone Ref : http://www.capstone-engine.org/lang_python.html

b3mb4m avatar May 12 '16 18:05 b3mb4m

I am familiar with Capstone. I used diStorm3 as I only wanted to retrieve the size of instructions.

kgretzky avatar May 12 '16 20:05 kgretzky

I implemented mine in Capstone. Good work, saw how you overcame some of the challenges I found too quite differently :)

I was trying to find out how to use "label" functionality in Capstone but did not think it supported it. I wonder how you overcame this? Will take some time to read your source.

vysecurity avatar May 13 '16 00:05 vysecurity

I'm just open it for future works(arm,mips,sparc etc. maybe) consider it :)

b3mb4m avatar May 13 '16 07:05 b3mb4m

vysec: Capstone, doesn't support labels, but it will give you the destination address of the jump instruction, but you can do it yourself as well easily. What I do then is create labels of my own. I put the disassembled instructions into array of objects and these objects have label parameters if needed. If I stumble upon a jump, I create a new label that I assign to this jump's destination and put also the jump destination label for that jump instruction. That allows me to be later independent from fixed addressing and I can then apply fixes to relative jump offsets as I know exactly to which instruction the jump should point to.

b3mb4m: Of course! Will change that in the future for sure.

kgretzky avatar May 13 '16 08:05 kgretzky