Fixed multiple hook

This commit is contained in:
hyugogirubato 2024-07-16 22:52:15 +02:00
parent a9ab9551cd
commit 1f831c3f5f
2 changed files with 16 additions and 4 deletions

View File

@ -6,9 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [2.0.7] - Not released ## [2.0.7] - Not released
### Changed
- Updated display of library disabler.
### Fixed ### Fixed
- Fix disabled library address. - Fix disabled library address.
- Fixed multiple hook for library disabler.
### New Contributors ### New Contributors

View File

@ -95,20 +95,27 @@ const disableLibrary = (name) => {
// Disables all functions in the specified library by replacing their implementations. // Disables all functions in the specified library by replacing their implementations.
const library = getLibrary(name); const library = getLibrary(name);
if (library) { if (library) {
// https://github.com/hyugogirubato/KeyDive/issues/23#issuecomment-2230374415
const functions = getFunctions(library); const functions = getFunctions(library);
const disabled = [];
functions.forEach(func => { functions.forEach(func => {
if (func.type !== 'function') return; const {name: funcName, address: funcAddr} = func;
if (func.type !== 'function' || disabled.includes(funcAddr)) return;
try { try {
Interceptor.replace(func.address, new NativeCallback(function () { Interceptor.replace(funcAddr, new NativeCallback(function () {
return 0; return 0;
}, 'int', [])); }, 'int', []));
disabled.push(funcAddr);
} catch (e) { } catch (e) {
print(Level.ERROR, `${e.message} for ${func.name}`); print(Level.DEBUG, `${e.message} for ${funcName}`);
} }
}); });
print(Level.INFO, `The library ${library.name} (${library.base}) has been disabled`); print(Level.INFO, `The library ${library.name} (${library.base}) has been disabled`);
} else { } else {
print(Level.DEBUG, `The library ${name} was not found`); print(Level.INFO, `The library ${name} was not found`);
} }
} }