/// <summary> /// Prepare currencier for retrieving rates from all possible sources. /// </summary> static void EnsureImportingMeansSetup() { if (fastWeb != null) { return; } fastWeb = new FastWeb2("https://www.google.com/") { WebAccessRetries = 0 }; rateParser = new BitParser() { SelectMethod = SelectMethod.XPath, DetailType = SelectDetailType.Property, SelectQuery = "//*[contains(text(),' United States Dollar')]", Detail = "InnerText", PostProcess = new[] { new Mold(MoldType.Before, " United States Dollar"), new Mold(MoldType.Substr, (-5).ToString()), new Mold(MoldType.OnlyFloatChars), } }; }
/// <summary> /// Reads MatrixData from swf into a byte-array /// </summary> /// <remarks> /// Since were only interested in bytecode actions, theres no need to parse this data. /// </remarks> protected byte[] ReadMatrixData() { byte[] b = br.ReadBytes(27); // max. byte size of matrix record BitArray ba = BitParser.GetBitValues(b); int bitcount = 1; int Nbits; if (ba[bitcount - 1]) { Nbits = (int)BitParser.ReadUInt32(ba, bitcount, 5); bitcount += 5 + Nbits * 2; } bitcount += 1; if (ba[bitcount - 1]) { Nbits = (int)BitParser.ReadUInt32(ba, bitcount, 5); bitcount += 5 + Nbits * 2; } Nbits = (int)BitParser.ReadUInt32(ba, bitcount, 5); bitcount += 5 + Nbits * 2; int bytecount = Convert.ToInt32(Math.Ceiling((double)bitcount / 8.0)); byte[] matrix = new byte[bytecount]; for (int i = 0; i < bytecount; i++) { matrix[i] = b[i]; } br.BaseStream.Position -= b.Length - bytecount; return(matrix); }
/// <summary> /// Creates a new <see cref="Pix15"/> instance. /// </summary> /// <param name="bytes">Bytes.</param> public Pix15(byte[] bytes) { BitArray ba = BitParser.GetBitValues(bytes); this.red = (byte)BitParser.ReadUInt32(ba, 1, 5); this.green = (byte)BitParser.ReadUInt32(ba, 6, 5); this.blue = (byte)BitParser.ReadUInt32(ba, 11, 5); }
private void ParseAttributes(BaseTag tag) { BitArray ba = BitParser.GetBitValues(tag.Data); FileAttributes.UseDirectBlit = (bool)ba[16 + 1]; FileAttributes.UseGPU = (bool)ba[16 + 2]; FileAttributes.HasMetaData = (bool)ba[16 + 3]; FileAttributes.Actionscript3 = (bool)ba[16 + 4]; FileAttributes.UseNetwork = (bool)ba[16 + 7]; }
/// <summary> /// Reads the data from the binary reader. /// </summary> /// <param name="binaryReader">Binary reader.</param> public override void ReadData(BufferedBinaryReader binaryReader) { byte[] b = binaryReader.ReadBytes(4); BitArray ba = BitParser.GetBitValues(b); blockWidth = (int)BitParser.ReadUInt32(ba, 0, 4); imageWidth = (int)BitParser.ReadUInt32(ba, 4, 12); blockHeight = (int)BitParser.ReadUInt32(ba, 16, 4); imageHeight = (int)BitParser.ReadUInt32(ba, 20, 12); int nbWBlock = 0; int nbBlockWInt = imageWidth / blockWidth; float nbBlockWDec = imageWidth / blockWidth; if (nbBlockWInt == nbBlockWDec) { nbWBlock = nbBlockWInt; } else { nbWBlock = nbBlockWInt + 1; } int nbHBlock = 0; int nbBlockHInt = imageHeight / blockHeight; float nbBlockHDec = imageHeight / blockHeight; if (nbBlockHInt == nbBlockHDec) { nbHBlock = nbBlockHInt; } else { nbHBlock = nbBlockHInt + 1; } int nbBlock = nbWBlock * nbHBlock; if (nbBlock > 0) { blocks = new ImageBlock[nbBlock]; for (int i = 0; i < nbBlock; i++) { blocks[i] = new ImageBlock(); blocks[i].ReadData(binaryReader); } } }
/// <summary> /// Reads the data from a binary reader. /// </summary> /// <param name="binaryReader">Binary reader.</param> public void ReadData(BufferedBinaryReader binaryReader) { byte[] b = binaryReader.ReadBytes(2); BitArray ba = BitParser.GetBitValues(b); dataSize = (int)BitParser.ReadUInt32(ba, 0, 16); data = null; if (dataSize != 0) { data = new byte[dataSize]; for (int i = 0; i < dataSize; i++) { data[i] = binaryReader.ReadByte(); } } }
/// <summary> /// Reads RectData from swf into a byte-array. /// </summary> /// <remarks> /// Since were only interested in bytecode actions, theres no need to parse this data. /// </remarks> protected byte[] ReadRectData() { byte[] b = br.ReadBytes(17); // max. byte size of rect record BitArray ba = BitParser.GetBitValues(b); int Nbits = (int)BitParser.ReadUInt32(ba, 5); int bitcount = 5 + Nbits * 4; int bytecount = Convert.ToInt32(Math.Ceiling((double)bitcount / 8.0)); byte[] rect = new byte[bytecount]; for (int i = 0; i < bytecount; i++) { rect[i] = b[i]; } br.BaseStream.Position -= b.Length - bytecount; return(rect); }
private Rectangle GetSwfRect(byte[] bytes) { BitArray ba = BitParser.GetBitValues(bytes); int Nbits = (int)BitParser.ReadUInt32(ba, 5); int index = 5; int xmin = (int)BitParser.ReadUInt32(ba, index, Nbits) / 20; index += Nbits; int xmax = (int)BitParser.ReadUInt32(ba, index, Nbits) / 20; index += Nbits; int ymin = (int)BitParser.ReadUInt32(ba, index, Nbits) / 20; index += Nbits; int ymax = (int)BitParser.ReadUInt32(ba, index, Nbits) / 20; return(new Rectangle(xmin, ymin, xmax, ymax)); }
/// <summary> /// Reads RectData from swf into a byte-array /// </summary> /// <remarks> /// Since were only interested in bytecode actions, theres no need to parse this data. /// </remarks> protected byte[] ReadCXFormWithAlphaData() { byte[] b = br.ReadBytes(17); // max. byte size of transform record BitArray ba = BitParser.GetBitValues(b); bool hasAdd = ba[0]; bool hasMult = ba[1]; int Nbits = (int)BitParser.ReadUInt32(ba, 2, 4); int bitcount = 6 + (hasAdd ? Nbits * 4 : 0) + (hasMult ? Nbits * 4 : 0); int bytecount = Convert.ToInt32(Math.Ceiling((double)bitcount / 8.0)); byte[] cfa = new byte[bytecount]; for (int i = 0; i < bytecount; i++) { cfa[i] = b[i]; } br.BaseStream.Position -= b.Length - bytecount; return(cfa); }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="firstByte">First byte.</param> /// <param name="buttonType">Button type.</param> public void ReadData(BufferedBinaryReader binaryReader, byte firstByte, TagCodeEnum buttonType) { BitArray ba = BitParser.GetBitValues(new byte[1] { firstByte }); buttonStateHitTest = ba.Get(4); buttonStateDown = ba.Get(5); buttonStateOver = ba.Get(6); buttonStateUp = ba.Get(7); characterId = binaryReader.ReadUInt16(); placeDepth = binaryReader.ReadUInt16(); placeMatrix = new Matrix(); placeMatrix.ReadData(binaryReader); colorTransform = null; if (buttonType == TagCodeEnum.DefineButton2) { colorTransform = new CXFormWithAlphaData(); colorTransform.ReadData(binaryReader); } }
/************************************************** * Read SWF Tags **************************************************/ /// <summary> /// Read and parse PlaceObject2Tag, leave non-bytecode data as raw byte-array /// </summary> protected PlaceObject2Tag ReadPlaceObject2Tag() { ReadRecordHeader(); // get flags byte byte0 = br.ReadByte(); BitArray flags = new BitArray(new byte[1] { byte0 }); BitParser.BytewiseReverse(flags); byte[] depth = br.ReadBytes(2); byte[] chId; byte[] matrix; byte[] ctf; byte[] ratio; byte[] name; byte[] clpd; bool hasActions; // even if length is 0 byte[] actionHead; // contains byte code data ClipActionRec[] clipActions; // read data, depending on flag settings if (flags[6]) { chId = br.ReadBytes(2); } else { chId = new byte[0]; } if (flags[5]) { matrix = ReadMatrixData(); } else { matrix = new byte[0]; } if (flags[4]) { ctf = ReadCXFormWithAlphaData(); } else { ctf = new byte[0]; } if (flags[3]) { ratio = br.ReadBytes(2); } else { ratio = new byte[0]; } if (flags[2]) { // save stream position long startStream = br.BaseStream.Position; // read characters byte ch; do { ch = br.ReadByte(); } while (ch != 0); // block length int len = Convert.ToInt32(br.BaseStream.Position - startStream); // reset stream position br.BaseStream.Position = startStream; // read name name = br.ReadBytes(len); } else { name = new byte[0]; } // clip id if (flags[1]) { clpd = br.ReadBytes(2); } else { clpd = new byte[0]; } hasActions = flags[0]; // get bytecode actions if (hasActions) { // different behaviour for Flash 6+ actionHead = (version >= 6) ? br.ReadBytes(6) : br.ReadBytes(4); // read clip action records to list ArrayList clpAc = new ArrayList(); ClipActionRec a; do { a = ReadClipActionRec(); if (a != null) { clpAc.Add(a); } } while (a != null); // copy list to array clipActions = new ClipActionRec[clpAc.Count]; clpAc.CopyTo(clipActions, 0); } else { // no actions -> null return(null); } // tag-header (non-bytecode data before clipActionRec in tag) size varies with flags int size = 3 // flags + chId.Length + matrix.Length + ctf.Length + ratio.Length + name.Length + clpd.Length + actionHead.Length; byte[] header = new byte[size]; int pos = 1; // copy all data to our tag-header array header[0] = byte0; depth.CopyTo(header, 1); pos += depth.Length; chId.CopyTo(header, pos); pos += chId.Length; matrix.CopyTo(header, pos); pos += matrix.Length; ctf.CopyTo(header, pos); pos += ctf.Length; ratio.CopyTo(header, pos); pos += ratio.Length; name.CopyTo(header, pos); pos += name.Length; clpd.CopyTo(header, pos); pos += clpd.Length; actionHead.CopyTo(header, pos); // return tag return(new PlaceObject2Tag(header, clipActions)); }
/// <summary> /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see> /// </summary> public override void ReadData(byte version, BufferedBinaryReader binaryReader) { RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); characterId = binaryReader.ReadUInt16(); rect = new Rect(); rect.ReadData(binaryReader); BitArray ba = BitParser.GetBitValues(new byte[1] { binaryReader.ReadByte() }); bool hasText = ba.Get(0); //binaryReader.ReadBoolean(); wordWrap = ba.Get(1); //binaryReader.ReadBoolean(); multiline = ba.Get(2); //binaryReader.ReadBoolean(); password = ba.Get(3); //binaryReader.ReadBoolean(); readOnly = ba.Get(4); //binaryReader.ReadBoolean(); bool hasTextColor = ba.Get(5); //binaryReader.ReadBoolean(); bool hasMaxLength = ba.Get(6); //binaryReader.ReadBoolean(); bool hasFont = ba.Get(7); //binaryReader.ReadBoolean(); //binaryReader.SynchBits(); ba = BitParser.GetBitValues(new byte[1] { binaryReader.ReadByte() }); //binaryReader.ReadBoolean(); //Reserved autoSize = ba.Get(1); //binaryReader.ReadBoolean(); bool hasLayout = ba.Get(2); //binaryReader.ReadBoolean(); noSelect = ba.Get(3); //binaryReader.ReadBoolean(); border = ba.Get(4); //binaryReader.ReadBoolean(); //binaryReader.ReadBoolean(); //Reserved html = ba.Get(6); //binaryReader.ReadBoolean(); usedOutlines = ba.Get(7); //binaryReader.ReadBoolean(); if (hasFont) { fontId = binaryReader.ReadUInt16(); fontHeight = binaryReader.ReadUInt16(); } if (hasTextColor) { textColor = new RGBA(); textColor.ReadData(binaryReader); } if (hasMaxLength) { maxLenght = binaryReader.ReadUInt16(); } if (hasLayout) { align = binaryReader.ReadByte(); leftMargin = binaryReader.ReadUInt16(); rightMargin = binaryReader.ReadUInt16(); indent = binaryReader.ReadUInt16(); leading = binaryReader.ReadUInt16(); } variableName = binaryReader.ReadString(); if (hasText) { initialText = binaryReader.ReadString(); } }
/// <summary> /// Next report. Or null if there is none. /// </summary> /// <returns></returns> public GLPBase NextReport() { GLPBase iBase = null; bool sendAck = false; if (m_bHeaderFound == false && m_cirBuf.UsedLength >= 14) { // Looking for header. byte[] arrPackets = m_cirBuf.Peek(0, 14); m_arrDeviceID = new byte[8]; // Device ID Array.Copy(arrPackets, m_arrDeviceID, 8); // Packet type m_iPacketType = arrPackets[8]; // Packet count m_iPacketCount = arrPackets[9]; // Firmware version BitParser bp = new BitParser(2, true, false); bp.WriteData(arrPackets, 10, 2); int build = bp.ReadIntX(6); int major = bp.ReadIntX(7); int minor = bp.ReadIntX(3); m_FirmwareVersion = minor + "." + major + "." + build; ushort ackAndLength = BitConverter.ToUInt16(arrPackets, 12); if ((ackAndLength & 0x8000) > 0) { sendAck = true; } else { sendAck = false; } m_iPacketLength = ackAndLength & (ushort)0x7FFF; if (m_cirBuf.UsedLength >= m_iPacketLength) { byte[] CRC = new byte[2]; byte[] packet = m_cirBuf.Peek(0, m_iPacketLength); GetCRC(packet, ref CRC); if (CRC[0] == packet[packet.Length - 2] && CRC[1] == packet[packet.Length - 1]) { m_bHeaderFound = true; m_iPacketsProcessed = 0; m_cirBuf.Seek(14); } else { m_bHeaderFound = false; m_cirBuf.Clear(); } } } if (m_bHeaderFound) { byte[] arrPackets = m_cirBuf.Peek(0, m_cirBuf.UsedLength); if (m_iPacketType == 0) { iBase = new GLPLogin(m_arrDeviceID, arrPackets); //iBase.AddStatus("FirmwareVersion", m_FirmwareVersion); iBase.loginPacket = true; iBase.sendAck = sendAck; } if (m_iPacketType == 1) { iBase = new GLPReport(m_arrDeviceID, arrPackets); iBase.AddStatus("FirmwareVersion", m_FirmwareVersion); m_iPacketsProcessed++; // Forward to next packet start. m_cirBuf.Seek(iBase != null ? iBase.Length : 0); iBase.sendAck = sendAck; } if (m_iPacketType == 0x20) { iBase = new GLPTerminal(m_arrDeviceID, arrPackets); m_cirBuf.Seek(iBase != null ? iBase.Length : 0); iBase.sendAck = sendAck; } if (m_iPacketType == 0x30) { iBase = new GLPBinaryPictureData(m_arrDeviceID, arrPackets); m_cirBuf.Seek(iBase != null ? iBase.Length : 0); iBase.sendAck = sendAck; } if (m_iPacketType >= 0xF0 && m_iPacketType <= 0xFF) { iBase = new GLPLogin(m_arrDeviceID, arrPackets); m_cirBuf.Seek(m_iPacketLength - 14); //bo nie wiemy jaka jest dlugosc m_bHeaderFound = false; iBase.loginPacket = true; iBase.sendAck = sendAck; return(iBase); } if (m_iPacketsProcessed >= m_iPacketCount || iBase.parseError) { // Forward to next packet start (jump CRC). if (iBase.parseError) { m_cirBuf.Clear(); } else { m_cirBuf.Seek(2); } m_bHeaderFound = false; } } return(iBase); }