public void Inject() { // get the target method first Type type = Type.GetType("Test.Test"); MethodInfo methodInfo = type.GetMethod("CompareOneAndTwo", BindingFlags.Public | BindingFlags.Instance); // the following line is unnecessary actually // Here we use it to cause the method to be compiled by JIT // so that we can verify this also works for JIT-compiled method :) RuntimeHelpers.PrepareMethod(methodInfo.MethodHandle); // get the original IL Codes for the method byte[] ilCodes = methodInfo.GetMethodBody().GetILAsByteArray(); // this is not a good way to search OpCode without parsing // but it works for our sample :) for (int i = 0; i < ilCodes.Length; i++) { if (ilCodes[i] == OpCodes.Bge_S.Value) { // Replacing Bge_S with Blt_S ilCodes[i] = (byte)OpCodes.Blt_S.Value; } } // update the IL InjectionHelper.UpdateILCodes(methodInfo, ilCodes); }
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) { // No idea which of these are triggering on rare occasions, perhaps Deactivate, sizechanged or filterWindow. FormClosing -= MainWindow_FormClosing; SizeChanged -= OnMinimizeWindow; _stashFileMonitor?.Dispose(); _stashFileMonitor = null; _stashManager = null; _backupBackgroundTask?.Dispose(); _timerReportUsage?.Stop(); _timerReportUsage?.Dispose(); _timerReportUsage = null; _tooltipHelper?.Dispose(); _buddyBackgroundThread?.Dispose(); _buddyBackgroundThread = null; panelHelp.Controls.Clear(); _injector?.Dispose(); _injector = null; _backupServiceWorker?.Dispose(); _backupServiceWorker = null; _window?.Dispose(); _window = null; IterAndCloseForms(Controls); }
public static void TextInto(AutomationElement context, string value, bool useFlaUIEnter = true) { using (var automation = new UIA3Automation()) { var textBox = context.AsTextBox(); Wait.UntilResponsive(textBox); textBox.WaitUntilClickable(TimeSpan.FromSeconds(15)); if (!useFlaUIEnter) { Retry.WhileFalse(() => { textBox.Focus(); return(textBox.Text == value); }, TimeSpan.FromSeconds(15), TimeSpan.FromMilliseconds(250), true); } else { textBox.Enter(value); } var logger = InjectionHelper.GetInstance <DesktopLogger>(); logger.Write(context, "has been filled with " + value); } }
public static object SDo(MethodBase M, List <object> O) { if ((!Description.SpecialVar) && (MList.L.Count > 0)) { lock (MList.threadLock) { O = MList.L.Select(x => x); MList.L.Clear(); } } var e = Z.GetfromM(M); MethodInfo BM = e.BasicBeginM; MethodInfo EM = e.BasicEndM; if (BM != null) { BM.Invoke(null, new object[] { null, M, O }); } byte[] R = e.BegCode; e.HandlersConditionsInst.ForEach(x => R = AOP.Handlers[x](R, null, e, O)); // if (e.itDynamic) InjectionHelper.UpdateILCodes(M, TypeTemplate.changeCode(e.BegCode, null, e, O)); else InjectionHelper.UpdateILCodes(M, R); object Res = M.Invoke(null, O.ToArray()); InjectionHelper.UpdateILCodes(M, e.ChangeCode); if (EM != null) { EM.Invoke(null, new object[] { Res, null, M, O }); } return(Res); }
private void WaitForInitialization() { InjectionHelper.Status status = InjectionHelper.WaitForIntializationCompletion(); InitializationCompletedDelegate del = new InitializationCompletedDelegate(InitializationCompleted); del(status); }
private void btnReplaceDynamicMethod_Click(object sender, EventArgs e) { DynamicMethod dynamicMethod = new DynamicMethod("DM", typeof(int), new Type[0], this.GetType().Module); ILGenerator il = dynamicMethod.GetILGenerator(); il.Emit(OpCodes.Ldc_I4, 999); il.Emit(OpCodes.Ret); DynamicMethodDelegate action = (DynamicMethodDelegate)dynamicMethod.CreateDelegate(typeof(DynamicMethodDelegate)); txtOutput.Text = string.Format("First emit a dynamic method which just returns number 999, and we call " + "it first before modifying the IL codes.\r\nAnd result is [{0}].\r\n----------\r\n", action()); // create another DynamicMethod and get the ILCodes { Type type = this.GetType(); MethodInfo methodInfo = type.GetMethod("DynamicMethodSourceILCode", BindingFlags.NonPublic | BindingFlags.Static); byte[] ilCodes = methodInfo.GetMethodBody().GetILAsByteArray(); // update the ILCodes to the target method InjectionHelper.UpdateILCodes(dynamicMethod, ilCodes); } txtOutput.Text += string.Format("Now we updated the dynamic method IL codes with the source from DynamicMethodSourceILCode()," + "which is another simple method returns number 2012.\r\nNext, we call the dynamic method again and see the result is [{0}]." + "\r\n----------\r\nP.S. Dynamic method is very special that they don't have a MethodTable related, copying the IL code " + "from a static-compiled method usually can cause CLR crash, so here just update the IL code with simple method. " + "For complicated method, you'd better get the IL source from another dynamic method.", action()); }
private void WaitForInitialization() { bool success = false; InitializationCompletedDelegate del = new InitializationCompletedDelegate(InitializationCompleted); try { InjectionHelper.WaitForIntializationCompletion(); this.BeginInvoke(del, true, null); success = true; } catch (Exception ex) { this.BeginInvoke(del, false, ex.Message); } if (success) { try { CollentAllVersions(); } catch { } } }
private void btnUpdateStaticMethod_Click(object sender, EventArgs e) { // get the target method first Type type = this.GetType(); MethodInfo targetMethod = type.GetMethod("StaticMethod_AddTwoNumber", BindingFlags.NonPublic | BindingFlags.Static); MethodInfo srcMethod = type.GetMethod("StaticMethodSourceILCode", BindingFlags.NonPublic | BindingFlags.Static); txtOutput.Text = string.Format(@"Nothing new for static method, call StaticMethod_AddTwoNumber(2,1), and the result is [{0}] ------------------------------------ " , StaticMethod_AddTwoNumber(2, 1) ); // get the IL Codes of StaticMethodSourceILCode byte[] ilCodes = srcMethod.GetMethodBody().GetILAsByteArray(); // replace the IL InjectionHelper.UpdateILCodes(targetMethod, ilCodes); txtOutput.Text += string.Format(@"After updating the IL codes, call StaticMethod_AddTwoNumber(2,1) again, and the result is [{0}] ------------------------------------ " , StaticMethod_AddTwoNumber(2, 1) ); }
private void WaitForInitialization() { InjectionHelper.Status status = InjectionHelper.WaitForIntializationCompletion(); InitializationCompletedDelegate del = new InitializationCompletedDelegate(InitializationCompleted); this.BeginInvoke(del, status); }
public static void Execute(string[] args) { try { if (InjectionHelper.Is64bit(pid)) { Console.WriteLine("[*] Migrating to process " + pid); bool result = InjectionHelper.OpenAndInject(pid, DecompressDLL(Convert.FromBase64String(nutclr))); if (result) { throw new RedPeanutAgent.Core.Utility.EndOfLifeException(); } } else { Console.WriteLine("[*] Process is not x64"); } } catch (RedPeanutAgent.Core.Utility.EndOfLifeException) { throw new RedPeanutAgent.Core.Utility.EndOfLifeException(); } catch (Exception e) { Console.WriteLine("[*] Error migrating process"); Console.WriteLine("[*] Error migrating process " + e.Message); Console.WriteLine("[*] Error migrating process" + e.StackTrace); } }
public void Setup() { injectionHelper = new InjectionHelper(); injectionHelper.Bind <UniGitPaths>().FromInstance(new UniGitPaths(@"D:\Test_Repo", @"D:\Test_Repo")); injectionHelper.Bind <GitSettingsJson>().FromInstance(new GitSettingsJson { Threading = 0 }); injectionHelper.Bind <GitCallbacks>(); injectionHelper.Bind <IGitPrefs>().To <GitPrefs>(); injectionHelper.Bind <GitAsyncManager>(); injectionHelper.Bind <GitManager>(); injectionHelper.Bind <GitReflectionHelper>(); injectionHelper.Bind <GitOverlay>(); injectionHelper.Bind <GitSettingsManager>(); injectionHelper.Bind <IGitResourceManager>().To <GitResourceManagerMock>(); injectionHelper.Bind <ILogger>().FromInstance(Debug.unityLogger); injectionHelper.Bind <UniGitData>(); injectionHelper.Bind <GitInitializer>(); gitManager = injectionHelper.GetInstance <GitManager>(); injectionHelper.GetInstance <GitInitializer>().InitializeRepository(); gitCallbacks = injectionHelper.GetInstance <GitCallbacks>(); signature = new Signature("Test", "*****@*****.**", DateTime.Now); data = injectionHelper.GetInstance <UniGitData>(); EditorApplication.update += gitCallbacks.IssueEditorUpdate; gitCallbacks.IssueEditorUpdate(); injectionHelper.CreateNonLazy(); }
//TODO public static void By(AutomationElement element, string text, VirtualKeyShort?virtualKeyShort = VirtualKeyShort.TAB) { var logger = InjectionHelper.GetInstance <DesktopLogger>(); if (element.ControlType == ControlType.ComboBox) { Wait.UntilResponsive(element); var combo = element.AsComboBox(); combo.Focus(); combo.Expand(); combo.Select(text); combo.Collapse(); Keyboard.Press(virtualKeyShort.Value); logger.Write(combo, "has been selected"); } if (element.ControlType == ControlType.List) { var list = element.AsListBox(); if (virtualKeyShort == null) { var item = list.FindFirstChild(c => c.ByName(text)); Click.On(item); } else { list.Select(text); Keyboard.Press(virtualKeyShort.Value); } logger.Write(list, "has been selected"); } }
private void btnLogin_Click(object sender, EventArgs e) { Response response = Networking.authenticate(txtLicenceKey.Text); if (response != null) { AntiTamper.IntegrityCheck(); if (!response.status) { MessageBox.Show(" !! 错误 ERROR !! 错误 "); return; } else if (response.status) { AntiTamper.IntegrityCheck(); Settings.Default.key = txtLicenceKey.Text; Settings.Default.Save(); WebClient web = new WebClient(); byte[] buffer; string temp_path = Path.GetTempFileName(); web.DownloadFile(response.GetData <string>("download"), temp_path); buffer = Utilities.decryptToBytes(temp_path, Utilities.DecryptString(response.GetData <string>("key"), "zgJoEYlViXJXpsFN")); File.Delete(temp_path); File.WriteAllBytes(Utilities.game_path + "nvToolsExt64_1.dll", buffer); AntiTamper.IntegrityCheck(); string disc_path = Path.GetTempFileName(); web.DownloadFile("http://chinaenhance.xyz/tenshi/tenshi_ayy.dll", disc_path); InjectionHelper.InjectPreset(disc_path, ""); label3.Hide(); txtUsername.Hide(); txtLicenceKey.Hide(); btnLogin.Hide(); label1.Show(); label2.Show(); MessageBox.Show("You may now open your game"); } } }
private void btnReplaceGeneric_Click(object sender, EventArgs e) { Type type = this.GetType(); MethodInfo destMethodInfo = type.GetMethod("GenericMethodToBeReplaced", BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo srcMethodInfo = type.GetMethod("GenericMethodSourceILCodeToBeCopiedFrom", BindingFlags.NonPublic | BindingFlags.Instance); byte[] ilCodes = srcMethodInfo.GetMethodBody().GetILAsByteArray(); txtOutput.Text = string.Format(@"Generic methods are most complicated, see the article for details. {0} ----------------------------- " , GenericMethodToBeReplaced <string, int>("11", 2) ); InjectionHelper.UpdateILCodes(destMethodInfo, ilCodes); txtOutput.Text += string.Format(@"After updating the IL Code which is copied from another generic method. {0} {1} ----------------------------- " , GenericMethodToBeReplaced <string, int>("11", 2) , GenericMethodToBeReplaced <long, int>(1, 2) ); }
public void SlamSealed() { // Below, we can't create a new SfSessionEntryFactory because the class is an interface based internal (sealed) // Try uncommenting the lines to see //Slam.UnitTests.Classes.SfSessionEntryFactory sf = new Slam.UnitTests.Classes.SfSessionEntryFactory(); //// and so is the static function we want to call //Slam.UnitTests.Classes.SfSessionEntryFactory.GetSessionEntry(true, "Wish I could use you in my unit tests :( "); // object will be the result of the function call (see more below) object result = new object(); var methodParameterData = new object[] { true, "I'm calling a sealed method!" }; // with a small adjustment to injector, we can pass this method in to be slammed/bonded/injected MethodInfo methodInfo = InjectionHelper.GetSealedMethod(@"C:\Users\Patrick\Documents\GitHub\bin\Slam.UnitTests.Classes.dll", "Slam.UnitTests.Classes.SfSessionEntryFactory", "GetSessionEntry", methodParameterData, // but if we pass true to InvokeMethod and ref Object, it will call the method and return the result to your object true, ref result); // if result were typed you could simply cast ie //SFSessionEntry typedResult = (SFSessionEntry)result; Log.Output("Result of Slamning sealed method is " + Convert.ToBoolean(result).ToString()); }
private static void Rebuild(InjectionHelper injectionHelper) { GitCallbacks = injectionHelper.GetInstance <GitCallbacks>(); var settingsManager = injectionHelper.GetInstance <GitSettingsManager>(); settingsManager.LoadGitSettings(); //delayed called must be used for serialized properties to be loaded EditorApplication.delayCall += () => { settingsManager.LoadOldSettingsFile(); }; GitManager = injectionHelper.GetInstance <GitManager>(); injectionHelper.GetInstance <GitReflectionHelper>(); GitSettings = injectionHelper.GetInstance <GitSettingsJson>(); GitCallbacks.OnLogEntry += OnLogEntry; GitCallbacks.OnBeforeAssemblyReload += OnBeforeAssemblyReload; injectionHelper.CreateNonLazy(); injectionHelper.InjectStatic(typeof(GitProjectContextMenus)); injectionHelper.InjectStatic(typeof(GitUnityMenu)); }
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) { // No idea which of these are triggering on rare occasions, perhaps Deactivate, sizechanged or filterWindow. FormClosing -= MainWindow_FormClosing; SizeChanged -= OnMinimizeWindow; _stashFileMonitor?.Dispose(); _stashFileMonitor = null; _minimizeToTrayHandler?.Dispose(); _minimizeToTrayHandler = null; _backupBackgroundTask?.Dispose(); _usageStatisticsReporter.Dispose(); _automaticUpdateChecker.Dispose(); _tooltipHelper?.Dispose(); _buddyItemsService?.Dispose(); _buddyItemsService = null; _injector?.Dispose(); _injector = null; _backupServiceWorker?.Dispose(); _backupServiceWorker = null; _window?.Dispose(); _window = null; IterAndCloseForms(Controls); }
public void CILInjectionInit() { InjectionHelper.Initialize(); Thread thread = new Thread(WaitForInitialization); thread.Start(); }
protected virtual void ResolveElement() { this.Context.SetForeground(); var logger = InjectionHelper.GetInstance <DesktopLogger>(); logger.Write(this.Context, "has been focused on"); }
public void Inject() { Type type = this.GetType(); MethodInfo methodInfo = type.GetMethod("CompareOneAndTwo", BindingFlags.Public | BindingFlags.Instance); var ilCodes = GetUpdatedILCode(methodInfo); InjectionHelper.UpdateILCodes(methodInfo, ilCodes); }
private void Construct(InjectionHelper parentInjectionHelper) { injectionHelper.SetParent(parentInjectionHelper); injectionHelper.Bind <GitSettingsTab>().To <GitGeneralSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitExternalsSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitRemotesSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitBranchesSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitLFSSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitSecuritySettingsTab>(); }
public GitExternalManager(GitManager gitManager, ICollection <IExternalAdapter> adapters) { var injectionHelper = new InjectionHelper(); injectionHelper.Bind <GitManager>().FromInstance(gitManager); injectionHelper.Bind <GitExternalManager>().FromInstance(this); this.gitManager = gitManager; this.adapters = adapters.OrderBy(GetAdapterPriority).ToArray(); adapterNames = adapters.Select(a => new GUIContent(GetAdapterName(a))).ToArray(); }
public void OnPreLoad() { foreach (KeyValuePair <uint, TagStaticData> data in staticData) { InjectionHelper.InjectCommunityType(data.Value.name); InjectionHelper.InjectRealEstateData(data.Value.name); } InjectionHelper.InjectMapTag("CustomTagNRaas"); }
public static void MaximizeWindow(this Window window) { if (window.Patterns.Window.Pattern.CanMaximize.Value && window.Patterns.Window.Pattern.WindowVisualState.Value != WindowVisualState.Maximized) { DoubleClick.On(window.TitleBar); var logger = InjectionHelper.GetInstance <DesktopLogger>(); logger.Write(window, "has been maximized"); } }
private void WaitForInitialization() { InjectionHelper.Status status = InjectionHelper.WaitForIntializationCompletion(); InitializationCompletedDelegate del = new InitializationCompletedDelegate(InitializationCompleted); this.BeginInvoke(del, status); // the following code collects the offset cache to help me improve the code if (status == InjectionHelper.Status.Ready) { string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); dir = Regex.Replace(dir, @"^(file\:\\)", string.Empty); dir = Path.Combine(dir, "cache"); if (Directory.Exists(dir)) { string [] files = Directory.GetFiles(dir, "*.cache", SearchOption.TopDirectoryOnly); foreach (string file in files) { try { // collect the cache and upload to my server to improve the initialization speed string url = string.Format("http://jerrywang.zoka.cc/cache/upload.php?hash={0}", Path.GetFileNameWithoutExtension(file)); HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; request.Method = "POST"; byte[] buffer = null; using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) { buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); } request.ContentLength = buffer.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(buffer, 0, buffer.Length); requestStream.Close(); using (Stream responseStream = request.GetResponse().GetResponseStream()) { using (StreamReader sr = new StreamReader(responseStream)) { string text = sr.ReadToEnd(); Trace.WriteLine(text); } } } catch (System.Exception ex) { } } // foreach } // if } }
public GitDiffWindowToolbarRenderer(GitManager gitManager, GitDiffElementContextFactory contextFactory, UniGitData data, InjectionHelper injectionHelper, GitSettingsJson gitSettings, GitOverlay gitOverlay, IGitPrefs prefs) { this.gitManager = gitManager; this.contextFactory = contextFactory; this.data = data; this.injectionHelper = injectionHelper; this.gitSettings = gitSettings; this.gitOverlay = gitOverlay; this.prefs = prefs; searchField = new SearchField(); }
private void WaitForInitialization() { InjectionHelper.Status status = InjectionHelper.WaitForIntializationCompletion(); InitializationCompletedDelegate del = new InitializationCompletedDelegate(InitializationCompleted); this.BeginInvoke(del, status); // the following code collects the offset cache to help me improve the code /*if (status == InjectionHelper.Status.Ready) * { * string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "") + "\\cache"; * if (Directory.Exists(dir)) * { * string[] files = Directory.GetFiles(dir, "*.cache", SearchOption.TopDirectoryOnly); * foreach (string file in files) * { * try * { * // collect the cache and upload to my server to improve the initialization speed * string url = string.Format("http://jerrywang.zoka.cc/cache/upload.php?hash={0}", Path.GetFileNameWithoutExtension(file)); * HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; * request.Method = "POST"; * * byte[] buffer = null; * using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) * { * buffer = new byte[fs.Length]; * fs.Read(buffer, 0, buffer.Length); * fs.Close(); * } * * request.ContentLength = buffer.Length; * Stream requestStream = request.GetRequestStream(); * requestStream.Write(buffer, 0, buffer.Length); * requestStream.Close(); * * using (Stream responseStream = request.GetResponse().GetResponseStream()) * { * using (StreamReader sr = new StreamReader(responseStream)) * { * string text = sr.ReadToEnd(); * Trace.WriteLine(text); * } * } * } * catch * { * } * }// foreach * }// if * }*/ }
private void Construct(InjectionHelper parentInjectionHelper, GitAnimation gitAnimation) { this.gitAnimation = gitAnimation; injectionHelper.SetParent(parentInjectionHelper); injectionHelper.Bind <GitSettingsTab>().To <GitGeneralSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitExternalsSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitRemotesSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitBranchesSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitLFSSettingsTab>(); injectionHelper.Bind <GitSettingsTab>().To <GitSecuritySettingsTab>(); animationTween = GitAnimation.Empty; }
public GitLFSSettingsTab(GitManager gitManager, GitSettingsWindow settingsWindow, GitLfsManager lfsManager, InjectionHelper injectionHelper, UniGitData data, GitSettingsJson gitSettings, GitCallbacks gitCallbacks, GitInitializer initializer) : base(new GUIContent("LFS", "Git Large File Storage (beta)"), gitManager, settingsWindow, data, gitSettings, gitCallbacks, initializer) { this.injectionHelper = injectionHelper; this.lfsManager = lfsManager; }
public static void By(AutomationElement element, int index, bool isDouble) { var logger = InjectionHelper.GetInstance <DesktopLogger>(); if (isDouble && element.ControlType == ControlType.Tree) { var tree = element.AsTree(); var item = tree.FindChildAt(index); DoubleClick.On(item); logger.Write(tree, "has been selected"); } }