private void btnSend_Click(object sender, EventArgs e) { DynamicByteProvider BytePro = hexBox1.ByteProvider as DynamicByteProvider; try { strPipeMsgOut.sockid = int.Parse(txtSockID.Text, System.Globalization.NumberStyles.HexNumber); } catch { MessageBox.Show("Invalid socket ID.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSockID.SelectAll(); txtSockID.Focus(); return; } bcBytes = BytePro.Bytes; strPipeMsgOut.command = Glob.CMD_INJECT; strPipeMsgOut.function = Glob.FUNC_SEND; strPipeMsgOut.datasize = bcBytes.Count; for (int times = int.Parse(txtTimes.Text); times > 0; times--) { pipeOut.Write(Glob.RawSerializeEx(strPipeMsgOut), 0, Marshal.SizeOf(strPipeMsgOut)); pipeOut.Write(bcBytes.GetBytes(), 0, strPipeMsgOut.datasize); } }
private void M24CXXDumpForm_DragDrop(object sender, DragEventArgs e) { string fileName = ((string[])e.Data.GetData("FileNameW"))[0]; List <MemoryRegionInfo> regionsInfo = new List <MemoryRegionInfo>() { new MemoryRegionInfo() { Address = 0, Size = (uint)s02512[chipSelectStripComboBox.SelectedItem.ToString()], Type = 1 } }; Action <FileWorkerIOCompleteInfo> complete = delegate(FileWorkerIOCompleteInfo info) { if (info.Error == null) { Text = "M24CXX DUMP " + fileName; _dataBytes = new ByteCollection(info.Regions[0].Data); hexBox1.ByteProvider = new DynamicByteProvider(_dataBytes); hexBox1.ByteProvider.Changed += HexBoxChanged; } else { infoPanel.SetErrorState(info.Error.Message); } }; file.Read(fileName, regionsInfo, complete); }
private void Xerox0190Form_DragDrop(object sender, DragEventArgs e) { string fileName = ((string[])e.Data.GetData("FileNameW"))[0]; List <MemoryRegionInfo> regionsInfo = new List <MemoryRegionInfo>() { new MemoryRegionInfo() { Address = 0, Size = 256, Type = 1 } }; Action <FileWorkerIOCompleteInfo> complete = delegate(FileWorkerIOCompleteInfo info) { if (info.Error == null) { Text = "XEROX 01/90 DUMP " + fileName; _dataBytes = new ByteCollection(info.Regions[0].Data); hexBox.ByteProvider = new DynamicByteProvider(_dataBytes); hexBox.ByteProvider.Changed += HexBoxChanged; } else { infoPanel.SetErrorState(info.Error.Message); } }; file.Read(fileName, regionsInfo, complete); }
/// <summary> /// Returns this DBF header in it's original raw binary data form. /// </summary> /// <returns>An Array of type System.Byte[]</returns> public byte[] GetDbfHeader() { try { ByteCollection bytes = new ByteCollection(32 + this._flds.Count * 32); // Keep the same file type ID. bytes.Add(this._id); // Then we right the last time the DBF was updated. byte lstUpYr = (byte)(this._lastUpd.Year - 1900), lstUpMn = (byte)this._lastUpd.Month, lstUpDy = (byte)this._lastUpd.Day; bytes.AddRange(lstUpYr, lstUpMn, lstUpDy); // Next comes the number of records in the table. byte[] recCnt = Hex.GetBytes(Hex.ToHex(this._recCount)); Array.Reverse(recCnt); bytes.AddRange(recCnt); // Now, the offset to the actual data. This is the header data (32 bytes), plus // the field headers (each field header is 32 bytes) plus 1 byte for the // header termination character. byte[] datOfst = Hex.GetBytes(Hex.ToHex(this._dataOffset)); Array.Reverse(datOfst); bytes.AddRange(datOfst); // Then, the size of each record in the table. byte[] recSz = Hex.GetBytes(Hex.ToHex(this._recSize)); Array.Reverse(recSz); bytes.AddRange(recSz); // Next, comes 16 "empty" bytes. byte[] empBts = new byte[16]; empBts.Initialize(); bytes.AddRange(empBts); // Then the CDX structure flag. bytes.Add(Convert.ToByte(this._cdxStruct)); // Then three (3) more "empty" bytes. empBts = new byte[3]; empBts.Initialize(); bytes.AddRange(empBts); // Finally, we write the file headers. for (int i = 0; i < this._flds.Count; i++) { bytes.AddRange(this._flds[0].GetFieldHeader()); } // Don't forget the header terminator character. bytes.Add(Convert.ToByte("0x0D")); // And... we're done ;) return(bytes.ToArray()); } catch { throw; } }
} // Read public static unsafe uint Read(this NativeReader reader, uint offset, out ByteCollection values) { values = new ByteCollection(reader, offset); uint count; offset = reader.DecodeUnsigned(offset, out count); offset = checked(offset + count * sizeof(Byte)); return offset; } // Read
internal static extern void cv_features2d_drawMatches( Arr img1, KeyPointCollection keypoints1, Arr img2, KeyPointCollection keypoints2, DMatchCollection matches1to2, Arr outImg, Scalar matchColor, Scalar singlePointColor, ByteCollection matchesMask, DrawMatchesFlags flags);
public HexElement() { this.InitializeComponent(); this.dbytes = new DynamicByteProvider(new byte[0]); this.bytes = this.dbytes.Bytes; this.hexBox1.ByteProvider = this.dbytes; this.dbytes.LengthChanged += this.dbytes_LengthChanged; this.dbytes.Changed += this.dbytes_Changed; }
} // Read public static unsafe uint Read(this NativeReader reader, uint offset, out ByteCollection values) { values = new ByteCollection(reader, offset); uint count; offset = reader.DecodeUnsigned(offset, out count); offset = checked (offset + count * sizeof(Byte)); return(offset); } // Read
private void Replace(Int32 startIndex, ByteCollection byteCollection) { this.m_FormIFFILFWSEditor.HasChanges = true; byteCollection.RemoveRange(startIndex, this.GetFindBytes().Length); if ((this.GetReplaceBytes() != null) && (this.GetReplaceBytes().Length > 0)) { byteCollection.InsertRange(startIndex, this.GetReplaceBytes()); } }
public HexElement() { InitializeComponent(); dbytes = new DynamicByteProvider(new byte[0]); bytes = dbytes.Bytes; hexBox1.ByteProvider = dbytes; dbytes.LengthChanged += dbytes_LengthChanged; dbytes.Changed += dbytes_Changed; }
private void chipSelectStripComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (chipSelectStripComboBox.SelectedItem.ToString() != lastselect) { _dataBytes = new ByteCollection((new MemoryRegion(0, (uint)s02512[chipSelectStripComboBox.SelectedItem.ToString()], 0)).Data); hexBox1.ByteProvider = new DynamicByteProvider(_dataBytes); lastselect = chipSelectStripComboBox.SelectedItem.ToString(); Text = "M24CXX DUMP " + "Empty"; } }
public byte[] GetRawHeader() { ByteCollection hdr = new ByteCollection(); foreach (DbfField fld in this.List) { hdr.AddRange(fld.GetFieldHeader()); } hdr.Add(0x0D); return(hdr.ToArray()); }
public HexDataEdit(string RecName, byte[] data, dFormIDLookupS formIDLookup) { InitializeComponent(); Icon = Resources.fomm02; this.formIDLookup = formIDLookup; tbName.Text = RecName; var dbytes = new DynamicByteProvider(data); bytes = dbytes.Bytes; hexBox1.ByteProvider = dbytes; Canceled = true; }
public HexEditor() { InitializeComponent(); var byteCollection = new ByteCollection(); _byteProvider = new DynamicByteProvider(byteCollection); _hexBox.ByteProvider = _byteProvider; _byteProvider.Changed += HandleHexBytesChangedInForm; }
public static byte[] ConvertByteCollectionToArray(this ByteCollection collection) { byte[] array = new byte[collection.Count]; int i = 0; foreach (byte b in collection) { array[i++] = b; } return(array); }
private void AT88DumpForm_DragDrop(object sender, DragEventArgs e) { string fileName = ((string[])e.Data.GetData("FileNameW"))[0]; List <MemoryRegionInfo> regionsInfo; if (dumpTabControl.SelectedTab == configDataEditorPage) { regionsInfo = new List <MemoryRegionInfo>() { new MemoryRegionInfo() { Address = 256, Size = 256, Type = 1 } }; } else { regionsInfo = new List <MemoryRegionInfo>() { new MemoryRegionInfo() { Address = 0, Size = 256, Type = 1 } }; } Action <FileWorkerIOCompleteInfo> complete = delegate(FileWorkerIOCompleteInfo info) { if (info.Error == null) { if (dumpTabControl.SelectedTab == configDataEditorPage) { _configDataBytes = new ByteCollection(info.Regions[0].Data); configDataHexBox.ByteProvider = new StaticByteProvider(_configDataBytes); } else { _userDataBytes = new ByteCollection(info.Regions[0].Data); userDataHexBox.ByteProvider = new DynamicByteProvider(_userDataBytes); } Text = "AT88 DUMP " + fileName; } else { infoPanel.SetErrorState(info.Error.Message); } }; file.Read(fileName, regionsInfo, complete); }
private void Xerox0190Form_Load(object sender, EventArgs e) { SetNoProgrammerState(); _hardwareController.DeviceInProgrammerModeDetected += HardwareController_DeviceInProgrammerModeDetected; _hardwareController.DeviceRemoved += HardwareController_DeviceRemoved; _programmersListIsRequested = true; _hardwareController.GetListOfDevicesInProgrammerMode(ProgrammersManagementProc); infoPanel.Visible = false; _dataBytes = new ByteCollection((new MemoryRegion(0, 256, 0)).Data); hexBox.ByteProvider = new DynamicByteProvider(_dataBytes); }
private void CRUM921Form_Load(object sender, EventArgs e) { SetProgrammerReadyState(); _programmer.Busy += BusyHandler; _programmer.Ready += ReadyHandler; infoPanel.Visible = false; _dataBytes = new ByteCollection((new MemoryRegion(0, 384, 0)).Data); hexBox.ByteProvider = new DynamicByteProvider(_dataBytes); }
private static byte[] ConvertByteCollectionToArray(ByteCollection collection) { byte[] array = new byte[collection.Count]; int i = 0; foreach (byte b in collection) { array[i] = b; } return(array); }
public static byte[] GetBinary(DateTime value) { ByteCollection bytes = new ByteCollection(); bytes.AddRange(Hex.GetBytes(value.ToString("yyyy"))); bytes.AddRange(Hex.GetBytes(value.ToString("MM"))); bytes.AddRange(Hex.GetBytes(value.ToString("dd"))); bytes.AddRange(Hex.GetBytes(value.ToString("HH"))); bytes.AddRange(Hex.GetBytes(value.ToString("mm"))); bytes.AddRange(Hex.GetBytes(value.ToString("ss"))); return(bytes.ToArray()); }
public HexDataEdit(string RecName, byte[] data, dFormIDLookupS formIDLookup) { this.InitializeComponent(); Icon = Resources.tesv_ico; this.formIDLookup = formIDLookup; Text += RecName; this.tbName.Text = RecName; Text += " (hex mode)"; this.dbytes = new DynamicByteProvider(data); this.bytes = this.dbytes.Bytes; this.hexBox1.ByteProvider = this.dbytes; Canceled = true; }
private void readCrumButton_Click(object sender, EventArgs e) { this.FormClosing += AT88DumpForm_FormClosing; if (_programmer.IsBusy || (_programmer == null)) { return; } List <MemoryRegionInfo> regionsInfo = new List <MemoryRegionInfo>() { new MemoryRegionInfo() { Address = 0, Size = 256, Type = 1 }, new MemoryRegionInfo() { Address = 256, Size = 256, Type = 1 } }; Action <ProgrammingCompleteInfo, List <MemoryRegion> > completed = delegate(ProgrammingCompleteInfo pcInfo, List <MemoryRegion> regions) { if (pcInfo.error != null) { infoPanel.SetErrorState(pcInfo.error.Message); } else { _userDataBytes = new ByteCollection(regions[0].Data); userDataHexBox.ByteProvider = new DynamicByteProvider(_userDataBytes); userDataHexBox.ByteProvider.Changed += HexBoxChanged; _configDataBytes = new ByteCollection(regions[1].Data); configDataHexBox.ByteProvider = new DynamicByteProvider(_configDataBytes); foreach (TabPage tp in dumpTabControl.TabPages) { sptext[tp] = "AT88 DUMP It is read from CRUM"; } Text = "AT88 DUMP " + "It is read from CRUM"; infoPanel.SetOkState("Read complete"); } this.FormClosing -= AT88DumpForm_FormClosing; }; infoPanel.SetProgressState("Reading"); _programmer.ReadChip(passwordSelectComboBox.SelectedItem.ToString(), regionsInfo, completed, infoPanel.GetProgressDelegate()); }
public static bool ComparePublicKeyOrTokens(ByteCollection keyOrToken1, bool isKey1, ByteCollection keyOrToken2, bool isKey2) { if (isKey1 != isKey2) { // Convert both to PublicKeyToken byte[] and compare byte[] token1 = ConvertByteCollectionKeyOrTokenToPublicKeyTokenByteArray(keyOrToken1, isKey1); byte[] token2 = ConvertByteCollectionKeyOrTokenToPublicKeyTokenByteArray(keyOrToken2, isKey2); if (token1.Length != token2.Length) { return(false); } for (int i = 0; i < token1.Length; i++) { if (token1[i] != token2[i]) { return(false); } } return(true); } var enum1 = keyOrToken1.GetEnumerator(); var enum2 = keyOrToken1.GetEnumerator(); while (true) { bool moveNext1 = enum1.MoveNext(); if (enum2.MoveNext() != moveNext1) { return(false); } if (moveNext1 == false) { break; } if (enum1.Current != enum2.Current) { return(false); } } return(true); }
private Int32 ReplaceAll(IFFFile.IFFNode iffNode, ref Int32 replacements) { ByteCollection byteCollection = new ByteCollection(iffNode.Data); Int32 startIndex = this.Find(iffNode); Int32 lastStartIndex = -1; while (startIndex >= 0) { this.Replace(startIndex, byteCollection); replacements++; lastStartIndex = startIndex; startIndex = this.Find(iffNode, (startIndex + ((this.GetReplaceBytes() != null) ? this.GetReplaceBytes().Length : 0))); } iffNode.Data = byteCollection.ToArray(); return(lastStartIndex); }
private static RuntimeAssemblyName CreateRuntimeAssemblyNameFromMetadata( MetadataReader reader, ConstantStringValueHandle name, ushort majorVersion, ushort minorVersion, ushort buildNumber, ushort revisionNumber, ConstantStringValueHandle culture, ByteCollection publicKeyOrToken, global::Internal.Metadata.NativeFormat.AssemblyFlags assemblyFlags) { AssemblyNameFlags assemblyNameFlags = AssemblyNameFlags.None; if (0 != (assemblyFlags & global::Internal.Metadata.NativeFormat.AssemblyFlags.PublicKey)) { assemblyNameFlags |= AssemblyNameFlags.PublicKey; } if (0 != (assemblyFlags & global::Internal.Metadata.NativeFormat.AssemblyFlags.Retargetable)) { assemblyNameFlags |= AssemblyNameFlags.Retargetable; } int contentType = ((int)assemblyFlags) & 0x00000E00; assemblyNameFlags |= (AssemblyNameFlags)contentType; ArrayBuilder <byte> keyOrTokenArrayBuilder = new ArrayBuilder <byte>(); foreach (byte b in publicKeyOrToken) { keyOrTokenArrayBuilder.Add(b); } return(new RuntimeAssemblyName( name.GetString(reader), new Version(majorVersion, minorVersion, buildNumber, revisionNumber), culture.GetStringOrNull(reader), assemblyNameFlags, keyOrTokenArrayBuilder.ToArray() )); }
private void openFileMenuItem_Click(object sender, EventArgs e) { //openFileDialog.Filter = "hex files (*.hex)|*.hex|bin files (*.bin)|*.bin|ponyprog files (*.eep;*.e2p;*.rom)|*.eep;*.e2p;*.rom"; openFileDialog.Filter = "dump files (.hex .bin .eep .e2p .rom)|*.hex;*.bin;*.eep;*.e2p;*.rom"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = false; openFileDialog.FileName = ""; if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } List <MemoryRegionInfo> regionsInfo = new List <MemoryRegionInfo>() { new MemoryRegionInfo() { Address = 0, Size = 256, Type = 1 } }; Action <FileWorkerIOCompleteInfo> complete = delegate(FileWorkerIOCompleteInfo info) { if (info.Error == null) { Text = "XEROX 01/90 DUMP " + openFileDialog.FileName; _dataBytes = new ByteCollection(info.Regions[0].Data); hexBox.ByteProvider = new DynamicByteProvider(_dataBytes); hexBox.ByteProvider.Changed += HexBoxChanged; } else { infoPanel.SetErrorState(info.Error.Message); } }; file.Read(openFileDialog.FileName, regionsInfo, complete); }
public static byte[] ToArray(this ByteCollection collection, Type enumType = null) { int count = collection.Count; byte[] result; if (enumType != null) { Debug.Assert(enumType.IsEnum); result = (byte[])Array.CreateInstance(enumType, count); } else { result = new byte[count]; } int i = 0; foreach (byte element in collection) { result[i++] = element; } Debug.Assert(i == count); return(result); }
private void readChipStripButton_Click(object sender, EventArgs e) { this.FormClosing += Xerox0190Form_FormClosing; if (_programmer.IsBusy || (_programmer == null)) { return; } MemoryRegionInfo regionInfo = new MemoryRegionInfo(); regionInfo.Address = 0; regionInfo.Type = 1; regionInfo.Size = 256; Action <ProgrammingCompleteInfo, MemoryRegion> completed = delegate(ProgrammingCompleteInfo pcInfo, MemoryRegion region) { if (pcInfo.error != null) { infoPanel.SetErrorState(pcInfo.error.Message); } else { _dataBytes = new ByteCollection(region.Data); hexBox.ByteProvider = new DynamicByteProvider(_dataBytes); hexBox.ByteProvider.Changed += HexBoxChanged; Text = "XEROX 01/90 DUMP " + "It is read from CRUM"; infoPanel.SetOkState("Read complete"); } this.FormClosing -= Xerox0190Form_FormClosing; }; infoPanel.SetProgressState("Reading"); _programmer.ReadChip("Mode 0", regionInfo, completed, infoPanel.GetProgressDelegate()); }
private void OpenConfigDataFileMenuItem_Click(object sender, EventArgs e) { //openFileDialog.Filter = "hex files (*.hex)|*.hex|bin files (*.bin)|*.bin"; openFileDialog.Filter = "dump files (.hex .bin .eep .e2p .rom)|*.hex;*.bin;*.eep;*.e2p;*.rom"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = false; openFileDialog.FileName = ""; if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } //List<MemoryRegion> regions = new List<MemoryRegion>() { new MemoryRegion(0x100, 256, 3) }; //List<MemoryRegionInfo> regionsInfo = new List<MemoryRegionInfo>() { regions[0].GetRegionInfo() }; List <MemoryRegionInfo> regionsInfo = new List <MemoryRegionInfo>() { new MemoryRegionInfo() { Address = 256, Size = 256, Type = 1 } }; Action <FileWorkerIOCompleteInfo> complete = delegate(FileWorkerIOCompleteInfo info) { if (info.Error == null) { _configDataBytes = new ByteCollection(info.Regions[0].Data); configDataHexBox.ByteProvider = new StaticByteProvider(_configDataBytes); Text = "AT88 DUMP " + openFileDialog.FileName; } else { infoPanel.SetErrorState(info.Error.Message); } }; file.Read(openFileDialog.FileName, regionsInfo, complete); }
static void Main(string[] args) { ByteCollection list1 = new ByteCollection(); for (int i = 0; i < 9; i++) { // list1.Add(i); // This isn't compiled list1.Add((byte)i); } foreach (byte i in list1) { Console.WriteLine(" {0} ", i); } Console.WriteLine(); CharCollection list2 = new CharCollection(); // list2.Add(5); // This isn't compiled list2.Add('a'); list2.Add('b'); list2.Add('c'); list2.Add('d'); list2.Add('e'); list2.Add('f'); foreach (char i in list2) { Console.WriteLine(" {0} ", i); } Console.ReadKey(); }
public HexEditor(ByteCollection collection) { //Set String format for the hex values _stringFormat = new StringFormat(StringFormat.GenericTypographic); _stringFormat.Alignment = StringAlignment.Center; _stringFormat.LineAlignment = StringAlignment.Center; //Set the provided byte collection _hexTable = collection; //Set the vertical scrollbar _vScrollBar = new VScrollBar(); _vScrollBar.Scroll += new ScrollEventHandler(OnVScrollBarScroll); //Redraw whenever the control is resized SetStyle(ControlStyles.ResizeRedraw, true); //Enable double buffering SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); //Enable selectable SetStyle(ControlStyles.Selectable, true); //Handle initialization of Caret _caret = new Caret(this); _caret.SelectionStartChanged += new EventHandler(CaretSelectionStartChanged); _caret.SelectionLengthChanged += new EventHandler(CaretSelectionLengthChanged); //Create the needed edit view _editView = new EditView(this); _handler = _editView; //Set defualt cursor this.Cursor = Cursors.IBeam; }
public byte[] GetRawHeader() { ByteCollection hdr = new ByteCollection(); foreach (DbfField fld in this.List) hdr.AddRange(fld.GetFieldHeader()); hdr.Add(0x0D); return hdr.ToArray(); }
/// <summary> /// Reads a byte array from the stream. /// </summary> public ByteCollection ReadByteArray(string fieldName) { bool isNil = false; ByteCollection values = new ByteCollection(); if (BeginField(fieldName, true, out isNil)) { PushNamespace(Namespaces.OpcUaXsd); while (MoveToElement("Byte")) { values.Add(ReadByte("Byte")); } // check the length. if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count) { throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded); } PopNamespace(); EndField(fieldName); return values; } if (isNil) { return null; } return values; }
private static byte[] ConvertByteCollectionOfPublicKeyToByteArrayOfPublicKeyToken(ByteCollection publicKeyCollection) { byte[] publicKey = ConvertByteCollectionToArray(publicKeyCollection); return AssemblyNameHelpers.ComputePublicKeyToken(publicKey); }
public byte[] GetMemoField(long row, int col) { // Make sure the user didn't select a field outside the bounds of the table. if (row < 0 || row > _hdr.RecordCount) throw new ArgumentOutOfRangeException("Requested row was greater than the length of the table.", "row"); if (col < 0 || col > _hdr.Fields.Count) throw new ArgumentOutOfRangeException("Requested field is outside the bounds of the record.", "col"); if (_hdr.Fields[col].FieldDataType != DbfHeader.dBaseFieldType.Memo) throw new ArgumentException("The selected field is not of type 'Memo'.", "col"); // We also want to check & make sure the file exists. if (!File.Exists(this.MemoFile)) throw new FileNotFoundException("The table's DBT file could not be found.", this.MemoFile); byte[] retData = null; using (FileStream fs = new FileStream(this.MemoFile, FileMode.Open, FileAccess.Read)) using (BinaryReader br = new BinaryReader(fs)) { // First thing we have to do is determine the offset of the block // we want to read. // dBASEIV files can have custom-sized blocks, so we get that from // the header first. int blockSize = 0; if (_hdr.TypeID == DbfHeader.dBaseType.Dbf3WithMemo) { br.ReadBytes(20); byte[] bl = br.ReadBytes(2); Array.Reverse(bl); blockSize = Convert.ToInt32(Hex.ToHex(bl), 16) * 512; br.ReadBytes(490); } else { blockSize = 512; br.ReadBytes(512); } // Now we can find the actual offset. We've already skipped the header, // so we don't have to include that in the offset. int offset = (Convert.ToInt32(this.GetValue(row, col)) - 1) * blockSize; br.ReadBytes(offset); // The first 8 bytes of data are header info. // The first 4 are reserved and always FF FF 08 00. br.ReadBytes(4); // The next 4 indicate the size of the memo field // with the usuall reversed bit array. byte[] btLen = br.ReadBytes(4); Array.Reverse(btLen); int fLen = Convert.ToInt32(Hex.ToHex(btLen), 16); // The stored length includes the 8 bytes for the header, so we // remove those from the total data length. retData = br.ReadBytes(fLen - 8); // Now we need to replace all the 0x08 carriage return bytes with the // standard Windows carriage return/line feed bytes, and make sure // the byte array terminates when the 'End of File' byte (0x0A) is // reached. ByteCollection bts = new ByteCollection(); for (int i = 0; i < retData.Length; i++) if (retData[i] == 0x0A && (i < retData.Length - 1 && retData[i + 1] == 0x0A)) break; //else if (retData[i] == 0x08) //{ // bts.Add(Convert.ToByte('\r')); // bts.Add(Convert.ToByte('\n')); //} else bts.Add(retData[i]); // And then we pump are 'corrected' byte array back into our variable // to return. retData = bts.ToArray(); //retData = new byte[bts.Count]; //for (int i = 0; i < retData.Length; i++) // retData[i] = (byte)bts[i]; } return retData; }
private Int32 ReplaceAll(IFFFile.IFFNode iffNode, ref Int32 replacements) { ByteCollection byteCollection = new ByteCollection(iffNode.Data); Int32 startIndex = this.Find(iffNode); Int32 lastStartIndex = -1; while (startIndex >= 0) { this.Replace(startIndex, byteCollection); replacements++; lastStartIndex = startIndex; startIndex = this.Find(iffNode, (startIndex + ((this.GetReplaceBytes() != null) ? this.GetReplaceBytes().Length : 0))); } iffNode.Data = byteCollection.ToArray(); return lastStartIndex; }
private static byte[] ConvertByteCollectionToArray(ByteCollection collection) { byte[] array = new byte[collection.Count]; int i = 0; foreach (byte b in collection) array[i] = b; return array; }
private static byte[] ConvertByteCollectionKeyOrTokenToPublicKeyTokenByteArray(ByteCollection publicKeyOrToken, bool isKey) { if (isKey) return ConvertByteCollectionOfPublicKeyToByteArrayOfPublicKeyToken(publicKeyOrToken); else return ConvertByteCollectionToArray(publicKeyOrToken); }
private static byte[] ConvertByteCollectionKeyOrTokenToPublicKeyTokenByteArray(ByteCollection publicKeyOrToken, bool isKey) { if (isKey) { return(ConvertByteCollectionOfPublicKeyToByteArrayOfPublicKeyToken(publicKeyOrToken)); } else { return(Internal.TypeSystem.NativeFormat.MetadataExtensions.ConvertByteCollectionToArray(publicKeyOrToken)); } }
/// <summary> /// Reads a byte array from the stream. /// </summary> public ByteCollection ReadByteArray(string fieldName) { var values = new ByteCollection(); List<object> token = null; if (!ReadArrayField(fieldName, out token)) { return values; } for (int ii = 0; ii < token.Count; ii++) { try { m_stack.Push(token[ii]); values.Add(ReadByte(null)); } finally { m_stack.Pop(); } } return values; }
/// <summary> /// Reads a byte array from the stream. /// </summary> public ByteCollection ReadByteArray(string fieldName) { int length = ReadArrayLength(); if (length == -1) { return null; } ByteCollection values = new ByteCollection(length); for (int ii = 0; ii < length; ii++) { values.Add(ReadByte(null)); } return values; }
public static byte[] GetBinary(DateTime value) { ByteCollection bytes = new ByteCollection(); bytes.AddRange(Hex.GetBytes(value.ToString("yyyy"))); bytes.AddRange(Hex.GetBytes(value.ToString("MM"))); bytes.AddRange(Hex.GetBytes(value.ToString("dd"))); bytes.AddRange(Hex.GetBytes(value.ToString("HH"))); bytes.AddRange(Hex.GetBytes(value.ToString("mm"))); bytes.AddRange(Hex.GetBytes(value.ToString("ss"))); return bytes.ToArray(); }
/// <summary> /// Initializes a new instance of the DynamicByteProvider class. /// </summary> /// <param name="byteCollection"></param> public DynamicProvider(ByteCollection byteCollection) { bytes = byteCollection; }
/// <summary> /// Returns this DBF header in it's original raw binary data form. /// </summary> /// <returns>An Array of type System.Byte[]</returns> public byte[] GetDbfHeader() { try { ByteCollection bytes = new ByteCollection(32 + this._flds.Count * 32); // Keep the same file type ID. bytes.Add(this._id); // Then we right the last time the DBF was updated. byte lstUpYr = (byte)(this._lastUpd.Year - 1900), lstUpMn = (byte)this._lastUpd.Month, lstUpDy = (byte)this._lastUpd.Day; bytes.AddRange(lstUpYr, lstUpMn, lstUpDy); // Next comes the number of records in the table. byte[] recCnt = Hex.GetBytes(Hex.ToHex(this._recCount)); Array.Reverse(recCnt); bytes.AddRange(recCnt); // Now, the offset to the actual data. This is the header data (32 bytes), plus // the field headers (each field header is 32 bytes) plus 1 byte for the // header termination character. byte[] datOfst = Hex.GetBytes(Hex.ToHex(this._dataOffset)); Array.Reverse(datOfst); bytes.AddRange(datOfst); // Then, the size of each record in the table. byte[] recSz = Hex.GetBytes(Hex.ToHex(this._recSize)); Array.Reverse(recSz); bytes.AddRange(recSz); // Next, comes 16 "empty" bytes. byte[] empBts = new byte[16]; empBts.Initialize(); bytes.AddRange(empBts); // Then the CDX structure flag. bytes.Add(Convert.ToByte(this._cdxStruct)); // Then three (3) more "empty" bytes. empBts = new byte[3]; empBts.Initialize(); bytes.AddRange(empBts); // Finally, we write the file headers. for (int i = 0; i < this._flds.Count; i++) bytes.AddRange(this._flds[0].GetFieldHeader()); // Don't forget the header terminator character. bytes.Add(Convert.ToByte("0x0D")); // And... we're done ;) return bytes.ToArray(); } catch { throw; } }
public static bool ComparePublicKeyOrTokens(ByteCollection keyOrToken1, bool isKey1, ByteCollection keyOrToken2, bool isKey2) { if (isKey1 != isKey2) { // Convert both to PublicKeyToken byte[] and compare byte[] token1 = ConvertByteCollectionKeyOrTokenToPublicKeyTokenByteArray(keyOrToken1, isKey1); byte[] token2 = ConvertByteCollectionKeyOrTokenToPublicKeyTokenByteArray(keyOrToken2, isKey2); if (token1.Length != token2.Length) return false; for (int i = 0; i < token1.Length; i++) { if (token1[i] != token2[i]) return false; } return true; } var enum1 = keyOrToken1.GetEnumerator(); var enum2 = keyOrToken1.GetEnumerator(); while (true) { bool moveNext1 = enum1.MoveNext(); if (enum2.MoveNext() != moveNext1) return false; if (moveNext1 == false) break; if (enum1.Current != enum2.Current) return false; } return true; }