python distorm3 1분요약
distorm3 는 파이썬에서 제공하는 x86/x64 디스어셈블 라이브러리이다.
다운로드/설치는 아래의 링크에서 zip 파일을 받아서 한다.
https://code.google.com/p/distorm/downloads/detail?name=distorm3.zip&can=2&q=
다운받은 zip 파일을 풀고
python setup.py build
python setup.py install
하면 distorm3 가 설치되는데 아래처럼 사용하면 된다
root@ubuntu:/var/www/distorm3/distorm3# python
Python 2.7.4 (default, Sep 26 2013, 03:20:56)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import distorm3
>>> print distorm3.Decode(0, '31c090c3'.decode('hex'), distorm3.Decode32Bits)
[(0L, 2L, 'XOR EAX, EAX', '31c0'), (2L, 1L, 'NOP', '90'), (3L, 1L, 'RET', 'c3')]
>>>
Decode 라는 함수가 핵심인데 3개의 인자를 받는다.
1. 명령어 바이트 스트림의 시작주소(메모리상 가상주소)
2. 명령어 바이트 스트림
3. 플래그(16, 32, 64비트)
1 의 경우 명령어의 현재위치같은게 상관없는경우 무시되므로 0 을 줘도된다.
이 함수가 리턴하는 결과는 디스어셈블된 명령 하나하나의 튜플이 연결된 리스트를 리턴한다.
여기서부터는 알아서 활용하면 끝.