Created
December 14, 2022 21:29
-
-
Save smx-smx/dc548226bcae16b57f9e6a44ca9d5f99 to your computer and use it in GitHub Desktop.
GetEntryAssembly override
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static unsafe void ReplaceGetEntryAssembly() { | |
MethodInfo methodToReplace = typeof(Assembly).GetMethod("GetEntryAssembly", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); | |
MethodInfo methodToInject = typeof(EzDotnetCompat).GetMethod("MyGetEntryAssembly", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); | |
RuntimeHelpers.PrepareMethod(methodToReplace.MethodHandle); | |
RuntimeHelpers.PrepareMethod(methodToInject.MethodHandle); | |
long* inj = (long*)methodToInject.MethodHandle.Value.ToPointer() + 1; | |
long* tar = (long*)methodToReplace.MethodHandle.Value.ToPointer() + 1; | |
byte* injInst = (byte*)*inj; | |
byte* tarInst = (byte*)*tar; | |
int* injSrc = (int*)(injInst + 1); | |
int* tarSrc = (int*)(tarInst + 1); | |
*tarSrc = (((int)injInst + 5) + *injSrc) - ((int)tarInst + 5); | |
} | |
private static Assembly MyGetEntryAssembly() { | |
return typeof(Program).Assembly; | |
} | |
public static void InstallHooks() { | |
// this is required for Log4Net to function properly | |
ReplaceGetEntryAssembly(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment