Commit bc3af8e6 authored by Skylot's avatar Skylot

fix: resolve some sonar warnings

parent 7bd428cf
......@@ -298,12 +298,10 @@ public class ClassGen {
} else {
insertDecompilationProblems(code, mth);
boolean badCode = mth.contains(AFlag.INCONSISTENT_CODE);
if (badCode) {
if (showInconsistentCode) {
code.startLine("/* Code decompiled incorrectly, please refer to instructions dump. */");
mth.remove(AFlag.INCONSISTENT_CODE);
badCode = false;
}
if (badCode && showInconsistentCode) {
code.startLine("/* Code decompiled incorrectly, please refer to instructions dump. */");
mth.remove(AFlag.INCONSISTENT_CODE);
badCode = false;
}
MethodGen mthGen;
if (badCode || mth.contains(AType.JADX_ERROR) || fallback) {
......
......@@ -224,7 +224,7 @@ public class InsnGen {
code.add(';');
}
}
} catch (Throwable th) {
} catch (Exception th) {
throw new CodegenException(mth, "Error generate insn: " + insn, th);
}
return true;
......
......@@ -7,7 +7,6 @@ import java.util.Set;
import jadx.core.Consts;
import jadx.core.deobf.NameMapper;
import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.attributes.nodes.LoopLabelAttr;
import jadx.core.dex.info.ClassInfo;
import jadx.core.dex.info.MethodInfo;
......
......@@ -53,4 +53,7 @@ public class AType<T extends IAttribute> {
public static final AType<DeclareVariablesAttr> DECLARE_VARIABLES = new AType<>();
public static final AType<LoopLabelAttr> LOOP_LABEL = new AType<>();
public static final AType<IgnoreEdgeAttr> IGNORE_EDGE = new AType<>();
private AType() {
}
}
......@@ -2,9 +2,7 @@ package jadx.core.dex.instructions;
import java.io.EOFException;
import com.android.dex.ClassData;
import com.android.dex.Code;
import com.android.dex.FieldId;
import com.android.dx.io.OpcodeInfo;
import com.android.dx.io.Opcodes;
import com.android.dx.io.instructions.DecodedInstruction;
......@@ -12,9 +10,6 @@ import com.android.dx.io.instructions.FillArrayDataPayloadDecodedInstruction;
import com.android.dx.io.instructions.PackedSwitchPayloadDecodedInstruction;
import com.android.dx.io.instructions.ShortArrayCodeInput;
import com.android.dx.io.instructions.SparseSwitchPayloadDecodedInstruction;
import jadx.core.dex.info.ClassInfo;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.FieldNode;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -117,17 +112,15 @@ public class InsnDecoder {
InsnArg.lit(insn, ArgType.WIDE));
case Opcodes.CONST_STRING:
case Opcodes.CONST_STRING_JUMBO: {
InsnNode node = new ConstStringNode(dex.getString(insn.getIndex()));
node.setResult(InsnArg.reg(insn, 0, ArgType.STRING));
return node;
}
case Opcodes.CONST_STRING_JUMBO:
InsnNode constStrInsn = new ConstStringNode(dex.getString(insn.getIndex()));
constStrInsn.setResult(InsnArg.reg(insn, 0, ArgType.STRING));
return constStrInsn;
case Opcodes.CONST_CLASS: {
InsnNode node = new ConstClassNode(dex.getType(insn.getIndex()));
node.setResult(InsnArg.reg(insn, 0, ArgType.CLASS));
return node;
}
case Opcodes.CONST_CLASS:
InsnNode constClsInsn = new ConstClassNode(dex.getType(insn.getIndex()));
constClsInsn.setResult(InsnArg.reg(insn, 0, ArgType.CLASS));
return constClsInsn;
case Opcodes.MOVE:
case Opcodes.MOVE_16:
......@@ -427,20 +420,18 @@ public class InsnDecoder {
null,
InsnArg.reg(insn, 0, method.getReturnType()));
case Opcodes.INSTANCE_OF: {
InsnNode node = new IndexInsnNode(InsnType.INSTANCE_OF, dex.getType(insn.getIndex()), 1);
node.setResult(InsnArg.reg(insn, 0, ArgType.BOOLEAN));
node.addArg(InsnArg.reg(insn, 1, ArgType.UNKNOWN_OBJECT));
return node;
}
case Opcodes.INSTANCE_OF:
InsnNode instInsn = new IndexInsnNode(InsnType.INSTANCE_OF, dex.getType(insn.getIndex()), 1);
instInsn.setResult(InsnArg.reg(insn, 0, ArgType.BOOLEAN));
instInsn.addArg(InsnArg.reg(insn, 1, ArgType.UNKNOWN_OBJECT));
return instInsn;
case Opcodes.CHECK_CAST: {
case Opcodes.CHECK_CAST:
ArgType castType = dex.getType(insn.getIndex());
InsnNode node = new IndexInsnNode(InsnType.CHECK_CAST, castType, 1);
node.setResult(InsnArg.reg(insn, 0, castType));
node.addArg(InsnArg.reg(insn, 0, ArgType.UNKNOWN_OBJECT));
return node;
}
InsnNode checkCastInsn = new IndexInsnNode(InsnType.CHECK_CAST, castType, 1);
checkCastInsn.setResult(InsnArg.reg(insn, 0, castType));
checkCastInsn.addArg(InsnArg.reg(insn, 0, ArgType.UNKNOWN_OBJECT));
return checkCastInsn;
case Opcodes.IGET:
case Opcodes.IGET_BOOLEAN:
......@@ -448,13 +439,12 @@ public class InsnDecoder {
case Opcodes.IGET_CHAR:
case Opcodes.IGET_SHORT:
case Opcodes.IGET_WIDE:
case Opcodes.IGET_OBJECT: {
FieldInfo field = FieldInfo.fromDex(dex, insn.getIndex());
InsnNode node = new IndexInsnNode(InsnType.IGET, field, 1);
node.setResult(InsnArg.reg(insn, 0, field.getType()));
node.addArg(InsnArg.reg(insn, 1, field.getDeclClass().getType()));
return node;
}
case Opcodes.IGET_OBJECT:
FieldInfo igetFld = FieldInfo.fromDex(dex, insn.getIndex());
InsnNode igetInsn = new IndexInsnNode(InsnType.IGET, igetFld, 1);
igetInsn.setResult(InsnArg.reg(insn, 0, igetFld.getType()));
igetInsn.addArg(InsnArg.reg(insn, 1, igetFld.getDeclClass().getType()));
return igetInsn;
case Opcodes.IPUT:
case Opcodes.IPUT_BOOLEAN:
......@@ -462,13 +452,12 @@ public class InsnDecoder {
case Opcodes.IPUT_CHAR:
case Opcodes.IPUT_SHORT:
case Opcodes.IPUT_WIDE:
case Opcodes.IPUT_OBJECT: {
FieldInfo field = FieldInfo.fromDex(dex, insn.getIndex());
InsnNode node = new IndexInsnNode(InsnType.IPUT, field, 2);
node.addArg(InsnArg.reg(insn, 0, field.getType()));
node.addArg(InsnArg.reg(insn, 1, field.getDeclClass().getType()));
return node;
}
case Opcodes.IPUT_OBJECT:
FieldInfo iputFld = FieldInfo.fromDex(dex, insn.getIndex());
InsnNode iputInsn = new IndexInsnNode(InsnType.IPUT, iputFld, 2);
iputInsn.addArg(InsnArg.reg(insn, 0, iputFld.getType()));
iputInsn.addArg(InsnArg.reg(insn, 1, iputFld.getDeclClass().getType()));
return iputInsn;
case Opcodes.SGET:
case Opcodes.SGET_BOOLEAN:
......@@ -476,12 +465,11 @@ public class InsnDecoder {
case Opcodes.SGET_CHAR:
case Opcodes.SGET_SHORT:
case Opcodes.SGET_WIDE:
case Opcodes.SGET_OBJECT: {
FieldInfo field = FieldInfo.fromDex(dex, insn.getIndex());
InsnNode node = new IndexInsnNode(InsnType.SGET, field, 0);
node.setResult(InsnArg.reg(insn, 0, field.getType()));
return node;
}
case Opcodes.SGET_OBJECT:
FieldInfo sgetFld = FieldInfo.fromDex(dex, insn.getIndex());
InsnNode sgetInsn = new IndexInsnNode(InsnType.SGET, sgetFld, 0);
sgetInsn.setResult(InsnArg.reg(insn, 0, sgetFld.getType()));
return sgetInsn;
case Opcodes.SPUT:
case Opcodes.SPUT_BOOLEAN:
......@@ -489,19 +477,17 @@ public class InsnDecoder {
case Opcodes.SPUT_CHAR:
case Opcodes.SPUT_SHORT:
case Opcodes.SPUT_WIDE:
case Opcodes.SPUT_OBJECT: {
FieldInfo field = FieldInfo.fromDex(dex, insn.getIndex());
InsnNode node = new IndexInsnNode(InsnType.SPUT, field, 1);
node.addArg(InsnArg.reg(insn, 0, field.getType()));
return node;
}
case Opcodes.ARRAY_LENGTH: {
InsnNode node = new InsnNode(InsnType.ARRAY_LENGTH, 1);
node.setResult(InsnArg.reg(insn, 0, ArgType.INT));
node.addArg(InsnArg.reg(insn, 1, ArgType.array(ArgType.UNKNOWN)));
return node;
}
case Opcodes.SPUT_OBJECT:
FieldInfo sputFld = FieldInfo.fromDex(dex, insn.getIndex());
InsnNode sputInsn = new IndexInsnNode(InsnType.SPUT, sputFld, 1);
sputInsn.addArg(InsnArg.reg(insn, 0, sputFld.getType()));
return sputInsn;
case Opcodes.ARRAY_LENGTH:
InsnNode arrLenInsn = new InsnNode(InsnType.ARRAY_LENGTH, 1);
arrLenInsn.setResult(InsnArg.reg(insn, 0, ArgType.INT));
arrLenInsn.addArg(InsnArg.reg(insn, 1, ArgType.array(ArgType.UNKNOWN)));
return arrLenInsn;
case Opcodes.AGET:
return arrayGet(insn, ArgType.NARROW);
......
......@@ -15,7 +15,6 @@ import com.android.dex.ClassDef;
import com.android.dex.Dex;
import com.android.dx.rop.code.AccessFlags;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
package jadx.core.dex.nodes;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import com.android.dex.Dex;
import jadx.core.dex.info.FieldInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
......@@ -19,6 +15,7 @@ import jadx.api.ResourcesLoader;
import jadx.core.clsp.ClspGraph;
import jadx.core.dex.info.ClassInfo;
import jadx.core.dex.info.ConstStorage;
import jadx.core.dex.info.FieldInfo;
import jadx.core.dex.info.InfoStorage;
import jadx.core.dex.info.MethodInfo;
import jadx.core.utils.ErrorsCounter;
......@@ -28,7 +25,6 @@ import jadx.core.utils.exceptions.JadxException;
import jadx.core.utils.exceptions.JadxRuntimeException;
import jadx.core.utils.files.DexFile;
import jadx.core.utils.files.InputFile;
import jadx.core.xmlgen.ResContainer;
import jadx.core.xmlgen.ResTableParser;
import jadx.core.xmlgen.ResourceStorage;
......
......@@ -3,6 +3,8 @@ package jadx.core.dex.visitors;
import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.Nullable;
import jadx.core.codegen.TypeGen;
import jadx.core.deobf.NameMapper;
import jadx.core.dex.attributes.AFlag;
......@@ -27,7 +29,6 @@ import jadx.core.dex.nodes.MethodNode;
import jadx.core.utils.ErrorsCounter;
import jadx.core.utils.InsnUtils;
import jadx.core.utils.exceptions.JadxException;
import org.jetbrains.annotations.Nullable;
@JadxVisitor(
name = "EnumVisitor",
......
......@@ -45,14 +45,12 @@ public class CheckRegions extends AbstractVisitor {
if (blocksInRegions.add(block)) {
return;
}
if (!block.contains(AFlag.RETURN)
if (LOG.isDebugEnabled()
&& !block.contains(AFlag.RETURN)
&& !block.contains(AFlag.SKIP)
&& !block.contains(AFlag.SYNTHETIC)
&& !block.getInstructions().isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Duplicated block: {} - {}", mth, block);
}
//mth.addWarn("Duplicated block: " + block);
LOG.debug("Duplicated block: {} - {}", mth, block);
}
}
});
......@@ -90,7 +88,8 @@ public class CheckRegions extends AbstractVisitor {
for (InsnNode insn : block.getInstructions()) {
try {
ig.makeInsn(insn, code);
} catch (CodegenException ignored) {
} catch (CodegenException e) {
// ignore
}
}
code.newLine().addIndent();
......
......@@ -91,19 +91,26 @@ public class Utils {
@Override
public void write(int b) {
char c = (char) b;
if (c == '\r') {
// ignore
} else if (c == '\n') {
code.startLine();
} else {
code.add(c);
switch (c) {
case '\n':
code.startLine();
break;
case '\r':
// ignore
break;
default:
code.add(c);
break;
}
}
};
PrintWriter pw = new PrintWriter(w, true);
filterRecursive(throwable);
throwable.printStackTrace(pw);
pw.flush();
try (PrintWriter pw = new PrintWriter(w, true)) {
filterRecursive(throwable);
throwable.printStackTrace(pw);
pw.flush();
}
}
private static void filterRecursive(Throwable th) {
......
......@@ -2,20 +2,15 @@ package jadx.gui;
import javax.swing.*;
import jadx.gui.utils.LangLocale;
import jadx.gui.utils.NLS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.gui.settings.JadxSettings;
import jadx.gui.settings.JadxSettingsAdapter;
import jadx.gui.ui.MainWindow;
import jadx.gui.utils.NLS;
import jadx.gui.utils.logs.LogCollector;
import java.util.Locale;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
public class JadxGUI {
private static final Logger LOG = LoggerFactory.getLogger(JadxGUI.class);
......
package jadx.gui.settings;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.prefs.Preferences;
import com.google.gson.ExclusionStrategy;
......
package jadx.gui.treemodel;
import javax.swing.*;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.api.ResourceFile;
import jadx.core.utils.files.ZipSecurity;
import jadx.gui.utils.CertificateManager;
import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils;
import javax.swing.*;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class JCertificate extends JNode {
private static final long serialVersionUID = 4308696770188518731L;
private static final Logger LOG = LoggerFactory.getLogger(JCertificate.class);
private static final ImageIcon CERTIFICATE_ICON = Utils.openIcon("certificate_obj");
private final transient ResourceFile rf;
private final transient ResourceFile rf;
public JCertificate(ResourceFile resFile) {
this.rf = resFile;
this.rf = resFile;
}
@Override
......@@ -35,7 +47,6 @@ public class JCertificate extends JNode {
@Override
public String getContent() {
try {
ResourceFile.ZipRef zipRef = rf.getZipRef();
if (zipRef == null) {
......@@ -53,17 +64,13 @@ public class JCertificate extends JNode {
return null;
}
try (InputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry))) {
return CertificateManager.decode(inputStream);
return CertificateManager.decode(inputStream);
}
}
}
} catch (Exception e) {
e.printStackTrace();
// throw new JadxException("Error decode: " + rf.getName(), e);
LOG.error("Certificate decode error: {}", rf.getName(), e);
return "Decode error: " + e.getMessage();
}
return null;
}
}
package jadx.gui.ui;
import jadx.gui.treemodel.JNode;
import javax.swing.*;
import java.awt.*;
import jadx.gui.treemodel.JNode;
public class CertificatePanel extends ContentPanel {
CertificatePanel(TabbedPane panel, JNode jnode) {
super(panel, jnode);
......
......@@ -28,7 +28,6 @@ import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;
import jadx.gui.treemodel.*;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -40,6 +39,12 @@ import jadx.gui.jobs.DecompileJob;
import jadx.gui.jobs.IndexJob;
import jadx.gui.settings.JadxSettings;
import jadx.gui.settings.JadxSettingsWindow;
import jadx.gui.treemodel.JCertificate;
import jadx.gui.treemodel.JClass;
import jadx.gui.treemodel.JLoadableNode;
import jadx.gui.treemodel.JNode;
import jadx.gui.treemodel.JResource;
import jadx.gui.treemodel.JRoot;
import jadx.gui.update.JadxUpdate;
import jadx.gui.update.JadxUpdate.IUpdateCallback;
import jadx.gui.update.data.Release;
......
package jadx.gui.ui;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.text.BadLocationException;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.text.BadLocationException;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.api.ResourceFile;
import jadx.api.ResourceType;
......@@ -57,19 +43,17 @@ class TabbedPane extends JTabbedPane {
setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
int direction = e.getWheelRotation();
int index = getSelectedIndex();
int maxIndex = getTabCount() - 1;
if ((index == 0 && direction < 0)
|| (index == maxIndex && direction > 0)) {
index = maxIndex - index;
} else {
index += direction;
}
setSelectedIndex(index);
addMouseWheelListener(e -> {
int direction = e.getWheelRotation();
int index = getSelectedIndex();
int maxIndex = getTabCount() - 1;
if ((index == 0 && direction < 0)
|| (index == maxIndex && direction > 0)) {
index = maxIndex - index;
} else {
index += direction;
}
setSelectedIndex(index);
});
}
......@@ -82,23 +66,20 @@ class TabbedPane extends JTabbedPane {
if (contentPanel == null) {
return;
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setSelectedComponent(contentPanel);
CodeArea codeArea = contentPanel.getCodeArea();
int line = pos.getLine();
if (line < 0) {
try {
line = 1 + codeArea.getLineOfOffset(-line);
} catch (BadLocationException e) {
LOG.error("Can't get line for: {}", pos, e);
line = pos.getNode().getLine();
}
SwingUtilities.invokeLater(() -> {
setSelectedComponent(contentPanel);
CodeArea codeArea = contentPanel.getCodeArea();
int line = pos.getLine();
if (line < 0) {
try {
line = 1 + codeArea.getLineOfOffset(-line);
} catch (BadLocationException e) {
LOG.error("Can't get line for: {}", pos, e);
line = pos.getNode().getLine();
}
codeArea.scrollToLine(line);
codeArea.requestFocus();
}
codeArea.scrollToLine(line);
codeArea.requestFocus();
});
}
......@@ -107,12 +88,7 @@ class TabbedPane extends JTabbedPane {
if (contentPanel == null) {
return;
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setSelectedComponent(contentPanel);
}
});
SwingUtilities.invokeLater(() -> setSelectedComponent(contentPanel));
}
public void showCertificate(JCertificate cert) {
......@@ -120,15 +96,9 @@ class TabbedPane extends JTabbedPane {
if (contentPanel == null) {
return;
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setSelectedComponent(contentPanel);
}
});
SwingUtilities.invokeLater(() -> setSelectedComponent(contentPanel));
}
public void codeJump(Position pos) {
Position curPos = getCurrentPosition();
if (curPos != null) {
......@@ -198,11 +168,9 @@ class TabbedPane extends JTabbedPane {
return null;
}
}
if(node instanceof JCertificate)
{
return new CertificatePanel(this,node);
if (node instanceof JCertificate) {
return new CertificatePanel(this, node);
}
return new CodePanel(this, node);
}
......@@ -232,12 +200,7 @@ class TabbedPane extends JTabbedPane {
button.setFocusable(false);
button.setBorder(null);
button.setBorderPainted(false);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeCodePanel(contentPanel);
}
});
button.addActionListener(e -> closeCodePanel(contentPanel));
panel.addMouseListener(new MouseAdapter() {
@Override
......@@ -248,7 +211,6 @@ class TabbedPane extends JTabbedPane {
JPopupMenu menu = createTabPopupMenu(contentPanel);
menu.show(panel, e.getX(), e.getY());
} else {
// TODO: make correct event delegation to tabbed pane
setSelectedComponent(contentPanel);
}
}
......@@ -264,45 +226,27 @@ class TabbedPane extends JTabbedPane {
JPopupMenu menu = new JPopupMenu();
JMenuItem copyRootClassName = new JMenuItem(NLS.str("tabs.copy_class_name"));
copyRootClassName.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
copyRootClassName();
}
});
copyRootClassName.addActionListener(actionEvent -> copyRootClassName());
menu.add(copyRootClassName);
JMenuItem closeTab = new JMenuItem(NLS.str("tabs.close"));
closeTab.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeCodePanel(contentPanel);
}
});
closeTab.addActionListener(e -> closeCodePanel(contentPanel));
menu.add(closeTab);
if (openTabs.size() > 1) {
JMenuItem closeOther = new JMenuItem(NLS.str("tabs.closeOthers"));
closeOther.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<ContentPanel> contentPanels = new ArrayList<>(openTabs.values());
for (ContentPanel panel : contentPanels) {
if (panel != contentPanel) {
closeCodePanel(panel);
}
closeOther.addActionListener(e -> {
List<ContentPanel> contentPanels = new ArrayList<>(openTabs.values());
for (ContentPanel panel : contentPanels) {
if (panel != contentPanel) {
closeCodePanel(panel);
}
}
});
menu.add(closeOther);
JMenuItem closeAll = new JMenuItem(NLS.str("tabs.closeAll"));
closeAll.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeAllTabs();
}
});
closeAll.addActionListener(e -> closeAllTabs());
menu.add(closeAll);
menu.addSeparator();
......@@ -315,12 +259,7 @@ class TabbedPane extends JTabbedPane {
JNode node = entry.getKey();
final String clsName = node.makeLongString();
JMenuItem item = new JMenuItem(clsName);
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSelectedComponent(cp);
}
});
item.addActionListener(e -> setSelectedComponent(cp));
item.setIcon(node.getIcon());
menu.add(item);
}
......@@ -335,13 +274,15 @@ class TabbedPane extends JTabbedPane {
}
}
public void copyRootClassName(){
public void copyRootClassName() {
ContentPanel selectedPanel = getSelectedCodePanel();
JNode node = selectedPanel.getNode();
JClass jClass = node.getRootClass();
if (jClass != null){
String name = jClass.getFullName();
Utils.setClipboardString(name);
if (selectedPanel != null) {
JNode node = selectedPanel.getNode();
JClass jClass = node.getRootClass();
if (jClass != null) {
String name = jClass.getFullName();
Utils.setClipboardString(name);
}
}
}
......
package jadx.gui.utils;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
......@@ -11,112 +12,95 @@ import java.security.cert.X509Certificate;
import java.security.interfaces.DSAPublicKey;
import java.security.interfaces.RSAPublicKey;
import java.util.Collection;
import java.util.Collections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CertificateManager {
private static final Logger LOG = LoggerFactory.getLogger(CertificateManager.class);
private static final String CERTIFICATE_TYPE_NAME = "X.509";
private X509Certificate x509cert;
private Certificate cert;
static public String decode(InputStream in){
public static String decode(InputStream in) {
StringBuilder strBuild = new StringBuilder();
Collection<? extends Certificate> certificates = readCertificates(in);
if(certificates!=null) {
if (certificates != null) {
for (Certificate cert : certificates) {
CertificateManager certificateManager= new CertificateManager(cert);
CertificateManager certificateManager = new CertificateManager(cert);
strBuild.append(certificateManager.generateText());
}
}
return strBuild.toString();
}
static Collection<? extends Certificate> readCertificates(InputStream in) {
CertificateFactory cf;
static Collection<? extends Certificate> readCertificates(InputStream in) {
try {
cf = CertificateFactory.getInstance("X.509");
Collection<? extends Certificate> certs = cf.generateCertificates(in);
in.close();
return certs;
CertificateFactory cf = CertificateFactory.getInstance(CERTIFICATE_TYPE_NAME);
return cf.generateCertificates(in);
} catch (Exception e) {
e.printStackTrace();
LOG.error("Certificate read error", e);
}
return null;
return Collections.emptyList();
}
private X509Certificate x509cert;
private Certificate cert;
public CertificateManager(Certificate cert)
{
public CertificateManager(Certificate cert) {
this.cert = cert;
String type = cert.getType();
if (type.equals("X.509")) {
if (cert instanceof X509Certificate) {
x509cert = (X509Certificate) cert;
}
if (type.equals(CERTIFICATE_TYPE_NAME) && cert instanceof X509Certificate) {
x509cert = (X509Certificate) cert;
}
}
String generateHeader()
{
String generateHeader() {
StringBuilder builder = new StringBuilder();
append(builder, NLS.str("certificate.cert_type"), x509cert.getType());
append(builder, NLS.str("certificate.serialSigVer"),((Integer) x509cert.getVersion()).toString());
// seral number
append(builder, NLS.str("certificate.serialSigVer"), ((Integer) x509cert.getVersion()).toString());
// serial number
append(builder, NLS.str("certificate.serialNumber"), "0x" + x509cert.getSerialNumber().toString(16));
// Get subject
Principal subjectDN = x509cert.getSubjectDN();
append(builder, NLS.str("certificate.cert_subject"), subjectDN.getName());
// Get issuer
// Principal issuerDN = x509cert.getIssuerDN();
// append(str, NLS.str("certificate.cert_issuer"), issuerDN.getName());
append(builder, NLS.str("certificate.serialValidFrom"), x509cert.getNotBefore().toString());
append(builder, NLS.str("certificate.serialValidUntil"), x509cert.getNotAfter().toString());
return builder.toString();
return builder.toString();
}
String generateSignature()
{
String generateSignature() {
StringBuilder builder = new StringBuilder();
append(builder, NLS.str("certificate.serialSigType"), x509cert.getSigAlgName());
append(builder, NLS.str("certificate.serialSigOID"), x509cert.getSigAlgOID());
return builder.toString();
return builder.toString();
}
String generateFingerprint()
{
String generateFingerprint() {
StringBuilder builder = new StringBuilder();
try {
append(builder, NLS.str("certificate.serialMD5"), getThumbPrint(x509cert, "MD5"));
append(builder, NLS.str("certificate.serialSHA1"), getThumbPrint(x509cert, "SHA-1"));
append(builder, NLS.str("certificate.serialSHA256"), getThumbPrint(x509cert, "SHA-256"));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (CertificateEncodingException e) {
e.printStackTrace();
} catch (Exception e) {
LOG.error("Failed to parse fingerprint", e);
}
return builder.toString();
return builder.toString();
}
String generatePublicKey()
{
String generatePublicKey() {
PublicKey publicKey = x509cert.getPublicKey();
if(publicKey instanceof RSAPublicKey)
{
if (publicKey instanceof RSAPublicKey) {
return generateRSAPublicKey();
}
if(publicKey instanceof DSAPublicKey)
{
if (publicKey instanceof DSAPublicKey) {
return generateDSAPublicKey();
}
return "";
}
String generateRSAPublicKey()
{
String generateRSAPublicKey() {
RSAPublicKey pub = (RSAPublicKey) cert.getPublicKey();
StringBuilder builder = new StringBuilder();
......@@ -127,21 +111,18 @@ public class CertificateManager {
return builder.toString();
}
String generateDSAPublicKey()
{
String generateDSAPublicKey() {
DSAPublicKey pub = (DSAPublicKey) cert.getPublicKey();
StringBuilder builder = new StringBuilder();
append(builder, NLS.str("certificate.serialPubKeyType"), pub.getAlgorithm());
append(builder, NLS.str("certificate.serialPubKeyY"), pub.getY().toString(10));
return builder.toString();
}
String generateTextForX509()
{
String generateTextForX509() {
StringBuilder builder = new StringBuilder();
if(x509cert!=null){
if (x509cert != null) {
builder.append(generateHeader());
builder.append("\n");
......@@ -151,31 +132,23 @@ public class CertificateManager {
builder.append(generateSignature());
builder.append("\n");
builder.append(generateFingerprint());
}
return builder.toString();
}
private String generateText() {
private String generateText() {
StringBuilder str = new StringBuilder();
String type = cert.getType();
if (!type.equals("X.509")) {
str.append(cert.toString());
} else {
if (type.equals(CERTIFICATE_TYPE_NAME)) {
str.append(generateTextForX509());
} else {
str.append(cert.toString());
}
return str.toString();
}
static void append(StringBuilder str, String name, String value) {
str.append(name + ": " + value + "\n");
str.append(name).append(": ").append(value).append("\n");
}
public static String getThumbPrint(X509Certificate cert, String type)
......@@ -185,23 +158,16 @@ public class CertificateManager {
md.update(der);
byte[] digest = md.digest();
return hexify(digest);
}
public static String hexify(byte bytes[]) {
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
public static String hexify(byte[] bytes) {
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuilder buf = new StringBuilder(bytes.length * 3);
for (int i = 0; i < bytes.length; ++i) {
buf.append(hexDigits[(bytes[i] & 0xf0) >> 4]);
buf.append(hexDigits[bytes[i] & 0x0f]);
for (byte aByte : bytes) {
buf.append(hexDigits[(aByte & 0xf0) >> 4]);
buf.append(hexDigits[aByte & 0x0f]);
buf.append(' ');
}
return buf.toString();
}
}
package jadx.gui.utils;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Font;
import java.awt.Toolkit;
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.io.InputStream;
import java.net.URL;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.instructions.args.ArgType;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment