29 lines
972 B
Python
29 lines
972 B
Python
import io
|
|
from .matcher import SignatureMatcher, Match
|
|
|
|
class FlattenDeviceTree(SignatureMatcher):
|
|
def __init__(self, file):
|
|
self.name = "Flatten Device Tree"
|
|
self.signature = b'\xd0\x0d\xfe\xed'
|
|
super().__init__(file)
|
|
|
|
def is_valid(self):
|
|
for match in self.search():
|
|
start = match
|
|
header = io.BytesIO(self.file[start:start+4*10])
|
|
magic = header.read(4)
|
|
totalsize = header.read(4)
|
|
off_dt_struct = header.read(4)
|
|
off_dt_strings = header.read(4)
|
|
off_mem_rsvmap = header.read(4)
|
|
version = header.read(4)
|
|
last_comp_version = header.read(4)
|
|
boot_cpuid_phys = header.read(4)
|
|
size_dt_strings = header.read(4)
|
|
size_dt_struct = header.read(4)
|
|
|
|
totalsize = int.from_bytes(totalsize, 'little')
|
|
self.matches += [Match(start, totalsize)]
|
|
|
|
return len(self.matches) != 0
|