Skip to content

Commit 1daa264

Browse files
author
Luca Marcelli
committed
Merge branch 'master' of https://github.com/ioncodes/dnpatch
2 parents 53b2119 + faa3b0b commit 1daa264

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

README.md

+25-19
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ To clear the whole methodbody and write your instructions, make sure that you do
113113
Here is an example:
114114
```cs
115115
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)
119119
};
120120
Target target = new Target()
121121
{
@@ -326,27 +326,33 @@ PropertyMethod can be 'PropertyMethod.Get' or 'PropertyMethod.Set'.
326326
Instructions are the new Instructions for the getter or setter.
327327

328328
### 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:
330330
```cs
331-
p.BuildMemberRef(string, string, string, Patcher.MemberRefType);
331+
p.BuildCall(typeof(Console), "WriteLine", typeof(void), new[] { typeof(string) })
332332
/*
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
337337
*/
338338
```
339-
MemberRefType is defined as follows:
340-
```cs
341-
public enum MemberRefType
342-
{
343-
Static,
344-
Instance
345-
}
346-
```
347339
Here is an IL example for Console.WriteLine:
348340
```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");
350356
```
351357

352358
### Injecting methods (Untested)
@@ -419,4 +425,4 @@ I'd like to thank these people:
419425
* [0xd4d](https://github.com/0xd4d) for creating [dnlib](https://github.com/0xd4d/dnlib)
420426
* [0xd4d](https://github.com/0xd4d) for creating [de4dot](https://github.com/0xd4d/de4dot)
421427
* [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

Comments
 (0)