Fix reading order for DexBackedExceptionHandler

This commit is contained in:
Ben Gruver 2012-10-27 12:34:57 -07:00
parent 9c60ef2a10
commit 005690e855
2 changed files with 13 additions and 4 deletions

View File

@ -36,9 +36,18 @@ import org.jf.dexlib2.immutable.ImmutableExceptionHandler;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class DexBackedExceptionHandler extends ImmutableExceptionHandler { public class DexBackedExceptionHandler extends ImmutableExceptionHandler {
public DexBackedExceptionHandler(@Nonnull DexReader reader) { private DexBackedExceptionHandler(String exceptionType, int handlerCodeOffset) {
// TODO: verify dalvik doesn't accept an exception handler that points in the middle of an instruction // TODO: verify dalvik doesn't accept an exception handler that points in the middle of an instruction
super(reader.getType(reader.readSmallUleb128()), reader.readSmallUleb128()); super(exceptionType, handlerCodeOffset);
}
// static factory method, because we can't read from the reader in the correct order while calling super() in the
// constructor. ugh.
public static DexBackedExceptionHandler createNew(@Nonnull DexReader reader) {
int typeId = reader.readSmallUleb128();
String exceptionType = reader.getType(typeId);
int handlerCodeOffset = reader.readSmallUleb128();
return new DexBackedExceptionHandler(exceptionType, handlerCodeOffset);
} }
public static void skipFrom(@Nonnull DexReader reader) { public static void skipFrom(@Nonnull DexReader reader) {

View File

@ -74,7 +74,7 @@ public class DexBackedTryBlock implements TryBlock {
@Nonnull @Nonnull
@Override @Override
protected ExceptionHandler readItem(@Nonnull DexReader reader, int index) { protected ExceptionHandler readItem(@Nonnull DexReader reader, int index) {
return new DexBackedExceptionHandler(reader); return DexBackedExceptionHandler.createNew(reader);
} }
@Override @Override
@ -94,7 +94,7 @@ public class DexBackedTryBlock implements TryBlock {
if (index == sizeWithCatchAll-1) { if (index == sizeWithCatchAll-1) {
return new DexBackedCatchAllExceptionHandler(dexReader); return new DexBackedCatchAllExceptionHandler(dexReader);
} else { } else {
return new DexBackedExceptionHandler(dexReader); return DexBackedExceptionHandler.createNew(dexReader);
} }
} }