Skip to content

Commit

Permalink
Drop resolved APIs which aren't actual exports
Browse files Browse the repository at this point in the history
  • Loading branch information
ergrelet committed Jul 18, 2022
1 parent dd62165 commit 615392a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion unlicense/frida_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def enumerate_exported_functions(self,
) -> Dict[int, Dict[str, Any]]:
if self._exported_functions_cache is None or update_cache:
value: List[Dict[
str, Any]] = self._frida_rpc.enumerate_exported_functions()
str, Any]] = self._frida_rpc.enumerate_exported_functions(
self.main_module_name)
exports_dict = {int(e["address"], 16): e for e in value}
self._exported_functions_cache = exports_dict
return exports_dict
Expand Down
12 changes: 9 additions & 3 deletions unlicense/resources/frida.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,17 @@ rpc.exports = {
return module != null && module.name.toUpperCase() == moduleName.toUpperCase();
});
},
enumerateExportedFunctions: function () {
enumerateExportedFunctions: function (excludedModuleName) {
const modules = Process.enumerateModules();
let exports = [];
modules.forEach(module => {
exports = exports.concat(module.enumerateExports());
modules.forEach(m => {
if (m.name != excludedModuleName) {
m.enumerateExports().forEach(e => {
if (e.type == "function") {
exports = exports.concat(e);
}
});
}
});
return exports;
},
Expand Down
16 changes: 12 additions & 4 deletions unlicense/winlicense3.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,18 @@ def in_main_module(address: int) -> bool:
process_controller.write_process_memory(
iat_range.base, list(new_iat_data))
return len(new_iat_data), resolved_import_count
LOG.debug("Resolved API: %s -> %s", hex(wrapper_start),
hex(resolved_api))
new_iat_data += struct.pack(ptr_format, resolved_api)
resolved_import_count += 1

if resolved_api not in exports_dict:
# TODO: Investigate. When TLS callbacks are used,
# `kernel32.ExitProcess` might not be resolved properly.
LOG.warn(
"A resolved API isn't an export, it'll be ignored.")
new_iat_data += struct.pack(ptr_format, 0)
else:
LOG.debug("Resolved API: %s -> %s", hex(wrapper_start),
hex(resolved_api))
new_iat_data += struct.pack(ptr_format, resolved_api)
resolved_import_count += 1
elif wrapper_start in exports_dict:
# Not wrapped, add as is
new_iat_data += struct.pack(ptr_format, wrapper_start)
Expand Down

0 comments on commit 615392a

Please sign in to comment.