예제 #1
0
        private void Button_NextStep_Click(object sender, RoutedEventArgs e)
        {
            TextBox_Log.Text += $"Шаг №{CurrentStep + 1}:" + "\n";
            TextBox_Log.Text += StepsLog[CurrentStep].Message + "\n";
            TextBox_Log.ScrollToEnd();
            ShowStep(CurrentStep);
            if (CurrentStep + 1 >= StepsLog.Count)
            {
                TextBox_Log.Text += "\n === Компоновка закончена ===\n";

                Button_FullComposition.IsEnabled      = true;
                Button_StartStepComposition.IsEnabled = true;
                Button_NextStep.IsEnabled             = false;
                Button_DropStepMode.IsEnabled         = false;

                string str;
                var    cmp = ApplicationData.ReadComposition(out str);
                if (str != "")
                {
                    return;
                }
                ShowWires(cmp);
            }
            else
            {
                CurrentStep++;
            }
        }
예제 #2
0
        private void Button_DropStepMode_Click(object sender, RoutedEventArgs e)
        {
            TextBox_Log.Text = "";
            for (int step = 0; step < StepsLog.Count; step++)
            {
                TextBox_Log.Text += $"Шаг №{step + 1}:" + "\n";
                TextBox_Log.Text += StepsLog[step].Message + "\n";
            }
            TextBox_Log.ScrollToEnd();
            ShowStep(StepsLog.Count - 1); // отображаем только последний шаг графически, т.к. он будет результатом компоновки

            string str;
            var    cmp = ApplicationData.ReadComposition(out str);

            if (str != "")
            {
                return;
            }
            ShowWires(cmp);

            CurrentStep = 0;
            Button_FullComposition.IsEnabled      = true;
            Button_StartStepComposition.IsEnabled = true;
            Button_NextStep.IsEnabled             = false;
            Button_DropStepMode.IsEnabled         = false;
        }
예제 #3
0
        private void Button_FullComposition_Click(object sender, RoutedEventArgs e)
        {
            TextBox_Log.Text = "";
            StepsLog         = DoComposition();
            if (StepsLog.Count == 0)
            {
                MessageBox.Show("Метод компоновки не сработал", "Revolution CAD", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            for (int step = 0; step < StepsLog.Count; step++)
            {
                TextBox_Log.Text += $"Шаг №{step + 1}:" + "\n";
                TextBox_Log.Text += StepsLog[step].Message + "\n";
            }
            TextBox_Log.ScrollToEnd();
            ShowStep(StepsLog.Count - 1); // отображаем только последний шаг графически, т.к. он будет результатом компоновки

            string str;
            var    cmp = ApplicationData.ReadComposition(out str);

            if (str != "")
            {
                return;
            }
            ShowWires(cmp);
        }
예제 #4
0
        private void WriteToLog(string text)
        {
            var time = DateTime.Now.ToShortTimeString();

            TextBox_Log.Text += time + ") " + text + Environment.NewLine;
            TextBox_Log.ScrollToEnd();
            TextBox_Log.CaretIndex = TextBox_Log.Text.Length - 1;
        }
예제 #5
0
        private async void Button_SelectProcess_Click(object sender, RoutedEventArgs e)
        {
            var window = (Window)this.VisualRoot;
            ProcessSelection processSelection = new ProcessSelection();
            var dialogResult = await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync <bool>(() => processSelection.ShowDialog <bool>(window));

            if (dialogResult != true)
            {
                return;
            }
            if (processSelection.SelectedProcess != null)
            {
                TargetProcess            = processSelection.SelectedProcess;
                TargetProcessHandle      = Helper.OpenProcess(TargetProcess.Id);
                TextBox_ProcessName.Text = processSelection.SelectedProcess.ProcessName;
                DataGrid_RIP.DataContext = null;
                TextBox_Log.Clear();

                TextBox_Stack.Clear();
                List <ProcessModule> modules = new List <ProcessModule>();
                var mainModule = TargetProcess.MainModule;
                foreach (ProcessModule m in TargetProcess.Modules)
                {
                    modules.Add(m);
                }

                modules.Sort((a, b) =>
                {
                    if (a.ModuleName == mainModule.ModuleName)
                    {
                        return(-1);
                    }
                    if (b.ModuleName == mainModule.ModuleName)
                    {
                        return(1);
                    }
                    return((int)(a.BaseAddress.ToInt64() - b.BaseAddress.ToInt64()));
                });

                ComboBox_SpecificModule.Items     = modules;
                ComboBox_ScanSpecificModule.Items = modules;
                foreach (ProcessModule m in modules)
                {
                    int    moduleMemorySize = m.ModuleMemorySize;
                    IntPtr startAddres      = m.BaseAddress;
                    IntPtr endAddres        = new IntPtr(m.BaseAddress.ToInt64() + moduleMemorySize);

                    TextBox_Stack.AppendText($"Module Name: {m.ModuleName}" + Environment.NewLine);
                    TextBox_Stack.AppendText($"File Name: {m.FileName}" + Environment.NewLine);
                    TextBox_Stack.AppendText($"Module Size: {moduleMemorySize.ToString("#,0")} Byte" + Environment.NewLine);
                    TextBox_Stack.AppendText($"Start Address: {startAddres.ToInt64().ToString("X2")} ({startAddres.ToInt64()})" + Environment.NewLine);
                    TextBox_Stack.AppendText($"End Address  : {endAddres.ToInt64().ToString("X2")} ({endAddres.ToInt64()})" + Environment.NewLine);
                    TextBox_Stack.AppendText($"---------------------------------------------------------------" + Environment.NewLine);
                }
            }
        }
예제 #6
0
        public void OnEvent(string message)
        {
            Action action = () =>
            {
                TextBox_Log.Text += $"{DateTime.Now}: {message}\r\n";
                TextBox_Log.ScrollToEnd();
            };

            TextBox_Log.Dispatcher.InvokeAsync(action);
        }
예제 #7
0
        private void Button_SelectProcess_Click(object sender, RoutedEventArgs e)
        {
            ProcessSelection processSelection = new ProcessSelection();
            Nullable <bool>  dialogResult     = processSelection.ShowDialog();

            if (dialogResult == true)
            {
                if (processSelection.SelectedProcess != null)
                {
                    TargetProcess            = processSelection.SelectedProcess;
                    TargetProcessHandle      = Helper.OpenProcess((int)Helper.ProcessAccessFlags.PROCESS_VM_READ, false, TargetProcess.Id);
                    TextBox_ProcessName.Text = processSelection.SelectedProcess.ProcessName;
                    DataGrid_RIP.ItemsSource = null;
                    TextBox_Log.Clear();

                    TextBox_Stack.Clear();
                    List <ProcessModule> modules = new List <ProcessModule>();
                    var mainModule = TargetProcess.MainModule;
                    foreach (ProcessModule m in TargetProcess.Modules)
                    {
                        modules.Add(m);
                    }

                    modules.Sort((a, b) => {
                        if (a.ModuleName == mainModule.ModuleName)
                        {
                            return(-1);
                        }
                        if (b.ModuleName == mainModule.ModuleName)
                        {
                            return(1);
                        }
                        return((int)(a.BaseAddress.ToInt64() - b.BaseAddress.ToInt64()));
                    });

                    foreach (ProcessModule m in modules)
                    {
                        int    moduleMemorySize = m.ModuleMemorySize;
                        IntPtr startAddres      = m.BaseAddress;
                        IntPtr endAddres        = new IntPtr(m.BaseAddress.ToInt64() + moduleMemorySize);

                        TextBox_Stack.AppendText($"Module Name: {m.ModuleName}" + "\r\n");
                        TextBox_Stack.AppendText($"File Name: {m.FileName}" + "\r\n");
                        TextBox_Stack.AppendText($"Module Size: {moduleMemorySize.ToString("#,0")} Byte" + "\r\n");
                        TextBox_Stack.AppendText($"Start Address: {startAddres.ToInt64().ToString("X2")} ({startAddres.ToInt64()})" + "\r\n");
                        TextBox_Stack.AppendText($"End Address  : {endAddres.ToInt64().ToString("X2")} ({endAddres.ToInt64()})" + "\r\n");
                        TextBox_Stack.AppendText($"---------------------------------------------------------------" + "\r\n");
                    }
                }
            }
        }
예제 #8
0
        private void Button_DropStepMode_Click(object sender, RoutedEventArgs e)
        {
            TextBox_Log.Text = "";
            for (int step = 0; step < StepsLog.Count; step++)
            {
                TextBox_Log.Text += $"Шаг №{step + 1}:" + "\n";
                TextBox_Log.Text += StepsLog[step].Message + "\n";
            }
            TextBox_Log.ScrollToEnd();
            ShowStep(StepsLog.Count - 1); // отображаем только последний шаг графически, т.к. он будет результатом трассировки

            Button_FullTracing.IsEnabled      = true;
            Button_StartStepTracing.IsEnabled = true;
            Button_NextStep.IsEnabled         = false;
            Button_DropStepMode.IsEnabled     = false;
        }
예제 #9
0
 private void Button_FullPlacement_Click(object sender, RoutedEventArgs e)
 {
     TextBox_Log.Text = "";
     StepsLog         = DoPlacement();
     if (StepsLog.Count == 0)
     {
         MessageBox.Show("Метод размещения не сработал", "Revolution CAD", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     for (int step = 0; step < StepsLog.Count; step++)
     {
         TextBox_Log.Text += $"Шаг №{step + 1}:" + "\n";
         TextBox_Log.Text += StepsLog[step].Message + "\n";
     }
     TextBox_Log.ScrollToEnd();
     ShowStep(StepsLog.Count - 1); // отображаем только последний шаг графически, т.к. он будет результатом компоновки
 }
예제 #10
0
 private void Button_NextStep_Click(object sender, RoutedEventArgs e)
 {
     TextBox_Log.Text += $"Шаг №{CurrentStep + 1}:" + "\n";
     TextBox_Log.Text += StepsLog[CurrentStep].Message + "\n";
     TextBox_Log.ScrollToEnd();
     ShowStep(CurrentStep);
     if (CurrentStep + 1 >= StepsLog.Count)
     {
         TextBox_Log.Text                 += "\n === Трассировка окончена ===\n";
         Button_FullTracing.IsEnabled      = true;
         Button_StartStepTracing.IsEnabled = true;
         Button_NextStep.IsEnabled         = false;
         Button_DropStepMode.IsEnabled     = false;;
     }
     else
     {
         CurrentStep++;
     }
 }
예제 #11
0
 private void Button_NextStep_Click(object sender, RoutedEventArgs e)
 {
     TextBox_Log.Text += $"Шаг №{CurrentStep + 1}:" + "\n";
     TextBox_Log.Text += StepsLog[CurrentStep].Message + "\n";
     TextBox_Log.ScrollToEnd();
     ShowStep(CurrentStep);
     if (CurrentStep + 1 >= StepsLog.Count)
     {
         TextBox_Log.Text += "\n === Размещение закончено ===\n";
         Button_FullPlacement.IsEnabled      = true;
         Button_StartStepPlacement.IsEnabled = true;
         Button_NextStep.IsEnabled           = false;
         Button_DropStepMode.IsEnabled       = false;
     }
     else
     {
         CurrentStep++;
     }
 }
예제 #12
0
 private void Log(string log)
 {
     TextBox_Log.AppendText(log + Environment.NewLine);
 }
예제 #13
0
 private void ClearLog()
 {
     TextBox_Log.Clear();
 }
예제 #14
0
        private async void Button_StartScan_Click(object sender, RoutedEventArgs e)
        {
            DataGrid_RIP.DataContext = null;
            entries = new List <RIPEntry>();
            TextBox_Log.Clear();
            GC.Collect();

            if (string.IsNullOrWhiteSpace(TextBox_FilterString.Text))
            {
                var result = await MessageBox.Show("Requires huge memories to run without filter.\n If results are more than 1M, snip them.\n Procced?", "Caution", MessageBoxButton.OKCancel);

                if (result != MessageBoxResult.OK)
                {
                    return;
                }
            }


            if (this.RadioButton_Group1_Process.IsChecked == true)
            {
                if (TargetProcess == null)
                {
                    return;
                }

                //List<RIPEntry> entries = new List<RIPEntry>();
                Stopwatch stopwatch = new Stopwatch();
                SetUIEnabled(false);

                List <string> filters = ParseFilter();
                foreach (var f in filters)
                {
                    TextBox_Log.AppendText($"filter: {f}" + Environment.NewLine);
                }

                bool searchFromAllModules = CheckBox_AllModules.IsChecked ?? false;
                bool onlyLEA = CheckBox_OnlyLEA.IsChecked ?? false;

                List <ProcessModule> ProcessModules = new List <ProcessModule>();

                if (searchFromAllModules)
                {
                    foreach (ProcessModule m in TargetProcess.Modules)
                    {
                        ProcessModules.Add(m);
                    }
                }
                else
                {
                    if (ComboBox_SpecificModule.SelectedItem != null)
                    {
                        ProcessModules.Add((ProcessModule)ComboBox_SpecificModule.SelectedItem);
                    }
                    else
                    {
                        ProcessModules.Add(TargetProcess.MainModule);
                    }
                }


                var task = Task.Run(() =>
                {
                    foreach (var m in ProcessModules)
                    {
                        int moduleMemorySize = m.ModuleMemorySize;
                        IntPtr startAddres   = m.BaseAddress;
                        IntPtr endAddres     = new IntPtr(m.BaseAddress.ToInt64() + moduleMemorySize);

                        this.Dispatcher.Invoke((Action)(() =>
                        {
                            TextBox_Log.AppendText($"----------------------------------------------------" + Environment.NewLine);

                            TextBox_Log.AppendText($"Module Name: {m.ModuleName}" + Environment.NewLine);
                            TextBox_Log.AppendText($"File Name: {m.FileName}" + Environment.NewLine);
                            TextBox_Log.AppendText($"Module Size: {moduleMemorySize.ToString("#,0")} Byte" + Environment.NewLine);
                            TextBox_Log.AppendText($"Start Address: {startAddres.ToInt64().ToString("X2")} ({startAddres.ToInt64()})" + Environment.NewLine);
                            TextBox_Log.AppendText($"End Address  : {endAddres.ToInt64().ToString("X2")} ({endAddres.ToInt64()})" + Environment.NewLine);
                            TextBox_Log.AppendText($"Scan started. Please wait..." + "  ");
                        }));

                        stopwatch.Start();

                        IntPtr currentAddress = startAddres;
                        int bufferSize        = 1 * 1024 * 1024;
                        byte[] buffer         = new byte[bufferSize];

                        while (currentAddress.ToInt64() < endAddres.ToInt64())
                        {
                            // size
                            IntPtr nSize = new IntPtr(bufferSize);

                            // if remaining memory size is less than splitSize, change nSize to remaining size
                            if (IntPtr.Add(currentAddress, bufferSize).ToInt64() > endAddres.ToInt64())
                            {
                                nSize = (IntPtr)(endAddres.ToInt64() - currentAddress.ToInt64());
                            }

                            IntPtr numberOfBytesRead = IntPtr.Zero;
                            if (Helper.ReadProcessMemory(TargetProcessHandle, currentAddress, buffer, nSize, ref numberOfBytesRead))
                            {
                                for (int i = 0; i < numberOfBytesRead.ToInt64() - 4; i++)
                                {
                                    var entry               = new RIPEntry();
                                    entry.Address           = new IntPtr(currentAddress.ToInt64() + i);
                                    entry.AddressValueInt64 = BitConverter.ToInt32(buffer, i);
                                    entry.TargetAddress     = new IntPtr(entry.Address.ToInt64() + entry.AddressValueInt64 + 4);


                                    if (entry.TargetAddress.ToInt64() < startAddres.ToInt64() || entry.TargetAddress.ToInt64() > endAddres.ToInt64())
                                    {
                                        continue;
                                    }

                                    var offsetString1 = (entry.Address.ToInt64() - startAddres.ToInt64()).ToString("X");
                                    if (offsetString1.Length % 2 == 1)
                                    {
                                        offsetString1 = "0" + offsetString1;
                                    }
                                    entry.AddressRelativeString = '"' + m.ModuleName + '"' + "+" + offsetString1;

                                    var offsetString2 = (entry.TargetAddress.ToInt64() - startAddres.ToInt64()).ToString("X");
                                    if (offsetString2.Length % 2 == 1)
                                    {
                                        offsetString2 = "0" + offsetString2;
                                    }
                                    entry.TargetAddressRelativeString = '"' + m.ModuleName + '"' + "+" + offsetString2;

                                    if (filters.Any() &&
                                        !filters.Any(x => x == entry.TargetAddressString) &&
                                        !filters.Any(x => x == entry.TargetAddressRelativeString))
                                    {
                                        continue;
                                    }

                                    // Signature
                                    int bufferSize2           = 64;
                                    byte[] buffer2            = new byte[bufferSize2];
                                    IntPtr nSize2             = new IntPtr(bufferSize2);
                                    IntPtr numberOfBytesRead2 = IntPtr.Zero;
                                    if (Helper.ReadProcessMemory(TargetProcessHandle, new IntPtr(entry.Address.ToInt64() - bufferSize2), buffer2, nSize2, ref numberOfBytesRead2))
                                    {
                                        if (numberOfBytesRead2.ToInt64() == bufferSize2)
                                        {
                                            if (onlyLEA && (buffer2.Length < 2 || buffer2[buffer2.Length - 2] != 0x8D))
                                            {
                                                continue;
                                            }
                                            entry.Signature = BitConverter.ToString(buffer2).Replace("-", "");
                                        }
                                    }

                                    if (entries.Count < MaxEntries)
                                    {
                                        entries.Add(entry);
                                    }
                                }
                            }
                            if ((currentAddress.ToInt64() + numberOfBytesRead.ToInt64()) == endAddres.ToInt64())
                            {
                                currentAddress = new IntPtr(currentAddress.ToInt64() + numberOfBytesRead.ToInt64());
                            }
                            else
                            {
                                currentAddress = new IntPtr(currentAddress.ToInt64() + numberOfBytesRead.ToInt64() - 4);
                            }
                        }

                        stopwatch.Stop();

                        this.Dispatcher.Invoke((Action)(() =>
                        {
                            TextBox_Log.AppendText($"Complete." + Environment.NewLine);
                            TextBox_Log.AppendText($"Result Count: {entries.Count.ToString("#,0")}" + Environment.NewLine);
                            TextBox_Log.AppendText($"Scan Time: {stopwatch.ElapsedMilliseconds}ms" + Environment.NewLine);
                        }));
                    }
                });

                await task;
                DataGrid_RIP.Items = entries;
                SetUIEnabled(true);
            }
            else if (this.RadioButton_Group1_File.IsChecked == true)
            {
                if (string.IsNullOrWhiteSpace(BinFileName))
                {
                    return;
                }
                Stopwatch stopwatch = new Stopwatch();

                SetUIEnabled(false);

                List <string> filters = ParseFilter();
                foreach (var f in filters)
                {
                    TextBox_Log.AppendText($"filter: {f}" + Environment.NewLine);
                }


                var task = Task.Run(() =>
                {
                    System.IO.FileStream fs  = new System.IO.FileStream(BinFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    System.IO.FileStream fs2 = new System.IO.FileStream(BinFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                    long startPosition   = 0;
                    long endPosition     = fs.Length;
                    long currentPosition = 0;

                    int bufferSize = 8 * 1024 * 1024;
                    byte[] buffer  = new byte[bufferSize];

                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        TextBox_Log.AppendText($"----------------------------------------------------" + Environment.NewLine);
                        TextBox_Log.AppendText($"File Name: {BinFileName}" + Environment.NewLine);
                        TextBox_Log.AppendText($"Module Size: {endPosition.ToString("#,0")} Byte" + Environment.NewLine);
                        TextBox_Log.AppendText($"Scan started. Please wait..." + "  ");
                    }));

                    stopwatch.Start();

                    while (currentPosition < endPosition)
                    {
                        int readSize = fs.Read(buffer, 0, bufferSize);

                        for (int i = 0; i < readSize - 4; i++)
                        {
                            var entry               = new RIPEntry();
                            entry.Address           = new IntPtr(currentPosition + i);
                            entry.AddressValueInt64 = BitConverter.ToInt32(buffer, i);
                            entry.TargetAddress     = new IntPtr(entry.Address.ToInt64() + entry.AddressValueInt64 + 4);

                            if (entry.TargetAddress.ToInt64() < startPosition || entry.TargetAddress.ToInt64() > endPosition)
                            {
                                continue;
                            }

                            var offsetString1 = (entry.Address.ToInt64() - startPosition).ToString("X");
                            if (offsetString1.Length % 2 == 1)
                            {
                                offsetString1 = "0" + offsetString1;
                            }
                            entry.AddressRelativeString = '"' + System.IO.Path.GetFileName(BinFileName) + '"' + "+" + offsetString1;

                            var offsetString2 = (entry.TargetAddress.ToInt64() - startPosition).ToString("X");
                            if (offsetString2.Length % 2 == 1)
                            {
                                offsetString2 = "0" + offsetString2;
                            }
                            entry.TargetAddressRelativeString = '"' + System.IO.Path.GetFileName(BinFileName) + '"' + "+" + offsetString2;

                            if (filters.Any() &&
                                !filters.Any(x => x == entry.TargetAddressString) &&
                                !filters.Any(x => x == entry.TargetAddressRelativeString))
                            {
                                continue;
                            }

                            // Signature

                            int bufferSize2 = 64;
                            byte[] buffer2  = new byte[bufferSize2];
                            int offset2     = entry.Address.ToInt32() - bufferSize2;
                            if (offset2 >= 0 && offset2 + bufferSize2 <= endPosition)
                            {
                                fs2.Seek(offset2, System.IO.SeekOrigin.Begin);
                                var readBytes = fs2.Read(buffer2, 0, bufferSize2);
                                if (readBytes == bufferSize2)
                                {
                                    entry.Signature = BitConverter.ToString(buffer2).Replace("-", "");
                                }
                            }

                            if (entries.Count < MaxEntries)
                            {
                                entries.Add(entry);
                            }
                        }

                        if (readSize < bufferSize)
                        {
                            currentPosition += readSize;
                        }
                        else
                        {
                            currentPosition += (readSize - 4);
                            fs.Seek(-4, System.IO.SeekOrigin.Current);
                        }
                    }

                    fs.Close();
                    fs2.Close();

                    stopwatch.Stop();

                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        TextBox_Log.AppendText($"Complete." + Environment.NewLine);
                        TextBox_Log.AppendText($"Result Count: {entries.Count.ToString("#,0")}" + Environment.NewLine);
                        TextBox_Log.AppendText($"Scan Time: {stopwatch.ElapsedMilliseconds}ms" + Environment.NewLine);
                    }));
                });

                await task;
                DataGrid_RIP.DataContext = entries;

                SetUIEnabled(true);
            }

            GC.Collect();
        }
예제 #15
0
 public void addLog(String message)
 {
     TextBox_Log.AppendText(message + Environment.NewLine);
 }