├── Sharprompt-2.3.0 ├── .gitattributes ├── .github │ ├── FUNDING.yml │ └── workflows │ │ ├── build.yml │ │ └── publish.yml ├── Sharprompt │ ├── ConfirmOptions.cs │ ├── PasswordOptions.cs │ ├── InputOptions.cs │ ├── SelectOptions.cs │ ├── ListOptions.cs │ ├── MultiSelectOptions.cs │ ├── Internal │ │ ├── NativeMethods.cs │ │ ├── Optional.cs │ │ ├── ValidationAttributeAdapter.cs │ │ ├── EnumValue.cs │ │ ├── Paginator.cs │ │ └── OffscreenBuffer.cs │ ├── Drivers │ │ ├── IConsoleDriver.cs │ │ └── DefaultConsoleDriver.cs │ ├── Symbol.cs │ ├── Sharprompt.csproj │ ├── Prompt.Customize.cs │ ├── Forms │ │ ├── FormRenderer.cs │ │ ├── FormBase.cs │ │ ├── PasswordForm.cs │ │ ├── SelectForm.cs │ │ ├── ConfirmForm.cs │ │ ├── InputForm.cs │ │ ├── ListForm.cs │ │ └── MultiSelectForm.cs │ ├── Validators.cs │ ├── Prompt.AutoForms.cs │ └── Prompt.Basic.cs ├── Sharprompt.Example │ ├── ExampleType.cs │ ├── Sharprompt.Example.csproj │ ├── Models │ │ ├── MyEnum.cs │ │ └── MyFormModel.cs │ └── Program.cs ├── LICENSE ├── Sharprompt.sln ├── README.md ├── .editorconfig └── .gitignore ├── Dis2Msil ├── Dis2Msil.Test │ ├── App.config │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Dis2Msil.Test.csproj ├── Dis2Msil │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Dis2Msil.csproj │ ├── Globals.cs │ ├── ILInstruction.cs │ └── MethodBodyReader.cs └── Dis2Msil.sln ├── JITK ├── Core │ ├── SJITHook │ │ ├── VTableAddrProvider.cs │ │ ├── ClrjitAddrProvider.cs │ │ ├── MscorjitAddrProvider.cs │ │ ├── JITHook.cs │ │ ├── JITHook64.cs │ │ └── Data.cs │ ├── Command │ │ ├── Clear.cs │ │ ├── Quit.cs │ │ ├── Command.cs │ │ ├── FileClear.cs │ │ ├── DisasH.cs │ │ ├── About.cs │ │ ├── FileArgument.cs │ │ ├── ListBreakpoint.cs │ │ ├── Help.cs │ │ ├── FileAssign.cs │ │ ├── StepFuncG.cs │ │ ├── InfoF.cs │ │ ├── DefBreakPoint.cs │ │ ├── InfoA.cs │ │ ├── Disas.cs │ │ ├── Continue.cs │ │ └── CommandEngine.cs │ ├── Style.cs │ └── Context.cs ├── packages.config ├── App.config ├── Properties │ └── AssemblyInfo.cs ├── Program.cs └── JITK.csproj ├── README.md ├── JITK.sln ├── .gitattributes └── .gitignore /Sharprompt-2.3.0/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: shibayan 4 | -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil.Test/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/ConfirmOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Sharprompt 2 | { 3 | public class ConfirmOptions 4 | { 5 | public string Message { get; set; } 6 | 7 | public bool? DefaultValue { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /JITK/Core/SJITHook/VTableAddrProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JITK.Core.SJITHook 4 | { 5 | public abstract class VTableAddrProvider 6 | { 7 | internal delegate IntPtr GetJit(); 8 | public abstract IntPtr VTableAddr { get; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /JITK/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt.Example/ExampleType.cs: -------------------------------------------------------------------------------- 1 | namespace Sharprompt.Example 2 | { 3 | public enum ExampleType 4 | { 5 | Input, 6 | Confirm, 7 | Password, 8 | Select, 9 | MultiSelect, 10 | SelectWithEnum, 11 | MultiSelectWithEnum, 12 | List, 13 | AutoForms 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt.Example/Sharprompt.Example.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/PasswordOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace Sharprompt 6 | { 7 | public class PasswordOptions 8 | { 9 | public string Message { get; set; } 10 | 11 | public IList> Validators { get; } = new List>(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /JITK/Core/Command/Clear.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JITK.Core.Command 4 | { 5 | class Clear : Command 6 | { 7 | override public string HelpText { get { return "Clear Console"; } } 8 | override public string Name { get { return "clear"; } } 9 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 10 | override public void Action() 11 | { 12 | Console.Clear(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/InputOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace Sharprompt 6 | { 7 | public class InputOptions 8 | { 9 | public string Message { get; set; } 10 | 11 | public object DefaultValue { get; set; } 12 | 13 | public IList> Validators { get; } = new List>(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /JITK/Core/Command/Quit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JITK.Core.Command 4 | { 5 | class Quit : Command 6 | { 7 | override public string HelpText { get { return "Suspend JIT Killer"; } } 8 | override public string Name { get { return "quit"; } } 9 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 10 | override public void Action() 11 | { 12 | Environment.Exit(0); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt.Example/Models/MyEnum.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace Sharprompt.Example.Models 4 | { 5 | public enum MyEnum 6 | { 7 | [Display(Name = "Foo value", Order = 3)] 8 | Foo, 9 | 10 | [Display(Name = "Bar value", Order = 2)] 11 | Bar, 12 | 13 | [Display(Name = "Baz value", Order = 1)] 14 | Baz, 15 | 16 | [Display(Name = "Test value")] 17 | Test 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/SelectOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Sharprompt 5 | { 6 | public class SelectOptions 7 | { 8 | public string Message { get; set; } 9 | 10 | public IEnumerable Items { get; set; } 11 | 12 | public object DefaultValue { get; set; } 13 | 14 | public int? PageSize { get; set; } 15 | 16 | public Func TextSelector { get; set; } = x => x.ToString(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /JITK/Core/Command/Command.cs: -------------------------------------------------------------------------------- 1 | namespace JITK.Core.Command 2 | { 3 | public enum ArgumentSize 4 | { 5 | None, //No argument 6 | Single, 7 | Poly, //More argument 8 | Opt //Optional argument 9 | } 10 | public abstract class Command 11 | { 12 | abstract public string HelpText { get; } 13 | abstract public string Name { get; } 14 | abstract public ArgumentSize ArgSize { get; } 15 | abstract public void Action(); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /JITK/Core/Command/FileClear.cs: -------------------------------------------------------------------------------- 1 | namespace JITK.Core.Command 2 | { 3 | class FileClear : Command 4 | { 5 | override public string HelpText { get { return "Path Clear"; } } 6 | override public string Name { get { return "fc"; } } 7 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 8 | override public void Action() 9 | { 10 | Context.filePath = ""; 11 | Style.WriteFormatted("[^] filePath Cleaned.\n"); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /JITK/Core/Command/DisasH.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JITK.Core.Command 4 | { 5 | class DisasH : Command 6 | { 7 | override public string HelpText { get { return "Print method body as hex"; } } 8 | override public string Name { get { return "disash"; } } 9 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 10 | override public void Action() 11 | { 12 | Console.WriteLine(Context.currentMethodBody); 13 | 14 | } 15 | 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /JITK/Core/Command/About.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JITK.Core.Command 4 | { 5 | class About : Command 6 | { 7 | override public string HelpText { get { return "About JITK"; } } 8 | override public string Name { get { return "about"; } } 9 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 10 | override public void Action() 11 | { 12 | Style.WriteFormatted("JITK - JIT Killer is hooker for clrjit. Created by rhotav \n github.com/rhotav \n", ConsoleColor.Blue); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /JITK/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/ListOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace Sharprompt 6 | { 7 | public class ListOptions 8 | { 9 | public string Message { get; set; } 10 | 11 | public IEnumerable DefaultValues { get; set; } 12 | 13 | public int Minimum { get; set; } = 1; 14 | 15 | public int Maximum { get; set; } = int.MaxValue; 16 | 17 | public IList> Validators { get; } = new List>(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/MultiSelectOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Sharprompt 5 | { 6 | public class MultiSelectOptions 7 | { 8 | public string Message { get; set; } 9 | 10 | public IEnumerable Items { get; set; } 11 | 12 | public IEnumerable DefaultValues { get; set; } 13 | 14 | public int? PageSize { get; set; } 15 | 16 | public int Minimum { get; set; } = 1; 17 | 18 | public int Maximum { get; set; } = int.MaxValue; 19 | 20 | public Func TextSelector { get; set; } = x => x.ToString(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /JITK/Core/Command/FileArgument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JITK.Core.Command 4 | { 5 | class FileArgument : Command 6 | { 7 | override public string HelpText { get { return "Assign File Argument/s"; } } 8 | override public string Name { get { return "fg"; } } 9 | override public ArgumentSize ArgSize { get { return ArgumentSize.Poly; } } 10 | override public void Action() 11 | { 12 | foreach (string arguments in CommandEngine.arg) 13 | { 14 | Context.arguments += $"{arguments} "; 15 | } 16 | Style.WriteFormatted($"[^] Arguments assigned.\n"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Internal/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Sharprompt.Internal 5 | { 6 | internal static class NativeMethods 7 | { 8 | public const int STD_OUTPUT_HANDLE = -11; 9 | public const int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004; 10 | 11 | [DllImport("kernel32.dll")] 12 | public static extern IntPtr GetStdHandle(int nStdHandle); 13 | 14 | [DllImport("kernel32.dll")] 15 | public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int dwMode); 16 | 17 | [DllImport("kernel32.dll")] 18 | public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int dwMode); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /JITK/Core/Command/ListBreakpoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using JITK.Core; 3 | using System.Collections.Generic; 4 | 5 | namespace JITK.Core.Command 6 | { 7 | class ListBreakpoint : Command 8 | { 9 | override public string HelpText { get { return "List All Breakpoint"; } } 10 | override public string Name { get { return "bl"; } } 11 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 12 | override public void Action() 13 | { 14 | foreach (KeyValuePair bps in Context.breakPoints) 15 | { 16 | Style.WriteFormatted($"ID: {bps.Key} -- Token: {bps.Value}\n", ConsoleColor.DarkGray); 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /JITK/Core/Command/Help.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace JITK.Core.Command 5 | { 6 | class Help : Command 7 | { 8 | override public string HelpText { get { return "Help"; } } 9 | override public string Name { get { return "help"; } } 10 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 11 | override public void Action() 12 | { 13 | string result = ""; 14 | foreach (KeyValuePair com in CommandEngine.commands) 15 | { 16 | result += com.Key + " -- " + com.Value.HelpText + " \n"; 17 | } 18 | Style.WriteFormatted(result); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /JITK/Core/SJITHook/ClrjitAddrProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace JITK.Core.SJITHook 5 | { 6 | public sealed class ClrjitAddrProvider : VTableAddrProvider 7 | { 8 | [DllImport("Clrjit.dll", CallingConvention = CallingConvention.StdCall, PreserveSig = true)] 9 | private static extern IntPtr getJit(); 10 | 11 | public override IntPtr VTableAddr 12 | { 13 | get 14 | { 15 | IntPtr pVTable = getJit(); 16 | if (pVTable == IntPtr.Zero) 17 | throw new Exception("Could not retrieve address for getJit"); 18 | 19 | return pVTable; 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /JITK/Core/SJITHook/MscorjitAddrProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace JITK.Core.SJITHook 5 | { 6 | public sealed class MscorjitAddrProvider : VTableAddrProvider 7 | { 8 | [DllImport("mscorjit.dll", CallingConvention = CallingConvention.StdCall, PreserveSig = true)] 9 | private static extern IntPtr getJit(); 10 | 11 | public override IntPtr VTableAddr 12 | { 13 | get 14 | { 15 | IntPtr pVTable = getJit(); 16 | if (pVTable == IntPtr.Zero) 17 | throw new Exception("Could not retrieve address for getJit"); 18 | 19 | return pVTable; 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | env: 10 | DOTNET_VERSION: 5.0.x 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | 18 | - name: Use .NET Core ${{ env.DOTNET_VERSION }} 19 | uses: actions/setup-dotnet@v1 20 | with: 21 | dotnet-version: ${{ env.DOTNET_VERSION }} 22 | 23 | - name: Install .NET Core format tool 24 | run: dotnet tool update -g dotnet-format 25 | 26 | - name: Build project 27 | run: dotnet build -c Release 28 | 29 | - name: Lint C# code 30 | run: dotnet format --check --verbosity detailed 31 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Drivers/IConsoleDriver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Sharprompt.Drivers 4 | { 5 | internal interface IConsoleDriver : IDisposable 6 | { 7 | void Beep(); 8 | void Reset(); 9 | void ClearLine(int top); 10 | ConsoleKeyInfo ReadKey(); 11 | void Write(string value, ConsoleColor color); 12 | void WriteLine(); 13 | (int left, int top) GetCursorPosition(); 14 | void SetCursorPosition(int left, int top); 15 | bool KeyAvailable { get; } 16 | bool CursorVisible { get; set; } 17 | int CursorLeft { get; } 18 | int CursorTop { get; } 19 | int BufferWidth { get; } 20 | int BufferHeight { get; } 21 | Action RequestCancellation { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Internal/Optional.cs: -------------------------------------------------------------------------------- 1 | namespace Sharprompt.Internal 2 | { 3 | internal readonly struct Optional 4 | { 5 | public Optional(T value) 6 | { 7 | HasValue = true; 8 | Value = value; 9 | } 10 | 11 | public bool HasValue { get; } 12 | 13 | public T Value { get; } 14 | 15 | public static implicit operator T(Optional optional) => optional.Value; 16 | 17 | public static readonly Optional Empty = new Optional(); 18 | 19 | public static Optional Create(T value) 20 | { 21 | return value == null ? Empty : new Optional(value); 22 | } 23 | 24 | public static Optional Create(object value) 25 | { 26 | return value == null ? Empty : new Optional((T)value); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /JITK/Core/Command/FileAssign.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JITK.Core.Command 4 | { 5 | class FileAssign : Command 6 | { 7 | override public string HelpText { get { return "Assign File"; } } 8 | override public string Name { get { return "f"; } } 9 | override public ArgumentSize ArgSize { get { return ArgumentSize.Single; } } 10 | override public void Action() 11 | { 12 | if (Context.IsNet(CommandEngine.arg[0])) 13 | { 14 | Context.filePath = CommandEngine.arg[0]; 15 | Style.WriteFormatted($"[^] {Context.filePath} assigned to the file path.\n"); 16 | } 17 | else 18 | { 19 | Style.WriteFormatted("[!] Upss! This file is not .NET! Please specify another assembly!", ConsoleColor.Red); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | tags: [ v* ] 6 | 7 | env: 8 | DOTNET_VERSION: 5.0.x 9 | 10 | jobs: 11 | publish: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Use .NET Core ${{ env.DOTNET_VERSION }} 17 | uses: actions/setup-dotnet@v1 18 | with: 19 | dotnet-version: ${{ env.DOTNET_VERSION }} 20 | 21 | - name: Setup Version 22 | id: setup_version 23 | run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/} 24 | 25 | - name: Pack NuGet Package 26 | run: dotnet pack Sharprompt/Sharprompt.csproj -c Release -o ./dist -p:Version=${{ steps.setup_version.outputs.VERSION }} 27 | 28 | - name: Publish 29 | run: dotnet nuget push dist/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json 30 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Symbol.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Sharprompt 5 | { 6 | public class Symbol 7 | { 8 | public Symbol(string value, string fallbackValue) 9 | { 10 | _value = value; 11 | _fallbackValue = fallbackValue; 12 | } 13 | 14 | private readonly string _value; 15 | private readonly string _fallbackValue; 16 | 17 | public override string ToString() 18 | { 19 | return IsUnicodeSupported ? _value : _fallbackValue; 20 | } 21 | 22 | public static implicit operator string(Symbol symbol) => symbol.ToString(); 23 | 24 | private static bool IsUnicodeSupported => !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || Console.OutputEncoding.CodePage == 1200 || Console.OutputEncoding.CodePage == 65001; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Internal/ValidationAttributeAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace Sharprompt.Internal 5 | { 6 | internal class ValidationAttributeAdapter 7 | { 8 | public ValidationAttributeAdapter(ValidationAttribute validationAttribute) 9 | { 10 | _validationAttribute = validationAttribute; 11 | } 12 | 13 | private readonly ValidationAttribute _validationAttribute; 14 | 15 | public Func GetValidator(string propertyName, object model) 16 | { 17 | var validationContext = new ValidationContext(model) 18 | { 19 | DisplayName = propertyName, 20 | MemberName = propertyName 21 | }; 22 | 23 | return input => _validationAttribute.GetValidationResult(input, validationContext); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /JITK/Core/Command/StepFuncG.cs: -------------------------------------------------------------------------------- 1 | using JITK.Core.SJITHook; 2 | using System; 3 | using System.Linq; 4 | 5 | namespace JITK.Core.Command 6 | { 7 | class StepFuncG : Command 8 | { 9 | override public string HelpText { get { return "Step next function."; } } 10 | override public string Name { get { return "g"; } } 11 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 12 | 13 | override public unsafe void Action() 14 | { 15 | if (Context.hookState == false) 16 | { 17 | Style.WriteFormatted("[!] Hook mode is not activated!\n", ConsoleColor.Red); 18 | return; 19 | } 20 | 21 | if (Context.hookState == true) 22 | { 23 | Context.continueOtherFunc = false; 24 | Context.stepOtherFunc = true; 25 | } 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt.Example/Models/MyFormModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace Sharprompt.Example.Models 5 | { 6 | public class MyFormModel 7 | { 8 | [Display(Prompt = "What's your name?", Order = 1)] 9 | [Required] 10 | public string Name { get; set; } 11 | 12 | [Display(Prompt = "Type new password", Order = 2)] 13 | [DataType(DataType.Password)] 14 | [Required] 15 | [MinLength(8)] 16 | public string Password { get; set; } 17 | 18 | [Display(Prompt = "Select enum value", Order = 3)] 19 | public MyEnum? MyEnum { get; set; } 20 | 21 | [Display(Prompt = "Select enum values", Order = 4)] 22 | public IEnumerable MyEnums { get; set; } 23 | 24 | [Display(Prompt = "Are you ready?", Order = 5)] 25 | public bool Ready { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /JITK/Core/Command/InfoF.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace JITK.Core.Command 5 | { 6 | class InfoF : Command 7 | { 8 | override public string HelpText { get { return "Get functions from loaded module."; } } 9 | override public string Name { get { return "infof"; } } 10 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 11 | override public void Action() 12 | { 13 | string result = ""; 14 | foreach (TypeDef type in Context.module.Types) 15 | { 16 | if (!type.HasMethods) continue; 17 | foreach (MethodDef method in type.Methods) 18 | { 19 | result += $"Name: {type.Name}.{method.Name} (0x{method.MDToken})\n "; 20 | } 21 | } 22 | 23 | Style.WriteFormatted(result + "\n", ConsoleColor.DarkGray); 24 | } 25 | 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Sharprompt.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 8.0 6 | 7 | 8 | 9 | shibayan 10 | shibayan 11 | Interactive command line interface toolkit for C# 12 | README.md 13 | https://github.com/shibayan/Sharprompt/releases 14 | MIT 15 | cli;command-line;interactive;prompt 16 | https://github.com/shibayan/Sharprompt 17 | git 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /JITK/Core/Command/DefBreakPoint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JITK.Core.Command 4 | { 5 | class DefBreakPoint : Command 6 | { 7 | override public string HelpText { get { return "Define breakpoint"; } } 8 | override public string Name { get { return "b"; } } 9 | override public ArgumentSize ArgSize { get { return ArgumentSize.Single; } } 10 | override public void Action() 11 | { 12 | if (CommandEngine.arg[0].Length == 8) 13 | { 14 | int id = Context.breakPoints.Count + 1; 15 | Context.breakPoints.Add(id, CommandEngine.arg[0]); 16 | Style.WriteFormatted($"[^] Breakpoint defined. ID: {id}\n", ConsoleColor.White); 17 | } 18 | else 19 | { 20 | Style.WriteFormatted("[!] Upss! Wrong format! Ex: \"b 06000002\"\n", ConsoleColor.Red); 21 | return; 22 | } 23 | 24 | } 25 | 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil.Test/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace Dis2Msil.Test 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | string testIl = "02-28-1C-00-00-0A-00-00-02-03-7D-11-00-00-04-2A"; 11 | byte[] testIlByte = { 0x02, 0x28, 0x1C, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x02, 0x03, 0x7D, 0x11, 0x00, 0x00, 0x04, 0x2A }; 12 | //string fileName = args[0]; 13 | string fileName = @"C:\Users\utku\Desktop\WorkSpace\JITK\asd.exe"; 14 | 15 | MethodBodyReader mr = new MethodBodyReader(Assembly.LoadFrom(fileName).EntryPoint.Module, testIl); 16 | Console.Write(mr.GetBodyCode()); 17 | 18 | Console.WriteLine("========================================"); 19 | 20 | MethodBodyReader mrByte = new MethodBodyReader(Assembly.LoadFrom(fileName).EntryPoint.Module, testIlByte); 21 | Console.Write(mrByte.GetBodyCode()); 22 | 23 | Console.ReadKey(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /JITK/Core/Command/InfoA.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JITK.Core.Command 4 | { 5 | class InfoA : Command 6 | { 7 | override public string HelpText { get { return "Get assembly info of target module."; } } 8 | override public string Name { get { return "infoa"; } } 9 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 10 | override public void Action() 11 | { 12 | string result = ""; 13 | result += " Assembly-Info: " + Context.module.Assembly.FullName; 14 | result += "\n EntryPoint: " + Context.module.EntryPoint.MDToken.ToString(); 15 | result += "\n Machine: " + Context.module.Machine.ToString(); 16 | result += "\n Characteristics: " + Context.module.Characteristics.ToString(); 17 | result += "\n HasResources: " + Context.module.HasResources.ToString(); 18 | result += "\n HasExportedTypes: " + Context.module.HasExportedTypes.ToString(); 19 | 20 | Style.WriteFormatted(result + "\n", ConsoleColor.DarkGray); 21 | } 22 | 23 | 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 shibayan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Prompt.Customize.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Sharprompt 4 | { 5 | public static partial class Prompt 6 | { 7 | public static class ColorSchema 8 | { 9 | public static ConsoleColor DoneSymbolColor { get; set; } = ConsoleColor.Green; 10 | public static ConsoleColor PromptSymbolColor { get; set; } = ConsoleColor.Green; 11 | public static ConsoleColor Answer { get; set; } = ConsoleColor.Cyan; 12 | public static ConsoleColor Select { get; set; } = ConsoleColor.Green; 13 | public static ConsoleColor DisabledOption { get; set; } = ConsoleColor.DarkCyan; 14 | } 15 | 16 | public static class Symbols 17 | { 18 | public static Symbol Prompt { get; set; } = new Symbol("?", "?"); 19 | public static Symbol Done { get; set; } = new Symbol("✔", "V"); 20 | public static Symbol Error { get; set; } = new Symbol("»", ">>"); 21 | public static Symbol Selector { get; set; } = new Symbol("›", ">"); 22 | public static Symbol Selected { get; set; } = new Symbol("◉", "(*)"); 23 | public static Symbol NotSelect { get; set; } = new Symbol("◯", "( )"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Dis2Msil")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Dis2Msil")] 12 | [assembly: AssemblyCopyright("Copyright © 2021")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("9873f12d-9c5b-4756-b31c-b514664638ce")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /JITK/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("JITK")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("JITK")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 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("ec28f37b-89c4-42aa-97cd-afdce7a7a818")] 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 | -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil.Test/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("Dis2Msil.Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Dis2Msil.Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 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("f4ef0212-1a06-4a72-8ad6-9e67f05666f9")] 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 | -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31515.178 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dis2Msil", "Dis2Msil\Dis2Msil.csproj", "{9873F12D-9C5B-4756-B31C-B514664638CE}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dis2Msil.Test", "Dis2Msil.Test\Dis2Msil.Test.csproj", "{F4EF0212-1A06-4A72-8AD6-9E67F05666F9}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9873F12D-9C5B-4756-B31C-B514664638CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {9873F12D-9C5B-4756-B31C-B514664638CE}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {9873F12D-9C5B-4756-B31C-B514664638CE}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {9873F12D-9C5B-4756-B31C-B514664638CE}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {F4EF0212-1A06-4A72-8AD6-9E67F05666F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {F4EF0212-1A06-4A72-8AD6-9E67F05666F9}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {F4EF0212-1A06-4A72-8AD6-9E67F05666F9}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {F4EF0212-1A06-4A72-8AD6-9E67F05666F9}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {BD033E96-83F5-46DF-B2D0-4B804D4FA73E} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29123.88 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharprompt", "Sharprompt\Sharprompt.csproj", "{32B1CF1F-4683-4B04-B435-424EC5EE0E40}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharprompt.Example", "Sharprompt.Example\Sharprompt.Example.csproj", "{8E8C45F4-6B12-42F9-B2EA-E0E3EBC4BCB2}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {32B1CF1F-4683-4B04-B435-424EC5EE0E40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {32B1CF1F-4683-4B04-B435-424EC5EE0E40}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {32B1CF1F-4683-4B04-B435-424EC5EE0E40}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {32B1CF1F-4683-4B04-B435-424EC5EE0E40}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {8E8C45F4-6B12-42F9-B2EA-E0E3EBC4BCB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {8E8C45F4-6B12-42F9-B2EA-E0E3EBC4BCB2}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {8E8C45F4-6B12-42F9-B2EA-E0E3EBC4BCB2}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {8E8C45F4-6B12-42F9-B2EA-E0E3EBC4BCB2}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {76E7FD3B-AB85-4725-8FCB-6113272E0BCD} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Internal/EnumValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Reflection; 6 | 7 | namespace Sharprompt.Internal 8 | { 9 | internal class EnumValue : IEquatable> where T : Enum 10 | { 11 | private EnumValue(T value) 12 | { 13 | var name = value.ToString(); 14 | var displayAttribute = typeof(T).GetField(name)?.GetCustomAttribute(); 15 | 16 | DisplayName = displayAttribute?.Name ?? name; 17 | Order = displayAttribute?.GetOrder() ?? int.MaxValue; 18 | Value = value; 19 | } 20 | 21 | public string DisplayName { get; } 22 | public int Order { get; } 23 | public T Value { get; } 24 | 25 | public override bool Equals(object obj) => Equals(obj as EnumValue); 26 | 27 | public bool Equals(EnumValue other) 28 | { 29 | if (other == null) 30 | { 31 | return false; 32 | } 33 | 34 | return EqualityComparer.Default.Equals(Value, other.Value); 35 | } 36 | 37 | public override int GetHashCode() => Value.GetHashCode(); 38 | 39 | public static implicit operator EnumValue(T value) 40 | { 41 | return new EnumValue(value); 42 | } 43 | 44 | public static IEnumerable> GetValues() 45 | { 46 | var values = (T[])Enum.GetValues(typeof(T)); 47 | 48 | return values.Select(x => new EnumValue(x)) 49 | .OrderBy(x => x.Order) 50 | .ToArray(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /JITK/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.IO; 4 | using JITK.Core; 5 | using Sharprompt; 6 | using System.Text; 7 | using JITK.Core.Command; 8 | 9 | namespace JITK 10 | { 11 | class Program 12 | { 13 | const string banner = @" 14 | _ _____ _______ _ __ 15 | | |_ _|__ __| |/ / 16 | | | | | | | | ' / 17 | _ | | | | | | | < 18 | | |__| |_| |_ | | | . \ 19 | \____/|_____| |_| |_|\_\ 20 | 21 | by rhotav"; 22 | 23 | 24 | static void Main(string[] args) 25 | { 26 | Style.WriteFormatted(banner + "\n\n", ConsoleColor.DarkRed); 27 | Style.LoadKeywords(); 28 | CommandEngine.LoadCommands(); 29 | 30 | string path = ""; 31 | try 32 | { 33 | if (Context.IsNet(args[0])) 34 | { 35 | Context.filePath = args[0]; 36 | } 37 | else 38 | { 39 | Style.WriteFormatted("[!] Upss! This file is not .NET! Please specify another assembly!", ConsoleColor.Red); 40 | while (!Context.IsNet(path)) 41 | { 42 | path = Style.WriteError("File Path"); 43 | } 44 | 45 | Context.filePath = path; 46 | } 47 | } 48 | catch 49 | { 50 | while (!Context.IsNet(path)) 51 | { 52 | path = Style.WriteError("File Path"); 53 | } 54 | 55 | Context.filePath = path; 56 | } 57 | 58 | CommandEngine.MainRoutine(); 59 | 60 | 61 | 62 | Console.ReadKey(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Forms/FormRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Sharprompt.Drivers; 4 | using Sharprompt.Internal; 5 | 6 | namespace Sharprompt.Forms 7 | { 8 | internal class FormRenderer : IDisposable 9 | { 10 | public FormRenderer(IConsoleDriver consoleDriver, bool cursorVisible = true) 11 | { 12 | _consoleDriver = consoleDriver; 13 | _cursorVisible = cursorVisible; 14 | 15 | _offscreenBuffer = new OffscreenBuffer(_consoleDriver); 16 | } 17 | 18 | private readonly bool _cursorVisible; 19 | private readonly IConsoleDriver _consoleDriver; 20 | private readonly OffscreenBuffer _offscreenBuffer; 21 | 22 | public string ErrorMessage { get; set; } 23 | 24 | public void Dispose() 25 | { 26 | _consoleDriver.Dispose(); 27 | } 28 | 29 | public void Render(Action template) 30 | { 31 | _consoleDriver.CursorVisible = false; 32 | 33 | _offscreenBuffer.ClearConsole(); 34 | 35 | template(_offscreenBuffer); 36 | 37 | if (ErrorMessage != null) 38 | { 39 | _offscreenBuffer.WriteErrorMessage(ErrorMessage); 40 | 41 | ErrorMessage = null; 42 | } 43 | 44 | _offscreenBuffer.RenderToConsole(); 45 | 46 | _consoleDriver.CursorVisible = _cursorVisible; 47 | } 48 | 49 | public void Render(Action template, TModel result) 50 | { 51 | _consoleDriver.CursorVisible = false; 52 | 53 | _offscreenBuffer.ClearConsole(); 54 | 55 | template(_offscreenBuffer, result); 56 | 57 | _offscreenBuffer.RenderToConsole(); 58 | 59 | _consoleDriver.WriteLine(); 60 | 61 | _consoleDriver.CursorVisible = _cursorVisible; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /JITK/Core/Command/Disas.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dis2Msil; 3 | using dnlib.DotNet; 4 | 5 | namespace JITK.Core.Command 6 | { 7 | class Disas : Command 8 | { 9 | override public string HelpText { get { return "Disassemble Method"; } } 10 | override public string Name { get { return "disas"; } } 11 | override public ArgumentSize ArgSize { get { return ArgumentSize.Opt; } } 12 | override public unsafe void Action() 13 | { 14 | if (CommandEngine.arg.Count > 1) 15 | { 16 | Style.WriteFormatted("[!] Upss! Wrong format! Ex: \"disas 06000002\"\n", ConsoleColor.Red); 17 | return; 18 | } 19 | if (CommandEngine.arg.Count > 0) //Static Disassemble with DNLIB thanks to 0xd4d a.k.a. wtfsck 20 | { 21 | foreach (TypeDef type in Context.module.Types) 22 | { 23 | foreach (MethodDef method in type.Methods) 24 | { 25 | if (method.MDToken.ToString() == CommandEngine.arg[0]) 26 | { 27 | string result = ""; 28 | for (int i = 0; i < method.Body.Instructions.Count; i++) 29 | { 30 | result += $"{method.Body.Instructions[i].OpCode} {method.Body.Instructions[i].Operand}\n"; 31 | } 32 | Console.Write(result); 33 | } 34 | } 35 | } 36 | } 37 | if (CommandEngine.arg.Count == 0) //Dynamic disassemble with Dis2MSIL by rhotav and CodeProject 38 | { 39 | try 40 | { 41 | MethodBodyReader mr = new MethodBodyReader(Context.assembly.EntryPoint.Module, Context.currentMethodBody); 42 | Console.Write(mr.GetBodyCode()); 43 | } 44 | catch { } 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # JITK - JIT Killer 3 | [![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/tterb/atomic-design-ui/blob/master/LICENSES) 4 | ![files](https://img.shields.io/github/directory-file-count/rhotav/JITK) 5 | 6 | ``` 7 | _ _____ _______ _ __ 8 | | |_ _|__ __| |/ / 9 | | | | | | | | ' / 10 | _ | | | | | | | < 11 | | |__| |_| |_ | | | . \ 12 | \____/|_____| |_| |_|\_\ 13 | 14 | by rhotav 15 | ``` 16 | 17 | JIT Killer is hooker for clrjit.dll 18 | 19 | This process presents the communication between the compiler and the program to the user. 20 | 21 | ## Features 22 | 23 | - Breakpoint 24 | - Disassemble from Hex Codes 25 | - User friendly design 26 | 27 | ## Demo 28 | 29 | ![Rec 0003](https://user-images.githubusercontent.com/54905232/177761753-f11b5ea9-c5b1-4353-98d5-ec272b13bd58.gif) 30 | 31 | ## Commands 32 | 33 | | Parameter | Description | 34 | | -------- | ------------------------- | 35 | | `quit` | Suspend JIT Killer | 36 | | `infoa` | Get assembly info of target module. | 37 | | `clear` | Clear Console | 38 | | `help` | Help | 39 | | `about` | About **JITK** | 40 | | `infof` | Get functions from loaded module. | 41 | | `fc` | Path Clear | 42 | | `f` | Assign File | 43 | | `fg` | Assign File Argument/s | 44 | | `c` | Continue or Start Hook Process. | 45 | | `g` | Step next function. | 46 | | `b` | Define breakpoint | 47 | | `bl` | List All Breakpoint | 48 | | `disas` | Disassemble Method | 49 | | `disash` | Print method body as hex | 50 | 51 | 52 | 53 | ## Thanks 54 | 55 | - [@Washi1337](https://www.github.com/Washi1337) For the information it gives about the compiler and the problems it solves. 56 | - [@shibayan](https://www.github.com/shibayan) For [Sharprompt](https://github.com/shibayan/Sharprompt) and for quickly merging my improvements on Sharprompt 57 | - [@0xd4d](https://www.github.com/0xd4d) For [dnlib](https://github.com/0xd4d/dnlib) 58 | - [@maddnias](https://github.com/maddnias) For [SJITHook](https://github.com/maddnias/SJITHook) 59 | - All RTN members 60 | 61 | 62 | -------------------------------------------------------------------------------- /JITK.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31515.178 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JITK", "JITK\JITK.csproj", "{EC28F37B-89C4-42AA-97CD-AFDCE7A7A818}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharprompt", "Sharprompt-2.3.0\Sharprompt\Sharprompt.csproj", "{8551B506-0778-4307-A811-FC3352DC9B5F}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dis2Msil", "Dis2Msil\Dis2Msil\Dis2Msil.csproj", "{9873F12D-9C5B-4756-B31C-B514664638CE}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {EC28F37B-89C4-42AA-97CD-AFDCE7A7A818}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {EC28F37B-89C4-42AA-97CD-AFDCE7A7A818}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {EC28F37B-89C4-42AA-97CD-AFDCE7A7A818}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {EC28F37B-89C4-42AA-97CD-AFDCE7A7A818}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {8551B506-0778-4307-A811-FC3352DC9B5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {8551B506-0778-4307-A811-FC3352DC9B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {8551B506-0778-4307-A811-FC3352DC9B5F}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {8551B506-0778-4307-A811-FC3352DC9B5F}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {9873F12D-9C5B-4756-B31C-B514664638CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {9873F12D-9C5B-4756-B31C-B514664638CE}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {9873F12D-9C5B-4756-B31C-B514664638CE}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {9873F12D-9C5B-4756-B31C-B514664638CE}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {325F1521-55FE-4569-B235-6D8D4C0778B4} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Forms/FormBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | using Sharprompt.Drivers; 6 | using Sharprompt.Internal; 7 | 8 | namespace Sharprompt.Forms 9 | { 10 | internal abstract class FormBase : IDisposable 11 | { 12 | protected FormBase(bool cursorVisible = true) 13 | { 14 | ConsoleDriver = new DefaultConsoleDriver(); 15 | 16 | _formRenderer = new FormRenderer(ConsoleDriver, cursorVisible); 17 | } 18 | 19 | private readonly FormRenderer _formRenderer; 20 | 21 | protected IConsoleDriver ConsoleDriver { get; } 22 | 23 | public void Dispose() 24 | { 25 | _formRenderer.Dispose(); 26 | } 27 | 28 | public T Start() 29 | { 30 | while (true) 31 | { 32 | _formRenderer.Render(InputTemplate); 33 | 34 | if (!TryGetResult(out var result)) 35 | { 36 | continue; 37 | } 38 | 39 | _formRenderer.Render(FinishTemplate, result); 40 | 41 | return result; 42 | } 43 | } 44 | 45 | protected abstract bool TryGetResult(out T result); 46 | 47 | protected abstract void InputTemplate(OffscreenBuffer screenBuffer); 48 | 49 | protected abstract void FinishTemplate(OffscreenBuffer screenBuffer, T result); 50 | 51 | protected void SetValidationResult(ValidationResult validationResult) 52 | { 53 | _formRenderer.ErrorMessage = validationResult.ErrorMessage; 54 | } 55 | 56 | protected void SetException(Exception exception) 57 | { 58 | _formRenderer.ErrorMessage = exception.Message; 59 | } 60 | 61 | protected bool TryValidate(object input, IList> validators) 62 | { 63 | foreach (var validator in validators) 64 | { 65 | var result = validator(input); 66 | 67 | if (result != ValidationResult.Success) 68 | { 69 | SetValidationResult(result); 70 | 71 | return false; 72 | } 73 | } 74 | 75 | return true; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil/Dis2Msil.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {9873F12D-9C5B-4756-B31C-B514664638CE} 8 | Library 9 | Properties 10 | Dis2Msil 11 | Dis2Msil 12 | v4.7.2 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Forms/PasswordForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | using Sharprompt.Internal; 5 | 6 | namespace Sharprompt.Forms 7 | { 8 | internal class PasswordForm : FormBase 9 | { 10 | public PasswordForm(PasswordOptions options) 11 | { 12 | _options = options; 13 | } 14 | 15 | private readonly PasswordOptions _options; 16 | 17 | private readonly StringBuilder _inputBuffer = new StringBuilder(); 18 | 19 | protected override bool TryGetResult(out string result) 20 | { 21 | do 22 | { 23 | var keyInfo = ConsoleDriver.ReadKey(); 24 | 25 | switch (keyInfo.Key) 26 | { 27 | case ConsoleKey.Enter: 28 | { 29 | result = _inputBuffer.ToString(); 30 | 31 | if (TryValidate(result, _options.Validators)) 32 | { 33 | return true; 34 | } 35 | 36 | break; 37 | } 38 | case ConsoleKey.Backspace when _inputBuffer.Length == 0: 39 | ConsoleDriver.Beep(); 40 | break; 41 | case ConsoleKey.Backspace: 42 | _inputBuffer.Length -= 1; 43 | break; 44 | default: 45 | { 46 | if (!char.IsControl(keyInfo.KeyChar)) 47 | { 48 | _inputBuffer.Append(keyInfo.KeyChar); 49 | } 50 | 51 | break; 52 | } 53 | } 54 | 55 | } while (ConsoleDriver.KeyAvailable); 56 | 57 | result = null; 58 | 59 | return false; 60 | } 61 | 62 | protected override void InputTemplate(OffscreenBuffer screenBuffer) 63 | { 64 | screenBuffer.WritePrompt(_options.Message); 65 | screenBuffer.Write(new string('*', _inputBuffer.Length)); 66 | 67 | screenBuffer.SetCursorPosition(); 68 | } 69 | 70 | protected override void FinishTemplate(OffscreenBuffer screenBuffer, string result) 71 | { 72 | screenBuffer.WriteFinish(_options.Message); 73 | screenBuffer.Write(new string('*', _inputBuffer.Length), Prompt.ColorSchema.Answer); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil/Globals.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Reflection.Emit; 5 | 6 | namespace Dis2Msil 7 | { 8 | //https://www.codeproject.com/Articles/14058/Parsing-the-IL-of-a-Method-Body 9 | public static class Globals 10 | { 11 | public static Dictionary Cache = new Dictionary(); 12 | 13 | public static OpCode[] multiByteOpCodes; 14 | public static OpCode[] singleByteOpCodes; 15 | public static Module[] modules = null; 16 | 17 | public static void LoadOpCodes() 18 | { 19 | singleByteOpCodes = new OpCode[0x100]; 20 | multiByteOpCodes = new OpCode[0x100]; 21 | FieldInfo[] infoArray1 = typeof(OpCodes).GetFields(); 22 | for (int num1 = 0; num1 < infoArray1.Length; num1++) 23 | { 24 | FieldInfo info1 = infoArray1[num1]; 25 | if (info1.FieldType == typeof(OpCode)) 26 | { 27 | OpCode code1 = (OpCode)info1.GetValue(null); 28 | ushort num2 = (ushort)code1.Value; 29 | if (num2 < 0x100) 30 | { 31 | singleByteOpCodes[num2] = code1; 32 | } 33 | else 34 | { 35 | if ((num2 & 0xff00) != 0xfe00) 36 | { 37 | throw new Exception("Invalid OpCode."); 38 | } 39 | multiByteOpCodes[num2 & 0xff] = code1; 40 | } 41 | } 42 | } 43 | } 44 | 45 | 46 | /// 47 | /// Retrieve the friendly name of a type 48 | /// 49 | /// 50 | /// The complete name to the type 51 | /// 52 | /// 53 | /// The simplified name of the type (i.e. "int" instead f System.Int32) 54 | /// 55 | public static string ProcessSpecialTypes(string typeName) 56 | { 57 | string result = typeName; 58 | switch (typeName) 59 | { 60 | case "System.string": 61 | case "System.String": 62 | case "String": 63 | result = "string"; break; 64 | case "System.Int32": 65 | case "Int": 66 | case "Int32": 67 | result = "int"; break; 68 | } 69 | return result; 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /JITK/Core/Command/Continue.cs: -------------------------------------------------------------------------------- 1 | using JITK.Core.SJITHook; 2 | using System; 3 | using System.Linq; 4 | using Dis2Msil; 5 | 6 | namespace JITK.Core.Command 7 | { 8 | class Continue : Command 9 | { 10 | override public string HelpText { get { return "Continue or Start Hook Process."; } } 11 | override public string Name { get { return "c"; } } 12 | override public ArgumentSize ArgSize { get { return ArgumentSize.None; } } 13 | 14 | /* 15 | * What is prepareMethods? by *Washi* from "Official RTN Discord Server" 16 | * Suppose your callback is in assembly A1, and it is using method M that is defined in an external assembly A2. 17 | Then A2.M still has to be JIT'ed 18 | Even if all methods from A1 are already JIT'ed 19 | * 20 | * 21 | */ 22 | 23 | override public unsafe void Action() 24 | { 25 | if (Context.hookState == false && Context.filePath.Trim() == "") 26 | { 27 | Style.WriteFormatted("[!] File path is not assigned!\n", ConsoleColor.Red); 28 | return; 29 | } 30 | if (Context.hookState == false) 31 | { 32 | Context._jitHook = new JITHook64(); 33 | Style.WriteFormatted("[^] Hook process is starting...\n"); 34 | Style.WriteFormatted("[^] Methods are preparing for pre-jit\n"); 35 | Context._jitHook.PrepareMethods(Context.assembly); 36 | Context._jitHook.PrepareMethods(System.Reflection.Assembly.GetExecutingAssembly()); 37 | 38 | object[] parameters = null; 39 | if (Context.assembly.EntryPoint.GetParameters().Length != 0) 40 | { 41 | parameters = new object[] 42 | { 43 | Context.arguments.Select(i => i.ToString()).ToArray() 44 | }; 45 | } 46 | Context.hookState = true; 47 | Style.WriteFormatted("[?] Hook mode activated.\n", ConsoleColor.Blue); 48 | Style.WriteFormatted("[?] Invoking...\n", ConsoleColor.Blue); 49 | 50 | if (Context._jitHook.Hook(Context.HookedCompileMethod)) 51 | { 52 | 53 | Context.assembly.EntryPoint.Invoke(null, parameters); 54 | } 55 | return; 56 | } 57 | if (Context.hookState == true) 58 | { 59 | Context.continueOtherFunc = true; 60 | return; 61 | } 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Validators.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Sharprompt 6 | { 7 | public static class Validators 8 | { 9 | public static Func Required(string errorMessage = null) 10 | { 11 | return input => 12 | { 13 | if (input == null) 14 | { 15 | return new ValidationResult(errorMessage ?? "Value is required"); 16 | } 17 | 18 | if (input is string strValue && string.IsNullOrEmpty(strValue)) 19 | { 20 | return new ValidationResult(errorMessage ?? "Value is required"); 21 | } 22 | 23 | return ValidationResult.Success; 24 | }; 25 | } 26 | 27 | public static Func MinLength(int length, string errorMessage = null) 28 | { 29 | return input => 30 | { 31 | if (!(input is string strValue)) 32 | { 33 | return ValidationResult.Success; 34 | } 35 | 36 | if (strValue.Length >= length) 37 | { 38 | return ValidationResult.Success; 39 | } 40 | 41 | return new ValidationResult(errorMessage ?? "Value is too short"); 42 | }; 43 | } 44 | 45 | public static Func MaxLength(int length, string errorMessage = null) 46 | { 47 | return input => 48 | { 49 | if (!(input is string strValue)) 50 | { 51 | return ValidationResult.Success; 52 | } 53 | 54 | if (strValue.Length <= length) 55 | { 56 | return ValidationResult.Success; 57 | } 58 | 59 | return new ValidationResult(errorMessage ?? "Value is too long"); 60 | }; 61 | } 62 | 63 | public static Func RegularExpression(string pattern, string errorMessage = null) 64 | { 65 | return input => 66 | { 67 | if (!(input is string strValue)) 68 | { 69 | return ValidationResult.Success; 70 | } 71 | 72 | if (Regex.IsMatch(strValue, pattern)) 73 | { 74 | return ValidationResult.Success; 75 | } 76 | 77 | return new ValidationResult(errorMessage ?? "Value is not match pattern"); 78 | }; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil.Test/Dis2Msil.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F4EF0212-1A06-4A72-8AD6-9E67F05666F9} 8 | Exe 9 | Dis2Msil.Test 10 | Dis2Msil.Test 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | False 38 | ..\Dis2Msil\bin\Debug\Dis2Msil.dll 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Drivers/DefaultConsoleDriver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | using Sharprompt.Internal; 5 | 6 | namespace Sharprompt.Drivers 7 | { 8 | internal sealed class DefaultConsoleDriver : IConsoleDriver 9 | { 10 | static DefaultConsoleDriver() 11 | { 12 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) 13 | { 14 | var hConsole = NativeMethods.GetStdHandle(NativeMethods.STD_OUTPUT_HANDLE); 15 | 16 | if (!NativeMethods.GetConsoleMode(hConsole, out var mode)) 17 | { 18 | return; 19 | } 20 | 21 | NativeMethods.SetConsoleMode(hConsole, mode | NativeMethods.ENABLE_VIRTUAL_TERMINAL_PROCESSING); 22 | } 23 | } 24 | 25 | public DefaultConsoleDriver() 26 | { 27 | Console.CancelKeyPress += CancelKeyPressHandler; 28 | } 29 | 30 | #region IDisposable 31 | 32 | public void Dispose() 33 | { 34 | Reset(); 35 | 36 | Console.CancelKeyPress -= CancelKeyPressHandler; 37 | } 38 | 39 | #endregion 40 | 41 | #region IConsoleDriver 42 | 43 | public void Beep() => Console.Write("\a"); 44 | 45 | public void Reset() 46 | { 47 | Console.CursorVisible = true; 48 | Console.ResetColor(); 49 | } 50 | 51 | public void ClearLine(int top) 52 | { 53 | SetCursorPosition(0, top); 54 | 55 | Console.Write("\x1b[2K"); 56 | } 57 | 58 | public ConsoleKeyInfo ReadKey() => Console.ReadKey(true); 59 | 60 | public void Write(string value, ConsoleColor color) 61 | { 62 | Console.ForegroundColor = color; 63 | Console.Write(value); 64 | Console.ResetColor(); 65 | } 66 | 67 | public void WriteLine() => Console.WriteLine(); 68 | 69 | public (int left, int top) GetCursorPosition() => (Console.CursorLeft, Console.CursorTop); 70 | 71 | public void SetCursorPosition(int left, int top) 72 | { 73 | if (top < 0) 74 | { 75 | top = 0; 76 | } 77 | else if (top >= Console.BufferHeight) 78 | { 79 | top = Console.BufferHeight - 1; 80 | } 81 | 82 | Console.SetCursorPosition(left, top); 83 | } 84 | 85 | public bool KeyAvailable => Console.KeyAvailable; 86 | 87 | public bool CursorVisible 88 | { 89 | get => Console.CursorVisible; 90 | set => Console.CursorVisible = value; 91 | } 92 | 93 | public int CursorLeft => Console.CursorLeft; 94 | 95 | public int CursorTop => Console.CursorTop; 96 | 97 | public int BufferWidth => Console.BufferWidth; 98 | 99 | public int BufferHeight => Console.BufferHeight; 100 | 101 | public Action RequestCancellation { get; set; } 102 | 103 | #endregion 104 | 105 | private void CancelKeyPressHandler(object sender, ConsoleCancelEventArgs e) 106 | { 107 | RequestCancellation?.Invoke(); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /JITK/Core/SJITHook/JITHook.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace JITK.Core.SJITHook 7 | { 8 | public unsafe class JITHook where T : VTableAddrProvider 9 | { 10 | private readonly T _addrProvider; 11 | public Data.CompileMethodDel OriginalCompileMethod { get; private set; } 12 | 13 | public JITHook() 14 | { 15 | _addrProvider = Activator.CreateInstance(); 16 | } 17 | 18 | public bool Hook(Data.CompileMethodDel hookedCompileMethod) 19 | { 20 | IntPtr pVTable = _addrProvider.VTableAddr; 21 | IntPtr pCompileMethod = Marshal.ReadIntPtr(pVTable); 22 | uint old; 23 | 24 | if ( 25 | !Data.VirtualProtect(pCompileMethod, (uint)IntPtr.Size, 26 | Data.Protection.PAGE_EXECUTE_READWRITE, out old)) 27 | return false; 28 | 29 | OriginalCompileMethod = 30 | (Data.CompileMethodDel) 31 | Marshal.GetDelegateForFunctionPointer(Marshal.ReadIntPtr(pCompileMethod), typeof(Data.CompileMethodDel)); 32 | 33 | // We don't want any infinite loops :-) 34 | RuntimeHelpers.PrepareDelegate(hookedCompileMethod); 35 | RuntimeHelpers.PrepareDelegate(OriginalCompileMethod); 36 | RuntimeHelpers.PrepareMethod(GetType().GetMethod("UnHook").MethodHandle, new[] { typeof(T).TypeHandle }); 37 | 38 | Marshal.WriteIntPtr(pCompileMethod, Marshal.GetFunctionPointerForDelegate(hookedCompileMethod)); 39 | 40 | return Data.VirtualProtect(pCompileMethod, (uint)IntPtr.Size, 41 | (Data.Protection)old, out old); 42 | } 43 | 44 | public bool UnHook() 45 | { 46 | IntPtr pVTable = _addrProvider.VTableAddr; 47 | IntPtr pCompileMethod = Marshal.ReadIntPtr(pVTable); 48 | uint old; 49 | 50 | if ( 51 | !Data.VirtualProtect(pCompileMethod, (uint)IntPtr.Size, 52 | Data.Protection.PAGE_EXECUTE_READWRITE, out old)) 53 | return false; 54 | 55 | Marshal.WriteIntPtr(pCompileMethod, Marshal.GetFunctionPointerForDelegate(OriginalCompileMethod)); 56 | 57 | return Data.VirtualProtect(pCompileMethod, (uint)IntPtr.Size, 58 | (Data.Protection)old, out old); 59 | } 60 | 61 | public void PrepareMethods(Assembly asm) 62 | { 63 | Module[] mods = asm.GetLoadedModules(); 64 | foreach (Module mod in mods) 65 | { 66 | Type[] classes = mod.GetTypes(); 67 | foreach (Type c in classes) 68 | { 69 | MethodInfo[] methods = c.GetMethods(); 70 | foreach (MethodInfo method in methods) 71 | { 72 | try 73 | { 74 | RuntimeHelpers.PrepareMethod(method.MethodHandle); 75 | } 76 | catch (Exception) 77 | { 78 | Console.WriteLine("[!] Failed to prepare method 0x{0:X}", method.MetadataToken); 79 | } 80 | } 81 | } 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /JITK/Core/SJITHook/JITHook64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace JITK.Core.SJITHook 7 | { 8 | public unsafe class JITHook64 where T : VTableAddrProvider 9 | { 10 | private readonly T _addrProvider; 11 | public Data.CompileMethodDel64 OriginalCompileMethod { get; private set; } 12 | 13 | public JITHook64() 14 | { 15 | _addrProvider = Activator.CreateInstance(); 16 | } 17 | 18 | public bool Hook(Data.CompileMethodDel64 hookedCompileMethod) 19 | { 20 | IntPtr pVTable = _addrProvider.VTableAddr; 21 | IntPtr pCompileMethod = Marshal.ReadIntPtr(pVTable); 22 | uint old; 23 | 24 | if ( 25 | !Data.VirtualProtect(pCompileMethod, (uint)IntPtr.Size, 26 | Data.Protection.PAGE_EXECUTE_READWRITE, out old)) 27 | return false; 28 | 29 | OriginalCompileMethod = 30 | (Data.CompileMethodDel64) 31 | Marshal.GetDelegateForFunctionPointer(Marshal.ReadIntPtr(pCompileMethod), typeof(Data.CompileMethodDel64)); 32 | 33 | // We don't want any infinite loops :-) 34 | RuntimeHelpers.PrepareDelegate(hookedCompileMethod); 35 | RuntimeHelpers.PrepareDelegate(OriginalCompileMethod); 36 | RuntimeHelpers.PrepareMethod(GetType().GetMethod("UnHook").MethodHandle, new[] { typeof(T).TypeHandle }); 37 | 38 | Marshal.WriteIntPtr(pCompileMethod, Marshal.GetFunctionPointerForDelegate(hookedCompileMethod)); 39 | 40 | return Data.VirtualProtect(pCompileMethod, (uint)IntPtr.Size, 41 | (Data.Protection)old, out old); 42 | } 43 | 44 | public bool UnHook() 45 | { 46 | IntPtr pVTable = _addrProvider.VTableAddr; 47 | IntPtr pCompileMethod = Marshal.ReadIntPtr(pVTable); 48 | uint old; 49 | 50 | if ( 51 | !Data.VirtualProtect(pCompileMethod, (uint)IntPtr.Size, 52 | Data.Protection.PAGE_EXECUTE_READWRITE, out old)) 53 | return false; 54 | 55 | Marshal.WriteIntPtr(pCompileMethod, Marshal.GetFunctionPointerForDelegate(OriginalCompileMethod)); 56 | 57 | return Data.VirtualProtect(pCompileMethod, (uint)IntPtr.Size, 58 | (Data.Protection)old, out old); 59 | } 60 | 61 | public void PrepareMethods(Assembly asm) 62 | { 63 | Module[] mods = asm.GetLoadedModules(); 64 | foreach (Module mod in mods) 65 | { 66 | Type[] classes = mod.GetTypes(); 67 | foreach (Type c in classes) 68 | { 69 | MethodInfo[] methods = c.GetMethods(); 70 | foreach (MethodInfo method in methods) 71 | { 72 | try 73 | { 74 | RuntimeHelpers.PrepareMethod(method.MethodHandle); 75 | } 76 | catch (Exception ex) 77 | { 78 | if (asm == Assembly.GetExecutingAssembly()) 79 | { 80 | continue; 81 | } 82 | Console.WriteLine(ex.Message + " 0x{0:X}", method.MetadataToken); 83 | } 84 | } 85 | } 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /JITK/Core/Style.cs: -------------------------------------------------------------------------------- 1 | using Sharprompt; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Drawing; 5 | 6 | namespace JITK.Core 7 | { 8 | 9 | class Style 10 | { 11 | public static Symbol error = new Symbol("[!] >", "[!]"); 12 | public static Symbol question = new Symbol("[?] >", "[?]"); 13 | public static Symbol done = new Symbol("[*]", "[^]"); 14 | public static Symbol selector = new Symbol(">>", ""); 15 | public static Symbol state = new Symbol($"[{Context.currentToken}]", ""); 16 | 17 | public static Dictionary keywords = new Dictionary(); 18 | public static void LoadKeywords() 19 | { 20 | keywords.Add("[*]", ConsoleColor.DarkGreen); 21 | keywords.Add("[^]", ConsoleColor.DarkGreen); 22 | keywords.Add("[?]", ConsoleColor.DarkBlue); 23 | keywords.Add("[!]", ConsoleColor.DarkRed) ; 24 | keywords.Add("[>]", ConsoleColor.DarkYellow); 25 | 26 | keywords.Add("Assembly-Info:", ConsoleColor.White); 27 | keywords.Add("EntryPoint:", ConsoleColor.White); 28 | keywords.Add("Machine:", ConsoleColor.White); 29 | keywords.Add("Characteristics:", ConsoleColor.White); 30 | keywords.Add("HasResources:", ConsoleColor.White); 31 | keywords.Add("HasExportedTypes:", ConsoleColor.White); 32 | keywords.Add("JITK", ConsoleColor.DarkRed); 33 | keywords.Add("rhotav", ConsoleColor.DarkGray); 34 | keywords.Add("Name:", ConsoleColor.White); 35 | keywords.Add("Token:", ConsoleColor.DarkMagenta); 36 | keywords.Add("ID:", ConsoleColor.DarkMagenta); 37 | 38 | 39 | } 40 | 41 | public static void WriteFormatted(string text, ConsoleColor defaultColor = ConsoleColor.Gray) 42 | { 43 | string[] strArray = text.Split(' '); 44 | for (int i = 0; i < strArray.Length; i++) 45 | { 46 | if (keywords.ContainsKey(strArray[i])) 47 | { 48 | Console.ForegroundColor = keywords[strArray[i]]; 49 | Console.Write(strArray[i] + " "); 50 | } 51 | else 52 | { 53 | Console.ForegroundColor = defaultColor; 54 | Console.Write(strArray[i] + " "); 55 | } 56 | } 57 | Console.ResetColor(); 58 | } 59 | 60 | public static void Write(string text, ConsoleColor color) 61 | { 62 | Console.ForegroundColor = color; 63 | Console.Write(text); 64 | } 65 | 66 | public static string WriteState(string Text) 67 | { 68 | state = new Symbol($"[{Context.currentToken}]", $"[{Context.currentToken}]"); 69 | Prompt.Symbols.Prompt = state; 70 | Prompt.Symbols.Done = done; 71 | Prompt.ColorSchema.DoneSymbolColor = ConsoleColor.Green; 72 | Prompt.ColorSchema.PromptSymbolColor = ConsoleColor.DarkYellow; 73 | Prompt.ColorSchema.Answer = ConsoleColor.White; 74 | 75 | string returnable = Prompt.Input(Text); 76 | return returnable; 77 | } 78 | 79 | 80 | public static string WriteError(string Text) { 81 | 82 | Prompt.Symbols.Prompt = error; 83 | Prompt.Symbols.Done = done; 84 | Prompt.ColorSchema.DoneSymbolColor = ConsoleColor.Red; 85 | Prompt.ColorSchema.PromptSymbolColor = ConsoleColor.DarkRed; 86 | Prompt.ColorSchema.Answer = ConsoleColor.Red; 87 | 88 | string returnable = Prompt.Input(Text); 89 | return returnable; 90 | } 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /JITK/Core/Context.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | using System.IO; 4 | using System.Reflection; 5 | using JITK.Core.SJITHook; 6 | using JITK.Core.Command; 7 | using System.Runtime.InteropServices; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using Dis2Msil; 11 | 12 | namespace JITK.Core 13 | { 14 | class Context 15 | { 16 | public static string filePath = ""; 17 | public static string arguments = ""; 18 | public static ModuleDefMD module = null; 19 | public static Assembly assembly = null; 20 | 21 | public static string currentToken = "00000000"; 22 | 23 | public static bool hookState = false; 24 | public static bool continueOtherFunc = false; 25 | public static bool stepOtherFunc = false; 26 | public static JITHook64 _jitHook; 27 | 28 | public static Dictionary breakPoints = new Dictionary(); 29 | public static string currentMethodBody = ""; 30 | 31 | public static bool IsNet(string path) 32 | { 33 | try 34 | { 35 | if (File.Exists(path)) 36 | { 37 | module = ModuleDefMD.Load(path); 38 | assembly = Assembly.LoadFile(path); 39 | 40 | Style.WriteFormatted($"[*] {module.Name} is loaded!\n"); 41 | return true; 42 | } 43 | else 44 | { 45 | return false; 46 | } 47 | } 48 | catch 49 | { 50 | return false; 51 | } 52 | } 53 | 54 | 55 | public static unsafe int HookedCompileMethod(IntPtr thisPtr, [In] IntPtr corJitInfo, 56 | [In] Data.CorMethodInfo64* methodInfo, Data.CorJitFlag flags, 57 | [Out] IntPtr nativeEntry, [Out] IntPtr nativeSizeOfCode) 58 | { 59 | int token = (0x06000000 + *(ushort*)methodInfo->methodHandle); 60 | var bodyBuffer = new byte[methodInfo->ilCodeSize]; 61 | Marshal.Copy(methodInfo->ilCode, bodyBuffer, 0, bodyBuffer.Length); 62 | currentMethodBody = BitConverter.ToString(bodyBuffer); 63 | 64 | Console.WriteLine("=============================================="); 65 | Style.WriteFormatted($"[>] Intercepted {token:x8}\n", ConsoleColor.Blue); 66 | Style.WriteFormatted($"[>] Body Size: {methodInfo->ilCodeSize}\n", ConsoleColor.Blue); 67 | currentToken = token.ToString("x8"); 68 | while (true) 69 | { 70 | if (breakPoints.ContainsValue(currentToken.Replace("0x", ""))) 71 | { 72 | Style.WriteFormatted($"[^] Hit breakpoint!\n", ConsoleColor.DarkCyan); 73 | continueOtherFunc = false; 74 | stepOtherFunc = false; 75 | } 76 | if (continueOtherFunc == true) 77 | { 78 | break; 79 | } 80 | string returnable = Style.WriteState(">"); 81 | if (CommandEngine.ExecuteCommand(returnable)) 82 | { 83 | 84 | if (stepOtherFunc == true) 85 | { 86 | stepOtherFunc = false; 87 | break; 88 | } 89 | if (continueOtherFunc == true) 90 | { 91 | return _jitHook.OriginalCompileMethod(thisPtr, corJitInfo, methodInfo, flags, nativeEntry, nativeSizeOfCode); 92 | } 93 | 94 | } 95 | } 96 | 97 | return _jitHook.OriginalCompileMethod(thisPtr, corJitInfo, methodInfo, flags, nativeEntry, nativeSizeOfCode); 98 | } 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Internal/Paginator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Sharprompt.Internal 6 | { 7 | internal class Paginator 8 | { 9 | public Paginator(IEnumerable items, int? pageSize, Optional defaultValue, Func textSelector) 10 | { 11 | _items = items.ToArray(); 12 | _pageSize = pageSize ?? _items.Length; 13 | _textSelector = textSelector; 14 | 15 | InitializeDefaults(defaultValue); 16 | } 17 | 18 | private readonly T[] _items; 19 | private readonly int _pageSize; 20 | private readonly Func _textSelector; 21 | 22 | private T[] _filteredItems; 23 | private int _pageCount; 24 | 25 | private int _selectedIndex = -1; 26 | private int _selectedPage; 27 | 28 | public int PageCount => _pageCount; 29 | public int SelectedPage => _selectedPage; 30 | public int TotalCount => _filteredItems.Length; 31 | 32 | public int Count => Math.Min(_filteredItems.Length - (_pageSize * _selectedPage), _pageSize); 33 | 34 | public string FilterTerm { get; private set; } = ""; 35 | 36 | public bool TryGetSelectedItem(out T selectedItem) 37 | { 38 | if (_selectedIndex == -1) 39 | { 40 | selectedItem = default; 41 | 42 | return false; 43 | } 44 | 45 | selectedItem = _filteredItems[(_pageSize * _selectedPage) + _selectedIndex]; 46 | 47 | return true; 48 | } 49 | 50 | public void NextItem() 51 | { 52 | _selectedIndex = _selectedIndex >= Count - 1 ? 0 : _selectedIndex + 1; 53 | } 54 | 55 | public void PreviousItem() 56 | { 57 | _selectedIndex = _selectedIndex <= 0 ? Count - 1 : _selectedIndex - 1; 58 | } 59 | 60 | public void NextPage() 61 | { 62 | if (_pageCount == 1) 63 | { 64 | return; 65 | } 66 | 67 | _selectedPage = _selectedPage >= _pageCount - 1 ? 0 : _selectedPage + 1; 68 | _selectedIndex = -1; 69 | } 70 | 71 | public void PreviousPage() 72 | { 73 | if (_pageCount == 1) 74 | { 75 | return; 76 | } 77 | 78 | _selectedPage = _selectedPage <= 0 ? _pageCount - 1 : _selectedPage - 1; 79 | _selectedIndex = -1; 80 | } 81 | 82 | public void UpdateFilter(string term) 83 | { 84 | FilterTerm = term; 85 | 86 | _selectedIndex = -1; 87 | _selectedPage = 0; 88 | 89 | InitializeCollection(); 90 | } 91 | 92 | public ArraySegment ToSubset() 93 | { 94 | return new ArraySegment(_filteredItems, _pageSize * _selectedPage, Count); 95 | } 96 | 97 | private void InitializeCollection() 98 | { 99 | _filteredItems = _items.Where(x => _textSelector(x).IndexOf(FilterTerm, StringComparison.OrdinalIgnoreCase) != -1) 100 | .ToArray(); 101 | 102 | _pageCount = (_filteredItems.Length - 1) / _pageSize + 1; 103 | } 104 | 105 | private void InitializeDefaults(Optional defaultValue) 106 | { 107 | InitializeCollection(); 108 | 109 | if (!defaultValue.HasValue) 110 | { 111 | return; 112 | } 113 | 114 | for (var i = 0; i < _filteredItems.Length; i++) 115 | { 116 | if (EqualityComparer.Default.Equals(_filteredItems[i], defaultValue)) 117 | { 118 | _selectedIndex = i % _pageSize; 119 | _selectedPage = i / _pageSize; 120 | 121 | break; 122 | } 123 | } 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt.Example/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | using Sharprompt.Example.Models; 5 | 6 | namespace Sharprompt.Example 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | Console.OutputEncoding = Encoding.UTF8; 13 | 14 | while (true) 15 | { 16 | var type = Prompt.Select("Choose prompt example"); 17 | 18 | switch (type) 19 | { 20 | case ExampleType.Input: 21 | RunInputSample(); 22 | break; 23 | case ExampleType.Confirm: 24 | RunConfirmSample(); 25 | break; 26 | case ExampleType.Password: 27 | RunPasswordSample(); 28 | break; 29 | case ExampleType.Select: 30 | RunSelectSample(); 31 | break; 32 | case ExampleType.MultiSelect: 33 | RunMultiSelectSample(); 34 | break; 35 | case ExampleType.SelectWithEnum: 36 | RunSelectEnumSample(); 37 | break; 38 | case ExampleType.MultiSelectWithEnum: 39 | RunMultiSelectEnumSample(); 40 | break; 41 | case ExampleType.List: 42 | RunListSample(); 43 | break; 44 | case ExampleType.AutoForms: 45 | RunAutoFormsSample(); 46 | break; 47 | default: 48 | throw new ArgumentOutOfRangeException(); 49 | } 50 | } 51 | } 52 | 53 | private static void RunInputSample() 54 | { 55 | var name = Prompt.Input("What's your name?", validators: new[] { Validators.Required(), Validators.MinLength(3) }); 56 | Console.WriteLine($"Hello, {name}!"); 57 | } 58 | 59 | private static void RunConfirmSample() 60 | { 61 | var answer = Prompt.Confirm("Are you ready?"); 62 | Console.WriteLine($"Your answer is {answer}"); 63 | } 64 | 65 | private static void RunPasswordSample() 66 | { 67 | var secret = Prompt.Password("Type new password", new[] { Validators.Required(), Validators.MinLength(8) }); 68 | Console.WriteLine("Password OK"); 69 | } 70 | 71 | private static void RunSelectSample() 72 | { 73 | var city = Prompt.Select("Select your city", new[] { "Seattle", "London", "Tokyo", "New York", "Singapore", "Shanghai" }, pageSize: 3); 74 | Console.WriteLine($"Hello, {city}!"); 75 | } 76 | 77 | private static void RunMultiSelectSample() 78 | { 79 | var options = Prompt.MultiSelect("Which cities would you like to visit?", new[] { "Seattle", "London", "Tokyo", "New York", "Singapore", "Shanghai" }, pageSize: 3, defaultValues: new[] { "Tokyo" }); 80 | Console.WriteLine($"You picked {string.Join(", ", options)}"); 81 | } 82 | 83 | private static void RunSelectEnumSample() 84 | { 85 | var value = Prompt.Select("Select enum value", defaultValue: MyEnum.Bar); 86 | Console.WriteLine($"You selected {value}"); 87 | } 88 | 89 | private static void RunMultiSelectEnumSample() 90 | { 91 | var value = Prompt.MultiSelect("Select enum value", defaultValues: new[] { MyEnum.Bar }); 92 | Console.WriteLine($"You picked {string.Join(", ", value)}"); 93 | } 94 | 95 | private static void RunListSample() 96 | { 97 | var value = Prompt.List("Please add item(s)"); 98 | Console.WriteLine($"You picked {string.Join(", ", value)}"); 99 | } 100 | 101 | private static void RunAutoFormsSample() 102 | { 103 | var model = Prompt.AutoForms(); 104 | Console.WriteLine("Forms OK"); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/README.md: -------------------------------------------------------------------------------- 1 | # Sharprompt 2 | 3 | ![Build](https://github.com/shibayan/Sharprompt/workflows/Build/badge.svg) 4 | [![License](https://img.shields.io/github/license/shibayan/Sharprompt)](https://github.com/shibayan/Sharprompt/blob/master/LICENSE) 5 | [![Downloads](https://img.shields.io/nuget/dt/Sharprompt)](https://www.nuget.org/packages/Sharprompt/) 6 | 7 | Interactive command line interface toolkit for C# 8 | 9 | ![sharprompt](https://user-images.githubusercontent.com/1356444/62227794-87506e00-b3f7-11e9-84ae-06c9a900448b.gif) 10 | 11 | ## NuGet Package 12 | 13 | Package Name | Target Framework | NuGet 14 | ---|---|--- 15 | Sharprompt | .NET Standard 2.0 | [![NuGet](https://img.shields.io/nuget/v/Sharprompt)](https://www.nuget.org/packages/Sharprompt/) 16 | 17 | ## Install 18 | 19 | ``` 20 | Install-Package Sharprompt 21 | ``` 22 | 23 | ``` 24 | dotnet add package Sharprompt 25 | ``` 26 | 27 | ## Features 28 | 29 | - Multi-platform support 30 | - Supports the popular Prompts (Input / Password / Select / etc) 31 | - Validation of input value 32 | - Automatic generation of data source using Enum value 33 | - Customize the color scheme 34 | - Unicode support (East asian width and Emoji) 35 | 36 | ## Usage 37 | 38 | ```csharp 39 | // Simple Input prompt 40 | var name = Prompt.Input("What's your name?"); 41 | Console.WriteLine($"Hello, {name}!"); 42 | 43 | // Password prompt 44 | var secret = Prompt.Password("Type new password", new[] { Validators.Required(), Validators.MinLength(8) }); 45 | Console.WriteLine("Password OK"); 46 | 47 | // Confirmation prompt 48 | var answer = Prompt.Confirm("Are you ready?", defaultValue: true); 49 | Console.WriteLine($"Your answer is {answer}"); 50 | ``` 51 | 52 | ## APIs 53 | 54 | ### Input 55 | 56 | ```csharp 57 | var name = Prompt.Input("What's your name?"); 58 | Console.WriteLine($"Hello, {name}!"); 59 | ``` 60 | 61 | ![input](https://user-images.githubusercontent.com/1356444/62228275-50c72300-b3f8-11e9-8d51-63892e8eeaaa.gif) 62 | 63 | ### Confirm 64 | 65 | ```csharp 66 | var answer = Prompt.Confirm("Are you ready?"); 67 | Console.WriteLine($"Your answer is {answer}"); 68 | ``` 69 | 70 | ![confirm](https://user-images.githubusercontent.com/1356444/62229064-e0210600-b3f9-11e9-8c52-b9c9257811c0.gif) 71 | 72 | ### Password 73 | 74 | ```csharp 75 | var secret = Prompt.Password("Type new password"); 76 | Console.WriteLine("Password OK"); 77 | ``` 78 | 79 | ![password](https://user-images.githubusercontent.com/1356444/62228952-9fc18800-b3f9-11e9-98ea-3aa52ee84e93.gif) 80 | 81 | ### Select 82 | 83 | ```csharp 84 | var city = Prompt.Select("Select your city", new[] { "Seattle", "London", "Tokyo" }); 85 | Console.WriteLine($"Hello, {city}!"); 86 | ``` 87 | 88 | ![select](https://user-images.githubusercontent.com/1356444/62228719-2de93e80-b3f9-11e9-8be5-f19e6ef58aeb.gif) 89 | 90 | **Enum value support** 91 | 92 | ```csharp 93 | var value = Prompt.Select("Select enum value"); 94 | Console.WriteLine($"You selected {value}"); 95 | ``` 96 | 97 | ### MultiSelect 98 | 99 | ```csharp 100 | var cities = Prompt.MultiSelect("Which cities would you like to visit?", new[] { "Seattle", "London", "Tokyo", "New York", "Singapore", "Shanghai" }, pageSize: 3); 101 | Console.WriteLine($"You picked {string.Join(", ", options)}"); 102 | ``` 103 | 104 | ## Configuration 105 | 106 | ### Custom Prompter 107 | 108 | ```csharp 109 | Prompt.ColorSchema.Answer = ConsoleColor.DarkRed; 110 | Prompt.ColorSchema.Select = ConsoleColor.DarkCyan; 111 | 112 | var name = Prompt.Input("What's your name?"); 113 | Console.WriteLine($"Hello, {name}!"); 114 | ``` 115 | 116 | ### Unicode Support 117 | 118 | ![unicode](https://user-images.githubusercontent.com/1356444/89803983-86a3f900-db6e-11ea-8fc8-5b6f9ef5644f.gif) 119 | 120 | ```csharp 121 | // Prefer UTF-8 as the output encoding 122 | Console.OutputEncoding = Encoding.UTF8; 123 | 124 | var name = Prompt.Input("What's your name?"); 125 | Console.WriteLine($"Hello, {name}!"); 126 | ``` 127 | 128 | ## Platforms 129 | 130 | - Windows 131 | - Command Prompt / PowerShell / Windows Terminal 132 | - Ubuntu 133 | - Bash 134 | - macOS 135 | - Bash 136 | 137 | ## License 138 | 139 | This project is licensed under the [MIT License](https://github.com/shibayan/Sharprompt/blob/master/LICENSE) 140 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Forms/SelectForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Text; 5 | 6 | using Sharprompt.Internal; 7 | 8 | namespace Sharprompt.Forms 9 | { 10 | internal class SelectForm : FormBase 11 | { 12 | public SelectForm(SelectOptions options) 13 | : base(false) 14 | { 15 | _paginator = new Paginator(options.Items, options.PageSize, Optional.Create(options.DefaultValue), options.TextSelector); 16 | 17 | _options = options; 18 | } 19 | 20 | private readonly SelectOptions _options; 21 | private readonly Paginator _paginator; 22 | 23 | private readonly StringBuilder _filterBuffer = new StringBuilder(); 24 | 25 | protected override bool TryGetResult(out T result) 26 | { 27 | do 28 | { 29 | var keyInfo = ConsoleDriver.ReadKey(); 30 | 31 | switch (keyInfo.Key) 32 | { 33 | case ConsoleKey.Enter when _paginator.TryGetSelectedItem(out result): 34 | return true; 35 | case ConsoleKey.Enter: 36 | SetValidationResult(new ValidationResult("Value is required")); 37 | break; 38 | case ConsoleKey.UpArrow: 39 | _paginator.PreviousItem(); 40 | break; 41 | case ConsoleKey.DownArrow: 42 | _paginator.NextItem(); 43 | break; 44 | case ConsoleKey.LeftArrow: 45 | _paginator.PreviousPage(); 46 | break; 47 | case ConsoleKey.RightArrow: 48 | _paginator.NextPage(); 49 | break; 50 | case ConsoleKey.Backspace when _filterBuffer.Length == 0: 51 | ConsoleDriver.Beep(); 52 | break; 53 | case ConsoleKey.Backspace: 54 | _filterBuffer.Length -= 1; 55 | 56 | _paginator.UpdateFilter(_filterBuffer.ToString()); 57 | break; 58 | default: 59 | { 60 | if (!char.IsControl(keyInfo.KeyChar)) 61 | { 62 | _filterBuffer.Append(keyInfo.KeyChar); 63 | 64 | _paginator.UpdateFilter(_filterBuffer.ToString()); 65 | } 66 | 67 | break; 68 | } 69 | } 70 | 71 | } while (ConsoleDriver.KeyAvailable); 72 | 73 | result = default; 74 | 75 | return false; 76 | } 77 | 78 | protected override void InputTemplate(OffscreenBuffer screenBuffer) 79 | { 80 | screenBuffer.WritePrompt(_options.Message); 81 | screenBuffer.Write(_paginator.FilterTerm); 82 | 83 | var subset = _paginator.ToSubset(); 84 | 85 | foreach (var item in subset) 86 | { 87 | var value = _options.TextSelector(item); 88 | 89 | screenBuffer.WriteLine(); 90 | 91 | if (_paginator.TryGetSelectedItem(out var selectedItem) && EqualityComparer.Default.Equals(item, selectedItem)) 92 | { 93 | screenBuffer.Write($"{Prompt.Symbols.Selector} {value}", Prompt.ColorSchema.Select); 94 | } 95 | else 96 | { 97 | screenBuffer.Write($" {value}"); 98 | } 99 | } 100 | 101 | if (_paginator.PageCount > 1) 102 | { 103 | screenBuffer.WriteLine(); 104 | screenBuffer.Write($"({_paginator.TotalCount} items, {_paginator.SelectedPage + 1}/{_paginator.PageCount} pages)"); 105 | } 106 | } 107 | 108 | protected override void FinishTemplate(OffscreenBuffer screenBuffer, T result) 109 | { 110 | screenBuffer.WriteFinish(_options.Message); 111 | screenBuffer.Write(_options.TextSelector(result), Prompt.ColorSchema.Answer); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Internal/OffscreenBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | using Sharprompt.Drivers; 6 | 7 | namespace Sharprompt.Internal 8 | { 9 | internal class OffscreenBuffer 10 | { 11 | public OffscreenBuffer(IConsoleDriver consoleDriver) 12 | { 13 | _consoleDriver = consoleDriver; 14 | 15 | _consoleDriver.RequestCancellation = RequestCancellation; 16 | } 17 | 18 | private readonly IConsoleDriver _consoleDriver; 19 | private readonly List> _outputBuffer = new List>(); 20 | 21 | private int _cursorLeft; 22 | private int _cursorTop; 23 | 24 | public int CursorBottom { get; set; } 25 | 26 | public int BufferWidth => _consoleDriver.BufferWidth; 27 | 28 | public int LineCount => _outputBuffer.Count + _outputBuffer.Sum(x => (x.Sum(xs => xs.Text.GetWidth()) - 1) / BufferWidth); 29 | 30 | public void Clear() 31 | { 32 | _outputBuffer.Clear(); 33 | _outputBuffer.Add(new List()); 34 | 35 | _cursorLeft = 0; 36 | _cursorTop = 0; 37 | } 38 | 39 | public void Write(string text) 40 | { 41 | _outputBuffer.Last().Add(new TextInfo(text, Console.ForegroundColor)); 42 | } 43 | 44 | public void Write(string text, ConsoleColor color) 45 | { 46 | _outputBuffer.Last().Add(new TextInfo(text, color)); 47 | } 48 | 49 | public void WriteLine() 50 | { 51 | _outputBuffer.Add(new List()); 52 | } 53 | 54 | public void WritePrompt(string message) 55 | { 56 | Write(Prompt.Symbols.Prompt, Prompt.ColorSchema.PromptSymbolColor); 57 | Write($" {message}: "); 58 | } 59 | 60 | public void WriteFinish(string message) 61 | { 62 | Write(Prompt.Symbols.Done, Prompt.ColorSchema.DoneSymbolColor); 63 | Write($" {message}: "); 64 | } 65 | 66 | public void WriteErrorMessage(string errorMessage) 67 | { 68 | WriteLine(); 69 | Write($"{Prompt.Symbols.Error} {errorMessage}", ConsoleColor.Red); 70 | } 71 | 72 | public (int left, int top) GetCursorPosition() 73 | { 74 | var left = _outputBuffer.Last().Sum(x => x.Text.GetWidth()) % BufferWidth; 75 | var top = LineCount - 1; 76 | 77 | return (left, top); 78 | } 79 | 80 | public void SetCursorPosition() 81 | { 82 | var (left, top) = GetCursorPosition(); 83 | 84 | SetCursorPosition(left, top); 85 | } 86 | 87 | public void SetCursorPosition(int left, int top) 88 | { 89 | _cursorLeft = left; 90 | _cursorTop = top; 91 | } 92 | 93 | public void RenderToConsole() 94 | { 95 | for (var i = 0; i < _outputBuffer.Count; i++) 96 | { 97 | var lineBuffer = _outputBuffer[i]; 98 | 99 | foreach (var textInfo in lineBuffer) 100 | { 101 | _consoleDriver.Write(textInfo.Text, textInfo.Color); 102 | } 103 | 104 | if (i < _outputBuffer.Count - 1) 105 | { 106 | _consoleDriver.WriteLine(); 107 | } 108 | } 109 | 110 | CursorBottom = _consoleDriver.CursorTop; 111 | 112 | _consoleDriver.SetCursorPosition(_cursorLeft, _consoleDriver.CursorTop - (LineCount - _cursorTop - 1)); 113 | } 114 | 115 | public void ClearConsole() 116 | { 117 | var bottom = CursorBottom; 118 | 119 | for (var i = 0; i < LineCount; i++) 120 | { 121 | _consoleDriver.ClearLine(bottom - i); 122 | } 123 | 124 | Clear(); 125 | } 126 | 127 | private void RequestCancellation() 128 | { 129 | _consoleDriver.SetCursorPosition(0, CursorBottom); 130 | _consoleDriver.Reset(); 131 | 132 | Environment.Exit(1); 133 | } 134 | 135 | private class TextInfo 136 | { 137 | public TextInfo(string text, ConsoleColor color) 138 | { 139 | Text = text; 140 | Color = color; 141 | } 142 | 143 | public string Text { get; } 144 | public ConsoleColor Color { get; } 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Prompt.AutoForms.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Reflection; 6 | 7 | using Sharprompt.Internal; 8 | 9 | namespace Sharprompt 10 | { 11 | public static partial class Prompt 12 | { 13 | public static T AutoForms() where T : new() 14 | { 15 | var model = new T(); 16 | 17 | StartForms(model); 18 | 19 | return model; 20 | } 21 | 22 | public static T AutoForms(T model) 23 | { 24 | StartForms(model); 25 | 26 | return model; 27 | } 28 | 29 | private static void StartForms(T model) 30 | { 31 | var propertyMetadatas = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance) 32 | .Select(x => new PropertyMetadata(x)) 33 | .OrderBy(x => x.Order) 34 | .ToArray(); 35 | 36 | foreach (var propertyMetadata in propertyMetadatas) 37 | { 38 | var propertyInfo = propertyMetadata.PropertyInfo; 39 | var validators = propertyMetadata.Validations.Select(x => new ValidationAttributeAdapter(x).GetValidator(propertyInfo.Name, model)).ToArray(); 40 | 41 | var defaultValue = propertyInfo.GetValue(model); 42 | 43 | if (propertyMetadata.DataType == DataType.Password) 44 | { 45 | propertyInfo.SetValue(model, Password(propertyMetadata.Prompt, validators)); 46 | } 47 | else if (propertyMetadata.PropertyType == typeof(bool)) 48 | { 49 | propertyInfo.SetValue(model, Confirm(propertyMetadata.Prompt, (bool?)defaultValue)); 50 | } 51 | else if (propertyMetadata.PropertyType.IsEnum) 52 | { 53 | var method = _selectMethod.MakeGenericMethod(propertyMetadata.PropertyType); 54 | 55 | propertyInfo.SetValue(model, InvokeMethod(method, propertyMetadata.Prompt, null, defaultValue)); 56 | } 57 | else if (propertyMetadata.IsCollection && propertyMetadata.PropertyType.GetGenericArguments()[0].IsEnum) 58 | { 59 | var method = _multiSelectMethod.MakeGenericMethod(propertyMetadata.PropertyType.GetGenericArguments()[0]); 60 | 61 | propertyInfo.SetValue(model, InvokeMethod(method, propertyMetadata.Prompt, null, 1, -1, defaultValue)); 62 | } 63 | else 64 | { 65 | var method = _inputMethod.MakeGenericMethod(propertyMetadata.PropertyType); 66 | 67 | propertyInfo.SetValue(model, InvokeMethod(method, propertyMetadata.Prompt, defaultValue, validators)); 68 | } 69 | } 70 | } 71 | 72 | private static object InvokeMethod(MethodInfo methodInfo, params object[] parameters) 73 | { 74 | return methodInfo.Invoke(null, parameters); 75 | } 76 | 77 | private class PropertyMetadata 78 | { 79 | public PropertyMetadata(PropertyInfo propertyInfo) 80 | { 81 | var displayAttribute = propertyInfo.GetCustomAttribute(); 82 | var dataTypeAttribute = propertyInfo.GetCustomAttribute(); 83 | 84 | PropertyInfo = propertyInfo; 85 | PropertyType = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType; 86 | DataType = dataTypeAttribute?.DataType; 87 | IsCollection = propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>); 88 | Prompt = displayAttribute?.GetPrompt(); 89 | Order = displayAttribute?.GetOrder(); 90 | Validations = propertyInfo.GetCustomAttributes(true); 91 | } 92 | 93 | public PropertyInfo PropertyInfo { get; } 94 | public Type PropertyType { get; } 95 | public DataType? DataType { get; } 96 | public bool IsCollection { get; } 97 | public string Prompt { get; } 98 | public int? Order { get; } 99 | public IEnumerable Validations { get; } 100 | } 101 | 102 | private static readonly MethodInfo _inputMethod = typeof(Prompt).GetMethods().First(x => x.Name == nameof(Input) && x.GetParameters().Length == 3); 103 | private static readonly MethodInfo _selectMethod = typeof(Prompt).GetMethods().First(x => x.Name == nameof(Select) && x.GetParameters().Length == 3); 104 | private static readonly MethodInfo _multiSelectMethod = typeof(Prompt).GetMethods().First(x => x.Name == nameof(MultiSelect) && x.GetParameters().Length == 5); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /JITK/JITK.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {EC28F37B-89C4-42AA-97CD-AFDCE7A7A818} 8 | Exe 9 | JITK 10 | JITK 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | true 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | true 36 | 37 | 38 | 39 | False 40 | ..\Dis2Msil\Dis2Msil\bin\Debug\Dis2Msil.dll 41 | 42 | 43 | ..\packages\dnlib.3.3.3\lib\net45\dnlib.dll 44 | 45 | 46 | False 47 | ..\Sharprompt-2.3.0\Sharprompt\bin\Debug\netstandard2.0\Sharprompt.dll 48 | 49 | 50 | 51 | ..\packages\System.ComponentModel.Annotations.4.7.0\lib\net461\System.ComponentModel.Annotations.dll 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Forms/ConfirmForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using Sharprompt.Internal; 7 | 8 | namespace Sharprompt.Forms 9 | { 10 | internal class ConfirmForm : FormBase 11 | { 12 | public ConfirmForm(ConfirmOptions options) 13 | { 14 | _options = options; 15 | } 16 | 17 | private readonly ConfirmOptions _options; 18 | 19 | private int _startIndex; 20 | private readonly StringBuilder _inputBuffer = new StringBuilder(); 21 | 22 | protected override bool TryGetResult(out bool result) 23 | { 24 | do 25 | { 26 | var keyInfo = ConsoleDriver.ReadKey(); 27 | 28 | switch (keyInfo.Key) 29 | { 30 | case ConsoleKey.Enter: 31 | { 32 | var input = _inputBuffer.ToString(); 33 | 34 | if (string.IsNullOrEmpty(input)) 35 | { 36 | if (_options.DefaultValue != null) 37 | { 38 | result = _options.DefaultValue.Value; 39 | 40 | return true; 41 | } 42 | 43 | SetValidationResult(new ValidationResult("Value is required")); 44 | } 45 | else 46 | { 47 | var lowerInput = input.ToLower(); 48 | 49 | if (lowerInput == "y" || lowerInput == "yes") 50 | { 51 | result = true; 52 | 53 | return true; 54 | } 55 | 56 | if (lowerInput == "n" || lowerInput == "no") 57 | { 58 | result = false; 59 | 60 | return true; 61 | } 62 | 63 | SetValidationResult(new ValidationResult("Value is invalid")); 64 | } 65 | 66 | break; 67 | } 68 | case ConsoleKey.LeftArrow when _startIndex > 0: 69 | _startIndex -= 1; 70 | break; 71 | case ConsoleKey.RightArrow when _startIndex < _inputBuffer.Length: 72 | _startIndex += 1; 73 | break; 74 | case ConsoleKey.Backspace when _startIndex > 0: 75 | _startIndex -= 1; 76 | 77 | _inputBuffer.Remove(_startIndex, 1); 78 | break; 79 | case ConsoleKey.Delete when _startIndex < _inputBuffer.Length: 80 | _inputBuffer.Remove(_startIndex, 1); 81 | break; 82 | case ConsoleKey.LeftArrow: 83 | case ConsoleKey.RightArrow: 84 | case ConsoleKey.Backspace: 85 | case ConsoleKey.Delete: 86 | ConsoleDriver.Beep(); 87 | break; 88 | default: 89 | { 90 | if (!char.IsControl(keyInfo.KeyChar)) 91 | { 92 | _inputBuffer.Insert(_startIndex, keyInfo.KeyChar); 93 | 94 | _startIndex += 1; 95 | } 96 | 97 | break; 98 | } 99 | } 100 | 101 | } while (ConsoleDriver.KeyAvailable); 102 | 103 | result = default; 104 | 105 | return false; 106 | } 107 | 108 | protected override void InputTemplate(OffscreenBuffer screenBuffer) 109 | { 110 | screenBuffer.WritePrompt(_options.Message); 111 | 112 | if (_options.DefaultValue == null) 113 | { 114 | screenBuffer.Write("(y/n) "); 115 | } 116 | else if (_options.DefaultValue.Value) 117 | { 118 | screenBuffer.Write("(Y/n) "); 119 | } 120 | else 121 | { 122 | screenBuffer.Write("(y/N) "); 123 | } 124 | 125 | var (left, top) = screenBuffer.GetCursorPosition(); 126 | 127 | var input = _inputBuffer.ToString(); 128 | 129 | screenBuffer.Write(input); 130 | 131 | var width = left + input.Take(_startIndex).GetWidth(); 132 | 133 | screenBuffer.SetCursorPosition(width % screenBuffer.BufferWidth, top + (width / screenBuffer.BufferWidth)); 134 | } 135 | 136 | protected override void FinishTemplate(OffscreenBuffer screenBuffer, bool result) 137 | { 138 | screenBuffer.WriteFinish(_options.Message); 139 | screenBuffer.Write(result ? "Yes" : "No", Prompt.ColorSchema.Answer); 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Forms/InputForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using Sharprompt.Internal; 7 | 8 | namespace Sharprompt.Forms 9 | { 10 | internal class InputForm : FormBase 11 | { 12 | public InputForm(InputOptions options) 13 | { 14 | _defaultValue = Optional.Create(options.DefaultValue); 15 | 16 | _options = options; 17 | } 18 | 19 | private readonly InputOptions _options; 20 | private readonly Optional _defaultValue; 21 | 22 | private readonly Type _targetType = typeof(T); 23 | private readonly Type _underlyingType = Nullable.GetUnderlyingType(typeof(T)); 24 | 25 | private int _startIndex; 26 | private readonly StringBuilder _inputBuffer = new StringBuilder(); 27 | 28 | protected override bool TryGetResult(out T result) 29 | { 30 | do 31 | { 32 | var keyInfo = ConsoleDriver.ReadKey(); 33 | 34 | switch (keyInfo.Key) 35 | { 36 | case ConsoleKey.Enter: 37 | { 38 | var input = _inputBuffer.ToString(); 39 | 40 | try 41 | { 42 | if (string.IsNullOrEmpty(input)) 43 | { 44 | if (_targetType.IsValueType && _underlyingType == null && !_defaultValue.HasValue) 45 | { 46 | SetValidationResult(new ValidationResult("Value is required")); 47 | 48 | result = default; 49 | 50 | return false; 51 | } 52 | 53 | result = _defaultValue; 54 | } 55 | else 56 | { 57 | result = (T)Convert.ChangeType(input, _underlyingType ?? _targetType); 58 | } 59 | 60 | if (!TryValidate(result, _options.Validators)) 61 | { 62 | result = default; 63 | 64 | return false; 65 | } 66 | 67 | return true; 68 | } 69 | catch (Exception ex) 70 | { 71 | SetException(ex); 72 | } 73 | 74 | break; 75 | } 76 | case ConsoleKey.LeftArrow when _startIndex > 0: 77 | _startIndex -= 1; 78 | break; 79 | case ConsoleKey.RightArrow when _startIndex < _inputBuffer.Length: 80 | _startIndex += 1; 81 | break; 82 | case ConsoleKey.Backspace when _startIndex > 0: 83 | _startIndex -= 1; 84 | 85 | _inputBuffer.Remove(_startIndex, 1); 86 | break; 87 | case ConsoleKey.Delete when _startIndex < _inputBuffer.Length: 88 | _inputBuffer.Remove(_startIndex, 1); 89 | break; 90 | case ConsoleKey.LeftArrow: 91 | case ConsoleKey.RightArrow: 92 | case ConsoleKey.Backspace: 93 | case ConsoleKey.Delete: 94 | ConsoleDriver.Beep(); 95 | break; 96 | default: 97 | { 98 | if (!char.IsControl(keyInfo.KeyChar)) 99 | { 100 | _inputBuffer.Insert(_startIndex, keyInfo.KeyChar); 101 | 102 | _startIndex += 1; 103 | } 104 | 105 | break; 106 | } 107 | } 108 | 109 | } while (ConsoleDriver.KeyAvailable); 110 | 111 | result = default; 112 | 113 | return false; 114 | } 115 | 116 | protected override void InputTemplate(OffscreenBuffer screenBuffer) 117 | { 118 | screenBuffer.WritePrompt(_options.Message); 119 | 120 | if (_defaultValue.HasValue) 121 | { 122 | screenBuffer.Write($"({_defaultValue.Value}) "); 123 | } 124 | 125 | var (left, top) = screenBuffer.GetCursorPosition(); 126 | 127 | var input = _inputBuffer.ToString(); 128 | 129 | screenBuffer.Write(input); 130 | 131 | var width = left + input.Take(_startIndex).GetWidth(); 132 | 133 | screenBuffer.SetCursorPosition(width % screenBuffer.BufferWidth, top + (width / screenBuffer.BufferWidth)); 134 | } 135 | 136 | protected override void FinishTemplate(OffscreenBuffer screenBuffer, T result) 137 | { 138 | screenBuffer.WriteFinish(_options.Message); 139 | 140 | if (result != null) 141 | { 142 | screenBuffer.Write(result.ToString(), Prompt.ColorSchema.Answer); 143 | } 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil/ILInstruction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection.Emit; 3 | 4 | namespace Dis2Msil 5 | { 6 | //https://www.codeproject.com/Articles/14058/Parsing-the-IL-of-a-Method-Body 7 | public class ILInstruction 8 | { 9 | // Fields 10 | private OpCode code; 11 | private object operand; 12 | private byte[] operandData; 13 | private int offset; 14 | 15 | // Properties 16 | public OpCode Code 17 | { 18 | get { return code; } 19 | set { code = value; } 20 | } 21 | 22 | public object Operand 23 | { 24 | get { return operand; } 25 | set { operand = value; } 26 | } 27 | 28 | public byte[] OperandData 29 | { 30 | get { return operandData; } 31 | set { operandData = value; } 32 | } 33 | 34 | public int Offset 35 | { 36 | get { return offset; } 37 | set { offset = value; } 38 | } 39 | 40 | /// 41 | /// Returns a friendly strign representation of this instruction 42 | /// 43 | /// 44 | public string GetCode() 45 | { 46 | string result = ""; 47 | result += GetExpandedOffset(offset) + " : " + code; 48 | if (operand != null) 49 | { 50 | switch (code.OperandType) 51 | { 52 | case OperandType.InlineField: 53 | System.Reflection.FieldInfo fOperand = ((System.Reflection.FieldInfo)operand); 54 | result += " " + Globals.ProcessSpecialTypes(fOperand.FieldType.ToString()) + " " + 55 | Globals.ProcessSpecialTypes(fOperand.ReflectedType.ToString()) + 56 | "::" + fOperand.Name + ""; 57 | break; 58 | case OperandType.InlineMethod: 59 | try 60 | { 61 | System.Reflection.MethodInfo mOperand = (System.Reflection.MethodInfo)operand; 62 | result += " "; 63 | if (!mOperand.IsStatic) result += "instance "; 64 | 65 | result += Globals.ProcessSpecialTypes(mOperand.ReturnType.ToString()) + 66 | " " + Globals.ProcessSpecialTypes(mOperand.ReflectedType.ToString()) + 67 | "::" + mOperand.Name + "()"; 68 | 69 | } 70 | catch 71 | { 72 | try 73 | { 74 | System.Reflection.ConstructorInfo mOperand = (System.Reflection.ConstructorInfo)operand; 75 | result += " "; 76 | if (!mOperand.IsStatic) result += "instance "; 77 | result += "void " + 78 | Globals.ProcessSpecialTypes(mOperand.ReflectedType.ToString()) + 79 | "::" + mOperand.Name + "()"; 80 | } 81 | catch 82 | { 83 | } 84 | } 85 | break; 86 | case OperandType.ShortInlineBrTarget: 87 | case OperandType.InlineBrTarget: 88 | result += " " + GetExpandedOffset((int)operand); 89 | break; 90 | case OperandType.InlineType: 91 | result += " " + Globals.ProcessSpecialTypes(operand.ToString()); 92 | break; 93 | case OperandType.InlineString: 94 | if (operand.ToString() == "\r\n") result += " \"\\r\\n\""; 95 | else result += " \"" + operand.ToString() + "\""; 96 | break; 97 | case OperandType.ShortInlineVar: 98 | result += operand.ToString(); 99 | break; 100 | case OperandType.InlineI: 101 | case OperandType.InlineI8: 102 | case OperandType.InlineR: 103 | case OperandType.ShortInlineI: 104 | case OperandType.ShortInlineR: 105 | result += operand.ToString(); 106 | break; 107 | case OperandType.InlineTok: 108 | if (operand is Type) 109 | result += ((Type)operand).FullName; 110 | else 111 | result += "not supported"; 112 | break; 113 | 114 | default: result += "not supported"; break; 115 | } 116 | } 117 | return result; 118 | 119 | } 120 | 121 | /// 122 | /// Add enough zeros to a number as to be represented on 4 characters 123 | /// 124 | /// 125 | /// The number that must be represented on 4 characters 126 | /// 127 | /// 128 | /// 129 | private string GetExpandedOffset(long offset) 130 | { 131 | string result = offset.ToString(); 132 | for (int i = 0; result.Length < 4; i++) 133 | { 134 | result = "0" + result; 135 | } 136 | return result; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Forms/ListForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | using Sharprompt.Internal; 8 | 9 | namespace Sharprompt.Forms 10 | { 11 | internal class ListForm : FormBase> 12 | { 13 | public ListForm(ListOptions options) 14 | { 15 | if (options.Minimum < 0) 16 | { 17 | throw new ArgumentOutOfRangeException(nameof(options.Minimum), $"The minimum ({options.Minimum}) is not valid"); 18 | } 19 | 20 | if (options.Maximum < options.Minimum) 21 | { 22 | throw new ArgumentException($"The maximum ({options.Maximum}) is not valid when minimum is set to ({options.Minimum})", nameof(options.Maximum)); 23 | } 24 | 25 | _options = options; 26 | 27 | _inputItems.AddRange(options.DefaultValues ?? Enumerable.Empty()); 28 | } 29 | 30 | private readonly ListOptions _options; 31 | 32 | private readonly Type _targetType = typeof(T); 33 | private readonly Type _underlyingType = Nullable.GetUnderlyingType(typeof(T)); 34 | 35 | private int _startIndex; 36 | private readonly StringBuilder _inputBuffer = new StringBuilder(); 37 | private readonly List _inputItems = new List(); 38 | 39 | protected override bool TryGetResult(out IEnumerable result) 40 | { 41 | do 42 | { 43 | var keyInfo = ConsoleDriver.ReadKey(); 44 | 45 | switch (keyInfo.Key) 46 | { 47 | case ConsoleKey.Enter: 48 | { 49 | var input = _inputBuffer.ToString(); 50 | 51 | try 52 | { 53 | result = _inputItems; 54 | 55 | if (string.IsNullOrEmpty(input)) 56 | { 57 | if (_inputItems.Count >= _options.Minimum) 58 | { 59 | return true; 60 | } 61 | 62 | SetValidationResult(new ValidationResult($"A minimum input of {_options.Minimum} items is required")); 63 | 64 | return false; 65 | } 66 | 67 | if (_inputItems.Count >= _options.Maximum) 68 | { 69 | SetValidationResult(new ValidationResult($"A maximum input of {_options.Maximum} items is required")); 70 | 71 | return false; 72 | } 73 | 74 | var inputValue = (T)Convert.ChangeType(input, _underlyingType ?? _targetType); 75 | 76 | if (!TryValidate(inputValue, _options.Validators)) 77 | { 78 | return false; 79 | } 80 | 81 | _startIndex = 0; 82 | _inputBuffer.Clear(); 83 | 84 | _inputItems.Add(inputValue); 85 | 86 | return false; 87 | } 88 | catch (Exception ex) 89 | { 90 | SetException(ex); 91 | } 92 | 93 | break; 94 | } 95 | case ConsoleKey.LeftArrow when _startIndex > 0: 96 | _startIndex -= 1; 97 | break; 98 | case ConsoleKey.RightArrow when _startIndex < _inputBuffer.Length: 99 | _startIndex += 1; 100 | break; 101 | case ConsoleKey.Backspace when _startIndex > 0: 102 | _startIndex -= 1; 103 | 104 | _inputBuffer.Remove(_startIndex, 1); 105 | break; 106 | case ConsoleKey.Delete when _startIndex < _inputBuffer.Length: 107 | _inputBuffer.Remove(_startIndex, 1); 108 | break; 109 | case ConsoleKey.LeftArrow: 110 | case ConsoleKey.RightArrow: 111 | case ConsoleKey.Backspace: 112 | case ConsoleKey.Delete: 113 | ConsoleDriver.Beep(); 114 | break; 115 | default: 116 | { 117 | if (!char.IsControl(keyInfo.KeyChar)) 118 | { 119 | _inputBuffer.Insert(_startIndex, keyInfo.KeyChar); 120 | 121 | _startIndex += 1; 122 | } 123 | 124 | break; 125 | } 126 | } 127 | 128 | } while (ConsoleDriver.KeyAvailable); 129 | 130 | result = null; 131 | 132 | return false; 133 | } 134 | 135 | protected override void InputTemplate(OffscreenBuffer screenBuffer) 136 | { 137 | screenBuffer.WritePrompt(_options.Message); 138 | 139 | var (left, top) = screenBuffer.GetCursorPosition(); 140 | 141 | var input = _inputBuffer.ToString(); 142 | 143 | screenBuffer.Write(input); 144 | 145 | foreach (var inputItem in _inputItems) 146 | { 147 | screenBuffer.WriteLine(); 148 | screenBuffer.Write($" {inputItem}"); 149 | } 150 | 151 | var width = left + input.Take(_startIndex).GetWidth(); 152 | 153 | screenBuffer.SetCursorPosition(width % screenBuffer.BufferWidth, top + (width / screenBuffer.BufferWidth)); 154 | } 155 | 156 | protected override void FinishTemplate(OffscreenBuffer screenBuffer, IEnumerable result) 157 | { 158 | screenBuffer.WriteFinish(_options.Message); 159 | screenBuffer.Write(string.Join(", ", result), Prompt.ColorSchema.Answer); 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Forms/MultiSelectForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | using Sharprompt.Internal; 8 | 9 | namespace Sharprompt.Forms 10 | { 11 | internal class MultiSelectForm : FormBase> 12 | { 13 | public MultiSelectForm(MultiSelectOptions options) 14 | : base(false) 15 | { 16 | if (options.Minimum < 0) 17 | { 18 | throw new ArgumentOutOfRangeException(nameof(options.Minimum), $"The minimum ({options.Minimum}) is not valid"); 19 | } 20 | 21 | if (options.Maximum < options.Minimum) 22 | { 23 | throw new ArgumentException($"The maximum ({options.Maximum}) is not valid when minimum is set to ({options.Minimum})", nameof(options.Maximum)); 24 | } 25 | 26 | _paginator = new Paginator(options.Items, options.PageSize, Optional.Empty, options.TextSelector); 27 | 28 | if (options.DefaultValues != null) 29 | { 30 | _selectedItems.AddRange(options.DefaultValues); 31 | } 32 | 33 | _options = options; 34 | } 35 | 36 | private readonly MultiSelectOptions _options; 37 | private readonly Paginator _paginator; 38 | 39 | private readonly List _selectedItems = new List(); 40 | private readonly StringBuilder _filterBuffer = new StringBuilder(); 41 | 42 | protected override bool TryGetResult(out IEnumerable result) 43 | { 44 | do 45 | { 46 | var keyInfo = ConsoleDriver.ReadKey(); 47 | 48 | switch (keyInfo.Key) 49 | { 50 | case ConsoleKey.Enter when _selectedItems.Count >= _options.Minimum: 51 | result = _selectedItems; 52 | return true; 53 | case ConsoleKey.Enter: 54 | SetValidationResult(new ValidationResult($"A minimum selection of {_options.Minimum} items is required")); 55 | break; 56 | case ConsoleKey.Spacebar when _paginator.TryGetSelectedItem(out var currentItem): 57 | { 58 | if (_selectedItems.Contains(currentItem)) 59 | { 60 | _selectedItems.Remove(currentItem); 61 | } 62 | else 63 | { 64 | if (_selectedItems.Count >= _options.Maximum) 65 | { 66 | SetValidationResult(new ValidationResult($"A maximum selection of {_options.Maximum} items is required")); 67 | } 68 | else 69 | { 70 | _selectedItems.Add(currentItem); 71 | } 72 | } 73 | 74 | break; 75 | } 76 | case ConsoleKey.UpArrow: 77 | _paginator.PreviousItem(); 78 | break; 79 | case ConsoleKey.DownArrow: 80 | _paginator.NextItem(); 81 | break; 82 | case ConsoleKey.LeftArrow: 83 | _paginator.PreviousPage(); 84 | break; 85 | case ConsoleKey.RightArrow: 86 | _paginator.NextPage(); 87 | break; 88 | case ConsoleKey.Backspace when _filterBuffer.Length == 0: 89 | ConsoleDriver.Beep(); 90 | break; 91 | case ConsoleKey.Backspace: 92 | _filterBuffer.Length -= 1; 93 | 94 | _paginator.UpdateFilter(_filterBuffer.ToString()); 95 | break; 96 | default: 97 | { 98 | if (!char.IsControl(keyInfo.KeyChar)) 99 | { 100 | _filterBuffer.Append(keyInfo.KeyChar); 101 | 102 | _paginator.UpdateFilter(_filterBuffer.ToString()); 103 | } 104 | 105 | break; 106 | } 107 | } 108 | 109 | } while (ConsoleDriver.KeyAvailable); 110 | 111 | result = null; 112 | 113 | return false; 114 | } 115 | 116 | protected override void InputTemplate(OffscreenBuffer screenBuffer) 117 | { 118 | screenBuffer.WritePrompt(_options.Message); 119 | screenBuffer.Write(_paginator.FilterTerm); 120 | 121 | if (string.IsNullOrEmpty(_paginator.FilterTerm)) 122 | { 123 | screenBuffer.Write(" Hit space to select", Prompt.ColorSchema.Answer); 124 | } 125 | 126 | var subset = _paginator.ToSubset(); 127 | 128 | foreach (var item in subset) 129 | { 130 | var value = _options.TextSelector(item); 131 | 132 | screenBuffer.WriteLine(); 133 | 134 | if (_paginator.TryGetSelectedItem(out var selectedItem) && EqualityComparer.Default.Equals(item, selectedItem)) 135 | { 136 | if (_selectedItems.Contains(item)) 137 | { 138 | screenBuffer.Write($"{Prompt.Symbols.Selector} {Prompt.Symbols.Selected} {value}", Prompt.ColorSchema.Select); 139 | } 140 | else 141 | { 142 | screenBuffer.Write($"{Prompt.Symbols.Selector} {Prompt.Symbols.NotSelect} {value}", Prompt.ColorSchema.Select); 143 | } 144 | } 145 | else 146 | { 147 | if (_selectedItems.Contains(item)) 148 | { 149 | screenBuffer.Write($" {Prompt.Symbols.Selected} {value}", Prompt.ColorSchema.Select); 150 | } 151 | else 152 | { 153 | screenBuffer.Write($" {Prompt.Symbols.NotSelect} {value}"); 154 | } 155 | } 156 | } 157 | 158 | if (_paginator.PageCount > 1) 159 | { 160 | screenBuffer.WriteLine(); 161 | screenBuffer.Write($"({_paginator.TotalCount} items, {_paginator.SelectedPage + 1}/{_paginator.PageCount} pages)"); 162 | } 163 | } 164 | 165 | protected override void FinishTemplate(OffscreenBuffer screenBuffer, IEnumerable result) 166 | { 167 | screenBuffer.WriteFinish(_options.Message); 168 | screenBuffer.Write(string.Join(", ", result.Select(_options.TextSelector)), Prompt.ColorSchema.Answer); 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /JITK/Core/Command/CommandEngine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace JITK.Core.Command 5 | { 6 | static class CommandEngine 7 | { 8 | 9 | /* 10 | * Command Syntax : 11 | * OPCODE OPERAND|NONE 12 | * 13 | * ~ NONE Operand Example: 14 | * INFOA|infoa -> Info Assembly Command 15 | * QUIT|quit -> Exit JITK. 16 | * lm -> List All Module 17 | * 18 | * ~ OPCODE with Example: 19 | * f %s -> Assign File Path 20 | * .... 21 | */ 22 | 23 | 24 | public static Dictionary commands = new Dictionary(); 25 | public static int CommandCount; 26 | public static List arg = new List(); 27 | 28 | public static void LoadCommands() 29 | { 30 | Command[] commandTypes = { 31 | new Quit(), 32 | new InfoA(), 33 | new Clear(), 34 | new About(), 35 | new Help(), 36 | new InfoF(), 37 | new FileClear(), 38 | new FileAssign(), 39 | new FileArgument(), 40 | new Continue(), 41 | new StepFuncG(), 42 | new DefBreakPoint(), 43 | new ListBreakpoint(), 44 | new Disas(), 45 | new DisasH() 46 | }; 47 | 48 | for (CommandCount = 0; CommandCount < commandTypes.Length; CommandCount++) 49 | { 50 | commands.Add(commandTypes[CommandCount].Name, commandTypes[CommandCount]); 51 | } 52 | 53 | Style.WriteFormatted($"[^] Loaded {CommandCount} command!\n"); 54 | } 55 | 56 | public static bool MainRoutine() 57 | { 58 | while (true) 59 | { 60 | string input = Style.WriteState(">"); 61 | ExecuteCommand(input); 62 | } 63 | 64 | } 65 | 66 | public static unsafe bool ExecuteCommand(string commandText) 67 | { 68 | 69 | if (commandText == null || commandText.Trim().Length == 0) 70 | { 71 | Style.WriteFormatted("[!] Type a command!", ConsoleColor.Red); 72 | return false; 73 | } 74 | 75 | string[] splittedText = commandText.Trim().Split(' '); 76 | if (commands.ContainsKey(splittedText[0])) 77 | { 78 | var selectedCommand = commands[splittedText[0]]; 79 | switch (selectedCommand.ArgSize) 80 | { 81 | case ArgumentSize.None: 82 | { 83 | if (splittedText.Length > 1 || splittedText.Length < 1) 84 | { 85 | Style.WriteFormatted("[!] Wrong argument size.", ConsoleColor.Red); 86 | return false; 87 | } 88 | 89 | 90 | if (Context._jitHook != null) 91 | { 92 | Context._jitHook.UnHook(); 93 | selectedCommand.Action(); 94 | Context._jitHook.Hook(Context.HookedCompileMethod); 95 | } 96 | else 97 | { 98 | selectedCommand.Action(); 99 | } 100 | break; 101 | } 102 | case ArgumentSize.Single: 103 | { 104 | if (splittedText.Length > 2 || splittedText.Length < 2) 105 | { 106 | Style.WriteFormatted("[!] Wrong argument size.\n", ConsoleColor.Red); 107 | return false; 108 | } 109 | 110 | arg.Add(splittedText[1]); 111 | 112 | if (Context._jitHook != null) 113 | { 114 | Context._jitHook.UnHook(); 115 | selectedCommand.Action(); 116 | Context._jitHook.Hook(Context.HookedCompileMethod); 117 | } 118 | else 119 | { 120 | selectedCommand.Action(); 121 | } 122 | 123 | arg.Clear(); 124 | break; 125 | } 126 | case ArgumentSize.Opt: 127 | { 128 | for (int i = 1; i < splittedText.Length; i++) 129 | { 130 | arg.Add(splittedText[i]); 131 | } 132 | 133 | if (Context._jitHook != null) 134 | { 135 | Context._jitHook.UnHook(); 136 | selectedCommand.Action(); 137 | Context._jitHook.Hook(Context.HookedCompileMethod); 138 | } 139 | else 140 | { 141 | selectedCommand.Action(); 142 | } 143 | 144 | arg.Clear(); 145 | break; 146 | } 147 | case ArgumentSize.Poly: 148 | { 149 | if (splittedText.Length < 1) 150 | { 151 | Style.WriteFormatted("[!] Wrong argument size.\n", ConsoleColor.Red); 152 | return false; 153 | } 154 | 155 | for (int i = 1; i < splittedText.Length; i++) 156 | { 157 | arg.Add(splittedText[i]); 158 | } 159 | 160 | if (Context._jitHook != null) 161 | { 162 | Context._jitHook.UnHook(); 163 | selectedCommand.Action(); 164 | Context._jitHook.Hook(Context.HookedCompileMethod); 165 | } 166 | else 167 | { 168 | selectedCommand.Action(); 169 | } 170 | 171 | arg.Clear(); 172 | break; 173 | } 174 | } 175 | } 176 | else 177 | { 178 | Style.WriteFormatted("[!] Type a valid command!\n", ConsoleColor.Red); 179 | } 180 | return true; 181 | } 182 | 183 | 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /JITK/Core/SJITHook/Data.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace JITK.Core.SJITHook 5 | { 6 | public static class Data 7 | { 8 | internal enum Protection 9 | { 10 | PAGE_NOACCESS = 0x01, 11 | PAGE_READONLY = 0x02, 12 | PAGE_READWRITE = 0x04, 13 | PAGE_WRITECOPY = 0x08, 14 | PAGE_EXECUTE = 0x10, 15 | PAGE_EXECUTE_READ = 0x20, 16 | PAGE_EXECUTE_READWRITE = 0x40, 17 | PAGE_EXECUTE_WRITECOPY = 0x80, 18 | PAGE_GUARD = 0x100, 19 | PAGE_NOCACHE = 0x200, 20 | PAGE_WRITECOMBINE = 0x400 21 | } 22 | [DllImport("kernel32.dll", SetLastError = true)] 23 | internal static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, 24 | Protection flNewProtect, out uint lpflOldProtect); 25 | 26 | public enum CorJitFlag 27 | { 28 | CORJIT_FLG_SPEED_OPT = 0x00000001, 29 | CORJIT_FLG_SIZE_OPT = 0x00000002, 30 | CORJIT_FLG_DEBUG_CODE = 0x00000004, // generate "debuggable" code (no code-mangling optimizations) 31 | CORJIT_FLG_DEBUG_EnC = 0x00000008, // We are in Edit-n-Continue mode 32 | CORJIT_FLG_DEBUG_INFO = 0x00000010, // generate line and local-var info 33 | CORJIT_FLG_LOOSE_EXCEPT_ORDER = 0x00000020, // loose exception order 34 | CORJIT_FLG_TARGET_PENTIUM = 0x00000100, 35 | CORJIT_FLG_TARGET_PPRO = 0x00000200, 36 | CORJIT_FLG_TARGET_P4 = 0x00000400, 37 | CORJIT_FLG_TARGET_BANIAS = 0x00000800, 38 | CORJIT_FLG_USE_FCOMI = 0x00001000, // Generated code may use fcomi(p) instruction 39 | CORJIT_FLG_USE_CMOV = 0x00002000, // Generated code may use cmov instruction 40 | CORJIT_FLG_USE_SSE2 = 0x00004000, // Generated code may use SSE-2 instructions 41 | CORJIT_FLG_PROF_CALLRET = 0x00010000, // Wrap method calls with probes 42 | CORJIT_FLG_PROF_ENTERLEAVE = 0x00020000, // Instrument prologues/epilogues 43 | CORJIT_FLG_PROF_INPROC_ACTIVE_DEPRECATED = 0x00040000, 44 | // Inprocess debugging active requires different instrumentation 45 | CORJIT_FLG_PROF_NO_PINVOKE_INLINE = 0x00080000, // Disables PInvoke inlining 46 | CORJIT_FLG_SKIP_VERIFICATION = 0x00100000, 47 | // (lazy) skip verification - determined without doing a full resolve. See comment below 48 | CORJIT_FLG_PREJIT = 0x00200000, // jit or prejit is the execution engine. 49 | CORJIT_FLG_RELOC = 0x00400000, // Generate relocatable code 50 | CORJIT_FLG_IMPORT_ONLY = 0x00800000, // Only import the function 51 | CORJIT_FLG_IL_STUB = 0x01000000, // method is an IL stub 52 | CORJIT_FLG_PROCSPLIT = 0x02000000, // JIT should separate code into hot and cold sections 53 | CORJIT_FLG_BBINSTR = 0x04000000, // Collect basic block profile information 54 | CORJIT_FLG_BBOPT = 0x08000000, // Optimize method based on profile information 55 | CORJIT_FLG_FRAMED = 0x10000000, // All methods have an EBP frame 56 | CORJIT_FLG_ALIGN_LOOPS = 0x20000000, // add NOPs before loops to align them at 16 byte boundaries 57 | CORJIT_FLG_PUBLISH_SECRET_PARAM = 0x40000000, 58 | // JIT must place stub secret param into local 0. (used by IL stubs) 59 | }; 60 | 61 | public enum CorInfoCallConv 62 | { 63 | C = 1, 64 | DEFAULT = 0, 65 | EXPLICITTHIS = 64, 66 | FASTCALL = 4, 67 | FIELD = 6, 68 | GENERIC = 16, 69 | HASTHIS = 32, 70 | LOCAL_SIG = 7, 71 | MASK = 15, 72 | NATIVEVARARG = 11, 73 | PARAMTYPE = 128, 74 | PROPERTY = 8, 75 | STDCALL = 2, 76 | THISCALL = 3, 77 | VARARG = 5 78 | } 79 | public enum CorInfoType : byte 80 | { 81 | BOOL = 2, 82 | BYREF = 18, 83 | BYTE = 4, 84 | CHAR = 3, 85 | CLASS = 20, 86 | COUNT = 23, 87 | DOUBLE = 15, 88 | FLOAT = 14, 89 | INT = 8, 90 | LONG = 10, 91 | NATIVEINT = 12, 92 | NATIVEUINT = 13, 93 | PTR = 17, 94 | REFANY = 21, 95 | SHORT = 6, 96 | STRING = 16, 97 | UBYTE = 5, 98 | UINT = 9, 99 | ULONG = 11, 100 | UNDEF = 0, 101 | USHORT = 7, 102 | VALUECLASS = 19, 103 | VAR = 22, 104 | VOID = 1 105 | } 106 | [StructLayout(LayoutKind.Sequential)] 107 | public struct CorinfoSigInst 108 | { 109 | public uint classInstCount; 110 | public unsafe IntPtr* classInst; 111 | public uint methInstCount; 112 | public unsafe IntPtr* methInst; 113 | } 114 | [StructLayout(LayoutKind.Sequential)] 115 | public unsafe struct CorinfoSigInst64 116 | { 117 | public uint classInstCount; 118 | uint dummy; 119 | public IntPtr* classInst; 120 | public uint methInstCount; 121 | uint dummy2; 122 | public IntPtr* methInst; 123 | } 124 | 125 | [StructLayout(LayoutKind.Sequential)] 126 | public struct CorinfoSigInfo 127 | { 128 | public CorInfoCallConv callConv; 129 | public IntPtr retTypeClass; 130 | public IntPtr retTypeSigClass; 131 | public CorInfoType retType; 132 | public byte flags; 133 | public ushort numArgs; 134 | public CorinfoSigInst sigInst; 135 | public IntPtr args; 136 | public uint token; 137 | public IntPtr sig; 138 | public IntPtr scope; 139 | } 140 | 141 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 142 | public struct CorMethodInfo64 143 | { 144 | public IntPtr methodHandle; 145 | public IntPtr moduleHandle; 146 | public IntPtr ilCode; 147 | public UInt32 ilCodeSize; 148 | public UInt16 maxStack; 149 | public UInt16 EHCount; 150 | public UInt32 corInfoOptions; 151 | public CorinfoSigInst64 args; 152 | public CorinfoSigInst64 locals; 153 | } 154 | 155 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 156 | public struct CorMethodInfo 157 | { 158 | public IntPtr methodHandle; 159 | public IntPtr moduleHandle; 160 | public IntPtr ilCode; 161 | public UInt32 ilCodeSize; 162 | public UInt16 maxStack; 163 | public UInt16 EHCount; 164 | public UInt32 corInfoOptions; 165 | public CorinfoSigInst args; 166 | public CorinfoSigInst locals; 167 | } 168 | 169 | [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)] 170 | public unsafe delegate int CompileMethodDel( 171 | IntPtr thisPtr, [In] IntPtr corJitInfo, [In] CorMethodInfo* methodInfo, CorJitFlag flags, 172 | [Out] IntPtr nativeEntry, [Out] IntPtr nativeSizeOfCode); 173 | 174 | [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)] 175 | public unsafe delegate int CompileMethodDel64( 176 | IntPtr thisPtr, [In] IntPtr corJitInfo, [In] CorMethodInfo64* methodInfo, CorJitFlag flags, 177 | [Out] IntPtr nativeEntry, [Out] IntPtr nativeSizeOfCode); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /Sharprompt-2.3.0/Sharprompt/Prompt.Basic.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | 6 | using Sharprompt.Forms; 7 | using Sharprompt.Internal; 8 | 9 | namespace Sharprompt 10 | { 11 | public static partial class Prompt 12 | { 13 | public static T Input(InputOptions options) 14 | { 15 | using var form = new InputForm(options); 16 | 17 | return form.Start(); 18 | } 19 | 20 | public static T Input(Action configure) 21 | { 22 | var options = new InputOptions(); 23 | 24 | configure(options); 25 | 26 | return Input(options); 27 | } 28 | 29 | public static T Input(string message, object defaultValue = null, IList> validators = null) 30 | { 31 | var options = new InputOptions 32 | { 33 | Message = message, 34 | DefaultValue = defaultValue 35 | }; 36 | 37 | if (validators != null) 38 | { 39 | foreach (var validator in validators) 40 | { 41 | options.Validators.Add(validator); 42 | } 43 | } 44 | 45 | return Input(options); 46 | } 47 | 48 | public static string Password(PasswordOptions options) 49 | { 50 | using var form = new PasswordForm(options); 51 | 52 | return form.Start(); 53 | } 54 | 55 | public static string Password(Action configure) 56 | { 57 | var options = new PasswordOptions(); 58 | 59 | configure(options); 60 | 61 | return Password(options); 62 | } 63 | 64 | public static string Password(string message, IList> validators = null) 65 | { 66 | var options = new PasswordOptions 67 | { 68 | Message = message 69 | }; 70 | 71 | if (validators != null) 72 | { 73 | foreach (var validator in validators) 74 | { 75 | options.Validators.Add(validator); 76 | } 77 | } 78 | 79 | return Password(options); 80 | } 81 | 82 | public static bool Confirm(ConfirmOptions options) 83 | { 84 | using var form = new ConfirmForm(options); 85 | 86 | return form.Start(); 87 | } 88 | 89 | public static bool Confirm(Action configure) 90 | { 91 | var options = new ConfirmOptions(); 92 | 93 | configure(options); 94 | 95 | return Confirm(options); 96 | } 97 | 98 | public static bool Confirm(string message, bool? defaultValue = null) 99 | { 100 | var options = new ConfirmOptions 101 | { 102 | Message = message, 103 | DefaultValue = defaultValue 104 | }; 105 | 106 | return Confirm(options); 107 | } 108 | 109 | public static T Select(SelectOptions options) 110 | { 111 | using var form = new SelectForm(options); 112 | 113 | return form.Start(); 114 | } 115 | 116 | public static T Select(Action> configure) 117 | { 118 | var options = new SelectOptions(); 119 | 120 | configure(options); 121 | 122 | return Select(options); 123 | } 124 | 125 | public static T Select(string message, int? pageSize = null, T? defaultValue = null) where T : struct, Enum 126 | { 127 | var items = EnumValue.GetValues(); 128 | 129 | var options = new SelectOptions> 130 | { 131 | Message = message, 132 | Items = items, 133 | DefaultValue = (EnumValue)defaultValue, 134 | PageSize = pageSize, 135 | TextSelector = x => x.DisplayName 136 | }; 137 | 138 | return Select(options).Value; 139 | } 140 | 141 | public static T Select(string message, IEnumerable items, int? pageSize = null, object defaultValue = null, Func textSelector = null) 142 | { 143 | var options = new SelectOptions 144 | { 145 | Message = message, 146 | Items = items, 147 | DefaultValue = defaultValue, 148 | PageSize = pageSize, 149 | TextSelector = textSelector ?? (x => x.ToString()) 150 | }; 151 | 152 | return Select(options); 153 | } 154 | 155 | public static IEnumerable MultiSelect(MultiSelectOptions options) 156 | { 157 | using var form = new MultiSelectForm(options); 158 | 159 | return form.Start(); 160 | } 161 | 162 | public static IEnumerable MultiSelect(Action> configure) 163 | { 164 | var options = new MultiSelectOptions(); 165 | 166 | configure(options); 167 | 168 | return MultiSelect(options); 169 | } 170 | 171 | public static IEnumerable MultiSelect(string message, int? pageSize = null, int minimum = 1, int maximum = int.MaxValue, IEnumerable defaultValues = null) where T : struct, Enum 172 | { 173 | var items = EnumValue.GetValues(); 174 | 175 | var options = new MultiSelectOptions> 176 | { 177 | Message = message, 178 | Items = items, 179 | DefaultValues = defaultValues?.Select(x => (EnumValue)x), 180 | PageSize = pageSize, 181 | Minimum = minimum, 182 | Maximum = maximum, 183 | TextSelector = x => x.DisplayName 184 | }; 185 | 186 | return MultiSelect(options).Select(x => x.Value); 187 | } 188 | 189 | public static IEnumerable MultiSelect(string message, IEnumerable items, int? pageSize = null, int minimum = 1, int maximum = int.MaxValue, IEnumerable defaultValues = null, Func textSelector = null) 190 | { 191 | var options = new MultiSelectOptions 192 | { 193 | Message = message, 194 | Items = items, 195 | DefaultValues = defaultValues, 196 | PageSize = pageSize, 197 | Minimum = minimum, 198 | Maximum = maximum, 199 | TextSelector = x => x.ToString() 200 | }; 201 | 202 | return MultiSelect(options); 203 | } 204 | 205 | public static IEnumerable List(ListOptions options) 206 | { 207 | using var form = new ListForm(options); 208 | 209 | return form.Start(); 210 | } 211 | 212 | public static IEnumerable List(Action> configure) 213 | { 214 | var options = new ListOptions(); 215 | 216 | configure(options); 217 | 218 | return List(options); 219 | } 220 | 221 | public static IEnumerable List(string message, int minimum = 1, int maximum = int.MaxValue, IList> validators = null) 222 | { 223 | var options = new ListOptions 224 | { 225 | Message = message, 226 | Minimum = minimum, 227 | Maximum = maximum 228 | }; 229 | 230 | if (validators != null) 231 | { 232 | foreach (var validator in validators) 233 | { 234 | options.Validators.Add(validator); 235 | } 236 | } 237 | 238 | return List(options); 239 | } 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /Sharprompt-2.3.0/.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Default settings: 7 | # A newline ending every file 8 | # Use 4 spaces as indentation 9 | [*] 10 | insert_final_newline = true 11 | indent_style = space 12 | indent_size = 4 13 | trim_trailing_whitespace = true 14 | 15 | [project.json] 16 | indent_size = 2 17 | 18 | # C# files 19 | [*.cs] 20 | charset = utf-8-bom 21 | 22 | # New line preferences 23 | csharp_new_line_before_open_brace = all 24 | csharp_new_line_before_else = true 25 | csharp_new_line_before_catch = true 26 | csharp_new_line_before_finally = true 27 | csharp_new_line_before_members_in_object_initializers = true 28 | csharp_new_line_before_members_in_anonymous_types = true 29 | csharp_new_line_between_query_expression_clauses = true 30 | 31 | # Indentation preferences 32 | csharp_indent_block_contents = true 33 | csharp_indent_braces = false 34 | csharp_indent_case_contents = true 35 | csharp_indent_case_contents_when_block = false 36 | csharp_indent_switch_labels = true 37 | csharp_indent_labels = one_less_than_current 38 | 39 | # Modifier preferences 40 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion 41 | 42 | # avoid this. unless absolutely necessary 43 | dotnet_style_qualification_for_field = false:suggestion 44 | dotnet_style_qualification_for_property = false:suggestion 45 | dotnet_style_qualification_for_method = false:suggestion 46 | dotnet_style_qualification_for_event = false:suggestion 47 | 48 | # Types: use keywords instead of BCL types, and permit var only when the type is clear 49 | csharp_style_var_for_built_in_types = true:suggestion 50 | csharp_style_var_when_type_is_apparent = true:suggestion 51 | csharp_style_var_elsewhere = true:suggestion 52 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion 53 | dotnet_style_predefined_type_for_member_access = true:suggestion 54 | 55 | # name all constant fields using PascalCase 56 | dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion 57 | dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields 58 | dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style 59 | dotnet_naming_symbols.constant_fields.applicable_kinds = field 60 | dotnet_naming_symbols.constant_fields.required_modifiers = const 61 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case 62 | 63 | # static fields should have s_ prefix 64 | dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion 65 | dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields 66 | dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style 67 | dotnet_naming_symbols.static_fields.applicable_kinds = field 68 | dotnet_naming_symbols.static_fields.required_modifiers = static 69 | dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected 70 | dotnet_naming_style.static_prefix_style.required_prefix = s_ 71 | dotnet_naming_style.static_prefix_style.capitalization = camel_case 72 | 73 | # internal and private fields should be _camelCase 74 | dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion 75 | dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields 76 | dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style 77 | dotnet_naming_symbols.private_internal_fields.applicable_kinds = field 78 | dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal 79 | dotnet_naming_style.camel_case_underscore_style.required_prefix = _ 80 | dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case 81 | 82 | # Code style defaults 83 | csharp_using_directive_placement = outside_namespace:suggestion 84 | dotnet_sort_system_directives_first = true 85 | dotnet_separate_import_directive_groups = true 86 | csharp_prefer_braces = true:refactoring 87 | csharp_preserve_single_line_blocks = true:none 88 | csharp_preserve_single_line_statements = false:none 89 | csharp_prefer_static_local_function = true:suggestion 90 | csharp_prefer_simple_using_statement = false:none 91 | csharp_style_prefer_switch_expression = true:suggestion 92 | 93 | # Code quality 94 | dotnet_style_readonly_field = true:suggestion 95 | dotnet_code_quality_unused_parameters = non_public:suggestion 96 | 97 | # Expression-level preferences 98 | dotnet_style_object_initializer = true:suggestion 99 | dotnet_style_collection_initializer = true:suggestion 100 | dotnet_style_explicit_tuple_names = true:suggestion 101 | dotnet_style_coalesce_expression = true:suggestion 102 | dotnet_style_null_propagation = true:suggestion 103 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion 104 | dotnet_style_prefer_inferred_tuple_names = true:suggestion 105 | dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion 106 | dotnet_style_prefer_auto_properties = true:suggestion 107 | dotnet_style_prefer_conditional_expression_over_assignment = true:refactoring 108 | dotnet_style_prefer_conditional_expression_over_return = true:refactoring 109 | csharp_prefer_simple_default_expression = true:suggestion 110 | 111 | # Expression-bodied members 112 | csharp_style_expression_bodied_methods = true:refactoring 113 | csharp_style_expression_bodied_constructors = true:refactoring 114 | csharp_style_expression_bodied_operators = true:refactoring 115 | csharp_style_expression_bodied_properties = true:refactoring 116 | csharp_style_expression_bodied_indexers = true:refactoring 117 | csharp_style_expression_bodied_accessors = true:refactoring 118 | csharp_style_expression_bodied_lambdas = true:refactoring 119 | csharp_style_expression_bodied_local_functions = true:refactoring 120 | 121 | # Pattern matching 122 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion 123 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion 124 | csharp_style_inlined_variable_declaration = true:suggestion 125 | 126 | # Null checking preferences 127 | csharp_style_throw_expression = true:suggestion 128 | csharp_style_conditional_delegate_call = true:suggestion 129 | 130 | # Other features 131 | csharp_style_prefer_index_operator = false:none 132 | csharp_style_prefer_range_operator = false:none 133 | csharp_style_pattern_local_over_anonymous_function = false:none 134 | 135 | # Space preferences 136 | csharp_space_after_cast = false 137 | csharp_space_after_colon_in_inheritance_clause = true 138 | csharp_space_after_comma = true 139 | csharp_space_after_dot = false 140 | csharp_space_after_keywords_in_control_flow_statements = true 141 | csharp_space_after_semicolon_in_for_statement = true 142 | csharp_space_around_binary_operators = before_and_after 143 | csharp_space_around_declaration_statements = do_not_ignore 144 | csharp_space_before_colon_in_inheritance_clause = true 145 | csharp_space_before_comma = false 146 | csharp_space_before_dot = false 147 | csharp_space_before_open_square_brackets = false 148 | csharp_space_before_semicolon_in_for_statement = false 149 | csharp_space_between_empty_square_brackets = false 150 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 151 | csharp_space_between_method_call_name_and_opening_parenthesis = false 152 | csharp_space_between_method_call_parameter_list_parentheses = false 153 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 154 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 155 | csharp_space_between_method_declaration_parameter_list_parentheses = false 156 | csharp_space_between_parentheses = false 157 | csharp_space_between_square_brackets = false 158 | 159 | # Analyzers 160 | dotnet_code_quality.ca1802.api_surface = private, internal 161 | 162 | # C++ Files 163 | [*.{cpp,h,in}] 164 | curly_bracket_next_line = true 165 | indent_brace_style = Allman 166 | 167 | # Xml project files 168 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] 169 | indent_size = 2 170 | 171 | # Xml build files 172 | [*.builds] 173 | indent_size = 2 174 | 175 | # Xml files 176 | [*.{xml,stylecop,resx,ruleset}] 177 | indent_size = 2 178 | 179 | # Xml config files 180 | [*.{props,targets,config,nuspec}] 181 | indent_size = 2 182 | 183 | # Shell scripts 184 | [*.sh] 185 | end_of_line = lf 186 | [*.{cmd, bat}] 187 | end_of_line = crlf 188 | 189 | # JavaScript files 190 | [*.{js,json}] 191 | indent_size= 2 192 | 193 | # Html files 194 | [*.html] 195 | indent_size= 2 -------------------------------------------------------------------------------- /Sharprompt-2.3.0/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Nuget personal access tokens and Credentials 210 | nuget.config 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | # Ionide (cross platform F# VS Code tools) working folder 363 | .ionide/ 364 | 365 | # Fody - auto-generated XML schema 366 | FodyWeavers.xsd 367 | 368 | # VS Code files for those working on multiple tools 369 | .vscode/* 370 | !.vscode/settings.json 371 | !.vscode/tasks.json 372 | !.vscode/launch.json 373 | !.vscode/extensions.json 374 | *.code-workspace 375 | 376 | # Local History for Visual Studio Code 377 | .history/ 378 | 379 | # Windows Installer files from build outputs 380 | *.cab 381 | *.msi 382 | *.msix 383 | *.msm 384 | *.msp 385 | 386 | # JetBrains Rider 387 | .idea/ 388 | *.sln.iml -------------------------------------------------------------------------------- /Dis2Msil/Dis2Msil/MethodBodyReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Reflection.Emit; 6 | 7 | //il = new byte[] { 0x02, 0x28, 0x1C, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x02, 0x03, 0x7D, 0x11, 0x00, 0x00, 0x04, 0x2A }; 8 | //02-28-1C-00-00-0A-00-00-02-03-7D-11-00-00-04-2A 9 | //TEST VALUE 10 | 11 | namespace Dis2Msil 12 | { 13 | //https://www.codeproject.com/Articles/14058/Parsing-the-IL-of-a-Method-Body 14 | public class MethodBodyReader 15 | { 16 | public List instructions = null; 17 | protected byte[] il = null; 18 | private MethodInfo mi = null; 19 | 20 | private int ReadInt16(byte[] _il, ref int position) 21 | { 22 | return ((il[position++] | (il[position++] << 8))); 23 | } 24 | private ushort ReadUInt16(byte[] _il, ref int position) 25 | { 26 | return (ushort)((il[position++] | (il[position++] << 8))); 27 | } 28 | private int ReadInt32(byte[] _il, ref int position) 29 | { 30 | return (((il[position++] | (il[position++] << 8)) | (il[position++] << 0x10)) | (il[position++] << 0x18)); 31 | } 32 | private ulong ReadInt64(byte[] _il, ref int position) 33 | { 34 | return (ulong)(((il[position++] | (il[position++] << 8)) | (il[position++] << 0x10)) | (il[position++] << 0x18) | (il[position++] << 0x20) | (il[position++] << 0x28) | (il[position++] << 0x30) | (il[position++] << 0x38)); 35 | } 36 | private double ReadDouble(byte[] _il, ref int position) 37 | { 38 | return (((il[position++] | (il[position++] << 8)) | (il[position++] << 0x10)) | (il[position++] << 0x18) | (il[position++] << 0x20) | (il[position++] << 0x28) | (il[position++] << 0x30) | (il[position++] << 0x38)); 39 | } 40 | private sbyte ReadSByte(byte[] _il, ref int position) 41 | { 42 | return (sbyte)il[position++]; 43 | } 44 | private byte ReadByte(byte[] _il, ref int position) 45 | { 46 | return il[position++]; 47 | } 48 | private Single ReadSingle(byte[] _il, ref int position) 49 | { 50 | return ((il[position++] | (il[position++] << 8)) | (il[position++] << 0x10)) | (il[position++] << 0x18); 51 | } 52 | 53 | /// 54 | /// Constructs the array of ILInstructions according to the IL byte code. 55 | /// 56 | /// 57 | private void ConstructInstructions(Module module) 58 | { 59 | try 60 | { 61 | Globals.LoadOpCodes(); 62 | byte[] il = this.il; 63 | int position = 0; 64 | instructions = new List(); 65 | while (position < il.Length) 66 | { 67 | ILInstruction instruction = new ILInstruction(); 68 | 69 | // get the operation code of the current instruction 70 | OpCode code = OpCodes.Nop; 71 | ushort value = il[position++]; 72 | if (value != 0xfe) 73 | { 74 | code = Globals.singleByteOpCodes[value]; 75 | } 76 | else 77 | { 78 | value = il[position++]; 79 | code = Globals.multiByteOpCodes[value]; 80 | value = (ushort)(value | 0xfe00); 81 | } 82 | instruction.Code = code; 83 | instruction.Offset = position - 1; 84 | int metadataToken = 0; 85 | // get the operand of the current operation 86 | switch (code.OperandType) 87 | { 88 | case OperandType.InlineBrTarget: 89 | metadataToken = ReadInt32(il, ref position); 90 | metadataToken += position; 91 | instruction.Operand = metadataToken; 92 | break; 93 | case OperandType.InlineField: 94 | metadataToken = ReadInt32(il, ref position); 95 | instruction.Operand = module.ResolveField(metadataToken); 96 | break; 97 | case OperandType.InlineMethod: 98 | metadataToken = ReadInt32(il, ref position); 99 | try 100 | { 101 | instruction.Operand = module.ResolveMethod(metadataToken); 102 | } 103 | catch 104 | { 105 | instruction.Operand = module.ResolveMember(metadataToken); 106 | } 107 | break; 108 | case OperandType.InlineSig: 109 | metadataToken = ReadInt32(il, ref position); 110 | instruction.Operand = module.ResolveSignature(metadataToken); 111 | break; 112 | case OperandType.InlineTok: 113 | metadataToken = ReadInt32(il, ref position); 114 | try 115 | { 116 | instruction.Operand = module.ResolveType(metadataToken); 117 | } 118 | catch 119 | { 120 | instruction.Operand = metadataToken; 121 | } 122 | break; 123 | case OperandType.InlineType: 124 | metadataToken = ReadInt32(il, ref position); 125 | // now we call the ResolveType always using the generic attributes type in order 126 | // to support decompilation of generic methods and classes 127 | 128 | // thanks to the guys from code project who commented on this missing feature 129 | try 130 | { 131 | if (mi == null) 132 | { 133 | instruction.Operand = metadataToken.ToString("x8"); 134 | break; 135 | } 136 | instruction.Operand = module.ResolveType(metadataToken, mi.DeclaringType.GetGenericArguments(), mi.GetGenericArguments()); 137 | } 138 | catch 139 | { 140 | instruction.Operand = metadataToken; 141 | } 142 | break; 143 | case OperandType.InlineI: 144 | { 145 | instruction.Operand = ReadInt32(il, ref position); 146 | break; 147 | } 148 | case OperandType.InlineI8: 149 | { 150 | instruction.Operand = ReadInt64(il, ref position); 151 | break; 152 | } 153 | case OperandType.InlineNone: 154 | { 155 | instruction.Operand = null; 156 | break; 157 | } 158 | case OperandType.InlineR: 159 | { 160 | instruction.Operand = ReadDouble(il, ref position); 161 | break; 162 | } 163 | case OperandType.InlineString: 164 | { 165 | metadataToken = ReadInt32(il, ref position); 166 | instruction.Operand = module.ResolveString(metadataToken); 167 | break; 168 | } 169 | case OperandType.InlineSwitch: 170 | { 171 | int count = ReadInt32(il, ref position); 172 | int[] casesAddresses = new int[count]; 173 | for (int i = 0; i < count; i++) 174 | { 175 | casesAddresses[i] = ReadInt32(il, ref position); 176 | } 177 | int[] cases = new int[count]; 178 | for (int i = 0; i < count; i++) 179 | { 180 | cases[i] = position + casesAddresses[i]; 181 | } 182 | break; 183 | } 184 | case OperandType.InlineVar: 185 | { 186 | instruction.Operand = ReadUInt16(il, ref position); 187 | break; 188 | } 189 | case OperandType.ShortInlineBrTarget: 190 | { 191 | instruction.Operand = ReadSByte(il, ref position) + position; 192 | break; 193 | } 194 | case OperandType.ShortInlineI: 195 | { 196 | instruction.Operand = ReadSByte(il, ref position); 197 | break; 198 | } 199 | case OperandType.ShortInlineR: 200 | { 201 | instruction.Operand = ReadSingle(il, ref position); 202 | break; 203 | } 204 | case OperandType.ShortInlineVar: 205 | { 206 | instruction.Operand = ReadByte(il, ref position); 207 | break; 208 | } 209 | default: 210 | { 211 | throw new Exception("Unknown operand type."); 212 | } 213 | } 214 | instructions.Add(instruction); 215 | } 216 | } 217 | catch { } 218 | } 219 | 220 | 221 | public object GetRefferencedOperand(Module module, int metadataToken) 222 | { 223 | AssemblyName[] assemblyNames = module.Assembly.GetReferencedAssemblies(); 224 | for (int i = 0; i < assemblyNames.Length; i++) 225 | { 226 | Module[] modules = Assembly.Load(assemblyNames[i]).GetModules(); 227 | for (int j = 0; j < modules.Length; j++) 228 | { 229 | try 230 | { 231 | Type t = modules[j].ResolveType(metadataToken); 232 | return t; 233 | } 234 | catch 235 | { 236 | return typeof(MissingMethodException); 237 | } 238 | 239 | } 240 | } 241 | return null; 242 | 243 | } 244 | 245 | public string GetBodyCode() 246 | { 247 | string result = ""; 248 | if (instructions != null) 249 | { 250 | for (int i = 0; i < instructions.Count; i++) 251 | { 252 | result += instructions[i].GetCode() + "\n"; 253 | } 254 | } 255 | return result; 256 | 257 | } 258 | 259 | public static byte[] StringToByteArray(string hex) 260 | { 261 | return Enumerable.Range(0, hex.Length) 262 | .Where(x => x % 2 == 0) 263 | .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) 264 | .ToArray(); 265 | } //https://stackoverflow.com/questions/321370/how-can-i-convert-a-hex-string-to-a-byte-array/321404 266 | 267 | 268 | public MethodBodyReader(Module module, string strilArray) 269 | { 270 | Globals.LoadOpCodes(); 271 | if (module != null) 272 | { 273 | byte[] ilArray = StringToByteArray(strilArray.Replace("-", "")); 274 | il = ilArray; 275 | ConstructInstructions(module); 276 | } 277 | } 278 | 279 | public MethodBodyReader(Module module, byte[] ilArray) 280 | { 281 | if (module != null) 282 | { 283 | 284 | il = ilArray; 285 | 286 | ConstructInstructions(module); 287 | } 288 | } 289 | } 290 | } --------------------------------------------------------------------------------