MCPcopy Create free account
hub / github.com/lief-project/LIEF / process

Function process

api/python/examples/objc_dump.py:15–48  ·  view source on GitHub ↗
(filepath: str, skip_protocols: bool = False,
            output_path: Optional[str] = None)

Source from the content-addressed store, hash-verified

13from typing import Optional
14
15def process(filepath: str, skip_protocols: bool = False,
16 output_path: Optional[str] = None) -> int:
17 target = Path(filepath)
18 if not target.is_file():
19 print(f"'{target}' is not a valid file", file=sys.stderr)
20 return 1
21
22 macho = lief.MachO.parse(target)
23 if macho is None:
24 print(f"Can't parse Mach-O file: {target}", file=sys.stderr)
25 metadata = macho.at(0).objc_metadata
26
27 if metadata is None:
28 print(f"Can't parse ObjC metadata in {target}'", file=sys.stderr)
29 return 1
30
31 if skip_protocols:
32 output = ""
33 for cls in metadata.classes:
34 output += cls.to_decl()
35 else:
36 output = metadata.to_decl()
37 print(output)
38
39 if output_path is not None:
40 out = Path(output_path)
41 if out.is_dir():
42 out /= f"{target.name}_objc.h"
43 out.write_text(output)
44 print(f"Saved in {out}")
45 else:
46 print(f"Saved in {out}")
47 out.write_text(output)
48 return 0
49
50
51def main() -> int:

Callers 1

mainFunction · 0.70

Calls 4

printFunction · 0.50
parseMethod · 0.45
atMethod · 0.45
to_declMethod · 0.45

Tested by

no test coverage detected