Skip to content

Commit

Permalink
fix(gui): QuarkReport data validation added and other minor improveme…
Browse files Browse the repository at this point in the history
…nts (PR #1556)

* QuarkReport: data validation added and other minor improvements
* checkStyle
  • Loading branch information
jpstotz committed Jun 25, 2022
1 parent 762ee65 commit 0721a6b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
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

0 comments on commit 0721a6b

Please sign in to comment.