pardeike / Harmony

A library for patching, replacing and decorating .NET and Mono methods during runtime
https://www.patreon.com/pardeike
MIT License
5.15k stars 485 forks source link

Any restriction to hook .Net service? #567

Closed yangboyd closed 7 months ago

yangboyd commented 7 months ago

Hook fail, No log file generated.

pardeike commented 7 months ago

More information please

yangboyd commented 7 months ago

The code hang at line: type.GetCustomAttributes(true). HarmonyLib.HarmonyMethodExtensions ///

Gets all annotations on a class/type /// The class/type /// A list of all // Token: 0x060001F4 RID: 500 RVA: 0x0000B51C File Offset: 0x0000971C public static List GetFromType(Type type) { return (from attr in type.GetCustomAttributes(true)<<<<=============== select HarmonyMethodExtensions.GetHarmonyMethodInfo(attr) into info where info != null select info).ToList(); }

pardeike commented 7 months ago

Do you have a stacktrace? What .NET version? What Harmony version? What operating system? On what hardware? Is this for a game or a web server container? When do you start the patch operation? Could it be that the class that contains the method you want to patch has a static initializer that runs when you patch the method but that is not suppose to run so early?

Answer to all questions are required or else I can’t help

yangboyd commented 7 months ago

More info: Harmony 2.1.0. .Net 4.3 Windows 10. X86_64 web server. Use Extreme Injector v3 , follow this sample https://github.com/AmmarHourani/Simple-Harmony-2.

The target function is in a dll. Succeed bypassing this error by manual load and manual patch. The patch seems OK, but not triggered. The call stack in dnSpy is like this: 捕获

It looks like the target method is called in unnormal way. Fail to get the original method. How to locate the original method? Can this kind of method be hooked?

pardeike commented 7 months ago

There are few possible reasons why your patch isn’t called: 1) the original method is too short and is inclined at runtime 2) due to this being a webserver things that normally work can be quite restricted due to security reasons 3) you are using an outdated Harmony version

yangboyd commented 7 months ago

The call stack is the way how the original method is called. It's called via reflection. Our hook is implemented via reflection too? Maybe they conflicted.

pardeike commented 7 months ago

Calling methods via reflection does not prevent patches to run.

yangboyd commented 7 months ago

Fixed, It's the app domain isolation, need inject to the specific app domain.

pardeike commented 7 months ago

Yeah, see my second guess. Nice