私は、2 つの値の間の 16 進文字列のインスタンスを 16 進ファイルから検索するプログラムを作成しようとしています。D4135B と D414AC の間で、最初の値から 2 番目の値に到達するまでの間をインクリメントします- D4135B、D4135C、D4135D など。なんとかインクリメントなどを取得できましたが、それは私が問題を抱えている検索部分です。これは私がこれまでに持っているコードです。他の場所から一緒に石畳にされており、何らかの方法ですべての検索ヒットを出力ファイル (file_out) に出力する必要があります。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')