Add support for dumping dex files that begin at some offset within a file

This commit is contained in:
Ben Gruver 2019-07-26 13:22:07 -07:00
parent 783943ebff
commit 52087a0c7c
3 changed files with 5 additions and 5 deletions

View File

@ -150,7 +150,7 @@ public class DexBuffer {
return buf; return buf;
} }
protected int getBaseOffset() { public int getBaseOffset() {
return baseOffset; return baseOffset;
} }
} }

View File

@ -175,7 +175,7 @@ public class DexAnnotator extends AnnotatedBytes {
annotator.annotateSection(this); annotator.annotateSection(this);
} }
} finally { } finally {
writeAnnotations(out, dexFile.getBuffer().getBuf()); writeAnnotations(out, dexFile.getBuffer().getBuf(), dexFile.getBuffer().getBaseOffset());
} }
} }

View File

@ -281,7 +281,7 @@ public class AnnotatedBytes {
* *
* @param out non-null; where to write to * @param out non-null; where to write to
*/ */
public void writeAnnotations(Writer out, byte[] data) throws IOException { public void writeAnnotations(Writer out, byte[] data, int offset) throws IOException {
int rightWidth = getAnnotationWidth(); int rightWidth = getAnnotationWidth();
int leftWidth = outputWidth - rightWidth - 1; int leftWidth = outputWidth - rightWidth - 1;
@ -315,14 +315,14 @@ public class AnnotatedBytes {
right = ""; right = "";
} }
String left = Hex.dump(data, rangeStart, rangeEnd - rangeStart, rangeStart, hexCols, 6); String left = Hex.dump(data, rangeStart + offset, rangeEnd - rangeStart, rangeStart + offset, hexCols, 6);
twoc.write(left, right); twoc.write(left, right);
} }
int lastKey = keys[keys.length-1]; int lastKey = keys[keys.length-1];
if (lastKey < data.length) { if (lastKey < data.length) {
String left = Hex.dump(data, lastKey, data.length - lastKey, lastKey, hexCols, 6); String left = Hex.dump(data, lastKey + offset, (data.length - offset) - lastKey, lastKey + offset, hexCols, 6);
twoc.write(left, ""); twoc.write(left, "");
} }
} }