From 877ba24c81cf15e8f13126573ed2ca06ccd4015f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 20 Apr 2013 10:46:00 +0200 Subject: [PATCH] Issue #66 Decompress LZMA from commandline --- .../src/com/jpexs/decompiler/flash/Main.java | 2 +- trunk/src/com/jpexs/decompiler/flash/SWF.java | 69 +++++++------------ .../jpexs/decompiler/flash/graph/Graph.java | 14 ++-- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/Main.java b/trunk/src/com/jpexs/decompiler/flash/Main.java index a34afbb94..41a61d5cf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/Main.java @@ -562,7 +562,7 @@ public class Main { badArguments(); } - if (SWF.cws2fws(new FileInputStream(args[pos + 1]), new FileOutputStream(args[pos + 2]))) { + if (SWF.decompress(new FileInputStream(args[pos + 1]), new FileOutputStream(args[pos + 2]))) { System.out.println("OK"); System.exit(0); } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index d61287d25..cd0a9071c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -320,57 +320,32 @@ public class SWF { return true; } - /** - * Decompress SWF file - * - * @param fis Input stream - * @param fos Output stream - */ - public static boolean cws2fws(InputStream fis, OutputStream fos) { - try { - byte swfHead[] = new byte[8]; - fis.read(swfHead); - InflaterInputStream iis = new InflaterInputStream(fis); - if (swfHead[0] != 'C') { - fis.close(); - return false; - } - swfHead[0] = 'F'; - fos.write(swfHead); - int i; - while ((i = iis.read()) != -1) { - fos.write(i); - } - - fis.close(); - fos.close(); - } catch (FileNotFoundException ex) { - return false; - } catch (IOException ex) { - return false; - } - return true; - } - - /** - * Decompress LZMA compressed SWF file - * - * @param fis Input stream - * @param fos Output stream - */ - public static boolean zws2fws(InputStream fis, OutputStream fos) { + public static boolean decompress(InputStream fis, OutputStream fos) { try { byte hdr[] = new byte[3]; fis.read(hdr); String shdr = new String(hdr); - if (!shdr.equals("ZWS")) { - return false; - } - int version = fis.read(); - SWFInputStream sis = new SWFInputStream(fis, version, 4); - long fileSize = sis.readUI32(); + if (shdr.equals("CWS")) { + int version = fis.read(); + SWFInputStream sis = new SWFInputStream(fis, version, 4); + long fileSize = sis.readUI32(); + SWFOutputStream sos = new SWFOutputStream(fos, version); + sos.write("FWS".getBytes()); + sos.writeUI8(version); + sos.writeUI32(fileSize); + InflaterInputStream iis = new InflaterInputStream(fis); + int i; + while ((i = iis.read()) != -1) { + fos.write(i); + } + + fis.close(); + fos.close(); + } else if (shdr.equals("ZWS")) { + int version = fis.read(); + SWFInputStream sis = new SWFInputStream(fis, version, 4); + long fileSize = sis.readUI32(); - if (hdr[0] == 'Z') { ByteArrayOutputStream baos = new ByteArrayOutputStream(); long outSize = sis.readUI32(); int propertiesSize = 5; @@ -392,6 +367,8 @@ public class SWF { sos.writeUI32(fileSize); sos.write(baos.toByteArray()); sos.close(); + fis.close(); + fos.close(); } else { return false; } diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java index c58d96766..c4c49c7a9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java @@ -1075,8 +1075,8 @@ public class Graph { } if ((!onTrue.isEmpty()) && (!onFalse.isEmpty())) { - GraphTargetItem last=onTrue.get(onTrue.size() - 1); - if ((last instanceof ExitItem)||(last instanceof ContinueItem)||(last instanceof BreakItem)) { + GraphTargetItem last = onTrue.get(onTrue.size() - 1); + if ((last instanceof ExitItem) || (last instanceof ContinueItem) || (last instanceof BreakItem)) { retw.addAll(onFalse); onFalse.clear(); } @@ -1146,7 +1146,7 @@ public class Graph { addIf = ift.onTrue; nextcmds = ift.onFalse; loopBody.remove(loopBody.size() - 1); - }else if ((!ift.onTrue.isEmpty() && (ift.onTrue.get(ift.onTrue.size() - 1) instanceof ExitItem)) || ((ift.onTrue.size() == 1) && (ift.onTrue.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onTrue.get(0)).loopId == currentLoop.id))) { + } else if ((!ift.onTrue.isEmpty() && (ift.onTrue.get(ift.onTrue.size() - 1) instanceof ExitItem)) || ((ift.onTrue.size() == 1) && (ift.onTrue.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onTrue.get(0)).loopId == currentLoop.id))) { if (ift.expression != null) { expr = ift.expression; if (expr instanceof LogicalOpItem) { @@ -1155,18 +1155,18 @@ public class Graph { expr = new NotItem(null, expr); } } - addIf = ift.onFalse; + addIf = ift.onFalse; nextcmds = ift.onTrue; loopBody.remove(loopBody.size() - 1); - if(addIf.isEmpty()){ + if (addIf.isEmpty()) { //addIf.addAll(loopBody); } } } - if ((!addIf.isEmpty())&&(!(addIf.get(0) instanceof ScriptEndItem))) { // && (addIf.get(addIf.size() - 1) instanceof ContinueItem) && (((ContinueItem) addIf.get(addIf.size() - 1)).loopId == currentLoop.id)) { + if ((!addIf.isEmpty()) && (!(addIf.get(0) instanceof ScriptEndItem))) { // && (addIf.get(addIf.size() - 1) instanceof ContinueItem) && (((ContinueItem) addIf.get(addIf.size() - 1)).loopId == currentLoop.id)) { loopBody.add(expr); checkContinueAtTheEnd(addIf, currentLoop); - ret.add(new WhileItem(null, currentLoop, addIf,loopBody)); + ret.add(new WhileItem(null, currentLoop, addIf, loopBody)); ret.addAll(nextcmds); } else { List ex = new ArrayList();