Commit 5c48a457 authored by Skylot's avatar Skylot

fix code style issues

parent b5f439e1
...@@ -43,7 +43,7 @@ public class AnnotationGen { ...@@ -43,7 +43,7 @@ public class AnnotationGen {
public void addForParameter(CodeWriter code, MethodParameters paramsAnnotations, int n) { public void addForParameter(CodeWriter code, MethodParameters paramsAnnotations, int n) {
AnnotationsList aList = paramsAnnotations.getParamList().get(n); AnnotationsList aList = paramsAnnotations.getParamList().get(n);
if (aList == null || aList.size() == 0) { if (aList == null || aList.isEmpty()) {
return; return;
} }
for (Annotation a : aList.getAll()) { for (Annotation a : aList.getAll()) {
...@@ -54,7 +54,7 @@ public class AnnotationGen { ...@@ -54,7 +54,7 @@ public class AnnotationGen {
private void add(IAttributeNode node, CodeWriter code) { private void add(IAttributeNode node, CodeWriter code) {
AnnotationsList aList = node.get(AType.ANNOTATION_LIST); AnnotationsList aList = node.get(AType.ANNOTATION_LIST);
if (aList == null || aList.size() == 0) { if (aList == null || aList.isEmpty()) {
return; return;
} }
for (Annotation a : aList.getAll()) { for (Annotation a : aList.getAll()) {
......
...@@ -148,7 +148,7 @@ public class ClassGen { ...@@ -148,7 +148,7 @@ public class ClassGen {
clsCode.add(' '); clsCode.add(' ');
} }
if (cls.getInterfaces().size() > 0 && !af.isAnnotation()) { if (!cls.getInterfaces().isEmpty() && !af.isAnnotation()) {
if (cls.getAccessFlags().isInterface()) { if (cls.getAccessFlags().isInterface()) {
clsCode.add("extends "); clsCode.add("extends ");
} else { } else {
...@@ -347,7 +347,7 @@ public class ClassGen { ...@@ -347,7 +347,7 @@ public class ClassGen {
for (Iterator<EnumField> it = enumFields.getFields().iterator(); it.hasNext(); ) { for (Iterator<EnumField> it = enumFields.getFields().iterator(); it.hasNext(); ) {
EnumField f = it.next(); EnumField f = it.next();
code.startLine(f.getName()); code.startLine(f.getName());
if (f.getArgs().size() != 0) { if (!f.getArgs().isEmpty()) {
code.add('('); code.add('(');
for (Iterator<InsnArg> aIt = f.getArgs().iterator(); aIt.hasNext(); ) { for (Iterator<InsnArg> aIt = f.getArgs().iterator(); aIt.hasNext(); ) {
InsnArg arg = aIt.next(); InsnArg arg = aIt.next();
...@@ -403,8 +403,8 @@ public class ClassGen { ...@@ -403,8 +403,8 @@ public class ClassGen {
code.attachAnnotation(classNode); code.attachAnnotation(classNode);
} }
String baseClass = useClassInternal(cls.getClassInfo(), classInfo); String baseClass = useClassInternal(cls.getClassInfo(), classInfo);
ArgType[] generics = classInfo.getType().getGenericTypes();
code.add(baseClass); code.add(baseClass);
ArgType[] generics = classInfo.getType().getGenericTypes();
if (generics != null) { if (generics != null) {
code.add('<'); code.add('<');
int len = generics.length; int len = generics.length;
...@@ -451,7 +451,7 @@ public class ClassGen { ...@@ -451,7 +451,7 @@ public class ClassGen {
if (classNode != null && !classNode.getAccessFlags().isPublic()) { if (classNode != null && !classNode.getAccessFlags().isPublic()) {
return shortName; return shortName;
} }
if (searchCollision(cls.dex(), useCls, shortName)) { if (searchCollision(cls.dex(), useCls, classInfo)) {
return fullName; return fullName;
} }
if (classInfo.getPackage().equals(useCls.getPackage())) { if (classInfo.getPackage().equals(useCls.getPackage())) {
...@@ -497,22 +497,24 @@ public class ClassGen { ...@@ -497,22 +497,24 @@ public class ClassGen {
return false; return false;
} }
private static boolean searchCollision(DexNode dex, ClassInfo useCls, String shortName) { private static boolean searchCollision(DexNode dex, ClassInfo useCls, ClassInfo searchCls) {
if (useCls == null) { if (useCls == null) {
return false; return false;
} }
String shortName = searchCls.getShortName();
if (useCls.getShortName().equals(shortName)) { if (useCls.getShortName().equals(shortName)) {
return true; return true;
} }
ClassNode classNode = dex.resolveClass(useCls); ClassNode classNode = dex.resolveClass(useCls);
if (classNode != null) { if (classNode != null) {
for (ClassNode inner : classNode.getInnerClasses()) { for (ClassNode inner : classNode.getInnerClasses()) {
if (inner.getShortName().equals(shortName)) { if (inner.getShortName().equals(shortName)
&& !inner.getClassInfo().equals(searchCls)) {
return true; return true;
} }
} }
} }
return searchCollision(dex, useCls.getParentClass(), shortName); return searchCollision(dex, useCls.getParentClass(), searchCls);
} }
private void insertSourceFileInfo(CodeWriter code, AttrNode node) { private void insertSourceFileInfo(CodeWriter code, AttrNode node) {
......
...@@ -47,6 +47,7 @@ import java.util.HashMap; ...@@ -47,6 +47,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -132,10 +133,9 @@ public class InsnGen { ...@@ -132,10 +133,9 @@ public class InsnGen {
private void instanceField(CodeWriter code, FieldInfo field, InsnArg arg) throws CodegenException { private void instanceField(CodeWriter code, FieldInfo field, InsnArg arg) throws CodegenException {
ClassNode pCls = mth.getParentClass(); ClassNode pCls = mth.getParentClass();
FieldNode fieldNode = pCls.searchField(field); FieldNode fieldNode = pCls.searchField(field);
while (fieldNode == null
while ((fieldNode == null) && pCls.getParentClass() != pCls
&& (pCls.getParentClass() != pCls) && (pCls.getParentClass() != null)) && pCls.getParentClass() != null) {
{
pCls = pCls.getParentClass(); pCls = pCls.getParentClass();
fieldNode = pCls.searchField(field); fieldNode = pCls.searchField(field);
} }
...@@ -201,7 +201,7 @@ public class InsnGen { ...@@ -201,7 +201,7 @@ public class InsnGen {
if (insn.getType() == InsnType.NOP) { if (insn.getType() == InsnType.NOP) {
return false; return false;
} }
EnumSet<Flags> state = EnumSet.noneOf(Flags.class); Set<Flags> state = EnumSet.noneOf(Flags.class);
if (flag == Flags.BODY_ONLY || flag == Flags.BODY_ONLY_NOWRAP) { if (flag == Flags.BODY_ONLY || flag == Flags.BODY_ONLY_NOWRAP) {
state.add(flag); state.add(flag);
makeInsnBody(code, insn, state); makeInsnBody(code, insn, state);
...@@ -224,7 +224,7 @@ public class InsnGen { ...@@ -224,7 +224,7 @@ public class InsnGen {
return true; return true;
} }
private void makeInsnBody(CodeWriter code, InsnNode insn, EnumSet<Flags> state) throws CodegenException { private void makeInsnBody(CodeWriter code, InsnNode insn, Set<Flags> state) throws CodegenException {
switch (insn.getType()) { switch (insn.getType()) {
case CONST_STR: case CONST_STR:
String str = ((ConstStringNode) insn).getString(); String str = ((ConstStringNode) insn).getString();
...@@ -748,7 +748,7 @@ public class InsnGen { ...@@ -748,7 +748,7 @@ public class InsnGen {
return true; return true;
} }
private void makeTernary(TernaryInsn insn, CodeWriter code, EnumSet<Flags> state) throws CodegenException { private void makeTernary(TernaryInsn insn, CodeWriter code, Set<Flags> state) throws CodegenException {
boolean wrap = state.contains(Flags.BODY_ONLY); boolean wrap = state.contains(Flags.BODY_ONLY);
if (wrap) { if (wrap) {
code.add('('); code.add('(');
...@@ -770,7 +770,7 @@ public class InsnGen { ...@@ -770,7 +770,7 @@ public class InsnGen {
} }
} }
private void makeArith(ArithNode insn, CodeWriter code, EnumSet<Flags> state) throws CodegenException { private void makeArith(ArithNode insn, CodeWriter code, Set<Flags> state) throws CodegenException {
if (insn.contains(AFlag.ARITH_ONEARG)) { if (insn.contains(AFlag.ARITH_ONEARG)) {
makeArithOneArg(insn, code); makeArithOneArg(insn, code);
return; return;
......
...@@ -206,14 +206,11 @@ public class MethodGen { ...@@ -206,14 +206,11 @@ public class MethodGen {
if (insn == null) { if (insn == null) {
continue; continue;
} }
if (addLabels) { if (addLabels && (insn.contains(AType.JUMP) || insn.contains(AType.EXC_HANDLER))) {
if (insn.contains(AType.JUMP)
|| insn.contains(AType.EXC_HANDLER)) {
code.decIndent(); code.decIndent();
code.startLine(getLabelName(insn.getOffset()) + ":"); code.startLine(getLabelName(insn.getOffset()) + ":");
code.incIndent(); code.incIndent();
} }
}
try { try {
if (insnGen.makeInsn(insn, code)) { if (insnGen.makeInsn(insn, code)) {
CatchAttr catchAttr = insn.get(AType.CATCH_BLOCK); CatchAttr catchAttr = insn.get(AType.CATCH_BLOCK);
......
...@@ -8,6 +8,9 @@ import jadx.core.utils.exceptions.JadxRuntimeException; ...@@ -8,6 +8,9 @@ import jadx.core.utils.exceptions.JadxRuntimeException;
public class TypeGen { public class TypeGen {
private TypeGen() {
}
public static String signature(ArgType type) { public static String signature(ArgType type) {
PrimitiveType stype = type.getPrimitiveType(); PrimitiveType stype = type.getPrimitiveType();
if (stype == PrimitiveType.OBJECT) { if (stype == PrimitiveType.OBJECT) {
......
...@@ -32,6 +32,10 @@ public class AnnotationsList implements IAttribute { ...@@ -32,6 +32,10 @@ public class AnnotationsList implements IAttribute {
return map.size(); return map.size();
} }
public boolean isEmpty() {
return map.isEmpty();
}
@Override @Override
public AType<AnnotationsList> getType() { public AType<AnnotationsList> getType() {
return AType.ANNOTATION_LIST; return AType.ANNOTATION_LIST;
......
...@@ -12,8 +12,6 @@ import jadx.core.dex.nodes.InsnNode; ...@@ -12,8 +12,6 @@ import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.utils.exceptions.DecodeException; import jadx.core.utils.exceptions.DecodeException;
import java.io.EOFException;
import com.android.dex.Code; import com.android.dex.Code;
import com.android.dx.io.OpcodeInfo; import com.android.dx.io.OpcodeInfo;
import com.android.dx.io.Opcodes; import com.android.dx.io.Opcodes;
......
...@@ -38,11 +38,11 @@ public final class LiteralArg extends InsnArg { ...@@ -38,11 +38,11 @@ public final class LiteralArg extends InsnArg {
public boolean isInteger() { public boolean isInteger() {
PrimitiveType type = this.type.getPrimitiveType(); PrimitiveType type = this.type.getPrimitiveType();
return (type == PrimitiveType.INT return type == PrimitiveType.INT
|| type == PrimitiveType.BYTE || type == PrimitiveType.BYTE
|| type == PrimitiveType.CHAR || type == PrimitiveType.CHAR
|| type == PrimitiveType.SHORT || type == PrimitiveType.SHORT
|| type == PrimitiveType.LONG); || type == PrimitiveType.LONG;
} }
@Override @Override
......
...@@ -29,7 +29,6 @@ public class SSAVar { ...@@ -29,7 +29,6 @@ public class SSAVar {
if (assign != null) { if (assign != null) {
assign.setSVar(this); assign.setSVar(this);
} }
startUseAddr = -1; startUseAddr = -1;
endUseAddr = -1; endUseAddr = -1;
} }
...@@ -52,30 +51,23 @@ public class SSAVar { ...@@ -52,30 +51,23 @@ public class SSAVar {
int start = Integer.MAX_VALUE; int start = Integer.MAX_VALUE;
int end = Integer.MIN_VALUE; int end = Integer.MIN_VALUE;
if (assign != null) { if (assign != null && assign.getParentInsn() != null) {
if (assign.getParentInsn() != null) {
int insnAddr = assign.getParentInsn().getOffset(); int insnAddr = assign.getParentInsn().getOffset();
if (insnAddr >= 0) { if (insnAddr >= 0) {
start = Math.min(insnAddr, start); start = Math.min(insnAddr, start);
end = Math.max(insnAddr, end); end = Math.max(insnAddr, end);
} }
} }
}
for (RegisterArg arg : useList) { for (RegisterArg arg : useList) {
if (arg.getParentInsn() != null) { if (arg.getParentInsn() != null) {
int insnAddr = arg.getParentInsn().getOffset(); int insnAddr = arg.getParentInsn().getOffset();
if (insnAddr >= 0) { if (insnAddr >= 0) {
start = Math.min(insnAddr, start); start = Math.min(insnAddr, start);
end = Math.max(insnAddr, end); end = Math.max(insnAddr, end);
} }
} }
} }
if (start != Integer.MAX_VALUE && end != Integer.MIN_VALUE) {
if ((start != Integer.MAX_VALUE)
&& (end != Integer.MIN_VALUE)) {
startUseAddr = start; startUseAddr = start;
endUseAddr = end; endUseAddr = end;
} }
......
...@@ -204,9 +204,8 @@ public class MethodNode extends LineAttrNode implements ILoadable { ...@@ -204,9 +204,8 @@ public class MethodNode extends LineAttrNode implements ILoadable {
list.add(thisArg); list.add(thisArg);
list.addAll(argsList); list.addAll(argsList);
return list; return list;
} else {
return argsList;
} }
return argsList;
} }
public RegisterArg removeFirstArgument() { public RegisterArg removeFirstArgument() {
...@@ -277,7 +276,6 @@ public class MethodNode extends LineAttrNode implements ILoadable { ...@@ -277,7 +276,6 @@ public class MethodNode extends LineAttrNode implements ILoadable {
for (TryCatchBlock ct : catches) { for (TryCatchBlock ct : catches) {
for (ExceptionHandler eh : ct.getHandlers()) { for (ExceptionHandler eh : ct.getHandlers()) {
int addr = eh.getHandleOffset(); int addr = eh.getHandleOffset();
// assert addrs.add(addr) : "Instruction already contains EXC_HANDLER attribute";
ExcHandlerAttr ehAttr = new ExcHandlerAttr(ct, eh); ExcHandlerAttr ehAttr = new ExcHandlerAttr(ct, eh);
insnByOffset[addr].addAttr(ehAttr); insnByOffset[addr].addAttr(ehAttr);
} }
...@@ -313,18 +311,17 @@ public class MethodNode extends LineAttrNode implements ILoadable { ...@@ -313,18 +311,17 @@ public class MethodNode extends LineAttrNode implements ILoadable {
continue; continue;
} }
switch (insn.getType()) { switch (insn.getType()) {
case SWITCH: { case SWITCH:
SwitchNode sw = (SwitchNode) insn; SwitchNode sw = (SwitchNode) insn;
for (int target : sw.getTargets()) { for (int target : sw.getTargets()) {
addJump(insnByOffset, offset, target); addJump(insnByOffset, offset, target);
} }
// default case // default case
int next = InsnDecoder.getNextInsnOffset(insnByOffset, offset); int nextInsnOffset = InsnDecoder.getNextInsnOffset(insnByOffset, offset);
if (next != -1) { if (nextInsnOffset != -1) {
addJump(insnByOffset, offset, next); addJump(insnByOffset, offset, nextInsnOffset);
} }
break; break;
}
case IF: case IF:
int next = InsnDecoder.getNextInsnOffset(insnByOffset, offset); int next = InsnDecoder.getNextInsnOffset(insnByOffset, offset);
...@@ -499,25 +496,19 @@ public class MethodNode extends LineAttrNode implements ILoadable { ...@@ -499,25 +496,19 @@ public class MethodNode extends LineAttrNode implements ILoadable {
public boolean isDefaultConstructor() { public boolean isDefaultConstructor() {
boolean result = false; boolean result = false;
if (accFlags.isConstructor() && mthInfo.isConstructor()) { if (accFlags.isConstructor() && mthInfo.isConstructor()) {
int defaultArgCount = 0; int defaultArgCount = 0;
/** workaround for non-static inner class constructor, that has synthetic argument */
/** workaround for non-static inner class constructor, that has
* synthetic argument */
if (parentClass.getClassInfo().isInner() if (parentClass.getClassInfo().isInner()
&& !parentClass.getAccessFlags().isStatic()) { && !parentClass.getAccessFlags().isStatic()) {
ClassNode outerCls = parentClass.getParentClass(); ClassNode outerCls = parentClass.getParentClass();
if ((argsList != null) && (argsList.size() >= 1)) { if (argsList != null && !argsList.isEmpty()
if (argsList.get(0).getType().equals(outerCls.getClassInfo().getType())) { && argsList.get(0).getType().equals(outerCls.getClassInfo().getType())) {
defaultArgCount = 1; defaultArgCount = 1;
} }
} }
}
result = (argsList == null) || (argsList.size() == defaultArgCount); result = (argsList == null) || (argsList.size() == defaultArgCount);
} }
return result; return result;
} }
......
...@@ -162,7 +162,7 @@ public class DebugInfoParser { ...@@ -162,7 +162,7 @@ public class DebugInfoParser {
for (LocalVar var : locals) { for (LocalVar var : locals) {
if (var != null && !var.isEnd()) { if (var != null && !var.isEnd()) {
var.end(mth.getCodeSize()-1, line); var.end(mth.getCodeSize() - 1, line);
setVar(var); setVar(var);
} }
} }
......
...@@ -21,9 +21,9 @@ final class LocalVar { ...@@ -21,9 +21,9 @@ final class LocalVar {
public LocalVar(DexNode dex, int rn, int nameId, int typeId, int signId) { public LocalVar(DexNode dex, int rn, int nameId, int typeId, int signId) {
this.regNum = rn; this.regNum = rn;
String name = (nameId == DexNode.NO_INDEX ? null : dex.getString(nameId)); String name = nameId == DexNode.NO_INDEX ? null : dex.getString(nameId);
ArgType type = (typeId == DexNode.NO_INDEX ? null : dex.getType(typeId)); ArgType type = typeId == DexNode.NO_INDEX ? null : dex.getType(typeId);
String sign = (signId == DexNode.NO_INDEX ? null : dex.getString(signId)); String sign = signId == DexNode.NO_INDEX ? null : dex.getString(signId);
init(name, type, sign); init(name, type, sign);
} }
...@@ -56,10 +56,8 @@ final class LocalVar { ...@@ -56,10 +56,8 @@ final class LocalVar {
LOG.warn("Generic type in debug info not equals: {} != {}", type, gType); LOG.warn("Generic type in debug info not equals: {} != {}", type, gType);
} }
apply = true; apply = true;
} else if (el.isGenericType()) {
apply = true;
} else { } else {
apply = false; apply = el.isGenericType();
} }
return apply; return apply;
} }
...@@ -71,6 +69,7 @@ final class LocalVar { ...@@ -71,6 +69,7 @@ final class LocalVar {
/** /**
* Sets end address of local variable * Sets end address of local variable
*
* @param addr address * @param addr address
* @param line source line * @param line source line
* @return <b>true</b> if local variable was active, else <b>false</b> * @return <b>true</b> if local variable was active, else <b>false</b>
...@@ -81,7 +80,6 @@ final class LocalVar { ...@@ -81,7 +80,6 @@ final class LocalVar {
this.endAddr = addr; this.endAddr = addr;
return true; return true;
} }
return false; return false;
} }
......
...@@ -126,7 +126,6 @@ public final class LoopRegion extends AbstractRegion { ...@@ -126,7 +126,6 @@ public final class LoopRegion extends AbstractRegion {
} }
} }
public LoopType getType() { public LoopType getType() {
return type; return type;
} }
......
...@@ -125,7 +125,7 @@ public class ClassModifier extends AbstractVisitor { ...@@ -125,7 +125,7 @@ public class ClassModifier extends AbstractVisitor {
List<InsnNode> insns = mth.getBasicBlocks().get(0).getInstructions(); List<InsnNode> insns = mth.getBasicBlocks().get(0).getInstructions();
if (insns.size() == 1 && insns.get(0).getType() == InsnType.CONSTRUCTOR) { if (insns.size() == 1 && insns.get(0).getType() == InsnType.CONSTRUCTOR) {
ConstructorInsn constr = (ConstructorInsn) insns.get(0); ConstructorInsn constr = (ConstructorInsn) insns.get(0);
if (constr.isThis() && mth.getArguments(false).size() >= 1) { if (constr.isThis() && !mth.getArguments(false).isEmpty()) {
mth.removeFirstArgument(); mth.removeFirstArgument();
mth.add(AFlag.DONT_GENERATE); mth.add(AFlag.DONT_GENERATE);
} }
...@@ -167,7 +167,7 @@ public class ClassModifier extends AbstractVisitor { ...@@ -167,7 +167,7 @@ public class ClassModifier extends AbstractVisitor {
private static boolean allBlocksEmpty(List<BlockNode> blocks) { private static boolean allBlocksEmpty(List<BlockNode> blocks) {
for (BlockNode block : blocks) { for (BlockNode block : blocks) {
if (block.getInstructions().size() != 0) { if (!block.getInstructions().isEmpty()) {
return false; return false;
} }
} }
......
...@@ -55,7 +55,7 @@ public class CodeShrinker extends AbstractVisitor { ...@@ -55,7 +55,7 @@ public class CodeShrinker extends AbstractVisitor {
} }
public static List<RegisterArg> getArgs(InsnNode insn) { public static List<RegisterArg> getArgs(InsnNode insn) {
LinkedList<RegisterArg> args = new LinkedList<RegisterArg>(); List<RegisterArg> args = new LinkedList<RegisterArg>();
addArgs(insn, args); addArgs(insn, args);
return args; return args;
} }
...@@ -105,9 +105,9 @@ public class CodeShrinker extends AbstractVisitor { ...@@ -105,9 +105,9 @@ public class CodeShrinker extends AbstractVisitor {
if (start > to) { if (start > to) {
throw new JadxRuntimeException("Invalid inline insn positions: " + start + " - " + to); throw new JadxRuntimeException("Invalid inline insn positions: " + start + " - " + to);
} }
BitSet args = new BitSet(); BitSet movedSet = new BitSet();
for (RegisterArg arg : movedArgs) { for (RegisterArg arg : movedArgs) {
args.set(arg.getRegNum()); movedSet.set(arg.getRegNum());
} }
for (int i = start; i < to; i++) { for (int i = start; i < to; i++) {
ArgsInfo argsInfo = argsList.get(i); ArgsInfo argsInfo = argsList.get(i);
...@@ -115,7 +115,7 @@ public class CodeShrinker extends AbstractVisitor { ...@@ -115,7 +115,7 @@ public class CodeShrinker extends AbstractVisitor {
continue; continue;
} }
InsnNode curInsn = argsInfo.insn; InsnNode curInsn = argsInfo.insn;
if (!curInsn.canReorder() || usedArgAssign(curInsn, args)) { if (!curInsn.canReorder() || usedArgAssign(curInsn, movedSet)) {
return false; return false;
} }
} }
...@@ -187,7 +187,8 @@ public class CodeShrinker extends AbstractVisitor { ...@@ -187,7 +187,8 @@ public class CodeShrinker extends AbstractVisitor {
List<WrapInfo> wrapList = new ArrayList<WrapInfo>(); List<WrapInfo> wrapList = new ArrayList<WrapInfo>();
for (ArgsInfo argsInfo : argsList) { for (ArgsInfo argsInfo : argsList) {
List<RegisterArg> args = argsInfo.getArgs(); List<RegisterArg> args = argsInfo.getArgs();
for (ListIterator<RegisterArg> it = args.listIterator(args.size()); it.hasPrevious(); ) { ListIterator<RegisterArg> it = args.listIterator(args.size());
while (it.hasPrevious()) {
RegisterArg arg = it.previous(); RegisterArg arg = it.previous();
// if (arg.getName() != null) { // if (arg.getName() != null) {
// continue; // continue;
...@@ -293,7 +294,7 @@ public class CodeShrinker extends AbstractVisitor { ...@@ -293,7 +294,7 @@ public class CodeShrinker extends AbstractVisitor {
} }
} }
// remove method args // remove method args
if (list.size() != 0 && args.size() != 0) { if (!list.isEmpty() && !args.isEmpty()) {
list.removeAll(args); list.removeAll(args);
} }
i++; i++;
......
...@@ -150,7 +150,7 @@ public class ConstInlinerVisitor extends AbstractVisitor { ...@@ -150,7 +150,7 @@ public class ConstInlinerVisitor extends AbstractVisitor {
InvokeNode inv = (InvokeNode) insn; InvokeNode inv = (InvokeNode) insn;
List<ArgType> types = inv.getCallMth().getArgumentsTypes(); List<ArgType> types = inv.getCallMth().getArgumentsTypes();
int count = insn.getArgsCount(); int count = insn.getArgsCount();
int k = (types.size() == count ? 0 : -1); int k = types.size() == count ? 0 : -1;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
InsnArg arg = insn.getArg(i); InsnArg arg = insn.getArg(i);
if (!arg.getType().isTypeKnown()) { if (!arg.getType().isTypeKnown()) {
......
...@@ -114,21 +114,17 @@ public class EnumVisitor extends AbstractVisitor { ...@@ -114,21 +114,17 @@ public class EnumVisitor extends AbstractVisitor {
for (InsnNode insn : insns) { for (InsnNode insn : insns) {
if (insn.getType() == InsnType.CONSTRUCTOR) { if (insn.getType() == InsnType.CONSTRUCTOR) {
ConstructorInsn co = (ConstructorInsn) insn; ConstructorInsn co = (ConstructorInsn) insn;
if (insn.getArgsCount() < 2) { if (insn.getArgsCount() < 2) {
continue; continue;
} }
ClassInfo clsInfo = co.getClassType(); ClassInfo clsInfo = co.getClassType();
ClassNode constrCls = cls.dex().resolveClass(clsInfo); ClassNode constrCls = cls.dex().resolveClass(clsInfo);
if (constrCls == null) { if (constrCls == null) {
continue; continue;
} }
if (!clsInfo.equals(cls.getClassInfo()) && !constrCls.getAccessFlags().isEnum()) { if (!clsInfo.equals(cls.getClassInfo()) && !constrCls.getAccessFlags().isEnum()) {
continue; continue;
} }
RegisterArg nameArg = (RegisterArg) insn.getArg(0); RegisterArg nameArg = (RegisterArg) insn.getArg(0);
// InsnArg pos = insn.getArg(1); // InsnArg pos = insn.getArg(1);
// TODO add check: pos == j // TODO add check: pos == j
...@@ -136,7 +132,6 @@ public class EnumVisitor extends AbstractVisitor { ...@@ -136,7 +132,6 @@ public class EnumVisitor extends AbstractVisitor {
if (name == null) { if (name == null) {
throw new JadxException("Unknown enum field name: " + cls); throw new JadxException("Unknown enum field name: " + cls);
} }
EnumField field = new EnumField(name, insn.getArgsCount() - 2); EnumField field = new EnumField(name, insn.getArgsCount() - 2);
attr.getFields().add(field); attr.getFields().add(field);
for (int i = 2; i < insn.getArgsCount(); i++) { for (int i = 2; i < insn.getArgsCount(); i++) {
......
...@@ -244,7 +244,7 @@ public class ModVisitor extends AbstractVisitor { ...@@ -244,7 +244,7 @@ public class ModVisitor extends AbstractVisitor {
InstructionRemover.remove(mth, excBlock, size - 1); InstructionRemover.remove(mth, excBlock, size - 1);
// move not removed instructions to 'finally' block // move not removed instructions to 'finally' block
if (insns.size() != 0) { if (!insns.isEmpty()) {
// TODO: support instructions from several blocks // TODO: support instructions from several blocks
// tryBlock.setFinalBlockFromInsns(mth, insns); // tryBlock.setFinalBlockFromInsns(mth, insns);
// TODO: because of incomplete realization don't extract final block, // TODO: because of incomplete realization don't extract final block,
...@@ -255,14 +255,13 @@ public class ModVisitor extends AbstractVisitor { ...@@ -255,14 +255,13 @@ public class ModVisitor extends AbstractVisitor {
} }
List<InsnNode> blockInsns = block.getInstructions(); List<InsnNode> blockInsns = block.getInstructions();
if (blockInsns.size() > 0) { if (!blockInsns.isEmpty()) {
InsnNode insn = blockInsns.get(0); InsnNode insn = blockInsns.get(0);
if (insn.getType() == InsnType.MOVE_EXCEPTION if (insn.getType() == InsnType.MOVE_EXCEPTION
&& insn.getResult().getSVar().getUseCount() == 0) { && insn.getResult().getSVar().getUseCount() == 0) {
InstructionRemover.remove(mth, block, 0); InstructionRemover.remove(mth, block, 0);
} }
} }
int totalSize = 0; int totalSize = 0;
for (BlockNode excBlock : excHandler.getBlocks()) { for (BlockNode excBlock : excHandler.getBlocks()) {
totalSize += excBlock.getInstructions().size(); totalSize += excBlock.getInstructions().size();
......
...@@ -218,7 +218,7 @@ public class ReSugarCode extends AbstractVisitor { ...@@ -218,7 +218,7 @@ public class ReSugarCode extends AbstractVisitor {
if (!(index instanceof FieldInfo)) { if (!(index instanceof FieldInfo)) {
return null; return null;
} }
FieldNode enumMapField = mth.dex().resolveField(((FieldInfo) index)); FieldNode enumMapField = mth.dex().resolveField((FieldInfo) index);
if (enumMapField == null || !enumMapField.getAccessFlags().isSynthetic()) { if (enumMapField == null || !enumMapField.getAccessFlags().isSynthetic()) {
return null; return null;
} }
......
...@@ -6,10 +6,10 @@ import jadx.core.dex.nodes.IBlock; ...@@ -6,10 +6,10 @@ import jadx.core.dex.nodes.IBlock;
import jadx.core.dex.nodes.IContainer; import jadx.core.dex.nodes.IContainer;
import jadx.core.dex.nodes.IRegion; import jadx.core.dex.nodes.IRegion;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.regions.Region;
import jadx.core.dex.regions.conditions.IfCondition; import jadx.core.dex.regions.conditions.IfCondition;
import jadx.core.dex.regions.conditions.IfCondition.Mode; import jadx.core.dex.regions.conditions.IfCondition.Mode;
import jadx.core.dex.regions.conditions.IfRegion; import jadx.core.dex.regions.conditions.IfRegion;
import jadx.core.dex.regions.Region;
import jadx.core.dex.visitors.AbstractVisitor; import jadx.core.dex.visitors.AbstractVisitor;
import jadx.core.utils.RegionUtils; import jadx.core.utils.RegionUtils;
......
...@@ -12,8 +12,8 @@ import jadx.core.dex.nodes.IContainer; ...@@ -12,8 +12,8 @@ import jadx.core.dex.nodes.IContainer;
import jadx.core.dex.nodes.IRegion; import jadx.core.dex.nodes.IRegion;
import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.regions.conditions.IfRegion;
import jadx.core.dex.regions.SwitchRegion; import jadx.core.dex.regions.SwitchRegion;
import jadx.core.dex.regions.conditions.IfRegion;
import jadx.core.dex.visitors.AbstractVisitor; import jadx.core.dex.visitors.AbstractVisitor;
import jadx.core.utils.RegionUtils; import jadx.core.utils.RegionUtils;
import jadx.core.utils.exceptions.JadxException; import jadx.core.utils.exceptions.JadxException;
......
...@@ -4,9 +4,9 @@ import jadx.core.dex.nodes.IContainer; ...@@ -4,9 +4,9 @@ import jadx.core.dex.nodes.IContainer;
import jadx.core.dex.nodes.IRegion; import jadx.core.dex.nodes.IRegion;
import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.regions.loops.LoopRegion;
import jadx.core.dex.regions.Region; import jadx.core.dex.regions.Region;
import jadx.core.dex.regions.SynchronizedRegion; import jadx.core.dex.regions.SynchronizedRegion;
import jadx.core.dex.regions.loops.LoopRegion;
import jadx.core.dex.visitors.AbstractVisitor; import jadx.core.dex.visitors.AbstractVisitor;
import jadx.core.utils.InstructionRemover; import jadx.core.utils.InstructionRemover;
import jadx.core.utils.exceptions.JadxException; import jadx.core.utils.exceptions.JadxException;
......
...@@ -8,9 +8,9 @@ import jadx.core.dex.nodes.IContainer; ...@@ -8,9 +8,9 @@ import jadx.core.dex.nodes.IContainer;
import jadx.core.dex.nodes.IRegion; import jadx.core.dex.nodes.IRegion;
import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.regions.SwitchRegion;
import jadx.core.dex.regions.conditions.IfRegion; import jadx.core.dex.regions.conditions.IfRegion;
import jadx.core.dex.regions.loops.LoopRegion; import jadx.core.dex.regions.loops.LoopRegion;
import jadx.core.dex.regions.SwitchRegion;
import jadx.core.dex.visitors.AbstractVisitor; import jadx.core.dex.visitors.AbstractVisitor;
import jadx.core.utils.exceptions.JadxException; import jadx.core.utils.exceptions.JadxException;
import jadx.core.utils.exceptions.JadxRuntimeException; import jadx.core.utils.exceptions.JadxRuntimeException;
......
...@@ -12,8 +12,8 @@ import jadx.core.dex.nodes.BlockNode; ...@@ -12,8 +12,8 @@ import jadx.core.dex.nodes.BlockNode;
import jadx.core.dex.nodes.IContainer; import jadx.core.dex.nodes.IContainer;
import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.regions.conditions.IfRegion;
import jadx.core.dex.regions.Region; import jadx.core.dex.regions.Region;
import jadx.core.dex.regions.conditions.IfRegion;
import jadx.core.dex.visitors.CodeShrinker; import jadx.core.dex.visitors.CodeShrinker;
import jadx.core.utils.InsnList; import jadx.core.utils.InsnList;
......
...@@ -16,6 +16,9 @@ import java.util.List; ...@@ -16,6 +16,9 @@ import java.util.List;
public class PostTypeInference { public class PostTypeInference {
private PostTypeInference() {
}
public static boolean process(MethodNode mth, InsnNode insn) { public static boolean process(MethodNode mth, InsnNode insn) {
switch (insn.getType()) { switch (insn.getType()) {
case CONST: case CONST:
...@@ -25,7 +28,7 @@ public class PostTypeInference { ...@@ -25,7 +28,7 @@ public class PostTypeInference {
long lit = litArg.getLiteral(); long lit = litArg.getLiteral();
if (lit != 0) { if (lit != 0) {
// incorrect literal value for object // incorrect literal value for object
ArgType type = (lit == 1 ? ArgType.BOOLEAN : ArgType.INT); ArgType type = lit == 1 ? ArgType.BOOLEAN : ArgType.INT;
// can't merge with object -> force it // can't merge with object -> force it
litArg.setType(type); litArg.setType(type);
res.getSVar().setType(type); res.getSVar().setType(type);
...@@ -115,15 +118,6 @@ public class PostTypeInference { ...@@ -115,15 +118,6 @@ public class PostTypeInference {
break; break;
} }
return false; return false;
}
static void setType(InsnArg arg, ArgType type) {
if (arg.isRegister()) {
((RegisterArg) arg).getSVar().setType(type);
} else {
arg.setType(type);
}
} }
private static boolean fixArrayTypes(InsnArg array, InsnArg elem) { private static boolean fixArrayTypes(InsnArg array, InsnArg elem) {
......
...@@ -6,6 +6,9 @@ import jadx.core.dex.nodes.InsnNode; ...@@ -6,6 +6,9 @@ import jadx.core.dex.nodes.InsnNode;
public class SelectTypeVisitor { public class SelectTypeVisitor {
private SelectTypeVisitor() {
}
public static void visit(InsnNode insn) { public static void visit(InsnNode insn) {
InsnArg res = insn.getResult(); InsnArg res = insn.getResult();
if (res != null && !res.getType().isTypeKnown()) { if (res != null && !res.getType().isTypeKnown()) {
......
...@@ -47,12 +47,7 @@ public class TypeInference extends AbstractVisitor { ...@@ -47,12 +47,7 @@ public class TypeInference extends AbstractVisitor {
if (assign != null && (useList.isEmpty() || var.isTypeImmutable())) { if (assign != null && (useList.isEmpty() || var.isTypeImmutable())) {
return assign.getType(); return assign.getType();
} }
ArgType type; ArgType type = assign != null ? assign.getType() : ArgType.UNKNOWN;
if (assign != null) {
type = assign.getType();
} else {
type = ArgType.UNKNOWN;
}
for (RegisterArg arg : useList) { for (RegisterArg arg : useList) {
ArgType useType = arg.getType(); ArgType useType = arg.getType();
ArgType newType = ArgType.merge(type, useType); ArgType newType = ArgType.merge(type, useType);
......
...@@ -66,6 +66,7 @@ public class ErrorsCounter { ...@@ -66,6 +66,7 @@ public class ErrorsCounter {
mth.dex().root().getErrorsCounter().addError(mth, msg, e); mth.dex().root().getErrorsCounter().addError(mth, msg, e);
return msg; return msg;
} }
public static String methodError(MethodNode mth, String errorMsg) { public static String methodError(MethodNode mth, String errorMsg) {
return methodError(mth, errorMsg, null); return methodError(mth, errorMsg, null);
} }
......
...@@ -27,7 +27,7 @@ public class RegionUtils { ...@@ -27,7 +27,7 @@ public class RegionUtils {
public static boolean hasExitEdge(IContainer container) { public static boolean hasExitEdge(IContainer container) {
if (container instanceof BlockNode) { if (container instanceof BlockNode) {
BlockNode block = (BlockNode) container; BlockNode block = (BlockNode) container;
return block.getSuccessors().size() != 0 return !block.getSuccessors().isEmpty()
&& !block.contains(AFlag.RETURN); && !block.contains(AFlag.RETURN);
} else if (container instanceof IRegion) { } else if (container instanceof IRegion) {
IRegion region = (IRegion) container; IRegion region = (IRegion) container;
...@@ -109,7 +109,7 @@ public class RegionUtils { ...@@ -109,7 +109,7 @@ public class RegionUtils {
public static boolean notEmpty(IContainer container) { public static boolean notEmpty(IContainer container) {
if (container instanceof BlockNode) { if (container instanceof BlockNode) {
return ((BlockNode) container).getInstructions().size() != 0; return !((BlockNode) container).getInstructions().isEmpty();
} else if (container instanceof IRegion) { } else if (container instanceof IRegion) {
IRegion region = (IRegion) container; IRegion region = (IRegion) container;
for (IContainer block : region.getSubBlocks()) { for (IContainer block : region.getSubBlocks()) {
......
package jadx.tests package jadx.tests
import jadx.api.IJadxArgs import jadx.api.IJadxArgs
import jadx.api.JadxDecompiler import jadx.api.JadxDecompiler
import jadx.core.utils.exceptions.JadxException import jadx.core.utils.exceptions.JadxException
......
package jadx.tests.integration.enums;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import org.junit.Test;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class TestEnums3 extends IntegrationTest {
public static class TestCls {
private static int three = 3;
public enum Numbers {
ONE(1), TWO(2), THREE(three), FOUR(three + 1);
private final int num;
private Numbers(int n) {
this.num = n;
}
public int getNum() {
return num;
}
}
public void check() {
assertTrue(Numbers.ONE.getNum() == 1);
assertTrue(Numbers.THREE.getNum() == 3);
assertTrue(Numbers.FOUR.getNum() == 4);
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("ONE(1)"));
// assertThat(code, containsOne("THREE(three)"));
// assertThat(code, containsOne("assertTrue(Numbers.ONE.getNum() == 1);"));
assertThat(code, containsOne("private Numbers(int n) {"));
}
}
package jadx.tests.integration.inner;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import org.junit.Test;
import static jadx.tests.api.utils.JadxMatchers.countString;
import static org.junit.Assert.assertThat;
public class TestRFieldAccess extends IntegrationTest {
public static class R {
public static final class id {
public static final int Button01 = 2131230730;
}
}
public static class TestR {
public int test() {
return R.id.Button01;
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestRFieldAccess.class);
String code = cls.getCode().toString();
assertThat(code, countString(2, "return R.id.Button01;"));
}
}
...@@ -16,30 +16,32 @@ public class TestOverloadedMethodInvoke extends IntegrationTest { ...@@ -16,30 +16,32 @@ public class TestOverloadedMethodInvoke extends IntegrationTest {
public static class TestCls { public static class TestCls {
int c; int c;
public void method(Throwable th) { public void method(Throwable th, int a) {
c++; c++;
if (th != null) { if (th != null) {
c += 100; c += 100;
} }
c += a;
} }
public void method(Exception e) { public void method(Exception e, int a) {
c += 1000; c += 1000;
if (e != null) { if (e != null) {
c += 10000; c += 10000;
} }
c += a;
} }
public void test(Throwable th, Exception e) { public void test(Throwable th, Exception e) {
method(e); method(e, 10);
method(th); method(th, 100);
method((Throwable) e); method((Throwable) e, 1000);
method((Exception) th); method((Exception) th, 10000);
} }
public void check() { public void check() {
test(null, new Exception()); test(null, new Exception());
assertEquals(12102, c); assertEquals(23212, c);
} }
} }
...@@ -48,11 +50,11 @@ public class TestOverloadedMethodInvoke extends IntegrationTest { ...@@ -48,11 +50,11 @@ public class TestOverloadedMethodInvoke extends IntegrationTest {
ClassNode cls = getClassNode(TestCls.class); ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString(); String code = cls.getCode().toString();
assertThat(code, containsString("public void test(Throwable th, Exception e) {")); assertThat(code, containsOne("public void test(Throwable th, Exception e) {"));
assertThat(code, containsOne("method(e);")); assertThat(code, containsOne("method(e, 10);"));
assertThat(code, containsOne("method(th);")); assertThat(code, containsOne("method(th, 100);"));
assertThat(code, containsOne("method((Throwable) e);")); assertThat(code, containsOne("method((Throwable) e, 1000);"));
assertThat(code, containsOne("method((Exception) th);")); assertThat(code, containsOne("method((Exception) th, 10000);"));
assertThat(code, not(containsString("(Exception) e"))); assertThat(code, not(containsString("(Exception) e")));
} }
} }
package jadx.tests.integration.invoke;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import org.junit.Test;
import static jadx.tests.api.utils.JadxMatchers.countString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class TestSuperInvoke extends IntegrationTest {
public class A {
public int a() {
return 1;
}
}
public class B extends A {
@Override
public int a() {
return super.a() + 2;
}
public int test() {
return a();
}
}
public void check() {
assertEquals(3, new B().test());
}
@Test
public void test() {
noDebugInfo();
ClassNode cls = getClassNode(TestSuperInvoke.class);
String code = cls.getCode().toString();
assertThat(code, countString(2, "return super.a() + 2;"));
}
}
package jadx.tests.smali; package jadx.tests.smali;
import jadx.tests.api.SmaliTest;
import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;
import org.junit.Test; import org.junit.Test;
......
...@@ -3,6 +3,7 @@ package jadx.gui.update; ...@@ -3,6 +3,7 @@ package jadx.gui.update;
import jadx.api.JadxDecompiler; import jadx.api.JadxDecompiler;
import jadx.gui.update.data.Release; import jadx.gui.update.data.Release;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.lang.reflect.Type; import java.lang.reflect.Type;
...@@ -29,7 +30,8 @@ public class JadxUpdate { ...@@ -29,7 +30,8 @@ public class JadxUpdate {
private static final Gson GSON = new Gson(); private static final Gson GSON = new Gson();
private static final Type RELEASES_LIST_TYPE = new TypeToken<List<Release>>() {}.getType(); private static final Type RELEASES_LIST_TYPE = new TypeToken<List<Release>>() {
}.getType();
private static final Comparator<Release> RELEASE_COMPARATOR = new Comparator<Release>() { private static final Comparator<Release> RELEASE_COMPARATOR = new Comparator<Release>() {
@Override @Override
...@@ -38,10 +40,13 @@ public class JadxUpdate { ...@@ -38,10 +40,13 @@ public class JadxUpdate {
} }
}; };
public static interface IUpdateCallback { public interface IUpdateCallback {
void onUpdate(Release r); void onUpdate(Release r);
} }
private JadxUpdate() {
}
public static void check(final IUpdateCallback callback) { public static void check(final IUpdateCallback callback) {
Runnable run = new Runnable() { Runnable run = new Runnable() {
@Override @Override
...@@ -62,7 +67,7 @@ public class JadxUpdate { ...@@ -62,7 +67,7 @@ public class JadxUpdate {
thread.start(); thread.start();
} }
private static Release checkForNewRelease() throws Exception { private static Release checkForNewRelease() throws IOException {
String version = JadxDecompiler.getVersion(); String version = JadxDecompiler.getVersion();
if (version.contains("dev")) { if (version.contains("dev")) {
LOG.debug("Ignore check for update: development version"); LOG.debug("Ignore check for update: development version");
...@@ -92,7 +97,7 @@ public class JadxUpdate { ...@@ -92,7 +97,7 @@ public class JadxUpdate {
return latest; return latest;
} }
private static <T> T get(String url, Type type) throws Exception { private static <T> T get(String url, Type type) throws IOException {
URL obj = new URL(url); URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET"); con.setRequestMethod("GET");
......
...@@ -2,6 +2,9 @@ package jadx.gui.update; ...@@ -2,6 +2,9 @@ package jadx.gui.update;
public class VersionComparator { public class VersionComparator {
private VersionComparator() {
}
public static int checkAndCompare(String str1, String str2) { public static int checkAndCompare(String str1, String str2) {
try { try {
return compare(clean(str1), clean(str2)); return compare(clean(str1), clean(str2));
......
...@@ -4,98 +4,79 @@ import java.util.prefs.Preferences; ...@@ -4,98 +4,79 @@ import java.util.prefs.Preferences;
public class JadxPreferences { public class JadxPreferences {
private static final String KEY_LAST_OPEN_FILE_PATH = "lastOpenFilePath";
private static final String KEY_LAST_SAVE_FILE_PATH = "lastSaveFilePath";
private static final String KEY_FLATTEN_PACKAGE = "flattenPackage";
private static Preferences prefs = null;
public static String getLastOpenFilePath() { public static String getLastOpenFilePath() {
String result = ""; String result = "";
try { try {
result = getPreferences().get(KEY_LAST_OPEN_FILE_PATH, ""); result = getPreferences().get(KEY_LAST_OPEN_FILE_PATH, "");
if (result.isEmpty()) {
if (result.isEmpty())
{
result = System.getProperty("user.home"); result = System.getProperty("user.home");
} }
} } catch (Exception anyEx) {
catch (Exception anyEx) {
/* do nothing, no preferences */ /* do nothing, no preferences */
} }
return result; return result;
} }
public static void putLastOpenFilePath(String path) { public static void putLastOpenFilePath(String path) {
try { try {
Preferences prefs = getPreferences(); Preferences prefs = getPreferences();
prefs.put(KEY_LAST_OPEN_FILE_PATH, path); prefs.put(KEY_LAST_OPEN_FILE_PATH, path);
prefs.sync(); prefs.sync();
} } catch (Exception anyEx) {
catch (Exception anyEx) {
/* do nothing, no preferences */ /* do nothing, no preferences */
} }
} }
public static String getLastSaveFilePath() { public static String getLastSaveFilePath() {
String result = ""; String result = "";
try { try {
result = getPreferences().get(KEY_LAST_SAVE_FILE_PATH, ""); result = getPreferences().get(KEY_LAST_SAVE_FILE_PATH, "");
if (result.isEmpty()) if (result.isEmpty()) {
{
result = getLastOpenFilePath(); result = getLastOpenFilePath();
} }
} } catch (Exception anyEx) {
catch (Exception anyEx) {
/* do nothing, no preferences */ /* do nothing, no preferences */
} }
return result; return result;
} }
public static void putLastSaveFilePath(String path) { public static void putLastSaveFilePath(String path) {
try { try {
Preferences prefs = getPreferences(); Preferences prefs = getPreferences();
prefs.put(KEY_LAST_SAVE_FILE_PATH, path); prefs.put(KEY_LAST_SAVE_FILE_PATH, path);
prefs.sync(); prefs.sync();
} } catch (Exception anyEx) {
catch (Exception anyEx) {
/* do nothing, no preferences */ /* do nothing, no preferences */
} }
} }
public static boolean getFlattenPackage() { public static boolean getFlattenPackage() {
boolean result = false; boolean result = false;
try { try {
Preferences prefs = getPreferences(); Preferences prefs = getPreferences();
result = prefs.getBoolean(KEY_FLATTEN_PACKAGE, false); result = prefs.getBoolean(KEY_FLATTEN_PACKAGE, false);
} } catch (Exception anyEx) {
catch (Exception anyEx) {
/* do nothing, no preferences */ /* do nothing, no preferences */
} }
return result; return result;
} }
public static void putFlattenPackage(boolean value) { public static void putFlattenPackage(boolean value) {
try { try {
Preferences prefs = getPreferences(); Preferences prefs = getPreferences();
prefs.putBoolean(KEY_FLATTEN_PACKAGE, value); prefs.putBoolean(KEY_FLATTEN_PACKAGE, value);
prefs.sync(); prefs.sync();
} } catch (Exception anyEx) {
catch (Exception anyEx) {
/* do nothing, no preferences */ /* do nothing, no preferences */
} }
} }
private static final String KEY_LAST_OPEN_FILE_PATH = "lastOpenFilePath";
private static final String KEY_LAST_SAVE_FILE_PATH = "lastSaveFilePath";
private static final String KEY_FLATTEN_PACKAGE = "flattenPackage";
private static Preferences prefs = null;
private static Preferences getPreferences() { private static Preferences getPreferences() {
if (prefs == null) { if (prefs == null) {
prefs = Preferences.userRoot(); prefs = Preferences.userRoot();
......
...@@ -12,9 +12,14 @@ import java.io.IOException; ...@@ -12,9 +12,14 @@ import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.awt.Desktop.Action; import static java.awt.Desktop.Action;
public class Link extends JLabel implements MouseListener { public class Link extends JLabel implements MouseListener {
private static final Logger LOG = LoggerFactory.getLogger(JLabel.class);
private String url; private String url;
public Link(String text, String url) { public Link(String text, String url) {
...@@ -42,10 +47,12 @@ public class Link extends JLabel implements MouseListener { ...@@ -42,10 +47,12 @@ public class Link extends JLabel implements MouseListener {
@Override @Override
public void mousePressed(MouseEvent arg0) { public void mousePressed(MouseEvent arg0) {
// ignore
} }
@Override @Override
public void mouseReleased(MouseEvent arg0) { public void mouseReleased(MouseEvent arg0) {
// ignore
} }
private void browse() { private void browse() {
...@@ -56,9 +63,9 @@ public class Link extends JLabel implements MouseListener { ...@@ -56,9 +63,9 @@ public class Link extends JLabel implements MouseListener {
desktop.browse(new java.net.URI(url)); desktop.browse(new java.net.URI(url));
return; return;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.debug("Open url error", e);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); LOG.debug("Open url error", e);
} }
} }
} }
...@@ -78,13 +85,13 @@ public class Link extends JLabel implements MouseListener { ...@@ -78,13 +85,13 @@ public class Link extends JLabel implements MouseListener {
return; return;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); LOG.debug("Open url error", e);
} }
showUrlDialog(); showUrlDialog();
} }
private void showUrlDialog() { private void showUrlDialog() {
JTextArea urlArea = new JTextArea("Can't open browser. Please browse to:\n"+url); JTextArea urlArea = new JTextArea("Can't open browser. Please browse to:\n" + url);
JOptionPane.showMessageDialog(null, urlArea); JOptionPane.showMessageDialog(null, urlArea);
} }
} }
package jadx.gui.treemodel; package jadx.gui.treemodel;
import jadx.api.JadxDecompiler;
import jadx.api.Factory; import jadx.api.Factory;
import jadx.api.IJadxArgs; import jadx.api.IJadxArgs;
import jadx.api.JadxDecompiler;
import jadx.api.JavaClass; import jadx.api.JavaClass;
import jadx.api.JavaPackage; import jadx.api.JavaPackage;
import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.ClassNode;
......
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