Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sqlmapproject
GitHub Repository: sqlmapproject/sqlmap
Path: blob/master/extra/dbgtool/dbgtool.py
2992 views
1
#!/usr/bin/env python
2
3
"""
4
dbgtool.py - Portable executable to ASCII debug script converter
5
6
Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)
7
See the file 'LICENSE' for copying permission
8
"""
9
10
from __future__ import print_function
11
12
import os
13
import sys
14
15
from optparse import OptionError
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):
63
print("ERROR: the provided input file '%s' is not a regular file" % inputFile)
64
sys.exit(1)
65
66
script = convert(inputFile)
67
68
if outputFile:
69
fpOut = open(outputFile, "w")
70
sys.stdout = fpOut
71
sys.stdout.write(script)
72
sys.stdout.close()
73
else:
74
print(script)
75
76
if __name__ == "__main__":
77
usage = "%s -i <input file> [-o <output file>]" % sys.argv[0]
78
parser = OptionParser(usage=usage, version="0.1")
79
80
try:
81
parser.add_option("-i", dest="inputFile", help="Input binary file")
82
83
parser.add_option("-o", dest="outputFile", help="Output debug.exe text file")
84
85
(args, _) = parser.parse_args()
86
87
if not args.inputFile:
88
parser.error("Missing the input file, -h for help")
89
90
except (OptionError, TypeError) as ex:
91
parser.error(ex)
92
93
inputFile = args.inputFile
94
outputFile = args.outputFile
95
96
main(inputFile, outputFile)
97
98