env:
os:ubuntu 16.04 x64openjdk8u//java.lang.Stringpackage java.lang;import java.lang.StringDebugHelper;//...public final class String{final char value[];//remove private public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof String) { // {replace begin String anotherString = (String)anObject; if(StringDebugHelper.Equals.isInAttention(this) || StringDebugHelper.Equals.isInAttention(anotherString)){ //new Throwable().getStackTrace();//not crash //System.out.println("xxxxx");//not crash new Throwable("attention:"+this).printStackTrace(); } //Thread.currentThread().getStackTrace();//crash //new Throwable().getStackTrace();//crash //new Exception("uuuuuuuuuu");//crash //new String("dddxx");//not crash //System.out.println("xxxxx");//crash int n = value.length; return StringDebugHelper.Equals.equals(this.value, anotherString.value); //replace end} } return false; }}
package java.lang;//import java.util.Set;public class StringDebugHelper{ public static class Equals{ public static String[] attention; public static boolean isInAttention(final String str){ if(attention==null) return false; for(int i = 0; i < attention.length; i++){ if(null != attention[i] && StringDebugHelper.Equals.equals(attention[i].value, str.value)) return true; } return false; } public static boolean equals(final char [] thiz,final char [] anotherString) { int n = thiz.length; if (n == anotherString.length) { char v1[] = thiz; char v2[] = anotherString; int i = 0; while (n-- != 0) { if (v1[i] != v2[i]) return false; i++; } return true; } return false; } }}
import java.util.HashSet;import java.util.Set;public class StringDebugHelperTest{ public static void main(String[] args){ // to this before boot app { String[] st = new String[5]; st[0] = "java"; st[1] = "tsogvilin"; StringDebugHelper.Equals.attention = st; // } // app content: //"java".equals(new String("java")); "tsogvilin".equals(new String("tsogvilin")); }}
#compilejavac -sourcepath main/src/ -d main/classes/ main/src/*.java javac -Xbootclasspath/p:main/classes -d test/classes/ test/src/*.java #runjava -Xbootclasspath/p:main/classes -cp test/classes T java -Xbootclasspath/p:main/classes -cp test/classes StringDebugHelperTest
real exmaple :apktool:
#replace javac cmd:mv /usr/lib/jvm/java-8-openjdk-amd64/bin/javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac.realcat /usr/lib/jvm/java-8-openjdk-amd64/bin/javac#!/bin/sh/usr/lib/jvm/java-8-openjdk-amd64/bin/javac.real -Xbootclasspath/p:/home/z/hg_openjdk_java_net/jdk8u_jdk8u/str.eq.dbg/main/classes/ "$@"
Apktool/build.gradle: tasks.withType(JavaCompile) { options.compilerArgs += ["-Xlint:-options"] // add this: options.bootClasspath = "/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar:/home/z/hg_openjdk_java_net/jdk8u_jdk8u/str.eq.dbg/main/classes/" //add this }
//Apktool/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java: // to this before boot app { String[] st = new String[1]; st[0] = "resources.arsc"; //st[1] = "tsogvilin"; StringDebugHelper.Equals.attention = st; System.out.println("rrrrrrrrrrrrrrrrrr"); // }
java -Xbootclasspath/p:main/classes -cp /home/z/a/Apktool/brut.apktool/apktool-cli/build/libs/apktool-cli-all.jar -Duser.language=en -Dfile.encoding=UTF8 brut.apktool.Main d ~/a/game.v182815.apk -o ~/a/myoutdir