Here's my code:
with open("SomeFile", mode="rb") as file:
byte = file.read(1)
count = 0
previous = []
while byte != b"":
if len(previous) >= 2:
addr = bytearray(b'')
addr.append(previous[len(previous) - 2])
addr.append(previous[len(previous) - 1])
addr.append(byte)
addr.append(b'\x00')
addr_int = int.from_bytes(addr, 'little')
# 0x105df0 == 1072624d
addr_rel = 1072624 - count;
if (addr_int == addr_rel):
print(hex(count))
previous.append(byte)
if len(previous) > 2:
previous.pop(0)
byte = file.read(1)
count += 1
I followed the method in this question (Python bytes concatenation) but got the error Python Error TypeError: 'bytes' object cannot be interpreted as an integer at line addr.append(previous[len(previous) - 2])
How should I concatenate the bytes from the "previous" array to the "addr" byte sequence?
EDIT:
I found the following method works, but it seems very inefficient as the constructor is called 5 times so I would still like to know the correct way to do it:
addr = bytearray(b'')
addr.extend(bytearray(previous[len(previous) - 2]))
addr.extend(bytearray(previous[len(previous) - 1]))
addr.extend(bytearray(byte))
addr.extend(bytearray(b'\x00'))
