private void buttonAssemble_Click(object sender, RoutedEventArgs e) { try { this.labelOutputTime.Content = DateTime.Now.ToLongTimeString(); cleanTempFolder(); resetAllErrorTags(); string userInput = this.textBoxInput.Text; FileInfo file = new FileInfo("temp/input_code.asm"); file.Directory.Create(); File.WriteAllText(file.FullName, userInput); System.Diagnostics.Process process_assembly = createProcess("nasm", "-o temp/output temp/input_code.asm"); process_assembly.Start(); process_assembly.WaitForExit(); System.Diagnostics.Process process_disassembly = createProcess("ndisasm", "temp/output"); process_disassembly.Start(); process_disassembly.WaitForExit(); try { if (process_disassembly.StandardError.ReadToEnd().Contains("No such file or directory")) { throw new Exception(); } string process_disassembly_output = process_disassembly.StandardOutput.ReadToEnd(); disasm = new Disassembly(process_disassembly_output); this.textBoxOutput.Text = DataManipulation.manipulateOutput(disasm.getAllOpcodes()); this.labelOutputSize.Content = "SC Length: " + disasm.getSize() + " Bytes"; this.assemblerSuccess = true; } catch (Exception exception) { throw exception; } } catch (Exception exception) { this.textBoxOutput.Text = "Assembler raised an error.\nPlease check your code.\n\n" + exception; this.assemblerSuccess = false; } finally { performTests(disasm); cleanTempFolder(); } }
private void performTests(Disassembly disasm) { // perform assembler test if (!this.assemblerSuccess) { this.buttonCheckAssemblerSuccess.Background = Brushes.Red; resetAllErrorTags(); // return so no the rest of the test won't be performed return; } this.buttonCheckAssemblerSuccess.Background = Brushes.Green; // perform null byte test if (Settings.getCheckContainsNullByte()) { this.buttonCheckNullByte.Background = Brushes.Green; foreach (DisassemblyLine dl in disasm.getLines()) { if ((DataManipulation.splitEveryNChars(dl.getOpcodes(), 2)).Contains("00")) { this.buttonCheckNullByte.Background = Brushes.Red; } } this.buttonCheckNullByte.IsEnabled = true; } else { resetErrorTag(this.buttonCheckNullByte); } // perform max size test if (Settings.getCheckMaxSize()) { if (disasm.getSize() > Settings.getMaxSize()) { this.buttonCheckMaxSize.Background = Brushes.Red; } else { this.buttonCheckMaxSize.Background = Brushes.Green; } this.buttonCheckMaxSize.IsEnabled = true; } else { resetErrorTag(this.buttonCheckMaxSize); } }