fwcutter/make: Avoid _DEFAULT_SOURCE warning
[b43-tools.git] / debug / patcher-template
1 #!/usr/bin/env python
2 """
3 #  Copyright (C) 2008 Michael Buesch <m@bues.ch>
4 #
5 #  This program is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License version 3
7 #  as published by the Free Software Foundation.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 """
17
18 import sys
19 from libb43 import *
20
21
22 if len(sys.argv) != 3 and len(sys.argv) != 2:
23         print "Usage: %s INPUT_FILE [OUTPUT_FILE]" % sys.argv[0]
24         sys.exit(1)
25
26 infile = sys.argv[1]
27 outfile = None
28 if len(sys.argv) == 3:
29         outfile = sys.argv[2]
30
31 try:
32
33         asm = Disassembler(file(infile).read(), "").getAsm()
34         p = TextPatcher(asm, "c053515533b60977d212fbcfa4fc2546") # TODO adjust the MD5SUM
35
36         # TODO
37         # Use p.addText() and p.delLine() for modifying the code
38
39         if outfile:
40                 bin = Assembler(p.getText(), "--psize").getBinary()
41                 file(outfile, "w").write(bin)
42         else:
43                 sys.stdout.write(p.getText())
44
45 except B43Exception:
46         print "Could not patch. Do you use the correct input file?"
47         sys.exit(1)