| 16 | from optparse import OptionParser |
| 17 | |
| 18 | def convert(inputFile): |
| 19 | fileStat = os.stat(inputFile) |
| 20 | fileSize = fileStat.st_size |
| 21 | |
| 22 | if fileSize > 65280: |
| 23 | print("ERROR: the provided input file '%s' is too big for debug.exe" % inputFile) |
| 24 | sys.exit(1) |
| 25 | |
| 26 | script = "n %s\nr cx\n" % os.path.basename(inputFile.replace(".", "_")) |
| 27 | script += "%x\nf 0100 ffff 00\n" % fileSize |
| 28 | scrString = "" |
| 29 | counter = 256 |
| 30 | counter2 = 0 |
| 31 | |
| 32 | fp = open(inputFile, "rb") |
| 33 | fileContent = fp.read() |
| 34 | |
| 35 | for fileChar in fileContent: |
| 36 | unsignedFileChar = fileChar if sys.version_info >= (3, 0) else ord(fileChar) |
| 37 | |
| 38 | if unsignedFileChar != 0: |
| 39 | counter2 += 1 |
| 40 | |
| 41 | if not scrString: |
| 42 | scrString = "e %0x %02x" % (counter, unsignedFileChar) |
| 43 | else: |
| 44 | scrString += " %02x" % unsignedFileChar |
| 45 | elif scrString: |
| 46 | script += "%s\n" % scrString |
| 47 | scrString = "" |
| 48 | counter2 = 0 |
| 49 | |
| 50 | counter += 1 |
| 51 | |
| 52 | if counter2 == 20: |
| 53 | script += "%s\n" % scrString |
| 54 | scrString = "" |
| 55 | counter2 = 0 |
| 56 | |
| 57 | script += "w\nq\n" |
| 58 | |
| 59 | return script |
| 60 | |
| 61 | def main(inputFile, outputFile): |
| 62 | if not os.path.isfile(inputFile): |