├── .gitmodules ├── JitTest ├── JitTest │ ├── main.cpp │ ├── JitTest.vcxproj.user │ ├── JitTest.vcxproj.filters │ └── JitTest.vcxproj └── JitTest.sln ├── screenshot.png ├── JitMagic ├── JitMagic │ ├── JitMagic.ico │ ├── App.xaml.cs │ ├── App.xaml │ ├── AssemblyInfo.cs │ ├── NativeMethods.txt │ ├── MVVMLibLite │ │ ├── OurViewModelBase.cs │ │ ├── ObservableClass.cs │ │ ├── OurCommand.cs │ │ └── MVVMSObservableObject.cs │ ├── JitMagic.csproj │ ├── Views │ │ ├── JITSelectorWindow.xaml.cs │ │ └── JITSelectorWindow.xaml │ ├── Models │ │ ├── ProcHelper.cs │ │ ├── JitDebugger.cs │ │ ├── CLIManager.cs │ │ ├── AEDebugManager.cs │ │ ├── ConfigManager.cs │ │ └── FileHelper.cs │ ├── app.manifest │ └── ViewModels │ │ └── JITSelectorViewModel.cs └── JitMagic.sln ├── .gitignore ├── ManagedJitTest ├── ManagedJitTest │ ├── App.config │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── ManagedJitTest.csproj └── ManagedJitTest.sln ├── .github └── workflows │ └── continuous.yml ├── README.md └── LICENSE /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /JitTest/JitTest/main.cpp: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | __debugbreak(); 4 | } -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrexodia/JitMagic/HEAD/screenshot.png -------------------------------------------------------------------------------- /JitMagic/JitMagic/JitMagic.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrexodia/JitMagic/HEAD/JitMagic/JitMagic/JitMagic.ico -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | asInvoker/ 3 | bin/ 4 | obj/ 5 | requireAdministrator/ 6 | Release/ 7 | Debug/ 8 | x64/ 9 | packages/ 10 | -------------------------------------------------------------------------------- /JitTest/JitTest/JitTest.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ManagedJitTest/ManagedJitTest/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Configuration; 2 | using System.Data; 3 | using System.Windows; 4 | 5 | namespace JitMagic { 6 | /// 7 | /// Interaction logic for App.xaml 8 | /// 9 | public partial class App : Application { 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /ManagedJitTest/ManagedJitTest/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ManagedJitTest 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | throw new Exception("ManagedJitTest"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] 11 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/NativeMethods.txt: -------------------------------------------------------------------------------- 1 | GetFinalPathNameByHandle 2 | CreateFile 3 | FILE_ACCESS_RIGHTS 4 | GENERIC_ACCESS_RIGHTS 5 | SetProcessMitigationPolicy 6 | GetProcessMitigationPolicy 7 | PROCESS_MITIGATION_REDIRECTION_TRUST_POLICY 8 | PROCESS_MITIGATION_DEP_POLICY 9 | DeviceIoControl 10 | MAXIMUM_REPARSE_DATA_BUFFER_SIZE 11 | FSCTL_GET_REPARSE_POINT 12 | REPARSE_DATA_BUFFER 13 | IO_REPARSE_TAG_SYMLINK 14 | IsWow64Process 15 | CreateEvent 16 | SetEvent 17 | WaitForSingleObject 18 | WaitForMultipleObjects 19 | CloseHandle 20 | SYMLINK_FLAG_RELATIVE 21 | IO_REPARSE_TAG_MOUNT_POINT -------------------------------------------------------------------------------- /.github/workflows/continuous.yml: -------------------------------------------------------------------------------- 1 | env: 2 | NUKE_TELEMETRY_OPTOUT: 1 3 | name: continuous 4 | 5 | on: 6 | push: 7 | branches-ignore: 8 | - trash 9 | 10 | jobs: 11 | continuous: 12 | name: Run 13 | runs-on: windows-latest 14 | defaults: 15 | run: 16 | shell: pwsh 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | with: 21 | submodules: recursive 22 | fetch-depth: 0 23 | 24 | - name: Run Build 25 | run: ./build.ps1 26 | 27 | - uses: actions/upload-artifact@v4 28 | with: 29 | name: JitMagic 30 | path: JitMagic\JitMagic\bin\x64\Release\net472\publish -------------------------------------------------------------------------------- /JitTest/JitTest/JitTest.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /JitMagic/JitMagic.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35417.141 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JitMagic", "JitMagic\JitMagic.csproj", "{63A0047E-64E8-4620-BB50-AE1CA17B3975}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {63A0047E-64E8-4620-BB50-AE1CA17B3975}.Debug|x64.ActiveCfg = Debug|x64 15 | {63A0047E-64E8-4620-BB50-AE1CA17B3975}.Debug|x64.Build.0 = Debug|x64 16 | {63A0047E-64E8-4620-BB50-AE1CA17B3975}.Release|x64.ActiveCfg = Release|x64 17 | {63A0047E-64E8-4620-BB50-AE1CA17B3975}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {D959A076-86C3-4F29-BF66-6ECD4D611E2D} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/MVVMLibLite/OurViewModelBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Threading.Tasks; 5 | namespace JitMagic.MVVMLibLite { 6 | abstract public class OurViewModelBase : MVVMSObservableObject { 7 | protected Dictionary func_to_cmd; 8 | protected Dictionary, OurCommand> func_to_cmd_tsk; 9 | 10 | 11 | protected OurCommand GetOurCmd(Func func, bool auto_disable = true) { 12 | OurCommand ret; 13 | if (func_to_cmd_tsk == null) 14 | func_to_cmd_tsk = new Dictionary, OurCommand>(); 15 | if (func_to_cmd_tsk.TryGetValue(func, out ret)) 16 | return ret; 17 | return func_to_cmd_tsk[func] = new OurCommand(func, auto_disable); 18 | 19 | } 20 | 21 | protected OurCommand GetOurCmdSync(Action func, bool auto_disable = true, bool in_background = false) { 22 | OurCommand ret; 23 | if (func_to_cmd == null) 24 | func_to_cmd = new Dictionary(); 25 | if (func_to_cmd.TryGetValue(func, out ret)) 26 | return ret; 27 | return func_to_cmd[func] = new OurCommand(func, auto_disable, in_background); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /ManagedJitTest/ManagedJitTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ManagedJitTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ManagedJitTest")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e56f4752-28c7-427d-8ab4-f2e5675aa695")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/MVVMLibLite/ObservableClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | namespace JitMagic.MVVMLibLite { 5 | 6 | public abstract class ObservableClass : MVVMSObservableObject { 7 | protected virtual void RaisePropertyChanged(string propertyName, T oldValue, T newValue) { 8 | if (string.IsNullOrEmpty(propertyName)) 9 | throw new ArgumentException("This method cannot be called with an empty string", "propertyName"); 10 | base.RaisePropertyChanged(propertyName); 11 | } 12 | protected virtual void RaisePropertyChanged(System.Linq.Expressions.Expression> propertyExpression, T oldValue, T newValue) { 13 | var propertyChangedHandler = PropertyChangedHandler; 14 | if (propertyChangedHandler == null) 15 | return; 16 | string propertyName = GetPropertyName(propertyExpression); 17 | propertyChangedHandler(this, new PropertyChangedEventArgs(propertyName)); 18 | } 19 | protected new bool Set(System.Linq.Expressions.Expression> propertyExpression, ref T field, T newValue) { 20 | if (EqualityComparer.Default.Equals(field, newValue)) 21 | return false; 22 | T oldValue = field; 23 | field = newValue; 24 | 25 | RaisePropertyChanged(propertyExpression, oldValue, field); 26 | return true; 27 | } 28 | protected new bool Set(string propertyName, ref T field, T newValue) { 29 | if (EqualityComparer.Default.Equals(field, newValue)) 30 | return false; 31 | T oldValue = field; 32 | field = newValue; 33 | RaisePropertyChanged(propertyName, oldValue, field); 34 | return true; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ManagedJitTest/ManagedJitTest.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27906.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedJitTest", "ManagedJitTest\ManagedJitTest.csproj", "{E56F4752-28C7-427D-8AB4-F2E5675AA695}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Any CPU|Any CPU = Any CPU|Any CPU 11 | Prefer 32-bit|Any CPU = Prefer 32-bit|Any CPU 12 | x64|Any CPU = x64|Any CPU 13 | x86|Any CPU = x86|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {E56F4752-28C7-427D-8AB4-F2E5675AA695}.Any CPU|Any CPU.ActiveCfg = Any CPU|Any CPU 17 | {E56F4752-28C7-427D-8AB4-F2E5675AA695}.Any CPU|Any CPU.Build.0 = Any CPU|Any CPU 18 | {E56F4752-28C7-427D-8AB4-F2E5675AA695}.Prefer 32-bit|Any CPU.ActiveCfg = Prefer 32-bit|Any CPU 19 | {E56F4752-28C7-427D-8AB4-F2E5675AA695}.Prefer 32-bit|Any CPU.Build.0 = Prefer 32-bit|Any CPU 20 | {E56F4752-28C7-427D-8AB4-F2E5675AA695}.x64|Any CPU.ActiveCfg = x64|Any CPU 21 | {E56F4752-28C7-427D-8AB4-F2E5675AA695}.x64|Any CPU.Build.0 = x64|Any CPU 22 | {E56F4752-28C7-427D-8AB4-F2E5675AA695}.x86|Any CPU.ActiveCfg = x86|Any CPU 23 | {E56F4752-28C7-427D-8AB4-F2E5675AA695}.x86|Any CPU.Build.0 = x86|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {EA417BF5-2CA6-4A99-B859-1F4BC81874B1} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /JitTest/JitTest.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27520.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JitTest", "JitTest\JitTest.vcxproj", "{A63276BB-9346-475E-A332-74700C9F73EE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | asInvoker|x64 = asInvoker|x64 11 | asInvoker|x86 = asInvoker|x86 12 | requireAdministrator|x64 = requireAdministrator|x64 13 | requireAdministrator|x86 = requireAdministrator|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {A63276BB-9346-475E-A332-74700C9F73EE}.asInvoker|x64.ActiveCfg = asInvoker|x64 17 | {A63276BB-9346-475E-A332-74700C9F73EE}.asInvoker|x64.Build.0 = asInvoker|x64 18 | {A63276BB-9346-475E-A332-74700C9F73EE}.asInvoker|x86.ActiveCfg = asInvoker|Win32 19 | {A63276BB-9346-475E-A332-74700C9F73EE}.asInvoker|x86.Build.0 = asInvoker|Win32 20 | {A63276BB-9346-475E-A332-74700C9F73EE}.requireAdministrator|x64.ActiveCfg = requireAdministrator|x64 21 | {A63276BB-9346-475E-A332-74700C9F73EE}.requireAdministrator|x64.Build.0 = requireAdministrator|x64 22 | {A63276BB-9346-475E-A332-74700C9F73EE}.requireAdministrator|x86.ActiveCfg = requireAdministrator|Win32 23 | {A63276BB-9346-475E-A332-74700C9F73EE}.requireAdministrator|x86.Build.0 = requireAdministrator|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {1657A21C-0659-4DF1-B3C5-FFC510BEDA9C} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/JitMagic.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | net472 6 | true 7 | JitMagic.ico 8 | x64 9 | preview 10 | app.manifest 11 | 12 | https://github.com/mrexodia/JitMagic 13 | Copyright © x64dbg 14 | x64 15 | $(DefineConstants);IS_WPF 16 | https://github.com/mrexodia/JitMagic 17 | git 18 | 2.0.0.0 19 | $(AssemblyVersion) 20 | $(AssemblyVersion) 21 | 22 | 23 | 24 | 25 | 26 | Never 27 | 28 | 29 | 30 | 31 | 32 | 33 | all 34 | runtime; build; native; contentfiles; analyzers; buildtransitive 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/MVVMLibLite/OurCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading.Tasks; 4 | using System.Windows.Input; 5 | 6 | namespace JitMagic.MVVMLibLite { 7 | public class OurCommand : ICommand { 8 | private static Task T(Action action) { 9 | try { 10 | action(); 11 | return Task.CompletedTask; 12 | } catch (Exception exception) { 13 | return Task.FromException(exception); 14 | } 15 | } 16 | public TimeSpan CommandMinRunTime = TimeSpan.FromSeconds(1); 17 | public bool CanExecute(object parameter) => (!auto_disable || !_running) && enabled; 18 | public OurCommand(Func action, bool auto_disable = true) { 19 | async_action = action; 20 | this.auto_disable = auto_disable; 21 | } 22 | public OurCommand(Action action, bool auto_disable, bool in_background) { 23 | if (in_background) 24 | async_action = () => Task.Run(action); 25 | else 26 | async_action = () => T(action); 27 | this.auto_disable = auto_disable; 28 | } 29 | private bool running { 30 | set { 31 | if (_running == value) 32 | return; 33 | _running = value; 34 | CanExecuteChanged?.Invoke(this, null); 35 | } 36 | } 37 | private bool _running; 38 | public bool enabled { 39 | get { return _enabled; } 40 | set { 41 | if (_enabled == value) 42 | return; 43 | _enabled = value; 44 | CanExecuteChanged?.Invoke(this, null); 45 | } 46 | } 47 | private bool _enabled = true; 48 | public event EventHandler CanExecuteChanged; 49 | public Func async_action; 50 | 51 | private readonly bool auto_disable; 52 | public void Execute(object parameter) { 53 | #pragma warning disable 4014 54 | Execute(); 55 | #pragma warning restore 4014 56 | } 57 | public async Task Execute() { 58 | if (!enabled) 59 | return; 60 | running = true; 61 | var start_time = DateTime.MinValue; 62 | try { 63 | if (auto_disable) 64 | start_time = DateTime.Now; 65 | await async_action.Invoke(); 66 | } catch (Exception e) { 67 | Debug.WriteLine($"Unhandled command exception of: {e}"); 68 | } finally { 69 | if (auto_disable) { 70 | var diff = DateTime.Now - start_time; 71 | if (diff < CommandMinRunTime) 72 | await Task.Delay(CommandMinRunTime - diff); 73 | } 74 | running = false; 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /JitMagic/JitMagic/Views/JITSelectorWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using System.Windows.Data; 10 | using System.Windows.Documents; 11 | using System.Windows.Input; 12 | using System.Windows.Media; 13 | using System.Windows.Media.Imaging; 14 | using System.Windows.Shapes; 15 | using JitMagic.ViewModels; 16 | 17 | namespace JitMagic.Views { 18 | /// 19 | /// Interaction logic for JITSelectorWindow.xaml 20 | /// 21 | public partial class JITSelectorWindow : Window { 22 | public JITSelectorWindow() { 23 | InitializeComponent(); 24 | Loaded += JITSelectorWindow_Loaded; 25 | KeyDown += JITSelectorWindow_KeyDown; 26 | Closing += JITSelectorWindow_Closing; 27 | vm.CloseWin += (_, _) => { if (!closing) Close(); }; 28 | vm.HideWin += (_,_) => Hide(); 29 | } 30 | 31 | 32 | 33 | 34 | 35 | private void JITSelectorWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { 36 | closing = true; 37 | vm.Close(); 38 | } 39 | 40 | private bool closing; 41 | private void JITSelectorWindow_KeyDown(object sender, KeyEventArgs e) { 42 | if (e.Key == Key.Escape) 43 | Close(); 44 | } 45 | 46 | private void JITSelectorWindow_Loaded(object sender, RoutedEventArgs e) { 47 | Visibility = Visibility.Visible; 48 | vm.Loaded(); 49 | if (listDebuggers.HasItems) { 50 | var firstUIItem = listDebuggers.ItemContainerGenerator.ContainerFromItem(listDebuggers.SelectedItem); 51 | Keyboard.Focus(firstUIItem as FrameworkElement); 52 | } 53 | 54 | } 55 | public JITSelectorViewModel vm => DataContext as JITSelectorViewModel; 56 | 57 | 58 | private void ListBox_KeyDown(object sender, KeyEventArgs e) { 59 | //sopport wrapping to the next line for selection 60 | var list = sender as ListBox; 61 | switch (e.Key) { 62 | case Key.Right: 63 | if (!list.Items.MoveCurrentToNext()) 64 | list.Items.MoveCurrentToLast(); 65 | break; 66 | case Key.Left: 67 | if (!list.Items.MoveCurrentToPrevious()) 68 | list.Items.MoveCurrentToFirst(); 69 | break; 70 | default: 71 | return; 72 | } 73 | 74 | e.Handled = true; 75 | if (list.SelectedItem != null) 76 | list.ScrollIntoView(list.SelectedItem); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/Models/ProcHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Management; 6 | using System.Reflection; 7 | using System.Security.Principal; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using Microsoft.Win32.SafeHandles; 11 | 12 | namespace JitMagic.Models { 13 | static class ProcHelper { 14 | public static bool IsUserAdministrator() { 15 | //bool value to hold our return value 16 | bool isAdmin; 17 | try { 18 | //get the currently logged in user 19 | var user = WindowsIdentity.GetCurrent(); 20 | var principal = new WindowsPrincipal(user); 21 | isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator); 22 | } catch (UnauthorizedAccessException) { 23 | isAdmin = false; 24 | } catch (Exception) { 25 | isAdmin = false; 26 | } 27 | return isAdmin; 28 | } 29 | public static void LaunchUs(bool asAdmin, String args = null) { 30 | Process.Start(new ProcessStartInfo { 31 | FileName = Assembly.GetExecutingAssembly().Location, 32 | UseShellExecute = true, 33 | Verb = asAdmin ? "runas" : "", 34 | Arguments = args, 35 | }); 36 | } 37 | public static void EnsureAdminOrRestartWith(String restartWithArg) { 38 | if (IsUserAdministrator()) 39 | return; 40 | LaunchUs(true, restartWithArg); 41 | Environment.Exit(0); 42 | } 43 | public static Architecture GetProcessArchitecture(Process p) { 44 | if (p.Id == 0 || p.HasExited) 45 | return Architecture.x64; 46 | if (Environment.Is64BitOperatingSystem) { 47 | if (Windows.Win32.PInvoke.IsWow64Process(new SafeProcessHandle(p.Handle, false), out var iswow64)) { 48 | return iswow64 ? Architecture.x86 : Architecture.x64; 49 | } 50 | throw new Exception("IsWow64Process failed"); 51 | } else { 52 | return Architecture.x86; 53 | } 54 | } 55 | public static string GetProcessPath(Process p) { 56 | if (p.Id == 0 || p.HasExited) 57 | return null; 58 | string MethodResult = ""; 59 | try { 60 | string Query = "SELECT ExecutablePath FROM Win32_Process WHERE ProcessId = " + p.Id; 61 | 62 | using (ManagementObjectSearcher mos = new ManagementObjectSearcher(Query)) { 63 | using (ManagementObjectCollection moc = mos.Get()) { 64 | string ExecutablePath = (from mo in moc.Cast() select mo["ExecutablePath"]).First().ToString(); 65 | MethodResult = ExecutablePath; 66 | } 67 | } 68 | } catch { 69 | } 70 | return MethodResult; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/MVVMLibLite/MVVMSObservableObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Reflection; 5 | using System.Linq.Expressions; 6 | using System.Runtime.CompilerServices; 7 | 8 | namespace JitMagic.MVVMLibLite { 9 | 10 | //modified from https://raw.githubusercontent.com/lbugnion/mvvmlight/b23c4d5bf6df654ad885be26ea053fb0efa04973/GalaSoft.MvvmLight/GalaSoft.MvvmLight%20(PCL)/ObservableObject.cs 11 | /* Original copyright */ 12 | // **************************************************************************** 13 | // 14 | // Copyright © GalaSoft Laurent Bugnion 2011-2016 15 | // 16 | // **************************************************************************** 17 | // Laurent Bugnion 18 | // laurent@galasoft.ch 19 | // 10.4.2011 20 | // GalaSoft.MvvmLight.Messaging 21 | // http://www.mvvmlight.net 22 | // 23 | // See license.txt in this project or http://www.galasoft.ch/license_MIT.txt 24 | // 25 | // **************************************************************************** 26 | 27 | public class MVVMSObservableObject : INotifyPropertyChanged { 28 | public event PropertyChangedEventHandler PropertyChanged; 29 | protected PropertyChangedEventHandler PropertyChangedHandler => PropertyChanged; 30 | 31 | public virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null) { 32 | var args = new PropertyChangedEventArgs(propertyName); 33 | PropertyChanged?.Invoke(this, args); 34 | 35 | } 36 | public virtual void RaisePropertyChanged(Expression> propertyExpression) { 37 | var handler = PropertyChanged; 38 | 39 | if (handler != null) { 40 | var propertyName = GetPropertyName(propertyExpression); 41 | if (!string.IsNullOrWhiteSpace(propertyName)) 42 | RaisePropertyChanged(propertyName); 43 | 44 | } 45 | } 46 | 47 | protected static string GetPropertyName(Expression> propertyExpression) { 48 | var body = propertyExpression.Body as MemberExpression; 49 | var property = body.Member as PropertyInfo; 50 | return property.Name; 51 | } 52 | internal static string IntGetPropertyName(Expression> propertyExpression) => GetPropertyName(propertyExpression); 53 | 54 | protected bool Set(Expression> propertyExpression, ref T field, T newValue) { 55 | if (EqualityComparer.Default.Equals(field, newValue)) 56 | return false; 57 | 58 | field = newValue; 59 | RaisePropertyChanged(propertyExpression); 60 | return true; 61 | } 62 | protected bool Set(string propertyName, ref T field, T newValue) { 63 | if (EqualityComparer.Default.Equals(field, newValue)) 64 | return false; 65 | 66 | field = newValue; 67 | RaisePropertyChanged(propertyName); 68 | return true; 69 | } 70 | 71 | protected bool Set(ref T field, T newValue, [CallerMemberName] string propertyName = null) => Set(propertyName, ref field, newValue); 72 | 73 | protected bool Set(ref T field, T newValue, Expression> propertyExpression) => Set(propertyExpression, ref field, newValue); 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/Models/JitDebugger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.IO; 4 | using System.Text.RegularExpressions; 5 | using System.Windows; 6 | #if IS_WPF 7 | using System.Windows.Interop; 8 | using System.Windows.Media; 9 | using System.Windows.Media.Imaging; 10 | #endif 11 | using Newtonsoft.Json; 12 | using Newtonsoft.Json.Converters; 13 | 14 | 15 | namespace JitMagic.Models { 16 | [JsonConverter(typeof(StringEnumConverter))] 17 | public enum Architecture { 18 | x64 = 1 << 0, 19 | x86 = 1 << 1, 20 | All = x86 | x64 21 | } 22 | public class JitDebugger { 23 | public JitDebugger(string name, Architecture architecture) { 24 | Name = name; 25 | Architecture = architecture; 26 | } 27 | public JitDebugger Clone() => (JitDebugger)this.MemberwiseClone(); 28 | public string Name { get; set; } 29 | public Architecture Architecture { get; } 30 | public string FileName { get; set; } 31 | public string Arguments { get; set; } 32 | public string IconOverridePath { get; set; } 33 | public int AdditionalDelaySecs { get; set; } = 0; // Additional time after it would normally exit where it exits. Good for misbehaving / non-signalling debuggers. 34 | 35 | [JsonIgnore] 36 | public bool Exists => File.Exists(FileName); 37 | public void LoadIcon(Icon fallback) { 38 | var iconFromAppRegex = new Regex(@"^(?.+[.](?:exe|dll))(?:[,](?[\-0-9]+))?$", RegexOptions.IgnoreCase); 39 | 40 | var GetIconMethod = (string path, int index) => Icon.ExtractAssociatedIcon(path);//backup method, downside is it can't take an index 41 | try { 42 | var mInfo = typeof(Icon).GetMethod(nameof(Icon.ExtractAssociatedIcon), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); 43 | if (mInfo != null) { 44 | var args = mInfo.GetParameters(); 45 | if (args.Length == 2 && args[0].ParameterType == typeof(string) && args[1].ParameterType == typeof(int)) 46 | GetIconMethod = (string path, int index) => (Icon)mInfo.Invoke(null, [path, index]); 47 | } 48 | } catch { } 49 | 50 | 51 | 52 | if (!File.Exists(FileName)) 53 | return; 54 | icon = null; 55 | try { 56 | var extractPath = FileName; 57 | var extractIndex = 0; 58 | if (!String.IsNullOrWhiteSpace(IconOverridePath)) { 59 | var extractMatch = iconFromAppRegex.Match(IconOverridePath); 60 | if (extractMatch.Success) { 61 | extractPath = extractMatch.Groups["path"].Value; 62 | if (extractMatch.Groups["index"].Success) 63 | extractIndex = int.Parse(extractMatch.Groups["index"].Value); 64 | } else 65 | icon = new Icon(IconOverridePath); 66 | 67 | } 68 | if (icon == null) 69 | icon = GetIconMethod(extractPath, extractIndex); 70 | } catch { } 71 | if (icon == null) 72 | icon = fallback; 73 | #if IS_WPF 74 | DisplayIcon = ToImageSource(icon); 75 | #endif 76 | } 77 | 78 | public Icon icon; 79 | #if IS_WPF 80 | [JsonIgnore] 81 | public ImageSource DisplayIcon { get; set; } 82 | private static ImageSource ToImageSource(Icon icon) { 83 | ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon( 84 | icon.Handle, 85 | Int32Rect.Empty, 86 | BitmapSizeOptions.FromEmptyOptions()); 87 | 88 | return imageSource; 89 | } 90 | #endif 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 54 | 55 | 56 | true 57 | PerMonitorV2 58 | true 59 | 60 | 61 | 62 | 63 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /ManagedJitTest/ManagedJitTest/ManagedJitTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E56F4752-28C7-427D-8AB4-F2E5675AA695} 8 | Exe 9 | ManagedJitTest 10 | ManagedJitTest 11 | v4.6.1 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | pdbonly 19 | true 20 | bin\Any CPU\ 21 | TRACE 22 | prompt 23 | 4 24 | false 25 | 26 | 27 | bin\x86\ 28 | TRACE 29 | true 30 | pdbonly 31 | x86 32 | prompt 33 | MinimumRecommendedRules.ruleset 34 | false 35 | 36 | 37 | bin\x64\ 38 | TRACE 39 | true 40 | pdbonly 41 | x64 42 | prompt 43 | MinimumRecommendedRules.ruleset 44 | false 45 | 46 | 47 | bin\Prefer 32-bit\ 48 | TRACE 49 | true 50 | pdbonly 51 | AnyCPU 52 | prompt 53 | MinimumRecommendedRules.ruleset 54 | true 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/Models/CLIManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | #if ! IS_WPF 9 | using System.Windows.Forms; 10 | #endif 11 | 12 | namespace JitMagic.Models { 13 | public enum APP_ACTION { None, RegCheck, Register, Unregister, AddDebugger, RemoveDebugger, AEDebug, Screenshot } 14 | public class CLIManager { 15 | 16 | 17 | 18 | public APP_ACTION mode; 19 | private string[] args; 20 | private int CurArg; 21 | private string GetNextArg() { 22 | if (args.Length > CurArg) 23 | return args[CurArg++]; 24 | return null; 25 | } 26 | public int ArgsLeft => args.Length - CurArg; 27 | public class RequestedTargetProc { 28 | public int Pid; 29 | public int EventHandleFD; 30 | public string JitDebugStructPtrAddy; 31 | public string ProcPath; 32 | public Architecture Architecture; 33 | } 34 | public RequestedTargetProc target; 35 | public CLIManager(ConfigManager config, AEDebugManager aeDebug, string[] args) { 36 | this.args = args; 37 | var action = GetNextArg(); 38 | if (action != null && action.StartsWith("--") && Enum.TryParse(action.Replace("-", ""), true, out var parsed)) 39 | mode = parsed; 40 | 41 | if (mode == APP_ACTION.None) { 42 | if (action == "-p") { 43 | try { 44 | target = new(); 45 | target.Pid = int.Parse(GetNextArg()); 46 | if (GetNextArg() == "-e"){ 47 | target.EventHandleFD = int.Parse(GetNextArg()); 48 | aeDebug.SetEventFD(new IntPtr(target.EventHandleFD)); 49 | } 50 | if (GetNextArg() == "-j") 51 | target.JitDebugStructPtrAddy = GetNextArg(); 52 | var process = Process.GetProcessById(target.Pid); 53 | target.ProcPath = ProcHelper.GetProcessPath(process); 54 | if (config.Config.BlacklistedPaths.Any(black => black.Equals(target.ProcPath, StringComparison.CurrentCultureIgnoreCase))) 55 | Environment.Exit(0); 56 | 57 | target.Architecture = ProcHelper.GetProcessArchitecture(process); 58 | mode = APP_ACTION.AEDebug; 59 | } catch (Exception ex) { 60 | MessageBox.Show("Error retrieving information! " + ex); 61 | } 62 | } 63 | } 64 | 65 | if (mode == APP_ACTION.None && config.Config.PerformRegisteredCheckOnStart && !aeDebug.UpdateRegistration(APP_ACTION.RegCheck)) { 66 | if (MessageBox.Show("We are not currently the default JIT debugger, should we set ourselves as the automatic debugger?", "Update JIT debugger to us?", 67 | #if IS_WPF 68 | MessageBoxButton.YesNo 69 | #else 70 | MessageBoxButtons.YesNo 71 | #endif 72 | ) == 73 | #if IS_WPF 74 | MessageBoxResult.Yes 75 | #else 76 | DialogResult.Yes 77 | #endif 78 | ) 79 | mode = APP_ACTION.Register; 80 | 81 | } 82 | 83 | switch (this.mode) { 84 | case APP_ACTION.AddDebugger: 85 | case APP_ACTION.RemoveDebugger: 86 | var name = GetNextArg(); 87 | if (String.IsNullOrWhiteSpace(name)) 88 | throw new ArgumentException("To add/remove a debugger the name must be passed for the first arg"); 89 | if (mode == APP_ACTION.RemoveDebugger) 90 | config.RemoveDebugger(name); 91 | else { 92 | if (ArgsLeft < 3) 93 | throw new Exception($"To add a new debugger the form should be JitMagic.exe --add-debugger \"[DebuggerName]\" \"[DebuggerPath]\" \"[DebuggerArgs]\" [x86|x64|All] [AdditionalDelaySecs(optional)]"); 94 | 95 | var path = GetNextArg(); 96 | var callArgs = GetNextArg(); 97 | var architecture = GetNextArg(); 98 | if (!Enum.TryParse(architecture, true, out var arch)) 99 | throw new Exception($"Archicture should be x64, x86, or All you passed: {architecture}"); 100 | var deb = new JitDebugger(name, arch) { FileName = path, Arguments = callArgs }; 101 | if (ArgsLeft > 0 && int.TryParse(GetNextArg(), out var addlDelaySecs)) 102 | deb.AdditionalDelaySecs = addlDelaySecs; 103 | config.AddDebugger(deb); 104 | 105 | } 106 | break; 107 | case APP_ACTION.Register: 108 | case APP_ACTION.Unregister: 109 | ProcHelper.EnsureAdminOrRestartWith(this.mode == APP_ACTION.Register ? "--register" : "--unregister"); 110 | aeDebug.UpdateRegistration(this.mode); 111 | break; 112 | case APP_ACTION.AEDebug: 113 | if (config.Config.IgnoringUntil > DateTime.Now) 114 | Environment.Exit(0); 115 | break; 116 | } 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /JitMagic/JitMagic/Views/JITSelectorWindow.xaml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |