Created
October 19, 2016 03:02
-
-
Save toptensoftware/975dffc7d1645312552ff077fbb93ef2 to your computer and use it in GitHub Desktop.
Creating thunks for exported methods
This file contains hidden or 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
| // Create thunks for all exported methods | |
| foreach (var mi in this.GetType().GetMethods()) | |
| { | |
| // Check it has an EntryPoint attribute | |
| var ep = mi.GetCustomAttributes<EntryPointAttribute>().FirstOrDefault(); | |
| if (ep==null) | |
| continue; | |
| // Create a system thunk for it | |
| var vmptr = _machine.CreateSystemThunk(() => { | |
| // When thunk called, use reflection to call the method | |
| mi.Invoke(this); | |
| }); | |
| // Connect the ordinal and the thunk (GetProcAddress will | |
| // return this ‘vmptr’ when asked for ordinal ‘ep.ordinal’) | |
| _mapProcAddress[ep.ordinal] = vmptr; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment