use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class InsnGen method makeConstructor.
private void makeConstructor(ConstructorInsn insn, ICodeWriter code) throws CodegenException {
ClassNode cls = mth.root().resolveClass(insn.getClassType());
if (cls != null && cls.isAnonymous() && !fallback) {
cls.ensureProcessed();
inlineAnonymousConstructor(code, cls, insn);
mth.getParentClass().addInlinedClass(cls);
return;
}
if (insn.isSelf()) {
throw new JadxRuntimeException("Constructor 'self' invoke must be removed!");
}
MethodNode callMth = mth.root().resolveMethod(insn.getCallMth());
if (insn.isSuper()) {
code.attachAnnotation(callMth);
code.add("super");
} else if (insn.isThis()) {
code.attachAnnotation(callMth);
code.add("this");
} else {
code.add("new ");
if (callMth == null || callMth.contains(AFlag.DONT_GENERATE)) {
// use class reference if constructor method is missing (default constructor)
code.attachAnnotation(mth.root().resolveClass(insn.getCallMth().getDeclClass()));
} else {
code.attachAnnotation(callMth);
}
mgen.getClassGen().addClsName(code, insn.getClassType());
GenericInfoAttr genericInfoAttr = insn.get(AType.GENERIC_INFO);
if (genericInfoAttr != null) {
code.add('<');
if (genericInfoAttr.isExplicit()) {
boolean first = true;
for (ArgType type : genericInfoAttr.getGenericTypes()) {
if (!first) {
code.add(',');
} else {
first = false;
}
mgen.getClassGen().useType(code, type);
}
}
code.add('>');
}
}
generateMethodArguments(code, insn, 0, callMth);
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class InsnGen method makeSimpleLambda.
private void makeSimpleLambda(ICodeWriter code, InvokeCustomNode customNode) {
try {
InsnNode callInsn = customNode.getCallInsn();
MethodInfo implMthInfo = customNode.getImplMthInfo();
int implArgsCount = implMthInfo.getArgsCount();
if (implArgsCount == 0) {
code.add("()");
} else {
code.add('(');
int callArgsCount = callInsn.getArgsCount();
int startArg = callArgsCount - implArgsCount;
if (customNode.getHandleType() != MethodHandleType.INVOKE_STATIC && customNode.getArgsCount() > 0 && customNode.getArg(0).isThis()) {
callInsn.getArg(0).add(AFlag.THIS);
}
if (startArg >= 0) {
for (int i = startArg; i < callArgsCount; i++) {
if (i != startArg) {
code.add(", ");
}
addArg(code, callInsn.getArg(i));
}
} else {
code.add("/* ERROR: " + startArg + " */");
}
code.add(')');
}
code.add(" -> {");
if (fallback) {
code.add(" // ").add(implMthInfo.toString());
}
code.incIndent();
code.startLine();
if (!implMthInfo.getReturnType().isVoid()) {
code.add("return ");
}
makeInsn(callInsn, code, Flags.INLINE);
code.add(";");
code.decIndent();
code.startLine('}');
} catch (Exception e) {
throw new JadxRuntimeException("Failed to generate 'invoke-custom' instruction: " + e.getMessage(), e);
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class ClsSet method save.
public void save(Path path) throws IOException {
FileUtils.makeDirsForFile(path);
String outputName = path.getFileName().toString();
if (outputName.endsWith(CLST_EXTENSION)) {
try (BufferedOutputStream outputStream = new BufferedOutputStream(Files.newOutputStream(path))) {
save(outputStream);
}
} else if (outputName.endsWith(".jar")) {
Path temp = FileUtils.createTempFile(".zip");
Files.copy(path, temp, StandardCopyOption.REPLACE_EXISTING);
try (ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(path));
ZipInputStream in = new ZipInputStream(Files.newInputStream(temp))) {
String clst = CLST_PATH;
boolean clstReplaced = false;
ZipEntry entry = in.getNextEntry();
while (entry != null) {
String entryName = entry.getName();
ZipEntry copyEntry = new ZipEntry(entryName);
// preserve modified time
copyEntry.setLastModifiedTime(entry.getLastModifiedTime());
out.putNextEntry(copyEntry);
if (entryName.equals(clst)) {
save(out);
clstReplaced = true;
} else {
FileUtils.copyStream(in, out);
}
entry = in.getNextEntry();
}
if (!clstReplaced) {
out.putNextEntry(new ZipEntry(clst));
save(out);
}
}
} else {
throw new JadxRuntimeException("Unknown file format: " + outputName);
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class JsonMappingGen method dump.
public static void dump(RootNode root) {
JsonMapping mapping = new JsonMapping();
fillMapping(mapping, root);
JadxArgs args = root.getArgs();
File outDirSrc = args.getOutDirSrc().getAbsoluteFile();
File mappingFile = new File(outDirSrc, "mapping.json");
FileUtils.makeDirsForFile(mappingFile);
try (Writer writer = new FileWriter(mappingFile)) {
GSON.toJson(mapping, writer);
LOG.info("Save mappings to {}", mappingFile.getAbsolutePath());
} catch (Exception e) {
throw new JadxRuntimeException("Failed to save mapping json", e);
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class InlineMethods method processInvokeInsn.
private void processInvokeInsn(MethodNode mth, BlockNode block, InvokeNode insn) {
IMethodDetails callMthDetails = insn.get(AType.METHOD_DETAILS);
if (!(callMthDetails instanceof MethodNode)) {
return;
}
MethodNode callMth = (MethodNode) callMthDetails;
try {
// TODO: sort inner classes process order by dependencies!
MethodInlineAttr mia = MarkMethodsForInline.process(callMth);
if (mia == null) {
// method not yet loaded => will retry at codegen stage
callMth.getParentClass().reloadAtCodegenStage();
return;
}
if (mia.notNeeded()) {
return;
}
inlineMethod(mth, callMth, mia, block, insn);
} catch (Exception e) {
throw new JadxRuntimeException("Failed to process method for inline: " + callMth, e);
}
}
Aggregations