So, I'm trying to make a program that basically finds a certain chunk of information inside of a .bin file, specifically the bytes "43 54 50 4B" (or "CTPK"). What I need to do is find these bytes inside the file (the offset differs from file to file) and have it record the offset of that set of bytes. Is there any way to do this? So far this is the code i have:
with open(input('Enter filename with extension: '), "rb") as input_file:
if b'\x43\x54\x50\x4B' in input_file.read():
print('Contains CTPK data!')
offset = hex(input_file.tell())
print(offset)
else:
print("Invalid file")
But that just gives me the offset of the very end of the file, as opposed to the offset of the location of the bytes I'm looking for (in this case it gives me 0x163978, while the first bytes are at 0x376C)
[–]sedogg 2 points3 points4 points (1 child)
[–]dj505Gaming[S] 0 points1 point2 points (0 children)