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

Commit 73b5285

Browse files
committed
non existing manifest elements
1 parent edaff30 commit 73b5285

File tree

3 files changed

+237
-17
lines changed

3 files changed

+237
-17
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.google.classyshark.silverghost.contentreader.dex;
22

3+
import java.io.File;
34
import org.jf.dexlib2.DexFileFactory;
5+
import org.jf.dexlib2.Opcodes;
6+
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
47
import org.jf.dexlib2.iface.DexFile;
58

6-
import java.io.File;
7-
8-
// TODO inline class, looks redundant
99
public class DexlibLoader {
1010
public static DexFile loadDexFile(File binaryArchiveFile) throws Exception {
11-
// TODO optimize
12-
DexFile newDexFile = DexFileFactory.loadDexFile(binaryArchiveFile,
13-
19 /*api level*/, true);
11+
DexBackedDexFile newDexFile = DexFileFactory.loadDexFile(binaryArchiveFile,
12+
Opcodes.forApi(19));
1413

1514
return newDexFile;
1615
}

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

Lines changed: 232 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,35 @@
1919
import com.google.classyshark.silverghost.translator.Translator;
2020
import com.google.classyshark.silverghost.translator.TranslatorFactory;
2121
import com.google.classyshark.silverghost.translator.java.MetaObject;
22+
import java.io.File;
23+
import java.util.ArrayList;
24+
import java.util.Iterator;
25+
import java.util.LinkedHashSet;
26+
import java.util.LinkedList;
27+
import java.util.List;
28+
import java.util.Set;
29+
import javax.annotation.Nonnull;
30+
import javax.annotation.Nullable;
2231
import org.jf.dexlib2.iface.Annotation;
2332
import org.jf.dexlib2.iface.ClassDef;
2433
import org.jf.dexlib2.iface.Field;
2534
import org.jf.dexlib2.iface.Method;
2635
import org.jf.dexlib2.iface.MethodParameter;
2736

28-
import java.io.File;
29-
import java.util.ArrayList;
30-
import java.util.List;
31-
import java.util.Set;
32-
3337
/**
3438
* Dex implementation of MetaObject
3539
*/
3640
public class MetaObjectDex extends MetaObject {
3741

38-
private final ClassDef classDef;
42+
private ClassDef classDef;
3943

4044
public MetaObjectDex(ClassDef classDef) {
4145
super();
4246
this.classDef = classDef;
47+
48+
if (this.classDef == null) {
49+
this.classDef = new EmptyClassDef();
50+
}
4351
}
4452

4553
@Override
@@ -76,7 +84,7 @@ public FieldInfo[] getDeclaredFields() {
7684
}
7785

7886
FieldInfo[] array = new FieldInfo[result.size()];
79-
return result.toArray(array);
87+
return result.toArray(array);
8088
}
8189

8290
@Override
@@ -85,7 +93,7 @@ public ConstructorInfo[] getDeclaredConstructors() {
8593
List<ConstructorInfo> result = new ArrayList<>();
8694

8795
for (Method constructor : implConstructors) {
88-
if(isConstructor(constructor)) {
96+
if (isConstructor(constructor)) {
8997
ConstructorInfo ci = new ConstructorInfo();
9098
ci.parameterTypes = convertParameters(constructor.getParameters());
9199
ci.annotations = convertAnnotations(constructor.getAnnotations());
@@ -96,7 +104,7 @@ public ConstructorInfo[] getDeclaredConstructors() {
96104
}
97105

98106
ConstructorInfo[] array = new ConstructorInfo[result.size()];
99-
return result.toArray(array);
107+
return result.toArray(array);
100108
}
101109

102110
@Override
@@ -105,7 +113,7 @@ public MethodInfo[] getDeclaredMethods() {
105113
List<MethodInfo> result = new ArrayList<>();
106114

107115
for (Method method : implMethods) {
108-
if(!isConstructor(method)) {
116+
if (!isConstructor(method)) {
109117
MethodInfo mi = new MethodInfo();
110118
mi.parameterTypes = convertParameters(method.getParameters());
111119
mi.annotations = convertAnnotations(method.getAnnotations());
@@ -119,7 +127,7 @@ public MethodInfo[] getDeclaredMethods() {
119127
}
120128

121129
MethodInfo[] array = new MethodInfo[result.size()];
122-
return result.toArray(array);
130+
return result.toArray(array);
123131
}
124132

125133
@Override
@@ -185,4 +193,217 @@ public static void main(String[] args) throws Exception {
185193

186194
System.out.println(translator.toString());
187195
}
196+
197+
private static class EmptyClassDef implements ClassDef {
198+
@Nonnull
199+
@Override
200+
public String getType() {
201+
return "";
202+
}
203+
204+
@Override
205+
public int compareTo(@Nonnull CharSequence charSequence) {
206+
return 0;
207+
}
208+
209+
@Override
210+
public int getAccessFlags() {
211+
return 0;
212+
}
213+
214+
@Nullable
215+
@Override
216+
public String getSuperclass() {
217+
return "";
218+
}
219+
220+
@Nonnull
221+
@Override
222+
public List<String> getInterfaces() {
223+
return new LinkedList<>();
224+
}
225+
226+
@Nullable
227+
@Override
228+
public String getSourceFile() {
229+
return "";
230+
}
231+
232+
@Nonnull
233+
@Override
234+
public Set<? extends Annotation> getAnnotations() {
235+
return new LinkedHashSet<>();
236+
}
237+
238+
@Nonnull
239+
@Override
240+
public Iterable<? extends Field> getStaticFields() {
241+
return new Iterable<Field>() {
242+
@Override
243+
public Iterator<Field> iterator() {
244+
return new Iterator<Field>() {
245+
@Override
246+
public boolean hasNext() {
247+
return false;
248+
}
249+
250+
@Override
251+
public Field next() {
252+
return null;
253+
}
254+
255+
@Override
256+
public void remove() {
257+
258+
}
259+
};
260+
}
261+
};
262+
}
263+
264+
@Nonnull
265+
@Override
266+
public Iterable<? extends Field> getInstanceFields() {
267+
return new Iterable<Field>() {
268+
@Override
269+
public Iterator<Field> iterator() {
270+
return new Iterator<Field>() {
271+
@Override
272+
public boolean hasNext() {
273+
return false;
274+
}
275+
276+
@Override
277+
public Field next() {
278+
return null;
279+
}
280+
281+
@Override
282+
public void remove() {
283+
284+
}
285+
};
286+
}
287+
};
288+
}
289+
290+
@Nonnull
291+
@Override
292+
public Iterable<? extends Field> getFields() {
293+
return new Iterable<Field>() {
294+
@Override
295+
public Iterator<Field> iterator() {
296+
return new Iterator<Field>() {
297+
@Override
298+
public boolean hasNext() {
299+
return false;
300+
}
301+
302+
@Override
303+
public Field next() {
304+
return null;
305+
}
306+
307+
@Override
308+
public void remove() {
309+
310+
}
311+
};
312+
}
313+
};
314+
}
315+
316+
@Nonnull
317+
@Override
318+
public Iterable<? extends Method> getDirectMethods() {
319+
return new Iterable<Method>() {
320+
@Override
321+
public Iterator<Method> iterator() {
322+
return new Iterator<Method>() {
323+
@Override
324+
public boolean hasNext() {
325+
return false;
326+
}
327+
328+
@Override
329+
public Method next() {
330+
return null;
331+
}
332+
333+
@Override
334+
public void remove() {
335+
336+
}
337+
};
338+
}
339+
};
340+
}
341+
342+
@Nonnull
343+
@Override
344+
public Iterable<? extends Method> getVirtualMethods() {
345+
return new Iterable<Method>() {
346+
@Override
347+
public Iterator<Method> iterator() {
348+
return new Iterator<Method>() {
349+
@Override
350+
public boolean hasNext() {
351+
return false;
352+
}
353+
354+
@Override
355+
public Method next() {
356+
return null;
357+
}
358+
359+
@Override
360+
public void remove() {
361+
362+
}
363+
};
364+
}
365+
};
366+
}
367+
368+
@Nonnull
369+
@Override
370+
public Iterable<? extends Method> getMethods() {
371+
return new Iterable<Method>() {
372+
@Override
373+
public Iterator<Method> iterator() {
374+
return new Iterator<Method>() {
375+
@Override
376+
public boolean hasNext() {
377+
return false;
378+
}
379+
380+
@Override
381+
public Method next() {
382+
return null;
383+
}
384+
385+
@Override
386+
public void remove() {
387+
388+
}
389+
};
390+
}
391+
};
392+
}
393+
394+
@Override
395+
public int length() {
396+
return 0;
397+
}
398+
399+
@Override
400+
public char charAt(int index) {
401+
return 0;
402+
}
403+
404+
@Override
405+
public CharSequence subSequence(int start, int end) {
406+
return "";
407+
}
408+
}
188409
}
Binary file not shown.

0 commit comments

Comments
 (0)