Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

file name added to the output #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/com/android/dexdeps/DexData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Data extracted from a DEX file.
*/
public class DexData {
private String mDexFileName;
private RandomAccessFile mDexFile;
private HeaderItem mHeaderItem;
private String[] mStrings; // strings from string_data_*
Expand All @@ -39,8 +40,9 @@ public class DexData {
/**
* Constructs a new DexData for this file.
*/
public DexData(RandomAccessFile raf) {
mDexFile = raf;
public DexData(String dexFileName, RandomAccessFile randomAccessFile) {
mDexFile = randomAccessFile;
mDexFileName = dexFileName;
}

/**
Expand All @@ -62,6 +64,10 @@ public void load() throws IOException {
markInternalClasses();
}

public String getDexFileName() {
return mDexFileName;
}

/**
* Verifies the given magic number.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/info/persistent/dex/DexFieldCounts.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void generate(DexData dexData, boolean includeClasses, String packageFilt

private static FieldRef[] getFieldRefs(DexData dexData, Filter filter) {
FieldRef[] fieldRefs = dexData.getFieldRefs();
out.println("Read in " + fieldRefs.length + " field IDs.");
out.println("Read in " + fieldRefs.length + " field IDs from " + dexData.getDexFileName() + ".");
if (filter == Filter.ALL) {
return fieldRefs;
}
Expand Down
2 changes: 1 addition & 1 deletion src/info/persistent/dex/DexMethodCounts.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void generate(DexData dexData, boolean includeClasses, String packageFilt

private static MethodRef[] getMethodRefs(DexData dexData, Filter filter) {
MethodRef[] methodRefs = dexData.getMethodRefs();
out.println("Read in " + methodRefs.length + " method IDs.");
out.println("Read in " + methodRefs.length + " method IDs from " + dexData.getDexFileName() + ".");
if (filter == Filter.ALL) {
return methodRefs;
}
Expand Down
27 changes: 11 additions & 16 deletions src/info/persistent/dex/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@
import com.android.dexdeps.DexData;
import com.android.dexdeps.DexDataException;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -54,10 +48,11 @@ void run(String[] args) {
} else {
counts = new DexMethodCounts(outputStyle);
}
List<RandomAccessFile> dexFiles = openInputFiles(fileName);
Map<String, RandomAccessFile> dexFiles = openInputFiles(fileName);

for (RandomAccessFile dexFile : dexFiles) {
DexData dexData = new DexData(dexFile);
for (String dexFilenName : dexFiles.keySet()) {
RandomAccessFile dexFile = dexFiles.get(dexFilenName);
DexData dexData = new DexData(dexFilenName, dexFile);
dexData.load();
counts.generate(dexData, includeClasses, packageFilter, maxDepth, filter);
dexFile.close();
Expand Down Expand Up @@ -85,14 +80,14 @@ void run(String[] args) {
* classes.dex inside. If the latter, we extract the contents to a
* temporary file.
*/
List<RandomAccessFile> openInputFiles(String fileName) throws IOException {
List<RandomAccessFile> dexFiles = new ArrayList<RandomAccessFile>();
Map<String,RandomAccessFile> openInputFiles(String fileName) throws IOException {
Map<String,RandomAccessFile> dexFiles = new HashMap<String, RandomAccessFile>();

openInputFileAsZip(fileName, dexFiles);
if (dexFiles.size() == 0) {
File inputFile = new File(fileName);
RandomAccessFile dexFile = new RandomAccessFile(inputFile, "r");
dexFiles.add(dexFile);
dexFiles.put(fileName, dexFile);
}

return dexFiles;
Expand All @@ -102,7 +97,7 @@ List<RandomAccessFile> openInputFiles(String fileName) throws IOException {
* Tries to open an input file as a Zip archive (jar/apk) with a
* "classes.dex" inside.
*/
void openInputFileAsZip(String fileName, List<RandomAccessFile> dexFiles) throws IOException {
void openInputFileAsZip(String fileName, Map<String,RandomAccessFile> dexFiles) throws IOException {
ZipFile zipFile;

// Try it as a zip file.
Expand All @@ -121,7 +116,7 @@ void openInputFileAsZip(String fileName, List<RandomAccessFile> dexFiles) throws
// Open and add all files matching "classes.*\.dex" in the zip file.
for (ZipEntry entry : Collections.list(zipFile.entries())) {
if (entry.getName().matches("classes.*\\.dex")) {
dexFiles.add(openDexFile(zipFile, entry));
dexFiles.put(entry.getName(), openDexFile(zipFile, entry));
}
}

Expand Down