use of jadx.plugins.input.dex.DexException in project jadx by skylot.
the class MUtf8 method decode.
public static String decode(SectionReader in) {
int len = in.readUleb128();
char[] out = new char[len];
int k = 0;
while (true) {
char a = (char) (in.readUByte() & 0xff);
if (a == 0) {
return new String(out, 0, k);
}
out[k] = a;
if (a < '\u0080') {
k++;
} else if ((a & 0xE0) == 0xC0) {
int b = in.readUByte();
if ((b & 0xC0) != 0x80) {
throw new DexException("Bad second byte");
}
out[k] = (char) (((a & 0x1F) << 6) | (b & 0x3F));
k++;
} else if ((a & 0xF0) == 0xE0) {
int b = in.readUByte();
int c = in.readUByte();
if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {
throw new DexException("Bad second or third byte");
}
out[k] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
k++;
} else {
throw new DexException("Bad byte");
}
}
}
use of jadx.plugins.input.dex.DexException in project jadx by skylot.
the class DexCodeReader method getTries.
@Override
public List<ITry> getTries() {
int triesOffset = getTriesOffset();
if (triesOffset == -1) {
return Collections.emptyList();
}
int triesCount = getTriesCount();
Map<Integer, ICatch> catchHandlers = getCatchHandlers(triesOffset + 8 * triesCount, in.copy());
in.pos(triesOffset);
List<ITry> triesList = new ArrayList<>(triesCount);
for (int i = 0; i < triesCount; i++) {
int startAddr = in.readInt();
int insnsCount = in.readUShort();
int handlerOff = in.readUShort();
ICatch catchHandler = catchHandlers.get(handlerOff);
if (catchHandler == null) {
throw new DexException("Catch handler not found by byte offset: " + handlerOff);
}
triesList.add(new TryData(startAddr, startAddr + insnsCount - 1, catchHandler));
}
return triesList;
}
use of jadx.plugins.input.dex.DexException in project jadx by skylot.
the class DexCheckSum method verify.
public static void verify(byte[] content) {
int len = content.length;
if (len < 12) {
throw new DexException("Dex file truncated, length: " + len);
}
int checksum = ByteBuffer.wrap(content, 8, 4).order(LITTLE_ENDIAN).getInt();
Adler32 adler32 = new Adler32();
adler32.update(content, 12, len - 12);
int fileChecksum = (int) (adler32.getValue());
if (checksum != fileChecksum) {
throw new DexException(String.format("Bad checksum: 0x%08x, expected: 0x%08x", fileChecksum, checksum));
}
}