| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Flanderra
Revision: 16
Author: pcherkas
Date: 19 Jul 2008 20:16:43
Changes:root SWF parser finished
Files:| ... | ...@@ -184,24 +184,20 @@ | |
| 184 | 184 | boolean zipContent = head[0] == 67; |
| 185 | 185 | result.put("zipContent", head[0] == 67); |
| 186 | 186 | result.put("version", head[3]); |
| 187 | is.read(head); | |
| 188 | long fileLength = parseUI32(head); | |
| 187 | head[0] = 0x46; | |
| 188 | byte[] lengthBytes = new byte[4]; | |
| 189 | is.read(lengthBytes); | |
| 190 | long fileLength = parseUI32(lengthBytes); | |
| 189 | 191 | result.put("fileLength", fileLength); |
| 190 | byte[] restFileData = new byte[(int) (fileLength - 8)]; | |
| 192 | InputStream swfUnzippedInputStream = null; | |
| 191 | 193 | if (zipContent) { |
| 192 | 194 | int i = 0; |
| 193 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
| 194 | while (!((i = is.read()) < 0)) { | |
| 195 | baos.write(i); | |
| 196 | } | |
| 197 | ||
| 198 | new InflaterInputStream(new ByteArrayInputStream(baos.toByteArray())).read(restFileData); | |
| 195 | swfUnzippedInputStream = new InflaterInputStream(is); | |
| 199 | 196 | } else { |
| 200 | is.read(restFileData); | |
| 197 | swfUnzippedInputStream = is; | |
| 201 | 198 | } |
| 202 | ||
| 203 | InputStream bais = new ByteArrayInputStream(restFileData); | |
| 204 | BitInputStream bis = new BitInputStream(bais); | |
| 199 | ||
| 200 | BitInputStream bis = new BitInputStream(swfUnzippedInputStream); | |
| 205 | 201 | |
| 206 | 202 | Map sizeRect = parseCompoundType("RECT", "sizes", new LinkedHashMap(), bis); |
| 207 | 203 | result.put("sizes", sizeRect); |
| ... | ...@@ -229,20 +225,20 @@ | |
| 229 | 225 | tagLength = BitUtils.parseSI32(new byte[] { bis.read(), bis.read(), bis.read(), bis.read() }); |
| 230 | 226 | } |
| 231 | 227 | String tagName = StructureFormatUtils.tagNameForCode((int) tagCode); |
| 232 | ByteArrayOutputStream tagContentBaos = new ByteArrayOutputStream((int) (tagLength + 2)); | |
| 233 | tagContentBaos.write(tagHeaderBytes); | |
| 228 | ByteArrayOutputStream tagContentBaos = new ByteArrayOutputStream((int) (tagLength)); | |
| 234 | 229 | for (int i = 0; i < tagLength; i++) { |
| 235 | 230 | tagContentBaos.write(bis.read()); |
| 236 | 231 | } |
| 237 | 232 | boolean supported = StructureFormatUtils.isSupportedStructure(tagName); |
| 238 | // tagContents.put("tagCode", new Long(tagCode)); | |
| 233 | tagContents.put("tagCode", new Long(tagCode)); | |
| 239 | 234 | tagContents.put("tagName", tagName); |
| 240 | 235 | // tagContents.put("isSupported", supported); |
| 241 | 236 | tagContents.put("tagLength", new Long(tagLength)); |
| 242 | 237 | tagContents.put("tagData", hex(tagContentBaos.toByteArray())); |
| 243 | if (supported) { | |
| 244 | tagContents.putAll(parseCompoundType(tagName, "tag".concat(tagName), result, bis)); | |
| 245 | } | |
| 238 | // if (supported) { | |
| 239 | // tagContents.putAll(parseCompoundType(tagName, | |
| 240 | // "tag".concat(tagName), result, bis)); | |
| 241 | // } | |
| 246 | 242 | if ((tags.size() > 2)) { |
| 247 | 243 | String prevTagName = (String) ((Map) tags.get(tags.size() - 1)).get("tagName"); |
| 248 | 244 | String prevPrevTagName = (String) ((Map) tags.get(tags.size() - 2)).get("tagName"); |
| ... | ...@@ -2,6 +2,7 @@ | |
| 2 | 2 | |
| 3 | 3 | import java.io.ByteArrayOutputStream; |
| 4 | 4 | import java.io.IOException; |
| 5 | import java.text.NumberFormat; | |
| 5 | 6 | import java.util.Arrays; |
| 6 | 7 | import java.util.BitSet; |
| 7 | 8 | |
| ... | ...@@ -628,6 +629,23 @@ | |
| 628 | 629 | } |
| 629 | 630 | |
| 630 | 631 | public static String hex(byte[] data) { |
| 631 | return hex(bytesToBits(data), 8 * data.length); | |
| 632 | int byteNumber = data.length; | |
| 633 | StringBuffer sb = new StringBuffer(""); | |
| 634 | for (int i = 0; i < byteNumber; i++) { | |
| 635 | BitSet bitSet = bitsSI8(data[i]); | |
| 636 | int bin1 = (bitSet.get(0)) ? 8 : 0; | |
| 637 | bin1 += (bitSet.get(1)) ? 4 : 0; | |
| 638 | bin1 += (bitSet.get(2)) ? 2 : 0; | |
| 639 | bin1 += (bitSet.get(3)) ? 1 : 0; | |
| 640 | ||
| 641 | int bin2 = (bitSet.get(4)) ? 8 : 0; | |
| 642 | bin2 += (bitSet.get(5)) ? 4 : 0; | |
| 643 | bin2 += (bitSet.get(6)) ? 2 : 0; | |
| 644 | bin2 += (bitSet.get(7)) ? 1 : 0; | |
| 645 | sb.append(hexChars[bin1]); | |
| 646 | sb.append(hexChars[bin2]); | |
| 647 | sb.append(' '); | |
| 648 | } | |
| 649 | return sb.toString(); | |
| 632 | 650 | } |
| 633 | 651 | } |
| 634 | 652 | \ No newline at end of file |
| ... | ...@@ -1,25 +1,32 @@ | |
| 1 | 1 | package com.flanderra.commons.test.swfinfo; |
| 2 | 2 | |
| 3 | import com.flanderra.commons.swfio.SWFIO; | |
| 4 | import com.flanderra.commons.swfio.impl.SWFIOImpl; | |
| 5 | import com.flanderra.commons.utils.SWFInfo; | |
| 6 | ||
| 3 | import java.io.ByteArrayInputStream; | |
| 7 | 4 | import java.io.File; |
| 8 | 5 | import java.io.FileInputStream; |
| 9 | 6 | import java.io.InputStream; |
| 10 | 7 | |
| 11 | 8 | import junit.framework.TestCase; |
| 12 | 9 | |
| 10 | import com.flanderra.commons.swfio.impl.SWFIOImpl; | |
| 11 | ||
| 13 | 12 | /** |
| 14 | 13 | * @author <a href="mailto:cherkashin.pavel@otr.ru">Pavel Cherkashin</a> |
| 15 | 14 | */ |
| 16 | 15 | public class SwfParserTest extends TestCase { |
| 16 | ||
| 17 | byte[] bytes = new byte[]{ | |
| 18 | ((byte)0x46), ((byte)0x57), ((byte)0x53), ((byte)0x03), ((byte)0x4F), ((byte)0x00), ((byte)0x00), ((byte)0x00), ((byte)0x78), ((byte)0x00), ((byte)0x05), ((byte)0x5F), ((byte)0x00), ((byte)0x00), ((byte)0x0F), ((byte)0xA0), | |
| 19 | ((byte)0x00), ((byte)0x00), ((byte)0x0C), ((byte)0x01), ((byte)0x00), ((byte)0x43), ((byte)0x02), ((byte)0xFF), ((byte)0xFF), ((byte)0xFF), ((byte)0xBF), ((byte)0x00), ((byte)0x23), ((byte)0x00), ((byte)0x00), ((byte)0x00), | |
| 20 | ((byte)0x01), ((byte)0x00), ((byte)0x70), ((byte)0xFB), ((byte)0x49), ((byte)0x97), ((byte)0x0D), ((byte)0x0C), ((byte)0x7D), ((byte)0x50), ((byte)0x00), ((byte)0x01), ((byte)0x14), ((byte)0x00), ((byte)0x00), ((byte)0x00), | |
| 21 | ((byte)0x00), ((byte)0x01), ((byte)0x25), ((byte)0xC9), ((byte)0x92), ((byte)0x0D), ((byte)0x21), ((byte)0xED), ((byte)0x48), ((byte)0x87), ((byte)0x65), ((byte)0x30), ((byte)0x3B), ((byte)0x6D), ((byte)0xE1), ((byte)0xD8), | |
| 22 | ((byte)0xB4), ((byte)0x00), ((byte)0x00), ((byte)0x86), ((byte)0x06), ((byte)0x06), ((byte)0x01), ((byte)0x00), ((byte)0x01), ((byte)0x00), ((byte)0x00), ((byte)0x40), ((byte)0x00), ((byte)0x00), ((byte)0x00)}; | |
| 23 | ||
| 17 | 24 | public void testRetrieveTags() { |
| 18 | 25 | try { |
| 19 | File srcFile = new File("com/flanderra/commons/test/test1.swf"); | |
| 20 | InputStream is = new FileInputStream(srcFile); | |
| 26 | // File srcFile = new File("com/flanderra/commons/test/test1.swf"); | |
| 27 | // InputStream is = new FileInputStream(srcFile); | |
| 28 | InputStream is = new ByteArrayInputStream(bytes); | |
| 21 | 29 | new SWFIOImpl().parseSWF(is, System.out); |
| 22 | ||
| 23 | 30 | } catch (Exception e) { |
| 24 | 31 | e.printStackTrace(); |
| 25 | 32 | fail(); |