| 179 |
theseven |
1 |
#!/usr/bin/env python
|
|
|
2 |
#
|
|
|
3 |
#
|
|
|
4 |
# Copyright 2010 TheSeven
|
|
|
5 |
#
|
|
|
6 |
#
|
|
|
7 |
# This file is part of TheSeven's iPod tools.
|
|
|
8 |
#
|
|
|
9 |
# TheSeven's iBugger is free software: you can redistribute it and/or
|
|
|
10 |
# modify it under the terms of the GNU General Public License as
|
|
|
11 |
# published by the Free Software Foundation, either version 2 of the
|
|
|
12 |
# License, or (at your option) any later version.
|
|
|
13 |
#
|
|
|
14 |
# TheSeven's iBugger is distributed in the hope that it will be useful,
|
|
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
17 |
# See the GNU General Public License for more details.
|
|
|
18 |
#
|
|
|
19 |
# You should have received a copy of the GNU General Public License along
|
|
|
20 |
# with TheSeven's iPod tools. If not, see <http://www.gnu.org/licenses/>.
|
|
|
21 |
#
|
|
|
22 |
#
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
import sys
|
|
|
26 |
import struct
|
|
|
27 |
|
|
|
28 |
from optparse import *
|
|
|
29 |
|
|
|
30 |
parser = OptionParser("usage: %prog [options] <infile> <outfile>")
|
|
|
31 |
parser.add_option("--signature", metavar = "SIGN",
|
|
|
32 |
help = "The device signature. Must be 4 characters, e.g. \"nn2x\". (mandantory)")
|
|
|
33 |
parser.add_option("--targetid", type = "int", metavar = "ID",
|
|
|
34 |
help = "The numeric target ID. (mandantory)")
|
|
|
35 |
(options, args) = parser.parse_args()
|
|
|
36 |
if len(args) != 2: parser.error("incorrect number of arguments")
|
|
|
37 |
if not options.signature: parser.error("please specify a device signature")
|
|
|
38 |
if not options.targetid: parser.error("please specify numeric target id")
|
|
|
39 |
if len(options.signature) != 4: parser.error("device signature must be 4 characters")
|
|
|
40 |
|
|
|
41 |
file = open(args[0], "rb")
|
|
|
42 |
data = file.read()
|
|
|
43 |
file.close()
|
|
|
44 |
|
|
|
45 |
checksum = options.targetid
|
|
|
46 |
for i in range(len(data)):
|
|
|
47 |
checksum = (checksum + struct.unpack("B", data[i])[0]) & 0xffffffff
|
|
|
48 |
|
|
|
49 |
file = open(args[1], "wb")
|
|
|
50 |
file.write(struct.pack(">I", checksum) + options.signature + data)
|
|
|
51 |
file.close()
|