1

I have a file that I am attempting to read the hex from and extract the hex value between two offsets. Here's what I have so far:

import re

path = input("Enter path to file you wish to decode (include file in path):  ")
count = 0

f = open(path, 'rb')
data = f.read()
f.close()

addedon = b'\x61\x64\x64\x65\x64\x5F\x6F\x6E\x69'



regex = re.compile(addedon)

for match_obj in regex.finditer(data):
    offset = match_obj.start()
    start = offset + 9
    end = start + 9
    value = data[start] + data[end]
    print("The offset is:  " + str(start) + ":" + str(end) + " containing: " + str(type(value)))
    count += 1

print("Number found:  " + str(count))

This produces the number of occurrences and where the value I want can be found. As an example:

The offset is: 117:126 containing:

How do I get the hex value between those two numbers?

1 Answers1

0

if you want only the hexa value you can use hex(n), the function return hexa represetation, like hex(126) -> 0x7e. You can make a simple .split('x') and pick only the value of hex.