-
-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f31c8ff
commit b2b7fb9
Showing
265 changed files
with
15,618 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
''' | ||
This script dumps the Objective-C metadata from the provided binary and | ||
generate a header-like of different structure identified. | ||
Note: this script is only working with the extended version of LIEF | ||
''' | ||
|
||
import sys | ||
import lief | ||
import argparse | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
def process(filepath: str, skip_protocols: bool = False, | ||
output_path: Optional[str] = None) -> int: | ||
target = Path(filepath) | ||
if not target.is_file(): | ||
print(f"'{target}' is not a valid file", file=sys.stderr) | ||
return 1 | ||
|
||
macho = lief.MachO.parse(target) | ||
if macho is None: | ||
print(f"Can't parse Mach-O file: {target}", file=sys.stderr) | ||
metadata = macho.at(0).objc_metadata | ||
|
||
if metadata is None: | ||
print(f"Can't parse ObjC metadata in {target}'", file=sys.stderr) | ||
return 1 | ||
|
||
if skip_protocols: | ||
output = "" | ||
for cls in metadata.classes: | ||
output += cls.to_decl() | ||
else: | ||
output = metadata.to_decl() | ||
print(output) | ||
|
||
if output_path is not None: | ||
out = Path(output_path) | ||
if out.is_dir(): | ||
out /= f"{target.name}_objc.h" | ||
out.write_text(output) | ||
print(f"Saved in {out}") | ||
else: | ||
print(f"Saved in {out}") | ||
out.write_text(output) | ||
return 0 | ||
|
||
|
||
def main() -> int: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-o', '--output', | ||
help='Output file', | ||
default=None) | ||
parser.add_argument('--skip-protocols', | ||
help='Skip ObjC protocols definition', | ||
action='store_true') | ||
parser.add_argument("file", help='Mach-O file') | ||
args = parser.parse_args() | ||
|
||
lief.logging.set_level(lief.logging.LEVEL.WARN) | ||
return process(args.file, args.skip_protocols, args.output) | ||
|
||
if __name__ == "__main__": | ||
raise SystemExit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import lief | ||
import sys | ||
|
||
pdb = lief.pdb.load(sys.argv[0]) | ||
|
||
print("arg={}, guid={}", pdb.age, pdb.guid) | ||
|
||
for sym in pdb.public_symbols: | ||
print("name={}, section={}, RVA={}", | ||
sym.name, sym.section_name, sym.RVA) | ||
|
||
for ty in pdb.types: | ||
if isinstance(ty, lief.pdb.types.Class): | ||
print("Class[name]={}", ty.name) | ||
|
||
for cu in pdb.compilation_units: | ||
print("module={}", cu.module_name) | ||
for src in cu.sources: | ||
print(" - {}", src) | ||
|
||
for func in cu.functions: | ||
print("name={}, section={}, RVA={}, code_size={}", | ||
func.name, func.section_name, func.RVA, func.code_size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.