apkpatcher package
Submodules
apkpatcher.cli module
- apkpatcher.cli.main() int
cli function
apkpatcher.conf module
conf file
Module contents
- class apkpatcher.Patcher(apk: str | Path, sdktools: str | Path, version: str, logger: Logger | None = None)
Bases:
object
- ARCH_ARM = 'arm'
- ARCH_ARM64 = 'arm64'
- ARCH_X64 = 'x64'
- ARCH_X86 = 'x86'
- ARCH_X86_64 = 'x86_64'
- AUTOLOAD_BIT = 2
- CONFIG_BIT = 1
- DEFAULT_CONFIG_NAME = 'generatedConfigFile.config'
- DEFAULT_GADGET_NAME = 'libfrida-gadget.so'
- DEFAULT_HOOKFILE_NAME = 'libhook.js.so'
- INTERNET_PERMISSION = 'android.permission.INTERNET'
- add_certificate(keycertificate: Path | str, keyalias: str, keypass: str)
Add signature certificate
- Args:
keycertificate (Path | str): certificate path keyalias (str): aliasname keypass (str): password
- add_network_certificate(cert: Path)
- calculate_sha256(file_path: Path)
Calculate the SHA-256 hash of a file.
- Parameters:
file_path – Path to the file.
- Returns:
SHA-256 hash as a hexadecimal string.
- check_libextract() bool
check if extractNativeLibs is enable and active it
- Returns:
bool: return False if we didn’t find manifest
- compute_directory_hashes(base_directory, hash_dict: dict | None = None) None
Compute SHA-256 hashes for all files in a directory and store them in a nested dictionary.
- Parameters:
base_directory – Path to the base directory.
- create_lib_arch_folders(arch)
make lib folder in the apk to put native lib
- create_security_config_xml(path_network: str)
Create security config file for add certificate
- Args:
path_network (str): path network
- delete_existing_gadget(arch_folder: Path, delete_custom_files: int = 0)
delete existing gadget inside the apk
- enable_debug_mode() bool
- enable_user_certificates(rsc: ARSC)
Enable user certificate
- Args:
rsc (pyaxml.ARSC): return ARSC file
- enable_v4_signature(file: Path | str)
enable v4 signature
- Args:
file (Path | str): v4_signature file
- extract_apk()
Extract the apk on the temporary folder
- static get_default_config_file() Path
get a default config to frida to auto start frida at launch
- get_entrypoint_class_name() str | None
get the class name of the entrypoint
- get_entrypoint_smali_path() Path | None
get the path of apk entrypoint on the smali files
- has_permission(permission_name: str) bool
Check if the apk have ‘permission_name’ as permission
- Parameters:
permission_name (str): name of the permission with format: android.permission.XXX
- Returns:
has_permission (bool): permission is present
- inject_custom_network_certificate(rsc, path_network: str)
- inject_permission_manifest(permission: str)
Inject permission on the Manifest
- inject_user_certificates_label(rsc: ARSC) str
Inject a proxy certificate directly inside the application
- Args:
rsc (pyaxml.ARSC): ARSC file (resource file of Android)
- Raises:
FileNotFoundError: raise when manifest is not found
- Returns:
str: return the path of network file
- insert_frida_lib(gadget_path: str, arch: str, config_file_path=None, auto_load_script_path=None)
Insert native lib inside the apk
- Parameters:
gadget_path (str): the path of the gadget to insert
- insert_frida_loader(frida_lib_name='frida-gadget')
inject snippet to load frida-gadget in smali code
- keep_certificate()
keep certificate after use it
- patching(gadget_to_use: str | None = None, output_file: Path | None = None, user_certificate: bool = False, splits_apk: list[Path] | None = None, entrypoint=None)
patch the apk with gadget ‘gadget_to_use’
- pause(pause: bool) None
enable a pause during the process to edit the application
- Args:
pause (bool): pause parameter
- repackage_apk(target_file: Path | None = None)
repackage the apk
- Parameters:
target_file (str) : the path of the new apk created if none, a new apk will be created with suffix “_patched.apk”
- set_arch(arch: str)
set architecture of target phone where apk would be installed
- Args:
arch (str): architecture
- set_debug()
set debug mode
- set_plugin(plugin: str | Path) None
set a plugin
- Args:
plugin (str | Path): _description_
- sign_and_zipalign(apk_path: Path, splits_apk)
sign and zipalign file
- apkpatcher.download_baksmali(output_file)
- apkpatcher.download_smali(output_file)
- apkpatcher.new_logger(level: logging._Level) Logger
- apkpatcher.plba(filename: str | Path, arch)