private With decodeWith(ActionFactory factory) { With a = new With(); int size = reader.readUI16(); int target = size + reader.Offset; a.endWith = factory.getLabel(target); return(a); }
private Branch decodeBranch(int code, ActionFactory factory) { Branch a = new Branch(code); int offset = reader.readSI16(); int target = offset + reader.Offset; a.target = factory.getLabel(target); return(a); }
/// <summary> consume actions until length bytes are used up</summary> /// <param name="length"> /// </param> /// <param name="throwExceptions">- if false exceptions will NOT be thrown. This is /// used for decoding a series of opcodes which may not be complete on their own. /// </param> /// <throws> IOException </throws> public virtual ActionList decode(int length, bool throwExceptions) { int startOffset = reader.Offset; int end = startOffset + length; bool ending = false; ActionFactory factory = new ActionFactory(length, startOffset, actionCount); try { for (int offset = startOffset; offset < end; offset = reader.Offset) { int opcode = reader.readUI8(); if (opcode > 0) { if (ending) { throw new SwfFormatException("unexpected bytes after sactionEnd: " + opcode); } factory.setActionOffset(actionCount, offset); decodeAction(opcode, offset, factory); actionCount++; } else if (opcode == 0) { ending = true; } else { break; } } // keep track of the end too factory.setActionOffset(actionCount, reader.Offset); } catch (System.IndexOutOfRangeException aio) { if (throwExceptions) { throw aio; } } catch (SwfFormatException swf) { if (throwExceptions) { throw swf; } } return(factory.createActionList(keepOffsets)); }
private WaitForFrame decodeWaitForFrame(int opcode, ActionFactory factory) { WaitForFrame a = new WaitForFrame(opcode); if (opcode == Flash.Swf.ActionConstants.sactionWaitForFrame) { a.frame = reader.readUI16(); } int skipCount = reader.readUI8(); int skipTarget = actionCount + 1 + skipCount; factory.addSkipEntry(a, skipTarget); return(a); }
/// <summary> consume actions until length bytes are used up</summary> /// <param name="length"> /// </param> /// <param name="throwExceptions">- if false exceptions will NOT be thrown. This is /// used for decoding a series of opcodes which may not be complete on their own. /// </param> /// <throws> IOException </throws> public virtual ActionList decode(int length, bool throwExceptions) { int startOffset = reader.Offset; int end = startOffset + length; bool ending = false; ActionFactory factory = new ActionFactory(length, startOffset, actionCount); try { for (int offset = startOffset; offset < end; offset = reader.Offset) { int opcode = reader.readUI8(); if (opcode > 0) { if (ending) throw new SwfFormatException("unexpected bytes after sactionEnd: " + opcode); factory.setActionOffset(actionCount, offset); decodeAction(opcode, offset, factory); actionCount++; } else if (opcode == 0) { ending = true; } else { break; } } // keep track of the end too factory.setActionOffset(actionCount, reader.Offset); } catch (System.IndexOutOfRangeException aio) { if (throwExceptions) throw aio; } catch (SwfFormatException swf) { if (throwExceptions) throw swf; } return factory.createActionList(keepOffsets); }
private Try decodeTry(ActionFactory factory) { Try a = new Try(); a.flags = reader.readUI8(); int trySize = reader.readUI16(); int catchSize = reader.readUI16(); int finallySize = reader.readUI16(); if (a.hasRegister()) { a.catchReg = reader.readUI8(); } else { a.catchName = reader.readString(); } // we have now consumed the try action. what follows is label mgmt int tryEnd = reader.Offset + trySize; a.endTry = factory.getLabel(tryEnd); // place the catchLabel to mark the end point of the catch handler if (a.hasCatch()) { a.endCatch = factory.getLabel(tryEnd + catchSize); } // place the finallyLabel to mark the end point of the finally handler if (a.hasFinally()) { a.endFinally = factory.getLabel(tryEnd + finallySize + (a.hasCatch()?catchSize:0)); } return(a); }
private With decodeWith(ActionFactory factory) { With a = new With(); int size = reader.readUI16(); int target = size + reader.Offset; a.endWith = factory.getLabel(target); return a; }
private Push decodePush(int offset, int end, ActionFactory factory) { Push p; do { int pushType = reader.readUI8(); switch (pushType) { case Flash.Swf.ActionConstants.kPushStringType: // string p = ActionFactory.createPush(reader.readString()); break; case Flash.Swf.ActionConstants.kPushFloatType: // float byte[] floatBytes = new byte[4]; reader.read(floatBytes, 0, 4); p = ActionFactory.createPush(BitConverter.ToSingle(floatBytes, 0)); // value break; case Flash.Swf.ActionConstants.kPushNullType: // null p = ActionFactory.createPushNull(); break; case Flash.Swf.ActionConstants.kPushUndefinedType: // undefined p = ActionFactory.createPushUndefined(); break; case Flash.Swf.ActionConstants.kPushRegisterType: // register p = ActionFactory.createPushRegister(reader.readUI8()); break; case Flash.Swf.ActionConstants.kPushBooleanType: // boolean p = ActionFactory.createPush(reader.readUI8() != 0); break; case Flash.Swf.ActionConstants.kPushDoubleType: // double // read two 32 bit little-endian values in big-endian order. weird. byte[] doubleBytes = new byte[8]; reader.read(doubleBytes, 4, 4); reader.read(doubleBytes, 0, 4); p = ActionFactory.createPush(BitConverter.ToDouble(doubleBytes, 0)); break; case Flash.Swf.ActionConstants.kPushIntegerType: // integer p = ActionFactory.createPush((int) reader.readUI32()); break; case Flash.Swf.ActionConstants.kPushConstant8Type: // 8-bit cpool reference p = ActionFactory.createPushCpool(reader.readUI8()); break; case Flash.Swf.ActionConstants.kPushConstant16Type: // 16-bit cpool reference p = ActionFactory.createPushCpool(reader.readUI16()); break; default: throw new SwfFormatException("Unknown push data type " + pushType); } factory.setAction(offset, p); offset = reader.Offset; } while (offset < end); return p; }
private WaitForFrame decodeWaitForFrame(int opcode, ActionFactory factory) { WaitForFrame a = new WaitForFrame(opcode); if (opcode == Flash.Swf.ActionConstants.sactionWaitForFrame) a.frame = reader.readUI16(); int skipCount = reader.readUI8(); int skipTarget = actionCount + 1 + skipCount; factory.addSkipEntry(a, skipTarget); return a; }
private Branch decodeBranch(int code, ActionFactory factory) { Branch a = new Branch(code); int offset = reader.readSI16(); int target = offset + reader.Offset; a.target = factory.getLabel(target); return a; }
private Try decodeTry(ActionFactory factory) { Try a = new Try(); a.flags = reader.readUI8(); int trySize = reader.readUI16(); int catchSize = reader.readUI16(); int finallySize = reader.readUI16(); if (a.hasRegister()) a.catchReg = reader.readUI8(); else a.catchName = reader.readString(); // we have now consumed the try action. what follows is label mgmt int tryEnd = reader.Offset + trySize; a.endTry = factory.getLabel(tryEnd); // place the catchLabel to mark the end point of the catch handler if (a.hasCatch()) a.endCatch = factory.getLabel(tryEnd + catchSize); // place the finallyLabel to mark the end point of the finally handler if (a.hasFinally()) a.endFinally = factory.getLabel(tryEnd + finallySize + (a.hasCatch()?catchSize:0)); return a; }
private void decodeAction(int opcode, int offset, ActionFactory factory) { LineRecord line = debug != null?debug.getLine(offset):null; if (line != null) { factory.setLine(offset, line); } // interleave register records in the action list RegisterRecord record = (debug != null)?debug.getRegisters(offset):null; if (record != null) { factory.setRegister(offset, record); } Action a; if (opcode < 0x80) { a = ActionFactory.createAction(opcode); factory.setAction(offset, a); return ; } int len = reader.readUI16(); int pos = offset + 3; switch (opcode) { case Flash.Swf.ActionConstants.sactionDefineFunction: a = decodeDefineFunction(pos, len); factory.setAction(offset, a); return ; case Flash.Swf.ActionConstants.sactionDefineFunction2: a = decodeDefineFunction2(pos, len); factory.setAction(offset, a); return ; case Flash.Swf.ActionConstants.sactionWith: a = decodeWith(factory); break; case Flash.Swf.ActionConstants.sactionTry: a = decodeTry(factory); break; case Flash.Swf.ActionConstants.sactionPush: Push p = decodePush(offset, pos + len, factory); checkConsumed(pos, len, p); return ; case Flash.Swf.ActionConstants.sactionStrictMode: a = decodeStrictMode(); break; case Flash.Swf.ActionConstants.sactionCall: // this actions opcode has the high bit set, but there is no length. considered a permanent bug. a = ActionFactory.createCall(); break; case Flash.Swf.ActionConstants.sactionGotoFrame: a = decodeGotoFrame(); break; case Flash.Swf.ActionConstants.sactionGetURL: a = decodeGetURL(); break; case Flash.Swf.ActionConstants.sactionStoreRegister: a = decodeStoreRegister(); break; case Flash.Swf.ActionConstants.sactionConstantPool: a = decodeConstantPool(); break; case Flash.Swf.ActionConstants.sactionWaitForFrame: a = decodeWaitForFrame(opcode, factory); break; case Flash.Swf.ActionConstants.sactionSetTarget: a = decodeSetTarget(); break; case Flash.Swf.ActionConstants.sactionGotoLabel: a = decodeGotoLabel(); break; case Flash.Swf.ActionConstants.sactionWaitForFrame2: a = decodeWaitForFrame(opcode, factory); break; case Flash.Swf.ActionConstants.sactionGetURL2: a = decodeGetURL2(); break; case Flash.Swf.ActionConstants.sactionJump: case Flash.Swf.ActionConstants.sactionIf: a = decodeBranch(opcode, factory); break; case Flash.Swf.ActionConstants.sactionGotoFrame2: a = decodeGotoFrame2(); break; default: a = decodeUnknown(opcode, len); break; } checkConsumed(pos, len, a); factory.setAction(offset, a); }
private Push decodePush(int offset, int end, ActionFactory factory) { Push p; do { int pushType = reader.readUI8(); switch (pushType) { case Flash.Swf.ActionConstants.kPushStringType: // string p = ActionFactory.createPush(reader.readString()); break; case Flash.Swf.ActionConstants.kPushFloatType: // float byte[] floatBytes = new byte[4]; reader.read(floatBytes, 0, 4); p = ActionFactory.createPush(BitConverter.ToSingle(floatBytes, 0)); // value break; case Flash.Swf.ActionConstants.kPushNullType: // null p = ActionFactory.createPushNull(); break; case Flash.Swf.ActionConstants.kPushUndefinedType: // undefined p = ActionFactory.createPushUndefined(); break; case Flash.Swf.ActionConstants.kPushRegisterType: // register p = ActionFactory.createPushRegister(reader.readUI8()); break; case Flash.Swf.ActionConstants.kPushBooleanType: // boolean p = ActionFactory.createPush(reader.readUI8() != 0); break; case Flash.Swf.ActionConstants.kPushDoubleType: // double // read two 32 bit little-endian values in big-endian order. weird. byte[] doubleBytes = new byte[8]; reader.read(doubleBytes, 4, 4); reader.read(doubleBytes, 0, 4); p = ActionFactory.createPush(BitConverter.ToDouble(doubleBytes, 0)); break; case Flash.Swf.ActionConstants.kPushIntegerType: // integer p = ActionFactory.createPush((int)reader.readUI32()); break; case Flash.Swf.ActionConstants.kPushConstant8Type: // 8-bit cpool reference p = ActionFactory.createPushCpool(reader.readUI8()); break; case Flash.Swf.ActionConstants.kPushConstant16Type: // 16-bit cpool reference p = ActionFactory.createPushCpool(reader.readUI16()); break; default: throw new SwfFormatException("Unknown push data type " + pushType); } factory.setAction(offset, p); offset = reader.Offset; }while (offset < end); return(p); }
private StrictMode decodeStrictMode() { bool mode = reader.readUI8() != 0; return(ActionFactory.createStrictMode(mode)); }
private StoreRegister decodeStoreRegister() { int register = reader.readUI8(); return(ActionFactory.createStoreRegister(register)); }
private void decodeAction(int opcode, int offset, ActionFactory factory) { LineRecord line = debug != null?debug.getLine(offset) : null; if (line != null) { factory.setLine(offset, line); } // interleave register records in the action list RegisterRecord record = (debug != null)?debug.getRegisters(offset):null; if (record != null) { factory.setRegister(offset, record); } Action a; if (opcode < 0x80) { a = ActionFactory.createAction(opcode); factory.setAction(offset, a); return; } int len = reader.readUI16(); int pos = offset + 3; switch (opcode) { case Flash.Swf.ActionConstants.sactionDefineFunction: a = decodeDefineFunction(pos, len); factory.setAction(offset, a); return; case Flash.Swf.ActionConstants.sactionDefineFunction2: a = decodeDefineFunction2(pos, len); factory.setAction(offset, a); return; case Flash.Swf.ActionConstants.sactionWith: a = decodeWith(factory); break; case Flash.Swf.ActionConstants.sactionTry: a = decodeTry(factory); break; case Flash.Swf.ActionConstants.sactionPush: Push p = decodePush(offset, pos + len, factory); checkConsumed(pos, len, p); return; case Flash.Swf.ActionConstants.sactionStrictMode: a = decodeStrictMode(); break; case Flash.Swf.ActionConstants.sactionCall: // this actions opcode has the high bit set, but there is no length. considered a permanent bug. a = ActionFactory.createCall(); break; case Flash.Swf.ActionConstants.sactionGotoFrame: a = decodeGotoFrame(); break; case Flash.Swf.ActionConstants.sactionGetURL: a = decodeGetURL(); break; case Flash.Swf.ActionConstants.sactionStoreRegister: a = decodeStoreRegister(); break; case Flash.Swf.ActionConstants.sactionConstantPool: a = decodeConstantPool(); break; case Flash.Swf.ActionConstants.sactionWaitForFrame: a = decodeWaitForFrame(opcode, factory); break; case Flash.Swf.ActionConstants.sactionSetTarget: a = decodeSetTarget(); break; case Flash.Swf.ActionConstants.sactionGotoLabel: a = decodeGotoLabel(); break; case Flash.Swf.ActionConstants.sactionWaitForFrame2: a = decodeWaitForFrame(opcode, factory); break; case Flash.Swf.ActionConstants.sactionGetURL2: a = decodeGetURL2(); break; case Flash.Swf.ActionConstants.sactionJump: case Flash.Swf.ActionConstants.sactionIf: a = decodeBranch(opcode, factory); break; case Flash.Swf.ActionConstants.sactionGotoFrame2: a = decodeGotoFrame2(); break; default: a = decodeUnknown(opcode, len); break; } checkConsumed(pos, len, a); factory.setAction(offset, a); }