GregSolidus
GregSolidus

Reputation: 23

How do I perform a wildcard search of a bytes hex value?

I'm currently trying to write a model import script for blender and the vertex coordinates within the file I need to parse through are preceded by the 8 bit header 68 * 80 04, with the decimal value of whatever "*" is identifying the number of vertices. Given that the header isn't entirely consistent throughout the file I was wondering what methods are there to perform a wildcard search of a bytes hexadecimal representation once it's read in?

Upvotes: 1

Views: 1118

Answers (1)

eigil
eigil

Reputation: 465

You could use regular expressions:

import re

with open('filename', 'rb') as file:
    bs = file.read()

matches = re.findall(b'\x68.\x80\x04', bs)

Upvotes: 1

Related Questions