Fix function reference

This commit is contained in:
hyugogirubato 2024-07-07 10:22:21 +02:00
parent 97764dfb67
commit 35fb6179ff
2 changed files with 10 additions and 8 deletions

View File

@ -105,7 +105,7 @@ def main() -> None:
cdm.set_challenge(data=args.challenge) cdm.set_challenge(data=args.challenge)
# Initialize Core instance for interacting with the device # Initialize Core instance for interacting with the device
core = Core(cdm=cdm, device=args.device, symbols=args.functions) core = Core(cdm=cdm, device=args.device, functions=args.functions)
# Process watcher loop # Process watcher loop
logger.info('Watcher delay: %ss' % args.delay) logger.info('Watcher delay: %ss' % args.delay)

View File

@ -18,14 +18,14 @@ class Core:
Core class for handling DRM operations and device interactions. Core class for handling DRM operations and device interactions.
""" """
def __init__(self, cdm: Cdm, device: str = None, symbols: Path = None): def __init__(self, cdm: Cdm, device: str = None, functions: Path = None):
""" """
Initializes a Core instance. Initializes a Core instance.
Args: Args:
cdm (Cdm): Instance of Cdm for managing DRM related operations. cdm (Cdm): Instance of Cdm for managing DRM related operations.
device (str, optional): ID of the Android device to connect to via ADB. Defaults to None (uses USB device). device (str, optional): ID of the Android device to connect to via ADB. Defaults to None (uses USB device).
symbols (Path, optional): Path to Ghidra XML functions file for symbol extraction. Defaults to None. functions (Path, optional): Path to Ghidra XML functions file for symbol extraction. Defaults to None.
""" """
self.logger = logging.getLogger(self.__class__.__name__) self.logger = logging.getLogger(self.__class__.__name__)
self.running = True self.running = True
@ -37,11 +37,12 @@ class Core:
# Obtain device properties # Obtain device properties
properties = self.device_properties() properties = self.device_properties()
self.logger.info('SDK API: %s', properties['ro.build.version.sdk']) self.sdk_api = properties['ro.build.version.sdk']
self.logger.info('SDK API: %s', self.sdk_api)
self.logger.info('ABI CPU: %s', properties['ro.product.cpu.abi']) self.logger.info('ABI CPU: %s', properties['ro.product.cpu.abi'])
# Load the hook script # Load the hook script
self.symbols = self.__prepare_symbols(symbols) self.functions = functions
self.script = self.__prepare_hook_script() self.script = self.__prepare_hook_script()
self.logger.info('Script loaded successfully') self.logger.info('Script loaded successfully')
@ -53,12 +54,13 @@ class Core:
str: The prepared script content. str: The prepared script content.
""" """
content = Path(__file__).with_name('keydive.js').read_text() content = Path(__file__).with_name('keydive.js').read_text()
symbols = self.__prepare_symbols(self.functions)
# Replace placeholders in script template # Replace placeholders in script template
replacements = { replacements = {
'${OEM_CRYPTO_API}': json.dumps(list(OEM_CRYPTO_API)), '${OEM_CRYPTO_API}': json.dumps(list(OEM_CRYPTO_API)),
'${NATIVE_C_API}': json.dumps(list(NATIVE_C_API)), '${NATIVE_C_API}': json.dumps(list(NATIVE_C_API)),
'${SYMBOLS}': json.dumps(self.symbols) '${SYMBOLS}': json.dumps(symbols)
} }
for placeholder, value in replacements.items(): for placeholder, value in replacements.items():
@ -222,9 +224,9 @@ class Core:
self.logger.info('Library: %s (%s)', library['name'], library['path']) self.logger.info('Library: %s (%s)', library['name'], library['path'])
# Check if Ghidra XML functions loaded # Check if Ghidra XML functions loaded
if vendor.oem > 17 and not self.symbols: if vendor.oem > 17 and not self.functions:
self.logger.warning('For OEM API > 17, specifying "functions" is required, refer to https://github.com/hyugogirubato/KeyDive/blob/main/docs/FUNCTIONS.md') self.logger.warning('For OEM API > 17, specifying "functions" is required, refer to https://github.com/hyugogirubato/KeyDive/blob/main/docs/FUNCTIONS.md')
elif vendor.oem < 18 and self.symbols: elif vendor.oem < 18 and self.functions:
self.logger.warning('The "functions" attribute is deprecated for OEM API < 18') self.logger.warning('The "functions" attribute is deprecated for OEM API < 18')
return script.exports_sync.hooklibrary(vendor.name) return script.exports_sync.hooklibrary(vendor.name)