Skip to content

Commit

Permalink
Merge pull request google#120 from google/synthetic-accessors
Browse files Browse the repository at this point in the history
Synthetic accessors
  • Loading branch information
borisf authored Aug 31, 2016
2 parents b934e72 + d62c457 commit ce6d176
Showing 9 changed files with 600 additions and 425 deletions.
4 changes: 2 additions & 2 deletions ClassySharkWS/src/com/google/classyshark/Version.java
Original file line number Diff line number Diff line change
@@ -21,6 +21,6 @@
*/
public class Version {

public static final int MAJOR = 6;
public static final int MINOR = 7;
public static final int MAJOR = 7;
public static final int MINOR = 0;
}
Original file line number Diff line number Diff line change
@@ -18,17 +18,11 @@

import com.google.classyshark.silverghost.contentreader.BinaryContentReader;
import com.google.classyshark.silverghost.contentreader.ContentReader;
import com.google.classyshark.silverghost.contentreader.dex.DexReader;
import com.google.classyshark.silverghost.translator.xml.XmlDecompressor;

import com.google.classyshark.silverghost.io.SherlockHash;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import static com.google.classyshark.silverghost.translator.java.dex.Multidex.readClassNamesFromMultidex;

public class ApkReader implements BinaryContentReader {

@@ -44,7 +38,7 @@ public ApkReader(File binaryArchive) {
public void read() {
readClassNamesFromMultidex(binaryArchive, allClassNames, components);

// TODO add check for manifest
// TODO add isPrivate for manifest
// allClassNames.add(6, "AndroidManifest.xml");
}

@@ -58,95 +52,4 @@ public List<ContentReader.Component> getComponents() {
// TODO add manifest here
return components;
}

private static void readClassNamesFromMultidex(File binaryArchiveFile,
List<String> classNames,
List<ContentReader.Component> components) {
ZipInputStream zipInputStream;
try {
zipInputStream = new ZipInputStream(new FileInputStream(
binaryArchiveFile));

ZipEntry zipEntry;

int dexIndex = 0;
while (true) {
zipEntry = zipInputStream.getNextEntry();

if (zipEntry == null) {
break;
}

if (zipEntry.getName().endsWith(".xml")) {
classNames.add(zipEntry.getName());
}

if (zipEntry.getName().endsWith(".dex")) {
String fName = "classes";
if(dexIndex > 0) {
fName = fName + dexIndex;
}
String ext = "dex";

File file = SherlockHash.INSTANCE.getFileFromZipStream(binaryArchiveFile,
zipInputStream, fName, ext);

List<String> classesAtDex =
DexReader.readClassNamesFromDex(file);

classNames.add(fName + ".dex");
classNames.addAll(classesAtDex);
dexIndex++;
}
if (zipEntry.getName().startsWith("lib")) {
components.add(
new ContentReader.Component(zipEntry.getName(),
ContentReader.ARCHIVE_COMPONENT.NATIVE_LIBRARY));
}

// Dynamic dex loading
if (zipEntry.getName().endsWith("jar") || zipEntry.getName().endsWith("zip")) {
String fName = "inner_zip";
String ext = "zip";

File innerZip = SherlockHash.INSTANCE.getFileFromZipStream(binaryArchiveFile,
zipInputStream, fName, ext);

// so far we have a zip file
ZipInputStream fromInnerZip = new ZipInputStream(new FileInputStream(
innerZip));

ZipEntry innerZipEntry;

while (true) {
innerZipEntry = fromInnerZip.getNextEntry();

if (innerZipEntry == null) {
break;
}

if (innerZipEntry.getName().endsWith(".dex")) {
fName = "inner_zip_classes" + dexIndex;
ext = "dex";
File tempDexFile =
SherlockHash.INSTANCE.getFileFromZipStream(binaryArchiveFile,
fromInnerZip, fName, ext);

List<String> classesAtDex =
DexReader.readClassNamesFromDex(tempDexFile);

String name = zipEntry.getName() + "###" + innerZipEntry.getName();

classNames.add(name);
classNames.addAll(classesAtDex);
}
}
}
}
zipInputStream.close();

} catch (Exception e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit ce6d176

Please sign in to comment.