0
我(試圖)編寫一個程序,通過十六進制文件搜索兩個值之間的十六進制字符串實例,例如。在D4135B和D414AC之間,在第一個值之間遞增,直到達到第二個值--D4135B,D4135C,D4135D等等。 我設法讓它增加等,但它是我遇到的搜索部分。 這是我到目前爲止的代碼,它已經從其他地方拼湊在一起,我需要使它以某種方式將所有搜索命中輸出到輸出文件(file_out) 我已經超出了我對Python的理解的限制,我確信這可能是一個更簡單的方法。我會非常感謝任何幫助。在文件中搜索兩個值之間的匹配並在Python中輸出搜索匹配
def search_process(hx): # searching for two binary strings
global FLAG
while threeByteHexPlusOne != threeByteHex2: #Keep incrementing until second value reached
If Flag:
if hx.find(threeByteHex2) != -1:
FLAG = False #If threeByteHex = ThreeByteHexPlusOne, end search
Print (「Reached the end of the search」,hx.find(threeByteHexPlusOne))
Else:
If hx.find(threeByteHexPlusOne) != -1:
FLAG = True
Return -1 #If no results found
if __name__ == '__main__':
try:
file_in = open(FILE_IN, "r") #opening input file
file_out = open(FILE_OUT, 'w') #opening output file
hx_read = file_in.read #read from input file
tmp = ''
found = ''
while hx_read: #reading from file till file is empty
hx_read = tmp + hx_read
pos = search_process(hx_read)
while pos != -1:
hex_read = hx_read[pos:]
if FLAG:
found = found + hx_read
pos = search_process(hx_read)
tmp = bytes_read[]
hx_read = file_in.read
file_out.write(found) #writing to output file
except IOError:
print('FILE NOT FOUND!!! Check your filename or directory/PATH')
所以...當你運行它時會發生什麼一些更多的信息?它會拋出異常嗎?此外,縮進和情況是混亂的。 – 2013-05-03 15:39:03