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

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

var classLoaderDef = Java.use('java.lang.ClassLoader');
var loadClass = classLoaderDef.loadClass.overload('java.lang.String', 'boolean');
var internalClasses = [ "android.", "org.", "com.google.", "java.", "androidx."];

/* taken from https://github.com/eybisi/nwaystounpackmobilemalware/blob/master/dereflect.js */
loadClass.implementation = function(class_name, resolve) {
    var isGood = true;
    for (var i = 0; i < internalClasses.length; i++) {
        if (class_name.startsWith(internalClasses[i])) {
            isGood = false;
        }
    }
    if (isGood) {
        agPacket({class_name: class_name}).send();
    }
    return loadClass.call(this, class_name, resolve);
}