有如下命令:
for i in $(objdump -d binary |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo
如何在我的python代码中使用此命令,然后将hexdump(print)的结果传递给控制台。
objdump = "$(objdump -d " + str(_arg_name) + "| grep '^ ' |cut -f2);" + " do echo -n $i; done; echo"
result = os.popen(objdump).read()
result = result.replace('"','')
print(result)
答案 0 :(得分:3)
您可以使用以下代码:
g1 = "grep '^ '"
g2 = "cut -f2"
objdump = "objdump -d " + str(binary) + "|" + g1 + "|" + g2
result = os.popen(objdump).read()
result = result.replace('\n','')
result = result.replace(' ','')
length = len(result) - 1
result = [r'\x' + result[i:i + 2] for i in range(0, length, 2)]
print(result)