Search in sources :

Example 11 with JavaClass

use of jadx.api.JavaClass in project jadx by skylot.

the class UsageDialog method processUsageClass.

private void processUsageClass(JavaNode usageNode) {
    JavaClass cls = usageNode.getTopParentClass();
    String code = cls.getCodeInfo().getCodeStr();
    CodeLinesInfo linesInfo = new CodeLinesInfo(cls);
    List<? extends JavaNode> targetNodes = getMethodWithOverride();
    for (JavaNode javaNode : targetNodes) {
        List<CodePosition> usage = cls.getUsageFor(javaNode);
        for (CodePosition pos : usage) {
            if (javaNode.getTopParentClass().equals(cls) && pos.getPos() == javaNode.getDefPos()) {
                // skip declaration
                continue;
            }
            StringRef line = getLineStrAt(code, pos.getPos());
            if (line.startsWith("import ")) {
                continue;
            }
            JavaNode javaNodeByLine = linesInfo.getJavaNodeByLine(pos.getLine());
            JNode useAtNode = javaNodeByLine == null ? node : getNodeCache().makeFrom(javaNodeByLine);
            usageList.add(new CodeNode(useAtNode, line, pos.getLine(), pos.getPos()));
        }
    }
}
Also used : CodePosition(jadx.api.CodePosition) JavaClass(jadx.api.JavaClass) CodeNode(jadx.gui.treemodel.CodeNode) CodeLinesInfo(jadx.gui.utils.CodeLinesInfo) StringRef(jadx.gui.utils.search.StringRef) JNode(jadx.gui.treemodel.JNode) JavaNode(jadx.api.JavaNode)

Example 12 with JavaClass

use of jadx.api.JavaClass in project jadx by skylot.

the class IndexJob method runJob.

protected void runJob() {
    JNodeCache nodeCache = cache.getNodeCache();
    final TextSearchIndex index = new TextSearchIndex(nodeCache);
    final CodeUsageInfo usageInfo = new CodeUsageInfo(nodeCache);
    cache.setTextIndex(index);
    cache.setUsageInfo(usageInfo);
    for (final JavaClass cls : wrapper.getClasses()) {
        addTask(new Runnable() {

            @Override
            public void run() {
                try {
                    index.indexNames(cls);
                    CodeLinesInfo linesInfo = new CodeLinesInfo(cls);
                    List<StringRef> lines = splitLines(cls);
                    usageInfo.processClass(cls, linesInfo, lines);
                    if (Utils.isFreeMemoryAvailable()) {
                        index.indexCode(cls, linesInfo, lines);
                    } else {
                        index.classCodeIndexSkipped(cls);
                    }
                } catch (Exception e) {
                    LOG.error("Index error in class: {}", cls.getFullName(), e);
                }
            }
        });
    }
}
Also used : CodeUsageInfo(jadx.gui.utils.CodeUsageInfo) JavaClass(jadx.api.JavaClass) List(java.util.List) JNodeCache(jadx.gui.utils.JNodeCache) TextSearchIndex(jadx.gui.utils.search.TextSearchIndex) CodeLinesInfo(jadx.gui.utils.CodeLinesInfo)

Example 13 with JavaClass

use of jadx.api.JavaClass in project jadx by skylot.

the class TextSearchIndex method indexNames.

public void indexNames(JavaClass cls) {
    clsNamesIndex.put(cls.getFullName(), nodeCache.makeFrom(cls));
    for (JavaMethod mth : cls.getMethods()) {
        JNode mthNode = nodeCache.makeFrom(mth);
        mthSignaturesIndex.put(mthNode.makeDescString(), mthNode);
    }
    for (JavaField fld : cls.getFields()) {
        JNode fldNode = nodeCache.makeFrom(fld);
        fldSignaturesIndex.put(fldNode.makeDescString(), fldNode);
    }
    for (JavaClass innerCls : cls.getInnerClasses()) {
        indexNames(innerCls);
    }
}
Also used : JavaField(jadx.api.JavaField) JavaClass(jadx.api.JavaClass) JavaMethod(jadx.api.JavaMethod) JNode(jadx.gui.treemodel.JNode)

Example 14 with JavaClass

use of jadx.api.JavaClass in project jadx by skylot.

the class IndexTask method scheduleJobs.

@Override
public List<Runnable> scheduleJobs() {
    IndexService indexService = mainWindow.getCacheObject().getIndexService();
    List<JavaClass> classesForIndex = wrapper.getIncludedClasses().stream().filter(indexService::isIndexNeeded).collect(Collectors.toList());
    expectedCompleteCount = classesForIndex.size();
    indexService.setComplete(false);
    complete.set(0);
    List<Runnable> jobs = new ArrayList<>(2);
    jobs.add(indexService::indexResources);
    jobs.add(() -> {
        for (JavaClass cls : classesForIndex) {
            try {
                // TODO: a lot of synchronizations to index object, not efficient for parallel usage
                if (indexService.indexCls(cls)) {
                    complete.incrementAndGet();
                } else {
                    LOG.debug("Index skipped for {}", cls);
                }
            } catch (Throwable e) {
                LOG.error("Failed to index class: {}", cls, e);
            }
        }
    });
    return jobs;
}
Also used : JavaClass(jadx.api.JavaClass) ArrayList(java.util.ArrayList)

Example 15 with JavaClass

use of jadx.api.JavaClass in project jadx by skylot.

the class DbgUtils method searchMainActivity.

/**
 * @return the Activity class for android.intent.action.MAIN.
 */
@Nullable
public static JClass searchMainActivity(MainWindow mainWindow) {
    String content = getManifestContent(mainWindow);
    // current position
    int pos;
    // last found action's index
    int actionPos = 0;
    String actionTag = "<action android:name=\"android.intent.action.MAIN\"";
    // beginning offset. suggested length set after first iteration
    int actionTagLen = 0;
    while (actionPos > -1) {
        pos = content.indexOf(actionTag, actionPos + actionTagLen);
        actionPos = pos;
        int activityPos = content.lastIndexOf("<activity ", pos);
        if (activityPos > -1) {
            int aliasPos = content.lastIndexOf("<activity-alias ", pos);
            boolean isAnAlias = aliasPos > -1 && aliasPos > activityPos;
            String classPathAttribute = " android:" + (isAnAlias ? "targetActivity" : "name") + "=\"";
            pos = content.indexOf(classPathAttribute, isAnAlias ? aliasPos : activityPos);
            if (pos > -1) {
                pos += classPathAttribute.length();
                String classFullName = content.substring(pos, content.indexOf("\"", pos));
                // in case the MainActivity class has been renamed before, we need raw name.
                JavaClass cls = mainWindow.getWrapper().getDecompiler().searchJavaClassByAliasFullName(classFullName);
                JNode jNode = mainWindow.getCacheObject().getNodeCache().makeFrom(cls);
                if (jNode != null) {
                    return jNode.getRootClass();
                }
            }
        }
        if (actionTagLen == 0) {
            actionTagLen = actionTag.length();
        }
    }
    return null;
}
Also used : JavaClass(jadx.api.JavaClass) JNode(jadx.gui.treemodel.JNode) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JavaClass (jadx.api.JavaClass)20 JavaMethod (jadx.api.JavaMethod)7 JavaField (jadx.api.JavaField)5 JavaNode (jadx.api.JavaNode)3 JNode (jadx.gui.treemodel.JNode)3 CodePosition (jadx.api.CodePosition)2 JClass (jadx.gui.treemodel.JClass)2 CodeLinesInfo (jadx.gui.utils.CodeLinesInfo)2 JNodeCache (jadx.gui.utils.JNodeCache)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 JavaVariable (jadx.api.JavaVariable)1 IJavaNodeRef (jadx.api.data.IJavaNodeRef)1 ICodeRawOffset (jadx.api.data.annotations.ICodeRawOffset)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1 JadxWrapper (jadx.gui.JadxWrapper)1 CodeNode (jadx.gui.treemodel.CodeNode)1 JField (jadx.gui.treemodel.JField)1 JMethod (jadx.gui.treemodel.JMethod)1