Im trying to find for bytes(unknown) that appear before another set of bytes that have already been found. i have a binary file that for example looks like this:
82 00 10 00 00 00 00 00 00 00 00 00 00 01 00 00
60 F8 6C 10 BF 58 87 45 87 6F 0C 61 0D 26 B0 F5
10 00 00 00 01 00 11 00 00 00 00 00 0E 00 11 00
2D 00 04 00 72 46 13 F4 18 43 C0 D2 0A 64 24 91
F3 E7 00 80 54 00 4E B2 61 00 00 08 00 00 00 00
the bytes that i know (the value and position of) is 0A 64 24 91 F3 E7
, by using this (bytes1 is inputed by user):
bytes1 = bytearray(base64.b16decode(self.txt_bytes1))
index = 0
while index < len(readfile):
index = readfile.find(bytes1, index)
if index != -1:
with open("LogFile.txt", "w") as found:
found.write("found : " + str(index))
index += 6 # +6 because len(bytes1) == 6
else:
break
so i know the starting location of bytes1. now, i want to look for the bytes that come before bytes1, which are 13 F4 18 43 C0 D2
. however, in real life situation, those bytes are unkown. the only thing known about those bytes are that they are located before bytes1 and are 6 bytes long. i want to get not the index but the string itself to be then written into a text file. i thought of range()
but didn't really know how to use it and it only works with int right? then i saw lookahead
and lookbehind
but i don't understand the docs. any help will be greatly appreciated.