// HTTP/S Traffic Dumper — HttpURLConnection + OkHttp request/response
// Usage: frida -U -f com.target.app -l dump-all-traffic.js --no-pause
// Combine with: mitmproxy or Burp Suite on port 8080

Java.perform(function() {
    // --- HttpURLConnection ---
    try {
        var HttpURLConnection = Java.use('java.net.HttpURLConnection');
        HttpURLConnection.getInputStream.implementation = function() {
            console.log('[HTTP] ' + this.getRequestMethod() + ' ' + this.getURL().toString());
            return this.getInputStream();
        };
        HttpURLConnection.getResponseCode.implementation = function() {
            var code = this.getResponseCode();
            console.log('[HTTP] Response: ' + code + ' ' + this.getURL().toString());
            return code;
        };
    } catch(e) {}

    // --- URL.openConnection ---
    try {
        var URL = Java.use('java.net.URL');
        URL.openConnection.overload().implementation = function() {
            console.log('[URL] openConnection: ' + this.toString());
            return this.openConnection();
        };
    } catch(e) {}

    // --- OkHttp3 Request builder ---
    try {
        var RequestBuilder = Java.use('okhttp3.Request$Builder');
        RequestBuilder.build.implementation = function() {
            var req = this.build();
            console.log('[OkHttp3] ' + req.method() + ' ' + req.url().toString());
            var headers = req.headers();
            for (var i = 0; i < headers.size(); i++) {
                console.log('  Header: ' + headers.name(i) + ': ' + headers.value(i));
            }
            return req;
        };
    } catch(e) {}

    // --- WebView URL load ---
    try {
        var WebView = Java.use('android.webkit.WebView');
        WebView.loadUrl.overload('java.lang.String').implementation = function(url) {
            console.log('[WebView] loadUrl: ' + url);
            return this.loadUrl(url);
        };
    } catch(e) {}

    console.log('[RTExit] Traffic dumper loaded. Use with Burp/mitmproxy on 8080.');
});
