mirror of
https://github.com/revanced/smali.git
synced 2025-05-29 12:20:11 +02:00
Massage the try blocks before writing them out to a dex file
This commit is contained in:
parent
8c3d16b7ee
commit
ab73502b60
@ -46,6 +46,7 @@ import org.jf.dexlib2.iface.reference.*;
|
|||||||
import org.jf.dexlib2.util.MethodUtil;
|
import org.jf.dexlib2.util.MethodUtil;
|
||||||
import org.jf.dexlib2.util.ReferenceUtil;
|
import org.jf.dexlib2.util.ReferenceUtil;
|
||||||
import org.jf.dexlib2.writer.util.InstructionWriteUtil;
|
import org.jf.dexlib2.writer.util.InstructionWriteUtil;
|
||||||
|
import org.jf.dexlib2.writer.util.TryListBuilder;
|
||||||
import org.jf.util.ExceptionWithContext;
|
import org.jf.util.ExceptionWithContext;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -152,7 +153,7 @@ public class CodeItemPool {
|
|||||||
InstructionWriteUtil instrWriteUtil = new InstructionWriteUtil(methodImpl, dexFile.stringPool);
|
InstructionWriteUtil instrWriteUtil = new InstructionWriteUtil(methodImpl, dexFile.stringPool);
|
||||||
writer.writeUshort(instrWriteUtil.getOutParamCount());
|
writer.writeUshort(instrWriteUtil.getOutParamCount());
|
||||||
|
|
||||||
List<? extends TryBlock> tryBlocks = methodImpl.getTryBlocks();
|
List<? extends TryBlock> tryBlocks = TryListBuilder.massageTryBlocks(methodImpl.getTryBlocks());
|
||||||
writer.writeUshort(tryBlocks.size());
|
writer.writeUshort(tryBlocks.size());
|
||||||
writer.writeInt(dexFile.debugInfoPool.getOffset(method));
|
writer.writeInt(dexFile.debugInfoPool.getOffset(method));
|
||||||
writer.writeInt(instrWriteUtil.getCodeUnitCount());
|
writer.writeInt(instrWriteUtil.getCodeUnitCount());
|
||||||
|
@ -62,6 +62,20 @@ public class TryListBuilder
|
|||||||
listEnd.prev = listStart;
|
listEnd.prev = listStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<TryBlock> massageTryBlocks(List<? extends TryBlock> tryBlocks) {
|
||||||
|
TryListBuilder tlb = new TryListBuilder();
|
||||||
|
for (TryBlock tryBlock: tryBlocks) {
|
||||||
|
int startAddress = tryBlock.getStartCodeAddress();
|
||||||
|
int endAddress = startAddress + tryBlock.getCodeUnitCount();
|
||||||
|
|
||||||
|
for (ExceptionHandler exceptionHandler: tryBlock.getExceptionHandlers()) {
|
||||||
|
tlb.addHandler(exceptionHandler.getExceptionType(), startAddress, endAddress,
|
||||||
|
exceptionHandler.getHandlerCodeAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tlb.getTryBlocks();
|
||||||
|
}
|
||||||
|
|
||||||
private static class TryBounds {
|
private static class TryBounds {
|
||||||
@Nonnull public final MutableTryBlock start;
|
@Nonnull public final MutableTryBlock start;
|
||||||
@Nonnull public final MutableTryBlock end;
|
@Nonnull public final MutableTryBlock end;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user