我正在(尝试)编写一个程序,该程序在十六进制文件中搜索两个值之间的十六进制字符串的实例,例如。在 D4135B 和 D414AC 之间,在第一个值之间递增,直到达到第二个值 - 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')