Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if file.endswith(".xml"):
tree = ET.parse(os.path.join(folder, file))
root = tree.getroot()
sig = {}
for child in root[0]:
if child.text:
sig[child.tag] = child.text
else:
for grandchild in child:
if grandchild.tag == "EXT_NAME":
sig[grandchild.tag] = grandchild.text.lower().split("|") # type: ignore
else:
sig[grandchild.tag] = grandchild.text # type: ignore
sigs.append(sig)
known_sigs = {binascii.hexlify(x[0]).decode("ascii") for x in puremagic.magic_header_array}
for sig in sigs:
sig["SIG"] = sig["SIG"].lower().strip()
try:
offset = int(sig.get("OFFSET", 0))
except Exception:
continue
if sig["SIG"] not in known_sigs and len(sig["EXT_NAME"]) == 1 and len(sig["EXT_NAME"][0]) < 5:
print(
"\t\t{},".format(
json.dumps(
[
sig["SIG"],
int(sig.get("OFFSET", 0)),
".{}".format(sig.get("EXT_NAME", "")[0]),