public static string BuildARCPacket(string command, string accept, string Sadress, string timeout, byte[] data) { try { if (command.Length == 8 && accept.Length == 6 && Sadress.Length == 14 && timeout.Length == 4 && data.Length < 512000) { // base arcp header string packetheader = Sadress + accept + command + timeout; // Encrypt data with SEA string dataSEAb64 = SEA.EncryptToBase64(data); // compute CRC32 string checksum = ComputeCRC32(data); // append checksum to packet header packetheader += checksum; return(Security.ConvertToHex(packetheader + dataSEAb64)); } else { return(null); } } catch { return(null); } }
public static byte[] BuildPacket(string source, string command, string accept, string timeout, byte[] data, byte state) { try { if (command.Length == 8 && accept.Length == 6 && source.Length == 14 && timeout.Length == 4 && data.Length < 512000) { // compute CRC32 string checksum = ComputeCRC32(data); byte[] packetheader = Append(Encoding.UTF8.GetBytes(source + accept + command + timeout + checksum), new byte[1] { state }); return(Append(packetheader, SEA.Encrypt(data))); } else { return(null); } } catch { return(null); } }
public static void Init() { try { SEA.InitializeKey(2048, SettingsManager.SEAKey, 32); } catch (Exception ex) { AntiCrash.LogException(ex); } finally { } }
public static void ReceiveDataFromMobile() { Lb_001: { try { string packet = null; bool c = ReceiveARCPacket(SettingsManager.MobileAdress, SettingsManager.ApplicationAdress, out packet); if (c) { if (packet.Substring(0, 14) == SettingsManager.MobileAdress) { // from 14 to 20 (accept) string accept = packet.Substring(0, 20).Remove(0, 14); // from 20 to 28 (command) string command = packet.Substring(0, 28).Remove(0, 20); // from 28 to 32 (timeout) Int32 timeout = Int32.Parse(packet.Substring(0, 32).Remove(0, 28)); // from 32 to 40 (crc) string checksum = packet.Substring(0, 40).Remove(0, 32); Timeout = timeout * 1000; object obj = null; byte[] data = SEA.DecryptFromBase64(packet.Remove(0, 40)); string crcdt = ComputeCRC32(data); if (crcdt == checksum) { string o = ""; try { obj = ProcessCommand(command, data, out o); goto Lb_003; } catch { SendPacket(SettingsManager.ApplicationAdress, SettingsManager.MobileAdress, BuildARCPacket("SHOWTEXT", "ALDATA", SettingsManager.ApplicationAdress, "0005", Encoding.UTF8.GetBytes("Error while executing command"))); } Lb_003: { if (o != "DONOT") { if (accept == "STRING") { SendPacket(SettingsManager.ApplicationAdress, SettingsManager.MobileAdress, BuildARCPacket("SHOWTEXT", "ALDATA", SettingsManager.ApplicationAdress, "0005", Encoding.UTF8.GetBytes(obj.ToString()))); } else if (accept == "AUDIOS") { // accept audio if (o == "STRING" || o == "AUDIOS") { KavprotVoice.SpeakInWave(obj.ToString(), "C:\\ASC.wav"); SendPacket(SettingsManager.ApplicationAdress, SettingsManager.MobileAdress, BuildARCPacket("PLAYAUDI", "ALDATA", SettingsManager.ApplicationAdress, "0005", File.ReadAllBytes("C:\\ASC.wav"))); } } else { if (o == "STRING" || o == "AUDIOS") { KavprotVoice.SpeakInWave(obj.ToString(), "C:\\ASC.wav"); SendPacket(SettingsManager.ApplicationAdress, SettingsManager.MobileAdress, BuildARCPacket("PLAYAUDI", "ALDATA", SettingsManager.ApplicationAdress, "0005", File.ReadAllBytes("C:\\ASC.wav"))); } } } } } else { SendPacket(SettingsManager.ApplicationAdress, SettingsManager.MobileAdress, BuildARCPacket("SHOWTEXT", "ALDATA", SettingsManager.ApplicationAdress, "0005", Encoding.UTF8.GetBytes("Data was modified, Cyclic redundancy check (UNMATCH)"))); } } } } catch (Exception ex) { SendPacket(SettingsManager.ApplicationAdress, SettingsManager.MobileAdress, BuildARCPacket("SHOWTEXT", "ALDATA", SettingsManager.ApplicationAdress, "0005", Encoding.UTF8.GetBytes(ex.Message))); } finally { } } // sleep for settings checktime Thread.Sleep(Timeout); goto Lb_001; }