Example #1
0
        private void Disasm_DataRecevied(object sender, DataReceivedEventArgs e)
        {
            Regex functionPattern = new Regex(@"^\d+ \<(.*)\>:\s*$");
            Regex linePattern     = new Regex(@"^\s*([0-9A-Fa-f]+):\s*(.*)(?: )*\t\s*([^\<#\s]*)([^\<#]*)?\s*(#.*)?\s*(?:\<([^\+]*)(?:\+0x([0-9A-Fa-f]+))\>)?\s*$");
            Regex locationPattern = new Regex(@"^((?:[A-Z]:\\)?[^:]+):(\d+)\s*$");

            if (e.Data == null)
            {
                return;
            }

            Match funcMatch = functionPattern.Match(e.Data);

            if (funcMatch.Success)
            {
                if (currentFunction != null)
                {
                    lock (functions) {
                        functions.Add(currentFunction);
                    }
                }
                currentFunction = new AsmFunction(funcMatch.Groups[1].Value, disasmLineNo);
            }
            else if (currentFunction != null)
            {
                Match lineMatch = linePattern.Match(e.Data);
                if (lineMatch.Success)
                {
                    (currentFunction.Assembly as List <AsmLine>)?.Add(new AsmLine()
                    {
                        Offset      = Convert.ToInt32(lineMatch.Groups[1].Value, 16),
                        MachineCode = lineMatch.Groups[2].Value.Trim(),
                        Opcode      = lineMatch.Groups[3].Value.Trim(),
                        Operands    = lineMatch.Groups[4].Value.Trim(),
                        Comment     = lineMatch.Groups[5].Value,
                        Reference   = new AsmReference(lineMatch.Groups[6].Value, lineMatch.Groups[7].Success ?
                                                       Convert.ToInt32(lineMatch.Groups[7].Value, 16) : 0),
                        SourceFile     = currentSourceFile,
                        SourceFileLine = currentSourceFileLine
                    });
                }
                else
                {
                    Match locMatch = locationPattern.Match(e.Data);
                    if (locMatch.Success)
                    {
                        currentSourceFile     = locMatch.Groups[1].Value;
                        currentSourceFileLine = Convert.ToInt32(locMatch.Groups[2].Value);
                    }
                }
            }

            disasmLineNo += 1;
        }
Example #2
0
        public void AddFunction(AsmFunction function)
        {
            var nameMargin = new Thickness(5, 0, 0, 0);

            var nameLabel = new TextBlock()
            {
                Margin = nameMargin,
                Text   = function.Name.ToString(),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                FontWeight          = FontWeights.Bold
            };

            var bgRect = new Rectangle()
            {
                Fill = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0))
            };

            bgRect.SetValue(Grid.RowProperty, nextRow);
            bgRect.SetValue(Grid.ColumnProperty, 0);
            bgRect.SetValue(Grid.ColumnSpanProperty, 4);
            this.asmGrid.Children.Add(bgRect);

            nameLabel.SetValue(Grid.ColumnProperty, 1);
            nameLabel.SetValue(Grid.ColumnSpanProperty, 3);

            this.asmGrid.RowDefinitions.Add(new RowDefinition());
            nameLabel.SetValue(Grid.RowProperty, nextRow);
            this.asmGrid.Children.Add(nameLabel);

            int startRow = nextRow++;

            foreach (var line in function.Assembly)
            {
                AddLine(line);
            }
            int endRow = nextRow;

            functionEntries.Add(function, new Tuple <int, int, TextBlock>(
                                    startRow, endRow, nameLabel));
        }
Example #3
0
        private void DoDisassembly()
        {
            // Check if one already running (TODO: There used to be a justification for using CVs!)
            if (!disassemblyCV.WaitOne(1))
            {
                return;
            }

            try
            {
                string includes = IncludePaths;
                string flags    = "";
                Dispatcher.Invoke((Action) delegate
                {
                    loadingText.Content    = "Initializing...";
                    progress.Visibility    = Visibility.Visible;
                    loadingGrid.Visibility = Visibility.Visible;

                    messageStack.Children.Clear();
                    messageStack.Children.Add(asmGrid);
                    asmGrid.Clear();

                    flags = flagsText.Text;
                });

                lock (messages) {
                    messages.Clear();
                }
                lock (functions)
                {
                    functions.Clear();
                    currentFunction = null;
                }


                // Delete the object file
                try { System.IO.File.Delete(objfile); }
                catch { }

                ProcessStartInfo info = new ProcessStartInfo()
                {
                    FileName  = compiler.Filepath,
                    Arguments = $"-g -o \"{objfile}\" {includes} {flags} -c \"{TargetFile}\"",

                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    UseShellExecute        = false,
                    CreateNoWindow         = true
                };

                var proc = Process.Start(info);
                proc.BeginErrorReadLine();
                proc.BeginOutputReadLine();

                proc.ErrorDataReceived  += Compiler_ErrorMsgReceived;
                proc.OutputDataReceived += Compiler_OutputMsgReceived;

                Dispatcher.Invoke((Action) delegate {
                    loadingText.Content = "Compiling...";
                });

                if (!proc.WaitForExit(10000))
                {
                    ShowError("The operation timed out.");
                    return;
                }

                if (proc.ExitCode == 0)
                {
                    info = new ProcessStartInfo()
                    {
                        FileName  = disasmFilepath,
                        Arguments = $"-C -l -d \"{objfile}\"",

                        RedirectStandardError  = true,
                        RedirectStandardOutput = true,
                        UseShellExecute        = false,
                        CreateNoWindow         = true
                    };

                    proc = Process.Start(info);
                    proc.BeginErrorReadLine();
                    proc.BeginOutputReadLine();

                    proc.OutputDataReceived += Disasm_DataRecevied;

                    Dispatcher.Invoke((Action) delegate {
                        loadingText.Content = "Disassembling...";
                    });

                    if (!proc.WaitForExit(10000))
                    {
                        ShowError("The operation timed out.");
                        return;
                    }
                }


                Dispatcher.BeginInvoke((Action) delegate
                {
                    lock (messages)
                    {
                        foreach (var msg in messages)
                        {
                            messageStack.Children.Add(new TextBlock()
                            {
                                Text = msg.Message
                            });
                        }
                    }
                    lock (functions)
                    {
                        foreach (var function in functions)
                        {
                            asmGrid.AddFunction(function);
                        }
                    }
                    loadingGrid.Visibility = Visibility.Collapsed;
                });
            }
            finally
            {
                // Release condition variable
                disassemblyCV.Set();
            }
        }