def find_selector_implementations(binary): print(f"Analyzing Mach-O slice built for {CPU_TYPE(binary.cpu_type).name}") analyzer = MachoAnalyzer(binary) desired_selector = "URLSession:didReceiveChallenge:completionHandler:" implementations = analyzer.get_imps_for_sel(desired_selector) for imp_function in implementations: instruction_size = 4 instruction_count = int( (imp_function.end_address - imp_function.start_address) / instruction_size) print( f"Found implementation of @selector({desired_selector}) at [{hex(imp_function.start_address)}" f" - {hex(imp_function.end_address)}] ({instruction_count} instructions)" )
from strongarm.macho import MachoAnalyzer, MachoParser from strongarm.objc import CodeSearch, CodeSearchTermCallDestination binary = MachoParser("./tests/bin/StrongarmTarget").get_arm64_slice() analyzer = MachoAnalyzer(binary) # we do not specify a class, because this is an NSURLSessionDelegate method and we don't # know which class will implement it desired_selector = "URLSession:didReceiveChallenge:completionHandler:" implementations = analyzer.get_imps_for_sel(desired_selector) for imp_function in implementations: log_search = CodeSearch( [CodeSearchTermCallDestination(binary, invokes_symbol="_NSLog")]) for search_result in imp_function.search_call_graph(log_search): function_containing_log_call = search_result.found_function print( f"Found a reachable code branch which calls NSLog originating from source function" f" {hex(function_containing_log_call.start_address)} at {hex(search_result.found_instruction.address)}" )