This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
79 lines (61 loc) · 2.49 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DisharmonyHookDetector
{
public static class Program
{
static void Main()
{
/*
* Написано на коленке за 10 минут
* Author: https://github.com/naweka
*/
Harmony h = new Harmony("a");
RuntimeHelpers.PrepareMethod(typeof(Program).GetMethod("aaa").MethodHandle);
Console.WriteLine("PREFIX before hook: " + IsHookedByHarmony(typeof(Program).GetMethod("aaa")));
// PREFIX
h.Patch(
typeof(Program).GetMethod("aaa"),
new HarmonyMethod(typeof(Program).GetMethod("bbb")));
Console.WriteLine("PREFIX after hook: " + IsHookedByHarmony(typeof(Program).GetMethod("aaa")));
h.UnpatchAll("a");
Console.WriteLine("PREFIX after unpatch (LOL): " + IsHookedByHarmony(typeof(Program).GetMethod("aaa")));
Console.WriteLine("POSTFIX before hook: " + IsHookedByHarmony(typeof(Program).GetMethod("aaa2")));
// POSTFIX
h.Patch(
typeof(Program).GetMethod("aaa2"),
null,
new HarmonyMethod(typeof(Program).GetMethod("bbb")));
Console.WriteLine("POSTFIX after hook: " + IsHookedByHarmony(typeof(Program).GetMethod("aaa2")));
h.UnpatchAll("a");
Console.WriteLine("POSTFIX after unpatch (LOL): " + IsHookedByHarmony(typeof(Program).GetMethod("aaa2")));
Console.ReadLine();
}
public static void aaa()
{
Console.WriteLine("12312312" + int.Parse("8464646"));
}
public static void aaa2()
{
Console.WriteLine("12312312" + int.Parse("8464646"));
}
public static void bbb()
{
Console.WriteLine("hi");
}
public static bool IsHookedByHarmony(MethodBase method)
{
var ptr = method.MethodHandle.GetFunctionPointer();
var first = Marshal.ReadByte(ptr);
//Console.WriteLine(first.ToString("X"));
return first == 0xE9;
}
}
}