Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/llvm-swift/Symbolic
A Swift library for dynamically loading shared objects
https://github.com/llvm-swift/Symbolic
Last synced: 3 months ago
JSON representation
A Swift library for dynamically loading shared objects
- Host: GitHub
- URL: https://github.com/llvm-swift/Symbolic
- Owner: llvm-swift
- License: mit
- Created: 2017-11-26T02:38:00.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-26T20:33:57.000Z (almost 7 years ago)
- Last Synced: 2024-08-06T17:19:27.822Z (3 months ago)
- Language: Swift
- Size: 16.6 KB
- Stars: 68
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Symbolic
Symbolic makes it easy to get information about an executable, shared object,
or static library.## Usage
### Note
⚠️ This library is incredibly unsafe. Use it with caution! ⚠️
To dynamically load a shared object file, create a `SharedObject`, passing in
the file URL where the object resides.You can also use `SharedObject.current()` to get ahold of the object in which
your code will reside once compiled.```swift
let libFoo = SharedObject(object: URL(fileURLWithPath: "/usr/lib/libfoo.dylib"))
let myExe = SharedObject.current()
```From there, you can ask the object for the addresses of symbols in the object
and (if you're adventurous) cast function addresses to `@convention(c)`
function pointers.```swift
let libcURL = URL(fileURLWithPath: "/usr/lib/libc.dylib")
let libc = SharedObject(object: libcURL)let addr = libc.address(forSymbol: "sin") // will not be `nil`
typealias SinFn = @convention(c) (Double) -> Double
// Will perform an unsafeBitCast on your behalf!
let sinFn = libc.function(forSymbol: "sin", ofType: SinFn.self)sinFn?(0.5) // 0.4794255386
```Additionally, if you have an address in mind that you've already linked, you
can ask for it directly in your current address space:```swift
let addrInfo = SymbolInfo(address: addr)
addrInfo.symbolName // "sin"
```## Author
Harlan Haskins ([@harlanhaskins](https://github.com/harlanhaskins))
## License
This project is released under the MIT license, a copy of which is avaialable
in this repository.