Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add button to go to Application class #2213

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private ApplicationParams parseAttributes() {
Integer versionCode = null;
String versionName = null;
String mainActivity = null;
String application = null;

Element manifest = (Element) androidManifest.getElementsByTagName("manifest").item(0);
Element usesSdk = (Element) androidManifest.getElementsByTagName("uses-sdk").item(0);
Expand Down Expand Up @@ -95,9 +96,12 @@ private ApplicationParams parseAttributes() {
if (parseAttrs.contains(AppAttribute.MAIN_ACTIVITY)) {
mainActivity = getMainActivityName();
}
if (parseAttrs.contains(AppAttribute.APPLICATION)) {
application = getApplicationName();
}

return new ApplicationParams(applicationLabel, minSdkVersion, targetSdkVersion, versionCode,
versionName, mainActivity);
versionName, mainActivity, application);
}

private String getApplicationLabel() {
Expand Down Expand Up @@ -137,6 +141,14 @@ private String getMainActivityName() {
return mainActivityName;
}

private String getApplicationName() {
Element application = (Element) androidManifest.getElementsByTagName("application").item(0);
if (application.hasAttribute("android:name")) {
return application.getAttribute("android:name");
}
return null;
}

private String getMainActivityNameThroughActivityAliasTag() {
NodeList activityAliasNodes = androidManifest.getElementsByTagName("activity-alias");
for (int i = 0; i < activityAliasNodes.getLength(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public enum AppAttribute {
VERSION_CODE,
VERSION_NAME,
MAIN_ACTIVITY,
APPLICATION,
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ public class ApplicationParams {
private final Integer versionCode;
private final String versionName;
private final String mainActivtiy;
private final String application;

public ApplicationParams(String applicationLabel, Integer minSdkVersion, Integer targetSdkVersion, Integer versionCode,
String versionName, String mainActivtiy) {
String versionName, String mainActivtiy, String application) {
this.applicationLabel = applicationLabel;
this.minSdkVersion = minSdkVersion;
this.targetSdkVersion = targetSdkVersion;
this.versionCode = versionCode;
this.versionName = versionName;
this.mainActivtiy = mainActivtiy;
this.application = application;
}

public String getApplicationName() {
Expand All @@ -42,11 +44,19 @@ public String getVersionName() {
return versionName;
}

public String getMainActivityName() {
public String getMainActivity() {
return mainActivtiy;
}

public JavaClass getMainActivity(JadxDecompiler decompiler) {
public JavaClass getMainActivityJavaClass(JadxDecompiler decompiler) {
return decompiler.searchJavaClassByOrigFullName(mainActivtiy);
}

public String getApplication() {
return application;
}

public JavaClass getApplicationJavaClass(JadxDecompiler decompiler) {
return decompiler.searchJavaClassByOrigFullName(application);
}
}
4 changes: 2 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/device/debugger/DbgUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public String getProcessName() {
return null;
}
ApplicationParams results = parser.parse();
String mainActivityName = results.getMainActivityName();
String mainActivityName = results.getMainActivity();
if (mainActivityName == null) {
UiUtils.errorMessage(mw, NLS.str("adb_dialog.msg_read_mani_fail"));
return null;
Expand All @@ -163,7 +163,7 @@ public String getProcessName() {
UiUtils.errorMessage(mw, "Invalid main activity name");
return null;
}
JavaClass mainActivityClass = results.getMainActivity(decompiler);
JavaClass mainActivityClass = results.getMainActivityJavaClass(decompiler);
if (mainActivityClass == null) {
UiUtils.errorMessage(mw, NLS.str("error_dialog.not_found", "Main activity class"));
return null;
Expand Down
53 changes: 44 additions & 9 deletions jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ public void textSearch() {
SearchDialog.search(MainWindow.this, SearchDialog.SearchPreset.TEXT);
}

public void gotoMainActivity() {
public void goToMainActivity() {
AndroidManifestParser parser = new AndroidManifestParser(
AndroidManifestParser.getAndroidManifest(getWrapper().getResources()),
EnumSet.of(AppAttribute.MAIN_ACTIVITY));
Expand All @@ -965,12 +965,12 @@ public void gotoMainActivity() {
}
try {
ApplicationParams results = parser.parse();
if (results.getMainActivityName() == null) {
if (results.getMainActivity() == null) {
throw new JadxRuntimeException("Failed to get main activity name from manifest");
}
JavaClass mainActivityClass = results.getMainActivity(getWrapper().getDecompiler());
JavaClass mainActivityClass = results.getMainActivityJavaClass(getWrapper().getDecompiler());
if (mainActivityClass == null) {
throw new JadxRuntimeException("Failed to find main activity class: " + results.getMainActivityName());
throw new JadxRuntimeException("Failed to find main activity class: " + results.getMainActivity());
}
tabbedPane.codeJump(getCacheObject().getNodeCache().makeFrom(mainActivityClass));
} catch (Exception e) {
Expand All @@ -982,6 +982,36 @@ public void gotoMainActivity() {
}
}

public void goToApplication() {
AndroidManifestParser parser = new AndroidManifestParser(
AndroidManifestParser.getAndroidManifest(getWrapper().getResources()),
EnumSet.of(AppAttribute.APPLICATION));
if (!parser.isManifestFound()) {
JOptionPane.showMessageDialog(MainWindow.this,
NLS.str("error_dialog.not_found", "AndroidManifest.xml"),
NLS.str("error_dialog.title"),
JOptionPane.ERROR_MESSAGE);
return;
}
try {
ApplicationParams results = parser.parse();
if (results.getApplication() == null) {
throw new JadxRuntimeException("Failed to get application from manifest");
}
JavaClass applicationClass = results.getApplicationJavaClass(getWrapper().getDecompiler());
if (applicationClass == null) {
throw new JadxRuntimeException("Failed to find application class: " + results.getApplication());
}
tabbedPane.codeJump(getCacheObject().getNodeCache().makeFrom(applicationClass));
} catch (Exception e) {
LOG.error("Application not found", e);
JOptionPane.showMessageDialog(MainWindow.this,
NLS.str("error_dialog.not_found", "Application"),
NLS.str("error_dialog.title"),
JOptionPane.ERROR_MESSAGE);
}
}

private void initMenuAndToolbar() {
JadxGuiAction openAction = new JadxGuiAction(ActionModel.OPEN, this::openFileDialog);
JadxGuiAction openProject = new JadxGuiAction(ActionModel.OPEN_PROJECT, this::openProjectDialog);
Expand Down Expand Up @@ -1036,8 +1066,10 @@ private void initMenuAndToolbar() {
() -> SearchDialog.search(MainWindow.this, SearchDialog.SearchPreset.CLASS));
JadxGuiAction commentSearchAction = new JadxGuiAction(ActionModel.COMMENT_SEARCH,
() -> SearchDialog.search(MainWindow.this, SearchDialog.SearchPreset.COMMENT));
JadxGuiAction gotoMainActivityAction = new JadxGuiAction(ActionModel.GOTO_MAIN_ACTIVITY,
this::gotoMainActivity);
JadxGuiAction goToMainActivityAction = new JadxGuiAction(ActionModel.GO_TO_MAIN_ACTIVITY,
this::goToMainActivity);
JadxGuiAction goToApplicationAction = new JadxGuiAction(ActionModel.GO_TO_APPLICATION,
this::goToApplication);
JadxGuiAction decompileAllAction = new JadxGuiAction(ActionModel.DECOMPILE_ALL, this::requestFullDecompilation);
JadxGuiAction resetCacheAction = new JadxGuiAction(ActionModel.RESET_CACHE, this::resetCodeCache);
JadxGuiAction deobfAction = new JadxGuiAction(ActionModel.DEOBF, this::toggleDeobfuscation);
Expand Down Expand Up @@ -1097,7 +1129,8 @@ private void initMenuAndToolbar() {
nav.add(textSearchAction);
nav.add(clsSearchAction);
nav.add(commentSearchAction);
nav.add(gotoMainActivityAction);
nav.add(goToMainActivityAction);
nav.add(goToApplicationAction);
nav.addSeparator();
nav.add(backAction);
nav.add(forwardAction);
Expand Down Expand Up @@ -1162,7 +1195,8 @@ public void actionPerformed(ActionEvent e) {
toolbar.add(textSearchAction);
toolbar.add(clsSearchAction);
toolbar.add(commentSearchAction);
toolbar.add(gotoMainActivityAction);
toolbar.add(goToMainActivityAction);
toolbar.add(goToApplicationAction);
toolbar.addSeparator();
toolbar.add(backAction);
toolbar.add(forwardAction);
Expand Down Expand Up @@ -1190,7 +1224,8 @@ public void actionPerformed(ActionEvent e) {
textSearchAction.setEnabled(loaded);
clsSearchAction.setEnabled(loaded);
commentSearchAction.setEnabled(loaded);
gotoMainActivityAction.setEnabled(loaded);
goToMainActivityAction.setEnabled(loaded);
goToApplicationAction.setEnabled(loaded);
backAction.setEnabled(loaded);
backVariantAction.setEnabled(loaded);
forwardAction.setEnabled(loaded);
Expand Down
4 changes: 3 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/action/ActionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ public enum ActionModel {
Shortcut.keyboard(KeyEvent.VK_N, UiUtils.ctrlButton())),
COMMENT_SEARCH(MENU_TOOLBAR, "menu.comment_search", "menu.comment_search", "ui/usagesFinder",
Shortcut.keyboard(KeyEvent.VK_SEMICOLON, UiUtils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK)),
GOTO_MAIN_ACTIVITY(MENU_TOOLBAR, "menu.goto_main_activity", "menu.goto_main_activity", "ui/home",
GO_TO_MAIN_ACTIVITY(MENU_TOOLBAR, "menu.goto_main_activity", "menu.goto_main_activity", "ui/home",
Shortcut.keyboard(KeyEvent.VK_M, UiUtils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK)),
GO_TO_APPLICATION(MENU_TOOLBAR, "menu.go_to_application", "menu.go_to_application", "ui/application",
Shortcut.keyboard(KeyEvent.VK_A, UiUtils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK)),
DECOMPILE_ALL(MENU_TOOLBAR, "menu.decompile_all", "menu.decompile_all", "ui/runAll",
Shortcut.none()),
RESET_CACHE(MENU_TOOLBAR, "menu.reset_cache", "menu.reset_cache", "ui/reset",
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.text_search=Textsuche
menu.class_search=Klassen-Suche
menu.comment_search=Kommentar suchen
#menu.goto_main_activity=
#menu.go_to_application=Go to Application
menu.tools=Tools
#menu.plugins=Plugins
#menu.decompile_all=Decompile all classes
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.text_search=Text search
menu.class_search=Class search
menu.comment_search=Comment search
menu.goto_main_activity=Go to main Activity
menu.go_to_application=Go to Application
menu.tools=Tools
menu.plugins=Plugins
menu.decompile_all=Decompile all classes
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_es_ES.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.text_search=Buscar texto
menu.class_search=Buscar clase
#menu.comment_search=Comment search
#menu.goto_main_activity=
#menu.go_to_application=Go to Application
menu.tools=Herramientas
#menu.plugins=Plugins
#menu.decompile_all=Decompile all classes
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_id_ID.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.text_search=Pencarian Teks
menu.class_search=Pencarian Kelas
menu.comment_search=Pencarian Komentar
menu.goto_main_activity=Pergi ke Activitas Utama
#menu.go_to_application=Go to Application
menu.tools=Alat
menu.plugins=Plugin
menu.decompile_all=Deskompilasi semua kelas
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_ko_KR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.text_search=텍스트 검색
menu.class_search=클래스 검색
menu.comment_search=주석 검색
#menu.goto_main_activity=
#menu.go_to_application=Go to Application
menu.tools=도구
#menu.plugins=Plugins
#menu.decompile_all=Decompile all classes
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.text_search=Buscar por texto
menu.class_search=Buscar por classe
menu.comment_search=Busca por comentário
#menu.goto_main_activity=
#menu.go_to_application=Go to Application
menu.tools=Ferramentas
#menu.plugins=Plugins
#menu.decompile_all=Decompile all classes
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_ru_RU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.text_search=Поиск строк
menu.class_search=Поиск классов
menu.comment_search=Поиск комментариев
menu.goto_main_activity=Найти главное Activity
#menu.go_to_application=Go to Application
menu.tools=Инструменты
menu.plugins=Плагины
menu.decompile_all=Декомпилировать все
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.text_search=文本搜索
menu.class_search=类名搜索
menu.comment_search=注释搜索
menu.goto_main_activity=前往主 Activity
#menu.go_to_application=Go to Application
menu.tools=工具
menu.plugins=插件
menu.decompile_all=反编译所有类
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/resources/i18n/Messages_zh_TW.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.text_search=文字搜尋
menu.class_search=類別搜尋
menu.comment_search=註解搜尋
menu.goto_main_activity=前往主 Activity
#menu.go_to_application=Go to Application
menu.tools=工具
menu.plugins=外掛程式
menu.decompile_all=反編譯所有類別
Expand Down
6 changes: 6 additions & 0 deletions jadx-gui/src/main/resources/icons/ui/application.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading