﻿  Immunity libdisassembly v2.2 
  ~~~~~~~~ ~~~~~~~~~~~~~~ ~~~~ 
  http://www.immunitysec.com 
  http://intelguardians.com ( Matthew Carpenter <mcarpenter@intelguardians.com> )
  http://atlas.r4780y.com   ( atlas <atlas@r4780y.com> )
  November 25, 2007


Libdisassemble is a python library for disassembling x86 opcodes. It was originally made for Immunity's PDB Project (a vulnerability development focused debugger) and has found its way into other projects such as Disass (by atlas) and invisigoth's Vtrace/VDB tools.  It is partially based on mammon libdisasm opcode list (http://www.eccentrix.com/members/mammon/).  Recently a great deal of logic and data bugs have been fixed my Matthew Carpenter (of Intelguardians) and atlas.  There is still a lot of work to do with the Metadata, but the library tries to return as much information it can get off of an opcode.  Libdisassemble currently supports 32-bit and 16-bit disassembly, although 64-bit disassembly is in the works.

INSTALLATION:

From the libdisassemble-x.x directory:
$ sudo python setup.py install




USAGE:

ie: 
   $ objdump -x /bin/cat | grep .text
     11 .text         00001e48  08048b00  08048b00  00000b00  2**4
   $ ./disassemble.py /bin/cat 0xb00 0x1e48

Disassembling file /bin/cat at offset: 0x2816
 00002816:   mov           0x8(%ebp),%edx
 00002819:   mov           0xc(%ebp),%eax
 0000281C:   mov           %edx,(%esp,1)
[...]

LIBRARY USAGE:
 Getting the string information of an opcode is really simple:
 
from disassemble import *
data="\xeb\xfe"
p=Opcode(data)
print p.printOpcode("AT&T")

The output would be:
 jmp         0xfffffffe

If for example, we want to put that information in a fancy GUI, we could request for a string separated in mnemonic, source, dest (or dest, source) with getOpcode(FORMAT).

 p.getOpcode("AT&T")

and it will return a table:
['jmp', '0xfffffffe']

Metadata info:
~~~~~~~~ ~~~~~
Every opcode has 4 variables: opcode, source, dest, and aux.

 - opcode, is the string of the mnenonic 
 - source, is an object or None
 - dest,   is an object or None
 - aux,    is an object or None

There are 3 types of objects,  Register, Address, SIB and Expression. There are a couple of common methods you can use:

 - object.printOpcode(FORMAT), the string representation of the object.
 - object.getSize(), size 
 - object.getType, information of the opcode table.
 - object.getSFlag, object permission ("R"ead, "W"rite, e"X"ecute)
 - etc (You can browse the source to get more information)



changelog
2.5	
	Reduction of str-object creation by linking each opcode to the original byte stream using an offset.
		This is quite a significant change, and should add performance... but may break tools using the internals.
		Please test your tools!  You have been warned.
	A few bug fixes, but few that would be noticed (like the highly localized F30fC730 which is VMXON)

2.3 and 2.4 were internal releases, with minor modifications.  2.5 was released because of the significant changes with .data and .dataoffset

2.2	
	More bug fixes, including the returning of an opcode with self.opcode == "invalid" instead of 0 where appropriate
2.1
	Fixed handling of offsets, particularly with 
	Fixed bugs in 16-bit mode
2.0
	Holy Crap...  completion of 1.0

