Skip to content

Commit 2b7ff9c

Browse files
author
ion
committed
Init
1 parent 4f4a6f5 commit 2b7ff9c

16 files changed

+691
-31
lines changed

Example/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>

Example/Example.csproj

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{B38BB1AE-DE16-41F1-926F-A1DA233B0A30}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Example</RootNamespace>
11+
<AssemblyName>Example</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="dnlib">
37+
<HintPath>..\dnlib.dll</HintPath>
38+
</Reference>
39+
<Reference Include="System" />
40+
<Reference Include="System.Core" />
41+
<Reference Include="System.Xml.Linq" />
42+
<Reference Include="System.Data.DataSetExtensions" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Data" />
45+
<Reference Include="System.Net.Http" />
46+
<Reference Include="System.Xml" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="Program.cs" />
50+
<Compile Include="Properties\AssemblyInfo.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<None Include="App.config" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<ProjectReference Include="..\dnpatch\dnpatch.csproj">
57+
<Project>{14ca7a28-7fa8-40a0-abc6-81e9f36318de}</Project>
58+
<Name>dnpatch</Name>
59+
</ProjectReference>
60+
</ItemGroup>
61+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
62+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
63+
Other similar extension points exist, see Microsoft.Common.targets.
64+
<Target Name="BeforeBuild">
65+
</Target>
66+
<Target Name="AfterBuild">
67+
</Target>
68+
-->
69+
</Project>

Example/Program.cs

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using dnlib.DotNet;
7+
using dnlib.DotNet.Emit;
8+
using dnpatch;
9+
10+
namespace Example
11+
{
12+
class Program
13+
{
14+
static void Main(string[] args)
15+
{
16+
/*
17+
* Replaces all instructions with your own body
18+
*/
19+
Patcher p = new Patcher("Test.exe");
20+
Instruction[] opcodesConsoleWriteLine = {
21+
Instruction.Create(OpCodes.Ldstr, "Hello Sir"), // String to print
22+
Instruction.Create(OpCodes.Call, p.BuildMemberRef("System", "Console", "WriteLine")), // Console.WriteLine call
23+
Instruction.Create(OpCodes.Ret) // Alaway return smth
24+
};
25+
Target target = new Target()
26+
{
27+
Namespace = "Test",
28+
Class = "Program",
29+
Method = "Print",
30+
Instructions = opcodesConsoleWriteLine
31+
};
32+
p.Patch(target);
33+
p.Save("Test1.exe");
34+
35+
36+
/*
37+
* Replaces the instructions at the given index
38+
*/
39+
p = new Patcher("Test.exe");
40+
Instruction[] opCodesManipulateOffset = {
41+
Instruction.Create(OpCodes.Ldstr, "Place easter egg here 1"),
42+
Instruction.Create(OpCodes.Ldstr, "Place easter egg here 2")
43+
};
44+
int[] indexes = {
45+
4,
46+
8
47+
};
48+
target = new Target()
49+
{
50+
Namespace = "Test",
51+
Class = "Program",
52+
Method = "PrintAlot",
53+
Instructions = opCodesManipulateOffset,
54+
Indexes = indexes
55+
};
56+
p.Patch(target);
57+
p.Save("Test2.exe");
58+
59+
60+
/*
61+
* Replaces the instructions at the given index in a nested class
62+
*/
63+
p = new Patcher("Test.exe");
64+
Instruction opCodeManipulateOffsetNestedClass = Instruction.Create(OpCodes.Ldstr, "FooBarCode");
65+
int index = 0;
66+
string nestedClass = "Bar";
67+
target = new Target()
68+
{
69+
Namespace = "Test",
70+
Class = "Foo",
71+
NestedClass = nestedClass,
72+
Method = "NestedPrint",
73+
Instruction = opCodeManipulateOffsetNestedClass,
74+
Index = index
75+
};
76+
p.Patch(target);
77+
p.Save("Test3.exe");
78+
79+
80+
/*
81+
* Replaces the instructions at the given index in a big nested class
82+
*/
83+
p = new Patcher("Test.exe");
84+
Instruction opCodeManipulateOffsetNestedClasses = Instruction.Create(OpCodes.Ldstr, "Eat fruits");
85+
index = 0;
86+
string[] nestedClasses = {
87+
"Am",
88+
"A",
89+
"Burger"
90+
};
91+
target = new Target()
92+
{
93+
Namespace = "Test",
94+
Class = "I",
95+
NestedClasses = nestedClasses,
96+
Method = "Eat",
97+
Instruction = opCodeManipulateOffsetNestedClasses,
98+
Index = index
99+
};
100+
p.Patch(target);
101+
p.Save(true);
102+
}
103+
}
104+
}

Example/Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Example")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Example")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("b38bb1ae-de16-41f1-926f-a1da233b0a30")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Test/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>

Test/Foo.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Test
8+
{
9+
class Foo
10+
{
11+
public class Bar
12+
{
13+
public void NestedPrint()
14+
{
15+
Console.WriteLine("Coded with Swag");
16+
}
17+
}
18+
}
19+
}

Test/I.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Test
8+
{
9+
class I
10+
{
11+
public class Am
12+
{
13+
public class A
14+
{
15+
public class Burger
16+
{
17+
public void Eat()
18+
{
19+
Console.WriteLine("Eating... Hold on.");
20+
}
21+
}
22+
}
23+
}
24+
}
25+
}

Test/Program.cs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Test
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
Print();
14+
Check(10);
15+
PrintAlot();
16+
Foo.Bar foobar = new Foo.Bar();
17+
foobar.NestedPrint();
18+
I.Am.A.Burger burger = new I.Am.A.Burger();
19+
burger.Eat();
20+
Console.Read();
21+
}
22+
23+
static void Print()
24+
{
25+
Console.WriteLine("Hello");
26+
}
27+
28+
static void Check(int i)
29+
{
30+
Console.WriteLine(i > 0 ? "Error" : "Secret Key Here");
31+
}
32+
33+
static void PrintAlot()
34+
{
35+
Console.WriteLine("Hello");
36+
Console.WriteLine("Hello");
37+
Console.WriteLine("Hello");
38+
Console.WriteLine("Hello");
39+
Console.WriteLine("Hello");
40+
Console.WriteLine("Hello");
41+
Console.WriteLine("Hello");
42+
Console.WriteLine("Hello");
43+
}
44+
}
45+
}

Test/Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Test")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Test")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("773f8b20-46d8-4dcc-a146-92e92e8b76f5")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)