njunwa1

v4 calc

Feb 7th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 28.44 KB | None | 0 0
  1. // Generated by .NET Reflector from C:\Users\Njunwa MG\Downloads\Compressed\Huawei Modem Unlocker\NewSalluV4CalculatorUpdated.exe
  2. namespace NewSalluV4CalculatorUpdated
  3. {
  4.     using System;
  5.     using System.Collections.Generic;
  6.     using System.ComponentModel;
  7.     using System.Drawing;
  8.     using System.Globalization;
  9.     using System.IO.Ports;
  10.     using System.Linq;
  11.     using System.Security.Cryptography;
  12.     using System.Text;
  13.     using System.Threading;
  14.     using System.Windows.Forms;
  15.    
  16.     public class Form1 : Form
  17.     {
  18.         private static List<string> appPorts;
  19.         private Button button1;
  20.         private Button button2;
  21.         private Button button3;
  22.         private Button button4;
  23.         private Button calcButton;
  24.         private IContainer components = null;
  25.         private Button detectButton;
  26.         private Label label1;
  27.         private Label label2;
  28.         private Label label3;
  29.         private Label label4;
  30.         private Label label5;
  31.         private Label label6;
  32.         private Label label8;
  33.         private RichTextBox logTextBox;
  34.         private static string nvrdex;
  35.         private static int oemCode;
  36.         private TextBox oemTextBox;
  37.         private TextBox outputTextBox;
  38.         private static string pattern1;
  39.         private TextBox pattern1Textbox;
  40.         private static string pattern2;
  41.         private TextBox pattern2Textbox;
  42.         private static SerialPort port;
  43.         private ComboBox portComboBox;
  44.         private ProgressBar progressBar1;
  45.         private Label progressLabel1;
  46.        
  47.         public Form1()
  48.         {
  49.             this.InitializeComponent();
  50.         }
  51.        
  52.         private void AddPortsToComboBox(string[] ports)
  53.         {
  54.             int num;
  55.             this.portComboBox.Items.Clear();
  56.             this.portComboBox.Items.Add("Auto Detect");
  57.             for (int i = 0; i < ports.Length; i = num + 1)
  58.             {
  59.                 this.portComboBox.Items.Add(ports[i]);
  60.                 num = i;
  61.             }
  62.         }
  63.        
  64.         private void button1_Click(object sender, EventArgs e)
  65.         {
  66.             oemCode = 1;
  67.             this.logTextBox.Clear();
  68.             this.logTextBox.AppendText("\n==========================================\n\n");
  69.             this.logTextBox.AppendText(" OEM string Selected .......  \n");
  70.             this.logTextBox.AppendText("\n==========================================\n\n");
  71.             this.logTextBox.AppendText(" *** In case of Port issue , Device not found , Please Close this application and re-open the app and do step1 , step 2 and step 3");
  72.         }
  73.        
  74.         private void button4_Click(object sender, EventArgs e)
  75.         {
  76.             MessageBox.Show("Important Notes:- \n \n *** Use this application in Compatibility mode for windows 7 . \n *** right click on this app and select 'Compatibility' tab . \n *** choose 'Run this program in compatibility mode for:' \n *** choose Windows 7 \n *** Click OK and Now use this application as normal and Enjoy!", "How to use :");
  77.         }
  78.        
  79.         private void calcButton_Click(object sender, EventArgs e)
  80.         {
  81.             if ((this.pattern1Textbox.Text == "") || (this.pattern2Textbox.Text == ""))
  82.             {
  83.                 this.logTextBox.Clear();
  84.                 this.logTextBox.AppendText("Unable to extract data from modem!");
  85.             }
  86.             else
  87.             {
  88.                 this.logTextBox.AppendText("\n==========================================\n\n");
  89.                 this.logTextBox.AppendText("Attention ! During Operation the Program stops responding to your actions .\n Time Calculation depend on the power of your Computer ( from 2 to 10 minutes ) \n\n");
  90.                 this.logTextBox.AppendText(string.Concat(new object[] { DateTime.Now.Hour, ":", DateTime.Now.Minute, ":", DateTime.Now.Second, " - Progress Started ..\n" }));
  91.                 this.logTextBox.ScrollToCaret();
  92.                 this.logTextBox.Update();
  93.                 string text = this.pattern1Textbox.Text;
  94.                 string str2 = this.pattern2Textbox.Text;
  95.                 if ((text.Length == 0x5f) && (str2.Length == 0x5f))
  96.                 {
  97.                     uint num;
  98.                     int num2;
  99.                     int num3;
  100.                     this.outputTextBox.Text = "";
  101.                     this.outputTextBox.Update();
  102.                     this.oemTextBox.Text = "";
  103.                     this.oemTextBox.Update();
  104.                     SHA256Managed managed = new SHA256Managed();
  105.                     byte[] second = new byte[0x20];
  106.                     byte[] destinationArray = new byte[0x40];
  107.                     byte[] buffer = new byte[8];
  108.                     for (num2 = 0; num2 < 0x20; num2 = num3 + 1)
  109.                     {
  110.                         uint.TryParse(text.Substring(num2 * 3, 2), NumberStyles.HexNumber, null, out num);
  111.                         second[num2] = (byte) num;
  112.                         num3 = num2;
  113.                     }
  114.                     num2 = 0;
  115.                     while (num2 < 0x20)
  116.                     {
  117.                         uint.TryParse(str2.Substring(num2 * 3, 2), NumberStyles.HexNumber, null, out num);
  118.                         destinationArray[0x20 + num2] = (byte) num;
  119.                         num3 = num2;
  120.                         num2 = num3 + 1;
  121.                     }
  122.                     int num4 = 0;
  123.                     for (int i = 0x5f5e0ff; i >= 0; i = num3 - 1)
  124.                     {
  125.                         int num6 = i;
  126.                         for (num2 = 0; num2 < 8; num2 = num3 + 1)
  127.                         {
  128.                             buffer[7 - num2] = (byte) ((num6 % 10) + 0x30);
  129.                             num6 /= 10;
  130.                             num3 = num2;
  131.                         }
  132.                         Array.Copy(managed.ComputeHash(buffer), destinationArray, 0x20);
  133.                         if (managed.ComputeHash(destinationArray).SequenceEqual<byte>(second))
  134.                         {
  135.                             this.outputTextBox.Text = i.ToString("D8");
  136.                             this.oemTextBox.Text = i.ToString("D8");
  137.                             break;
  138.                         }
  139.                         if ((num4 / 0xf4240) >= 100)
  140.                         {
  141.                             this.progressBar1.Value = 100;
  142.                             this.progressLabel1.Text = "Progress Calculation: 100%";
  143.                         }
  144.                         else
  145.                         {
  146.                             this.progressBar1.Value = num4 / 0xf4240;
  147.                             num3 = num4 / 0xf4240;
  148.                             this.progressLabel1.Text = "Progress Calculation: " + num3.ToString() + "%";
  149.                         }
  150.                         this.progressBar1.Update();
  151.                         this.progressLabel1.Update();
  152.                         num3 = num4;
  153.                         num4 = num3 + 1;
  154.                         num3 = i;
  155.                     }
  156.                     if (this.outputTextBox.Text != "")
  157.                     {
  158.                         this.progressBar1.Value = 100;
  159.                         this.progressLabel1.Text = "Progress Calculation: 100%";
  160.                         if (oemCode == 1)
  161.                         {
  162.                             this.outputTextBox.Text = "";
  163.                             oemCode = 0;
  164.                         }
  165.                         else
  166.                         {
  167.                             this.oemTextBox.Text = "";
  168.                         }
  169.                     }
  170.                     else
  171.                     {
  172.                         this.outputTextBox.Text = " Wrong Patterns or Incompatible  ";
  173.                         this.oemTextBox.Text = " Wrong Patterns or Incompatible  ";
  174.                     }
  175.                     this.logTextBox.AppendText(string.Concat(new object[] { DateTime.Now.Hour, ":", DateTime.Now.Minute, ":", DateTime.Now.Second, " - Processing of Data is Completed \n" }));
  176.                     this.logTextBox.AppendText("\n==========================================\n\n");
  177.                     this.logTextBox.AppendText("For NCK Network Unlock Code: \n");
  178.                     this.logTextBox.AppendText("1. go to your modem portal address from 192.168.x.1   \n");
  179.                     this.logTextBox.AppendText("2. if it prompts to put unlock code then Use 8 digit NCK Unlock code. \n");
  180.                     this.logTextBox.AppendText("3. and Enjoy !  No ?? . \n");
  181.                     this.logTextBox.AppendText("4. if it doesn't ask you for any type of code then Use AT Commands using dc unlocker or putty.\n");
  182.                     this.logTextBox.AppendText("*** Oem Code is for advanced users --- sometimes needed for telnet,adb,datalock and a lot more ....   \n");
  183.                     this.logTextBox.AppendText("*** stay in touch with the Forum and relevant thread to know more info \n");
  184.                     this.logTextBox.AppendText("*** if this app hang or freezes then Click this button >> 'For More Info' ...   \n");
  185.                     this.logTextBox.ScrollToCaret();
  186.                     this.logTextBox.Update();
  187.                 }
  188.             }
  189.         }
  190.        
  191.         private static void ClosePort()
  192.         {
  193.             if (port.IsOpen)
  194.             {
  195.                 port.Close();
  196.             }
  197.         }
  198.        
  199.         private void detectButton_Click(object sender, EventArgs e)
  200.         {
  201.             this.logTextBox.Clear();
  202.             port = new SerialPort();
  203.             if (this.portComboBox.SelectedIndex == 0)
  204.             {
  205.                 nvrdex = FindAndReadFirstAppPort();
  206.             }
  207.             else
  208.             {
  209.                 string portName = this.portComboBox.Items[this.portComboBox.SelectedIndex].ToString();
  210.                 nvrdex = this.TryReadPort(portName);
  211.             }
  212.             if (nvrdex == null)
  213.             {
  214.                 this.logTextBox.Clear();
  215.                 this.logTextBox.Text = "Device not Found .";
  216.             }
  217.             else
  218.             {
  219.                 this.SelectPortInComboBox(port.PortName);
  220.                 pattern1 = nvrdex.Substring(0x15, 0x5f);
  221.                 pattern2 = nvrdex.Substring(0xd5, 0x5f);
  222.                 this.pattern1Textbox.Text = pattern1;
  223.                 this.pattern2Textbox.Text = pattern2;
  224.                 this.PrintDeviceInfo(port.PortName);
  225.                 port.Close();
  226.             }
  227.         }
  228.        
  229.         protected override void Dispose(bool disposing)
  230.         {
  231.             if (disposing && (this.components > null))
  232.             {
  233.                 this.components.Dispose();
  234.             }
  235.             base.Dispose(disposing);
  236.         }
  237.        
  238.         private static string FindAndReadFirstAppPort()
  239.         {
  240.             string[] portNames = SerialPort.GetPortNames();
  241.             string str = "";
  242.             appPorts = new List<string>();
  243.             foreach (string str2 in portNames)
  244.             {
  245.                 if (TryOpenPort(str2))
  246.                 {
  247.                     if (oemCode == 1)
  248.                     {
  249.                         str = SendCommand("AT^NVRDEX=50502,0,128");
  250.                     }
  251.                     else
  252.                     {
  253.                         str = SendCommand("AT^NVRDEX=50503,0,128");
  254.                     }
  255.                     if (str.Contains("NVRDEX:"))
  256.                     {
  257.                         int index = str.IndexOf("^NVRDEX:");
  258.                         return str.Substring(index, 0x194);
  259.                     }
  260.                 }
  261.                 ClosePort();
  262.             }
  263.             return null;
  264.         }
  265.        
  266.         private string FindSubstring(string str, string fromString, string toString)
  267.         {
  268.             string str2 = "";
  269.             int index = str.IndexOf(fromString);
  270.             if (index > -1)
  271.             {
  272.                 int num2 = str.IndexOf(toString, (int) (index + 1));
  273.                 if (num2 > -1)
  274.                 {
  275.                     int num3 = num2 - index;
  276.                     str2 = str.Substring(index, num2 - index);
  277.                 }
  278.             }
  279.             return str2;
  280.         }
  281.        
  282.         private void Form1_Activated(object sender, EventArgs e)
  283.         {
  284.             this.AddPortsToComboBox(SerialPort.GetPortNames());
  285.             this.portComboBox.SelectedIndex = 0;
  286.         }
  287.        
  288.         private void InitializeComponent()
  289.         {
  290.             ComponentResourceManager manager = new ComponentResourceManager(typeof(Form1));
  291.             this.label1 = new Label();
  292.             this.label2 = new Label();
  293.             this.label3 = new Label();
  294.             this.portComboBox = new ComboBox();
  295.             this.detectButton = new Button();
  296.             this.calcButton = new Button();
  297.             this.label4 = new Label();
  298.             this.progressLabel1 = new Label();
  299.             this.progressBar1 = new ProgressBar();
  300.             this.pattern1Textbox = new TextBox();
  301.             this.pattern2Textbox = new TextBox();
  302.             this.logTextBox = new RichTextBox();
  303.             this.outputTextBox = new TextBox();
  304.             this.label5 = new Label();
  305.             this.button1 = new Button();
  306.             this.label6 = new Label();
  307.             this.button2 = new Button();
  308.             this.button3 = new Button();
  309.             this.label8 = new Label();
  310.             this.oemTextBox = new TextBox();
  311.             this.button4 = new Button();
  312.             base.SuspendLayout();
  313.             this.label1.AutoSize = true;
  314.             this.label1.Location = new Point(12, 0x54);
  315.             this.label1.Name = "label1";
  316.             this.label1.Size = new Size(0x38, 13);
  317.             this.label1.TabIndex = 0;
  318.             this.label1.Text = "Pattern 1:-";
  319.             this.label2.AutoSize = true;
  320.             this.label2.Location = new Point(12, 0x76);
  321.             this.label2.Name = "label2";
  322.             this.label2.Size = new Size(0x38, 13);
  323.             this.label2.TabIndex = 1;
  324.             this.label2.Text = "Pattern 2:-";
  325.             this.label3.AutoSize = true;
  326.             this.label3.Location = new Point(12, 9);
  327.             this.label3.Name = "label3";
  328.             this.label3.Size = new Size(0x3e, 13);
  329.             this.label3.TabIndex = 2;
  330.             this.label3.Text = "COM-Port : ";
  331.             this.portComboBox.FormattingEnabled = true;
  332.             this.portComboBox.Location = new Point(0x51, 6);
  333.             this.portComboBox.Name = "portComboBox";
  334.             this.portComboBox.Size = new Size(0xb2, 0x15);
  335.             this.portComboBox.TabIndex = 3;
  336.             this.detectButton.Font = new Font("Microsoft Sans Serif", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
  337.             this.detectButton.Location = new Point(310, 6);
  338.             this.detectButton.Name = "detectButton";
  339.             this.detectButton.Size = new Size(0x93, 0x17);
  340.             this.detectButton.TabIndex = 4;
  341.             this.detectButton.Text = "Click here to detect";
  342.             this.detectButton.UseVisualStyleBackColor = true;
  343.             this.detectButton.Click += new EventHandler(this.detectButton_Click);
  344.             this.calcButton.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
  345.             this.calcButton.Font = new Font("Comic Sans MS", 11.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
  346.             this.calcButton.Location = new Point(15, 0x1c4);
  347.             this.calcButton.Name = "calcButton";
  348.             this.calcButton.Size = new Size(0xcf, 0x25);
  349.             this.calcButton.TabIndex = 5;
  350.             this.calcButton.Text = "Calculate";
  351.             this.calcButton.UseVisualStyleBackColor = true;
  352.             this.calcButton.Click += new EventHandler(this.calcButton_Click);
  353.             this.label4.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
  354.             this.label4.AutoSize = true;
  355.             this.label4.Font = new Font("Microsoft Sans Serif", 9f, FontStyle.Bold, GraphicsUnit.Point, 0);
  356.             this.label4.Location = new Point(0x14d, 0x1c8);
  357.             this.label4.Name = "label4";
  358.             this.label4.Size = new Size(0x9e, 15);
  359.             this.label4.TabIndex = 6;
  360.             this.label4.Text = "Network Unlock code  : ";
  361.             this.progressLabel1.AutoSize = true;
  362.             this.progressLabel1.Font = new Font("Microsoft Sans Serif", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
  363.             this.progressLabel1.Location = new Point(14, 0x31);
  364.             this.progressLabel1.Name = "progressLabel1";
  365.             this.progressLabel1.Size = new Size(0x7d, 15);
  366.             this.progressLabel1.TabIndex = 7;
  367.             this.progressLabel1.Text = "Progress Completed .";
  368.             this.progressBar1.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
  369.             this.progressBar1.Location = new Point(0xe3, 0x29);
  370.             this.progressBar1.Name = "progressBar1";
  371.             this.progressBar1.Size = new Size(0x187, 0x17);
  372.             this.progressBar1.TabIndex = 8;
  373.             this.pattern1Textbox.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
  374.             this.pattern1Textbox.Font = new Font("Consolas", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
  375.             this.pattern1Textbox.Location = new Point(0x4a, 0x51);
  376.             this.pattern1Textbox.Name = "pattern1Textbox";
  377.             this.pattern1Textbox.Size = new Size(0x2d8, 0x17);
  378.             this.pattern1Textbox.TabIndex = 9;
  379.             this.pattern2Textbox.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
  380.             this.pattern2Textbox.Font = new Font("Consolas", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
  381.             this.pattern2Textbox.Location = new Point(0x4a, 0x73);
  382.             this.pattern2Textbox.Name = "pattern2Textbox";
  383.             this.pattern2Textbox.Size = new Size(0x2d8, 0x17);
  384.             this.pattern2Textbox.TabIndex = 10;
  385.             this.logTextBox.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
  386.             this.logTextBox.Location = new Point(13, 0x93);
  387.             this.logTextBox.Name = "logTextBox";
  388.             this.logTextBox.Size = new Size(0x315, 0x121);
  389.             this.logTextBox.TabIndex = 11;
  390.             this.logTextBox.Text = "";
  391.             this.outputTextBox.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
  392.             this.outputTextBox.Font = new Font("Microsoft Sans Serif", 12f, FontStyle.Bold, GraphicsUnit.Point, 0);
  393.             this.outputTextBox.Location = new Point(0x1f1, 0x1c7);
  394.             this.outputTextBox.Name = "outputTextBox";
  395.             this.outputTextBox.Size = new Size(0xe5, 0x1a);
  396.             this.outputTextBox.TabIndex = 12;
  397.             this.label5.AutoSize = true;
  398.             this.label5.Font = new Font("Microsoft Sans Serif", 12f, FontStyle.Bold, GraphicsUnit.Point, 0);
  399.             this.label5.Location = new Point(13, 0x1ec);
  400.             this.label5.Name = "label5";
  401.             this.label5.Size = new Size(0x30f, 20);
  402.             this.label5.TabIndex = 13;
  403.             this.label5.Text = "---------------------------------------------------------------------------------------------------------------------------------";
  404.             this.button1.Font = new Font("Microsoft Sans Serif", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
  405.             this.button1.Location = new Point(0x81, 530);
  406.             this.button1.Name = "button1";
  407.             this.button1.Size = new Size(0x52, 30);
  408.             this.button1.TabIndex = 14;
  409.             this.button1.Text = "1:- select";
  410.             this.button1.UseVisualStyleBackColor = true;
  411.             this.button1.Click += new EventHandler(this.button1_Click);
  412.             this.label6.AutoSize = true;
  413.             this.label6.Font = new Font("Microsoft Sans Serif", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
  414.             this.label6.Location = new Point(14, 0x21b);
  415.             this.label6.Name = "label6";
  416.             this.label6.Size = new Size(0x6d, 15);
  417.             this.label6.TabIndex = 15;
  418.             this.label6.Text = "For OEM Code ......";
  419.             this.button2.Font = new Font("Microsoft Sans Serif", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
  420.             this.button2.Location = new Point(0xe3, 530);
  421.             this.button2.Name = "button2";
  422.             this.button2.Size = new Size(0x89, 30);
  423.             this.button2.TabIndex = 0x10;
  424.             this.button2.Text = "2:- Click here to detect";
  425.             this.button2.UseVisualStyleBackColor = true;
  426.             this.button2.Click += new EventHandler(this.detectButton_Click);
  427.             this.button3.Font = new Font("Microsoft Sans Serif", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
  428.             this.button3.Location = new Point(370, 530);
  429.             this.button3.Name = "button3";
  430.             this.button3.Size = new Size(0x89, 30);
  431.             this.button3.TabIndex = 0x11;
  432.             this.button3.Text = "3:- Calculate";
  433.             this.button3.UseVisualStyleBackColor = true;
  434.             this.button3.Click += new EventHandler(this.calcButton_Click);
  435.             this.label8.AutoSize = true;
  436.             this.label8.Font = new Font("Microsoft Sans Serif", 9f, FontStyle.Bold, GraphicsUnit.Point, 0);
  437.             this.label8.Location = new Point(0x210, 0x219);
  438.             this.label8.Name = "label8";
  439.             this.label8.Size = new Size(0x52, 15);
  440.             this.label8.TabIndex = 0x13;
  441.             this.label8.Text = "Oem Code :";
  442.             this.oemTextBox.Font = new Font("Microsoft Sans Serif", 12f, FontStyle.Bold, GraphicsUnit.Point, 0);
  443.             this.oemTextBox.Location = new Point(0x268, 0x214);
  444.             this.oemTextBox.Name = "oemTextBox";
  445.             this.oemTextBox.Size = new Size(0xba, 0x1a);
  446.             this.oemTextBox.TabIndex = 20;
  447.             this.button4.Location = new Point(0x299, 0x15);
  448.             this.button4.Name = "button4";
  449.             this.button4.Size = new Size(0x89, 0x2b);
  450.             this.button4.TabIndex = 0x15;
  451.             this.button4.Text = "For More Info";
  452.             this.button4.UseVisualStyleBackColor = true;
  453.             this.button4.Click += new EventHandler(this.button4_Click);
  454.             base.AutoScaleDimensions = new SizeF(6f, 13f);
  455.             base.AutoScaleMode = AutoScaleMode.Font;
  456.             this.BackColor = SystemColors.InactiveCaption;
  457.             base.ClientSize = new Size(0x32e, 0x23c);
  458.             base.Controls.Add(this.button4);
  459.             base.Controls.Add(this.oemTextBox);
  460.             base.Controls.Add(this.label8);
  461.             base.Controls.Add(this.button3);
  462.             base.Controls.Add(this.button2);
  463.             base.Controls.Add(this.label6);
  464.             base.Controls.Add(this.button1);
  465.             base.Controls.Add(this.label5);
  466.             base.Controls.Add(this.outputTextBox);
  467.             base.Controls.Add(this.logTextBox);
  468.             base.Controls.Add(this.pattern2Textbox);
  469.             base.Controls.Add(this.pattern1Textbox);
  470.             base.Controls.Add(this.progressBar1);
  471.             base.Controls.Add(this.progressLabel1);
  472.             base.Controls.Add(this.label4);
  473.             base.Controls.Add(this.calcButton);
  474.             base.Controls.Add(this.detectButton);
  475.             base.Controls.Add(this.portComboBox);
  476.             base.Controls.Add(this.label3);
  477.             base.Controls.Add(this.label2);
  478.             base.Controls.Add(this.label1);
  479.             base.FormBorderStyle = FormBorderStyle.FixedDialog;
  480.             base.Icon = (Icon) manager.GetObject("$this.Icon");
  481.             base.MaximizeBox = false;
  482.             this.MinimumSize = new Size(830, 0x263);
  483.             base.Name = "Form1";
  484.             base.StartPosition = FormStartPosition.CenterScreen;
  485.             this.Text = "Huawei Unlock V4 Calculator ----------  updated By Salluhassan";
  486.             base.Activated += new EventHandler(this.Form1_Activated);
  487.             base.ResumeLayout(false);
  488.             base.PerformLayout();
  489.         }
  490.        
  491.         private void portComboBox_DropDown(object sender, EventArgs e)
  492.         {
  493.             this.AddPortsToComboBox(SerialPort.GetPortNames());
  494.         }
  495.        
  496.         private void PrintDeviceInfo(string portName)
  497.         {
  498.             string str = "";
  499.             string str2 = "";
  500.             string str3 = "";
  501.             string str4 = "";
  502.             string str5 = "";
  503.             string str6 = "";
  504.             string str7 = "";
  505.             string str8 = "";
  506.             string str9 = "";
  507.             this.logTextBox.AppendText("Found device.. Hurray!  :\n\n");
  508.             this.logTextBox.Update();
  509.             string str10 = SendCommand("ATI");
  510.             str = this.FindSubstring(str10, "Model", "\r\n");
  511.             str2 = this.FindSubstring(str10, "IMEI", "\r\n");
  512.             this.logTextBox.AppendText(str + "\n");
  513.             this.logTextBox.AppendText(str2 + "\n");
  514.             this.logTextBox.Update();
  515.             str3 = SendCommand("AT^SN");
  516.             this.logTextBox.AppendText(this.FindSubstring(str3, "SN", "\r\n").Replace("SN:", "S/N: ") + "\n");
  517.             this.logTextBox.Update();
  518.             string str11 = SendCommand("AT^VERSION?");
  519.             str4 = this.FindSubstring(str11, "^VERSION:EXTD:", "\r\n").Replace("^VERSION:EXTD:", "Dashboard version: ");
  520.             str5 = this.FindSubstring(str11, "^VERSION:EXTS:", "\r\n").Replace("^VERSION:EXTS:", "Firmware version: ");
  521.             str6 = this.FindSubstring(str11, "^VERSION:EXTH:", "\r\n").Replace("^VERSION:EXTH:", "Hardware version: ");
  522.             str7 = this.FindSubstring(str11, "^VERSION:BDT:", "\r\n").Replace("^VERSION:BDT:", "Build date/time: ");
  523.             this.logTextBox.AppendText(str4 + "\n");
  524.             this.logTextBox.AppendText(str5 + "\n");
  525.             this.logTextBox.AppendText(str6 + "\n");
  526.             this.logTextBox.AppendText(str7 + "\n");
  527.             this.logTextBox.Update();
  528.             string str12 = SendCommand("AT^CARDLOCK?");
  529.             str12 = this.FindSubstring(str12, "CARDLOCK:", "\r\n").Replace("CARDLOCK: ", "");
  530.             char ch = str12[0];
  531.             switch (ch.ToString())
  532.             {
  533.                 case "2":
  534.                     str8 = "SIM lock status: Locked";
  535.                     break;
  536.                
  537.                 case "1":
  538.                     str8 = "SIM lock status: Unlocked";
  539.                     break;
  540.             }
  541.             str9 = this.FindSubstring(str12, ",", ",").Replace(",", "");
  542.             str9 = "Attempts to enter: " + str9;
  543.             this.logTextBox.AppendText(str8 + "\n");
  544.             this.logTextBox.AppendText(str9 + "\n");
  545.         }
  546.        
  547.         private void readButton_Click(object sender, EventArgs e)
  548.         {
  549.         }
  550.        
  551.         private void SelectPortInComboBox(string port)
  552.         {
  553.             if (this.portComboBox.Items.Contains(port))
  554.             {
  555.                 int index = this.portComboBox.Items.IndexOf(port);
  556.                 this.portComboBox.SelectedIndex = index;
  557.             }
  558.         }
  559.        
  560.         private static string SendCommand(string text)
  561.         {
  562.             string str = "";
  563.             if (port.IsOpen)
  564.             {
  565.                 port.Write(text + "\r\n");
  566.                 Thread.Sleep(500);
  567.                 str = port.ReadExisting() + "\n";
  568.             }
  569.             return str;
  570.         }
  571.        
  572.         private static bool TryOpenPort(string portName)
  573.         {
  574.             if (port.IsOpen)
  575.             {
  576.                 port.Close();
  577.             }
  578.             port.BaudRate = 0x2580;
  579.             port.DataBits = 8;
  580.             port.StopBits = StopBits.One;
  581.             port.Parity = Parity.Odd;
  582.             port.ReadTimeout = 500;
  583.             port.WriteTimeout = 500;
  584.             port.Encoding = Encoding.GetEncoding("windows-1251");
  585.             port.PortName = portName;
  586.             try
  587.             {
  588.                 port.Open();
  589.                 return true;
  590.             }
  591.             catch
  592.             {
  593.                 return false;
  594.             }
  595.         }
  596.        
  597.         private string TryReadPort(string portName)
  598.         {
  599.             if (TryOpenPort(portName))
  600.             {
  601.                 string str = "";
  602.                 if (oemCode == 1)
  603.                 {
  604.                     str = SendCommand("AT^NVRDEX=50502,0,128");
  605.                 }
  606.                 else
  607.                 {
  608.                     str = SendCommand("AT^NVRDEX=50503,0,128");
  609.                 }
  610.                 if (str.Contains("^NVRDEX:"))
  611.                 {
  612.                     int index = str.IndexOf("^NVRDEX:");
  613.                     return str.Substring(index, 0x194);
  614.                 }
  615.             }
  616.             return null;
  617.         }
  618.     }
  619. }
Add Comment
Please, Sign In to add comment