📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  Target Specific - General  >>  PowerPC and IDA

Topic created on: March 2, 2011 20:09 CST by EFIUnlimited .

I am at a block, and I need another perspective.  I am reversing PowerPC code, and IDA correctly identifies data locations, but when I decode the instructions manually, I don't come up with the same answer IDa does.  I can't figure out where I am wrong, and IDA is right.

RAW code:
3C 60 00 0D 38 63 D0 C0
IDA Disassembly:
lis     %r3, ((unk_CD0C0+0x10000)@h)
addi    %r3, %r3, -0x2F40 # unk_CD0C0

Based on information I have, I know that address 0x0CD0C0 is the correct target data address.  However, manual decoding indicates the target address to be 0x10000 higher (0x0DD0C0).  How does IDA know to subtract 0x10000???

Brian

  cseagle     March 2, 2011 21:12.02 CST
IDA is not subtracting 0x10000.  it is telling you that the address is 0xCD0C0 + 0x10000 == 0xDC0C0 or the same thing that you decoded by hand. The reason that IDA has formatted the operand this way (probably) is that it has created a huge blob of data (probably an array of bytes) beginning at address unk_CD0C0 (0xCD0C0) and the address 0xDC0C0 lies within that declared block.  IDA wants to name every location that gets referenced, but this location lies in the middle of data that is already named.  Rather than breaking up the data block, IDA uses the name+offset form to format your operand.  If you undefine the blob at 0xCD0C0, you can name the byte at 0xDC0C0 and you will see IDA change the operand to reflect your new name.

  EFIUnlimited     March 2, 2011 21:37.21 CST
Chris,

  The thing is, I have alternate information sources that confirm IDA is correct with address 0xCD0C0, there is no need to rename/move it.

  The main area that contains data in this image ranges from 0x91800-0xFFFFF.  The location at 0xDC0C0 is currently undefined.

  I am figuring this is a PPC specific thing, and there may be some offset register, or something that I am not aware of.

PS: 'The IDA Pro Book' was a good read!  I reference it regularly.  Unfortunately, I don't know a good source for PPC specific info.

Brian

  EFIUnlimited     March 2, 2011 22:40.18 CST
Chris,

  Coincidentally, I just saw IDA do what you described above, with respect to creating an offset if the pointed data was already defined.  Thing is, it doesn't do this with the location in question.  Moreover, there are numerous other similar data references I have found to other locations that all have the same 0x10000 offset.

Brian

  aeppert     March 3, 2011 07:20.59 CST
This is somewhat a "feature" of IDA and PowerPC data addresses.  Generally speaking, provided what Chris said isn't true, you can mostly ignore the additional offset addition.  Those of us that have used IDA with PowerPC long enough pretty much mentally parse that out anyway.

  EFIUnlimited     March 3, 2011 09:17.42 CST
aeppert,

  I trust what it is doing, so I have been largely ignoring it.  It seems to universally apply this 0x10000 offset to any lis/addi pair.  I found a lis/ori pair that doesn't have the offset.  The reason I am so interested, is statements like this

lbz     %r9, -0x2B4C(%r13)
cmplwi  %r9, 0
bne     loc_106D4

%r13 is used frequently as a base address in this code.  I am curious how IDA knew to offset the lis/addi pairs, so I would know if I need to do the same thing to %r13.

Brian

  igorsk     March 3, 2011 16:11.52 CST
0x10000 is added to compensate for the signed low part. The high part actually loaded into r3 is 0xD while the high part of the final address (0xCD0C0) is 0xC. It's done just so the disassembly lines up. It has nothing to do with blobs of data, sorry Chris :)

P.S. IDA 6.1 will have an option to set the r13 base, similar to thr current rtoc/r2 setting.

  EFIUnlimited     March 3, 2011 16:47.04 CST
igorsk,

  It would be great if IDA would generate xref's relative to %r13.  Until I get 6.xx do you know of an IDC that will do it?  Otherwise, I'll probably wind up writing one.

  I think you have the answer, but I am having trouble following from A-B-C.  Is it clobbering the lower bit of 0x0D?  Would you mind expanding your explanation?

To refresh,
RAW code:
3C 60 00 0D 38 63 D0 C0
IDA Disassembly:
lis     %r3, ((unk_CD0C0+0x10000)@h)
addi    %r3, %r3, -0x2F40 # unk_CD0C0

My understanding says this translates to
addis  %r3, %r0, 0x000D
addi    %r3, %r3, 0xD0C0

Brian

  EFIUnlimited     March 4, 2011 01:09.31 CST
Ok, I got it!  The problem is I was looking at the ADD like an OR, when really it's a signed long added to a signed short.  Here is the break down.

lis     %r3, ((unk_CD0C0+0x10000)@h)

This results in 0x000D0000 being placed into %r3.  For those with a calculator, this is 851,968 decimal.

addi    %r3, %r3, -0x2F40 # unk_CD0C0
This then adds 0xD0C0 to it, which is -12,096 decimal.

When you add 851,968 + (-12,096) you get 839,872, which is 0xCD0C0.

BAM! just like that! Thanks for everyones input!

Brian

  systmu   March 11, 2011 14:23.19 CST
Igorsk:  How do I set the r2 or rtoc base in IDA? Thanks


> igorsk:
>
> P.S. IDA 6.1 will have an option to set the r13 base, similar to thr current rtoc/r2 setting.

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit