Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 9d314f8

Browse files
committed
fixed RetroLambda support and added case for manually stripped APK
1 parent 8527ecc commit 9d314f8

File tree

7 files changed

+79
-63
lines changed

7 files changed

+79
-63
lines changed

ClassySharkWS/src/com/google/classyshark/gui/panel/tree/FilesTree.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ private TreeNode createJTreeModelAndroid(String fileName,
132132
}
133133
}
134134
}
135+
136+
// hack for manually stripped APKs with one flat package
137+
if (packageNode != null && currentClassesDex.isLeaf()) {
138+
currentClassesDex.add(packageNode);
139+
}
140+
135141
for (DefaultMutableTreeNode node : noPkgNodes) {
136142
currentClassesDex.add(node);
137143
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2016 Google, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.classyshark.silverghost.contentreader.clazz;
18+
19+
import org.objectweb.asm.ClassVisitor;
20+
import org.objectweb.asm.Opcodes;
21+
22+
public class ClassNameVisitor extends ClassVisitor {
23+
24+
private String name;
25+
26+
public ClassNameVisitor() {
27+
super(Opcodes.ASM5);
28+
}
29+
30+
public void visit(int version, int access, String name,
31+
String signature, String superName,
32+
String[] interfaces) {
33+
this.name = name.replaceAll("/", "\\.");
34+
}
35+
36+
public String getName() {
37+
return name;
38+
}
39+
}

ClassySharkWS/src/com/google/classyshark/silverghost/contentreader/clazz/ClazzLoader.java

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

ClassySharkWS/src/com/google/classyshark/silverghost/contentreader/clazz/ClazzReader.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818

1919
import com.google.classyshark.silverghost.contentreader.BinaryContentReader;
2020
import com.google.classyshark.silverghost.contentreader.ContentReader;
21-
2221
import java.io.File;
22+
import java.io.IOException;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
import java.nio.file.Paths;
2326
import java.util.ArrayList;
2427
import java.util.List;
28+
import org.objectweb.asm.ClassReader;
2529

2630
public class ClazzReader implements BinaryContentReader {
2731

@@ -34,7 +38,21 @@ public ClazzReader(File binaryArchive) {
3438

3539
@Override
3640
public void read() {
37-
allClassNames.add(ClazzLoader.loadClassFromClassFile(binaryArchive).getName());
41+
try {
42+
43+
Path path = Paths.get(binaryArchive.getAbsolutePath());
44+
byte[] bytes = Files.readAllBytes(path);
45+
46+
ClassNameVisitor classNameVisitor = new ClassNameVisitor();
47+
ClassReader cr = new ClassReader(bytes);
48+
cr.accept(classNameVisitor, 0);
49+
50+
String className = classNameVisitor.getName();
51+
allClassNames.add(className);
52+
53+
} catch (IOException e) {
54+
e.printStackTrace();
55+
}
3856
}
3957

4058
@Override

ClassySharkWS/src/com/google/classyshark/silverghost/contentreader/dex/DexReader.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,14 @@ public static List<String> readClassNamesFromDex(File binaryArchiveFile) throws
6767
Collections.sort(result);
6868
return result;
6969
}
70+
71+
public static void main(String[] args) {
72+
DexReader dxr =
73+
new DexReader(new File("//Users//bfarber//Desktop//classes.dex"));
74+
75+
dxr.read();
76+
77+
System.out.println(dxr.getClassNames());
78+
79+
}
7080
}

ClassySharkWS/src/com/google/classyshark/silverghost/translator/dex/DexInfoTranslator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
/**
3636
* Translator for the classes.dex entry
3737
*/
38-
public class DexInfoTranslator implements Translator {
38+
public class
39+
DexInfoTranslator implements Translator {
3940
private File apkfile;
4041
private String dexFileName;
4142
private int index;

ClassySharkWS/src/com/google/classyshark/silverghost/translator/java/JavaTranslator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public static void testSystemClass() {
352352
}
353353

354354
public static void testCustomClass() {
355-
final File testFile = new File(System.getProperty("user.home") + "/Desktop/Scenarios/3 Class/Reducer.class");
355+
final File testFile = new File(System.getProperty("user.home") + "/Desktop/Scenarios/2 Class/Reducer.class");
356356
String textClass = "com.google.classyshark.gui.panel.reducer.Reducer.class";
357357
Translator translator = TranslatorFactory.createTranslator(textClass, testFile);
358358
translator.apply();
@@ -361,7 +361,7 @@ public static void testCustomClass() {
361361
}
362362

363363
public static void testInnerClass() {
364-
final File testFile = new File(System.getProperty("user.home") + "/Desktop/Scenarios/3 Class/Reducer$1.class");
364+
final File testFile = new File(System.getProperty("user.home") + "/Desktop/Scenarios/2 Class/Reducer$1.class");
365365
String textClass = "com.google.classyshark.gui.panel.reducer.Reducer$1.class";
366366
Translator translator = TranslatorFactory.createTranslator(textClass, testFile);
367367
translator.apply();

0 commit comments

Comments
 (0)