我正在尝试修复从ValueError: Unknown format code 'x' for object of type 'unicode'
进行解析的parser
,将其转换为0xeb, 0x19
字节代码,
我想如何改善if format == "sc_arr":
来解决此问题
def parser(obj, syntax,format):
lines = subprocess.check_output(['objdump', '-d', '-M', syntax, obj])
lines = lines.split(b'Disassembly of section')[1]
lines = lines.split(b'\n')[3:]
shellcode = ""
code = []
for l in lines:
l = l.strip()
tabs = l.split(b'\t')
if (len(tabs) < 2):
continue
bytes = tabs[1].strip()
bytes = bytes.split(b' ')
sh3llshock = ""
if format == "sc_arr":
for byte in bytes:
sh3llshock += " " + byte.decode("utf-8")
else:
for byte in bytes:
sh3llshock += "\\x" + byte.decode("utf-8")
shellcode += sh3llshock
show_shell = (32, '"'+sh3llshock+'"')
code.append(show_shell)
return shellcode
if __name__ == '__main__':
if sys.argv[2] == "sc_app":
opcode = parser('shellcode', 'intel', sys.argv[2])
shellcode = re.sub("(.{32})", "\\1\n",opcode, 0, re.DOTALL)
print shellcode
elif sys.argv[2] == 'sc_arr':
opcode = parser('shellcode', 'intel', sys.argv[2])
print ' '.join([format(x, '02x') for x in opcode])
else:
print "not found"