Exetools  

Go Back   Exetools > General > Source Code

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 11-17-2021, 08:56
Succubus Succubus is offline
Friend
 
Join Date: Oct 2021
Location: Japan
Posts: 6
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 1
Thanks Rcvd at 8 Times in 4 Posts
Succubus Reputation: 1
Lightbulb [C#] EAP-Resharper for VS-2022 Patch with DNLIB

Quote:
If you like this product please buy it It's quite cheap and c# and c++ ReSharper is nice, Matti introduces this to me at discord.
Quote:
This works on early access only which is ReSharper for vs2022 but you can edit it to make it work to a stable release one. by just telling this program where to find the DLL I use the registry to find the early access path so that's the hint
Quote:
Early Access - This version is not smooth yet because early access
https://i.postimg.cc/pLrDSc1Q/Capture.jpg
Stable Release for vs2019 - This one is fine
https://i.postimg.cc/3JnXnQ9J/unknown.png
Quote:
In theory, all ReSharper products will auto-registered
since they share a single licensing module.

whenever u update or uninstall or install another product under ReSharper you need to patch it again.
because they reinstalled the license module. I think it's for security measures.




Code:
using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using Microsoft.Win32;
using FileAttributes = System.IO.FileAttributes;

namespace ResharperPatch
{
    internal class Program
    {
        private static ModuleContext _mainCtx;
        private static ModuleDefMD _main;

        private static void PrintColor(string message, ConsoleColor color)
        {
            var pieces = Regex.Split(message, @"(\[[^\]]*\])");

            for (int i = 0; i < pieces.Length; i++)
            {
                string piece = pieces[i];

                if (piece.StartsWith("[") && piece.EndsWith("]"))
                {
                    Console.ForegroundColor = color;
                    piece = piece.Substring(1, piece.Length - 2);
                }

                Console.Write(piece);
                Console.ResetColor();
            }

            Console.WriteLine();
        }

        private static void Print(String data)
        {
            Console.WriteLine(data);
        }

        private static TypeDef GetType(ModuleDefMD module, string classPath)
        {
            foreach (var type in module.Types)
            {
                if (type.FullName == classPath)
                    return type;
            }

            return null;
        }

/*
        private static void debug_body(CilBody body)
        {
            for (int i = 0; i < body.Instructions.Count; i++)
            {
                var instr = body.Instructions[i];
                Print(instr.ToString());
            }
        }
*/

        private static CilBody return_bool(bool status)
        {
            CilBody body = new CilBody();
            OpCode state = status ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0;
            body.Instructions.Add(state.ToInstruction());
            body.Instructions.Add(OpCodes.Ret.ToInstruction());
            return body;
        } 

        private static CilBody return_digit(int num)
        {
            CilBody body = new CilBody();
            body.Instructions.Add(OpCodes.Ldc_I4.ToInstruction(num));
            body.Instructions.Add(OpCodes.Ret.ToInstruction());
            return body;
        }

        private static CilBody return_string(string txt)
        {
            CilBody body = new CilBody();
            body.Instructions.Add(OpCodes.Ldstr.ToInstruction(txt));
            body.Instructions.Add(OpCodes.Ret.ToInstruction());
            return body;
        }

        private static CilBody return_null()
        {
            CilBody body = new CilBody();
            body.Instructions.Add(OpCodes.Ldnull.ToInstruction());
            body.Instructions.Add(OpCodes.Ret.ToInstruction());
            return body;
        }

        private static CilBody return_empty()
        {
            CilBody body = new CilBody();
            body.Instructions.Add(OpCodes.Ret.ToInstruction());
            return body;
        }

        private static CilBody return_date(int year, int month, int day)
        {
            CilBody body = new CilBody();
            
            var systemDateTime = _main.CorLibTypes.GetTypeRef("System", "DateTime");
          
            var ctor = new MemberRefUser(_main, ".ctor",
                            MethodSig.CreateInstance(
                                _main.CorLibTypes.Void,
                                _main.CorLibTypes.Int32,
                                _main.CorLibTypes.Int32,
                                _main.CorLibTypes.Int32),
                            systemDateTime);
             

            body.Instructions.Add(OpCodes.Ldc_I4.ToInstruction(year));
            body.Instructions.Add(OpCodes.Ldc_I4.ToInstruction(month));
            body.Instructions.Add(OpCodes.Ldc_I4.ToInstruction(day));
            body.Instructions.Add(OpCodes.Newobj.ToInstruction(ctor));
            body.Instructions.Add(OpCodes.Ret.ToInstruction());
            return body;
        }

        private static CilBody return_id(string userKey)
        {
            var keyPart = userKey.IndexOf('-');
            int.TryParse(userKey.Substring(0, keyPart), out var num);
            return return_digit(num);
        }

        private static void PatchJetBrainsLicense(string user, string key )
        {
            PrintColor("---- Please Wait -----", ConsoleColor.Cyan);
            PrintColor("[Customer Key]: " + key, ConsoleColor.DarkCyan);
            PrintColor("[Customer ID]: " + user, ConsoleColor.DarkCyan);
            PrintColor("---- Please Wait -----", ConsoleColor.Cyan);
            // Class LicenseChecker
            var licenseChecker = GetType(_main, "JetBrains.Application.License.LicenseChecker");
            // Class LicenseData
            var licenseData = GetType(_main, "JetBrains.Application.License.LicenseData");
            // Class LicenseData
            var resultEx = GetType(_main, "JetBrains.Application.License2.ResultEx");
            // Class UserLicenseViewSubmodel
            var userLicenseViewSubmodel = GetType(_main, "JetBrains.Application.License2.UserLicenses.UserLicenseViewSubmodel");
            // Class UserLicenseStatus
            var userLicenseStatus = GetType(_main, "JetBrains.Application.License2.UserLicenses.UserLicenseStatus");
            // Class ResultWithDescription
            var resultWithDescription = GetType(_main, "JetBrains.Application.License2.ResultWithDescription");
            // Class LicensedEntityEx
            var licensedEntityEx = GetType(_main, "JetBrains.Application.License2.LicensedEntityEx");
            // Class LicensedEntityEx
            //var evaluationLicenseViewSubmodel = GetType(_main, "JetBrains.Application.License2.Evaluation.EvaluationLicenseViewSubmodel");
            //////////////////////////////////////////////////////////////////////
            // Patch get_IsChecksumOK
            licenseChecker.FindMethod("get_IsChecksumOK").Body = return_bool(true);
            // Patch HasLicense
            licenseChecker.FindMethod("get_HasLicense").Body = return_bool(true);
            // Patch HasLicense
            licenseChecker.FindMethod("get_Type").Body = return_digit(0);
            // Patch CustomerId
            licenseChecker.FindMethod("get_CustomerId").Body = return_id(key);
            // Patch get_ExpirationDate
            licenseData.FindMethod("get_ExpirationDate").Body = return_date(2030, 5, 5);
            // Patch get_SubscriptionEndDate
            licenseData.FindMethod("get_SubscriptionEndDate").Body = return_date(2030, 5, 5);
            // Patch get_GenerationDate
            licenseData.FindMethod("get_GenerationDate").Body = return_date(2020, 5, 5);
            // Patch get_IsEndless
            licenseData.FindMethod("get_IsEndless").Body = return_bool(true);
            // Patch get_ContainsSubscription
            licenseData.FindMethod("get_ContainsSubscription").Body = return_bool(true);
            // Patch get_LicenseKey
            licenseData.FindMethod("get_LicenseKey").Body = return_string(key);
            // Patch get_UserName
            licenseData.FindMethod("get_UserName").Body = return_string(user);
            // Patch customer id
            licenseData.FindMethod("get_CustomerId").Body = return_id(key);
            // Patch get_LicenseType
            licenseData.FindMethod("get_LicenseType").Body = return_digit(0);
            // Patch result
            resultWithDescription.FindMethod("get_Result").Body = return_digit(0);
            // RequiresLicense [ EA8 PATCH ]
            licensedEntityEx.FindMethod("RequiresLicense").Body = return_bool(false);
            // Patch TryCreateInfoForOldLicenseData 
            userLicenseViewSubmodel.FindMethod("TryCreateInfoForOldLicenseData").Body = return_null();
            // Patch CheckLicense [ EA8 PATCH ]
            userLicenseViewSubmodel.FindMethod("CheckLicense").Body = return_empty();
            resultEx.FindMethod("IsSuccessful").Body = return_bool(true);
            resultEx.FindMethod("ContainsWarnings").Body = return_bool(false);
            resultEx.FindMethod("Is30MinToShutdown").Body = return_bool(false);
            resultEx.FindMethod("IsFailed").Body = return_bool(false);
            // Patch get_Severity
            userLicenseStatus.FindMethod("get_Severity").Body = return_digit(0);
        }

        // ReSharper disable once ArrangeTypeMemberModifiers
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            if (args is null) { }

            Console.SetWindowSize(160, 32);

            try
            {

                var reSharperPlatformVs17 = Registry.CurrentUser.OpenSubKey("SOFTWARE\\JetBrains\\ReSharperPlatformVs17\\")?.GetSubKeyNames();

                if(reSharperPlatformVs17 == null)
                {
                    Print("ReSharper 2022 is not installed");
                    Console.ReadKey();
                    Environment.Exit(0);
                }
                else
                {
                    var sk = reSharperPlatformVs17[0];
                    PrintColor("[ReSharper 2022]: "+ sk, ConsoleColor.Cyan);
                    using (var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\JetBrains\\ReSharperPlatformVs17\\"+ sk))
                    {
                        var o = key?.GetValue("InstallDir");

                        if (o != null)
                        {
                            var installDir = (o as String);
                            var file = installDir + "\\JetBrains.Platform.Shell.dll"; 
                            var fileBackup = installDir + "\\JetBrains.Platform.Shell.dll.back";
                           
                            PrintColor("[InstallDir]: " + installDir, ConsoleColor.Cyan);

                            if (!File.Exists(fileBackup))
                            {
                                File.Copy(file, fileBackup);
                            }

                            PrintColor("[Backup Path]: " + fileBackup, ConsoleColor.Green);

                            var pname = Process.GetProcessesByName("devenv");

                            if (pname.Length > 0)
                            {
                                PrintColor("[Error]: [devenv.exe is running at the background please kill it!]", ConsoleColor.Red);
                                Console.ReadKey();
                                Environment.Exit(0);
                            }

                            PrintColor("[Patching]: " + file, ConsoleColor.Red);
                            _mainCtx = ModuleDef.CreateModuleContext();
                            // dont feed file directly here feed it with bytes so you can replace the file
                            _main = ModuleDefMD.Load(File.ReadAllBytes(file), _mainCtx);
                            PatchJetBrainsLicense("Succubus.ExeTools", "1234-1234-1234-1235");
                            File.SetAttributes(file, FileAttributes.Normal);
                            _main.NativeWrite(file); 
                                
                            //File.Copy(file_temp, file+".fuck", true);
                            PrintColor("[Finish]: Press any key to continue...", ConsoleColor.Green);
                        }
                    }
                    Console.ReadKey();
                    Environment.Exit(0);
                }
               
            }
            catch (Exception ex) 
            {
                PrintColor("[Error]: "+ex.Message, ConsoleColor.Red);
            }

            Console.ReadKey();
            Environment.Exit(0);
        }
}
}

Quote:
This helps also for you to learn how to use DNLIB to its finest xD
Quote:
Updated works with EAP 8 above now

Last edited by Succubus; 11-17-2021 at 11:55.
Reply With Quote
The Following 2 Users Say Thank You to Succubus For This Useful Post:
Aesculapius (11-17-2021), congviet (11-19-2021)
  #2  
Old 11-17-2021, 11:51
Succubus Succubus is offline
Friend
 
Join Date: Oct 2021
Location: Japan
Posts: 6
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 1
Thanks Rcvd at 8 Times in 4 Posts
Succubus Reputation: 1
Added fixed for EAP 8
Reply With Quote
The Following User Says Thank You to Succubus For This Useful Post:
Aesculapius (11-17-2021)
  #3  
Old 11-19-2021, 10:30
tK! tK! is offline
Family
 
Join Date: Jan 2013
Posts: 152
Rept. Given: 6
Rept. Rcvd 120 Times in 33 Posts
Thanks Given: 17
Thanks Rcvd at 47 Times in 32 Posts
tK! Reputation: 100-199 tK! Reputation: 100-199
Nice Part of Coding "//File.Copy(file_temp, file+".fuck", true);"


One question , can it be use on other prodcuts ? i am learning GoLang and they have something special product for it.
Reply With Quote
  #4  
Old 11-19-2021, 17:22
Succubus Succubus is offline
Friend
 
Join Date: Oct 2021
Location: Japan
Posts: 6
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 1
Thanks Rcvd at 8 Times in 4 Posts
Succubus Reputation: 1
Question

Quote:
Originally Posted by tK! View Post
Nice Part of Coding "//File.Copy(file_temp, file+".fuck", true);"


One question , can it be use on other prodcuts ? i am learning GoLang and they have something special product for it.
Are you talking about https://www.jetbrains.com/go/ ?

Well, thats not part of ReSharper bundle so no.

The list of products includes

Resharper .NET
Resharper C++
Rider - Unreal Engine IDE
DotTrace - Profiler
DotCover
DotMemory
DotPeek
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On



All times are GMT +8. The time now is 04:48.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX
( 1998 - 2021 )