Skip to content

Commit

Permalink
merge 0.0.9.x to default
Browse files Browse the repository at this point in the history
  • Loading branch information
bob committed Feb 3, 2013
2 parents b187a5b + 0cb80cf commit 7ac97b4
Show file tree
Hide file tree
Showing 246 changed files with 604 additions and 159 deletions.
Empty file modified .hgignore
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion commons-lite/pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>1.1</version>
</parent>
<artifactId>commons-lite</artifactId>
<version>1.13</version>
<version>1.14</version>
<name>Dex Commons Lite</name>
<description>A lightweight implementation of commons-io and commons-codec</description>
</project>
Empty file.
Empty file.
Empty file.
Empty file modified commons-lite/src/main/java/org/apache/commons/io/FileUtils.java
100644 → 100755
Empty file.
Empty file.
Empty file modified commons-lite/src/main/java/org/apache/commons/io/IOUtils.java
100644 → 100755
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion dex-ir/pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>1.1</version>
</parent>
<artifactId>dex-ir</artifactId>
<version>1.10</version>
<version>1.11</version>
<name>Dex Instruction Representation</name>
<dependencies>
<dependency>
Expand Down
Empty file modified dex-ir/src/main/java/com/googlecode/dex2jar/ir/Constant.java
100644 → 100755
Empty file.
Empty file modified dex-ir/src/main/java/com/googlecode/dex2jar/ir/ET.java
100644 → 100755
Empty file.
Empty file modified dex-ir/src/main/java/com/googlecode/dex2jar/ir/IrMethod.java
100644 → 100755
Empty file.
Empty file modified dex-ir/src/main/java/com/googlecode/dex2jar/ir/Local.java
100644 → 100755
Empty file.
Empty file modified dex-ir/src/main/java/com/googlecode/dex2jar/ir/LocalVar.java
100644 → 100755
Empty file.
Empty file.
29 changes: 20 additions & 9 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/Trap.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,40 @@
* @version $Rev$
*/
public class Trap {
public LabelStmt start, end, handler;
public Type type;
public LabelStmt start, end, handlers[];
public Type types[];

public Trap() {
super();
}

public Trap(LabelStmt start, LabelStmt end, LabelStmt handler, Type type) {
public Trap(LabelStmt start, LabelStmt end, LabelStmt handlers[], Type types[]) {
super();
this.start = start;
this.end = end;
this.handler = handler;
this.type = type;
this.handlers = handlers;
this.types = types;
}

public Trap clone(Map<LabelStmt, LabelStmt> map) {
return new Trap(start.clone(map), end.clone(map), handler.clone(map), type);
int size = handlers.length;
LabelStmt[] cloneHandlers = new LabelStmt[size];
Type[] cloneTypes = new Type[size];
for (int i = 0; i < size; i++) {
cloneHandlers[i] = handlers[i].clone(map);
cloneTypes[i] = types[i];
}
return new Trap(start.clone(map), end.clone(map), cloneHandlers, cloneTypes);
}

@Override
public String toString() {
return String.format(".catch %s - %s > %s // %s", start.getDisplayName(), end.getDisplayName(), handler.getDisplayName(),
type == null ? "all" : ToStringUtil.toShortClassName(type));
StringBuilder sb = new StringBuilder(String.format(".catch %s - %s : ", start.getDisplayName(),
end.getDisplayName()));
for (int i = 0; i < handlers.length; i++) {
sb.append(types[i] == null ? "all" : types[i]).append(" > ").append(handlers[i].getDisplayName())
.append(",");
}
return sb.toString();
}

}
Empty file modified dex-ir/src/main/java/com/googlecode/dex2jar/ir/Value.java
100644 → 100755
Empty file.
Empty file modified dex-ir/src/main/java/com/googlecode/dex2jar/ir/ValueBox.java
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/Exprs.java
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* dex2jar - Tools to work with android .dex and java .class files
* Copyright (c) 2009-2012 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.googlecode.dex2jar.ir.stmt;

import com.googlecode.dex2jar.ir.ValueBox;
import com.googlecode.dex2jar.ir.stmt.Stmt.E1Stmt;

/**
* Parent class of {@link LookupSwitchStmt} and {@link TableSwitchStmt}
*
* @author <a href="mailto:[email protected]">Panxiaobo</a>
*
*/
public abstract class BaseSwitchStmt extends E1Stmt {
public BaseSwitchStmt(ST type, ValueBox op) {
super(type, op);
}

public LabelStmt[] targets;
public LabelStmt defaultTarget;
}
Empty file.
Empty file.
7 changes: 2 additions & 5 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/LookupSwitchStmt.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,18 @@
import java.util.Map;

import com.googlecode.dex2jar.ir.ValueBox;
import com.googlecode.dex2jar.ir.stmt.Stmt.E1Stmt;

/**
* Represent a LOOKUP_SWITCH statement
*
* @see ST#LOOKUP_SWITCH
*
* @author <a href="mailto:[email protected]">Panxiaobo</a>
* @version $Rev$
* @version $Rev: 9fd8005bbaa4 $
*/
public class LookupSwitchStmt extends E1Stmt {
public class LookupSwitchStmt extends BaseSwitchStmt {

public LabelStmt defaultTarget;
public int[] lookupValues;
public LabelStmt[] targets;

public LookupSwitchStmt(ValueBox key, int[] lookupValues, LabelStmt[] targets, LabelStmt defaultTarget) {
super(ST.LOOKUP_SWITCH, key);
Expand Down
Empty file.
Empty file.
Empty file.
Empty file modified dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/Stmts.java
100644 → 100755
Empty file.
7 changes: 2 additions & 5 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/TableSwitchStmt.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@

import com.googlecode.dex2jar.ir.Value;
import com.googlecode.dex2jar.ir.ValueBox;
import com.googlecode.dex2jar.ir.stmt.Stmt.E1Stmt;

/**
* Represent a TABLE_SWITCH statement
*
* @see ST#TABLE_SWITCH
*
* @author <a href="mailto:[email protected]">Panxiaobo</a>
* @version $Rev$
* @version $Rev: 9fd8005bbaa4 $
*/
public class TableSwitchStmt extends E1Stmt {
public class TableSwitchStmt extends BaseSwitchStmt {

public LabelStmt defaultTarget;
public int lowIndex, highIndex;
public LabelStmt[] targets;

public TableSwitchStmt() {
super(ST.TABLE_SWITCH, null);
Expand Down
Empty file.
Empty file.
30 changes: 16 additions & 14 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/BaseLiveAnalyze.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;

import com.googlecode.dex2jar.ir.IrMethod;
Expand Down Expand Up @@ -48,18 +50,6 @@ public String toString() {
}
}

private static void doAddUsed(Phi r, Set<Phi> regs) {
if (r.used) {
if (!regs.contains(r)) {
regs.add(r);
for (Phi p : r.parents) {
p.used = true;
doAddUsed(p, regs);
}
}
}
}

protected int localSize;
protected IrMethod method;

Expand Down Expand Up @@ -142,8 +132,20 @@ protected Phi newPhi() {

protected Set<Phi> markUsed() {
Set<Phi> used = new HashSet<Phi>(phis.size() / 2);
for (Phi reg : phis) {
doAddUsed(reg, used);
Queue<Phi> q = new LinkedList<Phi>();
q.addAll(phis);
while (!q.isEmpty()) {
Phi v = q.poll();
if (v.used) {
if (used.contains(v)) {
continue;
}
used.add(v);
for (Phi p : v.parents) {
p.used = true;
q.add(p);
}
}
}
phis.clear();
phis.addAll(used);
Expand Down
8 changes: 6 additions & 2 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/Cfg.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ public static void createCfgForLiveAnalyze(IrMethod jm) {

for (Trap t : jm.traps) {
for (Stmt s = t.start; s != t.end; s = s.getNext()) {
link(s, t.handler);
for (LabelStmt handler : t.handlers) {
link(s, handler);
}
}
}

Expand Down Expand Up @@ -205,7 +207,9 @@ public static void createCFG(IrMethod jm) {
// 3 c=(string)b
// 0 - 2 > 2
// 如果1语句出错,则或使用0的frame到2去执行
link(s.getPre(), t.handler);
for (LabelStmt handler : t.handlers) {
link(s.getPre(), handler);
}
}
}
}
Expand Down
100 changes: 100 additions & 0 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/CleanLabel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* dex2jar - Tools to work with android .dex and java .class files
* Copyright (c) 2009-2012 Panxiaobo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.googlecode.dex2jar.ir.ts;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.googlecode.dex2jar.ir.IrMethod;
import com.googlecode.dex2jar.ir.LocalVar;
import com.googlecode.dex2jar.ir.Trap;
import com.googlecode.dex2jar.ir.stmt.BaseSwitchStmt;
import com.googlecode.dex2jar.ir.stmt.JumpStmt;
import com.googlecode.dex2jar.ir.stmt.LabelStmt;
import com.googlecode.dex2jar.ir.stmt.Stmt;
import com.googlecode.dex2jar.ir.stmt.StmtList;
import com.googlecode.dex2jar.ir.stmt.Stmt.ST;

/**
* Clean unused {@link LabelStmt}
*
* @author <a href="mailto:[email protected]">Panxiaobo</a>
*
*/
public class CleanLabel implements Transformer {

@Override
public void transform(IrMethod irMethod) {
Set<LabelStmt> uselabels = new HashSet<LabelStmt>();
addTrap(irMethod.traps, uselabels);
addVars(irMethod.vars, uselabels);
addStmt(irMethod.stmts, uselabels);
rmUnused(irMethod.stmts, uselabels);
}

private void addVars(List<LocalVar> vars, Set<LabelStmt> uselabels) {
if (vars != null) {
for (LocalVar var : vars) {
uselabels.add(var.start);
uselabels.add(var.end);
}
}

}

private void rmUnused(StmtList stmts, Set<LabelStmt> uselabels) {
for (Stmt p = stmts.getFirst(); p != null;) {
if (p.st == ST.LABEL) {
if (!uselabels.contains(p)) {
Stmt q = p.getNext();
stmts.remove(p);
p = q;
continue;
}
}
p = p.getNext();
}
}

private void addStmt(StmtList stmts, Set<LabelStmt> labels) {
for (Stmt p = stmts.getFirst(); p != null; p = p.getNext()) {
if (p instanceof JumpStmt) {
labels.add(((JumpStmt) p).target);
} else if (p instanceof BaseSwitchStmt) {
BaseSwitchStmt stmt = (BaseSwitchStmt) p;
labels.add(stmt.defaultTarget);
for (LabelStmt t : stmt.targets) {
labels.add(t);
}
}
}
}

private void addTrap(List<Trap> traps, Set<LabelStmt> labels) {
if (traps != null) {
for (Trap trap : traps) {
labels.add(trap.start);
labels.add(trap.end);
for (LabelStmt h : trap.handlers) {
labels.add(h);
}
}
}
}

}
15 changes: 15 additions & 0 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/EndRemover.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* <ol>
* <li>Move {@link Stmt}s outside a {@link Trap} if {@link Stmt}s are not throw</li>
* <li>Remove {@link Trap} if all {@link Stmt}s are not throw</li>
* <li>...;GOTO L2; ... ; L2: ; return; => ...;return ; ... ; L2: ; return;</li>
* </ol>
*
* @author bob
Expand Down Expand Up @@ -186,6 +187,20 @@ public void transform(IrMethod irMethod) {
irMethod.traps.remove(trap);
}
}
StmtList stmts = irMethod.stmts;
for (Stmt p = stmts.getFirst(); p != null; p = p.getNext()) {
if (p.st == ST.GOTO) {
LabelStmt target = ((JumpStmt) p).target;
Stmt next = target.getNext();
if (next != null && (next.st == ST.RETURN || next.st == ST.RETURN_VOID)) {
Stmt nnext = next.clone(null);
stmts.insertAfter(p, nnext);
stmts.remove(p);
p = nnext;
}
}
}

}

private void move4Label(StmtList stmts, LabelStmt start, Stmt end, LabelStmt label) {
Expand Down
Loading

0 comments on commit 7ac97b4

Please sign in to comment.