@@ -113,9 +113,9 @@ To clear the whole methodbody and write your instructions, make sure that you do
113
113
Here is an example:
114
114
``` cs
115
115
Instruction [] opCodes = {
116
- Instruction .Create (OpCodes .Ldstr , " Hello Sir" ), // String to print
117
- Instruction .Create (OpCodes .Call , p .BuildMemberRef ( " System " , " Console" , " WriteLine" )), // Console.WriteLine call -> BUILDMEMBERREF IS ONLY FOR CONSOLE.WRITELINE
118
- Instruction .Create (OpCodes .Ret ) // Alaway return smth
116
+ Instruction .Create (OpCodes .Ldstr , " Hello Sir" ),
117
+ Instruction .Create (OpCodes .Call , p .BuildCall ( typeof ( Console ) , " WriteLine" , typeof ( void ), new [] { typeof ( string ) })),
118
+ Instruction .Create (OpCodes .Ret )
119
119
};
120
120
Target target = new Target ()
121
121
{
@@ -326,27 +326,33 @@ PropertyMethod can be 'PropertyMethod.Get' or 'PropertyMethod.Set'.
326
326
Instructions are the new Instructions for the getter or setter.
327
327
328
328
### Building calls
329
- To build calls like "Console.WriteLine()" you can use this method:
329
+ To build calls like "Console.WriteLine(string )" you can use this method:
330
330
``` cs
331
- p .BuildMemberRef ( string , string , string , Patcher . MemberRefType );
331
+ p .BuildCall ( typeof ( Console ), " WriteLine " , typeof ( void ), new [] { typeof ( string ) })
332
332
/*
333
- * string 1 -> namespace, e.g. "System"
334
- * string 2 -> class, e.g. "Console"
335
- * string 3 -> method, e.g. "WriteLine"
336
- * MemberRefType -> the reference type, e.g. Static
333
+ * Type -> type, a Type instance
334
+ * string -> method, the name of the method
335
+ * Type -> returnType, a Type instance of the return value
336
+ * Type[] -> parameters, an array with the parameter's Types
337
337
*/
338
338
```
339
- MemberRefType is defined as follows:
340
- ``` cs
341
- public enum MemberRefType
342
- {
343
- Static ,
344
- Instance
345
- }
346
- ```
347
339
Here is an IL example for Console.WriteLine:
348
340
``` cs
349
- Instruction .Create (OpCodes .Call , p .BuildMemberRef (" System" , " Console" , " WriteLine" , Patcher .MemberRefType .Static ));
341
+ Patcher p = new Patcher (" Test.exe" );
342
+ Instruction [] opcodesConsoleWriteLine = {
343
+ Instruction .Create (OpCodes .Ldstr , " Hello Sir" ), // String to print
344
+ Instruction .Create (OpCodes .Call , p .BuildCall (typeof (Console ), " WriteLine" , typeof (void ), new [] { typeof (string ) })), // Console.WriteLine call
345
+ Instruction .Create (OpCodes .Ret ) // Always return smth
346
+ };
347
+ Target target = new Target ()
348
+ {
349
+ Namespace = " Test" ,
350
+ Class = " Program" ,
351
+ Method = " Print" ,
352
+ Instructions = opcodesConsoleWriteLine
353
+ };
354
+ p .Patch (target );
355
+ p .Save (" Test1.exe" );
350
356
```
351
357
352
358
### Injecting methods (Untested)
@@ -419,4 +425,4 @@ I'd like to thank these people:
419
425
* [ 0xd4d] ( https://github.com/0xd4d ) for creating [ dnlib] ( https://github.com/0xd4d/dnlib )
420
426
* [ 0xd4d] ( https://github.com/0xd4d ) for creating [ de4dot] ( https://github.com/0xd4d/de4dot )
421
427
* [ Rottweiler] ( https://github.com/Rottweiler ) for the PRs and help!
422
- * [ 0megaD] ( https://github.com/0megaD ) for the fixes which my eyes missed and for using dnpatch in his projects!
428
+ * [ 0megaD] ( https://github.com/0megaD ) for the fixes which my eyes missed and for using dnpatch in his projects!
0 commit comments