format code

This commit is contained in:
honfika@gmail.com
2014-09-07 22:27:39 +02:00
parent 8ae999a617
commit c9907ef4d1
24 changed files with 177 additions and 186 deletions

View File

@@ -23,6 +23,8 @@ package com.jpexs.decompiler.flash;
public interface DisassemblyListener {
public void progressReading(long pos, long total);
public void progressToString(long pos, long total);
public void progressDeobfuscating(long pos, long total);
}

View File

@@ -573,7 +573,7 @@ public final class SWF implements TreeItem, Timelined {
assignClassesToSymbols();
findFileAttributes();
findABCTags();
SWFDecompilerPlugin.fireSwfParsed(this);
} else {
boolean hasNonUnknownTag = false;
@@ -1188,7 +1188,7 @@ public final class SWF implements TreeItem, Timelined {
getASMs("", list, asms);
return asms;
}
private static void getASMs(String path, List<TreeNode> nodes, Map<String, ASMSource> result) {
for (TreeNode n : nodes) {
String subPath = path + "/" + n.toString();
@@ -1206,7 +1206,7 @@ public final class SWF implements TreeItem, Timelined {
getASMs(subPath, n.subNodes, result);
}
}
public static void getTagsFromTreeNodes(List<TreeNode> treeNodes, List<Tag> result) {
for (TreeNode treeNode : treeNodes) {
TreeItem treeItem = treeNode.getItem();

View File

@@ -572,7 +572,7 @@ public class ABC {
System.out.println(""+t.toString());
}
System.exit(0);*/
SWFDecompilerPlugin.fireAbcParsed(this, swf);
}
@@ -1178,7 +1178,7 @@ public class ABC {
pack(); //removes old classes/methods
((Tag) parentTag).setModified(true);
}
public void pack() {
for (int c = 0; c < instance_info.size(); c++) {
if (instance_info.get(c).deleted) {

View File

@@ -854,7 +854,7 @@ public class AVM2Code implements Cloneable {
ais.endDumpLevelUntil(diParent);
}
}
code.addAll(codeMap.values());
}

View File

@@ -95,7 +95,7 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem {
public String toString() {
StringBuilder s = new StringBuilder();
s.append(definition.instructionName);
if (operands != null) {
if (operands != null) {
for (int i = 0; i < operands.length; i++) {
s.append(" ");
s.append(operands[i]);

View File

@@ -1619,7 +1619,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
mbody.method_info = abc.addMethodInfo(mi);
mi.setBody(mbody);
List<AVM2Instruction> mbodyCode = toInsList(src);
List<AVM2Instruction> mbodyCode = toInsList(src);
mbody.setCode(new AVM2Code());
mbody.getCode().code = mbodyCode;

View File

@@ -101,7 +101,6 @@ public abstract class AssignableAVM2Item extends AVM2Item {
ret.add(ins(new KillIns(), register.getVal()));
return ret;
}*/
public static List<GraphSourceItem> killTemp(SourceGeneratorLocalData localData, SourceGenerator generator, List<Reference<Integer>> registers) {
List<GraphSourceItem> ret = new ArrayList<>();
for (Reference<Integer> register : registers) {

View File

@@ -758,7 +758,8 @@ public final class MethodInfoLexer {
*
* @return the next token
* @exception java.io.IOException if any I/O-Error occurs
* @throws com.jpexs.decompiler.flash.abc.methodinfo_parser.MethodInfoParseException
* @throws
* com.jpexs.decompiler.flash.abc.methodinfo_parser.MethodInfoParseException
*/
public ParsedSymbol yylex() throws java.io.IOException, MethodInfoParseException {
int zzInput;

View File

@@ -76,11 +76,11 @@ public class MethodBody implements Cloneable {
}
return code;
}
public void setCode(AVM2Code code) {
this.code = code;
}
public List<Integer> getExceptionEntries() {
List<Integer> ret = new ArrayList<>();
for (ABCException e : exceptions) {

View File

@@ -139,8 +139,7 @@ public class ActionList extends ArrayList<Action> {
}
@Override
public void remove()
{
public void remove() {
throw new UnsupportedOperationException();
}
};

View File

@@ -102,18 +102,18 @@ public class Matrix {
public Point transform(Point point) {
return transform(point.x, point.y);
}
public Point deltaTransform(double x, double y){
public Point deltaTransform(double x, double y) {
Point result = new Point(
scaleX * x + rotateSkew1 * y,
rotateSkew0 * x + scaleY * y);
return result;
}
public Point deltaTransform(Point point) {
return deltaTransform(point.x, point.y);
}
public java.awt.Point deltaTransform(java.awt.Point point) {
Point p = deltaTransform(point.x, point.y);
return new java.awt.Point((int) p.x, (int) p.y);
@@ -245,48 +245,47 @@ public class Matrix {
public String toString() {
return "[Matrix scale:" + scaleX + "," + scaleY + ", rotate:" + rotateSkew0 + "," + rotateSkew1 + ", translate:" + translateX + "," + translateY + "]";
}
public Matrix inverse(Matrix m){
double a=m.scaleX;
double b=m.rotateSkew0;
double c=m.rotateSkew1;
double d=m.scaleY;
double tx=m.translateX;
double ty=m.translateY;
double a2=d/(a*d-b*c);
double b2=-b/(a*d-b*c);
double c2=-c/(a*d-b*c);
double d2=a*(a*d-b*c);
double tx2=(c*ty-d*tx)/(a*d-b*c);
double ty2=-(a*ty-b*tx)/(a*d-b*c);
Matrix ret=new Matrix();
ret.scaleX = a2;
ret.rotateSkew0 = b2;
ret.rotateSkew1 = c2;
ret.scaleY = d2;
ret.translateX = tx2;
ret.translateY = ty2;
return ret;
public Matrix inverse(Matrix m) {
double a = m.scaleX;
double b = m.rotateSkew0;
double c = m.rotateSkew1;
double d = m.scaleY;
double tx = m.translateX;
double ty = m.translateY;
double a2 = d / (a * d - b * c);
double b2 = -b / (a * d - b * c);
double c2 = -c / (a * d - b * c);
double d2 = a * (a * d - b * c);
double tx2 = (c * ty - d * tx) / (a * d - b * c);
double ty2 = -(a * ty - b * tx) / (a * d - b * c);
Matrix ret = new Matrix();
ret.scaleX = a2;
ret.rotateSkew0 = b2;
ret.rotateSkew1 = c2;
ret.scaleY = d2;
ret.translateX = tx2;
ret.translateY = ty2;
return ret;
}
public double getTotalSkewAngleX(){
Point px = deltaTransform(new Point(0,1));
return ((180/Math.PI) * Math.atan2(px.y, px.x) - 90);
public double getTotalSkewAngleX() {
Point px = deltaTransform(new Point(0, 1));
return ((180 / Math.PI) * Math.atan2(px.y, px.x) - 90);
}
public double getTotalSkewAngleY(){
Point py = deltaTransform(new Point(1,0));
return ((180/Math.PI) * Math.atan2(py.y, py.x));
public double getTotalSkewAngleY() {
Point py = deltaTransform(new Point(1, 0));
return ((180 / Math.PI) * Math.atan2(py.y, py.x));
}
public double getTotalScaleX(){
public double getTotalScaleX() {
return Math.sqrt(scaleX * scaleX + rotateSkew0 * rotateSkew0);
}
public double getTotalScaleY(){
public double getTotalScaleY() {
return Math.sqrt(rotateSkew1 * rotateSkew1 + scaleY * scaleY);
}
}

View File

@@ -34,6 +34,6 @@ public interface SWFDecompilerListener {
void actionListParsed(ActionList actions, SWF swf);
void abcParsed(ABC abc, SWF swf);
void methodBodyParsed(MethodBody body, SWF swf);
}

View File

@@ -79,7 +79,7 @@ public class SWFDecompilerPlugin {
logger.log(Level.SEVERE, null, ex);
}
}
public static byte[] fireProxyFileCatched(byte[] data) {
byte[] result = null;
for (SWFDecompilerListener listener : listeners) {

View File

@@ -28,7 +28,7 @@ import java.io.IOException;
* @author JPEXS
*/
public class ImageImporter extends TagImporter {
public Tag importImage(ImageTag it, byte[] newData) throws IOException {
if (it instanceof DefineBitsTag) {
SWF swf = it.getSwf();

View File

@@ -14,7 +14,6 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.importers;
/**

View File

@@ -37,7 +37,7 @@ import java.util.List;
* @author JPEXS
*/
public class DefineFontTag extends FontTag {
@SWFType(BasicType.UI16)
public int fontId;
public List<SHAPE> glyphShapeTable;
@@ -46,22 +46,22 @@ public class DefineFontTag extends FontTag {
@Internal
private DefineFontInfo2Tag fontInfo2Tag = null;
public static final int ID = 10;
@Override
public boolean isSmall() {
return false;
}
@Override
public double getGlyphAdvance(int glyphIndex) {
return -1;
}
@Override
public int getGlyphWidth(int glyphIndex) {
return glyphShapeTable.get(glyphIndex).getBounds().getWidth();
}
private void ensureFontInfo() {
if (fontInfoTag == null) {
for (Tag t : swf.tags) {
@@ -80,7 +80,7 @@ public class DefineFontTag extends FontTag {
}
}
}
@Override
public char glyphToChar(int glyphIndex) {
ensureFontInfo();
@@ -92,7 +92,7 @@ public class DefineFontTag extends FontTag {
return '?';
}
}
@Override
public int charToGlyph(char c) {
ensureFontInfo();
@@ -102,7 +102,7 @@ public class DefineFontTag extends FontTag {
return fontInfoTag.codeTable.indexOf((int) c);
}
return -1;
}
/**
@@ -147,7 +147,7 @@ public class DefineFontTag extends FontTag {
int firstOffset = sis.readUI16("firstOffset");
int nGlyphs = firstOffset / 2;
glyphShapeTable = new ArrayList<>();
for (int i = 1; i < nGlyphs; i++) {
sis.readUI16("offset"); //offset
}
@@ -155,22 +155,22 @@ public class DefineFontTag extends FontTag {
glyphShapeTable.add(sis.readSHAPE(1, false, "shape"));
}
}
@Override
public int getFontId() {
return fontId;
}
@Override
public List<SHAPE> getGlyphShapeTable() {
return glyphShapeTable;
}
@Override
public int getCharacterId() {
return fontId;
}
@Override
public String getFontName() {
ensureFontInfo();
@@ -182,7 +182,7 @@ public class DefineFontTag extends FontTag {
}
return null;
}
@Override
public boolean isBold() {
if (fontInfo2Tag != null) {
@@ -193,7 +193,7 @@ public class DefineFontTag extends FontTag {
}
return false;
}
@Override
public boolean isItalic() {
if (fontInfo2Tag != null) {
@@ -204,26 +204,26 @@ public class DefineFontTag extends FontTag {
}
return false;
}
@Override
public boolean isSmallEditable() {
return false;
}
@Override
public boolean isBoldEditable() {
return fontInfo2Tag != null || fontInfoTag != null;
}
@Override
public boolean isItalicEditable() {
return fontInfo2Tag != null || fontInfoTag != null;
}
@Override
public void setSmall(boolean value) {
}
@Override
public void setBold(boolean value) {
if (fontInfo2Tag != null) {
@@ -233,7 +233,7 @@ public class DefineFontTag extends FontTag {
fontInfoTag.fontFlagsBold = value;
}
}
@Override
public void setItalic(boolean value) {
if (fontInfo2Tag != null) {
@@ -243,27 +243,27 @@ public class DefineFontTag extends FontTag {
fontInfoTag.fontFlagsItalic = value;
}
}
@Override
public int getAscent() {
return -1;
}
@Override
public int getDescent() {
return -1;
}
@Override
public int getLeading() {
return -1;
}
@Override
public int getDivider() {
return 1;
}
@Override
public void addCharacter(char character, String fontName) {
SHAPE shp = SHAPERECORD.systemFontCharacterToSHAPE(fontName, getFontStyle(), getDivider() * 1024, character);
@@ -297,10 +297,10 @@ public class DefineFontTag extends FontTag {
} else {
glyphShapeTable.set(pos, shp);
}
setModified(true);
}
@Override
public String getCharacters(List<Tag> tags) {
String ret = "";
@@ -317,7 +317,7 @@ public class DefineFontTag extends FontTag {
}
return ret;
}
@Override
public int getGlyphKerningAdjustment(int glyphIndex, int nextGlyphIndex) {
return 0;

View File

@@ -58,7 +58,7 @@ public class Timeline {
public RECT displayRect;
public int frameRate;
public List<Tag> tags;
public Map<Integer,Integer> depthMaxFrame = new HashMap<>();
public Map<Integer, Integer> depthMaxFrame = new HashMap<>();
public int getMaxDepth() {
int max_depth = 0;
@@ -191,10 +191,10 @@ public class Timeline {
frames.add(frame);
}
detectTweens();
for(int d=1;d<=getMaxDepth();d++){
for(int f=frames.size()-1;f>=0;f--){
if(frames.get(f).layers.get(d) != null){
depthMaxFrame.put(d, f+1);
for (int d = 1; d <= getMaxDepth(); d++) {
for (int f = frames.size() - 1; f >= 0; f--) {
if (frames.get(f).layers.get(d) != null) {
depthMaxFrame.put(d, f + 1);
break;
}
}
@@ -202,7 +202,7 @@ public class Timeline {
}
private boolean compare(int a, int b, int c, int tolerance) {
return Math.abs((b - a) - (c - b))<tolerance;
return Math.abs((b - a) - (c - b)) < tolerance;
}
private void detectTweens() {
@@ -210,29 +210,29 @@ public class Timeline {
int characterId = -1;
int len = 0;
for (int f = 0; f <= frames.size(); f++) {
DepthState ds = f>=frames.size()?null:frames.get(f).layers.get(d);
if(f<frames.size() && ds!=null && ds.characterId == characterId && ds.characterId!=-1){
DepthState ds = f >= frames.size() ? null : frames.get(f).layers.get(d);
if (f < frames.size() && ds != null && ds.characterId == characterId && ds.characterId != -1) {
len++;
}else{
if(characterId!=-1){
List<MATRIX> matrices=new ArrayList<>();
for(int k=0;k<len;k++){
matrices.add(frames.get(f-len+k).layers.get(d).matrix);
} else {
if (characterId != -1) {
List<MATRIX> matrices = new ArrayList<>();
for (int k = 0; k < len; k++) {
matrices.add(frames.get(f - len + k).layers.get(d).matrix);
}
List<TweenRange> ranges=TweenDetector.detectRanges(matrices);
for(TweenRange r:ranges){
System.out.println(""+r);
for(int t = r.startPosition;t<=r.endPosition;t++){
frames.get(f-len+t).layers.get(d).motionTween = true;
frames.get(f-len+t).layers.get(d).key = false;
List<TweenRange> ranges = TweenDetector.detectRanges(matrices);
for (TweenRange r : ranges) {
System.out.println("" + r);
for (int t = r.startPosition; t <= r.endPosition; t++) {
frames.get(f - len + t).layers.get(d).motionTween = true;
frames.get(f - len + t).layers.get(d).key = false;
}
frames.get(r.startPosition).layers.get(d).key = true;
}
}
len = 1;
}
characterId = ds==null?-1:ds.characterId;
characterId = ds == null ? -1 : ds.characterId;
}
}
}

View File

@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.timeline;
import com.jpexs.decompiler.flash.types.MATRIX;
@@ -22,67 +21,66 @@ import java.util.ArrayList;
import java.util.List;
/**
*
*
* NOT WORKING STUB!!! FIXME
*
* @author JPEXS
*/
public class TweenDetector {
public static List<TweenRange> detectRanges(List<MATRIX> matrices) {
//TODO: make this working :-(
return new ArrayList<>();
/*
List<TweenRange> ret = new ArrayList<>();
double tolerance = 1;
int min = 3;
int startpos = 0;
Double last = null;
int i = min;
List<Double> translateX=new ArrayList<>();
List<Double> translateY=new ArrayList<>();
List<Double> scaleX=new ArrayList<>();
List<Double> scaleY=new ArrayList<>();
List<Double> rotateSkew0=new ArrayList<>();
List<Double> rotateSkew1=new ArrayList<>();
List<TweenRange> ret = new ArrayList<>();
double tolerance = 1;
int min = 3;
int startpos = 0;
Double last = null;
int i = min;
List<Double> translateX=new ArrayList<>();
List<Double> translateY=new ArrayList<>();
List<Double> scaleX=new ArrayList<>();
List<Double> scaleY=new ArrayList<>();
List<Double> rotateSkew0=new ArrayList<>();
List<Double> rotateSkew1=new ArrayList<>();
Set<MATRIX> ms=new HashSet<MATRIX>();
ms.addAll(matrices);
if(ms.size()==1){
return new ArrayList<>();
}
Set<MATRIX> ms=new HashSet<MATRIX>();
ms.addAll(matrices);
if(ms.size()==1){
return new ArrayList<>();
}
for(MATRIX n:matrices){
//...
}
for(MATRIX n:matrices){
//...
}
for (; startpos + i <= matrices.size() + 1; i++) {
double errTranslateX = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(translateX, startpos, i);
double errTranslateY = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(translateY, startpos, i);
double errScaleX = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(scaleX, startpos, i);
double errScaleY = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(scaleY, startpos, i);
double errRotateSkew0 = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(rotateSkew0, startpos, i);
double errRotateSkew1 = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(rotateSkew1, startpos, i);
double err = startpos + i > matrices.size()?Double.MAX_VALUE:(errTranslateX/20+errTranslateY/20+0.1*errScaleX+0.1*errScaleY+errRotateSkew0/360+errRotateSkew1/360);
if (err > tolerance) {
if (last == null) {
startpos++;
i = min - 1;
continue;
}
ret.add(new TweenRange(startpos, startpos+i-1-1));
startpos = startpos + i -1;
i = min - 1;
last = null;
continue;
}
last = err;
}
return ret;*/
for (; startpos + i <= matrices.size() + 1; i++) {
double errTranslateX = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(translateX, startpos, i);
double errTranslateY = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(translateY, startpos, i);
double errScaleX = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(scaleX, startpos, i);
double errScaleY = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(scaleY, startpos, i);
double errRotateSkew0 = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(rotateSkew0, startpos, i);
double errRotateSkew1 = startpos + i > matrices.size() ? Double.MAX_VALUE : getErrorLevel(rotateSkew1, startpos, i);
double err = startpos + i > matrices.size()?Double.MAX_VALUE:(errTranslateX/20+errTranslateY/20+0.1*errScaleX+0.1*errScaleY+errRotateSkew0/360+errRotateSkew1/360);
if (err > tolerance) {
if (last == null) {
startpos++;
i = min - 1;
continue;
}
ret.add(new TweenRange(startpos, startpos+i-1-1));
startpos = startpos + i -1;
i = min - 1;
last = null;
continue;
}
last = err;
}
return ret;*/
}
private static double getErrorLevel(List<Double> yValues, int start, int len) {
@@ -96,7 +94,7 @@ public class TweenDetector {
double ynew = a + b * (i - start);
double ydelta = Math.abs(ynew - yorig);
sumdelta += ydelta;
if(ydelta>maxdelta){
if (ydelta > maxdelta) {
maxdelta = ydelta;
}
}
@@ -106,7 +104,7 @@ public class TweenDetector {
private static double[] calc(List<Double> yValues, int start, int len) {
List<Double> xValues = new ArrayList<>();
for (int i = 0; i < len; i++) {
xValues.add((double)i);
xValues.add((double) i);
}
yValues = yValues.subList(start, start + len);

View File

@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.timeline;
/**
@@ -22,6 +21,7 @@ package com.jpexs.decompiler.flash.timeline;
* @author JPEXS
*/
public class TweenRange {
public int startPosition;
public int endPosition;
@@ -32,6 +32,6 @@ public class TweenRange {
@Override
public String toString() {
return "["+startPosition+"-"+endPosition+"]";
}
return "[" + startPosition + "-" + endPosition + "]";
}
}

View File

@@ -221,6 +221,4 @@ public class MATRIX implements Serializable {
return true;
}
}