You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
241 lines
6.7 KiB
241 lines
6.7 KiB
2 weeks ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel;
|
||
|
using System.Drawing;
|
||
|
using System.IO.Ports;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading;
|
||
|
using System.Windows.Forms;
|
||
|
using iMonitorApp.Properties;
|
||
|
using Microsoft.Win32;
|
||
|
|
||
|
namespace iMonitorApp
|
||
|
{
|
||
|
// Token: 0x02000014 RID: 20
|
||
|
public partial class SMSForm : Form
|
||
|
{
|
||
|
// Token: 0x0600007D RID: 125 RVA: 0x00005C41 File Offset: 0x00003E41
|
||
|
public SMSForm()
|
||
|
{
|
||
|
this.InitializeComponent();
|
||
|
this.Init();
|
||
|
}
|
||
|
|
||
|
// Token: 0x0600007E RID: 126 RVA: 0x00005C78 File Offset: 0x00003E78
|
||
|
private void Init()
|
||
|
{
|
||
|
Dictionary<string, string> dictionary = this.BuildPortNameHash(SerialPort.GetPortNames());
|
||
|
using (Dictionary<string, string>.Enumerator enumerator = dictionary.GetEnumerator())
|
||
|
{
|
||
|
if (enumerator.MoveNext())
|
||
|
{
|
||
|
KeyValuePair<string, string> keyValuePair = enumerator.Current;
|
||
|
bool flag = keyValuePair.Value.Contains("HUAWEI Mobile Connect - 3G Modem");
|
||
|
if (!flag)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
Console.WriteLine(keyValuePair.Value + " found connected on Port " + keyValuePair.Key);
|
||
|
this.portnumber = keyValuePair.Key;
|
||
|
}
|
||
|
}
|
||
|
this.po = new SerialPort();
|
||
|
this.po.PortName = this.portnumber;
|
||
|
this.po.BaudRate = int.Parse("9600");
|
||
|
this.po.DataBits = Convert.ToInt32("8");
|
||
|
this.po.Parity = Parity.None;
|
||
|
this.po.StopBits = StopBits.One;
|
||
|
this.po.ReadTimeout = int.Parse("300");
|
||
|
this.po.WriteTimeout = int.Parse("300");
|
||
|
this.po.Encoding = Encoding.GetEncoding("iso-8859-1");
|
||
|
this.sem = new Semaphore(1, 1);
|
||
|
this.mutex = false;
|
||
|
Thread thread = new Thread(new ThreadStart(this.LaunchListener));
|
||
|
thread.Start();
|
||
|
}
|
||
|
|
||
|
// Token: 0x0600007F RID: 127 RVA: 0x00005DEC File Offset: 0x00003FEC
|
||
|
private void LaunchListener()
|
||
|
{
|
||
|
AsynchronousSocketListenerSMS asynchronousSocketListenerSMS = new AsynchronousSocketListenerSMS(Config.GetIP4Address(), Settings.Default.SMSPort);
|
||
|
AsynchronousSocketListenerSMS.Received += this.AsynchronousSocketListener_Received;
|
||
|
AsynchronousSocketListenerSMS.StartListening();
|
||
|
}
|
||
|
|
||
|
// Token: 0x06000080 RID: 128 RVA: 0x00005E28 File Offset: 0x00004028
|
||
|
private void AsynchronousSocketListener_Received(object sender, EventArgs e)
|
||
|
{
|
||
|
this.Log("Receiving Instruction");
|
||
|
Stack<SMSInput> obj = this.stack;
|
||
|
lock (obj)
|
||
|
{
|
||
|
List<string> list = sender.ToString().Split(new char[]
|
||
|
{
|
||
|
','
|
||
|
}).ToList<string>();
|
||
|
this.stack.Push(new SMSInput
|
||
|
{
|
||
|
PhoneNumber = list[0],
|
||
|
Message = list[1]
|
||
|
});
|
||
|
}
|
||
|
this.Log("Instruction Received");
|
||
|
this.MakeCall();
|
||
|
}
|
||
|
|
||
|
// Token: 0x06000081 RID: 129 RVA: 0x00005ED8 File Offset: 0x000040D8
|
||
|
private void po_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
||
|
{
|
||
|
bool flag = e.EventType == SerialData.Chars;
|
||
|
if (flag)
|
||
|
{
|
||
|
bool isOpen = ((SerialPort)sender).IsOpen;
|
||
|
if (isOpen)
|
||
|
{
|
||
|
this.Log(((SerialPort)sender).ReadExisting());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Token: 0x06000082 RID: 130 RVA: 0x00005F18 File Offset: 0x00004118
|
||
|
private void MakeCall()
|
||
|
{
|
||
|
SMSInput smsinput = default(SMSInput);
|
||
|
Stack<SMSInput> obj = this.stack;
|
||
|
lock (obj)
|
||
|
{
|
||
|
bool flag2 = this.stack.Count == 0;
|
||
|
if (flag2)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
smsinput = this.stack.Pop();
|
||
|
}
|
||
|
bool flag3 = smsinput.PhoneNumber == "";
|
||
|
if (!flag3)
|
||
|
{
|
||
|
bool flag4 = smsinput.Message == "";
|
||
|
if (!flag4)
|
||
|
{
|
||
|
this.mutex = true;
|
||
|
this.Log("Sending SMS");
|
||
|
this.SendSingleSMS(smsinput.PhoneNumber, smsinput.Message);
|
||
|
this.mutex = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Token: 0x06000083 RID: 131 RVA: 0x00005FE0 File Offset: 0x000041E0
|
||
|
public void SendSingleSMS(string number, string message)
|
||
|
{
|
||
|
this.po.Open();
|
||
|
this.po.DtrEnable = true;
|
||
|
this.po.RtsEnable = true;
|
||
|
this.po.DataReceived += this.po_DataReceived;
|
||
|
this.po.WriteLine("AT+CMGF=1;\r");
|
||
|
this.po.WriteLine("AT+CMGS=\"" + number + "\"\r");
|
||
|
this.po.WriteLine(message + char.ConvertFromUtf32(26));
|
||
|
this.po.Close();
|
||
|
this.Log("SMS Sent");
|
||
|
}
|
||
|
|
||
|
// Token: 0x06000084 RID: 132 RVA: 0x0000608A File Offset: 0x0000428A
|
||
|
private void HangUp()
|
||
|
{
|
||
|
this.po.Close();
|
||
|
}
|
||
|
|
||
|
// Token: 0x06000085 RID: 133 RVA: 0x0000609C File Offset: 0x0000429C
|
||
|
public void Log(string text)
|
||
|
{
|
||
|
bool invokeRequired = this.console.InvokeRequired;
|
||
|
if (invokeRequired)
|
||
|
{
|
||
|
this.console.Invoke(new Action(delegate()
|
||
|
{
|
||
|
this.console.Text = text + "\r\n" + this.console.Text;
|
||
|
}));
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
this.console.Text = text + "\r\n" + this.console.Text;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Token: 0x06000086 RID: 134 RVA: 0x00006110 File Offset: 0x00004310
|
||
|
private Dictionary<string, string> BuildPortNameHash(string[] portsToMap)
|
||
|
{
|
||
|
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
|
this.MineRegistryForPortName("SYSTEM\\CurrentControlSet\\Enum", dictionary, portsToMap);
|
||
|
return dictionary;
|
||
|
}
|
||
|
|
||
|
// Token: 0x06000087 RID: 135 RVA: 0x00006138 File Offset: 0x00004338
|
||
|
private void MineRegistryForPortName(string startKeyPath, Dictionary<string, string> targetMap, string[] portsToMap)
|
||
|
{
|
||
|
bool flag = targetMap.Count >= portsToMap.Length;
|
||
|
if (!flag)
|
||
|
{
|
||
|
using (RegistryKey localMachine = Registry.LocalMachine)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
using (RegistryKey registryKey = localMachine.OpenSubKey(startKeyPath))
|
||
|
{
|
||
|
string[] subKeyNames = registryKey.GetSubKeyNames();
|
||
|
bool flag2 = subKeyNames.Contains("Device Parameters") && startKeyPath != "SYSTEM\\CurrentControlSet\\Enum";
|
||
|
if (flag2)
|
||
|
{
|
||
|
object value = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + startKeyPath + "\\Device Parameters", "PortName", null);
|
||
|
bool flag3 = value == null || !portsToMap.Contains(value.ToString());
|
||
|
if (!flag3)
|
||
|
{
|
||
|
object value2 = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + startKeyPath, "FriendlyName", null);
|
||
|
string text = "N/A";
|
||
|
bool flag4 = value2 != null;
|
||
|
if (flag4)
|
||
|
{
|
||
|
text = value2.ToString();
|
||
|
}
|
||
|
bool flag5 = !text.Contains(value.ToString());
|
||
|
if (flag5)
|
||
|
{
|
||
|
text = string.Format("{0} ({1})", text, value);
|
||
|
}
|
||
|
targetMap[value.ToString()] = text;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
foreach (string str in subKeyNames)
|
||
|
{
|
||
|
this.MineRegistryForPortName(startKeyPath + "\\" + str, targetMap, portsToMap);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Token: 0x04000053 RID: 83
|
||
|
private string portnumber = "";
|
||
|
|
||
|
// Token: 0x04000054 RID: 84
|
||
|
private SerialPort po;
|
||
|
|
||
|
// Token: 0x04000055 RID: 85
|
||
|
private Semaphore sem;
|
||
|
|
||
|
// Token: 0x04000056 RID: 86
|
||
|
private Stack<SMSInput> stack = new Stack<SMSInput>();
|
||
|
|
||
|
// Token: 0x04000057 RID: 87
|
||
|
private bool mutex;
|
||
|
}
|
||
|
}
|