use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class RegionUtils method getFirstInsn.
public static InsnNode getFirstInsn(IContainer container) {
if (container instanceof IBlock) {
IBlock block = (IBlock) container;
List<InsnNode> insnList = block.getInstructions();
if (insnList.isEmpty()) {
return null;
}
return insnList.get(0);
} else if (container instanceof IBranchRegion) {
return null;
} else if (container instanceof IRegion) {
IRegion region = (IRegion) container;
List<IContainer> blocks = region.getSubBlocks();
if (blocks.isEmpty()) {
return null;
}
return getFirstInsn(blocks.get(0));
} else {
throw new JadxRuntimeException(unknownContainerType(container));
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class RegionUtils method getLastInsn.
public static InsnNode getLastInsn(IContainer container) {
if (container instanceof IBlock) {
IBlock block = (IBlock) container;
List<InsnNode> insnList = block.getInstructions();
if (insnList.isEmpty()) {
return null;
}
return insnList.get(insnList.size() - 1);
} else if (container instanceof IBranchRegion) {
return null;
} else if (container instanceof IRegion) {
IRegion region = (IRegion) container;
List<IContainer> blocks = region.getSubBlocks();
if (blocks.isEmpty()) {
return null;
}
return getLastInsn(blocks.get(blocks.size() - 1));
} else {
throw new JadxRuntimeException(unknownContainerType(container));
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class Res9patchStreamDecoder method decode.
public boolean decode(InputStream in, OutputStream out) {
try {
BufferedImage im = ImageIO.read(in);
NinePatch np = getNinePatch(in);
if (np == null) {
return false;
}
int w = im.getWidth();
int h = im.getHeight();
BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB);
im2.createGraphics().drawImage(im, 1, 1, w, h, null);
drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight);
drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom);
int[] xDivs = np.xDivs;
for (int i = 0; i < xDivs.length - 1; i += 2) {
drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]);
}
int[] yDivs = np.yDivs;
for (int i = 0; i < yDivs.length - 1; i += 2) {
drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]);
}
ImageIO.write(im2, "png", out);
return true;
} catch (Exception e) {
throw new JadxRuntimeException("9patch image decode error", e);
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class ManifestAttributes method loadXML.
private Document loadXML(String xml) {
Document doc;
try (InputStream xmlStream = ManifestAttributes.class.getResourceAsStream(xml)) {
if (xmlStream == null) {
throw new JadxRuntimeException(xml + " not found in classpath");
}
DocumentBuilder dBuilder = XmlSecurity.getSecureDbf().newDocumentBuilder();
doc = dBuilder.parse(xmlStream);
} catch (Exception e) {
throw new JadxRuntimeException("Xml load error, file: " + xml, e);
}
return doc;
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class InsnRemover method removeSsaVar.
private static void removeSsaVar(MethodNode mth, SSAVar ssaVar) {
int useCount = ssaVar.getUseCount();
if (useCount == 0) {
mth.removeSVar(ssaVar);
return;
}
// check if all usage only in PHI insns
boolean allPhis = true;
for (RegisterArg arg : ssaVar.getUseList()) {
InsnNode parentInsn = arg.getParentInsn();
if (parentInsn == null || parentInsn.getType() != InsnType.PHI) {
allPhis = false;
break;
}
}
if (allPhis) {
for (RegisterArg arg : new ArrayList<>(ssaVar.getUseList())) {
InsnNode parentInsn = arg.getParentInsn();
if (parentInsn != null) {
((PhiInsn) parentInsn).removeArg(arg);
}
}
mth.removeSVar(ssaVar);
return;
}
if (Consts.DEBUG_WITH_ERRORS) {
throw new JadxRuntimeException("Can't remove SSA var, still in use, count: " + useCount + ", list:" + ICodeWriter.NL + " " + ssaVar.getUseList().stream().map(arg -> arg + " from " + arg.getParentInsn()).collect(Collectors.joining(ICodeWriter.NL + " ")));
}
}
Aggregations