use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class ProcessKotlinInternals method processInvoke.
private void processInvoke(MethodNode mth, InsnNode insn) {
int argsCount = insn.getArgsCount();
if (argsCount < 2) {
return;
}
MethodInfo invokeMth = ((InvokeNode) insn).getCallMth();
if (!kotlinVarNameSourceMethods.contains(invokeMth)) {
return;
}
InsnArg firstArg = insn.getArg(0);
if (!firstArg.isRegister()) {
return;
}
RegisterArg varArg = (RegisterArg) firstArg;
boolean renamed = false;
if (argsCount == 2) {
String str = getConstString(mth, insn, 1);
if (str != null) {
renamed = checkAndRename(varArg, str);
}
} else if (argsCount == 3) {
// TODO: use second arg for rename class
String str = getConstString(mth, insn, 2);
if (str != null) {
renamed = checkAndRename(varArg, str);
}
}
if (renamed && hideInsns) {
insn.add(AFlag.DONT_GENERATE);
}
}
use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class FridaAction method generateMethodSnippet.
private String generateMethodSnippet(JMethod jMth) {
JavaMethod javaMethod = jMth.getJavaMethod();
MethodInfo methodInfo = javaMethod.getMethodNode().getMethodInfo();
String methodName = methodInfo.getName();
if (methodInfo.isConstructor()) {
methodName = "$init";
}
String rawClassName = javaMethod.getDeclaringClass().getRawName();
String shortClassName = javaMethod.getDeclaringClass().getName();
String functionUntilImplementation;
if (isOverloaded(javaMethod.getMethodNode())) {
List<ArgType> methodArgs = methodInfo.getArgumentsTypes();
String overloadStr = methodArgs.stream().map(this::parseArgType).collect(Collectors.joining(", "));
functionUntilImplementation = String.format("%s.%s.overload(%s).implementation", shortClassName, methodName, overloadStr);
} else {
functionUntilImplementation = String.format("%s.%s.implementation", shortClassName, methodName);
}
String functionParametersString = Objects.requireNonNull(javaMethod.getTopParentClass().getCodeInfo()).getAnnotations().entrySet().stream().filter(e -> e.getKey().getLine() == jMth.getLine() && e.getValue() instanceof VarDeclareRef).sorted(Comparator.comparingInt(e -> e.getKey().getPos())).map(e -> ((VarDeclareRef) e.getValue()).getName()).collect(Collectors.joining(", "));
String functionParameterAndBody = String.format("%s = function(%s){\n" + " console.log('%s is called');\n" + " let ret = this.%s(%s);\n" + " console.log('%s ret value is ' + ret);\n" + " return ret;\n" + "};", functionUntilImplementation, functionParametersString, methodName, methodName, functionParametersString, methodName);
String finalFridaCode;
if (isInitial.getOrDefault(rawClassName, true)) {
String classSnippet = generateClassSnippet(jMth.getJParent());
finalFridaCode = classSnippet + "\n" + functionParameterAndBody;
} else {
finalFridaCode = functionParameterAndBody;
}
return finalFridaCode;
}
use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class EnumVisitor method extractEnumFieldsFromInvoke.
private List<EnumField> extractEnumFieldsFromInvoke(ClassNode cls, BlockNode staticBlock, InvokeNode invokeNode, List<InsnNode> toRemove) {
MethodInfo callMth = invokeNode.getCallMth();
MethodNode valuesMth = cls.root().resolveMethod(callMth);
if (valuesMth == null || valuesMth.isVoidReturn()) {
return null;
}
BlockNode returnBlock = Utils.getOne(valuesMth.getPreExitBlocks());
InsnNode returnInsn = BlockUtils.getLastInsn(returnBlock);
InsnNode wrappedInsn = getWrappedInsn(getSingleArg(returnInsn));
if (wrappedInsn == null) {
return null;
}
List<EnumField> enumFields = extractEnumFieldsFromInsn(cls, staticBlock, wrappedInsn, toRemove);
if (enumFields != null) {
valuesMth.add(AFlag.DONT_GENERATE);
}
return enumFields;
}
use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class CheckCode method visit.
@Override
public void visit(MethodNode mth) throws JadxException {
MethodInfo mthInfo = mth.getMethodInfo();
if (mthInfo.getArgumentsTypes().size() > 255) {
// java spec don't allow more than 255 args
if (canRemoveMethod(mth)) {
mth.ignoreMethod();
} else {
// TODO: convert args to array
}
}
checkInstructions(mth);
}
use of jadx.core.dex.info.MethodInfo in project jadx by skylot.
the class ConstInlineVisitor method needExplicitCast.
private static boolean needExplicitCast(InsnNode insn, LiteralArg arg) {
if (insn instanceof BaseInvokeNode) {
BaseInvokeNode callInsn = (BaseInvokeNode) insn;
MethodInfo callMth = callInsn.getCallMth();
int offset = callInsn.getFirstArgOffset();
int argIndex = insn.getArgIndex(arg);
ArgType argType = callMth.getArgumentsTypes().get(argIndex - offset);
if (argType.isPrimitive()) {
arg.setType(argType);
return argType.equals(ArgType.BYTE);
}
}
return false;
}
Aggregations