views:

30

answers:

0

I'm trying to analyze programatically (python) a Symbian v9 Logical Device Driver (LDD zlib deflated).

I'm able to read E32ImageHeader, but I can't decompress de code section.

I always get "zlib.error: Error -3 while decompressing data: invalid block type"

import zlib  
import struct  

full = ""  
f = open("c:\\file.ldd","rb")  
part = f.read(1)  
while part:  
    full += part  
    part = f.read(1)  
f.close()  

# 0x1C: Compression type  
cType=struct.unpack("I",full[0x1C:0x20])[0]  
# KUidCompressionDeflate   
if cType == 0x101f7afc:  
    # 0x30: Code size offset  
    codeSize = struct.unpack("I", full[0x30:0x30+4])[0]  
    # 0x64: Offset in file to code section.  
    codeOff  = struct.unpack("I", full[0x64:0x64+4])[0]  
    code = full[codeOff:]  
    unc = zlib.decompress(code, -15)  

I'm using this references:

http://wiki.forum.nokia.com/index.php/E32Image_file_format_on_Symbian_OS_9 http://developer.symbian.org/wiki/index.php/Symbian_OS_Internals/Appendix_2:_The_E32ImageHeader

What I'm doing wrong ?

Exactly what file part is compressed ?

UPDATED:
I found one way to do it, I will prefer to use zlib to do it, but i don't know how.

Actual solution.

(...)  
import os,sys  
(..old code here..)  
res=os.system('elftran -nocompress file.ldd')  
if res==0:  
    f2=open('file.ldd','rb')  
    # inflated file
    unfull = f2.read()  
    f2.close()  
(...)  
# apply patchs here
(...)
# re-deflate
os.system('elftran -compress file.ldd')