首页 > 苹果『iOS』 > 发个以前的ithmb解析的代码

发个以前的ithmb解析的代码

原理请参考:
http://bbs.pediy.com/showthread.php?t=187820

代码是python的,只处理到iOS7 ,对于8 和9 没有做处理,也没做分析。如果有童鞋感兴趣可以完善这份代码。如果有任何修改,请在帖子中说明,感谢大家对共享精神的支持。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
######################################################################################
#iThmbUnpacker by obaby 
#Unpack the .ithmb file 
#Date:2014.5.15 
#Site:http://www.h4ck.org.cn
######################################################################################
 
import sys
import os,os.path,platform,struct
 
 
def ithmbunpack120(filename):
        i120width=120
        i120height=120
        i120size=i120height*i120width*2
 
        i120header_data=b'BM'
        i120header_data+=struct.pack('l', i120size+0x36)
        i120header_data+=b'\x00\x00\x00\x00\x36\x00\x00\x00\x28\x00\x00\x00'
        i120header_data+=struct.pack('l', i120width)+struct.pack('l', -i120height)
        i120header_data+=b'\x01\x00\x10\x00\x00\x00\x00\x00'
        i120header_data+=struct.pack('l', i120size)
        i120header_data+=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        infile =open(filename,'rb')
        bitmapfileno =1
        while True:
                data = infile.read(i120size)
                outfile = open(os.path.dirname(os.path.realpath(__file__))+'/bmp120/'+str(bitmapfileno) +'.bmp','wb+')
                outfile.write(i120header_data)
                outfile.write(data)
                outfile.close
                infile.read(28)
                bitmapfileno = bitmapfileno+1
                if not data:break
 
def ithmbunpack158(filename):
        width=160
        height=158
        size=height*width*2
 
        header_data=b'BM'
        header_data+=struct.pack('l', size+0x36)
        header_data+=b'\x00\x00\x00\x00\x36\x00\x00\x00\x28\x00\x00\x00'
        header_data+=struct.pack('l', width)+struct.pack('l', -height)
        header_data+=b'\x01\x00\x10\x00\x00\x00\x00\x00'
        header_data+=struct.pack('l', size)
        header_data+=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        infile =open(filename,'rb')
        bitmapfileno =1
        while True:
                data = infile.read(size)
                outfile = open(os.path.dirname(os.path.realpath(__file__))+'/bmp158/'+str(bitmapfileno) +'.bmp','wb+')
                outfile.write(header_data)
                outfile.write(data)
                outfile.close
                infile.read(28)
                bitmapfileno = bitmapfileno+1
                if not data:break
 
def PrintRuler():
        for i in range(0,16):    
            print "%3s" % hex(i) ,    
        print    
        for i in range(0,16):    
            print "%-3s" % "#" ,    
        print
 
def iOS7ithmb2Pix(ithmb):
        return{
                "3303":22,
                "3309":64,
                "3319":157,
                "4031":120
                }.get(ithmb,110)
######################################################################################
#ithmb type in iOS7:
#               iOS7type Width Height RealWidth RealHeight
#                 3303 [24  22 ]
#                 3309 [64  64]
#                 3319 [160 157]
#                 3141 [160 158 150 150 true true 2],
#                 3041 [80 79 75 75 true true 1],
#                 
#                 4131 [240 240 240 240 false],
#                 4031 [120 120 120 120 false],
#                 4132 [64 64 64 64 false],
#                 4032 [32 32 32 32 false],
#                 
#                 4140 [336 332 304 332 false false 4],
#                 4040 [168 166 152 166 false false 2],
######################################################################################
def ithmbunpack(filename):
 
        ifilename = os.path.basename(filename)
        if (ifilename.find("x") != -1):
                itmbsize = int(ifilename.split(".")[0].split("x")[0])
        else:
                itmbsize = iOS7ithmb2Pix(ifilename.split(".")[0])
 
        print ('The bitmap is in resoulation :'+str(itmbsize))
 
        PrintRuler()
 
        if itmbsize ==22: #done
                width =24
                height =22
        if itmbsize ==64:
                width =64
                height =64
        if itmbsize ==157: #done 
                width =160
                height =157
 
        if itmbsize == 32:
                width =32
                height = 32
        if itmbsize == 79:
                width = 80
                height = 79
        if itmbsize == 120:
                width = 120
                height = 120
        if itmbsize == 158:
                width =160
                height = 158
        if itmbsize == 166:
                width = 168
                height = 166
 
 
        size=height*width*2
 
        header_data=b'BM'
        header_data+=struct.pack('l', size+0x36)
        header_data+=b'\x00\x00\x00\x00\x36\x00\x00\x00\x28\x00\x00\x00'
        header_data+=struct.pack('l', width)+struct.pack('l', -height)
        header_data+=b'\x01\x00\x10\x00\x00\x00\x00\x00'
        header_data+=struct.pack('l', size)
        header_data+=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        infile =open(filename,'rb')
        bitmapfileno =1
        while True:
                data = infile.read(size)
                outfile = open(os.path.dirname(os.path.realpath(__file__))+'/bmp/'+str(bitmapfileno) +'.bmp','wb+')
                outfile.write(header_data)
                outfile.write(data)
                outfile.close
                #infile.read(28) #print the data between the bitmap file
                index= 0
                for f in range (0,28):
                        temp=infile.read(1)    
                        if len(temp) == 0:    
                                break    
                        else:    
                                print "%3s" % temp.encode('hex'),    
                                index=index+1    
                        if index == 16:    
                                index=0    
                                print
                print("\n")
 
                bitmapfileno = bitmapfileno+1
                if not data:break
        print("\nTotal: " + str(bitmapfileno) +" unpacked!")
 
 
def printusage():
        print("================================================================")
        print(sys.argv[0].split("\\")[-1] + " By obaby")
        print("Usage:\n    " +sys.argv[0].split("\\")[-1] + " < .ithmb>")
        print(".ithmb is the file u want to unpacked!")
        print("================================================================")
  pass
 
if __name__=="__main__":
 
        if len(sys.argv)>1:
                filename = sys.argv[1]
                print("================================================================")
                print(sys.argv[0].split("\\")[-1] + " By obaby \n")
                print("Start to unpack the file :\n    " + filename)
                ithmbunpack(filename)
                print("================================================================")                
  else:
                printusage()

bitbucket 链接:https://bitbucket.org/obaby/ithmbunpacker

原创文章,转载请注明: 转载自 火星信息安全研究院

本文标题: 《发个以前的ithmb解析的代码》

本文链接地址: http://h4ck.org.cn/2016/03/%e5%8f%91%e4%b8%aa%e4%bb%a5%e5%89%8d%e7%9a%84ithmb%e8%a7%a3%e6%9e%90%e7%9a%84%e4%bb%a3%e7%a0%81/

  1. 还没有评论
评论提交中, 请稍候...

留言

可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Trackbacks & Pingbacks ( 1 )
  1. 3月 21st, 2016 @ 22:06 | #1
    Pingback: 发个以前的ithmb解析的代码 – 开发啦-开发啦