// Ripped from https://github.com/Ch0pin/medusa/ and modified to fit Androguard packets

colorLog('[+] LOADING HTTP_COMMUNICATIONS/URI.JS', {c: Color.Red});

var url_g = ''
var uriParseClz = Java.use('java.net.URI');
var uriParseClzConstruct = uriParseClz.$init.overload("java.lang.String");

uriParseClzConstruct.implementation = function(url) {
    var result = uriParseClzConstruct.call(this, url);
    agPacket({url: url}).send();
    return result;
};

var URLClz = Java.use('java.net.URL');
var urlConstruct = URLClz.$init.overload("java.lang.String");
urlConstruct.implementation = function(url) {
    var result = urlConstruct.call(this, url);
    agPacket({url: url}).send();
    return result;
};

var sysBuilderClz = tryGetClass('com.android.okhttp.Request$Builder');
if (sysBuilderClz) {
    sysBuilderClz.build.implementation = function() {
        var okRequestResult = this.build();
        var httpUrl = okRequestResult.url();
        var url = httpUrl.toString();
        agPacket({url: url, httpUrl:httpUrl}).send();
        return okRequestResult
    };
}

var builderClz = tryGetClass('okhttp3.Request$Builder');
if (builderClz) {
    var buildFunc = builderClz.build.overload();
    buildFunc.implementation = function() {
        var okRequestResult = buildFunc.call(this);
        var httpUrl = okRequestResult.url();
        var url = httpUrl.toString();
        agPacket({url: url, httpUrl:httpUrl}).send();
        return okRequestResult
    };
}

var android_net_Uri_clz = Java.use('android.net.Uri');
var android_net_Uri_clz_method_parse_u5rj = android_net_Uri_clz.parse.overload('java.lang.String');
android_net_Uri_clz_method_parse_u5rj.implementation = function(url) {
    agPacket({url: url}).send();
    return android_net_Uri_clz_method_parse_u5rj.call(android_net_Uri_clz, url);
};