import io from PyRomfsImage import * from .matcher import SignatureMatcher, Match class RomFS(SignatureMatcher): """ RomFS a readonly file system big-endian https://www.kernel.org/doc/Documentation/filesystems/romfs.txt """ def __init__(self, file): self.name = "RomFS" self.signature = b'-rom1fs-' super().__init__(file) def is_valid(self): for match in self.search(): start = match header = io.BytesIO(self.file[start:start+14]) magic = header.read(8) fullsize = header.read(4) checksum = header.read(4) fullsize = int.from_bytes(fullsize, 'big') self.matches += [Match(start, fullsize)] return len(self.matches) != 0 def view(self, match): start = match.offset length = match.length raw = io.BytesIO(self.file[start:start+length]) rom = Romfs(raw) root = rom.getRoot() print(root.name) for ch in root.children: print(ch.name)