Index: emcore/trunk/tools/libipodcrypto.py |
— | — | @@ -144,74 +144,42 @@ |
145 | 145 | emcore.free(addr)
|
146 | 146 | return data
|
147 | 147 |
|
| 148 | +def fileoperation(infilepath, outfilepath, function):
|
| 149 | + with open(infilepath, "rb") as infile:
|
| 150 | + infiledata = infile.read()
|
| 151 | +
|
| 152 | + try:
|
| 153 | + outfiledata = function(infiledata)
|
| 154 | + except:
|
| 155 | + os.remove(outfilepath)
|
| 156 | + raise
|
| 157 | +
|
| 158 | + with open(outfilepath, "wb") as outfile:
|
| 159 | + outfile.write(outfiledata)
|
148 | 160 |
|
149 | 161 | def s5l8701cryptdfufile(infile, outfile):
|
150 | | - infile = open(infile, "rb")
|
151 | | - outfile = open(outfile, "wb")
|
152 | | - outfile.write(s5l8701cryptdfu(infile.read()))
|
153 | | - infile.close()
|
154 | | - outfile.close()
|
| 162 | + fileoperation(infile, outfile, s5l8701cryptdfu)
|
155 | 163 |
|
156 | | -
|
157 | 164 | def s5l8701decryptdfufile(infile, outfile):
|
158 | | - infile = open(infile, "rb")
|
159 | | - outfile = open(outfile, "wb")
|
160 | | - outfile.write(s5l8701decryptdfu(infile.read()))
|
161 | | - infile.close()
|
162 | | - outfile.close()
|
| 165 | + fileoperation(infile, outfile, s5l8701decryptdfu)
|
163 | 166 |
|
164 | | -
|
165 | 167 | def s5l8701cryptfirmwarefile(infile, outfile):
|
166 | | - infile = open(infile, "rb")
|
167 | | - outfile = open(outfile, "wb")
|
168 | | - outfile.write(s5l8701cryptfirmware(infile.read()))
|
169 | | - infile.close()
|
170 | | - outfile.close()
|
| 168 | + fileoperation(infile, outfile, s5l8701cryptfirmware)
|
171 | 169 |
|
172 | | -
|
173 | 170 | def s5l8701decryptfirmwarefile(infile, outfile):
|
174 | | - infile = open(infile, "rb")
|
175 | | - outfile = open(outfile, "wb")
|
176 | | - outfile.write(s5l8701decryptfirmware(infile.read()))
|
177 | | - infile.close()
|
178 | | - outfile.close()
|
| 171 | + fileoperation(infile, outfile, s5l8701decryptfirmware)
|
179 | 172 |
|
180 | | -
|
181 | 173 | def s5l8702cryptnorfile(infile, outfile):
|
182 | | - infile = open(infile, "rb")
|
183 | | - outfile = open(outfile, "wb")
|
184 | | - outfile.write(s5l8702cryptnor(infile.read()))
|
185 | | - infile.close()
|
186 | | - outfile.close()
|
| 174 | + fileoperation(infile, outfile, s5l8702cryptnor)
|
187 | 175 |
|
188 | | -
|
189 | 176 | def s5l8702decryptnorfile(infile, outfile):
|
190 | | - infile = open(infile, "rb")
|
191 | | - outfile = open(outfile, "wb")
|
192 | | - outfile.write(s5l8702decryptnor(infile.read()))
|
193 | | - infile.close()
|
194 | | - outfile.close()
|
| 177 | + fileoperation(infile, outfile, s5l8702decryptnor)
|
195 | 178 |
|
196 | | -
|
197 | 179 | def s5l8702genpwnagefile(infile, outfile):
|
198 | | - infile = open(infile, "rb")
|
199 | | - outfile = open(outfile, "wb")
|
200 | | - outfile.write(s5l8702genpwnage(infile.read()))
|
201 | | - infile.close()
|
202 | | - outfile.close()
|
| 180 | + fileoperation(infile, outfile, s5l8702genpwnage)
|
203 | 181 |
|
204 | | -
|
205 | 182 | def s5l8702genpwnagefile800(infile, outfile):
|
206 | | - infile = open(infile, "rb")
|
207 | | - outfile = open(outfile, "wb")
|
208 | | - outfile.write(s5l8702genpwnage800(infile.read()))
|
209 | | - infile.close()
|
210 | | - outfile.close()
|
| 183 | + fileoperation(infile, outfile, s5l8702genpwnage800)
|
211 | 184 |
|
212 | | -
|
213 | 185 | def s5l8720genpwnagefile(infile, outfile):
|
214 | | - infile = open(infile, "rb")
|
215 | | - outfile = open(outfile, "wb")
|
216 | | - outfile.write(s5l8720genpwnage(infile.read()))
|
217 | | - infile.close()
|
218 | | - outfile.close()
|
| 186 | + fileoperation(infile, outfile, s5l8720genpwnage)
|