def load_flirt_signature(path): # lazy import enables us to only require flirt here and not in IDA, for example import flirt if path.endswith(".sig"): with open(path, "rb") as f: with timing("flirt: parsing .sig: " + path): sigs = flirt.parse_sig(f.read()) elif path.endswith(".pat"): with open(path, "rb") as f: with timing("flirt: parsing .pat: " + path): sigs = flirt.parse_pat(f.read().decode("utf-8").replace( "\r\n", "\n")) elif path.endswith(".pat.gz"): with gzip.open(path, "rb") as f: with timing("flirt: parsing .pat.gz: " + path): sigs = flirt.parse_pat(f.read().decode("utf-8").replace( "\r\n", "\n")) else: raise ValueError("unexpect signature file extension: " + path) return sigs
def test_parse_pat(__EH_prolog3_pat): sigs = flirt.parse_pat(__EH_prolog3_pat) matcher = flirt.compile(sigs) matches = matcher.match(__EH_prolog3_catch_align) assert len(matches) == 1 match = matches[0] assert match.names[0] == ("__EH_prolog3_catch_align", "public", 0) assert str(match) == 'FlirtSignature("__EH_prolog3_catch_align")'
def load_flirt_signature(path): if path.endswith(".sig"): with open(path, "rb") as f: with timing("flirt: parsing .sig: " + path): sigs = flirt.parse_sig(f.read()) elif path.endswith(".pat"): with open(path, "rb") as f: with timing("flirt: parsing .pat: " + path): sigs = flirt.parse_pat(f.read().decode("utf-8").replace("\r\n", "\n")) elif path.endswith(".pat.gz"): with gzip.open(path, "rb") as f: with timing("flirt: parsing .pat.gz: " + path): sigs = flirt.parse_pat(f.read().decode("utf-8").replace("\r\n", "\n")) else: raise ValueError("unexpect signature file extension: " + path) return sigs