use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class TextResMapFile method write.
public static void write(Path resMapFile, Map<Integer, String> inputResMap) {
try {
Map<Integer, String> resMap = new TreeMap<>(inputResMap);
List<String> lines = new ArrayList<>(resMap.size());
for (Map.Entry<Integer, String> entry : resMap.entrySet()) {
lines.add(String.format("%08x=%s", entry.getKey(), entry.getValue()));
}
Files.write(resMapFile, lines, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new JadxRuntimeException("Failed to write res-map file", e);
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class ExportGradleProject method parseXml.
private Document parseXml(String xmlContent) {
try {
DocumentBuilder builder = XmlSecurity.getSecureDbf().newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(xmlContent)));
document.getDocumentElement().normalize();
return document;
} catch (Exception e) {
throw new JadxRuntimeException("Can not parse xml content", e);
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class FileUtils method createTempDir.
public static Path createTempDir(String prefix) {
try {
Path dir = Files.createTempDirectory(TEMP_ROOT_DIR, prefix);
dir.toFile().deleteOnExit();
return dir;
} catch (Exception e) {
throw new JadxRuntimeException("Failed to create temp directory with suffix: " + prefix, e);
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class RegionGen method makeLoop.
public void makeLoop(LoopRegion region, ICodeWriter code) throws CodegenException {
code.startLineWithNum(region.getSourceLine());
LoopLabelAttr labelAttr = region.getInfo().getStart().get(AType.LOOP_LABEL);
if (labelAttr != null) {
code.add(mgen.getNameGen().getLoopLabel(labelAttr)).add(": ");
}
IfCondition condition = region.getCondition();
if (condition == null) {
// infinite loop
code.add("while (true) {");
makeRegionIndent(code, region.getBody());
code.startLine('}');
return;
}
InsnNode condInsn = condition.getFirstInsn();
InsnCodeOffset.attach(code, condInsn);
ConditionGen conditionGen = new ConditionGen(this);
LoopType type = region.getType();
if (type != null) {
if (type instanceof ForLoop) {
ForLoop forLoop = (ForLoop) type;
code.add("for (");
makeInsn(forLoop.getInitInsn(), code, Flags.INLINE);
code.add("; ");
conditionGen.add(code, condition);
code.add("; ");
makeInsn(forLoop.getIncrInsn(), code, Flags.INLINE);
code.add(") {");
CodeGenUtils.addCodeComments(code, mth, condInsn);
makeRegionIndent(code, region.getBody());
code.startLine('}');
return;
}
if (type instanceof ForEachLoop) {
ForEachLoop forEachLoop = (ForEachLoop) type;
code.add("for (");
declareVar(code, forEachLoop.getVarArg());
code.add(" : ");
addArg(code, forEachLoop.getIterableArg(), false);
code.add(") {");
CodeGenUtils.addCodeComments(code, mth, condInsn);
makeRegionIndent(code, region.getBody());
code.startLine('}');
return;
}
throw new JadxRuntimeException("Unknown loop type: " + type.getClass());
}
if (region.isConditionAtEnd()) {
code.add("do {");
CodeGenUtils.addCodeComments(code, mth, condInsn);
makeRegionIndent(code, region.getBody());
code.startLineWithNum(region.getSourceLine());
code.add("} while (");
conditionGen.add(code, condition);
code.add(");");
} else {
code.add("while (");
conditionGen.add(code, condition);
code.add(") {");
CodeGenUtils.addCodeComments(code, mth, condInsn);
makeRegionIndent(code, region.getBody());
code.startLine('}');
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class InsnDecoder method invokeSpecial.
private InsnNode invokeSpecial(InsnData insn) {
IMethodRef mthRef = InsnDataUtils.getMethodRef(insn);
if (mthRef == null) {
throw new JadxRuntimeException("Failed to load method reference for insn: " + insn);
}
MethodInfo mthInfo = MethodInfo.fromRef(root, mthRef);
// convert 'special' to 'direct/super' same as dx
InvokeType type;
if (mthInfo.isConstructor() || Objects.equals(mthInfo.getDeclClass(), method.getParentClass().getClassInfo())) {
type = InvokeType.DIRECT;
} else {
type = InvokeType.SUPER;
}
return new InvokeNode(mthInfo, insn, type, false);
}
Aggregations