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

QuarkReport: data validation added and other minor improvements #1556

Merged
merged 2 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 36 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/plugins/quark/QuarkReportData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

@SuppressWarnings("MemberName")
public class QuarkReportData {

public static class Crime {
public String crime;
public String confidence;
Expand All @@ -18,6 +19,23 @@ public static class Crime {
List<Method> native_api;
List<JsonElement> combination;
List<Map<String, InvokePlace>> register;

public int parseConfidence() {
return Integer.parseInt(confidence.replace("%", ""));
}

@Override
public String toString() {
final StringBuffer sb = new StringBuffer("Crime{");
sb.append("crime='").append(crime).append('\'');
sb.append(", confidence='").append(confidence).append('\'');
sb.append(", permissions=").append(permissions);
sb.append(", native_api=").append(native_api);
sb.append(", combination=").append(combination);
sb.append(", register=").append(register);
sb.append('}');
return sb.toString();
}
}

public static class Method {
Expand Down Expand Up @@ -46,4 +64,22 @@ public static class InvokePlace {
String threat_level;
int total_score;
List<Crime> crimes;

public void validate() {
if (crimes == null) {
throw new RuntimeException("Invalid data: \"crimes\" list missing");
}
for (Crime crime : crimes) {
if (crime.confidence == null) {
throw new RuntimeException("Confidence value missing: " + crime);
}
try {
crime.parseConfidence();
} catch (Exception e) {
throw new RuntimeException("Invalid crime entry: " + crime);
}
}

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jadx.gui.plugins.quark;

import java.io.BufferedReader;
import java.nio.file.Files;
import java.nio.file.Path;

Expand Down Expand Up @@ -33,12 +34,12 @@ public class QuarkReportNode extends JNode {

private static final ImageIcon ICON = UiUtils.openSvgIcon("ui/quark");

private final Path apkFile;
private final Path reportFile;

private ICodeInfo errorContent;

public QuarkReportNode(Path apkFile) {
this.apkFile = apkFile;
public QuarkReportNode(Path reportFile) {
this.reportFile = reportFile;
}

@Override
Expand All @@ -59,7 +60,11 @@ public String makeString() {
@Override
public ContentPanel getContentPanel(TabbedPane tabbedPane) {
try {
QuarkReportData data = GSON.fromJson(Files.newBufferedReader(apkFile), QuarkReportData.class);
QuarkReportData data;
try (BufferedReader reader = Files.newBufferedReader(reportFile)) {
data = GSON.fromJson(reader, QuarkReportData.class);
}
data.validate();
return new QuarkReportPanel(tabbedPane, this, data);
} catch (Exception e) {
LOG.error("Quark report parse error", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected QuarkReportPanel(TabbedPane panel, QuarkReportNode node, QuarkReportDa
}

private void prepareData() {
data.crimes.sort(Comparator.comparingInt(c -> -Integer.parseInt(c.confidence.replace("%", ""))));
data.crimes.sort(Comparator.comparingInt(c -> -c.parseConfidence()));
}

private void initUI() {
Expand Down Expand Up @@ -290,7 +290,7 @@ public MutableTreeNode resolveMethod(String descr) {
}
return new MethodTreeNode(javaMethod);
} catch (Exception e) {
LOG.error("Failed to parse method descriptor string", e);
LOG.error("Failed to parse method descriptor string: {}", descr, e);
return new TextTreeNode(descr);
}
}
Expand Down