Debian Codegraph @

scripts/munger.py

raw symbols SCIP
1 #
2 # Copyright (C) 2006 Steve Ratcliffe
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 2 as
6 # published by the Free Software Foundation.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 #
14 # Author: Steve Ratcliffe
15 # Create date: 18 Dec 2006
16 #
17
18 import sys
19 from imgfile import Imgfile
20 from struct import *
21
22 def main():
23 myimg = Imgfile('gmapsupp.bad')
24 workimg = Imgfile('pp')
25
26 for dtype in ('LBL','RGN'):
27 ld1 = myimg.get_dirent(dtype)
28 ld2 = workimg.get_dirent(dtype)
29
30 # Get first block of the sub file itself
31 bl = ld1.get_block(0)
32 ld2.write_block(0, bl)
33
34 # So TRE is what kills it, investigate further.
35
36 # copy our first block
37 bl = myimg.get_block(0)
38 workimg.write_block(0, bl)
39
40 dtype = 'TRE'
41 ld1 = myimg.get_dirent(dtype)
42 ld2 = workimg.get_dirent(dtype)
43
44 ld2.get_block(0)
45 new = ld1.get_block(0)
46
47 # Works
48 #off = 0x10
49 #new = wrk[0:off] + new[off:]
50
51 off = 0x10
52 ch1 = pack("<H10s2BBB", 0x78, "GARMIN TRE", 1, 0, 7, 0x07)
53 new = ch1 + new[off:]
54 ld2.write_block(0, new)
55
56 workimg.set_time()
57 workimg.close()
58 #return
59
60 # Copy over the directory entries apart from the block numbers
61 for dtype in ('LBL', 'TRE', 'RGN'):
62 ld1 = myimg.get_dirent(dtype)
63 ld2 = workimg.get_dirent(dtype)
64
65 # existing block
66 bl = workimg.get_block(ld2.dir_block_num)
67
68 # transfer first 32 bytes from our file
69 bl2 = myimg.get_block(ld1.dir_block_num)
70 #bl[0:0x20] = bl2[0:0x20]
71 bl = bl2[0:0x20] + bl[0x20:]
72
73 # write it back
74 workimg.write_block(ld2.dir_block_num, bl)
75
76
77 if __name__ == '__main__':
78 main()