java-decompiler: post-import cleanup (common fixes and optimizations)

This commit is contained in:
Roman Shevchenko
2014-08-29 21:58:12 +04:00
parent 63b8d35d08
commit f5431c3bb1
62 changed files with 410 additions and 422 deletions

View File

@@ -24,10 +24,7 @@ import org.jetbrains.java.decompiler.code.cfg.ExceptionRangeCFG;
import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
public class DeadCodeHelper {
@@ -177,7 +174,7 @@ public class DeadCodeHelper {
}
// finally exit edges
HashSet<BasicBlock> setFinallyExits = graph.getFinallyExits();
Set<BasicBlock> setFinallyExits = graph.getFinallyExits();
if (setFinallyExits.contains(block)) {
setFinallyExits.remove(block);
setFinallyExits.add(setPreds.iterator().next());

View File

@@ -83,11 +83,8 @@ public class DecHelper {
boolean repeat = false;
setDest.remove(post);
Iterator<Statement> it = setDest.iterator();
while (it.hasNext()) {
Statement stat = it.next();
for (Statement stat : setDest) {
if (stat.getLastBasicType() != Statement.LASTBASICTYPE_GENERAL) {
if (post == null) {
post = stat;

View File

@@ -497,10 +497,7 @@ public class DomHelper {
while (true) {
boolean hdfound = false;
Iterator<Statement> itHandlers = setHandlers.iterator();
while (itHandlers.hasNext()) {
Statement handler = itHandlers.next();
for (Statement handler : setHandlers) {
if (setNodes.contains(handler)) {
continue;
}
@@ -553,9 +550,7 @@ public class DomHelper {
setHandlers.removeAll(setNodes);
boolean excok = true;
Iterator<Statement> itt = setHandlers.iterator();
while (itt.hasNext()) {
Statement handler = itt.next();
for (Statement handler : setHandlers) {
if (!handler.getNeighbours(StatEdge.TYPE_EXCEPTION, Statement.DIRECTION_BACKWARD).containsAll(setNodes)) {
excok = false;
break;

View File

@@ -259,7 +259,7 @@ public class ExprProcessor implements CodeConstants {
}
// FIXME: Ugly code, to be rewritten. A tuple class is needed.
private String buildEntryPointKey(LinkedList<String> entrypoints) {
private static String buildEntryPointKey(LinkedList<String> entrypoints) {
if (entrypoints.isEmpty()) {
return null;
}
@@ -273,7 +273,7 @@ public class ExprProcessor implements CodeConstants {
}
}
private PrimitiveExprsList copyVarExprents(PrimitiveExprsList data) {
private static PrimitiveExprsList copyVarExprents(PrimitiveExprsList data) {
ExprentStack stack = data.getStack();
for (int i = 0; i < stack.size(); i++) {
stack.set(i, stack.get(i).copy());
@@ -281,7 +281,7 @@ public class ExprProcessor implements CodeConstants {
return data;
}
private void collectCatchVars(Statement stat, FlattenStatementsHelper flatthelper, Map<String, VarExprent> map) {
private static void collectCatchVars(Statement stat, FlattenStatementsHelper flatthelper, Map<String, VarExprent> map) {
List<VarExprent> lst = null;
@@ -306,7 +306,7 @@ public class ExprProcessor implements CodeConstants {
}
}
private void initStatementExprents(Statement stat) {
private static void initStatementExprents(Statement stat) {
stat.initExprents();
for (Statement st : stat.getStats()) {
@@ -754,7 +754,7 @@ public class ExprProcessor implements CodeConstants {
}
public static String jmpWrapper(Statement stat, int indent, boolean semicolon) {
StringBuffer buf = new StringBuffer(stat.toJava(indent));
StringBuilder buf = new StringBuilder(stat.toJava(indent));
String new_line_separator = DecompilerContext.getNewLineSeparator();
@@ -773,14 +773,14 @@ public class ExprProcessor implements CodeConstants {
}
if (edge.labeled) {
buf.append(" label" + edge.closure.id);
buf.append(" label").append(edge.closure.id);
}
buf.append(";" + new_line_separator);
buf.append(";").append(new_line_separator);
}
}
if (buf.length() == 0 && semicolon) {
buf.append(InterpreterUtil.getIndentString(indent) + ";" + new_line_separator);
buf.append(InterpreterUtil.getIndentString(indent)).append(";").append(new_line_separator);
}
return buf.toString();
@@ -789,7 +789,7 @@ public class ExprProcessor implements CodeConstants {
public static String buildJavaClassName(String name) {
String res = name.replace('/', '.');
if (res.indexOf("$") >= 0) { // attempt to invoke foreign member
if (res.contains("$")) { // attempt to invoke foreign member
// classes correctly
StructClass cl = DecompilerContext.getStructcontext().getClass(name);
if (cl == null || !cl.isOwn()) {
@@ -808,7 +808,7 @@ public class ExprProcessor implements CodeConstants {
String indstr = InterpreterUtil.getIndentString(indent);
String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
for (Exprent expr : lst) {
String content = expr.toJava(indent);

View File

@@ -46,9 +46,8 @@ import java.util.Map.Entry;
public class FinallyProcessor {
private HashMap<Integer, Integer> finallyBlockIDs = new HashMap<Integer, Integer>();
private HashMap<Integer, Integer> catchallBlockIDs = new HashMap<Integer, Integer>();
private Map<Integer, Integer> finallyBlockIDs = new HashMap<Integer, Integer>();
private Map<Integer, Integer> catchallBlockIDs = new HashMap<Integer, Integer>();
private VarProcessor varprocessor;
@@ -92,7 +91,7 @@ public class FinallyProcessor {
}
else {
Object[] inf = getFinallyInformation(mt, root, fin);
Record inf = getFinallyInformation(mt, root, fin);
if (inf == null) { // inconsistent finally
catchallBlockIDs.put(handler.id, null);
@@ -181,10 +180,20 @@ public class FinallyProcessor {
// return res;
// }
private static class Record {
private final int firstCode;
private final Map<BasicBlock, Boolean> mapLast;
private Object[] getFinallyInformation(StructMethod mt, RootStatement root, CatchAllStatement fstat) {
private Record(int firstCode, Map<BasicBlock, Boolean> mapLast) {
this.firstCode = firstCode;
this.mapLast = mapLast;
}
}
HashMap<BasicBlock, Boolean> mapLast = new HashMap<BasicBlock, Boolean>();
private static Record getFinallyInformation(StructMethod mt, RootStatement root, CatchAllStatement fstat) {
Map<BasicBlock, Boolean> mapLast = new HashMap<BasicBlock, Boolean>();
BasicBlockStatement firstBlockStatement = fstat.getHandler().getBasichead();
BasicBlock firstBasicBlock = firstBlockStatement.getBlock();
@@ -216,7 +225,7 @@ public class FinallyProcessor {
LinkedList<DirectNode> stack = new LinkedList<DirectNode>();
stack.add(dgraph.first);
HashSet<DirectNode> setVisited = new HashSet<DirectNode>();
Set<DirectNode> setVisited = new HashSet<DirectNode>();
while (!stack.isEmpty()) {
@@ -356,21 +365,21 @@ public class FinallyProcessor {
}
}
return new Object[]{firstcode, mapLast};
return new Record(firstcode, mapLast);
}
private void insertSemaphore(ControlFlowGraph graph,
HashSet<BasicBlock> setTry,
BasicBlock head,
BasicBlock handler,
int var,
Object[] information,
int bytecode_version) {
private static void insertSemaphore(ControlFlowGraph graph,
Set<BasicBlock> setTry,
BasicBlock head,
BasicBlock handler,
int var,
Record information,
int bytecode_version) {
HashSet<BasicBlock> setCopy = new HashSet<BasicBlock>(setTry);
Set<BasicBlock> setCopy = new HashSet<BasicBlock>(setTry);
int finallytype = (Integer)information[0];
HashMap<BasicBlock, Boolean> mapLast = (HashMap<BasicBlock, Boolean>)information[1];
int finallytype = information.firstCode;
Map<BasicBlock, Boolean> mapLast = information.mapLast;
// first and last statements
removeExceptionInstructionsEx(handler, 1, finallytype);
@@ -468,7 +477,7 @@ public class FinallyProcessor {
}
private void insertBlockBefore(ControlFlowGraph graph, BasicBlock oldblock, BasicBlock newblock) {
private static void insertBlockBefore(ControlFlowGraph graph, BasicBlock oldblock, BasicBlock newblock) {
List<BasicBlock> lstTemp = new ArrayList<BasicBlock>();
lstTemp.addAll(oldblock.getPreds());
@@ -501,7 +510,7 @@ public class FinallyProcessor {
}
}
private HashSet<BasicBlock> getAllBasicBlocks(Statement stat) {
private static HashSet<BasicBlock> getAllBasicBlocks(Statement stat) {
List<Statement> lst = new LinkedList<Statement>();
lst.add(stat);
@@ -530,13 +539,13 @@ public class FinallyProcessor {
}
private boolean verifyFinallyEx(ControlFlowGraph graph, CatchAllStatement fstat, Object[] information) {
private boolean verifyFinallyEx(ControlFlowGraph graph, CatchAllStatement fstat, Record information) {
HashSet<BasicBlock> tryBlocks = getAllBasicBlocks(fstat.getFirst());
HashSet<BasicBlock> catchBlocks = getAllBasicBlocks(fstat.getHandler());
int finallytype = (Integer)information[0];
HashMap<BasicBlock, Boolean> mapLast = (HashMap<BasicBlock, Boolean>)information[1];
int finallytype = information.firstCode;
Map<BasicBlock, Boolean> mapLast = information.mapLast;
BasicBlock first = fstat.getHandler().getBasichead().getBlock();
boolean skippedFirst = false;
@@ -571,16 +580,16 @@ public class FinallyProcessor {
startBlocks.remove(graph.getLast());
startBlocks.removeAll(tryBlocks);
List<Object[]> lstAreas = new ArrayList<Object[]>();
List<Area> lstAreas = new ArrayList<Area>();
for (BasicBlock start : startBlocks) {
Object[] arr = compareSubgraphsEx(graph, start, catchBlocks, first, finallytype, mapLast, skippedFirst);
Area arr = compareSubgraphsEx(graph, start, catchBlocks, first, finallytype, mapLast, skippedFirst);
if (arr == null) {
return false;
}
lstAreas.add(new Object[]{start, arr[0], arr[1]});
lstAreas.add(arr);
}
// try {
@@ -588,7 +597,7 @@ public class FinallyProcessor {
// } catch(Exception ex){ex.printStackTrace();}
// delete areas
for (Object[] area : lstAreas) {
for (Area area : lstAreas) {
deleteArea(graph, area);
}
@@ -611,13 +620,25 @@ public class FinallyProcessor {
return true;
}
private Object[] compareSubgraphsEx(ControlFlowGraph graph,
BasicBlock startSample,
HashSet<BasicBlock> catchBlocks,
BasicBlock startCatch,
int finallytype,
HashMap<BasicBlock, Boolean> mapLast,
boolean skippedFirst) {
private static class Area {
private final BasicBlock start;
private final Set<BasicBlock> sample;
private final BasicBlock next;
private Area(BasicBlock start, Set<BasicBlock> sample, BasicBlock next) {
this.start = start;
this.sample = sample;
this.next = next;
}
}
private Area compareSubgraphsEx(ControlFlowGraph graph,
BasicBlock startSample,
HashSet<BasicBlock> catchBlocks,
BasicBlock startCatch,
int finallytype,
Map<BasicBlock, Boolean> mapLast,
boolean skippedFirst) {
class BlockStackEntry {
public BasicBlock blockCatch;
@@ -635,9 +656,9 @@ public class FinallyProcessor {
List<BlockStackEntry> stack = new LinkedList<BlockStackEntry>();
HashSet<BasicBlock> setSample = new HashSet<BasicBlock>();
Set<BasicBlock> setSample = new HashSet<BasicBlock>();
HashMap<String, BasicBlock[]> mapNext = new HashMap<String, BasicBlock[]>();
Map<String, BasicBlock[]> mapNext = new HashMap<String, BasicBlock[]>();
stack.add(new BlockStackEntry(startCatch, startSample, new ArrayList<int[]>()));
@@ -719,7 +740,7 @@ public class FinallyProcessor {
}
if (isLastBlock) {
HashSet<BasicBlock> setSuccs = new HashSet<BasicBlock>(blockSample.getSuccs());
Set<BasicBlock> setSuccs = new HashSet<BasicBlock>(blockSample.getSuccs());
setSuccs.removeAll(setSample);
for (BlockStackEntry stackent : stack) {
@@ -734,10 +755,10 @@ public class FinallyProcessor {
}
}
return new Object[]{setSample, getUniqueNext(graph, new HashSet<BasicBlock[]>(mapNext.values()))};
return new Area(startSample, setSample, getUniqueNext(graph, new HashSet<BasicBlock[]>(mapNext.values())));
}
private BasicBlock getUniqueNext(ControlFlowGraph graph, HashSet<BasicBlock[]> setNext) {
private static BasicBlock getUniqueNext(ControlFlowGraph graph, Set<BasicBlock[]> setNext) {
// precondition: there is at most one true exit path in a finally statement
@@ -784,7 +805,7 @@ public class FinallyProcessor {
return null;
}
for (int j = 0; i < instrNext.getOperands().length; j++) {
for (int j = 0; j < instrNext.getOperands().length; j++) {
if (instrNext.getOperand(j) != instrBlock.getOperand(j)) {
return null;
}
@@ -889,7 +910,7 @@ public class FinallyProcessor {
graph.getBlocks().addWithKey(newblock, newblock.id);
HashSet<BasicBlock> setFinallyExits = graph.getFinallyExits();
Set<BasicBlock> setFinallyExits = graph.getFinallyExits();
if (setFinallyExits.contains(sample)) {
setFinallyExits.remove(sample);
setFinallyExits.add(newblock);
@@ -939,10 +960,10 @@ public class FinallyProcessor {
return true;
}
private void deleteArea(ControlFlowGraph graph, Object[] area) {
private static void deleteArea(ControlFlowGraph graph, Area area) {
BasicBlock start = (BasicBlock)area[0];
BasicBlock next = (BasicBlock)area[2];
BasicBlock start = area.start;
BasicBlock next = area.next;
if (start == next) {
return;
@@ -954,23 +975,23 @@ public class FinallyProcessor {
}
// collect common exception ranges of predecessors and successors
HashSet<BasicBlock> setCommonExceptionHandlers = new HashSet<BasicBlock>(next.getSuccExceptions());
Set<BasicBlock> setCommonExceptionHandlers = new HashSet<BasicBlock>(next.getSuccExceptions());
for (BasicBlock pred : start.getPreds()) {
setCommonExceptionHandlers.retainAll(pred.getSuccExceptions());
}
boolean is_outside_range = false;
HashSet<BasicBlock> setPredecessors = new HashSet<BasicBlock>(start.getPreds());
Set<BasicBlock> setPredecessors = new HashSet<BasicBlock>(start.getPreds());
// replace start with next
for (BasicBlock pred : setPredecessors) {
pred.replaceSuccessor(start, next);
}
HashSet<BasicBlock> setBlocks = (HashSet<BasicBlock>)area[1];
Set<BasicBlock> setBlocks = area.sample;
HashSet<ExceptionRangeCFG> setCommonRemovedExceptionRanges = null;
Set<ExceptionRangeCFG> setCommonRemovedExceptionRanges = null;
// remove all the blocks inbetween
for (BasicBlock block : setBlocks) {
@@ -983,7 +1004,7 @@ public class FinallyProcessor {
is_outside_range = true;
}
HashSet<ExceptionRangeCFG> setRemovedExceptionRanges = new HashSet<ExceptionRangeCFG>();
Set<ExceptionRangeCFG> setRemovedExceptionRanges = new HashSet<ExceptionRangeCFG>();
for (BasicBlock handler : block.getSuccExceptions()) {
setRemovedExceptionRanges.add(graph.getExceptionRange(handler, block));
}
@@ -1036,7 +1057,7 @@ public class FinallyProcessor {
}
}
private void removeExceptionInstructionsEx(BasicBlock block, int blocktype, int finallytype) {
private static void removeExceptionInstructionsEx(BasicBlock block, int blocktype, int finallytype) {
InstructionSequence seq = block.getSeq();

View File

@@ -223,10 +223,8 @@ public class LabelHelper {
processEdgesWithNext(ifstat.getFirst(), mapEdges, null);
}
else {
if (ifstat.getIfstat() != null) {
mapEdges = setExplicitEdges(ifstat.getIfstat());
processEdgesWithNext(ifstat.getIfstat(), mapEdges, null);
}
mapEdges = setExplicitEdges(ifstat.getIfstat());
processEdgesWithNext(ifstat.getIfstat(), mapEdges, null);
HashMap<Statement, List<StatEdge>> mapEdges1 = null;
if (ifstat.getElsestat() != null) {
@@ -422,17 +420,14 @@ public class LabelHelper {
}
}
private static HashSet<Statement>[] processStatementLabel(Statement stat) {
HashSet<Statement> setBreak = new HashSet<Statement>();
HashSet<Statement> setContinue = new HashSet<Statement>();
private static void processStatementLabel(Statement stat) {
processStatementLabel(stat, new HashSet<Statement>(), new HashSet<Statement>());
}
private static void processStatementLabel(Statement stat, Set<Statement> setBreak, Set<Statement> setContinue) {
if (stat.getExprents() == null) {
for (Statement st : stat.getStats()) {
HashSet<Statement>[] arr = processStatementLabel(st);
setBreak.addAll(arr[0]);
setContinue.addAll(arr[1]);
processStatementLabel(st, setBreak, setContinue);
}
boolean shieldtype = (stat.type == Statement.TYPE_DO || stat.type == Statement.TYPE_SWITCH);
@@ -456,8 +451,6 @@ public class LabelHelper {
setBreak.add(stat);
setContinue.add(stat);
return new HashSet[]{setBreak, setContinue};
}
public static void replaceContinueWithBreak(Statement stat) {

View File

@@ -110,7 +110,7 @@ public class StackVarsProcessor {
setVersionsToNull(root);
}
private void setVersionsToNull(Statement stat) {
private static void setVersionsToNull(Statement stat) {
if (stat.getExprents() == null) {
for (Object obj : stat.getSequentialObjects()) {
@@ -129,7 +129,7 @@ public class StackVarsProcessor {
}
}
private void setExprentVersionsToNull(Exprent exprent) {
private static void setExprentVersionsToNull(Exprent exprent) {
List<Exprent> lst = exprent.getAllExprents(true);
lst.add(exprent);
@@ -236,7 +236,7 @@ public class StackVarsProcessor {
}
private Exprent isReplaceableVar(Exprent exprent, HashMap<VarVersionPaar, Exprent> mapVarValues, SSAUConstructorSparseEx ssau) {
private static Exprent isReplaceableVar(Exprent exprent, HashMap<VarVersionPaar, Exprent> mapVarValues, SSAUConstructorSparseEx ssau) {
Exprent dest = null;
@@ -248,7 +248,7 @@ public class StackVarsProcessor {
return dest;
}
private void replaceSingleVar(Exprent parent, VarExprent var, Exprent dest, SSAUConstructorSparseEx ssau) {
private static void replaceSingleVar(Exprent parent, VarExprent var, Exprent dest, SSAUConstructorSparseEx ssau) {
parent.replaceExprent(var, dest);
@@ -438,7 +438,7 @@ public class StackVarsProcessor {
}
}
private HashSet<VarVersionPaar> getAllVersions(Exprent exprent) {
private static HashSet<VarVersionPaar> getAllVersions(Exprent exprent) {
HashSet<VarVersionPaar> res = new HashSet<VarVersionPaar>();
@@ -455,11 +455,11 @@ public class StackVarsProcessor {
return res;
}
private Object[] iterateChildExprent(Exprent exprent,
Exprent parent,
Exprent next,
HashMap<VarVersionPaar, Exprent> mapVarValues,
SSAUConstructorSparseEx ssau) {
private static Object[] iterateChildExprent(Exprent exprent,
Exprent parent,
Exprent next,
HashMap<VarVersionPaar, Exprent> mapVarValues,
SSAUConstructorSparseEx ssau) {
boolean changed = false;
@@ -589,7 +589,7 @@ public class StackVarsProcessor {
return new Object[]{null, changed, false};
}
private boolean getUsedVersions(SSAUConstructorSparseEx ssa, VarVersionPaar var, List<VarVersionNode> res) {
private static boolean getUsedVersions(SSAUConstructorSparseEx ssa, VarVersionPaar var, List<VarVersionNode> res) {
VarVersionsGraph ssuversions = ssa.getSsuversions();
VarVersionNode varnode = ssuversions.nodes.getWithKey(var);
@@ -638,10 +638,10 @@ public class StackVarsProcessor {
return !setNotDoms.isEmpty();
}
private boolean isVersionToBeReplaced(VarVersionPaar usedvar,
HashMap<Integer, HashSet<VarVersionPaar>> mapVars,
SSAUConstructorSparseEx ssau,
VarVersionPaar leftpaar) {
private static boolean isVersionToBeReplaced(VarVersionPaar usedvar,
HashMap<Integer, HashSet<VarVersionPaar>> mapVars,
SSAUConstructorSparseEx ssau,
VarVersionPaar leftpaar) {
VarVersionsGraph ssuversions = ssau.getSsuversions();
@@ -687,9 +687,9 @@ public class StackVarsProcessor {
return true;
}
private HashMap<Integer, HashSet<VarVersionPaar>> getAllVarVersions(VarVersionPaar leftvar,
Exprent exprent,
SSAUConstructorSparseEx ssau) {
private static HashMap<Integer, HashSet<VarVersionPaar>> getAllVarVersions(VarVersionPaar leftvar,
Exprent exprent,
SSAUConstructorSparseEx ssau) {
HashMap<Integer, HashSet<VarVersionPaar>> map = new HashMap<Integer, HashSet<VarVersionPaar>>();
SFormsFastMapDirect mapLiveVars = ssau.getLiveVarVersionsMap(leftvar);

View File

@@ -43,7 +43,7 @@ public class DominatorEngine {
}
}
private Integer getCommonIDom(Integer key1, Integer key2, VBStyleCollection<Integer, Integer> orderedIDoms) {
private static Integer getCommonIDom(Integer key1, Integer key2, VBStyleCollection<Integer, Integer> orderedIDoms) {
if (key1 == null) {
return key2;

View File

@@ -45,7 +45,7 @@ public class GenericDominatorEngine {
}
}
private IGraphNode getCommonIDom(IGraphNode node1, IGraphNode node2, VBStyleCollection<IGraphNode, IGraphNode> orderedIDoms) {
private static IGraphNode getCommonIDom(IGraphNode node1, IGraphNode node2, VBStyleCollection<IGraphNode, IGraphNode> orderedIDoms) {
IGraphNode nodeOld;

View File

@@ -32,16 +32,30 @@ import java.util.Map.Entry;
public class ExceptionDeobfuscator {
private static class Range {
private final BasicBlock handler;
private final String uniqueStr;
private final Set<BasicBlock> protectedRange;
private final ExceptionRangeCFG rangeCFG;
private Range(BasicBlock handler, String uniqueStr, Set<BasicBlock> protectedRange, ExceptionRangeCFG rangeCFG) {
this.handler = handler;
this.uniqueStr = uniqueStr;
this.protectedRange = protectedRange;
this.rangeCFG = rangeCFG;
}
}
public static void restorePopRanges(ControlFlowGraph graph) {
List<Object[]> lstRanges = new ArrayList<Object[]>();
List<Range> lstRanges = new ArrayList<Range>();
// aggregate ranges
for (ExceptionRangeCFG range : graph.getExceptions()) {
boolean found = false;
for (Object[] arr : lstRanges) {
if (arr[0] == range.getHandler() && InterpreterUtil.equalObjects(range.getUniqueExceptionsString(), arr[1])) {
((HashSet<BasicBlock>)arr[2]).addAll(range.getProtectedRange());
for (Range arr : lstRanges) {
if (arr.handler == range.getHandler() && InterpreterUtil.equalObjects(range.getUniqueExceptionsString(), arr.uniqueStr)) {
arr.protectedRange.addAll(range.getProtectedRange());
found = true;
break;
}
@@ -49,37 +63,36 @@ public class ExceptionDeobfuscator {
if (!found) {
// doesn't matter, which range chosen
lstRanges.add(
new Object[]{range.getHandler(), range.getUniqueExceptionsString(), new HashSet<BasicBlock>(range.getProtectedRange()), range});
lstRanges.add(new Range(range.getHandler(), range.getUniqueExceptionsString(), new HashSet<BasicBlock>(range.getProtectedRange()), range));
}
}
// process aggregated ranges
for (Object[] range : lstRanges) {
for (Range range : lstRanges) {
if (range[1] != null) {
if (range.uniqueStr != null) {
BasicBlock handler = (BasicBlock)range[0];
BasicBlock handler = range.handler;
InstructionSequence seq = handler.getSeq();
Instruction firstinstr = null;
Instruction firstinstr;
if (seq.length() > 0) {
firstinstr = seq.getInstr(0);
if (firstinstr.opcode == CodeConstants.opc_pop ||
firstinstr.opcode == CodeConstants.opc_astore) {
HashSet<BasicBlock> setrange = new HashSet<BasicBlock>((HashSet<BasicBlock>)range[2]);
Set<BasicBlock> setrange = new HashSet<BasicBlock>(range.protectedRange);
for (Object[] range_super : lstRanges) { // finally or strict superset
for (Range range_super : lstRanges) { // finally or strict superset
if (range != range_super) {
HashSet<BasicBlock> setrange_super = new HashSet<BasicBlock>((HashSet<BasicBlock>)range_super[2]);
Set<BasicBlock> setrange_super = new HashSet<BasicBlock>(range_super.protectedRange);
if (!setrange.contains(range_super[0]) && !setrange_super.contains(handler)
&& (range_super[1] == null || setrange_super.containsAll(setrange))) {
if (!setrange.contains(range_super.handler) && !setrange_super.contains(handler)
&& (range_super.uniqueStr == null || setrange_super.containsAll(setrange))) {
if (range_super[1] == null) {
if (range_super.uniqueStr == null) {
setrange_super.retainAll(setrange);
}
else {
@@ -129,11 +142,10 @@ public class ExceptionDeobfuscator {
seq.removeInstruction(0);
}
newblock.addSuccessorException(range_super.handler);
range_super.rangeCFG.getProtectedRange().add(newblock);
newblock.addSuccessorException((BasicBlock)range_super[0]);
((ExceptionRangeCFG)range_super[3]).getProtectedRange().add(newblock);
handler = ((ExceptionRangeCFG)range[3]).getHandler();
handler = range.rangeCFG.getHandler();
seq = handler.getSeq();
}
}
@@ -147,7 +159,7 @@ public class ExceptionDeobfuscator {
public static void insertEmptyExceptionHandlerBlocks(ControlFlowGraph graph) {
HashSet<BasicBlock> setVisited = new HashSet<BasicBlock>();
Set<BasicBlock> setVisited = new HashSet<BasicBlock>();
for (ExceptionRangeCFG range : graph.getExceptions()) {
BasicBlock handler = range.getHandler();
@@ -255,7 +267,7 @@ public class ExceptionDeobfuscator {
List<BasicBlock> lstRes = new ArrayList<BasicBlock>();
LinkedList<BasicBlock> stack = new LinkedList<BasicBlock>();
HashSet<BasicBlock> setVisited = new HashSet<BasicBlock>();
Set<BasicBlock> setVisited = new HashSet<BasicBlock>();
BasicBlock handler = range.getHandler();
stack.addFirst(handler);
@@ -285,22 +297,20 @@ public class ExceptionDeobfuscator {
public static boolean hasObfuscatedExceptions(ControlFlowGraph graph) {
BasicBlock first = graph.getFirst();
HashMap<BasicBlock, HashSet<BasicBlock>> mapRanges = new HashMap<BasicBlock, HashSet<BasicBlock>>();
Map<BasicBlock, Set<BasicBlock>> mapRanges = new HashMap<BasicBlock, Set<BasicBlock>>();
for (ExceptionRangeCFG range : graph.getExceptions()) {
HashSet<BasicBlock> set = mapRanges.get(range.getHandler());
Set<BasicBlock> set = mapRanges.get(range.getHandler());
if (set == null) {
mapRanges.put(range.getHandler(), set = new HashSet<BasicBlock>());
}
set.addAll(range.getProtectedRange());
}
for (Entry<BasicBlock, HashSet<BasicBlock>> ent : mapRanges.entrySet()) {
HashSet<BasicBlock> setEntries = new HashSet<BasicBlock>();
for (Entry<BasicBlock, Set<BasicBlock>> ent : mapRanges.entrySet()) {
Set<BasicBlock> setEntries = new HashSet<BasicBlock>();
for (BasicBlock block : ent.getValue()) {
HashSet<BasicBlock> setTemp = new HashSet<BasicBlock>(block.getPreds());
Set<BasicBlock> setTemp = new HashSet<BasicBlock>(block.getPreds());
setTemp.removeAll(ent.getValue());
if (!setTemp.isEmpty()) {

View File

@@ -65,7 +65,7 @@ public class AnnotationExprent extends Exprent {
String indstr1 = InterpreterUtil.getIndentString(indent + 1);
for (int i = 0; i < parnames.size(); i++) {
buffer.append(new_line_separator + indstr1);
buffer.append(new_line_separator).append(indstr1);
buffer.append(parnames.get(i));
buffer.append(" = ");
buffer.append(parvalues.get(i).toJava(indent + 2));
@@ -74,7 +74,7 @@ public class AnnotationExprent extends Exprent {
buffer.append(",");
}
}
buffer.append(new_line_separator + indstr);
buffer.append(new_line_separator).append(indstr);
}
buffer.append(")");

View File

@@ -116,7 +116,7 @@ public class ConstExprent extends Exprent {
else {
switch (consttype.type) {
case CodeConstants.TYPE_BOOLEAN:
return new Boolean(((Integer)value).intValue() != 0).toString();
return Boolean.toString(((Integer)value).intValue() != 0);
case CodeConstants.TYPE_CHAR:
Integer val = (Integer)value;
String ret = escapes.get(val);
@@ -267,7 +267,7 @@ public class ConstExprent extends Exprent {
throw new RuntimeException("invalid constant type");
}
private String convertStringToJava(String value, boolean ascii) {
private static String convertStringToJava(String value, boolean ascii) {
char[] arr = value.toCharArray();
StringBuilder buffer = new StringBuilder(arr.length);

View File

@@ -94,7 +94,7 @@ public class FieldExprent extends Exprent {
}
public String toJava(int indent) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
if (isStatic) {

View File

@@ -568,7 +568,7 @@ public class FunctionExprent extends Exprent {
return res;
}
private VarType getMaxVarType(VarType[] arr) {
private static VarType getMaxVarType(VarType[] arr) {
int[] types = new int[]{CodeConstants.TYPE_DOUBLE, CodeConstants.TYPE_FLOAT, CodeConstants.TYPE_LONG};
VarType[] vartypes = new VarType[]{VarType.VARTYPE_DOUBLE, VarType.VARTYPE_FLOAT, VarType.VARTYPE_LONG};

View File

@@ -112,11 +112,7 @@ public class IfExprent extends Exprent {
}
public String toJava(int indent) {
StringBuffer buf = new StringBuffer("if(");
buf.append(condition.toJava(indent));
buf.append(")");
return buf.toString();
return "if(" + condition.toJava(indent) + ")";
}
public boolean equals(Object o) {

View File

@@ -277,15 +277,15 @@ public class InvocationExprent extends Exprent {
VarType leftType = new VarType(CodeConstants.TYPE_OBJECT, 0, classname);
if (rightType.equals(VarType.VARTYPE_OBJECT) && !leftType.equals(rightType)) {
buf.append("((" + ExprProcessor.getCastTypeName(leftType) + ")");
buf.append("((").append(ExprProcessor.getCastTypeName(leftType)).append(")");
if (instance.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) {
res = "(" + res + ")";
}
buf.append(res + ")");
buf.append(res).append(")");
}
else if (instance.getPrecedence() > getPrecedence()) {
buf.append("(" + res + ")");
buf.append("(").append(res).append(")");
}
else {
buf.append(res);

View File

@@ -402,7 +402,7 @@ public class NewExprent extends Exprent {
return buf.toString();
}
private String getQualifiedNewInstance(String classname, List<Exprent> lstParams, int indent) {
private static String getQualifiedNewInstance(String classname, List<Exprent> lstParams, int indent) {
ClassNode node = DecompilerContext.getClassprocessor().getMapRootClasses().get(classname);

View File

@@ -115,7 +115,7 @@ public class VarExprent extends Exprent {
if (processor != null && processor.getVarFinal(new VarVersionPaar(index, version)) == VarTypeProcessor.VAR_FINALEXPLICIT) {
buf.append("final ");
}
buf.append(ExprProcessor.getCastTypeName(getVartype()) + " ");
buf.append(ExprProcessor.getCastTypeName(getVartype())).append(" ");
}
buf.append(name == null ? ("var" + index + (version == 0 ? "" : "_" + version)) : name);

View File

@@ -53,7 +53,7 @@ public class DirectGraph {
}
}
private void addToReversePostOrderListIterative(DirectNode root, List<DirectNode> lst) {
private static void addToReversePostOrderListIterative(DirectNode root, List<DirectNode> lst) {
LinkedList<DirectNode> stackNode = new LinkedList<DirectNode>();
LinkedList<Integer> stackIndex = new LinkedList<Integer>();

View File

@@ -26,20 +26,19 @@ import java.util.Map.Entry;
public class FlattenStatementsHelper {
// statement.id, node.id(direct), node.id(continue)
private HashMap<Integer, String[]> mapDestinationNodes = new HashMap<Integer, String[]>();
private Map<Integer, String[]> mapDestinationNodes = new HashMap<Integer, String[]>();
// node.id(source), statement.id(destination), edge type
private List<Edge> listEdges = new ArrayList<Edge>();
// node.id(exit), [node.id(source), statement.id(destination)]
public HashMap<String, List<String[]>> mapShortRangeFinallyPathIds = new HashMap<String, List<String[]>>();
private Map<String, List<String[]>> mapShortRangeFinallyPathIds = new HashMap<String, List<String[]>>();
// node.id(exit), [node.id(source), statement.id(destination)]
public HashMap<String, List<String[]>> mapLongRangeFinallyPathIds = new HashMap<String, List<String[]>>();
private Map<String, List<String[]>> mapLongRangeFinallyPathIds = new HashMap<String, List<String[]>>();
// positive if branches
public HashMap<String, String> mapPosIfBranch = new HashMap<String, String>();
private Map<String, Integer> mapPosIfBranch = new HashMap<String, Integer>();
private DirectGraph graph;
@@ -99,7 +98,7 @@ public class FlattenStatementsHelper {
LinkedList<StackEntry> stackFinally = statEntry.stackFinally;
int statementBreakIndex = statEntry.statementIndex;
DirectNode node = null, nd = null;
DirectNode node, nd;
List<StatEdge> lstSuccEdges = new ArrayList<StatEdge>();
DirectNode sourcenode = null;
@@ -133,7 +132,7 @@ public class FlattenStatementsHelper {
// 'if' statement: record positive branch
if (stat.getLastBasicType() == Statement.LASTBASICTYPE_IF) {
mapPosIfBranch.put(sourcenode.id, lstSuccEdges.get(0).getDestination().id.toString());
mapPosIfBranch.put(sourcenode.id, lstSuccEdges.get(0).getDestination().id);
}
break;
@@ -485,7 +484,7 @@ public class FlattenStatementsHelper {
}
}
public HashMap<Integer, String[]> getMapDestinationNodes() {
public Map<Integer, String[]> getMapDestinationNodes() {
return mapDestinationNodes;
}

View File

@@ -416,7 +416,7 @@ public class SSAConstructorSparseEx {
return mapNew;
}
private SFormsFastMapDirect mergeMaps(SFormsFastMapDirect mapTo, SFormsFastMapDirect map2) {
private static SFormsFastMapDirect mergeMaps(SFormsFastMapDirect mapTo, SFormsFastMapDirect map2) {
if (map2 != null && !map2.isEmpty()) {
mapTo.union(map2);
@@ -425,7 +425,7 @@ public class SSAConstructorSparseEx {
return mapTo;
}
private boolean mapsEqual(SFormsFastMapDirect map1, SFormsFastMapDirect map2) {
private static boolean mapsEqual(SFormsFastMapDirect map1, SFormsFastMapDirect map2) {
if (map1 == null) {
return map2 == null;

View File

@@ -683,7 +683,7 @@ public class SSAUConstructorSparseEx {
return mapNew;
}
private SFormsFastMapDirect mergeMaps(SFormsFastMapDirect mapTo, SFormsFastMapDirect map2) {
private static SFormsFastMapDirect mergeMaps(SFormsFastMapDirect mapTo, SFormsFastMapDirect map2) {
if (map2 != null && !map2.isEmpty()) {
mapTo.union(map2);
@@ -692,7 +692,7 @@ public class SSAUConstructorSparseEx {
return mapTo;
}
private boolean mapsEqual(SFormsFastMapDirect map1, SFormsFastMapDirect map2) {
private static boolean mapsEqual(SFormsFastMapDirect map1, SFormsFastMapDirect map2) {
if (map1 == null) {
return map2 == null;
@@ -789,7 +789,7 @@ public class SSAUConstructorSparseEx {
return map;
}
private Integer getFirstProtectedRange(Statement stat) {
private static Integer getFirstProtectedRange(Statement stat) {
while (true) {
Statement parent = stat.getParent();

View File

@@ -116,13 +116,13 @@ public class CatchAllStatement extends Statement {
String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(ExprProcessor.listToJava(varDefinitions, indent));
boolean labeled = isLabeled();
if (labeled) {
buf.append(indstr + "label" + this.id + ":" + new_line_separator);
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
}
List<StatEdge> lstSuccs = first.getSuccessorEdges(STATEDGE_DIRECT_ALL);
@@ -134,26 +134,26 @@ public class CatchAllStatement extends Statement {
buf.append(content);
}
else {
buf.append(indstr + "try {" + new_line_separator);
buf.append(indstr).append("try {").append(new_line_separator);
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true));
buf.append(indstr + "}");
buf.append(indstr).append("}");
}
buf.append((isFinally ? " finally" :
" catch (" + vars.get(0).toJava(indent) + ")") + " {" + new_line_separator);
buf.append(isFinally ? " finally" :
" catch (" + vars.get(0).toJava(indent) + ")").append(" {").append(new_line_separator);
if (monitor != null) {
indstr1 = InterpreterUtil.getIndentString(indent + 1);
buf.append(indstr1 + "if(" + monitor.toJava(indent) + ") {" + new_line_separator);
buf.append(indstr1).append("if(").append(monitor.toJava(indent)).append(") {").append(new_line_separator);
}
buf.append(ExprProcessor.jmpWrapper(handler, indent + 1 + (monitor != null ? 1 : 0), true));
if (monitor != null) {
buf.append(indstr1 + "}" + new_line_separator);
buf.append(indstr1).append("}").append(new_line_separator);
}
buf.append(indstr + "}" + new_line_separator);
buf.append(indstr).append("}").append(new_line_separator);
return buf.toString();
}

View File

@@ -151,19 +151,19 @@ public class CatchStatement extends Statement {
public String toJava(int indent) {
String indstr = InterpreterUtil.getIndentString(indent);
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
String new_line_separator = DecompilerContext.getNewLineSeparator();
buf.append(ExprProcessor.listToJava(varDefinitions, indent));
if (isLabeled()) {
buf.append(indstr + "label" + this.id + ":" + new_line_separator);
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
}
buf.append(indstr + "try {" + new_line_separator);
buf.append(indstr).append("try {").append(new_line_separator);
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true));
buf.append(indstr + "}");
buf.append(indstr).append("}");
for (int i = 1; i < stats.size(); i++) {
List<String> exception_types = exctstrings.get(i - 1);
@@ -174,11 +174,12 @@ public class CatchStatement extends Statement {
VarType exc_type = new VarType(CodeConstants.TYPE_OBJECT, 0, exception_types.get(exc_index));
String exc_type_name = ExprProcessor.getCastTypeName(exc_type);
buf.append(exc_type_name + " | ");
buf.append(exc_type_name).append(" | ");
}
}
buf.append(vars.get(i - 1).toJava(indent));
buf.append(") {" + new_line_separator + ExprProcessor.jmpWrapper(stats.get(i), indent + 1, true) + indstr + "}");
buf.append(") {").append(new_line_separator).append(ExprProcessor.jmpWrapper(stats.get(i), indent + 1, true)).append(indstr)
.append("}");
}
buf.append(new_line_separator);

View File

@@ -93,37 +93,38 @@ public class DoStatement extends Statement {
public String toJava(int indent) {
String indstr = InterpreterUtil.getIndentString(indent);
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
String new_line_separator = DecompilerContext.getNewLineSeparator();
buf.append(ExprProcessor.listToJava(varDefinitions, indent));
if (isLabeled()) {
buf.append(indstr + "label" + this.id + ":" + new_line_separator);
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
}
switch (looptype) {
case LOOP_DO:
buf.append(indstr + "while(true) {" + new_line_separator);
buf.append(indstr).append("while(true) {").append(new_line_separator);
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true));
buf.append(indstr + "}" + new_line_separator);
buf.append(indstr).append("}").append(new_line_separator);
break;
case LOOP_DOWHILE:
buf.append(indstr + "do {" + new_line_separator);
buf.append(indstr).append("do {").append(new_line_separator);
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true));
buf.append(indstr + "} while(" + conditionExprent.get(0).toJava(indent) + ");" + new_line_separator);
buf.append(indstr).append("} while(").append(conditionExprent.get(0).toJava(indent)).append(");").append(new_line_separator);
break;
case LOOP_WHILE:
buf.append(indstr + "while(" + conditionExprent.get(0).toJava(indent) + ") {" + new_line_separator);
buf.append(indstr).append("while(").append(conditionExprent.get(0).toJava(indent)).append(") {").append(new_line_separator);
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true));
buf.append(indstr + "}" + new_line_separator);
buf.append(indstr).append("}").append(new_line_separator);
break;
case LOOP_FOR:
buf.append(indstr + "for(" + (initExprent.get(0) == null ? "" : initExprent.get(0).toJava(indent)) +
"; " + conditionExprent.get(0).toJava(indent) + "; " + incExprent.get(0).toJava(indent) + ") {" + new_line_separator);
buf.append(indstr).append("for(").append(initExprent.get(0) == null ? "" : initExprent.get(0).toJava(indent)).append("; ")
.append(conditionExprent.get(0).toJava(indent)).append("; ").append(incExprent.get(0).toJava(indent)).append(") {")
.append(new_line_separator);
buf.append(ExprProcessor.jmpWrapper(first, indent + 1, true));
buf.append(indstr + "}" + new_line_separator);
buf.append(indstr).append("}").append(new_line_separator);
}
return buf.toString();

View File

@@ -55,19 +55,19 @@ public class GeneralStatement extends Statement {
public String toJava(int indent) {
String indstr = InterpreterUtil.getIndentString(indent);
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
String new_line_separator = DecompilerContext.getNewLineSeparator();
if (isLabeled()) {
buf.append(indstr + "label" + this.id + ":" + new_line_separator);
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
}
buf.append(indstr + "abstract statement {" + new_line_separator);
buf.append(indstr).append("abstract statement {").append(new_line_separator);
for (int i = 0; i < stats.size(); i++) {
buf.append(stats.get(i).toJava(indent + 1));
}
buf.append(indstr + "}");
buf.append(indstr).append("}");
return buf.toString();
}

View File

@@ -201,7 +201,7 @@ public class IfStatement extends Statement {
public String toJava(int indent) {
String indstr = InterpreterUtil.getIndentString(indent);
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
String new_line_separator = DecompilerContext.getNewLineSeparator();
@@ -209,10 +209,10 @@ public class IfStatement extends Statement {
buf.append(first.toJava(indent));
if (isLabeled()) {
buf.append(indstr + "label" + this.id + ":" + new_line_separator);
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
}
buf.append(indstr + headexprent.get(0).toJava(indent) + " {" + new_line_separator);
buf.append(indstr).append(headexprent.get(0).toJava(indent)).append(" {").append(new_line_separator);
if (ifstat == null) {
buf.append(InterpreterUtil.getIndentString(indent + 1));
@@ -228,10 +228,10 @@ public class IfStatement extends Statement {
}
if (ifedge.labeled) {
buf.append(" label" + ifedge.closure.id);
buf.append(" label").append(ifedge.closure.id);
}
}
buf.append(";" + new_line_separator);
buf.append(";").append(new_line_separator);
}
else {
buf.append(ExprProcessor.jmpWrapper(ifstat, indent + 1, true));
@@ -248,7 +248,7 @@ public class IfStatement extends Statement {
String content = ExprProcessor.jmpWrapper(elsestat, indent, false);
content = content.substring(indstr.length());
buf.append(indstr + "} else ");
buf.append(indstr).append("} else ");
buf.append(content);
elseif = true;
@@ -257,14 +257,14 @@ public class IfStatement extends Statement {
String content = ExprProcessor.jmpWrapper(elsestat, indent + 1, false);
if (content.length() > 0) {
buf.append(indstr + "} else {" + new_line_separator);
buf.append(indstr).append("} else {").append(new_line_separator);
buf.append(content);
}
}
}
if (!elseif) {
buf.append(indstr + "}" + new_line_separator);
buf.append(indstr).append("}").append(new_line_separator);
}
return buf.toString();

View File

@@ -112,7 +112,7 @@ public class SequenceStatement extends Statement {
if (islabeled) {
indstr = InterpreterUtil.getIndentString(indent);
indent++;
buf.append(indstr + "label" + this.id + ": {" + new_line_separator);
buf.append(indstr).append("label").append(this.id).append(": {").append(new_line_separator);
}
boolean notempty = false;
@@ -132,7 +132,7 @@ public class SequenceStatement extends Statement {
}
if (islabeled) {
buf.append(indstr + "}" + new_line_separator);
buf.append(indstr).append("}").append(new_line_separator);
}
return buf.toString();

View File

@@ -126,28 +126,21 @@ public class Statement {
isMonitorEnter = false;
containsMonitorExit = false;
for (Map<Integer, List<StatEdge>> map : new Map[]{mapSuccEdges, mapPredEdges}) {
map.remove(StatEdge.TYPE_EXCEPTION);
processMap(mapSuccEdges);
processMap(mapPredEdges);
processMap(mapSuccStates);
processMap(mapPredStates);
}
List<StatEdge> lst = map.get(STATEDGE_DIRECT_ALL);
if (lst != null) {
map.put(STATEDGE_ALL, new ArrayList<StatEdge>(lst));
}
else {
map.remove(STATEDGE_ALL);
}
private static <T> void processMap(Map<Integer, List<T>> map) {
map.remove(StatEdge.TYPE_EXCEPTION);
List<T> lst = map.get(STATEDGE_DIRECT_ALL);
if (lst != null) {
map.put(STATEDGE_ALL, new ArrayList<T>(lst));
}
for (Map<Integer, List<Statement>> map : new Map[]{mapSuccStates, mapPredStates}) {
map.remove(StatEdge.TYPE_EXCEPTION);
List<Statement> lst = map.get(STATEDGE_DIRECT_ALL);
if (lst != null) {
map.put(STATEDGE_ALL, new ArrayList<Statement>(lst));
}
else {
map.remove(STATEDGE_ALL);
}
else {
map.remove(STATEDGE_ALL);
}
}
@@ -579,7 +572,7 @@ public class Statement {
// private methods
// *****************************************************************************
private void addToReversePostOrderListIterative(Statement root, List<Statement> lst) {
private static void addToReversePostOrderListIterative(Statement root, List<Statement> lst) {
LinkedList<Statement> stackNode = new LinkedList<Statement>();
LinkedList<Integer> stackIndex = new LinkedList<Integer>();
@@ -622,7 +615,7 @@ public class Statement {
}
private void addToPostReversePostOrderList(Statement stat, List<Statement> lst, HashSet<Statement> setVisited) {
private static void addToPostReversePostOrderList(Statement stat, List<Statement> lst, HashSet<Statement> setVisited) {
if (setVisited.contains(stat)) { // because of not considered exception edges, s. isExitComponent. Should be rewritten, if possible.
return;

View File

@@ -117,10 +117,10 @@ public class SwitchStatement extends Statement {
buf.append(first.toJava(indent));
if (isLabeled()) {
buf.append(indstr + "label" + this.id + ":" + new_line_separator);
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
}
buf.append(indstr + headexprent.get(0).toJava(indent) + " {" + new_line_separator);
buf.append(indstr).append(headexprent.get(0).toJava(indent)).append(" {").append(new_line_separator);
VarType switch_type = headexprent.get(0).getExprType();
@@ -132,20 +132,20 @@ public class SwitchStatement extends Statement {
for (int j = 0; j < edges.size(); j++) {
if (edges.get(j) == default_edge) {
buf.append(indstr + "default:" + new_line_separator);
buf.append(indstr).append("default:").append(new_line_separator);
}
else {
ConstExprent value = (ConstExprent)values.get(j).copy();
value.setConsttype(switch_type);
buf.append(indstr + "case " + value.toJava(indent) + ":" + new_line_separator);
buf.append(indstr).append("case ").append(value.toJava(indent)).append(":").append(new_line_separator);
}
}
buf.append(ExprProcessor.jmpWrapper(stat, indent + 1, false));
}
buf.append(indstr + "}" + new_line_separator);
buf.append(indstr).append("}").append(new_line_separator);
return buf.toString();
}

View File

@@ -73,17 +73,17 @@ public class SynchronizedStatement extends Statement {
String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(ExprProcessor.listToJava(varDefinitions, indent));
buf.append(first.toJava(indent));
if (isLabeled()) {
buf.append(indstr + "label" + this.id + ":" + new_line_separator);
buf.append(indstr).append("label").append(this.id).append(":").append(new_line_separator);
}
buf.append(indstr + headexprent.get(0).toJava(indent) + " {" + new_line_separator);
buf.append(indstr).append(headexprent.get(0).toJava(indent)).append(" {").append(new_line_separator);
buf.append(ExprProcessor.jmpWrapper(body, indent + 1, true));
buf.append(indstr + "}" + new_line_separator);
buf.append(indstr).append("}").append(new_line_separator);
return buf.toString();
}

View File

@@ -43,7 +43,7 @@ public class CheckTypesResult {
return lstMinTypeExprents;
}
public class ExprentTypePair {
public static class ExprentTypePair {
public Exprent exprent;
public VarType type;
public VarType desttype;

View File

@@ -125,10 +125,7 @@ public class VarDefinitionHelper {
VarNamesCollector vc = DecompilerContext.getVarncollector();
Iterator<Entry<Integer, Statement>> it = mapVarDefStatements.entrySet().iterator();
while (it.hasNext()) {
Entry<Integer, Statement> en = it.next();
for (Entry<Integer, Statement> en : mapVarDefStatements.entrySet()) {
Statement stat = en.getValue();
Integer index = en.getKey();
@@ -312,9 +309,7 @@ public class VarDefinitionHelper {
HashSet<Integer> set = new HashSet<Integer>(mapCount.keySet());
// put all variables defined in this statement into the set
Iterator<Entry<Integer, Integer>> itMult = mapCount.entrySet().iterator();
while (itMult.hasNext()) {
Entry<Integer, Integer> en = itMult.next();
for (Entry<Integer, Integer> en : mapCount.entrySet()) {
if (en.getValue().intValue() > 1) {
mapVarDefStatements.put(en.getKey(), stat);
}
@@ -325,7 +320,7 @@ public class VarDefinitionHelper {
return set;
}
private List<VarExprent> getAllVars(List<Exprent> lst) {
private static List<VarExprent> getAllVars(List<Exprent> lst) {
List<VarExprent> res = new ArrayList<VarExprent>();
List<Exprent> listTemp = new ArrayList<Exprent>();
@@ -344,7 +339,7 @@ public class VarDefinitionHelper {
return res;
}
private boolean setDefinition(Exprent expr, Integer index) {
private static boolean setDefinition(Exprent expr, Integer index) {
if (expr.type == Exprent.EXPRENT_ASSIGNMENT) {
Exprent left = ((AssignmentExprent)expr).getLeft();
if (left.type == Exprent.EXPRENT_VAR) {

View File

@@ -102,7 +102,7 @@ public class VarTypeProcessor {
while (!processVarTypes(dgraph)) ;
}
private void resetExprentTypes(DirectGraph dgraph) {
private static void resetExprentTypes(DirectGraph dgraph) {
dgraph.iterateExprents(new DirectGraph.ExprentIterator() {
public int processExprent(Exprent exprent) {

View File

@@ -106,7 +106,7 @@ public class VarVersionsGraph {
engine.initialize();
}
private LinkedList<VarVersionNode> getReversedPostOrder(Collection<VarVersionNode> roots) {
private static LinkedList<VarVersionNode> getReversedPostOrder(Collection<VarVersionNode> roots) {
LinkedList<VarVersionNode> lst = new LinkedList<VarVersionNode>();
HashSet<VarVersionNode> setVisited = new HashSet<VarVersionNode>();
@@ -122,7 +122,7 @@ public class VarVersionsGraph {
return lst;
}
private void addToReversePostOrderListIterative(VarVersionNode root, List<VarVersionNode> lst, HashSet<VarVersionNode> setVisited) {
private static void addToReversePostOrderListIterative(VarVersionNode root, List<VarVersionNode> lst, HashSet<VarVersionNode> setVisited) {
HashMap<VarVersionNode, List<VarVersionEdge>> mapNodeSuccs = new HashMap<VarVersionNode, List<VarVersionEdge>>();

View File

@@ -66,7 +66,7 @@ public class VarVersionsProcessor {
setNewVarIndices(typeproc, dgraph);
}
private void mergePhiVersions(SSAConstructorSparseEx ssa, DirectGraph dgraph) {
private static void mergePhiVersions(SSAConstructorSparseEx ssa, DirectGraph dgraph) {
// collect phi versions
List<HashSet<VarVersionPaar>> lst = new ArrayList<HashSet<VarVersionPaar>>();
@@ -125,7 +125,7 @@ public class VarVersionsProcessor {
});
}
private void eliminateNonJavaTypes(VarTypeProcessor typeproc) {
private static void eliminateNonJavaTypes(VarTypeProcessor typeproc) {
HashMap<VarVersionPaar, VarType> mapExprentMaxTypes = typeproc.getMapExprentMaxTypes();
HashMap<VarVersionPaar, VarType> mapExprentMinTypes = typeproc.getMapExprentMinTypes();
@@ -152,7 +152,7 @@ public class VarVersionsProcessor {
}
}
private void simpleMerge(VarTypeProcessor typeproc, DirectGraph dgraph, StructMethod mt) {
private static void simpleMerge(VarTypeProcessor typeproc, DirectGraph dgraph, StructMethod mt) {
HashMap<VarVersionPaar, VarType> mapExprentMaxTypes = typeproc.getMapExprentMaxTypes();
HashMap<VarVersionPaar, VarType> mapExprentMinTypes = typeproc.getMapExprentMinTypes();

View File

@@ -193,11 +193,12 @@ public class IdentifierConverter {
}
String classOldFullName = cl.qualifiedName;
String classNewFullName = classOldFullName;
// TODO: rename packages
String clsimplename = ConverterHelper.getSimpleClassName(classOldFullName);
if (helper.toBeRenamed(IIdentifierRenamer.ELEMENT_CLASS, clsimplename, null, null)) {
String classNewFullName;
do {
classNewFullName = ConverterHelper.replaceSimpleClassName(classOldFullName,
helper.getNextClassname(classOldFullName, ConverterHelper
@@ -339,7 +340,7 @@ public class IdentifierConverter {
return descriptor;
}
private List<ClassWrapperNode> getReversePostOrderListIterative(List<ClassWrapperNode> roots) {
private static List<ClassWrapperNode> getReversePostOrderListIterative(List<ClassWrapperNode> roots) {
List<ClassWrapperNode> res = new ArrayList<ClassWrapperNode>();