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()));
}
}
}
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);
}
}
});
}
}
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);
}
}
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;
}
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;
}
Aggregations