mirror of
https://github.com/revanced/smali.git
synced 2025-05-05 00:54:25 +02:00
Tweak dexlib's "skip instructions" functionality so that it doesn't read in the CodeItems or DebugInfoItems at all
git-svn-id: https://smali.googlecode.com/svn/trunk@635 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
2bdbf739bf
commit
d79d9ebbe9
@ -478,8 +478,13 @@ public class ClassDataItem extends Item<ClassDataItem> {
|
||||
int previousIndex = previousEncodedMethod==null?0:previousEncodedMethod.method.getIndex();
|
||||
method = dexFile.MethodIdsSection.getItemByIndex(in.readUnsignedLeb128() + previousIndex);
|
||||
accessFlags = in.readUnsignedLeb128();
|
||||
codeItem = (CodeItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_CODE_ITEM,
|
||||
in.readUnsignedLeb128());
|
||||
if (dexFile.skipInstructions()) {
|
||||
in.readUnsignedLeb128();
|
||||
codeItem = null;
|
||||
} else {
|
||||
codeItem = (CodeItem)readContext.getOptionalOffsettedItemByOffset(ItemType.TYPE_CODE_ITEM,
|
||||
in.readUnsignedLeb128());
|
||||
}
|
||||
if (codeItem != null) {
|
||||
codeItem.setParent(this);
|
||||
}
|
||||
|
@ -151,77 +151,55 @@ public class CodeItem extends Item<CodeItem> {
|
||||
|
||||
int instructionCount = in.readInt();
|
||||
|
||||
if (dexFile.skipInstructions()) {
|
||||
in.skipBytes(instructionCount * 2);
|
||||
final ArrayList<Instruction> instructionList = new ArrayList<Instruction>();
|
||||
|
||||
if (triesCount > 0) {
|
||||
in.alignTo(4);
|
||||
in.skipBytes(8 * triesCount);
|
||||
byte[] encodedInstructions = in.readBytes(instructionCount * 2);
|
||||
InstructionIterator.IterateInstructions(dexFile, encodedInstructions,
|
||||
new InstructionIterator.ProcessInstructionDelegate() {
|
||||
public void ProcessInstruction(int codeAddress, Instruction instruction) {
|
||||
instructionList.add(instruction);
|
||||
}
|
||||
});
|
||||
|
||||
int handlerCount = in.readUnsignedLeb128();
|
||||
for (int i=0; i<handlerCount; i++) {
|
||||
int size = in.readSignedLeb128();
|
||||
int absSize = Math.abs(size);
|
||||
for (int j=0; j<absSize; j++) {
|
||||
in.readUnsignedLeb128();
|
||||
in.readUnsignedLeb128();
|
||||
}
|
||||
if (size <= 0) {
|
||||
in.readUnsignedLeb128();
|
||||
}
|
||||
this.instructions = new Instruction[instructionList.size()];
|
||||
instructionList.toArray(instructions);
|
||||
|
||||
if (triesCount > 0) {
|
||||
in.alignTo(4);
|
||||
|
||||
//we need to read in the catch handlers first, so save the offset to the try items for future reference
|
||||
int triesOffset = in.getCursor();
|
||||
in.setCursor(triesOffset + 8 * triesCount);
|
||||
|
||||
//read in the encoded catch handlers
|
||||
int encodedHandlerStart = in.getCursor();
|
||||
int handlerCount = in.readUnsignedLeb128();
|
||||
SparseArray<EncodedCatchHandler> handlerMap = new SparseArray<EncodedCatchHandler>(handlerCount);
|
||||
encodedCatchHandlers = new EncodedCatchHandler[handlerCount];
|
||||
for (int i=0; i<handlerCount; i++) {
|
||||
try {
|
||||
int position = in.getCursor() - encodedHandlerStart;
|
||||
encodedCatchHandlers[i] = new EncodedCatchHandler(dexFile, in);
|
||||
handlerMap.append(position, encodedCatchHandlers[i]);
|
||||
} catch (Exception ex) {
|
||||
throw ExceptionWithContext.withContext(ex, "Error while reading EncodedCatchHandler at index " + i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final ArrayList<Instruction> instructionList = new ArrayList<Instruction>();
|
||||
int codeItemEnd = in.getCursor();
|
||||
|
||||
byte[] encodedInstructions = in.readBytes(instructionCount * 2);
|
||||
InstructionIterator.IterateInstructions(dexFile, encodedInstructions,
|
||||
new InstructionIterator.ProcessInstructionDelegate() {
|
||||
public void ProcessInstruction(int codeAddress, Instruction instruction) {
|
||||
instructionList.add(instruction);
|
||||
}
|
||||
});
|
||||
|
||||
this.instructions = new Instruction[instructionList.size()];
|
||||
instructionList.toArray(instructions);
|
||||
|
||||
if (triesCount > 0) {
|
||||
in.alignTo(4);
|
||||
|
||||
//we need to read in the catch handlers first, so save the offset to the try items for future reference
|
||||
int triesOffset = in.getCursor();
|
||||
in.setCursor(triesOffset + 8 * triesCount);
|
||||
|
||||
//read in the encoded catch handlers
|
||||
int encodedHandlerStart = in.getCursor();
|
||||
int handlerCount = in.readUnsignedLeb128();
|
||||
SparseArray<EncodedCatchHandler> handlerMap = new SparseArray<EncodedCatchHandler>(handlerCount);
|
||||
encodedCatchHandlers = new EncodedCatchHandler[handlerCount];
|
||||
for (int i=0; i<handlerCount; i++) {
|
||||
try {
|
||||
int position = in.getCursor() - encodedHandlerStart;
|
||||
encodedCatchHandlers[i] = new EncodedCatchHandler(dexFile, in);
|
||||
handlerMap.append(position, encodedCatchHandlers[i]);
|
||||
} catch (Exception ex) {
|
||||
throw ExceptionWithContext.withContext(ex, "Error while reading EncodedCatchHandler at index " + i);
|
||||
}
|
||||
//now go back and read the tries
|
||||
in.setCursor(triesOffset);
|
||||
tries = new TryItem[triesCount];
|
||||
for (int i=0; i<triesCount; i++) {
|
||||
try {
|
||||
tries[i] = new TryItem(in, handlerMap);
|
||||
} catch (Exception ex) {
|
||||
throw ExceptionWithContext.withContext(ex, "Error while reading TryItem at index " + i);
|
||||
}
|
||||
int codeItemEnd = in.getCursor();
|
||||
|
||||
//now go back and read the tries
|
||||
in.setCursor(triesOffset);
|
||||
tries = new TryItem[triesCount];
|
||||
for (int i=0; i<triesCount; i++) {
|
||||
try {
|
||||
tries[i] = new TryItem(in, handlerMap);
|
||||
} catch (Exception ex) {
|
||||
throw ExceptionWithContext.withContext(ex, "Error while reading TryItem at index " + i);
|
||||
}
|
||||
}
|
||||
|
||||
//and now back to the end of the code item
|
||||
in.setCursor(codeItemEnd);
|
||||
}
|
||||
|
||||
//and now back to the end of the code item
|
||||
in.setCursor(codeItemEnd);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,6 +409,10 @@ public class DexFile
|
||||
continue;
|
||||
}
|
||||
|
||||
if (skipInstructions && (section == CodeItemsSection || section == DebugInfoItemsSection)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int sectionOffset = readContext.getSectionOffset(section.ItemType);
|
||||
if (sectionOffset > 0) {
|
||||
int sectionSize = readContext.getSectionSize(section.ItemType);
|
||||
|
Loading…
x
Reference in New Issue
Block a user