dex动态自修改demo题解


本文为看雪论坛优秀文章
看雪论坛作者ID:Simp1er
前言
正文

package com.kanxue.test;
import android.util.Base64;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class Utils {
public static String cipher;
static {
Utils.cipher = "sGpdX0nDoRPWnonSt0SQQXOk/0wID0jvtAqb2QxJoW4=";
}
public Utils() {
super();
}
public static String aaaaa(String arg7, String arg8) throws Exception {
String v0 = null;
if(arg8 == null) {
return v0;
}
if(arg8.length() != 16) {
return v0;
}
SecretKeySpec v2 = new SecretKeySpec(arg8.getBytes("utf-8"), "AES");
Cipher v3 = Cipher.getInstance("AES/ECB/PKCS5Padding");
v3.init(1, ((Key)v2));
return new String(Base64.encode(v3.doFinal(arg7.getBytes("utf-8")), 0));
}
static String bbbbb(String arg14, String arg15) {
int v0 = 0x100;
char[] v1 = new char[v0];
char[] v2 = new char[v0];
int v3;
for(v3 = 0; v3 < v0; ++v3) {
v1[v3] = arg14.charAt(v3 % arg14.length());
v2[v3] = ((char)v3);
}
v3 = 0;
int v4;
for(v4 = 0; v4 < v0; ++v4) {
v3 = v2[v4] + v3 + v1[v4] & 0xFF;
char v5 = v2[v4];
v2[v4] = v2[v3];
v2[v3] = v5;
}
v0 = 0;
v3 = 0;
String v4_1 = "";
int v5_1;
for(v5_1 = 0; v5_1 < arg15.length(); ++v5_1) {
v0 = v0 + 1 & 0xFF;
char v6 = v2[v0];
v3 = v3 + v6 & 0xFF;
char v7 = ((char)(v2[v3] + v6 & 0xFF));
v2[v0] = v2[v3];
v2[v3] = v6;
try {
v4_1 = v4_1 + new String(new char[]{((char)(arg15.charAt(v5_1) ^ v2[v7]))});
}
catch(Exception v8) {
v8.printStackTrace();
}
}
return v4_1;
}
public static boolean test(String arg6) {
boolean v0 = false;
new Utils();
String v2 = Utils.bbbbb("kanxue", arg6);
try {
if(!Utils.aaaaa(v2, "0123456789abcdef").replace("\n", "").equals(Utils.cipher)) {
return v0;
}
}
catch(Exception v3) {
v3.printStackTrace();
return v0;
}
return true;
}
}




function hexToBytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
var jsBytes = hexToBytes("c3bfc29fc3b3c3a335c2a803c294c38c4c670ac39cc3a6c29229005176216dc38d1773");
var buffer = Java.array('byte', jsBytes);
var inputStr = string.$new(buffer);
var test = Utils.bbbbb("kanxue", inputStr);
console.log("Src ->",test);
public class main {
static String bbbbb(String key, String input) {
int len = 256;
char[] k = new char[len];
char[] S = new char[len];
int i;
for(i = 0; i < len; ++i) {
k[i] = key.charAt(i % key.length());
S[i] = ((char)i);
}
i = 0;
int j;
for(j = 0; j < len; ++j) {
i = S[j] + i + k[j] & 0xFF;
char tmp = S[j];
S[j] = S[i];
S[i] = tmp;
}
len = 0;
i = 0;
String v4_1 = "";
int t;
for(t = 0; t < input.length(); ++t) {
len = len + 1 & 0xFF;
char v6 = S[len];
i = i + v6 & 0xFF;
char v7 = ((char)(S[i] + v6 & 0xFF));
S[len] = S[i];
S[i] = v6;
try {
v4_1 = v4_1 + new String(new char[]{((char)(input.charAt(t) ^ S[v7]))});
}
catch(Exception v8) {
v8.printStackTrace();
}
}
return v4_1;
}
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i+1), 16));
}
return data;
}
public static void main(String[] args) {
String hex = "c3bfc29fc3b3c3a335c2a803c294c38c4c670ac39cc3a6c29229005176216dc38d1773";
byte[] bytes_input = hexStringToByteArray(hex);
String result = bbbbb("kanxue",new String(bytes_input));
System.out.println(result);
/*
byte[] bytes = result.getBytes();
for (int i = 0; i < bytes.length; i++) {
System.out.print(String.format("%02x", bytes[i] & 0xff));
}*/
}
}

后记

看雪ID:Simp1er
https://bbs.pediy.com/user-home-715334.htm

# 往期推荐


球分享

球点赞

球在看

点击“阅读原文”,了解更多!
[广告]赞助链接:
关注数据与安全,洞悉企业级服务市场:https://www.ijiandao.com/
让资讯触达的更精准有趣:https://www.0xu.cn/