public static bool WriteBIN(DeviceFilterClass devFilter, string fileName) { bool flag; try { using (FileStream stream = File.Create(fileName)) { binWriter = new BinaryWriter(stream); binWriter.Write(0x17042013); binWriter.Write(ConversionUtils.BytesToHexString(Encoding.UTF8.GetBytes(devFilter._displayName))); binWriter.Write(ConversionUtils.BytesToHexString(Encoding.UTF8.GetBytes(devFilter._partToDisp))); binWriter.Write(ConversionUtils.BytesToHexString(Encoding.UTF8.GetBytes(devFilter._description))); binWriter.Write(0x30091989); binWriter.Close(); } flag = true; } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Exception exception = exception1; Interaction.MsgBox("Error writing binary file!", MsgBoxStyle.Critical, null); flag = false; ProjectData.ClearProjectError(); } return(flag); }
public static byte[] FlipByteArray(byte[] inByteArray) { byte[] testBytes; try { string strInput = ""; string str = ConversionUtils.BytesToHexString(inByteArray); int num2 = str.Length - 1; for (int i = 0; i <= num2; i++) { string str3 = FlipByteBitsToString(Conversions.ToString(str[i])); string str4 = FlipByteBitsToString(Conversions.ToString(str[i + 1])); strInput = strInput + str4 + str3; i++; } testBytes = ConversionUtils.HexStringToBytes(strInput); } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Interaction.MsgBox("Error Flipping Byte Array!", MsgBoxStyle.Critical, null); testBytes = CRC.testBytes; ProjectData.ClearProjectError(); } return(testBytes); }
public static byte[] InvertBytes(byte[] inByte) { long num = (long)Math.Round(Conversion.Val("&H" + ConversionUtils.BytesToHexString(inByte))); byte[] bytes = BitConverter.GetBytes((long)(-1L ^ num)); return(new byte[] { bytes[1], bytes[0] }); }
public override object Decode() { if (this.CurrentQCDMCommand == Qcdm.Cmd.DIAG_NV_READ_F) { return(ConversionUtils.BytesToHexString(HelperUtils.GetByteArray(this.BytesRX, 3, 7))); } if (this.CurrentQCDMCommand == Qcdm.Cmd.DIAG_NV_WRITE_F) { return(ConversionUtils.BytesToHexString(this.BytesRX)); } return("-1"); }
public NVItem(Command cmd) { try { string str2; string str3; if (cmd.ErrorResponse == Qcdm.NV_Response.NV_ERR_BAD_SECURITY_MODE) { str2 = ConversionUtils.BytesToHexString(cmd.BytesTX).Substring(4, 2); str3 = ConversionUtils.BytesToHexString(cmd.BytesTX).Substring(2, 2); } else { str2 = ConversionUtils.BytesToHexString(cmd.BytesRX).Substring(4, 2); str3 = ConversionUtils.BytesToHexString(cmd.BytesRX).Substring(2, 2); } long num = long.Parse(str2 + str3, NumberStyles.HexNumber); this._itemNumber = num; if (cmd.ErrorResponse == Qcdm.NV_Response.NV_ERR_BAD_PARAM) { this._itemStatus = NVStatus.BadParameter; this._itemData = ""; } else if (cmd.ErrorResponse == Qcdm.NV_Response.NV_ERR_BAD_SECURITY_MODE) { this._itemStatus = NVStatus.AccessDenied; this._itemData = ""; } else if (cmd.ErrorResponse == Qcdm.NV_Response.NV_ERR_INACTIVE_NV_ITEM) { this._itemStatus = NVStatus.InactiveItem; this._itemData = ""; } else { this._itemStatus = NVStatus.Okay; } if (this._itemStatus == NVStatus.Okay) { this._itemData = ConversionUtils.BytesToHexString(cmd.BytesRX).Substring(6, 0x100); } } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Exception exception = exception1; Interaction.MsgBox("Error Parsing NV Item!", MsgBoxStyle.Critical, null); ProjectData.ClearProjectError(); } }
public override object Decode() { using (MemoryStream stream = new MemoryStream(this.BytesRX)) { using (BinaryReader reader = new BinaryReader(stream)) { if (stream.Length <= 3L) { return(new DIAG_VERNO_F_CLS("-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1")); } reader.BaseStream.Position = 1L; this.compileDate = ConversionUtils.GetASCIIString(reader.ReadBytes(11)); this.compileTime = ConversionUtils.GetASCIIString(reader.ReadBytes(8)); this.releaseDate = ConversionUtils.GetASCIIString(reader.ReadBytes(11)); this.releaseTime = ConversionUtils.GetASCIIString(reader.ReadBytes(8)); this.verDir = ConversionUtils.GetASCIIString(reader.ReadBytes(8)); this.stationClassMark = Conversions.ToString(reader.ReadByte()); if (File.Exists(this.fileMobCAIRev)) { this.mobCAIRev = HelperUtils.GetEnumValue(reader.ReadByte(), this.fileMobCAIRev, EnumFileParser.ParseType.Dec); } else { this.mobCAIRev = Conversions.ToString(reader.ReadByte()); } if (File.Exists(this.fileMobModel)) { this.mobModel = HelperUtils.GetEnumValue(reader.ReadByte(), this.fileMobModel, EnumFileParser.ParseType.Dec); } else { this.mobModel = Conversions.ToString(reader.ReadByte()); } this.mobFWRev = Conversions.ToString((int)reader.ReadInt16()); this.slotCycleIndex = reader.ReadByte().ToString(); if (File.Exists(this.fileMSMRev)) { this.msmRev = HelperUtils.GetEnumValue(ConversionUtils.BytesToHexString(reader.ReadBytes(2).Reverse <byte>().ToArray <byte>()), this.fileMSMRev, EnumFileParser.ParseType.Hex); } else { this.msmRev = "0x" + ConversionUtils.BytesToHexString(reader.ReadBytes(2).Reverse <byte>().ToArray <byte>()); } return(new DIAG_VERNO_F_CLS(this.compileDate, this.compileTime, this.releaseDate, this.releaseTime, this.verDir, this.stationClassMark, this.mobCAIRev, this.mobModel, this.mobFWRev, this.slotCycleIndex, this.msmRev)); } } }
public override object Decode() { using (MemoryStream stream = new MemoryStream(this.BytesRX)) { using (BinaryReader reader = new BinaryReader(stream)) { if (stream.Length <= 3L) { return(new DIAG_EXT_BUILD_ID_F_CLS("-1", "-1", "-1")); } reader.BaseStream.Position = 1L; byte[] byteInput = reader.ReadBytes(3).Reverse <byte>().ToArray <byte>(); this.reserved = "0x00" + ConversionUtils.BytesToHexString(byteInput); byteInput = BitConverter.GetBytes(reader.ReadInt32()).Reverse <byte>().ToArray <byte>(); if (File.Exists(this.fileMSMHWRev)) { this.msmHWRev = HelperUtils.GetEnumValue(ConversionUtils.BytesToHexString(byteInput), this.fileMSMHWRev, EnumFileParser.ParseType.Hex); } else { this.msmHWRev = "0x" + ConversionUtils.BytesToHexString(byteInput); } if (File.Exists(this.fileMobModelID)) { this.mobModelID = HelperUtils.GetEnumValue(reader.ReadInt32(), this.fileMobModelID, EnumFileParser.ParseType.Dec); } else { this.mobModelID = Conversions.ToString(reader.ReadInt32()); } List <byte> list = new List <byte>(); while (reader.BaseStream.Position < (reader.BaseStream.Length - 1L)) { byte num = reader.ReadByte(); if (Convert.ToChar(num) == '\0') { break; } list.Add(num); } this.mobSWRev = ConversionUtils.GetASCIIString(list.ToArray()); return(new DIAG_EXT_BUILD_ID_F_CLS(this.msmHWRev, this.mobModelID, this.mobSWRev)); } } }
public override object Decode() { object obj2; try { string str = ConversionUtils.BytesToHexString(this.BytesRX); string str2 = ""; obj2 = str2 + Conversions.ToString(str[7]) + Conversions.ToString(str[9]) + Conversions.ToString(str[11]) + Conversions.ToString(str[13]); } catch (Exception exception1) { ProjectData.SetProjectError(exception1); obj2 = "-1"; ProjectData.ClearProjectError(); } return(obj2); }
public override object Decode() { object obj2; try { if (this.BytesRX[0] == 0x42) { Interaction.MsgBox("Error! SPC Not Found!", MsgBoxStyle.Critical, null); return("-1"); } string str = ConversionUtils.BytesToHexString(this.BytesRX); string str2 = ""; obj2 = str2 + Conversions.ToString(str[7]) + Conversions.ToString(str[9]) + Conversions.ToString(str[11]) + Conversions.ToString(str[13]) + Conversions.ToString(str[15]) + Conversions.ToString(str[0x11]); } catch (Exception exception1) { ProjectData.SetProjectError(exception1); obj2 = "-1"; ProjectData.ClearProjectError(); } return(obj2); }
private void ProcessCommandQueue(AsyncOperation asyncOp) { this._isBusy = true; this._commandOutput = new ArrayList(); long count = this.GetCount(); long num2 = 0L; long position = 0L; string consoleTX = string.Empty; string consoleRX = string.Empty; string consoleRXASCII = string.Empty; Exception exc = null; try { object syncRoot = this.cmdQueue.SyncRoot; ObjectFlowControl.CheckForSyncLockOnValueType(syncRoot); lock (syncRoot) { while (this.cmdQueue.Count != 0) { if (this.Cancelled()) { this.CompletionMethod(null, true, asyncOp); return; } Command command = (Command)this.cmdQueue.Dequeue(); this._qcdmCmd.Add(command.CurrentQCDMCommand); this._nvCmd.Add(command.CurrentNVItem); if (!command.TransmitTX(this._instance, asyncOp)) { throw new Exception("Phone connection has been lost!"); } object objectValue = RuntimeHelpers.GetObjectValue(command.Decode()); if (command.BytesRX.Length == 0x88) { this._errorResponse.Add((Qcdm.NV_Response)command.BytesRX[0x83]); } else if (command.BytesRX.Length == 0x89) { this._errorResponse.Add((Qcdm.NV_Response)command.BytesRX[0x84]); } else if (command.BytesRX.Length < 0x88) { this._errorResponse.Add((Qcdm.NV_Response)command.BytesRX[0]); } if (objectValue == null) { throw new Exception("Error decoding command output!"); } this._commandOutput.Add(RuntimeHelpers.GetObjectValue(objectValue)); if (!this._disableLogging && !string.IsNullOrEmpty(command.ConsoleOutput)) { consoleTX = ConversionUtils.FormatHexStr(ConversionUtils.BytesToHexString(command.BytesTX)); consoleRX = ConversionUtils.FormatHexStr(ConversionUtils.BytesToHexString(command.BytesRX)); consoleRXASCII = ConversionUtils.GetASCIIString(command.BytesRX); } position += 1L; CommandQueueProgressChangedEventArgs arg = new CommandQueueProgressChangedEventArgs(command.ConsoleOutput, consoleTX, consoleRX, consoleRXASCII, (int)command.CurrentNVItem, (int)position, (int)count, (int)Math.Round((double)((((float)position) / ((float)count)) * 100f)), RuntimeHelpers.GetObjectValue(asyncOp.UserSuppliedState)); asyncOp.Post(this.onProgressReportDelegate, arg); } } if (this._chkNVItems) { position = 0L; long badParamNVItems = 0L; long badSecNVItems = 0L; long inactiveNVItems = 0L; long okayNVItems = 0L; object expression = this.cmdNVQueue.SyncRoot; ObjectFlowControl.CheckForSyncLockOnValueType(expression); lock (expression) { IEnumerator enumerator; try { enumerator = this.cmdNVQueue.GetEnumerator(); while (enumerator.MoveNext()) { byte num6; Command current = (Command)enumerator.Current; if (this.Cancelled()) { this.CompletionMethod(null, true, asyncOp); return; } if (current.BytesRX.Length == 0x88) { num6 = current.BytesRX[0x83]; } else if (current.BytesRX.Length == 0x89) { num6 = current.BytesRX[0x84]; } else if (current.BytesRX.Length < 0x88) { num6 = current.BytesRX[0]; } if (((num6 == 20) | (num6 == 5)) | (num6 == 6)) { current.ErrorResponse = (Qcdm.NV_Response)num6; num2 += 1L; } } } finally { if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } } object obj5 = this.cmdNVQueue.SyncRoot; ObjectFlowControl.CheckForSyncLockOnValueType(obj5); lock (obj5) { IEnumerator enumerator2; if (string.IsNullOrEmpty(this._fileName)) { throw new FileNotFoundException(); } StreamWriter writer = new StreamWriter(this.FileName, false); writer.Write("[NV items]\r\n"); writer.Write(("[Complete items - " + ((count - num2)).ToString() + ", Items size - 128]") + "\r\n\r\n"); try { enumerator2 = this.cmdNVQueue.GetEnumerator(); while (enumerator2.MoveNext()) { string str6; Command command3 = (Command)enumerator2.Current; List <string> list = new List <string>(); if (command3.BytesRX[0] == 20) { str6 = ConversionUtils.BytesToHexString(command3.BytesTX).Substring(2, 4); } else { str6 = ConversionUtils.BytesToHexString(command3.BytesRX).Substring(2, 4); } string s = ConversionUtils.ReverseHex(str6).Replace(" ", ""); long num9 = long.Parse(s, NumberStyles.HexNumber); if (command3.ErrorResponse == Qcdm.NV_Response.NV_ERR_BAD_PARAM) { writer.Write((num9.ToString("d5") + " (0x" + s + ") - Parameter bad") + "\r\n\r\n"); badParamNVItems += 1L; } else if (command3.ErrorResponse == Qcdm.NV_Response.NV_ERR_BAD_SECURITY_MODE) { writer.Write((num9.ToString("d5") + " (0x" + s + ") - Access denied") + "\r\n\r\n"); badSecNVItems += 1L; } else if (command3.ErrorResponse == Qcdm.NV_Response.NV_ERR_INACTIVE_NV_ITEM) { writer.Write((num9.ToString("d5") + " (0x" + s + ") - Inactive item") + "\r\n\r\n"); inactiveNVItems += 1L; } else { string str11 = ConversionUtils.BytesToHexString(command3.BytesRX).Substring(6, 0x100); writer.Write((num9.ToString("d5") + " (0x" + s + ") - OK") + "\r\n"); writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0, 0x20)) + "\r\n"); writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x20, 0x20)) + "\r\n"); writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x40, 0x20)) + "\r\n"); writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x60, 0x20)) + "\r\n"); writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x40, 0x20)) + "\r\n"); writer.Write(ConversionUtils.FormatHexStr(str11.Substring(80, 0x20)) + "\r\n"); writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x60, 0x20)) + "\r\n"); writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x80, 0x20)) + "\r\n\r\n"); okayNVItems += 1L; } position += 1L; NVItemsStatusEventArgs args2 = new NVItemsStatusEventArgs(position, badParamNVItems, badSecNVItems, inactiveNVItems, okayNVItems, count, (long)Math.Round((double)((((float)position) / ((float)count)) * 100f))); asyncOp.Post(this.onNVItemsStatusDelegate, args2); } } finally { if (enumerator2 is IDisposable) { (enumerator2 as IDisposable).Dispose(); } } writer.Close(); } } } catch (Exception exception1) { ProjectData.SetProjectError(exception1); exc = exception1; ProjectData.ClearProjectError(); } this.CompletionMethod(exc, this.Cancelled(), asyncOp); }
public static string GetCRCAsStringFromString(string incomingString) { CDMACRC cdmacrc = new CDMACRC(CDMACRC.InitialCrcValue.NonZero1); return(ConversionUtils.BytesToHexString(FlipByteArray(InvertBytes(cdmacrc.ComputeChecksumBytes(FlipByteArray(ConversionUtils.HexStringToBytes(incomingString))))))); }