summaryrefslogtreecommitdiff
path: root/apple-efi-dump-verbs.py
blob: c79b7c449f7fb91bd6c6afc4ea51c221bee72220 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
import argparse
import sys
import os
import struct

def main():
    parser = argparse.ArgumentParser(description="Dump verbs from Apple EFI resource file")
    parser.add_argument("file", nargs=1, help="Path to file")
    parser.add_argument("--decode", action="store_true")

    args = parser.parse_args()

    file = args.file[0]
    if not os.path.isfile(file):
        return "%s does not exists or is not a file" % (file)

    with open(args.file[0], "rb") as f:
        f.seek(16)
        size = struct.unpack("i", f.read(4))[0]

        for i in range(int(size / 8)):
            val = struct.unpack("i", f.read(4))[0]
            print("0x{0:08X}".format(val), end="")
            if (args.decode):
                node_id = (val >> 20) & 0xffff
                verb_id = (val >> 8) & 0xffff
                payload = val & 0xffff
                print(" (0x{0:02x} 0x{1:04x} 0x{2:02x})".format(node_id, verb_id, payload), end="")
            print()

if __name__ == "__main__":
    result = main()
    if result:
        print("error: %s" % result)
        sys.exit(1)