Skip to content

Commit 7de7e4e

Browse files
committed
Update v1.1
1 parent 0f0052b commit 7de7e4e

File tree

10 files changed

+257
-17
lines changed

10 files changed

+257
-17
lines changed

.classpath

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<classpath>
33
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
44
<classpathentry kind="src" path="src"/>
5-
<classpathentry kind="lib" path="libs/ApkStringDecryptor-1.0.jar"/>
65
<classpathentry kind="lib" path="libs/dexlib2-2.2.5.jar"/>
6+
<classpathentry kind="lib" path="libs/guava-18.0.jar"/>
7+
<classpathentry kind="lib" path="libs/jsr305-1.3.9.jar"/>
78
<classpathentry kind="output" path="bin"/>
89
</classpath>

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
bin/
2-
/test/classes-decrypt.dex
3-
/test/classes-decrypt2.dex
2+
/test/classes-D.dex
3+
/test/classes-DRC.dex

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ Decrypt String in classes.dex without decompile
1414

1515
- Keep Call
1616

17-
decryptString("test\\classes.dex", "test\\classes-decrypt.dex", 16, immutableMethodReference.toString(), false, immutableMethodReference);
17+
decryptString("test\\classes.dex", "test\\classes-D.dex", 15, immutableMethodReference.toString(), false, immutableMethodReference);
1818

1919
- Remove Call
2020

21-
decryptString("test\\classes.dex", "test\\classes-decrypt2.dex", 16, immutableMethodReference.toString(), true, immutableMethodReference);
21+
decryptString("test\\classes.dex", "test\\classes-DRC.dex", 15, immutableMethodReference.toString(), true, immutableMethodReference);
2222

2323
#### asd/transformers/StringDecryptor.java:->
2424

@@ -27,18 +27,15 @@ Decrypt String in classes.dex without decompile
2727
public static String decryptor(String str) {
2828
2929
// Replace with your code
30-
31-
try {
32-
return new String(Base64.decode(str));
33-
} catch (IOException e) {
34-
// TODO Auto-generated catch block
35-
throw new RuntimeException(e);
36-
}
37-
30+
...
31+
// Code
3832
}
3933

4034
### Support
4135
(Ljava/lang/String;)Ljava/lang/String;
36+
Custom StackTraceElement
4237

4338
### License
44-
dexlib2-2.2.5: The 3-Clause BSD License
39+
dexlib2: The 3-Clause BSD License
40+
guava: http://www.apache.org/licenses/LICENSE-2.0.txt
41+
jsr350: http://www.apache.org/licenses/LICENSE-2.0.txt

libs/ApkStringDecryptor-1.0.jar

-5.42 KB
Binary file not shown.

libs/dexlib2-2.2.5.jar

-2.18 MB
Binary file not shown.

libs/guava-18.0.jar

2.15 MB
Binary file not shown.

libs/jsr305-1.3.9.jar

32.2 KB
Binary file not shown.

src/aSD/Main.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ static void test() throws Exception {
3333
"MyMethod", Lists.newArrayList("Ljava/lang/String;"), "Ljava/lang/String;");
3434

3535
// Keep call
36-
decryptString("test\\classes.dex", "test\\classes-decrypt.dex", 16, immutableMethodReference.toString(), false,
36+
decryptString("test\\classes.dex", "test\\classes-D.dex", 15, immutableMethodReference.toString(), false,
3737
immutableMethodReference);
3838

3939
// Remove call
40-
decryptString("test\\classes.dex", "test\\classes-decrypt2.dex", 16, immutableMethodReference.toString(), true,
40+
decryptString("test\\classes.dex", "test\\classes-DRC.dex", 15, immutableMethodReference.toString(), true,
4141
immutableMethodReference);
42+
4243
}
4344

4445
/***
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
11
package aSD.transformers;
22

33
import java.io.IOException;
4+
import java.util.ArrayList;
5+
import java.util.List;
46

57
import net.iharder.Base64;
68

9+
import org.jf.dexlib2.iface.Method;
10+
711
/**
812
* @author Gorav Gupta
913
*
1014
*/
1115
public class StringDecryptor {
1216

17+
// Note: Do not change field
18+
public static List<Method> method = new ArrayList<>();
19+
1320
// Note: Don't change method name and parameter
1421
public static String decryptor(String str) {
22+
23+
String StackTraceElement = getMethod().getName()
24+
+ getMethod().getDefiningClass().replaceFirst("L", "").replace("/", ".").replaceFirst(";", "");
25+
26+
String StackTraceElement2 = getMethod().getDefiningClass().replaceFirst("L", "").replace("/", ".")
27+
.replaceFirst(";", "") + getMethod().getName();
28+
1529
// Replace with your code
16-
30+
1731
try {
1832
return new String(Base64.decode(str));
1933
} catch (IOException e) {
2034
// TODO Auto-generated catch block
2135
throw new RuntimeException(e);
2236
}
2337

38+
// End
39+
}
40+
41+
// Note: Do not change method
42+
private static Method getMethod() {
43+
return method.get(0);
2444
}
2545

2646
}
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
package aSD.transformers;
2+
3+
import java.util.AbstractSet;
4+
import java.util.ArrayList;
5+
import java.util.Collections;
6+
import java.util.Iterator;
7+
import java.util.List;
8+
import java.util.Set;
9+
10+
import javax.annotation.Nonnull;
11+
12+
import org.jf.dexlib2.DexFileFactory;
13+
import org.jf.dexlib2.Opcode;
14+
import org.jf.dexlib2.Opcodes;
15+
import org.jf.dexlib2.ReferenceType;
16+
import org.jf.dexlib2.builder.BuilderInstruction;
17+
import org.jf.dexlib2.builder.MutableMethodImplementation;
18+
import org.jf.dexlib2.builder.instruction.BuilderInstruction10x;
19+
import org.jf.dexlib2.builder.instruction.BuilderInstruction21c;
20+
import org.jf.dexlib2.builder.instruction.BuilderInstruction31c;
21+
import org.jf.dexlib2.iface.ClassDef;
22+
import org.jf.dexlib2.iface.DexFile;
23+
import org.jf.dexlib2.iface.Method;
24+
import org.jf.dexlib2.iface.MethodImplementation;
25+
import org.jf.dexlib2.iface.instruction.Instruction;
26+
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction;
27+
import org.jf.dexlib2.iface.instruction.ReferenceInstruction;
28+
import org.jf.dexlib2.immutable.ImmutableClassDef;
29+
import org.jf.dexlib2.immutable.ImmutableMethod;
30+
import org.jf.dexlib2.immutable.ImmutableMethodImplementation;
31+
import org.jf.dexlib2.immutable.instruction.ImmutableInstruction11x;
32+
import org.jf.dexlib2.immutable.reference.ImmutableMethodReference;
33+
import org.jf.dexlib2.immutable.reference.ImmutableStringReference;
34+
35+
import com.google.common.collect.ImmutableList;
36+
37+
/**
38+
* @author Gorav Gupta
39+
*
40+
*/
41+
public class Transformers {
42+
43+
public static void decryptStrings(String inDex, String outDex, int API, String callMethodRef, boolean removeCall,
44+
ImmutableMethodReference immutableMethodReference) throws Exception {
45+
46+
DexFile dexFile = DexFileFactory.loadDexFile(inDex, Opcodes.forApi(API));
47+
48+
List<ClassDef> classes = new ArrayList<>();
49+
50+
for (ClassDef classDef : dexFile.getClasses()) {
51+
52+
List<Method> methods = new ArrayList<>();
53+
boolean modifiedMethod = false;
54+
55+
for (Method method : classDef.getMethods()) {
56+
MethodImplementation implementation = method.getImplementation();
57+
58+
if (!removeCall && method.equals(immutableMethodReference)) {
59+
modifiedMethod = true;
60+
methods.add(new ImmutableMethod(method.getDefiningClass(), method.getName(), method.getParameters(),
61+
method.getReturnType(), method.getAccessFlags(), method.getAnnotations(),
62+
new ImmutableMethodImplementation(1,
63+
ImmutableList.of(new ImmutableInstruction11x(Opcode.RETURN_OBJECT, 0)), null,
64+
null)));
65+
66+
} else if (implementation != null && methodNeedsModification(implementation)) {
67+
modifiedMethod = true;
68+
StringDecryptor.method.add(method);
69+
methods.add(new ImmutableMethod(method.getDefiningClass(), method.getName(), method.getParameters(),
70+
method.getReturnType(), method.getAccessFlags(), method.getAnnotations(),
71+
modifyMethod(implementation, callMethodRef, removeCall)));
72+
StringDecryptor.method.remove(0);
73+
} else {
74+
methods.add(method);
75+
}
76+
}
77+
78+
if (!modifiedMethod) {
79+
classes.add(classDef);
80+
} else {
81+
classes.add(new ImmutableClassDef(classDef.getType(), classDef.getAccessFlags(),
82+
classDef.getSuperclass(), classDef.getInterfaces(), classDef.getSourceFile(),
83+
classDef.getAnnotations(), classDef.getFields(), methods));
84+
}
85+
}
86+
87+
writeDexFile(classes, outDex, API);
88+
System.out.println("https://github.com/Modify24x7");
89+
}
90+
91+
static boolean methodNeedsModification(@Nonnull MethodImplementation implementation) {
92+
for (Instruction instruction : implementation.getInstructions()) {
93+
if (instruction instanceof ReferenceInstruction) {
94+
if (((ReferenceInstruction) instruction).getReferenceType() == ReferenceType.STRING) {
95+
return true;
96+
}
97+
}
98+
}
99+
return false;
100+
}
101+
102+
static MethodImplementation modifyMethod(@Nonnull MethodImplementation implementation, String callMethodRef,
103+
boolean removeCall) {
104+
105+
MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
106+
List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
107+
ArrayList<Integer> callList = new ArrayList<>();
108+
109+
// Analyze
110+
for (int i = 0; i < instructions.size(); i++) {
111+
Instruction instruction = instructions.get(i);
112+
if (instruction instanceof ReferenceInstruction) {
113+
String call = ((ReferenceInstruction) instruction).getReference().toString();
114+
if (call.equals(callMethodRef)) {
115+
callList.add(i);
116+
}
117+
}
118+
}
119+
120+
// Decode and replace string
121+
for (int i = 0; i < instructions.size(); i++) {
122+
Instruction instruction = instructions.get(i);
123+
if (instruction instanceof ReferenceInstruction) {
124+
if (((ReferenceInstruction) instruction).getReferenceType() == ReferenceType.STRING) {
125+
if (repTrue(callList, i)) {
126+
String str = ((ReferenceInstruction) instruction).getReference().toString();
127+
Opcode opcode = instruction.getOpcode();
128+
129+
int register = ((OneRegisterInstruction) instruction).getRegisterA();
130+
131+
if (opcode == Opcode.CONST_STRING_JUMBO)
132+
mutableImplementation.replaceInstruction(i, new BuilderInstruction31c(opcode, register,
133+
new ImmutableStringReference(StringDecryptor.decryptor(str))));
134+
else
135+
mutableImplementation.replaceInstruction(i, new BuilderInstruction21c(opcode, register,
136+
new ImmutableStringReference(StringDecryptor.decryptor(str))));
137+
}
138+
}
139+
}
140+
}
141+
142+
if (removeCall) {
143+
// Replace Method Call to NOP
144+
for (int i = 0; i < instructions.size(); i++) {
145+
Instruction instruction = instructions.get(i);
146+
if (instruction instanceof ReferenceInstruction) {
147+
String call = ((ReferenceInstruction) instruction).getReference().toString();
148+
if (call.equals(callMethodRef)) {
149+
mutableImplementation.replaceInstruction(i, new BuilderInstruction10x(Opcode.NOP));
150+
}
151+
}
152+
}
153+
154+
// Replace MOVE_RESULT_OBJECT to NOP
155+
for (int i = 0; i < instructions.size(); i++) {
156+
if (repTrue2(callList, i)) {
157+
mutableImplementation.replaceInstruction(i, new BuilderInstruction10x(Opcode.NOP));
158+
}
159+
}
160+
}
161+
162+
return mutableImplementation;
163+
}
164+
165+
// Replace String
166+
static boolean repTrue(ArrayList<Integer> callList, int ins) {
167+
for (int i = 0; i < callList.size(); i++) {
168+
if (ins == callList.get(i) - 1) {
169+
return true;
170+
}
171+
}
172+
return false;
173+
}
174+
175+
// Replace MOVE_RESULT_OBJECT
176+
static boolean repTrue2(ArrayList<Integer> callList, int ins) {
177+
for (int i = 0; i < callList.size(); i++) {
178+
if (ins == callList.get(i) + 1) {
179+
return true;
180+
}
181+
}
182+
return false;
183+
}
184+
185+
// Write Output Dex
186+
static void writeDexFile(List<ClassDef> classes, String outDex, int API) throws Exception {
187+
188+
Collections.sort(classes);
189+
190+
DexFileFactory.writeDexFile(outDex, new DexFile() {
191+
192+
@Nonnull
193+
@Override
194+
public Set<? extends ClassDef> getClasses() {
195+
// TODO Auto-generated method stub
196+
return new AbstractSet<ClassDef>() {
197+
198+
@Override
199+
public Iterator<ClassDef> iterator() {
200+
// TODO Auto-generated method stub
201+
return classes.iterator();
202+
}
203+
204+
@Override
205+
public int size() {
206+
// TODO Auto-generated method stub
207+
return classes.size();
208+
}
209+
210+
};
211+
}
212+
213+
@Override
214+
public Opcodes getOpcodes() {
215+
// TODO Auto-generated method stub
216+
return Opcodes.forApi(API);
217+
}
218+
});
219+
}
220+
221+
}

0 commit comments

Comments
 (0)