Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnno1962/DLKit
A rather subscript oriented interface to the dynamic linker.
https://github.com/johnno1962/DLKit
Last synced: 3 months ago
JSON representation
A rather subscript oriented interface to the dynamic linker.
- Host: GitHub
- URL: https://github.com/johnno1962/DLKit
- Owner: johnno1962
- License: mit
- Created: 2021-04-19T14:45:36.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-16T11:19:57.000Z (7 months ago)
- Last Synced: 2024-05-02T00:54:29.685Z (7 months ago)
- Language: Swift
- Homepage:
- Size: 42 KB
- Stars: 22
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DLKit
### A subscript oriented interface to the symbol tables maintained by the dynamic linker.
DLKit is intended to be a "Swifty" encapsulation of the dynamic linker APIs gleaned from
assorted manual pages and system headers. Loaded images (the main executable
or frameworks) are wrapped in the class `ImageSymbols` which you can use to lookup
symbols or find the symbol at an address less than or equal to a pointer and it's
wrapped image. ImageSymbols instances can also be iterated over in a loop
to find all symbol definitions in that image. Think of them as representing
the image/object file as bi-directional dictionaries.A couple of `ImageSymbols` subclasses represent groups of images such as
`DLKit.allImages` for all images loaded in an application or `DLKit.appImages`
for this list of images filtered to include only those in the app bundle.To look up a symbol use the allImages pseudo image:
```
if let pointer = DLKit.allImages["main"] {
```Or you can find the symbol and wrapped image for an address:
```
if let (name, image) = DLKit.allImages[pointer] else {
```There is a typealias of `UnsafePointer` to `ImageSymbols.SymbolName`
and an extension on this typealias to `"demangle"` Swift symbols to
the Swift language representation of the symbol. There is also a method
`mangle` on an image which can "re-mangle" this representation to a
symbol name provided the symbol is defined or referred to in the image.
```
let swift = name.demangled
let name = image.mangle(swift: swift)
```The subscript operators are settable and you can also "rebind" or "interpose"
a symbol in your application by assigning it to point to a new implementation:
```
DLKit.appImages["function_name"] = new_implementation
```This "rebinding" works across framework boundaries or inside an application if it has
been linked with "Other Linker Flags" -Xlinker -interposable and uses facebook's
[fishhook](https://github.com/facebook/fishhook) for rebinding indirect symbols.$Date: 2024/04/03 $