ProxymanApp / atlantis

Capture HTTP/HTTPS, and Websocket from iOS app without proxy.
https://proxyman.io
Apache License 2.0
1.25k stars 92 forks source link

Research Swizzle with InterposeKit #1

Open NghiaTranUIT opened 3 years ago

NghiaTranUIT commented 3 years ago

Description

InterposeKit is a modern framework that provides better swizzle functions. It's crucial for atlantis since we have to swizzle the original methods from NSURLConnection or NSURLSession in order to capture the request/response on the fly.

Acceptance Criteria

NghiaTranUIT commented 3 years ago

Swizzle works fine:

class Person: NSObject {

    let name: String

    init(name: String) {
        self.name = name
    }

    @objc dynamic func sayHi() {
        print("Hi: \(name)")
    }
}

class ViewController: UIViewController {

    private var interposer: Interpose!
    override func viewDidLoad() {
        super.viewDidLoad()
        do {
            interposer = try Interpose(Person.self) {
                try $0.hook(
                    #selector(Person.sayHi),
                    methodSignature: (@convention(c) (AnyObject, Selector) -> Void).self,
                    hookSignature: (@convention(block) (AnyObject) -> Void).self) {
                        store in { `self` in
                            print("Hi: Nghia v2")
                        }
                }
            }

            let person = Person(name: "Nghia Tran")
            person.sayHi()

        } catch let error {
            print(error)
        }
    }
}
NghiaTranUIT commented 3 years ago

We decide not to use InterposeKit since it's too complicated.