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

Commit 32c1e03

Browse files
committed
Merge pull request #104 from google/plugins-full
implemented plugin system
2 parents 9ca1ce4 + 5068fd5 commit 32c1e03

16 files changed

+213
-46
lines changed

ClassySharkWS/src/com/google/classyshark/Version.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
public class Version {
2323

2424
public static final int MAJOR = 6;
25-
public static final int MINOR = 4;
25+
public static final int MINOR = 5;
2626
}

ClassySharkWS/src/com/google/classyshark/gui/panel/ClassySharkPanel.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import com.google.classyshark.silverghost.SilverGhost;
3333
import com.google.classyshark.silverghost.exporter.Exporter;
3434
import com.google.classyshark.silverghost.methodscounter.ClassNode;
35-
import com.google.classyshark.silverghost.tokensmapper.ProguardMapper;
35+
import com.google.classyshark.silverghost.TokensMapper;
3636
import com.google.classyshark.silverghost.translator.Translator;
3737

3838
import javax.swing.JFileChooser;
@@ -446,11 +446,11 @@ protected void done() {
446446

447447
private void readMappingFile(final File resultFile) {
448448
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
449-
private ProguardMapper reverseMappings;
449+
private TokensMapper reverseMappings;
450450

451451
@Override
452452
protected Void doInBackground() throws Exception {
453-
reverseMappings = SilverGhost.readMappingFile(resultFile);
453+
reverseMappings = silverGhost.readMappingFile(resultFile);
454454
return null;
455455
}
456456

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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;
18+
19+
import com.google.classyshark.silverghost.translator.Translator;
20+
import java.io.File;
21+
22+
public interface FullArchiveReader {
23+
void readAsyncArchive(File file);
24+
25+
Translator buildTranslator(String className, File archiveFile);
26+
}

ClassySharkWS/src/com/google/classyshark/silverghost/SilverGhost.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
package com.google.classyshark.silverghost;
1818

1919
import com.google.classyshark.gui.panel.reducer.Reducer;
20+
import com.google.classyshark.silverghost.plugins.EmptyFullArchiveReader;
2021
import com.google.classyshark.silverghost.contentreader.ContentReader;
21-
import com.google.classyshark.silverghost.tokensmapper.MappingReader;
22-
import com.google.classyshark.silverghost.tokensmapper.ProguardMapper;
22+
import com.google.classyshark.silverghost.plugins.IdentityMapper;
2323
import com.google.classyshark.silverghost.translator.Translator;
2424
import com.google.classyshark.silverghost.translator.TranslatorFactory;
25-
2625
import java.io.File;
27-
import java.io.IOException;
2826
import java.util.List;
2927

3028
/**
@@ -36,7 +34,13 @@ public class SilverGhost {
3634
private Reducer reducer;
3735
private Translator translator;
3836
private ContentReader contentReader;
39-
private ProguardMapper proguardMapper = ProguardMapper.IDENTITY;
37+
private static TokensMapper tokensMapper;
38+
private static FullArchiveReader fullArchiveReader;
39+
40+
static {
41+
tokensMapper = new IdentityMapper();
42+
fullArchiveReader = new EmptyFullArchiveReader();
43+
}
4044

4145
public SilverGhost() {
4246
}
@@ -45,7 +49,7 @@ public void setBinaryArchive(File binArchive) {
4549
this.binaryArchive = binArchive;
4650

4751
// TODO think of initialyzing data members as they hold prev file state
48-
proguardMapper = ProguardMapper.IDENTITY;
52+
tokensMapper = new IdentityMapper();
4953
}
5054

5155
// 1. READ CONTENTS
@@ -56,6 +60,8 @@ public void readContents() {
5660
reducer = new Reducer(contentReader.getAllClassNames());
5761
System.out.println("Archive Reading "
5862
+ (System.currentTimeMillis() - start) + " ms ");
63+
64+
fullArchiveReader.readAsyncArchive(binaryArchive);
5965
}
6066

6167
public File getBinaryArchive() {
@@ -91,19 +97,13 @@ public boolean isArchiveError() {
9197
}
9298

9399
// 2. READ MAPPINGS FILE
94-
public static ProguardMapper readMappingFile(File mappingFile) {
95-
try {
96-
MappingReader mr = new MappingReader(mappingFile);
97-
ProguardMapper proguardMapper = new ProguardMapper();
98-
mr.pump(proguardMapper);
99-
return proguardMapper;
100-
} catch (IOException e) {
101-
return ProguardMapper.IDENTITY;
102-
}
100+
public TokensMapper readMappingFile(File mappingFile) {
101+
tokensMapper.readMappings(mappingFile);
102+
return tokensMapper;
103103
}
104104

105-
public void addMappings(ProguardMapper proguardMapper) {
106-
this.proguardMapper = proguardMapper;
105+
public void addMappings(TokensMapper tokensMapper) {
106+
this.tokensMapper = tokensMapper;
107107
}
108108

109109
// 3. BINARY ARCHIVE ELEMENT
@@ -113,8 +113,8 @@ public void translateArchiveElement(String elementName) {
113113
TranslatorFactory.createTranslator(
114114
elementName,
115115
getBinaryArchive(),
116-
reducer.getAllClassNames());
117-
translator.addMapper(this.proguardMapper);
116+
reducer.getAllClassNames(), fullArchiveReader);
117+
translator.addMapper(tokensMapper);
118118
translator.apply();
119119
}
120120

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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;
18+
19+
import java.io.File;
20+
import java.util.Map;
21+
22+
public interface TokensMapper {
23+
24+
TokensMapper readMappings(File file);
25+
26+
Map<String,String> getReverseClasses();
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.plugins;
18+
19+
import com.google.classyshark.silverghost.FullArchiveReader;
20+
import com.google.classyshark.silverghost.TokensMapper;
21+
import com.google.classyshark.silverghost.translator.Translator;
22+
import java.io.File;
23+
import java.util.LinkedList;
24+
import java.util.List;
25+
26+
public class EmptyFullArchiveReader implements FullArchiveReader{
27+
@Override
28+
public void readAsyncArchive(File file) {
29+
30+
}
31+
32+
@Override
33+
public Translator buildTranslator(String className, File archiveFile) {
34+
return new Translator() {
35+
@Override
36+
public String getClassName() {
37+
return "Empty";
38+
}
39+
40+
@Override
41+
public void addMapper(TokensMapper reverseMappings) {
42+
43+
}
44+
45+
@Override
46+
public void apply() {
47+
48+
}
49+
50+
@Override
51+
public List<ELEMENT> getElementsList() {
52+
return new LinkedList<>();
53+
}
54+
55+
@Override
56+
public List<String> getDependencies() {
57+
return new LinkedList<>();
58+
}
59+
};
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.plugins;
18+
19+
import com.google.classyshark.silverghost.TokensMapper;
20+
import java.io.File;
21+
import java.util.Map;
22+
import java.util.TreeMap;
23+
24+
public class IdentityMapper implements TokensMapper {
25+
26+
private Map<String, String> identityMap = new TreeMap<>();
27+
28+
public IdentityMapper() {
29+
30+
}
31+
32+
@Override
33+
public TokensMapper readMappings(File file) {
34+
return this;
35+
}
36+
37+
@Override
38+
public Map<String, String> getReverseClasses() {
39+
return this.identityMap;
40+
}
41+
}

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package com.google.classyshark.silverghost.translator;
1818

19-
import com.google.classyshark.silverghost.tokensmapper.ProguardMapper;
20-
19+
import com.google.classyshark.silverghost.TokensMapper;
2120
import java.util.List;
2221

2322
/**
@@ -49,7 +48,7 @@ public ELEMENT(String word, TAG tag) {
4948

5049
String getClassName();
5150

52-
void addMapper(ProguardMapper reverseMappings);
51+
void addMapper(TokensMapper reverseMappings);
5352

5453
void apply();
5554

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,42 @@
1616

1717
package com.google.classyshark.silverghost.translator;
1818

19+
import com.google.classyshark.silverghost.FullArchiveReader;
20+
import com.google.classyshark.silverghost.plugins.EmptyFullArchiveReader;
1921
import com.google.classyshark.silverghost.translator.apk.ApkTranslator;
2022
import com.google.classyshark.silverghost.translator.dex.DexInfoTranslator;
2123
import com.google.classyshark.silverghost.translator.elf.ElfTranslator;
2224
import com.google.classyshark.silverghost.translator.jar.JarInfoTranslator;
2325
import com.google.classyshark.silverghost.translator.java.JavaTranslator;
2426
import com.google.classyshark.silverghost.translator.xml.AndroidXmlTranslator;
25-
2627
import java.io.File;
2728
import java.util.LinkedList;
2829
import java.util.List;
2930

3031
/**
31-
* Creates translators based on class names and archives
32+
* Creates translators based on class names and archives
3233
*/
3334
public class TranslatorFactory {
3435

3536
public static Translator createTranslator(String className, File archiveFile) {
36-
return createTranslator(className, archiveFile, new LinkedList<String>());
37+
return createTranslator(className, archiveFile, new LinkedList<String>(), null);
3738
}
3839

40+
3941
public static Translator createTranslator(String className, File archiveFile,
4042
List<String> allClassNames) {
41-
if(className.endsWith(".xml")) {
43+
return createTranslator(className, archiveFile, allClassNames, null);
44+
}
45+
46+
47+
public static Translator createTranslator(String className, File archiveFile,
48+
List<String> allClassNames, FullArchiveReader fullArchiveReader) {
49+
if (className.endsWith(".xml")) {
4250
return new AndroidXmlTranslator(className, archiveFile);
4351
}
4452

4553
if (className.endsWith(".dex")) {
46-
return new DexInfoTranslator(className, archiveFile);
54+
return new DexInfoTranslator(className, archiveFile);
4755
}
4856

4957
if (className.endsWith(".jar")) {
@@ -58,6 +66,11 @@ public static Translator createTranslator(String className, File archiveFile,
5866
return new ElfTranslator(className, archiveFile);
5967
}
6068

69+
if (fullArchiveReader != null &&
70+
!(fullArchiveReader instanceof EmptyFullArchiveReader)) {
71+
return fullArchiveReader.buildTranslator(className, archiveFile);
72+
}
73+
6174
return new JavaTranslator(className, archiveFile);
6275
}
6376
}

ClassySharkWS/src/com/google/classyshark/silverghost/translator/apk/ApkTranslator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.google.classyshark.silverghost.contentreader.dex.DexlibLoader;
2020
import com.google.classyshark.silverghost.io.SherlockHash;
21-
import com.google.classyshark.silverghost.tokensmapper.ProguardMapper;
21+
import com.google.classyshark.silverghost.TokensMapper;
2222
import com.google.classyshark.silverghost.translator.Translator;
2323
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
2424
import org.jf.dexlib2.iface.DexFile;
@@ -59,7 +59,7 @@ public String getClassName() {
5959
}
6060

6161
@Override
62-
public void addMapper(ProguardMapper reverseMappings) {
62+
public void addMapper(TokensMapper reverseMappings) {
6363

6464
}
6565

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.google.classyshark.silverghost.contentreader.dex.DexlibLoader;
2020
import com.google.classyshark.silverghost.io.SherlockHash;
21-
import com.google.classyshark.silverghost.tokensmapper.ProguardMapper;
21+
import com.google.classyshark.silverghost.TokensMapper;
2222
import com.google.classyshark.silverghost.translator.Translator;
2323
import com.google.classyshark.silverghost.translator.apk.ApkTranslator;
2424
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
@@ -52,7 +52,7 @@ public String getClassName() {
5252
}
5353

5454
@Override
55-
public void addMapper(ProguardMapper reverseMappings) {
55+
public void addMapper(TokensMapper reverseMappings) {
5656

5757
}
5858

0 commit comments

Comments
 (0)