mirror of
https://github.com/Karmaz95/Snake_Apple.git
synced 2026-03-30 14:00:16 +02:00
Update to lief 15.0.1
This commit is contained in:
@@ -5,21 +5,21 @@ import sys
|
||||
import argparse
|
||||
|
||||
class MachOFileFinder:
|
||||
'''Class for finding ARM64 Mach-O binaries in a given directory.'''
|
||||
'''Class for finding Mach-O binaries in a given directory, with an option to filter for ARM64 architecture only.'''
|
||||
|
||||
def __init__(self, directory_path, recursive=False):
|
||||
'''Constructor to initialize the directory path and recursive flag.'''
|
||||
def __init__(self, directory_path, recursive=False, only_arm64=False):
|
||||
'''Constructor to initialize the directory path, recursive flag, and architecture filter.'''
|
||||
self.directory_path = directory_path
|
||||
self.recursive = recursive
|
||||
self.only_arm64 = only_arm64
|
||||
|
||||
def parse_fat_binary(self, binaries):
|
||||
'''Function to parse Mach-O file, whether compiled for multiple architectures or just for a single one.
|
||||
It returns the ARM64 binary if it exists. If not, it exits the program.'''
|
||||
arm64_bin = None
|
||||
'''Function to parse Mach-O files and check for architecture type.
|
||||
If only_arm64 is set, it returns only ARM64 binaries; otherwise, it returns the first valid binary.'''
|
||||
for binary in binaries:
|
||||
if binary.header.cpu_type == lief.MachO.CPU_TYPES.ARM64:
|
||||
arm64_bin = binary
|
||||
return arm64_bin
|
||||
if not self.only_arm64 or binary.header.cpu_type == lief.MachO.Header.CPU_TYPE.ARM64:
|
||||
return binary
|
||||
return None
|
||||
|
||||
def process_directory(self, root, files):
|
||||
'''Method to process all files in the specified directory.'''
|
||||
@@ -42,9 +42,10 @@ class MachOFileFinder:
|
||||
break # Break the loop if not searching recursively
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='Find ARM64 Mach-O binaries in a directory.')
|
||||
parser = argparse.ArgumentParser(description='Find Mach-O binaries in a directory with an option to filter for ARM64.')
|
||||
parser.add_argument('path', metavar='PATH', type=str, help='the directory path to search for Mach-O binaries')
|
||||
parser.add_argument('-r', '--recursive', action='store_true', help='search recursively (default: false)')
|
||||
parser.add_argument('--only_arm64', action='store_true', help='only match ARM64 architecture binaries')
|
||||
|
||||
args = parser.parse_args()
|
||||
directory_path = args.path
|
||||
@@ -53,5 +54,5 @@ if __name__ == "__main__":
|
||||
print(f"Error: {directory_path} is not a valid directory.")
|
||||
sys.exit(1)
|
||||
|
||||
macho_finder = MachOFileFinder(directory_path, recursive=args.recursive)
|
||||
macho_finder.process_files()
|
||||
macho_finder = MachOFileFinder(directory_path, recursive=args.recursive, only_arm64=args.only_arm64)
|
||||
macho_finder.process_files()
|
||||
Reference in New Issue
Block a user