fork download
  1. namespace VAG_TACHO_LIVE
  2. {
  3. using ProgressODoom;
  4. using SimpleTCP;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Diagnostics;
  9. using System.Drawing;
  10. using System.Globalization;
  11. using System.IO;
  12. using System.IO.Ports;
  13. using System.Linq;
  14. using System.Runtime.CompilerServices;
  15. using System.Runtime.InteropServices;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. using System.Windows.Forms;
  21.  
  22. public class Form1 : Form
  23. {
  24. public const uint FT_BAUD_300 = 300;
  25. public const uint FT_BAUD_600 = 600;
  26. public const uint FT_BAUD_1200 = 0x4b0;
  27. public const uint FT_BAUD_2400 = 0x960;
  28. public const uint FT_BAUD_4800 = 0x12c0;
  29. public const uint FT_BAUD_9600 = 0x2580;
  30. public const uint FT_BAUD_14400 = 0x3840;
  31. public const uint FT_BAUD_19200 = 0x4b00;
  32. public const uint FT_BAUD_38400 = 0x9600;
  33. public const uint FT_BAUD_57600 = 0xe100;
  34. public const uint FT_BAUD_115200 = 0x1c200;
  35. public const uint FT_BAUD_230400 = 0x38400;
  36. public const uint FT_BAUD_460800 = 0x70800;
  37. public const uint FT_BAUD_921600 = 0xe1000;
  38. public const uint FT_LIST_NUMBER_ONLY = 0x80000000;
  39. public const uint FT_LIST_BY_INDEX = 0x40000000;
  40. public const uint FT_LIST_ALL = 0x20000000;
  41. public const uint FT_OPEN_BY_SERIAL_NUMBER = 1;
  42. public const uint FT_OPEN_BY_DESCRIPTION = 2;
  43. public const byte FT_BITS_8 = 8;
  44. public const byte FT_BITS_7 = 7;
  45. public const byte FT_BITS_6 = 6;
  46. public const byte FT_BITS_5 = 5;
  47. public const byte FT_STOP_BITS_1 = 0;
  48. public const byte FT_STOP_BITS_1_5 = 1;
  49. public const byte FT_STOP_BITS_2 = 2;
  50. public const byte FT_PARITY_NONE = 0;
  51. public const byte FT_PARITY_ODD = 1;
  52. public const byte FT_PARITY_EVEN = 2;
  53. public const byte FT_PARITY_MARK = 3;
  54. public const byte FT_PARITY_SPACE = 4;
  55. public const ushort FT_FLOW_NONE = 0;
  56. public const ushort FT_FLOW_RTS_CTS = 0x100;
  57. public const ushort FT_FLOW_DTR_DSR = 0x200;
  58. public const ushort FT_FLOW_XON_XOFF = 0x400;
  59. public const byte FT_PURGE_RX = 1;
  60. public const byte FT_PURGE_TX = 2;
  61. public const uint FT_EVENT_RXCHAR = 1;
  62. public const uint FT_EVENT_MODEM_STATUS = 2;
  63. private int cnt = 0;
  64. private bool fContinue = false;
  65. protected internal static uint m_hPort;
  66. protected uint dwListDescFlags;
  67. protected Thread pThreadRead;
  68. private bool available_com_ports = false;
  69. internal static bool is_connected = false;
  70. private string receiveBuffer = "";
  71. internal static byte can_ask_did = 0;
  72. private string rCanId = "";
  73. private string rDlc = "";
  74. internal static byte[] rData;
  75. internal static byte[] rData_FULL;
  76. internal static byte[] rData_DUMP;
  77. private int frame_len = 0;
  78. private int frame_len_recieved = 0;
  79. internal static bool pierwsza_ramka = false;
  80. private byte[] working_frame = new byte[0];
  81. internal static byte[] b_DS_Type;
  82. internal static byte[] b_Data;
  83. internal static bool multi_frame = false;
  84. private byte rDID = 0;
  85. private byte rService = 0;
  86. private byte rSubfunction = 0;
  87. internal static string rImmo = "";
  88. public static byte[] eeprom = new byte[0];
  89. internal static uint cont;
  90. internal static uint max;
  91. private byte[] sData;
  92. internal static int ack_spd = 20;
  93. internal static bool reading_mcu = false;
  94. internal static bool ready = false;
  95. internal static int read_data_cnt = 0x40;
  96. internal static bool eeprom_access = false;
  97. internal static string dump_type = "";
  98. public static byte[] eeprom_mod = new byte[0];
  99. public static string f_sw_tb = "";
  100. public static string f_cn_tb = "";
  101. public static string f_mil_tb = "";
  102. public static string f_skey_tb = "";
  103. internal static string seed_key;
  104. internal static string calc_seed = "";
  105. internal static byte[] SA2_REQUEST;
  106. internal static bool skey_read = false;
  107. private string keyhex;
  108. private int empty_read = 0;
  109. private int prev_cont = 0;
  110. internal static bool read_lcd = false;
  111. private int lcd_move = 0;
  112. internal static bool immo_active = false;
  113. internal static string skey_BKP = "";
  114. private string return_from_cluster;
  115. private bool rFD1103 = false;
  116. internal static bool old_cluster = false;
  117. internal static DateTime save_now;
  118. private DateTime global_time;
  119. internal static string global_path;
  120. private int global_eeprom_read = 0;
  121. internal static RichTextBox INT_LOG;
  122. internal static ProgressBarEx INT_PB;
  123. internal static TextBox INT_SWID;
  124. internal static TextBox INT_SKEY;
  125. internal static byte[] g_working_frame = new byte[0];
  126. internal static SerialPort INT_SP;
  127. internal static TextBox INT_PN;
  128. internal static TextBox INT_SW;
  129. internal static TextBox INT_MIL;
  130. internal static ComboBox INT_CPL;
  131. internal static DateTime LastBufferTime = DateTime.Now;
  132. internal static bool data_received = false;
  133. private readonly Functions Func = new Functions();
  134. private readonly UDS_Functions UDS_Func = new UDS_Functions();
  135. private bool FD04dbg = false;
  136. private FT_STATUS ftStatus = FT_STATUS.FT_OK;
  137. private static byte[] InputBuffer = new byte[500];
  138. private static byte[] InputBuffer2 = new byte[500];
  139. private bool VCDS_RTS;
  140. private byte[] frame = new byte[20];
  141. private uint NumBytesSent = 0;
  142. private static byte Q_Iter = 0;
  143. private static byte[] iter = new byte[4];
  144. internal static string Last_send = "";
  145. private byte[] xor_array = new byte[] { 0xf7, 0xc0, 0xc0, 0x88, 0x51, 0x51, 0x1a, 0xe2 };
  146. public static SimpleTcpClient client;
  147. private byte[] SeedVomTacho;
  148. private byte[] SendSeedRequest;
  149. private byte[] key;
  150. private byte[] CT1;
  151. private byte[] iv;
  152. private string plaintext;
  153. private Form2 frm2 = new Form2();
  154. private Form3 frm3 = new Form3();
  155. private Form4 frm4 = new Form4();
  156. private IContainer components = null;
  157. private TextBox mileage_tb_hex;
  158. private TextBox mileage_tb;
  159. private TextBox fazid;
  160. private TextBox coding_tb;
  161. public TextBox sw_tb;
  162. private TextBox hw_tb;
  163. private TextBox cluster_number_tb;
  164. public ComboBox com_port_speed;
  165. public ComboBox com_port_list;
  166. private Button connect_btn;
  167. private Button refresh_ports_btn;
  168. private Button log_clear_btn;
  169. private Button clear_all_btn;
  170. private Button get_cluster_info_btn;
  171. private Button reset_cluster_btn;
  172. private Button read_mcu_btn;
  173. private Button save_mcu_btn;
  174. private Button read_eeprom_btn;
  175. private Button save_eeprom_btn;
  176. private Button read_lcd_btn;
  177. private Button save_lcd_btn;
  178. private TextBox error_rate_tb;
  179. private Button exit_bl_btn;
  180. private Button button1;
  181. private Button try_skey_btn;
  182. private Button edit_eeprom_btn;
  183. private Button write_eeprom_btn;
  184. private PlainBackgroundPainter plainBackgroundPainter1;
  185. private PlainBorderPainter plainBorderPainter1;
  186. private PlainProgressPainter plainProgressPainter1;
  187. private Button dump_aes_btn;
  188. private Button pro_btn;
  189. private Button mil_fix_btn;
  190. private RichTextBox LOG;
  191. internal TextBox Skey_TB;
  192. internal TextBox sw_id;
  193. internal SerialPort serialPort;
  194. private ProgressBarEx progressBar1;
  195. private Button read_immo_btn;
  196. private Button write_immo_btn;
  197. private Button immo_form;
  198. private Button SaveImmo_BTN;
  199. private Button ADD_IP_BTN;
  200. private Button exit_god;
  201. private Button TEST_BTN;
  202.  
  203. public Form1()
  204. {
  205. this.InitializeComponent();
  206. INT_LOG = this.LOG;
  207. INT_PB = this.progressBar1;
  208. INT_SP = this.serialPort;
  209. INT_PN = this.cluster_number_tb;
  210. INT_SW = this.sw_tb;
  211. INT_SWID = this.sw_id;
  212. INT_MIL = this.mileage_tb;
  213. INT_CPL = this.com_port_list;
  214. }
  215.  
  216. private void ADD_IP_BTN_Click(object sender, EventArgs e)
  217. {
  218. this.com_port_list.Items.Add("IP:10.0.0.1:10001");
  219. this.GuiEnable();
  220. }
  221.  
  222. public static byte[] addByteToArray(byte[] bArray, byte newByte)
  223. {
  224. byte[] array = new byte[bArray.Length + 1];
  225. bArray.CopyTo(array, 0);
  226. array[bArray.Length] = newByte;
  227. return array;
  228. }
  229.  
  230. public static string ByteArrayToString(byte[] ba)
  231. {
  232. StringBuilder builder = new StringBuilder(ba.Length * 2);
  233. foreach (byte num2 in ba)
  234. {
  235. builder.AppendFormat("{0:x2}", num2);
  236. }
  237. return builder.ToString();
  238. }
  239.  
  240. private byte[] calculate_FD04(string s_odpowiedz_z_licznika, bool debug = false)
  241. {
  242. this.SeedVomTacho = StringToByteArray(s_odpowiedz_z_licznika);
  243. this.key = StringToByteArray(this.keyhex);
  244. if (debug)
  245. {
  246. Console.WriteLine("SVT : " + BitConverter.ToString(this.SeedVomTacho).Replace("-", string.Empty));
  247. Console.WriteLine("Try to skip AESKEY");
  248. Console.WriteLine("AES KEY : " + BitConverter.ToString(this.key).Replace("-", string.Empty));
  249. this.LOG.AppendText("\nSVT : " + BitConverter.ToString(this.SeedVomTacho).Replace("-", string.Empty));
  250. this.LOG.AppendText("\nTry to skip AESKEY");
  251. this.LOG.AppendText("\nAES KEY : " + BitConverter.ToString(this.key).Replace("-", string.Empty));
  252. }
  253. this.iv = this.SendSeedRequest.Skip<byte>(1).Take<byte>(0x10).ToArray<byte>();
  254. this.plaintext = BitConverter.ToString(this.SeedVomTacho.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty);
  255. if (debug)
  256. {
  257. Console.WriteLine("IV : " + BitConverter.ToString(this.iv).Replace("-", string.Empty));
  258. Console.WriteLine("Plain : " + this.plaintext);
  259. this.LOG.AppendText("\nIV : " + BitConverter.ToString(this.iv).Replace("-", string.Empty));
  260. this.LOG.AppendText("\nPlain : " + this.plaintext);
  261. }
  262. AesGenericEncryptionService service = new AesGenericEncryptionService(this.key, this.iv);
  263. this.CT1 = service.Encrypt(this.SeedVomTacho.Take<byte>(0x10).ToArray<byte>());
  264. if (debug)
  265. {
  266. Console.WriteLine("AESS IV: " + BitConverter.ToString(service.m_IV).Replace("-", string.Empty));
  267. Console.WriteLine("AESS KEY: " + BitConverter.ToString(service.m_Key).Replace("-", string.Empty));
  268. Console.WriteLine("CT1 : " + BitConverter.ToString(this.CT1).Replace("-", string.Empty));
  269. this.LOG.AppendText("\nAESS IV: " + BitConverter.ToString(service.m_IV).Replace("-", string.Empty));
  270. this.LOG.AppendText("\nAESS KEY: " + BitConverter.ToString(service.m_Key).Replace("-", string.Empty));
  271. this.LOG.AppendText("\nCT1 : " + BitConverter.ToString(this.CT1).Replace("-", string.Empty));
  272. }
  273. this.iv = this.CT1.Take<byte>(0x10).ToArray<byte>();
  274. if (debug)
  275. {
  276. Console.WriteLine("IV2 : " + BitConverter.ToString(this.iv).Replace("-", string.Empty));
  277. this.LOG.AppendText("\nIV2 : " + BitConverter.ToString(this.iv).Replace("-", string.Empty));
  278. }
  279. AesGenericEncryptionService service2 = new AesGenericEncryptionService(this.key, this.iv);
  280. if (debug)
  281. {
  282. Console.WriteLine("AESS2 IV: " + BitConverter.ToString(service2.m_IV).Replace("-", string.Empty));
  283. Console.WriteLine("AESS2 KEY: " + BitConverter.ToString(service2.m_Key).Replace("-", string.Empty));
  284. this.LOG.AppendText("\nAESS2 IV: " + BitConverter.ToString(service2.m_IV).Replace("-", string.Empty));
  285. this.LOG.AppendText("\nAESS2 KEY: " + BitConverter.ToString(service2.m_Key).Replace("-", string.Empty));
  286. }
  287. byte[] buffer = new byte[] { 1 };
  288. byte[] data = StringToByteArray(BitConverter.ToString(this.SeedVomTacho.Skip<byte>(0x10).Take<byte>(7).ToArray<byte>()).Replace("-", string.Empty) + BitConverter.ToString(this.SendSeedRequest.Skip<byte>(0x11).Take<byte>(8).ToArray<byte>()).Replace("-", string.Empty) + BitConverter.ToString(buffer));
  289. byte[] buffer3 = service2.Encrypt(data);
  290. if (debug)
  291. {
  292. Console.WriteLine("Dataparts : ");
  293. Console.WriteLine(BitConverter.ToString(buffer).Replace("-", string.Empty));
  294. Console.WriteLine(BitConverter.ToString(data).Replace("-", string.Empty));
  295. Console.WriteLine(BitConverter.ToString(buffer3).Replace("-", string.Empty));
  296. this.LOG.AppendText("\nDataparts : ");
  297. this.LOG.AppendText("\n" + BitConverter.ToString(buffer).Replace("-", string.Empty));
  298. this.LOG.AppendText("\n" + BitConverter.ToString(data).Replace("-", string.Empty));
  299. this.LOG.AppendText("\n" + BitConverter.ToString(buffer3).Replace("-", string.Empty));
  300. }
  301. string hex = BitConverter.ToString(this.CT1.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty);
  302. if (debug)
  303. {
  304. Console.WriteLine("END P1 : " + hex);
  305. this.LOG.AppendText("\nEND P1 : " + hex);
  306. }
  307. hex = hex + BitConverter.ToString(buffer3.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty);
  308. if (debug)
  309. {
  310. Console.WriteLine("END P2 : " + BitConverter.ToString(buffer3.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty));
  311. Console.WriteLine("END FIN : " + hex);
  312. this.LOG.AppendText("\nEND P2 : " + BitConverter.ToString(buffer3.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty));
  313. this.LOG.AppendText("\nEND FIN : " + hex);
  314. }
  315. return StringToByteArray(hex);
  316. }
  317.  
  318. public void can_ask_more()
  319. {
  320. pierwsza_ramka = false;
  321. byte[] buffer1 = new byte[3];
  322. buffer1[0] = 0x30;
  323. buffer1[2] = 1;
  324. this.sData = buffer1;
  325. this.wyslij_ramke("714", 8, this.sData, false);
  326. }
  327.  
  328. private void clear_all_btn_Click(object sender, EventArgs e)
  329. {
  330. this.cluster_number_tb.Text = "";
  331. this.coding_tb.Text = "";
  332. this.hw_tb.Text = "";
  333. this.mileage_tb.Text = "";
  334. this.mileage_tb_hex.Text = "";
  335. this.sw_tb.Text = "";
  336. this.Skey_TB.Text = "";
  337. this.fazid.Text = "";
  338. this.sw_id.Text = "";
  339. this.log_clear_btn_Click(sender, e);
  340. }
  341.  
  342. private void Client_DataReceived(object sender, SimpleTCP.Message e)
  343. {
  344. string str = e.MessageString.Remove(e.MessageString.Length - 1, 1).Replace(" ", "");
  345. string[] strArray = null;
  346. this.receiveBuffer = str;
  347. char[] separator = new char[] { '\x0013' };
  348. strArray = this.receiveBuffer.Split(separator);
  349. int length = strArray.Length;
  350. for (int i = 0; i < length; i++)
  351. {
  352. if (strArray[i] == "")
  353. {
  354. i++;
  355. }
  356. this.process_can_data(strArray[i]);
  357. Console.WriteLine(strArray[i]);
  358. }
  359. }
  360.  
  361. public void CloseCANC
Success #stdin #stdout 0.02s 25620KB
stdin
Standard input is empty
stdout
namespace VAG_TACHO_LIVE
{
    using ProgressODoom;
    using SimpleTCP;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Globalization;
    using System.IO;
    using System.IO.Ports;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    public class Form1 : Form
    {
        public const uint FT_BAUD_300 = 300;
        public const uint FT_BAUD_600 = 600;
        public const uint FT_BAUD_1200 = 0x4b0;
        public const uint FT_BAUD_2400 = 0x960;
        public const uint FT_BAUD_4800 = 0x12c0;
        public const uint FT_BAUD_9600 = 0x2580;
        public const uint FT_BAUD_14400 = 0x3840;
        public const uint FT_BAUD_19200 = 0x4b00;
        public const uint FT_BAUD_38400 = 0x9600;
        public const uint FT_BAUD_57600 = 0xe100;
        public const uint FT_BAUD_115200 = 0x1c200;
        public const uint FT_BAUD_230400 = 0x38400;
        public const uint FT_BAUD_460800 = 0x70800;
        public const uint FT_BAUD_921600 = 0xe1000;
        public const uint FT_LIST_NUMBER_ONLY = 0x80000000;
        public const uint FT_LIST_BY_INDEX = 0x40000000;
        public const uint FT_LIST_ALL = 0x20000000;
        public const uint FT_OPEN_BY_SERIAL_NUMBER = 1;
        public const uint FT_OPEN_BY_DESCRIPTION = 2;
        public const byte FT_BITS_8 = 8;
        public const byte FT_BITS_7 = 7;
        public const byte FT_BITS_6 = 6;
        public const byte FT_BITS_5 = 5;
        public const byte FT_STOP_BITS_1 = 0;
        public const byte FT_STOP_BITS_1_5 = 1;
        public const byte FT_STOP_BITS_2 = 2;
        public const byte FT_PARITY_NONE = 0;
        public const byte FT_PARITY_ODD = 1;
        public const byte FT_PARITY_EVEN = 2;
        public const byte FT_PARITY_MARK = 3;
        public const byte FT_PARITY_SPACE = 4;
        public const ushort FT_FLOW_NONE = 0;
        public const ushort FT_FLOW_RTS_CTS = 0x100;
        public const ushort FT_FLOW_DTR_DSR = 0x200;
        public const ushort FT_FLOW_XON_XOFF = 0x400;
        public const byte FT_PURGE_RX = 1;
        public const byte FT_PURGE_TX = 2;
        public const uint FT_EVENT_RXCHAR = 1;
        public const uint FT_EVENT_MODEM_STATUS = 2;
        private int cnt = 0;
        private bool fContinue = false;
        protected internal static uint m_hPort;
        protected uint dwListDescFlags;
        protected Thread pThreadRead;
        private bool available_com_ports = false;
        internal static bool is_connected = false;
        private string receiveBuffer = "";
        internal static byte can_ask_did = 0;
        private string rCanId = "";
        private string rDlc = "";
        internal static byte[] rData;
        internal static byte[] rData_FULL;
        internal static byte[] rData_DUMP;
        private int frame_len = 0;
        private int frame_len_recieved = 0;
        internal static bool pierwsza_ramka = false;
        private byte[] working_frame = new byte[0];
        internal static byte[] b_DS_Type;
        internal static byte[] b_Data;
        internal static bool multi_frame = false;
        private byte rDID = 0;
        private byte rService = 0;
        private byte rSubfunction = 0;
        internal static string rImmo = "";
        public static byte[] eeprom = new byte[0];
        internal static uint cont;
        internal static uint max;
        private byte[] sData;
        internal static int ack_spd = 20;
        internal static bool reading_mcu = false;
        internal static bool ready = false;
        internal static int read_data_cnt = 0x40;
        internal static bool eeprom_access = false;
        internal static string dump_type = "";
        public static byte[] eeprom_mod = new byte[0];
        public static string f_sw_tb = "";
        public static string f_cn_tb = "";
        public static string f_mil_tb = "";
        public static string f_skey_tb = "";
        internal static string seed_key;
        internal static string calc_seed = "";
        internal static byte[] SA2_REQUEST;
        internal static bool skey_read = false;
        private string keyhex;
        private int empty_read = 0;
        private int prev_cont = 0;
        internal static bool read_lcd = false;
        private int lcd_move = 0;
        internal static bool immo_active = false;
        internal static string skey_BKP = "";
        private string return_from_cluster;
        private bool rFD1103 = false;
        internal static bool old_cluster = false;
        internal static DateTime save_now;
        private DateTime global_time;
        internal static string global_path;
        private int global_eeprom_read = 0;
        internal static RichTextBox INT_LOG;
        internal static ProgressBarEx INT_PB;
        internal static TextBox INT_SWID;
        internal static TextBox INT_SKEY;
        internal static byte[] g_working_frame = new byte[0];
        internal static SerialPort INT_SP;
        internal static TextBox INT_PN;
        internal static TextBox INT_SW;
        internal static TextBox INT_MIL;
        internal static ComboBox INT_CPL;
        internal static DateTime LastBufferTime = DateTime.Now;
        internal static bool data_received = false;
        private readonly Functions Func = new Functions();
        private readonly UDS_Functions UDS_Func = new UDS_Functions();
        private bool FD04dbg = false;
        private FT_STATUS ftStatus = FT_STATUS.FT_OK;
        private static byte[] InputBuffer = new byte[500];
        private static byte[] InputBuffer2 = new byte[500];
        private bool VCDS_RTS;
        private byte[] frame = new byte[20];
        private uint NumBytesSent = 0;
        private static byte Q_Iter = 0;
        private static byte[] iter = new byte[4];
        internal static string Last_send = "";
        private byte[] xor_array = new byte[] { 0xf7, 0xc0, 0xc0, 0x88, 0x51, 0x51, 0x1a, 0xe2 };
        public static SimpleTcpClient client;
        private byte[] SeedVomTacho;
        private byte[] SendSeedRequest;
        private byte[] key;
        private byte[] CT1;
        private byte[] iv;
        private string plaintext;
        private Form2 frm2 = new Form2();
        private Form3 frm3 = new Form3();
        private Form4 frm4 = new Form4();
        private IContainer components = null;
        private TextBox mileage_tb_hex;
        private TextBox mileage_tb;
        private TextBox fazid;
        private TextBox coding_tb;
        public TextBox sw_tb;
        private TextBox hw_tb;
        private TextBox cluster_number_tb;
        public ComboBox com_port_speed;
        public ComboBox com_port_list;
        private Button connect_btn;
        private Button refresh_ports_btn;
        private Button log_clear_btn;
        private Button clear_all_btn;
        private Button get_cluster_info_btn;
        private Button reset_cluster_btn;
        private Button read_mcu_btn;
        private Button save_mcu_btn;
        private Button read_eeprom_btn;
        private Button save_eeprom_btn;
        private Button read_lcd_btn;
        private Button save_lcd_btn;
        private TextBox error_rate_tb;
        private Button exit_bl_btn;
        private Button button1;
        private Button try_skey_btn;
        private Button edit_eeprom_btn;
        private Button write_eeprom_btn;
        private PlainBackgroundPainter plainBackgroundPainter1;
        private PlainBorderPainter plainBorderPainter1;
        private PlainProgressPainter plainProgressPainter1;
        private Button dump_aes_btn;
        private Button pro_btn;
        private Button mil_fix_btn;
        private RichTextBox LOG;
        internal TextBox Skey_TB;
        internal TextBox sw_id;
        internal SerialPort serialPort;
        private ProgressBarEx progressBar1;
        private Button read_immo_btn;
        private Button write_immo_btn;
        private Button immo_form;
        private Button SaveImmo_BTN;
        private Button ADD_IP_BTN;
        private Button exit_god;
        private Button TEST_BTN;

        public Form1()
        {
            this.InitializeComponent();
            INT_LOG = this.LOG;
            INT_PB = this.progressBar1;
            INT_SP = this.serialPort;
            INT_PN = this.cluster_number_tb;
            INT_SW = this.sw_tb;
            INT_SWID = this.sw_id;
            INT_MIL = this.mileage_tb;
            INT_CPL = this.com_port_list;
        }

        private void ADD_IP_BTN_Click(object sender, EventArgs e)
        {
            this.com_port_list.Items.Add("IP:10.0.0.1:10001");
            this.GuiEnable();
        }

        public static byte[] addByteToArray(byte[] bArray, byte newByte)
        {
            byte[] array = new byte[bArray.Length + 1];
            bArray.CopyTo(array, 0);
            array[bArray.Length] = newByte;
            return array;
        }

        public static string ByteArrayToString(byte[] ba)
        {
            StringBuilder builder = new StringBuilder(ba.Length * 2);
            foreach (byte num2 in ba)
            {
                builder.AppendFormat("{0:x2}", num2);
            }
            return builder.ToString();
        }

        private byte[] calculate_FD04(string s_odpowiedz_z_licznika, bool debug = false)
        {
            this.SeedVomTacho = StringToByteArray(s_odpowiedz_z_licznika);
            this.key = StringToByteArray(this.keyhex);
            if (debug)
            {
                Console.WriteLine("SVT : " + BitConverter.ToString(this.SeedVomTacho).Replace("-", string.Empty));
                Console.WriteLine("Try to skip AESKEY");
                Console.WriteLine("AES KEY : " + BitConverter.ToString(this.key).Replace("-", string.Empty));
                this.LOG.AppendText("\nSVT : " + BitConverter.ToString(this.SeedVomTacho).Replace("-", string.Empty));
                this.LOG.AppendText("\nTry to skip AESKEY");
                this.LOG.AppendText("\nAES KEY : " + BitConverter.ToString(this.key).Replace("-", string.Empty));
            }
            this.iv = this.SendSeedRequest.Skip<byte>(1).Take<byte>(0x10).ToArray<byte>();
            this.plaintext = BitConverter.ToString(this.SeedVomTacho.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty);
            if (debug)
            {
                Console.WriteLine("IV : " + BitConverter.ToString(this.iv).Replace("-", string.Empty));
                Console.WriteLine("Plain : " + this.plaintext);
                this.LOG.AppendText("\nIV : " + BitConverter.ToString(this.iv).Replace("-", string.Empty));
                this.LOG.AppendText("\nPlain : " + this.plaintext);
            }
            AesGenericEncryptionService service = new AesGenericEncryptionService(this.key, this.iv);
            this.CT1 = service.Encrypt(this.SeedVomTacho.Take<byte>(0x10).ToArray<byte>());
            if (debug)
            {
                Console.WriteLine("AESS IV: " + BitConverter.ToString(service.m_IV).Replace("-", string.Empty));
                Console.WriteLine("AESS KEY: " + BitConverter.ToString(service.m_Key).Replace("-", string.Empty));
                Console.WriteLine("CT1 : " + BitConverter.ToString(this.CT1).Replace("-", string.Empty));
                this.LOG.AppendText("\nAESS IV: " + BitConverter.ToString(service.m_IV).Replace("-", string.Empty));
                this.LOG.AppendText("\nAESS KEY: " + BitConverter.ToString(service.m_Key).Replace("-", string.Empty));
                this.LOG.AppendText("\nCT1 : " + BitConverter.ToString(this.CT1).Replace("-", string.Empty));
            }
            this.iv = this.CT1.Take<byte>(0x10).ToArray<byte>();
            if (debug)
            {
                Console.WriteLine("IV2 : " + BitConverter.ToString(this.iv).Replace("-", string.Empty));
                this.LOG.AppendText("\nIV2 : " + BitConverter.ToString(this.iv).Replace("-", string.Empty));
            }
            AesGenericEncryptionService service2 = new AesGenericEncryptionService(this.key, this.iv);
            if (debug)
            {
                Console.WriteLine("AESS2 IV: " + BitConverter.ToString(service2.m_IV).Replace("-", string.Empty));
                Console.WriteLine("AESS2 KEY: " + BitConverter.ToString(service2.m_Key).Replace("-", string.Empty));
                this.LOG.AppendText("\nAESS2 IV: " + BitConverter.ToString(service2.m_IV).Replace("-", string.Empty));
                this.LOG.AppendText("\nAESS2 KEY: " + BitConverter.ToString(service2.m_Key).Replace("-", string.Empty));
            }
            byte[] buffer = new byte[] { 1 };
            byte[] data = StringToByteArray(BitConverter.ToString(this.SeedVomTacho.Skip<byte>(0x10).Take<byte>(7).ToArray<byte>()).Replace("-", string.Empty) + BitConverter.ToString(this.SendSeedRequest.Skip<byte>(0x11).Take<byte>(8).ToArray<byte>()).Replace("-", string.Empty) + BitConverter.ToString(buffer));
            byte[] buffer3 = service2.Encrypt(data);
            if (debug)
            {
                Console.WriteLine("Dataparts : ");
                Console.WriteLine(BitConverter.ToString(buffer).Replace("-", string.Empty));
                Console.WriteLine(BitConverter.ToString(data).Replace("-", string.Empty));
                Console.WriteLine(BitConverter.ToString(buffer3).Replace("-", string.Empty));
                this.LOG.AppendText("\nDataparts : ");
                this.LOG.AppendText("\n" + BitConverter.ToString(buffer).Replace("-", string.Empty));
                this.LOG.AppendText("\n" + BitConverter.ToString(data).Replace("-", string.Empty));
                this.LOG.AppendText("\n" + BitConverter.ToString(buffer3).Replace("-", string.Empty));
            }
            string hex = BitConverter.ToString(this.CT1.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty);
            if (debug)
            {
                Console.WriteLine("END P1 : " + hex);
                this.LOG.AppendText("\nEND P1 : " + hex);
            }
            hex = hex + BitConverter.ToString(buffer3.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty);
            if (debug)
            {
                Console.WriteLine("END P2 : " + BitConverter.ToString(buffer3.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty));
                Console.WriteLine("END FIN : " + hex);
                this.LOG.AppendText("\nEND P2 : " + BitConverter.ToString(buffer3.Take<byte>(0x10).ToArray<byte>()).Replace("-", string.Empty));
                this.LOG.AppendText("\nEND FIN : " + hex);
            }
            return StringToByteArray(hex);
        }

        public void can_ask_more()
        {
            pierwsza_ramka = false;
            byte[] buffer1 = new byte[3];
            buffer1[0] = 0x30;
            buffer1[2] = 1;
            this.sData = buffer1;
            this.wyslij_ramke("714", 8, this.sData, false);
        }

        private void clear_all_btn_Click(object sender, EventArgs e)
        {
            this.cluster_number_tb.Text = "";
            this.coding_tb.Text = "";
            this.hw_tb.Text = "";
            this.mileage_tb.Text = "";
            this.mileage_tb_hex.Text = "";
            this.sw_tb.Text = "";
            this.Skey_TB.Text = "";
            this.fazid.Text = "";
            this.sw_id.Text = "";
            this.log_clear_btn_Click(sender, e);
        }

        private void Client_DataReceived(object sender, SimpleTCP.Message e)
        {
            string str = e.MessageString.Remove(e.MessageString.Length - 1, 1).Replace(" ", "");
            string[] strArray = null;
            this.receiveBuffer = str;
            char[] separator = new char[] { '\x0013' };
            strArray = this.receiveBuffer.Split(separator);
            int length = strArray.Length;
            for (int i = 0; i < length; i++)
            {
                if (strArray[i] == "")
                {
                    i++;
                }
                this.process_can_data(strArray[i]);
                Console.WriteLine(strArray[i]);
            }
        }

        public void CloseCANC