Java教程

frida hook

本文主要是介绍frida hook,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
//frida hook aes
 function hook_cipher(){
    var cipher = Java.use("javax.crypto.Cipher");
    cipher.doFinal.implementation = function(data, offset, length){
        var ret = this.doFinal(data, offset, length);
        console.log("doFinal: " + ret);
        return ret;
    }
}
function hook_aes(){
    var aes = Java.use("javax.crypto.spec.SecretKeySpec");
    aes.getEncoded.implementation = function(){
        var ret = this.getEncoded();
        console.log("getEncoded: " + ret);
        return ret;
    }
}
function hook_base64(){
    var base64 = Java.use("android.util.Base64");
    base64.encodeToString.implementation = function(data, flags){
        var ret = this.encodeToString(data, flags);
        console.log("encodeToString: " + ret);
        return ret;
    }
}
function hook_md5(){
    var md5 = Java.use("java.security.MessageDigest");
    md5.digest.implementation = function(data){
        var ret = this.digest(data);
        console.log("digest: " + ret);
        return ret;
    }
}
function hook_sha1(){
    var sha1 = Java.use("java.security.MessageDigest");
    sha1.digest.implementation = function(data){
        var ret = this.digest(data);
        console.log("digest: " + ret);
        return ret;
    }
}
function hook_sha256(){
    var sha256 = Java.use("java.security.MessageDigest");
    sha256.digest.implementation = function(data){
        var ret = this.digest(data);
        console.log("digest: " + ret);
        return ret;
    }
}
function hook_sha512(){
    var sha512 = Java.use("java.security.MessageDigest");
    sha512.digest.implementation = function(data){
        var ret = this.digest(data);
        console.log("digest: " + ret);
        return ret;
    }
}
function hook_hmac(){
    var hmac = Java.use("javax.crypto.Mac");
    hmac.doFinal.implementation = function(data){
        var ret = this.doFinal(data);
        console.log("doFinal: " + ret);
        return ret;
    }
}
function hook_rsa(){
    var rsa = Java.use("java.security.interfaces.RSAPublicKey");
    rsa.getEncoded.implementation = function(){
        var ret = this.getEncoded();
        console.log("getEncoded: " + ret);
        return ret;
    }
}
function hook_map(){
    var map = Java.use("java.util.HashMap");
    map.put.implementation = function(key, value){
        var ret = this.put(key, value);
        console.log("put: " + ret);
        return ret;
    }
       
}
function hook_list(){
    var list = Java.use("java.util.ArrayList");
    list.add.implementation = function(value){
        var ret = this.add(value);
        console.log("add: " + ret);
        return ret;
    }
}
function hook_perform_click(){
    var click = Java.use("android.view.View");
    click.performClick.implementation = function(){
        var ret = this.performClick();
        console.log("performClick: " + ret);
        return ret;
    }
}
function hook_set_text(){
    var text = Java.use("android.widget.TextView");
    text.setText.implementation = function(text){
        var ret = this.setText(text);
        console.log("setText: " + ret);
        return ret;
    }
}
function hook_get_text(){
    var text = Java.use("android.widget.TextView"); 
    text.getText.implementation = function(){
        var ret = this.getText();
        console.log("getText: " + ret);
        return ret;
    }   
}
function hook_get_package_name(){
    var package_name = Java.use("android.content.Context");
    package_name.getPackageName.implementation = function(){
        var ret = this.getPackageName();
        console.log("getPackageName: " + ret);
        return ret;
    }
}
//frida byte to string 
function hook_byte_to_string(){
    var byte = Java.use("[B");
    byte.toString.implementation = function(){
        var ret = this.toString();
        console.log("toString: " + ret);
        return ret;
    }
}
//frida string to byte
function hook_string_to_byte(){
    var string = Java.use("java.lang.String");
    string.getBytes.implementation = function(){
        var ret = this.getBytes();
        console.log("getBytes: " + ret);
        return ret;
    }
}
function hook_response(){
    var response = Java.use("okhttp3.Response");
    response.body.implementation = function(){
        var ret = this.body();
        console.log("body: " + ret);
        return ret;
    }
}
function hook_request_url(){
    var request = Java.use("okhttp3.Request");
    request.url.implementation = function(){
        var ret = this.url();
        console.log("url: " + ret);
        return ret;
    }
}
function hook_url(){
    var url = Java.use("java.net.URL");
    url.toString.implementation = function(){
        var ret = this.toString();
        console.log("toString: " + ret);
        return ret;
    }
}
function hook_url_connection(){
    var url_connection = Java.use("java.net.URLConnection");
    url_connection.getInputStream.implementation = function(){
        var ret = this.getInputStream();
        console.log("getInputStream: " + ret);
        return ret;
    }
}
function hook_output_stream(){
    var output_stream = Java.use("java.io.OutputStream");
    output_stream.write.implementation = function(data){
        var ret = this.write(data);
        console.log("write: " + ret);
        return ret;
    }
};
function hook_loadLibrary(){
    var lib = Java.use("java.lang.System");
    lib.loadLibrary.implementation = function(name){
        var ret = this.loadLibrary(name);
        console.log("loadLibrary: " + ret);
        return ret;
    }
    var linker = Java.use("dalvik.system.DexClassLoader");
    linker.loadClass.implementation = function(name){
        var ret = this.loadClass(name);
        console.log("loadClass: " + ret);
        return ret;
    }

}
function libart_hook(){
    var libart = Java.use("libart.DexFile");
    libart.openDexFile.implementation = function(path,name,flags){
        var ret = this.openDexFile(path,name,flags);
        console.log("openDexFile: " + ret);
        return ret;
    }
    var libart_native = Java.use("libart.DexFile.Native");
    libart_native.dexFileOpen.implementation = function(path,name,flags){
        var ret = this.dexFileOpen(path,name,flags);
        console.log("dexFileOpen: " + ret);
        return ret;
    }

}
这篇关于frida hook的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!