Hehouhua / idapython

Automatically exported from code.google.com/p/idapython
Other
0 stars 0 forks source link

AssembleLine() doesn't work with PPC processor #102

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
You should be able to obtain the corresponding opcodes for a assembly 
instruction using the [idaapi.AssembleLine][1] function.

----------

Here is an example of that using a PE-file / x86 processor type:

    ea = FirstSeg()
    seg = idaapi.getseg(ea)
    ip  = ea - (idaapi.ask_selector(seg.sel) << 4)
    buf=idaapi.AssembleLine(ea, seg.sel, ip, seg.bitness, "adsf")
    #Invalid mnemonic -> OK
    print buf
    #None

As we can see, the `idaapi.AssembleLine` call returns `None` and prints a error 
message for a invalid mnemonic when using an incorrect assembly instruction 
like `asdf`.

With a valid assembly instruction, the correct opcode is returned:

    buf=idaapi.AssembleLine(ea, seg.sel, ip, seg.bitness, "ret")
    print ' '.join(["%02X" % ord(x) for x in buf])
    #C3

----------

Here is the same function using a PPC-ELF/ppc processor type:

    ea = FirstSeg()
    seg = idaapi.getseg(ea)
    ip  = ea - (idaapi.ask_selector(seg.sel) << 4)
    buf=idaapi.AssembleLine(ea, seg.sel, ip, seg.bitness, "adsf")
    print ' '.join(["%02X" % ord(x) for x in buf])
    #53
As we can see, no error message is printed and return isn't `None`, but `0x53`.

The valid `sc` instruction and any other valid ppc instructions return the same 
(wrong) value of `0x53`:

    buf=idaapi.AssembleLine(ea, seg.sel, ip, seg.bitness, "sc")
    print ' '.join(["%02X" % ord(x) for x in buf])
    #53

How to fix this?

  [1]: https://code.google.com/p/idapython/source/browse/trunk/swig/idp.i#68

Original issue reported on code.google.com by yannik.s...@googlemail.com on 17 May 2015 at 9:28