private void FlashDevice_DoWork(object sender, DoWorkEventArgs e) { CheckForIllegalCrossThreadCalls = false; try { log.ForeColor = Color.Cyan; DownloadManager dwm = new DownloadManager(DownloadManager.DownloadMode.BIN1MB); dwm.ShowDialog(); status_flash.Text = "Preparing to flash device on " + CurrentPort + "..."; if (CurrentPort != null) { if (!COM_DEVICE.IsOpen) { COM_DEVICE.PortName = CurrentPort; } COM_DEVICE.StopBits = System.IO.Ports.StopBits.One; COM_DEVICE.Open(); log.AppendText("\r\nINFO: Manual Mode -- COM: " + CurrentPort + " is open! \r\n"); log.AppendText("Connecting to ESP8266....\r\n"); COM_DEVICE.RtsEnable = false; COM_DEVICE.DtrEnable = false; Thread.Sleep(100); // resets the nodemcu / d1 mini COM_DEVICE.RtsEnable = true; COM_DEVICE.DtrEnable = true; Thread.Sleep(100); COM_DEVICE.RtsEnable = false; COM_DEVICE.DtrEnable = false; COM_DEVICE.Close(); } else { log.AppendText("INFO: esptool.py is auto selecting your device."); } log.AppendText("....done\r\n"); Thread.Sleep(2000); log.AppendText("Preparing firmware files.....\r\n"); string dir = Directory.GetCurrentDirectory().ToString() + "\\"; string binaryPath = dwm.binary1mb; log.AppendText("....done\r\n"); log.AppendText("Creating Parameters.....\r\n"); var assembly = Assembly.GetExecutingAssembly(); string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith("esptool.exe")); log.AppendText(resourceName + "\r\n"); string path = dir + "flash_module.exe"; using (Stream input = assembly.GetManifestResourceStream(resourceName)) using (Stream output = File.Create(path)) { CopyStream(input, output); } var script = path; string argv; if (CurrentPort != null) { argv = "--port " + CurrentPort + " --baud 115200" + " write_flash --flash_mode dio" + " 0x00000 " + binaryPath; } else { argv = " --baud 115200" + " write_flash --flash_mode dio" + " 0x00000 " + binaryPath; } log.AppendText("....done\r\n"); log.AppendText("Setting up procedures.....\r\n"); var psi = new ProcessStartInfo(); psi.FileName = path; psi.Arguments = argv; psi.UseShellExecute = false; psi.CreateNoWindow = true; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; var errors = ""; var output_c = ""; log.AppendText("....done\r\n"); icon2.Image = N2D.Properties.Resources.done; icon3.Image = N2D.Properties.Resources.inprog; log.AppendText("Flashing Device.....\r\n"); stat.Text = "Flashing Device"; status_flash.Text = "Flashing your device, please wait...."; using (var proc = Process.Start(psi)) { errors = proc.StandardError.ReadToEnd(); output_c = proc.StandardOutput.ReadToEnd(); } log.AppendText("....done\r\n"); Thread.Sleep(2000); log.ForeColor = Color.Lime; log.AppendText("Success! - Your " + devicename + " has been converted into a deauther!\r\n"); icon3.Image = N2D.Properties.Resources.done; COM_DEVICE.RtsEnable = false; COM_DEVICE.DtrEnable = false; Thread.Sleep(100); COM_DEVICE.RtsEnable = true; COM_DEVICE.DtrEnable = true; Thread.Sleep(100); COM_DEVICE.RtsEnable = false; COM_DEVICE.DtrEnable = false; } catch (Exception ex) { log.ForeColor = Color.Red; log.AppendText("Something went wrong! - Restarting in 30s\r\n" + ex.Message); COM_DEVICE.RtsEnable = true; COM_DEVICE.DtrEnable = true; icon3.Image = N2D.Properties.Resources.error; MessageBox.Show("Aw Snap! - Something didn't go quite right while flashing your device! - Try holding down the flash button.", "Something didn't go quite the way we wanted it to", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); Thread.Sleep(30000); Application.Restart(); } }
public static extern UInt32 ymcOpenController( ref COM_DEVICE pComDevice, ref UInt32 hController);
public void FlashDevice_DoWork() { string binaryPath = string.Empty; CheckForIllegalCrossThreadCalls = false; try { DialogResult dg = MessageBox.Show("Do you want to use a custom image for your device? - If unsure, just choose 'No' and the recommended will be applied.", "Correct Image?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly); if (dg == DialogResult.Yes) { _ = BeginInvoke(new MethodInvoker(() => { FlashDevice.Suspend(); stat.Text = "Loading Image"; status_flash.Text = "Reading binary...."; ofd.Filter = "Binary Images | *.bin"; ofd.InitialDirectory = "C:\\"; DialogResult res = ofd.ShowDialog(); if (res == DialogResult.OK) { binaryPath = ofd.FileName; FlashDevice.Resume(); } else { MessageBox.Show("No Image File Selected - Downloading..."); DownloadManager dwmx = new DownloadManager(DownloadManager.DownloadMode.BIN1MB); dwmx.ShowDialog(); binaryPath = dwmx.binary1mb; FlashDevice.Resume(); } })); } else if (dg == DialogResult.No) { BeginInvoke(new MethodInvoker(() => { FlashDevice.Suspend(); DownloadManager dwm = new DownloadManager(DownloadManager.DownloadMode.BIN1MB); dwm.ShowDialog(); binaryPath = dwm.binary1mb; FlashDevice.Resume(); })); } log.ForeColor = Color.Blue; status_flash.Text = "Preparing to flash device on " + CurrentPort + "..."; if (CurrentPort != null) { if (!COM_DEVICE.IsOpen) { COM_DEVICE.PortName = CurrentPort; } COM_DEVICE.StopBits = System.IO.Ports.StopBits.One; COM_DEVICE.Open(); log.AppendText("\r\nINFO: Manual Mode -- COM: " + CurrentPort + " is open! \r\n"); log.AppendText("Connecting to ESP8266....\r\n"); COM_DEVICE.RtsEnable = false; COM_DEVICE.DtrEnable = false; Thread.Sleep(100); // resets the nodemcu / d1 mini COM_DEVICE.RtsEnable = true; COM_DEVICE.DtrEnable = true; Thread.Sleep(100); COM_DEVICE.RtsEnable = false; COM_DEVICE.DtrEnable = false; COM_DEVICE.Close(); } else { log.AppendText("INFO: esptool.py is auto selecting your device."); } log.AppendText("....done\r\n"); Thread.Sleep(2000); log.AppendText("Preparing firmware files.....\r\n"); string dir = Directory.GetCurrentDirectory().ToString() + "\\"; log.AppendText("....done\r\n"); log.AppendText("Creating Parameters.....\r\n"); var assembly = Assembly.GetExecutingAssembly(); string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith("esptool.exe")); log.AppendText(resourceName + "\r\n"); string path = dir + "flash_module.exe"; using (Stream input = assembly.GetManifestResourceStream(resourceName)) using (Stream output = File.Create(path)) { CopyStream(input, output); } var script = path; string argv; if (CurrentPort != null) { argv = "--port " + CurrentPort + " --baud 115200" + " write_flash --flash_mode dio" + " 0x00000 " + binaryPath; } else { argv = " --baud 115200" + " write_flash --flash_mode dio" + " 0x00000 " + binaryPath; } log.AppendText("....done\r\n"); log.AppendText("Setting up procedures.....\r\n"); var psi = new ProcessStartInfo(); psi.FileName = path; psi.Arguments = argv; psi.UseShellExecute = false; psi.CreateNoWindow = true; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; var errors = ""; var output_c = ""; log.AppendText("....done\r\n"); icon2.Image = N2D.Properties.Resources.done; icon3.Image = N2D.Properties.Resources.inprog; log.AppendText("Flashing Device.....\r\n"); stat.Text = "Flashing Device"; status_flash.Text = "Flashing your device, please wait...."; using (var proc = Process.Start(psi)) { errors = proc.StandardError.ReadToEnd(); output_c = proc.StandardOutput.ReadToEnd(); } log.AppendText("....done\r\n"); Thread.Sleep(2000); log.ForeColor = Color.Green; log.AppendText("Success! - Your " + devicename + " has been converted into a deauther!\r\n"); icon3.Image = N2D.Properties.Resources.done; COM_DEVICE.RtsEnable = false; COM_DEVICE.DtrEnable = false; Thread.Sleep(100); COM_DEVICE.RtsEnable = true; COM_DEVICE.DtrEnable = true; Thread.Sleep(100); COM_DEVICE.RtsEnable = false; COM_DEVICE.DtrEnable = false; this.BeginInvoke(new MethodInvoker(() => { FlashDevice_Done(); })); } catch (Exception ex) { stat.Text = "Uh oh!"; status_flash.Text = "A problem has occured"; circlebar.Visible = false; log.ForeColor = Color.Red; log.AppendText("Something went wrong! - Restarting in 30s\r\n" + ex.Message); COM_DEVICE.RtsEnable = true; COM_DEVICE.DtrEnable = true; icon3.Image = N2D.Properties.Resources.error; MessageBox.Show("Aw Snap! - Something didn't go quite right while flashing your device! - Try holding down the flash button.", "Something didn't go quite the way we wanted it to", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); Thread.Sleep(30000); Application.Restart(); } }