Android 类代码防止反编译的办法
//将此函数添加到要防止被反编译的类中即可!
//注意:1.for循环不可用do{}while(false)的形式来代替,否则无效!
// 2.a[0-i]=0;数组下标必须为数值计算(0-i)的形式,否则无效!
privatestaticvoid//static最好保留以防被优化掉此函数
AntiDecompile()
{
chara[]={0};
for(inti=0;
i<1;
i++)
{
a[0-i]=0;
}
}
在反编译工具下会报如下错误:
$./dex2jar.shclasses.dex
12:18:14.360ERRORp.a.d.reader.DexFileReader-Failonclass
java.lang.RuntimeException:Errorinmethod:[Lcom/example/antidecompile/MainActivity;.AntiDecompile()V]
atpxb.android.dex2jar.reader.DexFileReader.visitMethod(DexFileReader.java:479)[dex2jar-0.0.7-SNAPSHOT.jar:na]
atpxb.android.dex2jar.reader.DexFileReader.acceptClass(DexFileReader.java:300)[dex2jar-0.0.7-SNAPSHOT.jar:na]
atpxb.android.dex2jar.reader.DexFileReader.accept(DexFileReader.java:175)[dex2jar-0.0.7-SNAPSHOT.jar:na]
atpxb.android.dex2jar.v3.Main.doFile(Main.java:66)[dex2jar-0.0.7-SNAPSHOT.jar:na]
atpxb.android.dex2jar.v3.Main.main(Main.java:47)[dex2jar-0.0.7-SNAPSHOT.jar:na]
Causedby:java.lang.RuntimeException:NotsupportOpcode:[0x00d9]=RSUB_INT_LIT8yet!
atpxb.android.dex2jar.v3.V3CodeAdapter.visitInInsn(V3CodeAdapter.java:816)[dex2jar-0.0.7-SNAPSHOT.jar:na]
atpxb.android.dex2jar.reader.DexOpcodeAdapter.visit(DexOpcodeAdapter.java:317)[dex2jar-0.0.7-SNAPSHOT.jar:na]
atpxb.android.dex2jar.reader.DexCodeReader.accept(DexCodeReader.java:277)[dex2jar-0.0.7-SNAPSHOT.jar:na]
atpxb.android.dex2jar.reader.DexFileReader.visitMethod(DexFileReader.java:477)[dex2jar-0.0.7-SNAPSHOT.jar:na]
...4commonframesomitted
Exceptioninthread"main"java.lang.RuntimeException:java.lang.RuntimeException:Errorinmethod:[Lcom/example/antidecompile/MainActivity;.AntiDecompile()V]
atpxb.android.dex2jar.reader.DexFileReader.accept(DexFileReader.java:179)
atpxb.android.dex2jar.v3.Main.doFile(Main.java:66)
atpxb.android.dex2jar.v3.Main.main(Main.java:47)
Causedby:java.lang.RuntimeException:Errorinmethod:[Lcom/example/antidecompile/MainActivity;.AntiDecompile()V]
atpxb.android.dex2jar.reader.DexFileReader.visitMethod(DexFileReader.java:479)
atpxb.android.dex2jar.reader.DexFileReader.acceptClass(DexFileReader.java:300)
atpxb.android.dex2jar.reader.DexFileReader.accept(DexFileReader.java:175)
...2more
Causedby:java.lang.RuntimeException:NotsupportOpcode:[0x00d9]=RSUB_INT_LIT8yet!
atpxb.android.dex2jar.v3.V3CodeAdapter.visitInInsn(V3CodeAdapter.java:816)
atpxb.android.dex2jar.reader.DexOpcodeAdapter.visit(DexOpcodeAdapter.java:317)
atpxb.android.dex2jar.reader.DexCodeReader.accept(DexCodeReader.java:277)
atpxb.android.dex2jar.reader.DexFileReader.visitMethod(DexFileReader.java:477)
...4more