我正在使用python,我應該從命令行讀取文件以供進一步處理。我的輸入文件有一個二進制文件,應該讀取它以便進一步處理。這是我的輸入文件sub.py:如何在python中從命令行導入文件
CODE = " \x55\x48\x8b\x05\xb8\x13\x00\x00"
和我的主文件,它應該閱讀這是這樣的:
import pyvex
import archinfo
import fileinput
import sys
filename = sys.argv[-1]
f = open(sys.argv[-1],"r")
CODE = f.read()
f.close()
print CODE
#CODE = b"\x55\x48\x8b\x05\xb8\x13\x00\x00"
# translate an AMD64 basic block (of nops) at 0x400400 into VEX
irsb = pyvex.IRSB(CODE, 0x1000, archinfo.ArchAMD64())
# pretty-print the basic block
irsb.pp()
# this is the IR Expression of the jump target of the unconditional exit at the end of the basic block
print irsb.next
# this is the type of the unconditional exit (i.e., a call, ret, syscall, etc)
print irsb.jumpkind
# you can also pretty-print it
irsb.next.pp()
# iterate through each statement and print all the statements
for stmt in irsb.statements:
stmt.pp()
# pretty-print the IR expression representing the data, and the *type* of that IR expression written by every store statement
import pyvex
for stmt in irsb.statements:
if isinstance(stmt, pyvex.IRStmt.Store):
print "Data:",
stmt.data.pp()
print ""
print "Type:",
print stmt.data.result_type
print ""
# pretty-print the condition and jump target of every conditional exit from the basic block
for stmt in irsb.statements:
if isinstance(stmt, pyvex.IRStmt.Exit):
print "Condition:",
stmt.guard.pp()
print ""
print "Target:",
stmt.dst.pp()
print ""
# these are the types of every temp in the IRSB
print irsb.tyenv.types
# here is one way to get the type of temp 0
print irsb.tyenv.types[0]
的問題是,當我運行「蟒蛇maincode.py子。 py'它將代碼作爲文件的內容讀取,但其輸出與直接將CODE添加到語句irsb = pyvex.IRSB(CODE, 0x1000, archinfo.ArchAMD64())
中的輸出完全不同。有誰知道什麼是問題,我該如何解決它?我甚至使用從輸入文件導入,但它不會讀取文字
請分享輸出獲得並指出您實際預期的輸出。 –