Frida 17.30.0 Released ∞
release
More work on modules, this time for ELF. Looking up an export of a module now only finds what that module itself defines, and on Android it works for a library the linker is still busy loading, which is exactly when a module observer wants to hook it. @hsorbo also fixed fractional numbers being truncated by the Node.js bindings, and added a way to send a number as a double over XPC.
Exports stay local
On ELF platforms, Module#findExportByName() asked the dynamic linker, through a handle to the module. Such a lookup also searches the module’s dependencies, so asking a library for a symbol that one of its dependencies defines would find it there, and return an address outside the module. That is no longer the case: an address outside the module’s range is only accepted when the module’s own dynamic symbol table defines the symbol.
To make that check cheap, the ELF parser learned to look a dynamic symbol up by name through the module’s GNU or SysV hash table, rather than walking the table, and resolves the tables once rather than on each use. It is available as gum_elf_module_find_dynamic_symbol_by_name() for those using Gum from C.
Android
Since 17.28.0, a hook attached from a module observer’s onAdded is live before the library gets to run. On Android that handler is called while the linker is still linking the library, and looking up an export meant asking the linker for a handle to it. Two changes deal with that. We no longer open a handle to a module that isn’t fully linked. And with Android’s own linker, exports are now looked up in the module’s dynamic symbol table, without a handle at all. Only IFUNC and TLS symbols, which need the linker to resolve them, still go through it. So findExportByName() inside onAdded gives you the export.
A library that failed to load could also leave its dependencies behind in the module registry. When a library pulls in a dependency and then turns out to be unlinkable, the linker unloads both, but we had already picked up the dependency from its list. Modules are now only tracked once they show up in the debugger’s view of loaded libraries, the r_debug map.
Doubles
Håvard ran into two problems sending coordinates to a CoreDevice service. The first was in the Node.js bindings, where numbers always went through an integer conversion that truncates, so 0.5 silently became 0. Safe integers are still sent as integers, and everything else is now sent as a double.
The second is that a number that happens to be integral is marshaled as an integer, which the device rejects where it expects a double, such as a digitizer coordinate of exactly 0 or 1. There is now a type annotation to force it in XPC messages:
{ x: [Symbol('double'), 1], y: 0.5 }Thanks!
Enjoy!
Changelog
- elf: Keep export lookups local to the module.
- elf-module: Look up dynamic symbols by hash, and resolve the dynamic symbol tables once.
- android: Look up exports without a linker handle.
- android: Don’t open modules still being linked.
- android: Track modules through the r_debug map.
- fruity: Add an XPC double type annotation. Thanks @hsorbo!
- node: Marshal non-integer numbers as doubles. Thanks @hsorbo!
oleavr