patcher-template 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. import sys
  18. from libb43 import *
  19. if len(sys.argv) != 3 and len(sys.argv) != 2:
  20. print "Usage: %s INPUT_FILE [OUTPUT_FILE]" % sys.argv[0]
  21. sys.exit(1)
  22. infile = sys.argv[1]
  23. outfile = None
  24. if len(sys.argv) == 3:
  25. outfile = sys.argv[2]
  26. try:
  27. asm = Disassembler(file(infile).read(), "").getAsm()
  28. p = TextPatcher(asm, "c053515533b60977d212fbcfa4fc2546") # TODO adjust the MD5SUM
  29. # TODO
  30. # Use p.addText() and p.delLine() for modifying the code
  31. if outfile:
  32. bin = Assembler(p.getText(), "--psize").getBinary()
  33. file(outfile, "w").write(bin)
  34. else:
  35. sys.stdout.write(p.getText())
  36. except B43Exception:
  37. print "Could not patch. Do you use the correct input file?"
  38. sys.exit(1)