📚 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  >>  Arm and Com interfaces.

Topic created on: August 23, 2008 03:42 CDT by roozbeh .

I am trying to decompile a code which heavily uses com interfaces.
For doing so i tried to first decompile my own program/samples and see how it works.
But the situation is very difficult for me.
Here is my asm+code listing.


AREA |.text|, CODE, ARM

|?CreateIImage@CImageView@@AAAJXZ| PROC ; CImageView::CreateIImage

; 183  : {

|$LN13@CreateIIma|
stmdb       sp!, {r4 - r7, lr}
sub         sp, sp, #0x48
|$M45474|
mov         r6, r0

; 184  : HRESULT hr;
; 185  : if(!pStream)

ldr         r3, [r6, #0x1C]
cmp         r3, #0
bne         |$LN5@CreateIIma|
|$LN10@CreateIIma|
mov         r3, #0x16, 2

; 186  : return E_FAIL;

orr         r0, r3, #1, 18 ; 16384 (0x4000)

; 220  : }
; 221  : return hr;
; 222  : }

add         sp, sp, #0x48
ldmia       sp!, {r4 - r7, pc}
|$LN5@CreateIIma|

; 187  :
; 188  : assert (m_pImage == NULL);

ldr         r3, [r6, #0x30]
cmp         r3, #0
beq         |$LN8@CreateIIma|
ldr         r0, [pc, #0x12C]
bl          OutputDebugStringW
__debugbreak_ce
|$LN8@CreateIIma|

; 189  : hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

mov         r1, #0
mov         r0, #0
bl          CoInitializeEx
cmp         r0, #0

; 190  : if FAILED(hr)
; 191  : return E_FAIL;

bmi         |$LN10@CreateIIma|
; 192  :      -------------------------------------------------------------------------------    READ FROM HERE ---------------------------------------------
; 193  : IImagingFactory *pImgFactory = NULL;
; 194  : hr = CoCreateInstance (CLSID_ImagingFactory, NULL, SCTX_INPROC_SERVER,IID_IImagingFactory, (void **)&pImgFactory);

ldr         r3, [pc, #0x108]
ldr         r0, [pc, #0x100]
mov         r4, #0
add         lr, sp, #4
mov         r2, #1
mov         r1, #0
str         r4, [sp, #4]
str         lr, [sp]
bl          CoCreateInstance
movs        r7, r0

; 196  : if FAILED(hr)
; 197  : return E_FAIL;

bmi         |$LN10@CreateIIma|

; 198  : if (SUCCEEDED (hr))
; 199  : {
; 200  :         ImageInfo imageInfo;
; 202  :
; 203  : pImgFactory->CreateImageDecoder(pStream, DecoderInitFlagNone, &pDecoder);

ldr         r0, [sp, #4]
ldr         r1, [r6, #0x1C]
add         r3, r6, #0x20
ldr         r2, [r0]
ldr         r4, [r2, #0x24]
mov         r2, #0
mov         lr, pc
mov         pc, r4

; 204  : if (pDecoder==NULL)

ldr         r3, [r6, #0x20]
movs        r0, r3

; 205  : return E_FAIL;

beq         |$LN10@CreateIIma|

; 206  : pDecoder->GetImageInfo(&imageInfo);

ldr         r3, [r0]
add         r1, sp, #8
mov         lr, pc
ldr         pc, [r3, #0x30]

I have used python plugin + classinterface + vtables plugins all accessible from http://www.reconstructer.org/code.html.

1.
IDA pro 5.2 do not translate mov lr,pc and mov pc,r4 into something like bx r4 (i read somewhere it should).

2.
I was able to find following code LDR     R4, [R2,#IImagingFactoryVtbl.CreateImageDecoder] from ida,it was easy.
i followed instructions in this demo file http://www.reconstructer.org/papers/Practical%20COM%20code%20reconstruction.swf .
But how can i find in ida the pDecoder interface?

3.
Also it seems to me first argument in coms start from r1?right?it seems r0 is pointer to base interface?

4.
And I somehow think how it is called.
In CreateImageDecoder , add     r3, r6, #0x20 is pDecoder pointer and i guess
ldr         pc, [r3, #0x30] is also pointer to GetImageInfo,as you subtract 0x20 from 0x30 and it gives you pointer
to this function inside pDecoder.
But what is default value for r6?it is r0 from start of procedure.but what is r0?
Also because all this data is referenced by registers i dont know how to keep up with them and give them names inside ida.
Is there any automated way or...?

I hope i was clear.


Thanks.

No posts found under this topic.
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