use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class InvokeCustomBuilder method build.
public static InsnNode build(MethodNode mth, InsnData insn, boolean isRange) {
try {
ICallSite callSite = InsnDataUtils.getCallSite(insn);
if (callSite == null) {
throw new JadxRuntimeException("Failed to get call site for insn: " + insn);
}
callSite.load();
List<EncodedValue> values = callSite.getValues();
if (CustomLambdaCall.isLambdaInvoke(values)) {
return CustomLambdaCall.buildLambdaMethodCall(mth, insn, isRange, values);
}
if (CustomStringConcat.isStringConcat(values)) {
return CustomStringConcat.buildStringConcat(insn, isRange, values);
}
// TODO: output raw dynamic call
throw new JadxRuntimeException("Failed to process invoke-custom instruction: " + callSite);
} catch (Exception e) {
throw new JadxRuntimeException("'invoke-custom' instruction processing error: " + e.getMessage(), e);
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class IntegrationTest method runSourceAutoCheck.
private boolean runSourceAutoCheck(String clsName) {
if (sourceCompiler == null) {
// no source code (smali case)
return true;
}
Class<?> origCls;
try {
origCls = sourceCompiler.getClass(clsName);
} catch (ClassNotFoundException e) {
rethrow("Missing class: " + clsName, e);
return true;
}
Method checkMth;
try {
checkMth = sourceCompiler.getMethod(origCls, CHECK_METHOD_NAME, new Class[] {});
} catch (NoSuchMethodException e) {
// ignore
return true;
}
if (!checkMth.getReturnType().equals(void.class) || !Modifier.isPublic(checkMth.getModifiers()) || Modifier.isStatic(checkMth.getModifiers())) {
fail("Wrong 'check' method");
return true;
}
try {
limitExecTime(() -> checkMth.invoke(origCls.getConstructor().newInstance()));
System.out.println("Source check: PASSED");
} catch (Throwable e) {
throw new JadxRuntimeException("Source check failed", e);
}
return false;
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class BaseExternalTest method processCls.
private boolean processCls(@Nullable String mthPattern, ClassNode classNode) {
classNode.load();
boolean decompile = false;
if (mthPattern == null) {
decompile = true;
} else {
for (MethodNode mth : classNode.getMethods()) {
if (isMthMatch(mth, mthPattern)) {
decompile = true;
break;
}
}
}
if (!decompile) {
return false;
}
try {
classNode.decompile();
} catch (Exception e) {
throw new JadxRuntimeException("Class process failed", e);
}
LOG.info("----------------------------------------------------------------");
LOG.info("Print class: {} from: {}", classNode.getFullName(), classNode.getInputFileName());
if (mthPattern != null) {
printMethods(classNode, mthPattern);
} else {
LOG.info("Code: \n{}", classNode.getCode());
}
checkCode(classNode);
return true;
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class RenameDialog method refreshState.
private void refreshState() {
RootNode rootNode = mainWindow.getWrapper().getDecompiler().getRoot();
new RenameVisitor().init(rootNode);
JNodeCache nodeCache = cache.getNodeCache();
JavaNode javaNode = node.getJavaNode();
List<JavaNode> toUpdate = new ArrayList<>();
if (source != null && source != node) {
toUpdate.add(source.getJavaNode());
}
if (javaNode != null) {
toUpdate.add(javaNode);
toUpdate.addAll(javaNode.getUseIn());
if (node instanceof JMethod) {
toUpdate.addAll(((JMethod) node).getJavaMethod().getOverrideRelatedMethods());
}
} else if (node instanceof JPackage) {
processPackage(toUpdate);
} else {
throw new JadxRuntimeException("Unexpected node type: " + node);
}
Set<JClass> updatedTopClasses = toUpdate.stream().map(JavaNode::getTopParentClass).map(nodeCache::makeFrom).filter(Objects::nonNull).collect(Collectors.toSet());
LOG.debug("Classes to update: {}", updatedTopClasses);
refreshTabs(mainWindow.getTabbedPane(), updatedTopClasses);
if (!updatedTopClasses.isEmpty()) {
mainWindow.getBackgroundExecutor().execute("Refreshing", () -> refreshClasses(updatedTopClasses), (status) -> {
if (status == TaskStatus.CANCEL_BY_MEMORY) {
mainWindow.showHeapUsageBar();
UiUtils.errorMessage(this, NLS.str("message.memoryLow"));
}
if (node instanceof JPackage) {
mainWindow.getTreeRoot().update();
}
mainWindow.reloadTree();
});
}
}
use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.
the class RenameDialog method buildRename.
@NotNull
private JadxCodeRename buildRename(JNode node, String newName, Set<ICodeRename> renames) {
if (node instanceof JMethod) {
JavaMethod javaMethod = ((JMethod) node).getJavaMethod();
List<JavaMethod> relatedMethods = javaMethod.getOverrideRelatedMethods();
if (!relatedMethods.isEmpty()) {
for (JavaMethod relatedMethod : relatedMethods) {
renames.remove(new JadxCodeRename(JadxNodeRef.forMth(relatedMethod), ""));
}
}
return new JadxCodeRename(JadxNodeRef.forMth(javaMethod), newName);
}
if (node instanceof JField) {
return new JadxCodeRename(JadxNodeRef.forFld(((JField) node).getJavaField()), newName);
}
if (node instanceof JClass) {
return new JadxCodeRename(JadxNodeRef.forCls(((JClass) node).getCls()), newName);
}
if (node instanceof JPackage) {
return new JadxCodeRename(JadxNodeRef.forPkg(((JPackage) node).getFullName()), newName);
}
if (node instanceof JVariable) {
JavaVariable javaVar = ((JVariable) node).getJavaVarNode();
return new JadxCodeRename(JadxNodeRef.forMth(javaVar.getMth()), JadxCodeRef.forVar(javaVar), newName);
}
throw new JadxRuntimeException("Failed to build rename node for: " + node);
}
Aggregations