public Command WriteNVItem(int item, string value) { string strConsoleOut = "DIAG_NV_WRITE - Item: " + item.ToString(); byte[] commandPrefixArray = ConversionUtils.HexStringToBytes("27" + this.ProcessNVItem(item, 4) + value); return(new Command(HelperUtils.BuildTermCommand(CommandByteArrays.nullCmd_133_length, commandPrefixArray, HelperUtils.BuildDataArray("0")), strConsoleOut)); }
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[] GenerateNSizeArray(int n) { string strInput = ""; int num2 = n; for (int i = 0; i <= num2; i++) { strInput = strInput + "00"; } return(ConversionUtils.HexStringToBytes(strInput)); }
public static bool ReadBIN(string fileName, ref DeviceFilterClass devFilter) { bool flag; try { string str; string str2; string str3; using (FileStream stream = File.OpenRead(fileName)) { binReader = new BinaryReader(stream); if (binReader.ReadInt32() != 0x17042013) { Interaction.MsgBox("Device Filter contains an invalid header!", MsgBoxStyle.Critical, null); return(false); } str2 = Encoding.UTF8.GetString(ConversionUtils.HexStringToBytes(binReader.ReadString())); str3 = Encoding.UTF8.GetString(ConversionUtils.HexStringToBytes(binReader.ReadString())); str = Encoding.UTF8.GetString(ConversionUtils.HexStringToBytes(binReader.ReadString())); binReader.BaseStream.Position = binReader.BaseStream.Length - 4L; if (binReader.ReadInt32() != 0x30091989) { Interaction.MsgBox("Device Filter contains an invalid signature!", MsgBoxStyle.Critical, null); return(false); } binReader.Close(); } devFilter = new DeviceFilterClass(fileName, str2, str3, str); flag = true; } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Exception exception = exception1; Interaction.MsgBox("Error reading binary file!", MsgBoxStyle.Critical, null); flag = false; ProjectData.ClearProjectError(); } return(flag); }
public Command ReadNVItem(int item) { string strConsoleOut = "DIAG_NV_WRITE - Item: " + item.ToString(); byte[] buffer3 = new byte[3]; byte[] buffer2 = ConversionUtils.HexStringToBytes("26" + this.ProcessNVItem(item, 6)); List <byte> list = new List <byte>(); foreach (byte num in buffer2) { list.Add(num); } while (list.Count < 0x85) { list.Add(0); } byte[] cRCAsByteFromByte = CRC.GetCRCAsByteFromByte(list.ToArray()); list.Add(cRCAsByteFromByte[0]); list.Add(cRCAsByteFromByte[1]); list.Add(0x7e); return(new Command(list.ToArray(), strConsoleOut)); }
public static string GetCRCAsStringFromString(string incomingString) { CDMACRC cdmacrc = new CDMACRC(CDMACRC.InitialCrcValue.NonZero1); return(ConversionUtils.BytesToHexString(FlipByteArray(InvertBytes(cdmacrc.ComputeChecksumBytes(FlipByteArray(ConversionUtils.HexStringToBytes(incomingString))))))); }
public static byte[] GetBufferWithCRC(string s) => GetBufferWithCRC(ConversionUtils.HexStringToBytes(s), (int)Math.Round((double)(((double)s.Length) / 2.0)));
public void DoRestoreNVItems() { long position = 0L; long totalLength = 0L; int num = 0; int num2 = 0; int num4 = 0; int num5 = 0; StreamReader reader = new StreamReader(this._writeNVItems.FileName); ArrayList list = new ArrayList(); totalLength = reader.BaseStream.Length; while (reader.Peek() != -1) { string str = reader.ReadLine(); if (str.Contains("Parameter bad")) { num++; } else if (str.Contains("Access denied")) { num2++; } else if (str.Contains("Inactive item")) { num4++; } else if (str.Contains("OK")) { num5++; } list.Add(str); position = reader.BaseStream.Position; NVItemsStatusEventArgs arg = new NVItemsStatusEventArgs(position, (long)num, (long)num2, (long)num4, (long)num5, totalLength, (long)Math.Round((double)((((float)position) / ((float)totalLength)) * 100f))); this._asyncOp.Post(this.onNVItemsStatusDelegate, arg); } reader.Close(); this._writeNVItems.Dispose(); if (Operators.ConditionalCompareObjectEqual(list[0], "[NV items]", false)) { int num9 = list.Count - 1; for (int i = 3; i <= num9; i++) { string left = ""; string strInput = ""; string str2 = ""; int num10 = Conversions.ToInteger(Operators.SubtractObject(NewLateBinding.LateGet(list[i], null, "IndexOf", new object[] { "(" }, null, null, null), 1)); for (int j = 0; j <= num10; j++) { left = Conversions.ToString(Operators.AddObject(left, NewLateBinding.LateIndexGet(list[i], new object[] { j }, null))); } if (list[i].ToString().Contains("OK")) { if (list[i + 1].ToString().Contains("|")) { str2 = list[i + 1].ToString(); strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]); str2 = list[i + 2].ToString(); strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]); str2 = list[i + 3].ToString(); strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]); str2 = list[i + 4].ToString(); strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]); str2 = list[i + 5].ToString(); strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]); str2 = list[i + 6].ToString(); strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]); str2 = list[i + 7].ToString(); strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]); str2 = list[i + 8].ToString(); strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]); } else { strInput = (((strInput + list[i + 1].ToString() + list[i + 2].ToString()) + list[i + 3].ToString() + list[i + 4].ToString()) + list[i + 5].ToString() + list[i + 6].ToString()) + list[i + 7].ToString() + list[i + 8].ToString(); } strInput = strInput.Replace(" ", ""); string strConsoleOut = "DIAG_NV_READ_F, RestoreNVItems - " + left.ToString(); EFS_Professional.Command inCommand = new EFS_Professional.Command(Qcdm.Cmd.DIAG_NV_WRITE_F, ConversionUtils.HexStringToBytes(strInput), strConsoleOut); this._myQueue.Add(ref inCommand); } i++; } } else { Interaction.MsgBox("Invalid NV Items file!", MsgBoxStyle.Critical, "Error!"); return; } this._asyncOp.Post(this.onPrepareForRestoreCompleted, new EventArgs()); this._asyncOp.OperationCompleted(); }