Skip to content

Commit 3adc699

Browse files
committed
清除无用代理类等
1 parent 8a4b5bd commit 3adc699

File tree

5 files changed

+24
-113
lines changed

5 files changed

+24
-113
lines changed

nmm-protect/apkprotect/src/main/java/com/nmmedit/apkprotect/ApkProtect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private static List<String> getApplicationClassesFromMainDex(GlobalDexConfig glo
361361
for (DexConfig config : globalConfig.getConfigs()) {
362362
DexBackedDexFile dexFile = DexBackedDexFile.fromInputStream(
363363
Opcodes.getDefault(),
364-
new BufferedInputStream(new FileInputStream(config.getNativeDexFile())));
364+
new BufferedInputStream(new FileInputStream(config.getShellDexFile())));
365365
final Set<? extends DexBackedClassDef> classes = dexFile.getClasses();
366366
ClassDef classDef;
367367
while (true) {
@@ -419,7 +419,7 @@ private static List<File> injectInstructionAndWriteToFile(GlobalDexConfig global
419419

420420
DexBackedDexFile dexNativeFile = DexBackedDexFile.fromInputStream(
421421
Opcodes.getDefault(),
422-
new BufferedInputStream(new FileInputStream(config.getNativeDexFile())));
422+
new BufferedInputStream(new FileInputStream(config.getShellDexFile())));
423423

424424
for (ClassDef classDef : dexNativeFile.getClasses()) {
425425
if (mainClassSet.contains(classDef.getType())) {

nmm-protect/apkprotect/src/main/java/com/nmmedit/apkprotect/dex2c/Dex2c.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ public static DexConfig handleDex(InputStream dex,
189189

190190

191191
//写入需要运行的dex
192-
nativeMethodDexPool.writeTo(new FileDataStore(config.getNativeDexFile()));
192+
nativeMethodDexPool.writeTo(new FileDataStore(config.getShellDexFile()));
193193
//写入符号dex
194-
symDexPool.writeTo(new FileDataStore(config.getSymbolDexFile()));
194+
symDexPool.writeTo(new FileDataStore(config.getImplDexFile()));
195195

196196

197197
final DexBackedDexFile symDexFile = DexBackedDexFile.fromInputStream(Opcodes.getDefault(),
198-
new BufferedInputStream(new FileInputStream(config.getSymbolDexFile())));
198+
new BufferedInputStream(new FileInputStream(config.getImplDexFile())));
199199

200200
//根据符号dex生成c代码
201201
try (FileWriter nativeCodeWriter = new FileWriter(config.getNativeFunctionsFile());
@@ -244,7 +244,7 @@ public static List<DexPool> injectCallRegisterNativeInsns(DexConfig config,
244244

245245
DexBackedDexFile dexNativeFile = DexBackedDexFile.fromInputStream(
246246
Opcodes.getDefault(),
247-
new BufferedInputStream(new FileInputStream(config.getNativeDexFile())));
247+
new BufferedInputStream(new FileInputStream(config.getShellDexFile())));
248248

249249
List<DexPool> dexPools = new ArrayList<>();
250250
dexPools.add(lastDexPool);
@@ -265,7 +265,7 @@ public static List<DexPool> injectCallRegisterNativeInsns(DexConfig config,
265265
}
266266

267267
public static void internClass(DexConfig config, DexPool dexPool, ClassDef classDef) {
268-
final Set<String> classes = config.getNativeClasses();
268+
final Set<String> classes = config.getHandledNativeClasses();
269269
final String type = classDef.getType();
270270
final String className = type.substring(1, type.length() - 1);
271271
if (classes.contains(className)) {

nmm-protect/apkprotect/src/main/java/com/nmmedit/apkprotect/dex2c/DexConfig.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class DexConfig {
1616

1717

1818
//jnicodegenerator 处理完成后,缓存已处理的类及方法
19-
private Set<String> nativeClasses;
19+
private Set<String> handledNativeClasses;
2020
private Map<String, Integer> nativeMethodOffsets;
2121

2222
public DexConfig(File outputDir, String dexFileName) {
@@ -47,32 +47,32 @@ public String getRegisterNativesMethodName() {
4747
}
4848

4949
@Nonnull
50-
public Set<String> getNativeClasses() {
51-
return nativeClasses;
50+
public Set<String> getHandledNativeClasses() {
51+
return handledNativeClasses;
5252
}
5353

5454
public int getOffsetFromClassName(String className) {
5555
return nativeMethodOffsets.get(className);
5656
}
5757

5858
public void setResult(JniCodeGenerator codeGenerator) {
59-
nativeClasses = codeGenerator.getNativeClasses();
59+
handledNativeClasses = codeGenerator.getHandledNativeClasses();
6060
nativeMethodOffsets = codeGenerator.getNativeMethodOffsets();
6161
}
6262

6363

6464
/**
6565
* 方法被标识为native的dex,用于替换原dex
6666
*/
67-
public File getNativeDexFile() {
68-
return new File(outputDir, dexName + "_native.dex");
67+
public File getShellDexFile() {
68+
return new File(outputDir, dexName + "_shell.dex");
6969
}
7070

7171
/**
72-
* 符号dex文件,用于生成c代码
72+
* 符号及方法实现dex文件,用于生成c代码
7373
*/
74-
public File getSymbolDexFile() {
75-
return new File(outputDir, dexName + "_sym.dex");
74+
public File getImplDexFile() {
75+
return new File(outputDir, dexName + "_impl.dex");
7676
}
7777

7878
/**

nmm-protect/apkprotect/src/main/java/com/nmmedit/apkprotect/dex2c/converter/JniCodeGenerator.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public class JniCodeGenerator {
2626

2727

2828
private final boolean isRegisterNative;
29-
private final HashMultimap<String, MyMethod> nativeMethods = HashMultimap.create();
29+
30+
private final HashMultimap<String, MyMethod> handledNativeMethods = HashMultimap.create();
31+
3032
private final Map<String, Integer> nativeMethodOffsets = new HashMap<>();
3133
private final ResolverCodeGenerator resolverCodeGenerator;
3234
private final InstructionRewriter instructionRewriter;
@@ -62,7 +64,7 @@ public void addMethod(Method method, Writer writer) throws IOException {
6264

6365
String clazzName = classType.substring(1, classType.length() - 1);
6466

65-
nativeMethods.put(clazzName, new MyMethod(clazzName, methodName, parameterTypes, returnType));
67+
handledNativeMethods.put(clazzName, new MyMethod(clazzName, methodName, parameterTypes, returnType));
6668

6769
writer.write(String.format("%s %s %s(JNIEnv *env, %s ",
6870
isRegisterNative ? "static" : "JNIEXPORT",
@@ -223,8 +225,8 @@ public void addMethod(Method method, Writer writer) throws IOException {
223225
}
224226

225227

226-
public Set<String> getNativeClasses() {
227-
return nativeMethods.keySet();
228+
public Set<String> getHandledNativeClasses() {
229+
return handledNativeMethods.keySet();
228230
}
229231

230232
//必须在产生代码后调用才有效果
@@ -319,10 +321,10 @@ private void generateNativeMethodCode(DexConfig config, Writer writer) throws IO
319321

320322
int methodIdx = 0;
321323
writer.write("static const MyNativeMethod gNativeMethods[] = {\n");
322-
for (String clazz : nativeMethods.keySet()) {
324+
for (String clazz : handledNativeMethods.keySet()) {
323325

324326
int startIdx = methodIdx;
325-
Set<MyMethod> methods = nativeMethods.get(clazz);
327+
Set<MyMethod> methods = handledNativeMethods.get(clazz);
326328
for (MyMethod method : methods) {
327329
int nameIdx = resolverCodeGenerator.getIndexByString(method.name);
328330
int sigIdx = resolverCodeGenerator.getIndexByString(MyMethodUtil.getMethodSignature(method.parameterTypes, method.returnType));

nmm-protect/apkprotect/src/main/java/com/nmmedit/apkprotect/dex2c/converter/structs/ClassDefAdapter.java

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)