├── .gitignore
├── CInject.Engine
├── CInject.Engine.csproj
├── CInject.Engine.csproj.user
├── CInject.Engine.csproj.vspscc
├── CInject.snk
├── Data
│ ├── Injection.cs
│ ├── MessageEventArgs.cs
│ ├── MessageType.cs
│ └── Runtime.cs
├── Extensions
│ ├── MonoExtensions.cs
│ └── ReflectionExtensions.cs
├── Properties
│ └── AssemblyInfo.cs
├── Resolvers
│ ├── BaseAssemblyResolver.cs
│ ├── MonoAssemblyResolver.cs
│ └── ReflectionAssemblyResolver.cs
├── Utils
│ ├── CacheStore.cs
│ └── MethodInjector.cs
└── packages.config
├── CInject.Injections
├── App.config
├── Attributes
│ └── DependentFiles.cs
├── CInject.Injections.csproj
├── CInject.Injections.csproj.user
├── CInject.Injections.csproj.vspscc
├── CInject.Injections.snk
├── Injectors
│ ├── LogInject.cs
│ ├── ObjectValueInject.cs
│ └── PerformanceInject.cs
├── Interfaces
│ └── ICInject.cs
├── Library
│ ├── CInjection.cs
│ ├── Converter.cs
│ ├── Logger.cs
│ ├── ReflectionHelper.cs
│ └── Serializer.cs
├── LogInject.log4net.xml
├── Models
│ └── CallInfo.cs
├── ObjectSearch.xml
├── Properties
│ └── AssemblyInfo.cs
├── obj
│ └── Debug
│ │ └── DesignTimeResolveAssemblyReferencesInput.cache
└── packages.config
├── CInject.Plugin.Sample
├── CInject.Plugin.Sample.csproj
├── CInject.Plugin.Sample.csproj.vspscc
├── CInject.snk
├── Plugin.cs
└── Properties
│ └── AssemblyInfo.cs
├── CInject.PluginInterface
├── CInject.PluginInterface.csproj
├── CInject.PluginInterface.csproj.vspscc
├── CInject.snk
├── EventType.cs
├── IPlugin.cs
├── Message.cs
└── Properties
│ └── AssemblyInfo.cs
├── CInject.SampleWPF
├── App.config
├── App.xaml
├── App.xaml.cs
├── CInject.SampleWPF.csproj
├── MainWindow.xaml
├── MainWindow.xaml.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── CInject.SampleWinform
├── CInject.SampleWinform.csproj
├── CInject.SampleWinform.csproj.vspscc
├── Form1.Designer.cs
├── Form1.cs
├── Form1.resx
├── Program.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── CInject.TargetAssembly
├── App.config
├── CInject.TargetAssembly.csproj
├── CInject.TargetAssembly.csproj.user
├── CInject.TargetAssembly.csproj.vspscc
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── TestClass.cs
├── CInject.sln
├── CInject.suo
├── CInject.vssscc
├── CInject
├── CInject.csproj
├── CInject.csproj.user
├── CInject.csproj.vspscc
├── CInject.snk
├── CInject_TemporaryKey.pfx
├── Data
│ ├── BindItem.cs
│ ├── Injection.cs
│ ├── InjectionMapping.cs
│ ├── MessageEventArgs.cs
│ ├── MessageType.cs
│ ├── Project.cs
│ ├── ProjectInjectionMapping.cs
│ └── Runtime.cs
├── Extensions
│ ├── Extensions.cs
│ ├── MonoExtensions.cs
│ └── ReflectionExtensions.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── DataSources
│ │ └── CInject.Data.InjectionMapping.datasource
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ ├── Settings.settings
│ └── app.manifest
├── Resolvers
│ ├── BaseAssemblyResolver.cs
│ ├── MonoAssemblyResolver.cs
│ └── ReflectionAssemblyResolver.cs
├── Utils
│ ├── CInjectTreeView.cs
│ ├── FileSearch.cs
│ ├── MethodInjector.cs
│ └── ObjectCache.cs
├── app.config
├── frmAbout.Designer.cs
├── frmAbout.cs
├── frmAbout.resx
├── frmMain.Designer.cs
├── frmMain.cs
├── frmMain.resx
└── packages.config
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 | [Dd]ebug/
11 | [Dd]ebugPublic/
12 | [Rr]elease/
13 | [Rr]eleases/
14 | x64/
15 | x86/
16 | build/
17 | bld/
18 | [Bb]in/
19 | [Oo]bj/
20 |
21 | # Roslyn cache directories
22 | *.ide/
23 |
24 | # MSTest test Results
25 | [Tt]est[Rr]esult*/
26 | [Bb]uild[Ll]og.*
27 |
28 | #NUNIT
29 | *.VisualState.xml
30 | TestResult.xml
31 |
32 | # Build Results of an ATL Project
33 | [Dd]ebugPS/
34 | [Rr]eleasePS/
35 | dlldata.c
36 |
37 | *_i.c
38 | *_p.c
39 | *_i.h
40 | *.ilk
41 | *.meta
42 | *.obj
43 | *.pch
44 | *.pdb
45 | *.pgc
46 | *.pgd
47 | *.rsp
48 | *.sbr
49 | *.tlb
50 | *.tli
51 | *.tlh
52 | *.tmp
53 | *.tmp_proj
54 | *.log
55 | *.vspscc
56 | *.vssscc
57 | .builds
58 | *.pidb
59 | *.svclog
60 | *.scc
61 |
62 | # Chutzpah Test files
63 | _Chutzpah*
64 |
65 | # Visual C++ cache files
66 | ipch/
67 | *.aps
68 | *.ncb
69 | *.opensdf
70 | *.sdf
71 | *.cachefile
72 |
73 | # Visual Studio profiler
74 | *.psess
75 | *.vsp
76 | *.vspx
77 |
78 | # TFS 2012 Local Workspace
79 | $tf/
80 |
81 | # Guidance Automation Toolkit
82 | *.gpState
83 |
84 | # ReSharper is a .NET coding add-in
85 | _ReSharper*/
86 | *.[Rr]e[Ss]harper
87 | *.DotSettings.user
88 |
89 | # JustCode is a .NET coding addin-in
90 | .JustCode
91 |
92 | # TeamCity is a build add-in
93 | _TeamCity*
94 |
95 | # DotCover is a Code Coverage Tool
96 | *.dotCover
97 |
98 | # NCrunch
99 | _NCrunch_*
100 | .*crunch*.local.xml
101 |
102 | # MightyMoose
103 | *.mm.*
104 | AutoTest.Net/
105 |
106 | # Web workbench (sass)
107 | .sass-cache/
108 |
109 | # Installshield output folder
110 | [Ee]xpress/
111 |
112 | # DocProject is a documentation generator add-in
113 | DocProject/buildhelp/
114 | DocProject/Help/*.HxT
115 | DocProject/Help/*.HxC
116 | DocProject/Help/*.hhc
117 | DocProject/Help/*.hhk
118 | DocProject/Help/*.hhp
119 | DocProject/Help/Html2
120 | DocProject/Help/html
121 |
122 | # Click-Once directory
123 | publish/
124 |
125 | # Publish Web Output
126 | *.[Pp]ublish.xml
127 | *.azurePubxml
128 | # TODO: Comment the next line if you want to checkin your web deploy settings
129 | # but database connection strings (with potential passwords) will be unencrypted
130 | *.pubxml
131 | *.publishproj
132 |
133 | # NuGet Packages
134 | *.nupkg
135 | # The packages folder can be ignored because of Package Restore
136 | **/packages/*
137 | # except build/, which is used as an MSBuild target.
138 | !**/packages/build/
139 | # If using the old MSBuild-Integrated Package Restore, uncomment this:
140 | #!**/packages/repositories.config
141 |
142 | # Windows Azure Build Output
143 | csx/
144 | *.build.csdef
145 |
146 | # Windows Store app package directory
147 | AppPackages/
148 |
149 | # Others
150 | sql/
151 | *.Cache
152 | ClientBin/
153 | [Ss]tyle[Cc]op.*
154 | ~$*
155 | *~
156 | *.dbmdl
157 | *.dbproj.schemaview
158 | *.pfx
159 | *.publishsettings
160 | node_modules/
161 |
162 | # RIA/Silverlight projects
163 | Generated_Code/
164 |
165 | # Backup & report files from converting an old project file
166 | # to a newer Visual Studio version. Backup files are not needed,
167 | # because we have git ;-)
168 | _UpgradeReport_Files/
169 | Backup*/
170 | UpgradeLog*.XML
171 | UpgradeLog*.htm
172 |
173 | # SQL Server files
174 | *.mdf
175 | *.ldf
176 |
177 | # Business Intelligence projects
178 | *.rdl.data
179 | *.bim.layout
180 | *.bim_*.settings
181 |
182 | # Microsoft Fakes
183 | FakesAssemblies/
184 |
--------------------------------------------------------------------------------
/CInject.Engine/CInject.Engine.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {35D6A1B5-E3E9-414E-899C-EFF310EDD009}
9 | Library
10 | Properties
11 | CInject.Engine
12 | CInject.Engine
13 | v4.6
14 | 512
15 | SAK
16 | SAK
17 | SAK
18 | SAK
19 |
20 |
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | true
39 |
40 |
41 | CInject.snk
42 |
43 |
44 |
45 | ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll
46 | True
47 |
48 |
49 | ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll
50 | True
51 |
52 |
53 | ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll
54 | True
55 |
56 |
57 | ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll
58 | True
59 |
60 |
61 | ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll
62 | True
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | {FD92845E-20BA-4519-9C70-F14A7C2D4131}
91 | CInject.Injections
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
106 |
--------------------------------------------------------------------------------
/CInject.Engine/CInject.Engine.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ShowAllFiles
5 |
6 |
--------------------------------------------------------------------------------
/CInject.Engine/CInject.Engine.csproj.vspscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10 | }
11 |
--------------------------------------------------------------------------------
/CInject.Engine/CInject.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/punitganshani/CodeInject/f3fce32f79aa1c562f18fad636ea393fcbdbf620/CInject.Engine/CInject.snk
--------------------------------------------------------------------------------
/CInject.Engine/Data/Injection.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file Injection.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using Mono.Cecil;
21 |
22 | namespace CInject.Engine.Data
23 | {
24 | public class Injection
25 | {
26 | public MethodReference Constructor { get; set; }
27 |
28 | public Type InjectionType { get; set; }
29 |
30 | public MethodReference OnInvoke { get; set; }
31 |
32 | public TypeReference TypeReference { get; set; }
33 |
34 | public MethodReference OnComplete { get; set; }
35 | }
36 | }
--------------------------------------------------------------------------------
/CInject.Engine/Data/MessageEventArgs.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file MessageEventArgs.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 |
21 | namespace CInject.Engine.Data
22 | {
23 | public class MessageEventArgs : EventArgs
24 | {
25 | public string Message { get; set; }
26 |
27 | public MessageType MessageType { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/CInject.Engine/Data/MessageType.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file MessageType.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | namespace CInject.Engine.Data
20 | {
21 | public enum MessageType
22 | {
23 | Output,
24 | Error,
25 | Warning
26 | }
27 | }
--------------------------------------------------------------------------------
/CInject.Engine/Data/Runtime.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file frmMain.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 | using System.Text;
23 |
24 | namespace CInject.Engine.Data
25 | {
26 | public enum Runtime
27 | {
28 | Net_1_0 = 0,
29 | Net_1_1 = 1,
30 | Net_2_0 = 2,
31 | Net_4_0 = 3,
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/CInject.Engine/Extensions/ReflectionExtensions.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file ReflectionExtensions.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 | using System.Reflection;
23 | using CInject.Engine.Data;
24 | using System.IO;
25 |
26 | namespace CInject.Engine.Extensions
27 | {
28 | public static class ReflectionExtensions
29 | {
30 | public static List GetType(this Assembly assembly)
31 | {
32 | //TODO: Optimize this...
33 | Type[] types = assembly.GetTypes();
34 | Type interfaceType = typeof(T);
35 |
36 | //does not work!
37 | //return types.Where(x => x.IsAssignableFrom(interfaceType)).ToList();
38 |
39 | var selected = new List();
40 |
41 | for (int x = 0; x < types.Length; x++)
42 | {
43 | var s1 = types[x].GetInterfaces();
44 | var counter = s1.Count(y => y.FullName == interfaceType.FullName);
45 |
46 | if (counter > 0)
47 | selected.Add(types[x]);
48 | }
49 |
50 | return selected;
51 | }
52 |
53 | public static Runtime GetRuntime(this Assembly assembly)
54 | {
55 | if (assembly.ImageRuntimeVersion.Contains("v1.0"))
56 | return Runtime.Net_1_0;
57 | else if (assembly.ImageRuntimeVersion.Contains("v1.1"))
58 | return Runtime.Net_1_1;
59 | else if (assembly.ImageRuntimeVersion.Contains("v2.0")
60 | || assembly.ImageRuntimeVersion.Contains("v3.0")
61 | || assembly.ImageRuntimeVersion.Contains("v3.5"))
62 | return Runtime.Net_2_0;
63 | else
64 | return Runtime.Net_4_0;
65 | }
66 |
67 | public static string GetPath(this Assembly assembly)
68 | {
69 | return new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/CInject.Engine/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
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("CInject.Engine")]
9 | [assembly: AssemblyDescription("CInject Engine")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Punit Ganshani [ www.ganshani.com ]")]
12 | [assembly: AssemblyProduct("CInject")]
13 | [assembly: AssemblyCopyright("Copyright © Punit Ganshani 2011-2013")]
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("4a787d44-5470-4060-90ba-3c8fc6d399ce")]
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.5")]
36 | [assembly: AssemblyFileVersion("1.5")]
37 |
--------------------------------------------------------------------------------
/CInject.Engine/Resolvers/BaseAssemblyResolver.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file BaseAssemblyResolver.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using CInject.Engine.Data;
21 |
22 | namespace CInject.Engine.Resolvers
23 | {
24 | public abstract class BaseAssemblyResolver
25 | {
26 | private string _path;
27 |
28 | public string Path
29 | {
30 | get { return _path; }
31 | protected set { _path = value; }
32 | }
33 |
34 | public BaseAssemblyResolver(string path)
35 | {
36 | _path = path;
37 | }
38 |
39 | public event EventHandler OnMessageReceived;
40 |
41 | public void SendMessage(string message, MessageType messageType)
42 | {
43 | if (OnMessageReceived != null)
44 | {
45 | OnMessageReceived(this, new MessageEventArgs
46 | {
47 | MessageType = messageType,
48 | Message = message
49 | });
50 | }
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/CInject.Engine/Resolvers/ReflectionAssemblyResolver.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file ReflectionAssemblyResolver.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Reflection;
22 | using CInject.Engine.Extensions;
23 | using System.IO;
24 |
25 | namespace CInject.Engine.Resolvers
26 | {
27 | public class ReflectionAssemblyResolver : BaseAssemblyResolver
28 | {
29 | private Assembly _assembly;
30 |
31 | public ReflectionAssemblyResolver(string path)
32 | : base(path)
33 | {
34 | _assembly = Assembly.LoadFrom(path);
35 | }
36 |
37 | public Assembly Assembly
38 | {
39 | get { return _assembly; }
40 | private set { _assembly = value; }
41 | }
42 |
43 | public List FindTypes()
44 | {
45 | return _assembly.GetType();
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/CInject.Engine/Utils/MethodInjector.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file MonoExtensions.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 | using CInject.Engine.Extensions;
19 | using Mono.Cecil.Cil;
20 | using Mono.Cecil;
21 |
22 | namespace CInject.Engine.Utils
23 | {
24 | public class MethodInjector
25 | {
26 | private readonly ILProcessor _ilprocessor;
27 | private readonly MethodBody _methodBody;
28 |
29 | public MethodBody MethodBody
30 | {
31 | get { return _methodBody; }
32 | }
33 |
34 | public MethodInjector(MethodDefinition method)
35 | {
36 | _methodBody = method.Body;
37 | _ilprocessor = method.Body.GetILProcessor();
38 | }
39 |
40 | public Instruction Create(OpCode opcode, VariableDefinition variable)
41 | {
42 | return _ilprocessor.Create(opcode, variable);
43 | }
44 |
45 | public void InsertBefore(Instruction target, Instruction instruction)
46 | {
47 | _ilprocessor.InsertBefore(target, instruction);
48 | UpdateReferences(target, instruction); // shift the instructions and offsets & handlers down
49 | }
50 |
51 | private void UpdateReferences(Instruction instruction, Instruction replaceBy)
52 | {
53 | if (_methodBody.Instructions.Count > 0)
54 | _methodBody.Instructions.UpdateReferences(instruction, replaceBy);
55 |
56 | if (_methodBody.ExceptionHandlers.Count > 0)
57 | _methodBody.ExceptionHandlers.UpdateReferences(instruction, replaceBy);
58 | }
59 |
60 | internal Instruction Create(OpCode opCode, ParameterDefinition parameterDefinition)
61 | {
62 | return _ilprocessor.Create(opCode, parameterDefinition);
63 | }
64 |
65 | internal Instruction Create(OpCode opCode)
66 | {
67 | return _ilprocessor.Create(opCode);
68 | }
69 |
70 | internal Instruction Create(OpCode opCode, int value)
71 | {
72 | return _ilprocessor.Create(opCode, value);
73 | }
74 |
75 | public Instruction Create(OpCode opCode, MethodReference reference)
76 | {
77 | return _ilprocessor.Create(opCode, reference);
78 | }
79 |
80 | public Instruction Create(OpCode opCode, TypeReference reference)
81 | {
82 | return _ilprocessor.Create(opCode, reference);
83 | }
84 |
85 | public Instruction Create(OpCode opCode, FieldReference reference)
86 | {
87 | return _ilprocessor.Create(opCode, reference);
88 | }
89 |
90 | public VariableDefinition AddVariable(TypeReference type)
91 | {
92 | _methodBody.InitLocals = true;
93 |
94 | VariableDefinition variable = new VariableDefinition(type);
95 | _methodBody.Variables.Add(variable);
96 |
97 | return variable;
98 | }
99 |
100 | //public PropertyDefinition AddProperty(string name, TypeReference type)
101 | //{
102 | // PropertyDefinition property = new PropertyDefinition(name, PropertyAttributes.HasDefault, type);
103 | // _ilprocessor.Create(OpCodes.
104 | //}
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/CInject.Engine/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/CInject.Injections/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/CInject.Injections/Attributes/DependentFiles.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace CInject.Injections.Attributes
7 | {
8 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited=true)]
9 | public class DependentFilesAttribute : Attribute
10 | {
11 | public string[] Files { get; set; }
12 |
13 | public DependentFilesAttribute(params string[] files)
14 | {
15 | Files = files;
16 |
17 | if (files.Length == 0)
18 | Files = new string[0];
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/CInject.Injections/CInject.Injections.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {FD92845E-20BA-4519-9C70-F14A7C2D4131}
9 | Library
10 | Properties
11 | CInject.Injections
12 | CInject.Injections
13 | v4.6
14 | 512
15 | SAK
16 | SAK
17 | SAK
18 | SAK
19 |
20 |
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | true
39 |
40 |
41 | CInject.Injections.snk
42 |
43 |
44 |
45 | ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll
46 | True
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | Code
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | Designer
75 |
76 |
77 |
78 |
79 |
80 |
81 | Always
82 |
83 |
84 | Always
85 |
86 |
87 |
88 |
89 | REM copy "$(TargetPath)" "$(SolutionDir)Test Directory\$(TargetFileName)"
90 | REM copy "$(TargetDir)$(TargetFileName).config" "$(SolutionDir)Test Directory\$(TargetFileName).config"
91 | REM copy "$(TargetDir)LogInject.log4net.xml" "$(SolutionDir)Test Directory\LogInject.log4net.xml"
92 |
93 |
94 |
95 |
102 |
--------------------------------------------------------------------------------
/CInject.Injections/CInject.Injections.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProjectFiles
5 |
6 |
--------------------------------------------------------------------------------
/CInject.Injections/CInject.Injections.csproj.vspscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10 | }
11 |
--------------------------------------------------------------------------------
/CInject.Injections/CInject.Injections.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/punitganshani/CodeInject/f3fce32f79aa1c562f18fad636ea393fcbdbf620/CInject.Injections/CInject.Injections.snk
--------------------------------------------------------------------------------
/CInject.Injections/Injectors/ObjectValueInject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using CInject.Injections.Attributes;
6 | using CInject.Injections.Interfaces;
7 | using CInject.Injections.Library;
8 | using System.IO;
9 |
10 | namespace CInject.Injections.Injectors
11 | {
12 | [DependentFiles("ObjectSearch.xml", "CInject.Injections.dll", "LogInject.log4net.xml", "log4net.dll")]
13 | public class ObjectValueInject : ICInject
14 | {
15 | public class ObjectSearch
16 | {
17 | public string[] PropertyNames;
18 | }
19 |
20 | private const string FileName = "ObjectSearch.xml";
21 | private CInjection _injection;
22 | private bool _disposed;
23 |
24 | public void OnInvoke(CInjection injection)
25 | {
26 | _injection = injection;
27 |
28 |
29 | if (!Logger.IsDebugEnabled) return;
30 | if (_injection == null) return;
31 | if (!File.Exists(FileName)) return;
32 | if (!injection.IsValid()) return;
33 |
34 | var objectSearch = CachedSerializer.Deserialize(File.ReadAllText(FileName), Encoding.UTF8);
35 | if (objectSearch == null || objectSearch.PropertyNames == null) return;
36 |
37 | foreach (string propertyName in objectSearch.PropertyNames)
38 | {
39 | var dictionary = _injection.GetPropertyValue(propertyName);
40 |
41 | foreach (var key in dictionary.Keys)
42 | {
43 | Logger.Debug(String.Format("Method {0} Argument #{1} :{2}= {3}", injection.Method.Name, key, propertyName, dictionary[key] ?? ""));
44 | }
45 | }
46 | }
47 |
48 | public void OnComplete()
49 | {
50 | //if (_injection != null && _injection.IsValid())
51 | // Logger.Info(String.Format("{0} executed in {1} mSec",
52 | // _injection.Method.Name, DateTime.Now.Subtract(_startTime).TotalMilliseconds));
53 | }
54 |
55 | ~ObjectValueInject()
56 | {
57 | if (_disposed) return;
58 |
59 | DestroyObject();
60 | }
61 |
62 | private void DestroyObject()
63 | {
64 | _injection = null;
65 | }
66 |
67 | public void Dispose()
68 | {
69 | _injection = null;
70 | _disposed = true;
71 | GC.SuppressFinalize(this);
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/CInject.Injections/Injectors/PerformanceInject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using CInject.Injections.Attributes;
6 | using CInject.Injections.Interfaces;
7 | using CInject.Injections.Library;
8 |
9 | namespace CInject.Injections.Injectors
10 | {
11 | ///
12 | /// Injector provided with CInject that logs the method execution time in milliseconds
13 | ///
14 | [DependentFiles("CInject.Injections.dll", "LogInject.log4net.xml", "log4net.dll")]
15 | public class PerformanceInject : ICInject
16 | {
17 | private DateTime _startTime;
18 | private CInjection _injection;
19 | private bool _disposed;
20 |
21 | public void OnInvoke(CInjection injection)
22 | {
23 | _injection = injection;
24 | _startTime = DateTime.Now;
25 | }
26 |
27 | public void OnComplete()
28 | {
29 | if (_injection != null && _injection.IsValid())
30 | Logger.Info(String.Format("{0} executed in {1} mSec",
31 | _injection.Method.Name, DateTime.Now.Subtract(_startTime).TotalMilliseconds));
32 | }
33 |
34 | ~PerformanceInject()
35 | {
36 | if (_disposed) return;
37 |
38 | DestroyObject();
39 | }
40 |
41 | private void DestroyObject()
42 | {
43 | _injection = null;
44 | }
45 |
46 | public void Dispose()
47 | {
48 | _injection = null;
49 | _disposed = true;
50 | GC.SuppressFinalize(this);
51 | }
52 |
53 | public string[] DependentFiles
54 | {
55 | get
56 | {
57 | return new string[]
58 | {
59 | "CInject.Injections.dll",
60 | "LogInject.log4net.xml",
61 | "log4net.dll"
62 | };
63 | }
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/CInject.Injections/Interfaces/ICInject.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file ICInject.cs is part of CInject.Injections.
6 | //
7 | // CInject.Injections is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject.Injections is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject.Injections. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using CInject.Injections.Library;
20 | using System;
21 | namespace CInject.Injections.Interfaces
22 | {
23 | public interface ICInject : IDisposable
24 | {
25 | void OnInvoke(CInjection injection);
26 | void OnComplete();
27 | }
28 | }
--------------------------------------------------------------------------------
/CInject.Injections/Library/CInjection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Reflection;
6 |
7 | namespace CInject.Injections.Library
8 | {
9 | public class CInjection
10 | {
11 | public MethodBase Method { get; set; }
12 |
13 | public Assembly ExecutingAssembly { get; set; }
14 |
15 | public object[] Arguments { get; set; }
16 |
17 | public bool IsValid()
18 | {
19 | return Method != null
20 | && ExecutingAssembly != null
21 | && Method.DeclaringType != null;
22 | }
23 |
24 | public string GetMessage(string prefix)
25 | {
26 | if (!IsValid()) return string.Empty;
27 |
28 | return String.Format("{0} {1}.{2}, {3}", prefix, Method.DeclaringType.Name, Method.Name,
29 | ExecutingAssembly.GetName().Name);
30 | }
31 |
32 | ///
33 | /// If the argument in the CInjection is a complex object (any class actually), you can get the value of
34 | /// its property
35 | ///
36 | /// Index of Argument
37 | /// Name of property
38 | /// If the argumentIndex does not exist
39 | /// Value of the property. If property is not found, it will return NULL
40 | public object GetPropertyOfArgument(int argumentIndex, string propertyName)
41 | {
42 | if (Arguments == null || string.IsNullOrEmpty(propertyName)) return null;
43 |
44 | if (Arguments.Length <= argumentIndex)
45 | throw new InvalidOperationException("ArgumentIndex does not exist in the Injection :" + argumentIndex);
46 |
47 | object argumentRequired = Arguments[argumentIndex];
48 |
49 | if (argumentRequired != null)
50 | {
51 | var property = argumentRequired.GetType().GetProperty(propertyName);
52 | if (property == null) return null;
53 | return property.GetValue(argumentRequired, null);
54 | }
55 |
56 | return null;
57 | }
58 |
59 | ///
60 | /// Scans all arguments for a PropertyName
61 | ///
62 | /// PropertyName by which the method has to search
63 | /// dictionary of argument index and property name
64 | public Dictionary GetPropertyValue(string propertyName)
65 | {
66 | var argumentsAndPropertyValues = new Dictionary();
67 | if (Arguments == null) return argumentsAndPropertyValues;
68 |
69 | for (int i = 0; i < Arguments.Length; i++)
70 | {
71 | var propertyValue = GetPropertyOfArgument(i, propertyName);
72 | if (propertyValue != null)
73 | {
74 | argumentsAndPropertyValues.Add(i, propertyValue);
75 | }
76 | }
77 |
78 | return argumentsAndPropertyValues;
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/CInject.Injections/Library/Converter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | namespace CInject.Injections.Library
4 | {
5 | internal class Converter
6 | {
7 | internal static string ToString(byte[] characters)
8 | {
9 | var encoding = new UTF8Encoding();
10 | string constructedString = encoding.GetString(characters);
11 | return (constructedString);
12 | }
13 |
14 | internal static Byte[] ToByte(string input)
15 | {
16 | var encoding = new UTF8Encoding();
17 | byte[] byteArray = encoding.GetBytes(input);
18 | return byteArray;
19 | }
20 |
21 | internal static string ToString(object value, string defaultValue)
22 | {
23 | return value == null ? defaultValue : Convert.ToString(value);
24 | }
25 |
26 | internal static object Enum(string value)
27 | {
28 | return (T)System.Enum.Parse(typeof(T), value, true);
29 | }
30 |
31 | internal static object Enum(long value)
32 | {
33 | return (T)System.Enum.Parse(typeof(T), value.ToString(), true);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/CInject.Injections/Library/Logger.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file Logger.cs is part of CInject.Injections.
6 | //
7 | // CInject.Injections is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject.Injections is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject.Injections. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System.IO;
20 | using System.Reflection;
21 | using log4net;
22 | using log4net.Config;
23 | using System;
24 |
25 | namespace CInject.Injections.Library
26 | {
27 | internal static class Logger
28 | {
29 | private static readonly ILog Log;
30 | static Logger()
31 | {
32 | if (File.Exists("LogInject.log4net.xml"))
33 | XmlConfigurator.Configure(new FileInfo("LogInject.log4net.xml"));
34 | else
35 | BasicConfigurator.Configure();
36 |
37 | Log = LogManager.GetLogger("CInject");
38 | }
39 |
40 | public static bool IsDebugEnabled
41 | {
42 | get { return Log.IsDebugEnabled; }
43 | }
44 |
45 | public static void Debug(string message)
46 | {
47 | if (Log.IsDebugEnabled)
48 | Log.Debug(message);
49 | }
50 |
51 | public static void Info(string message)
52 | {
53 | if (Log.IsInfoEnabled)
54 | Log.Info(message);
55 | }
56 |
57 | public static void Error(Exception exception)
58 | {
59 | if (Log.IsErrorEnabled)
60 | Log.Error("An error occured while logging", exception);
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/CInject.Injections/Library/ReflectionHelper.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file ReflectionHelper.cs is part of CInject.Injections.
6 | //
7 | // CInject.Injections is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject.Injections is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject.Injections. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System.Diagnostics;
20 | using System.Reflection;
21 |
22 | namespace CInject.Injections.Library
23 | {
24 | internal class ReflectionHelper
25 | {
26 | internal static string GetMethodName()
27 | {
28 | var stackTrace = new StackTrace();
29 |
30 | if (stackTrace.FrameCount > 2)
31 | return stackTrace.GetFrame(2).GetMethod().Name;
32 | else
33 | return stackTrace.GetFrame(1).GetMethod().Name;
34 | }
35 |
36 | internal static MethodBase GetCallInformation()
37 | {
38 | var stackTrace = new StackTrace();
39 |
40 | if (stackTrace.FrameCount > 2)
41 | return stackTrace.GetFrame(2).GetMethod();
42 | else
43 | return stackTrace.GetFrame(1).GetMethod();
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/CInject.Injections/Library/Serializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Xml.Serialization;
5 | using System.IO;
6 | using System.Xml;
7 |
8 | namespace CInject.Injections.Library
9 | {
10 | internal static class CachedSerializer
11 | {
12 | private static readonly Dictionary Serializer;
13 |
14 | static CachedSerializer()
15 | {
16 | Serializer = new Dictionary();
17 | }
18 |
19 | private static XmlSerializer GetSerializer()
20 | {
21 | Type type = typeof(T);
22 | if (Serializer.ContainsKey(type))
23 | return Serializer[type];
24 | else
25 | {
26 | var xs = new XmlSerializer(type);
27 | Serializer[type] = xs;
28 | return xs;
29 | }
30 | }
31 |
32 | private static XmlSerializer GetSerializer(Type type)
33 | {
34 | if (Serializer.ContainsKey(type))
35 | return Serializer[type];
36 | else
37 | {
38 | var xs = new XmlSerializer(type);
39 | Serializer[type] = xs;
40 | return xs;
41 | }
42 | }
43 |
44 | public static string Serialize(Type type, object obj, Encoding encoding)
45 | {
46 | try
47 | {
48 | string xmlString = null;
49 | var memoryStream = new MemoryStream();
50 | XmlSerializer xs = GetSerializer(type);
51 | var xmlTextWriter = new XmlTextWriter(memoryStream, encoding);
52 | xs.Serialize(xmlTextWriter, obj);
53 | memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
54 | xmlString = Converter.ToString(memoryStream.ToArray());
55 | return xmlString;
56 | }
57 | catch
58 | {
59 | throw;
60 | }
61 | }
62 |
63 | public static string Serialize(T obj, Encoding encoding)
64 | {
65 | try
66 | {
67 |
68 | string xmlString = null;
69 | var memoryStream = new MemoryStream();
70 | XmlSerializer xs = GetSerializer();
71 | var xmlTextWriter = new XmlTextWriter(memoryStream, encoding);
72 | xs.Serialize(xmlTextWriter, obj);
73 | memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
74 | xmlString = Converter.ToString(memoryStream.ToArray());
75 | return xmlString;
76 | }
77 | catch
78 | {
79 | throw;
80 | }
81 | }
82 |
83 | public static T Deserialize(string xml, Encoding encoding)
84 | {
85 | XmlSerializer xs = GetSerializer();
86 | var memoryStream = new MemoryStream(Converter.ToByte(xml));
87 | var xmlTextWriter = new XmlTextWriter(memoryStream, encoding);
88 | return (T)xs.Deserialize(memoryStream);
89 | }
90 |
91 | public static object Deserialize(Type type, string xml, Encoding encoding)
92 | {
93 | XmlSerializer xs = GetSerializer(type);
94 | var memoryStream = new MemoryStream(Converter.ToByte(xml));
95 | var xmlTextWriter = new XmlTextWriter(memoryStream, encoding);
96 | return xs.Deserialize(memoryStream);
97 | }
98 |
99 |
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/CInject.Injections/LogInject.log4net.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | `
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/CInject.Injections/Models/CallInfo.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file CallInfo.cs is part of CInject.Injections.
6 | //
7 | // CInject.Injections is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject.Injections is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject.Injections. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System.Diagnostics;
20 | using System.Reflection;
21 |
22 | namespace CInject.Injections.Models
23 | {
24 | public class CallInfo
25 | {
26 | public MethodBase CallingMethod { get; set; }
27 | public MethodBase CurrentMethod { get; set; }
28 | public StackFrame Stack { get; set; }
29 | }
30 | }
--------------------------------------------------------------------------------
/CInject.Injections/ObjectSearch.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Text
5 | Name
6 |
7 |
--------------------------------------------------------------------------------
/CInject.Injections/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file AssemblyInfo.cs is part of CInject.Injections.
6 | //
7 | // CInject.Injections is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject.Injections is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject.Injections. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System.Reflection;
20 | using System.Runtime.InteropServices;
21 |
22 | // General Information about an assembly is controlled through the following
23 | // set of attributes. Change these attribute values to modify the information
24 | // associated with an assembly.
25 |
26 | [assembly: AssemblyTitle("CInject.Injections")]
27 | [assembly: AssemblyDescription("Part of CInject (http://codeinject.codeplex.com)")]
28 | [assembly: AssemblyConfiguration("")]
29 | [assembly: AssemblyCompany("Punit Ganshani [ www.ganshani.com ]")]
30 | [assembly: AssemblyProduct("CInject")]
31 | [assembly: AssemblyCopyright("Copyright © Punit Ganshani 2011-2013")]
32 | [assembly: AssemblyTrademark("")]
33 | [assembly: AssemblyCulture("")]
34 | //[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.xml", Watch = true)]
35 |
36 | // Setting ComVisible to false makes the types in this assembly not visible
37 | // to COM components. If you need to access a type in this assembly from
38 | // COM, set the ComVisible attribute to true on that type.
39 |
40 | [assembly: ComVisible(false)]
41 |
42 | // The following GUID is for the ID of the typelib if this project is exposed to COM
43 |
44 | [assembly: Guid("7e8d75c4-5467-4dbc-b79d-a00a01945a00")]
45 |
46 | // Version information for an assembly consists of the following four values:
47 | //
48 | // Major Version
49 | // Minor Version
50 | // Build Number
51 | // Revision
52 | //
53 | // You can specify all the values or you can default the Build and Revision Numbers
54 | // by using the '*' as shown below:
55 | // [assembly: AssemblyVersion("1.0.*")]
56 |
57 | [assembly: AssemblyVersion("1.5")]
58 | [assembly: AssemblyFileVersion("1.5")]
59 |
--------------------------------------------------------------------------------
/CInject.Injections/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/punitganshani/CodeInject/f3fce32f79aa1c562f18fad636ea393fcbdbf620/CInject.Injections/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/CInject.Injections/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CInject.Plugin.Sample/CInject.Plugin.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {938CE94C-539D-48D1-9DB7-9E3EF3CE0D3A}
9 | Library
10 | Properties
11 | CInject.Plugin.Sample
12 | CInject.Plugin.SamplePlugin
13 | v4.6
14 | 512
15 | SAK
16 | SAK
17 | SAK
18 | SAK
19 |
20 |
21 | true
22 | full
23 | false
24 | ..\CInject\bin\Debug\Plugins\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | true
39 |
40 |
41 | CInject.snk
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | Code
58 |
59 |
60 |
61 |
62 |
63 | {3AF71CBE-9986-4B9C-810D-E8E4F30FEC35}
64 | CInject.PluginInterface
65 |
66 |
67 |
68 |
69 |
70 |
71 |
78 |
--------------------------------------------------------------------------------
/CInject.Plugin.Sample/CInject.Plugin.Sample.csproj.vspscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10 | }
11 |
--------------------------------------------------------------------------------
/CInject.Plugin.Sample/CInject.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/punitganshani/CodeInject/f3fce32f79aa1c562f18fad636ea393fcbdbf620/CInject.Plugin.Sample/CInject.snk
--------------------------------------------------------------------------------
/CInject.Plugin.Sample/Plugin.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using CInject.PluginInterface;
6 | using System.ComponentModel.Composition;
7 | using System.Diagnostics;
8 | using System.Windows.Forms;
9 |
10 | namespace CInject.Plugin.Sample
11 | {
12 | [Export(typeof(IPlugin))]
13 | public class SamplePlugin : IPlugin
14 | {
15 | private List _menuItems;
16 | private ToolStripItem _menuResults;
17 |
18 | public SamplePlugin()
19 | {
20 | _menuResults = new ToolStripMenuItem
21 | {
22 | Name = "toolStripSample",
23 | Text = "&Results",
24 | ShortcutKeys = Keys.Alt | Keys.B,
25 | ShowShortcutKeys = true
26 | };
27 | _menuResults.Click += new EventHandler(_menuResults_Click);
28 | _menuItems = new List { _menuResults };
29 | }
30 |
31 | public void OnStart()
32 | {
33 |
34 | }
35 |
36 | public void OnMessageReceived(EventType eventType, PluginInterface.Message message)
37 | {
38 | switch (eventType)
39 | {
40 | case EventType.ApplicationClosing:
41 | case EventType.ApplicationStarted:
42 | break;
43 | // Here Error property will be null
44 | // Only Result will be non-null
45 | MessageBox.Show("I received a injection related message: " + message.Result);
46 | case EventType.TargetAssemblyLoaded:
47 | case EventType.InjectionAssemblyLoaded:
48 | break;
49 | // Here Error property will be null
50 | // Only Result will be non-null with injector/target assembly path
51 | MessageBox.Show("I received a injection related message: " + message.Result);
52 | case EventType.MethodInjectionStart:
53 | case EventType.MethodInjectionComplete:
54 | // Here Error property will be null
55 | // Expect Target, Injector will be non-null
56 | MessageBox.Show("I received a injection related message: " + message.ToString());
57 | break;
58 | case EventType.ProcessComplete:
59 | case EventType.ProcessStart:
60 | // Here Error property will be null
61 | // Expect only the Result to be non-null
62 | MessageBox.Show("I received a process related message: " + message.Result);
63 | break;
64 | case EventType.Error:
65 | MessageBox.Show("I received an error message: " + message.Error);
66 | break;
67 | }
68 | }
69 |
70 | void _menuResults_Click(object sender, EventArgs e)
71 | {
72 | MessageBox.Show("I am clicked from menu!");
73 | }
74 |
75 | public string Name
76 | {
77 | get { return "Sample Plugin"; }
78 | }
79 |
80 | public string Version
81 | {
82 | get { return "1.0"; }
83 | }
84 |
85 | ToolStripMenuItem IPlugin.Menu
86 | {
87 | get
88 | {
89 | ToolStripMenuItem mainMenu = new ToolStripMenuItem("Sample plugin");
90 |
91 | mainMenu.DropDownItems.AddRange(_menuItems.ToArray());
92 | return mainMenu;
93 | }
94 | }
95 |
96 |
97 | public void HandleError(Exception exception)
98 | {
99 | MessageBox.Show("Unhandled exception caught :" + exception.Message);
100 | }
101 |
102 | public void OnClose()
103 | {
104 | _menuItems = null;
105 | _menuResults = null;
106 | }
107 | }
108 | }
--------------------------------------------------------------------------------
/CInject.Plugin.Sample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
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("CInject.Plugin.Sample")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Punit Ganshani [ www.ganshani.com ]")]
12 | [assembly: AssemblyProduct("CInject Plugin")]
13 | [assembly: AssemblyCopyright("Copyright © Punit Ganshani 2011-2013")]
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("c1e81b77-18fa-43b0-acc8-16a57d233760")]
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.4")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/CInject.PluginInterface/CInject.PluginInterface.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {3AF71CBE-9986-4B9C-810D-E8E4F30FEC35}
9 | Library
10 | Properties
11 | CInject.PluginInterface
12 | CInject.PluginInterface
13 | v4.6
14 | 512
15 | SAK
16 | SAK
17 | SAK
18 | SAK
19 |
20 |
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | true
39 |
40 |
41 | CInject.snk
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
72 |
--------------------------------------------------------------------------------
/CInject.PluginInterface/CInject.PluginInterface.csproj.vspscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10 | }
11 |
--------------------------------------------------------------------------------
/CInject.PluginInterface/CInject.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/punitganshani/CodeInject/f3fce32f79aa1c562f18fad636ea393fcbdbf620/CInject.PluginInterface/CInject.snk
--------------------------------------------------------------------------------
/CInject.PluginInterface/EventType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace CInject.PluginInterface
7 | {
8 | ///
9 | /// Types of events that CInject raises
10 | ///
11 | public enum EventType
12 | {
13 | ///
14 | /// Called when overall processing starts
15 | ///
16 | ProcessStart = 10,
17 | ///
18 | /// Called before an assembly method is injected
19 | ///
20 | MethodInjectionStart = 20,
21 | ///
22 | /// Called after an assembly method is injected
23 | ///
24 | MethodInjectionComplete = 30,
25 | ///
26 | /// Called when overall processing completes
27 | ///
28 | ProcessComplete = 40,
29 | ///
30 | /// Called when a target assembly is loaded
31 | ///
32 | TargetAssemblyLoaded = 50,
33 | ///
34 | /// Called when an injection assembly is loaded
35 | ///
36 | InjectionAssemblyLoaded = 60,
37 | ///
38 | /// Called when CInject application has started
39 | ///
40 | ApplicationStarted = 70,
41 | ///
42 | /// Called when CInject application is closing
43 | ///
44 | ApplicationClosing = 80,
45 |
46 | ///
47 | /// Called when an error occurs
48 | ///
49 | Error = 200
50 |
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/CInject.PluginInterface/IPlugin.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows.Forms;
6 |
7 | namespace CInject.PluginInterface
8 | {
9 | ///
10 | /// Interface that all plugins should implement
11 | ///
12 | public interface IPlugin
13 | {
14 | ///
15 | /// Name of the plugin
16 | ///
17 | string Name { get; }
18 |
19 | ///
20 | /// Version of the plugin
21 | ///
22 | string Version { get; }
23 |
24 | ///
25 | /// This menu will be displayed in CInject
26 | ///
27 | ToolStripMenuItem Menu { get; }
28 |
29 | ///
30 | /// This method will be called whenever an event will be performed by the user
31 | ///
32 | /// Type of Event
33 | /// Message details
34 | void OnMessageReceived(EventType eventType, Message message);
35 |
36 | ///
37 | /// Handles the un-handled error
38 | ///
39 | /// Unhandled exception passed by CInject application
40 | void HandleError(Exception exception);
41 |
42 | ///
43 | /// Called when the plugin is loaded
44 | ///
45 | void OnStart();
46 |
47 | ///
48 | /// Called when the plugin is unloaded (i.e. when the CInject application closes)
49 | ///
50 | void OnClose();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/CInject.PluginInterface/Message.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace CInject.PluginInterface
7 | {
8 | ///
9 | /// Events raised by CInject provide more information using Message class
10 | ///
11 | public sealed class Message
12 | {
13 | ///
14 | /// Represents the logged in user on Windows OS
15 | ///
16 | public string UserId
17 | {
18 | get { return Environment.UserName; }
19 | }
20 |
21 | ///
22 | /// Technical Exception if thrown by CInject will be caught here. This will be not-null only for EventType 'Error'
23 | ///
24 | public Exception Error { get; set; }
25 |
26 | ///
27 | /// Represents the timestamp of the event occured.
28 | ///
29 | public DateTime TimeStamp { get; set; }
30 |
31 | ///
32 | /// Result is non-null value for all events.
33 | ///
34 | public string Result { get; set; }
35 |
36 | ///
37 | /// This represents the target method for EventType MethodInjectionStart and MethodInjectionComplete
38 | ///
39 | public string Target { get; set; }
40 |
41 | ///
42 | /// This represents the injector method for EventType MethodInjectionStart and MethodInjectionComplete
43 | ///
44 | public string Injector { get; set; }
45 |
46 | public override string ToString()
47 | {
48 | StringBuilder builder = new StringBuilder();
49 | builder.AppendFormat("Result : {0}", Result).AppendLine();
50 | builder.AppendFormat("User : {0}", UserId).AppendLine();
51 | builder.AppendFormat("Target : {0}", String.IsNullOrEmpty(Target) ? "N/A" : Target).AppendLine();
52 | builder.AppendFormat("Injector : {0}", String.IsNullOrEmpty(Injector) ? "N/A" : Injector).AppendLine();
53 | builder.AppendFormat("Error : {0}", Error == null ? "N/A" : Error.Message).AppendLine();
54 | builder.AppendFormat("TimeStamp : {0}", TimeStamp).AppendLine();
55 | return builder.ToString();
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/CInject.PluginInterface/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
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("CInject.PluginInterface")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Punit Ganshani [ www.ganshani.com ]")]
12 | [assembly: AssemblyProduct("CInject Interfaces")]
13 | [assembly: AssemblyCopyright("Copyright © Punit Ganshani 2011-2013")]
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("dbff238e-0364-40dd-aaef-cdafb004c368")]
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.4")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
38 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace CInject.SampleWPF
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/CInject.SampleWPF.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {BE33811B-F71A-439B-A4F7-99B3B2002BD2}
8 | WinExe
9 | Properties
10 | CInject.SampleWPF
11 | CInject.SampleWPF
12 | v4.6
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 |
18 |
19 |
20 | AnyCPU
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | AnyCPU
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | 4.0
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | MSBuild:Compile
57 | Designer
58 |
59 |
60 | MSBuild:Compile
61 | Designer
62 |
63 |
64 | App.xaml
65 | Code
66 |
67 |
68 | MainWindow.xaml
69 | Code
70 |
71 |
72 |
73 |
74 | Code
75 |
76 |
77 | True
78 | True
79 | Resources.resx
80 |
81 |
82 | True
83 | Settings.settings
84 | True
85 |
86 |
87 | ResXFileCodeGenerator
88 | Resources.Designer.cs
89 |
90 |
91 | SettingsSingleFileGenerator
92 | Settings.Designer.cs
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
107 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace CInject.SampleWPF
17 | {
18 | ///
19 | /// Interaction logic for MainWindow.xaml
20 | ///
21 | public partial class MainWindow : Window
22 | {
23 | public MainWindow()
24 | {
25 | InitializeComponent();
26 | }
27 |
28 | private void Window_Loaded(object sender, RoutedEventArgs e)
29 | {
30 | if (string.IsNullOrEmpty(Environment.MachineName))
31 | {
32 | DoSomething();
33 | }
34 | }
35 |
36 | private void DoSomething()
37 | {
38 |
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("CInject.SampleWPF")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("CInject.SampleWPF")]
15 | [assembly: AssemblyCopyright("Copyright © 2015")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CInject.SampleWPF.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CInject.SampleWPF.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CInject.SampleWPF.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/CInject.SampleWPF/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/CInject.SampleWinform.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {1027339A-1B47-42A3-A30A-67FBE5F3CEAC}
8 | WinExe
9 | Properties
10 | CInject.SampleWinform
11 | CInject.SampleWinform
12 | v4.6
13 | 512
14 | SAK
15 | SAK
16 | SAK
17 | SAK
18 |
19 |
20 | AnyCPU
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | AnyCPU
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | Form
53 |
54 |
55 | Form1.cs
56 |
57 |
58 |
59 |
60 | Form1.cs
61 |
62 |
63 | ResXFileCodeGenerator
64 | Resources.Designer.cs
65 | Designer
66 |
67 |
68 | True
69 | Resources.resx
70 |
71 |
72 | SettingsSingleFileGenerator
73 | Settings.Designer.cs
74 |
75 |
76 | True
77 | Settings.settings
78 | True
79 |
80 |
81 |
82 |
89 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/CInject.SampleWinform.csproj.vspscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10 | }
11 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace CInject.SampleWinform
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.txtInputValue = new System.Windows.Forms.TextBox();
32 | this.btnChangeValue = new System.Windows.Forms.Button();
33 | this.label1 = new System.Windows.Forms.Label();
34 | this.lblValue = new System.Windows.Forms.Label();
35 | this.SuspendLayout();
36 | //
37 | // txtInputValue
38 | //
39 | this.txtInputValue.Location = new System.Drawing.Point(80, 14);
40 | this.txtInputValue.Name = "txtInputValue";
41 | this.txtInputValue.Size = new System.Drawing.Size(100, 20);
42 | this.txtInputValue.TabIndex = 0;
43 | //
44 | // btnChangeValue
45 | //
46 | this.btnChangeValue.Location = new System.Drawing.Point(80, 40);
47 | this.btnChangeValue.Name = "btnChangeValue";
48 | this.btnChangeValue.Size = new System.Drawing.Size(155, 23);
49 | this.btnChangeValue.TabIndex = 1;
50 | this.btnChangeValue.Text = "Print the Value in label";
51 | this.btnChangeValue.UseVisualStyleBackColor = true;
52 | this.btnChangeValue.Click += new System.EventHandler(this.btnChangeValue_Click);
53 | //
54 | // label1
55 | //
56 | this.label1.AutoSize = true;
57 | this.label1.Location = new System.Drawing.Point(12, 17);
58 | this.label1.Name = "label1";
59 | this.label1.Size = new System.Drawing.Size(37, 13);
60 | this.label1.TabIndex = 2;
61 | this.label1.Text = "Value:";
62 | //
63 | // lblValue
64 | //
65 | this.lblValue.AutoSize = true;
66 | this.lblValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
67 | this.lblValue.ForeColor = System.Drawing.Color.Red;
68 | this.lblValue.Location = new System.Drawing.Point(289, 17);
69 | this.lblValue.Name = "lblValue";
70 | this.lblValue.Size = new System.Drawing.Size(211, 20);
71 | this.lblValue.TabIndex = 3;
72 | this.lblValue.Text = "This value should change";
73 | //
74 | // Form1
75 | //
76 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
77 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
78 | this.ClientSize = new System.Drawing.Size(508, 86);
79 | this.Controls.Add(this.lblValue);
80 | this.Controls.Add(this.label1);
81 | this.Controls.Add(this.btnChangeValue);
82 | this.Controls.Add(this.txtInputValue);
83 | this.Name = "Form1";
84 | this.Text = "Form1";
85 | this.ResumeLayout(false);
86 | this.PerformLayout();
87 |
88 | }
89 |
90 | #endregion
91 |
92 | private System.Windows.Forms.TextBox txtInputValue;
93 | private System.Windows.Forms.Button btnChangeValue;
94 | private System.Windows.Forms.Label label1;
95 | private System.Windows.Forms.Label lblValue;
96 | }
97 | }
98 |
99 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Windows.Forms;
9 |
10 | namespace CInject.SampleWinform
11 | {
12 | public partial class Form1 : Form
13 | {
14 | public Form1()
15 | {
16 | InitializeComponent();
17 | }
18 |
19 | private void btnChangeValue_Click(object sender, EventArgs e)
20 | {
21 | ChangeValue(txtInputValue);
22 | }
23 |
24 | private void ChangeValue(TextBox textValue)
25 | {
26 | lblValue.Text = textValue.Text;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Windows.Forms;
5 |
6 | namespace CInject.SampleWinform
7 | {
8 | static class Program
9 | {
10 | ///
11 | /// The main entry point for the application.
12 | ///
13 | [STAThread]
14 | static void Main()
15 | {
16 | Application.EnableVisualStyles();
17 | Application.SetCompatibleTextRenderingDefault(false);
18 | Application.Run(new Form1());
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
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("CInject.SampleWinform")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Punit Ganshani [ www.ganshani.com ]")]
12 | [assembly: AssemblyProduct("CInject SampleWinform")]
13 | [assembly: AssemblyCopyright("Copyright © Punit Ganshani 2011-2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("63fdf2d6-75ef-4dab-8723-d51ba98c93cc")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.4")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18051
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CInject.SampleWinform.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CInject.SampleWinform.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18051
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CInject.SampleWinform.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/CInject.SampleWinform/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CInject.TargetAssembly/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | `
22 |
23 |
24 |
--------------------------------------------------------------------------------
/CInject.TargetAssembly/CInject.TargetAssembly.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {D242525B-148D-4AE6-AFD3-C5B58BFD2F52}
9 | Exe
10 | bin\Debug\
11 | Properties
12 | CInject.TargetAssembly
13 | CInject.TargetAssembly
14 | v4.6
15 |
16 |
17 | 512
18 | SAK
19 | SAK
20 | SAK
21 | SAK
22 |
23 |
24 | bin\Release\
25 |
26 |
27 | bin\Debug\
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | Designer
46 |
47 |
48 |
49 |
50 | {FD92845E-20BA-4519-9C70-F14A7C2D4131}
51 | CInject.Injections
52 |
53 |
54 |
55 |
56 | REM copy "$(TargetPath)" "$(SolutionDir)Test Directory\$(TargetFileName)"
57 | REM copy "$(TargetDir)$(TargetFileName).config" "$(SolutionDir)Test Directory\$(TargetFileName).config"
58 |
59 |
66 |
--------------------------------------------------------------------------------
/CInject.TargetAssembly/CInject.TargetAssembly.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProjectFiles
5 |
6 |
--------------------------------------------------------------------------------
/CInject.TargetAssembly/CInject.TargetAssembly.csproj.vspscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10 | }
11 |
--------------------------------------------------------------------------------
/CInject.TargetAssembly/Program.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file Program.cs is part of CInject.TargetAssembly.
6 | //
7 | // CInject.TargetAssembly is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject.TargetAssembly is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject.TargetAssembly. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 |
21 | namespace CInject.TargetAssembly
22 | {
23 | internal class Program
24 | {
25 | private static void Main(string[] args)
26 | {
27 | var testClass = new TestClass("TestInstance");
28 |
29 | Console.WriteLine("Test of integer param to a method. Expected value: 5 Return Value:" + testClass.Add(2, 3));
30 | Console.WriteLine("Test of double param to a method. Expected value: 4 Return Value:" + testClass.Subtract(6, 2));
31 |
32 | Console.WriteLine("Test of return value of a method. Expected value: TestInstance Return Value:" + testClass.GetName());
33 | Console.WriteLine("Test of generic parameters to a method. Expected value: TestClass Return Value:" + testClass.GetTypeName());
34 | Console.WriteLine("Test of generic parameters to a method. Expected value: TestClass Return Value:" + testClass.GetTypeName(testClass));
35 |
36 | string name = "Punit", name2 = string.Empty;
37 |
38 | Console.WriteLine("Test of ref parameters to a method. Expected value: Punit.appended Return Value:" + testClass.GetRefValue(ref name));
39 | Console.WriteLine("Test of string parameter to a method. Expected value: Work Done Return Value:" + testClass.GetStringValue("Done"));
40 |
41 | Console.WriteLine("Value of name (ref)" + name);
42 |
43 | Console.WriteLine("Test of out parameters to a method. Expected value: new Value Return Value:" + testClass.GetOutValue(out name2));
44 | Console.WriteLine("Value of name (out)" + name2);
45 |
46 | Console.WriteLine("Test of static method. Expected value: NewInstance Return Value:" + TestClass.Create().Name);
47 | Console.WriteLine("Test of array as parameter to a method. Expected value: 2 Return Value:" + testClass.GetArrayCount(new[] { "new1", "new2" }));
48 |
49 | Console.WriteLine("Test of optional parameter to a method. Expected value: 8 Return Value:" + testClass.AddOptional(3));
50 | Console.WriteLine("Test of optional parameter to a method. Expected value: 10 Return Value:" + testClass.AddOptional(3, 7));
51 |
52 |
53 |
54 | Console.WriteLine("Test call of delegate");
55 |
56 | TestClass.MyDelegate delegateDefinition = new TestClass.MyDelegate(DelegateCalled);
57 | testClass.CallDelegate(delegateDefinition);
58 |
59 | Console.WriteLine("Name is: " + testClass.NameProperty);
60 | Console.WriteLine("Press any key to exit...");
61 | Console.ReadKey();
62 | }
63 |
64 | public static void DelegateCalled()
65 | {
66 | Console.WriteLine("Delegate Called, Wonderful!");
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/CInject.TargetAssembly/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file AssemblyInfo.cs is part of CInject.TargetAssembly.
6 | //
7 | // CInject.TargetAssembly is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject.TargetAssembly is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject.TargetAssembly. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System.Reflection;
20 | using System.Runtime.InteropServices;
21 |
22 | // General Information about an assembly is controlled through the following
23 | // set of attributes. Change these attribute values to modify the information
24 | // associated with an assembly.
25 |
26 | [assembly: AssemblyTitle("CInject.TargetAssembly")]
27 | [assembly: AssemblyDescription("")]
28 | [assembly: AssemblyConfiguration("")]
29 | [assembly: AssemblyCompany("Punit Ganshani [ www.ganshani.com ]")]
30 | [assembly: AssemblyProduct("CInject TargetAssembly")]
31 | [assembly: AssemblyCopyright("Copyright © Punit Ganshani 2011-2013")]
32 | [assembly: AssemblyTrademark("")]
33 | [assembly: AssemblyCulture("")]
34 | // Setting ComVisible to false makes the types in this assembly not visible
35 | // to COM components. If you need to access a type in this assembly from
36 | // COM, set the ComVisible attribute to true on that type.
37 |
38 | [assembly: ComVisible(false)]
39 |
40 | // The following GUID is for the ID of the typelib if this project is exposed to COM
41 |
42 | [assembly: Guid("0d99ecb8-77b1-4b66-9329-be7ac08b0c1c")]
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 |
55 | [assembly: AssemblyVersion("1.4")]
56 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/CInject.TargetAssembly/TestClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using CInject.Injections.Injectors;
6 | using CInject.Injections.Library;
7 | using System.Threading;
8 |
9 | namespace CInject.TargetAssembly
10 | {
11 | public class TestClass
12 | {
13 | public string Name { get; set; }
14 | public delegate void MyDelegate();
15 |
16 | public TestClass(string name)
17 | {
18 | this.Name = name;
19 | }
20 |
21 | public string GetName()
22 | {
23 | return Name;
24 | }
25 |
26 | public string GetTypeName()
27 | {
28 | return typeof(T).Name;
29 | }
30 |
31 | public string GetTypeName(T obj)
32 | {
33 | return obj.GetType().Name;
34 | }
35 |
36 | public string GetStringValue(string name)
37 | {
38 | return "Work " + name;
39 | }
40 |
41 |
42 | public string GetRefValue(ref string name)
43 | {
44 | try
45 | {
46 | LogInject inject = new LogInject();
47 | CInjection injection = new CInjection();
48 | injection.Method = System.Reflection.MethodBase.GetCurrentMethod();
49 | injection.ExecutingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
50 | injection.Arguments = new object[] { name };
51 | inject.OnInvoke(injection);
52 | }
53 | catch { }
54 | Sleep();
55 | name += ".appended";
56 | return name;
57 | }
58 |
59 | public int GetArrayCount(string[] array)
60 | {
61 | //LogInject inject = new LogInject();
62 | //CInjection injection = new CInjection();
63 | //injection.Method = System.Reflection.MethodBase.GetCurrentMethod();
64 | //injection.ExecutingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
65 | //injection.Arguments = new object[] { array};
66 | //inject.OnInvoke(injection);
67 |
68 | if (array != null)
69 | return array.Length;
70 |
71 | return 0;
72 | }
73 |
74 | public int AddOptional(int x, int y = 5)
75 | {
76 | //LogInject inject = new LogInject();
77 | //CInjection injection = new CInjection();
78 | //injection.Method = System.Reflection.MethodBase.GetCurrentMethod();
79 | //injection.ExecutingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
80 | //injection.Arguments = new object[] { x, y };
81 | //inject.OnInvoke(injection);
82 |
83 | return x + y;
84 | }
85 |
86 | public string GetOutValue(out string name)
87 | {
88 | name = "new Value";
89 | return name;
90 | }
91 |
92 | public void CallDelegate(MyDelegate d)
93 | {
94 | d(); // call the delegate that was passed in
95 | }
96 |
97 | public void Sleep()
98 | {
99 | Thread.Sleep(1200);
100 | }
101 |
102 | public static TestClass Create()
103 | {
104 |
105 | return new TestClass("NewInstance");
106 | }
107 |
108 | public int Add(int x, int y)
109 | {
110 | Sleep();
111 | return x + y;
112 | }
113 |
114 | public double Subtract(double x, double y)
115 | {
116 | return x - y;
117 | }
118 |
119 | public string NameProperty
120 | {
121 | get
122 | {
123 | return Name;
124 | }
125 | }
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/CInject.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/punitganshani/CodeInject/f3fce32f79aa1c562f18fad636ea393fcbdbf620/CInject.suo
--------------------------------------------------------------------------------
/CInject.vssscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
10 | }
11 |
--------------------------------------------------------------------------------
/CInject/CInject.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProjectFiles
5 | C:\publish\|publish\
6 |
7 |
8 |
9 |
10 |
11 | en-US
12 | false
13 |
14 |
--------------------------------------------------------------------------------
/CInject/CInject.csproj.vspscc:
--------------------------------------------------------------------------------
1 | ""
2 | {
3 | "FILE_VERSION" = "9237"
4 | "ENLISTMENT_CHOICE" = "NEVER"
5 | "PROJECT_FILE_RELATIVE_PATH" = ""
6 | "NUMBER_OF_EXCLUDED_FILES" = "0"
7 | "ORIGINAL_PROJECT_FILE_PATH" = ""
8 | "NUMBER_OF_NESTED_PROJECTS" = "0"
9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
10 | }
11 |
--------------------------------------------------------------------------------
/CInject/CInject.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/punitganshani/CodeInject/f3fce32f79aa1c562f18fad636ea393fcbdbf620/CInject/CInject.snk
--------------------------------------------------------------------------------
/CInject/CInject_TemporaryKey.pfx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/punitganshani/CodeInject/f3fce32f79aa1c562f18fad636ea393fcbdbf620/CInject/CInject_TemporaryKey.pfx
--------------------------------------------------------------------------------
/CInject/Data/BindItem.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file BindItem.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using CInject.Engine.Resolvers;
20 | using Mono.Cecil;
21 |
22 | namespace CInject.Data
23 | {
24 | internal class BindItem
25 | {
26 | public MethodDefinition Method { get; set; }
27 | public MonoAssemblyResolver Assembly { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/CInject/Data/Injection.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file Injection.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using Mono.Cecil;
21 |
22 | namespace CInject.Data
23 | {
24 | public class Injection
25 | {
26 | public MethodReference Constructor { get; set; }
27 |
28 | public Type InjectionType { get; set; }
29 |
30 | public MethodReference OnInvoke { get; set; }
31 |
32 | public TypeReference TypeReference { get; set; }
33 |
34 | public MethodReference OnComplete { get; set; }
35 | }
36 | }
--------------------------------------------------------------------------------
/CInject/Data/InjectionMapping.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file InjectionMapping.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using CInject.Engine.Resolvers;
21 | using Mono.Cecil;
22 | using System.Xml.Serialization;
23 | using CInject.Extensions;
24 | using CInject.Engine.Extensions;
25 | using CInject.Engine.Utils;
26 |
27 | namespace CInject.Data
28 | {
29 | [Serializable]
30 | internal sealed class InjectionMapping
31 | {
32 | public InjectionMapping(MonoAssemblyResolver assembly,
33 | MethodDefinition method, Type injector)
34 | {
35 | Assembly = assembly;
36 | Method = method;
37 | Injector = injector;
38 |
39 | MethodName = method.Name;
40 | InjectorName = injector.FullName;
41 | AssemblyName = assembly.Assembly.FullName;
42 | }
43 |
44 | public MonoAssemblyResolver Assembly { get; private set; }
45 | public MethodDefinition Method { get; private set; }
46 | public Type Injector { get; private set; }
47 |
48 | public string MethodName { get; private set; }
49 | public string AssemblyName { get; private set; }
50 | public string InjectorName { get; private set; }
51 |
52 | public override int GetHashCode()
53 | {
54 | return Method.GetHashCode() + Assembly.GetHashCode() + Injector.GetHashCode();
55 | }
56 |
57 | internal static InjectionMapping FromProjectInjectionMapping(ProjectInjectionMapping projMapping)
58 | {
59 | MonoAssemblyResolver targetAssembly = null;
60 | TypeDefinition type = null;
61 | MethodDefinition method = null;
62 | Type injector = null;
63 | if (CacheStore.Exists(projMapping.TargetAssemblyPath))
64 | {
65 | targetAssembly = CacheStore.Get(projMapping.TargetAssemblyPath);
66 | }
67 | else
68 | {
69 | targetAssembly = new MonoAssemblyResolver(projMapping.TargetAssemblyPath);
70 | CacheStore.Add(projMapping.TargetAssemblyPath, targetAssembly);
71 | }
72 |
73 | string classNameKey = targetAssembly.Assembly.Name.Name + "." + projMapping.ClassName;
74 |
75 | if (CacheStore.Exists(classNameKey))
76 | {
77 | type = CacheStore.Get(classNameKey);
78 | }
79 | else
80 | {
81 | type = targetAssembly.Assembly.MainModule.GetType(classNameKey);
82 | CacheStore.Add(classNameKey, type);
83 | }
84 |
85 | if (CacheStore.Exists(classNameKey + projMapping.MethodName))
86 | {
87 | method = CacheStore.Get(classNameKey + projMapping.MethodName);
88 | }
89 | else
90 | {
91 | method = type.GetMethodDefinition(projMapping.MethodName, projMapping.MethodParameters);
92 | CacheStore.Add(classNameKey + projMapping.MethodName, method);
93 | }
94 |
95 | if (CacheStore.Exists(projMapping.InjectorType))
96 | {
97 | injector = CacheStore.Get(projMapping.InjectorType);
98 | }
99 | else
100 | {
101 | injector = Type.GetType(projMapping.InjectorType);
102 | CacheStore.Add(projMapping.InjectorType, injector);
103 | }
104 |
105 | return new InjectionMapping(targetAssembly, method, injector);
106 | }
107 | }
108 | }
--------------------------------------------------------------------------------
/CInject/Data/MessageEventArgs.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file MessageEventArgs.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 |
21 | namespace CInject.Data
22 | {
23 | public class MessageEventArgs : EventArgs
24 | {
25 | public string Message { get; set; }
26 |
27 | public MessageType MessageType { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/CInject/Data/MessageType.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file MessageType.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | namespace CInject.Data
20 | {
21 | public enum MessageType
22 | {
23 | Output,
24 | Error,
25 | Warning
26 | }
27 | }
--------------------------------------------------------------------------------
/CInject/Data/Project.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file frmMain.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 | using System.Text;
23 | using System.Xml.Serialization;
24 |
25 | namespace CInject.Data
26 | {
27 | [Serializable]
28 | public class Project
29 | {
30 | [XmlElement("ta")]
31 | public List TargetAssemblies { get; set; }
32 |
33 | [XmlElement("in")]
34 | public List Injectors { get; set; }
35 |
36 | [XmlElement("maps")]
37 | public List Mapping { get; set; }
38 |
39 | public Project()
40 | {
41 | TargetAssemblies = new List();
42 | Injectors = new List();
43 | Mapping = new List();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/CInject/Data/ProjectInjectionMapping.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file frmMain.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 | using System.Text;
23 | using CInject.Extensions;
24 | using CInject.Engine.Extensions;
25 |
26 | namespace CInject.Data
27 | {
28 | public class ProjectInjectionMapping
29 | {
30 | public string TargetAssemblyPath { get; set; }
31 | public string ClassName { get; set; }
32 | public string MethodName { get; set; }
33 | public int MethodParameters { get; set; }
34 |
35 | public string InjectorAssemblyPath { get; set; }
36 | public string InjectorType { get; set; }
37 |
38 | public ProjectInjectionMapping()
39 | {
40 |
41 | }
42 |
43 | internal static ProjectInjectionMapping FromInjectionMapping(InjectionMapping mapping)
44 | {
45 | ProjectInjectionMapping projMapping = new ProjectInjectionMapping();
46 |
47 | projMapping.ClassName = mapping.Method.DeclaringType.Name;
48 | projMapping.TargetAssemblyPath = mapping.Assembly.Path;
49 | projMapping.MethodName = mapping.Method.Name;
50 | projMapping.MethodParameters = mapping.Method.Parameters.Count;
51 |
52 | projMapping.InjectorAssemblyPath = mapping.Injector.Assembly.GetPath();
53 | projMapping.InjectorType = mapping.Injector.AssemblyQualifiedName;
54 |
55 | return projMapping;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/CInject/Data/Runtime.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file frmMain.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 | using System.Text;
23 |
24 | namespace CInject.Data
25 | {
26 | public enum Runtime
27 | {
28 | Net_1_0 = 0,
29 | Net_1_1 = 1,
30 | Net_2_0 = 2,
31 | Net_4_0 = 3,
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/CInject/Extensions/Extensions.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file Extensions.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 | using System.Windows.Forms;
23 |
24 | namespace CInject.Extensions
25 | {
26 | public static class Extensions
27 | {
28 | public static List GetCheckedNodes(this TreeNode root, Func predicate)
29 | {
30 | List items = root.GetCheckedNodes();
31 |
32 | return items.Where(predicate).ToList();
33 | }
34 |
35 | public static List GetCheckedNodes(this TreeNode root)
36 | {
37 | var types = new List();
38 |
39 | if (root.Checked && root.Tag != null)
40 | {
41 | if (root.Tag is T) // except for first node
42 | {
43 | var item = (T) root.Tag;
44 | types.Add(item);
45 | }
46 | }
47 |
48 | // check for nodes in the root node
49 | for (int i = 0; i < root.Nodes.Count; i++)
50 | {
51 | TreeNode currentNode = root.Nodes[i];
52 |
53 | if (currentNode.Checked && currentNode.Tag != null)
54 | {
55 | if (currentNode.Tag is T) // except for first node
56 | {
57 | var item = (T) currentNode.Tag;
58 | types.Add(item);
59 | }
60 | }
61 |
62 | for (int x = 0; x < currentNode.Nodes.Count; x++)
63 | {
64 | types.AddRange(currentNode.Nodes[x].GetCheckedNodes());
65 | }
66 | }
67 |
68 | return types;
69 | }
70 |
71 | public static List GetNodes(this TreeNode root, Func predicate)
72 | {
73 | List items = root.GetNodes();
74 |
75 | return items.Where(predicate).ToList();
76 | }
77 |
78 | public static List GetNodes(this TreeNode root)
79 | {
80 | var types = new List();
81 |
82 | if (root.Tag != null)
83 | {
84 | if (root.Tag is T) // except for first node
85 | {
86 | var item = (T) root.Tag;
87 | types.Add(item);
88 | }
89 | }
90 |
91 | // check for nodes in the root node
92 | for (int i = 0; i < root.Nodes.Count; i++)
93 | {
94 | TreeNode currentNode = root.Nodes[i];
95 |
96 | if (currentNode.Tag != null)
97 | {
98 | if (currentNode.Tag is T) // except for first node
99 | {
100 | var item = (T) currentNode.Tag;
101 | types.Add(item);
102 | }
103 | }
104 |
105 | for (int x = 0; x < currentNode.Nodes.Count; x++)
106 | {
107 | types.AddRange(currentNode.Nodes[x].GetNodes());
108 | }
109 | }
110 |
111 | return types;
112 | }
113 |
114 | // Updates all child tree nodes recursively.
115 | public static void CheckAllChildNodes(this TreeNode treeNode, bool nodeChecked)
116 | {
117 | foreach (TreeNode node in treeNode.Nodes)
118 | {
119 | node.Checked = nodeChecked;
120 | if (node.Nodes.Count > 0)
121 | {
122 | // If the current node has child nodes, call the CheckAllChildsNodes method recursively.
123 | node.CheckAllChildNodes(nodeChecked);
124 | }
125 | }
126 | }
127 |
128 | public static void CheckParentNode(this TreeNode treeNode, bool nodeChecked)
129 | {
130 | if (treeNode.Parent != null)
131 | {
132 | if (treeNode.Parent.Nodes.Count == 1)
133 | {
134 | treeNode.Parent.Checked = nodeChecked;
135 | }
136 | else
137 | {
138 | bool childNodeState = nodeChecked;
139 | foreach (TreeNode node in treeNode.Parent.Nodes)
140 | {
141 | childNodeState &= node.Checked;
142 | }
143 |
144 | treeNode.Parent.Checked = childNodeState;
145 | }
146 | }
147 | }
148 | }
149 | }
--------------------------------------------------------------------------------
/CInject/Extensions/ReflectionExtensions.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file ReflectionExtensions.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 | using System.Reflection;
23 | using CInject.Data;
24 | using System.IO;
25 |
26 | namespace CInject.Extensions
27 | {
28 | public static class ReflectionExtensions
29 | {
30 | public static List GetType(this Assembly assembly)
31 | {
32 | //TODO: Optimize this...
33 | Type[] types = assembly.GetTypes();
34 | Type interfaceType = typeof(T);
35 |
36 | //does not work!
37 | //return types.Where(x => x.IsAssignableFrom(interfaceType)).ToList();
38 |
39 | var selected = new List();
40 |
41 | for (int x = 0; x < types.Length; x++)
42 | {
43 | var s1 = types[x].GetInterfaces();
44 | var counter = s1.Count(y => y.FullName == interfaceType.FullName);
45 |
46 | if (counter > 0)
47 | selected.Add(types[x]);
48 | }
49 |
50 | return selected;
51 | }
52 |
53 | public static Runtime GetRuntime(this Assembly assembly)
54 | {
55 | if (assembly.ImageRuntimeVersion.Contains("v1.0"))
56 | return Runtime.Net_1_0;
57 | else if (assembly.ImageRuntimeVersion.Contains("v1.1"))
58 | return Runtime.Net_1_1;
59 | else if (assembly.ImageRuntimeVersion.Contains("v2.0")
60 | || assembly.ImageRuntimeVersion.Contains("v3.0")
61 | || assembly.ImageRuntimeVersion.Contains("v3.5"))
62 | return Runtime.Net_2_0;
63 | else
64 | return Runtime.Net_4_0;
65 | }
66 |
67 | public static string GetPath(this Assembly assembly)
68 | {
69 | return new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/CInject/Program.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file Program.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Windows.Forms;
21 | using System.ComponentModel.Composition.Hosting;
22 | using CInject.Injections.Attributes;
23 | using CInject.Injections.Injectors;
24 | using CInject.PluginInterface;
25 |
26 | namespace CInject
27 | {
28 | internal static class Program
29 | {
30 | ///
31 | /// The main entry point for the application.
32 | ///
33 | [STAThread]
34 | private static void Main()
35 | {
36 | Application.EnableVisualStyles();
37 | Application.SetCompatibleTextRenderingDefault(false);
38 |
39 | Application.Run(new frmMain());
40 | }
41 |
42 | //public IPlugin Compose()
43 | //{
44 | // var catalog = new AggregateCatalog(); //The special type of catalog that combines a number of catalogs
45 | // catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
46 | // catalog.Catalogs.Add(new DirectoryCatalog(@".\Plugins", "CInject.Plugin.*.dll"));
47 |
48 | // CompositionContainer container = new CompositionContainer(catalog);
49 |
50 | // return container.GetExportedObject();
51 | //}
52 | }
53 | }
--------------------------------------------------------------------------------
/CInject/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file AssemblyInfo.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System.Reflection;
20 | using System.Runtime.InteropServices;
21 |
22 | // General Information about an assembly is controlled through the following
23 | // set of attributes. Change these attribute values to modify the information
24 | // associated with an assembly.
25 |
26 | [assembly: AssemblyTitle("CInject")]
27 | [assembly:
28 | AssemblyDescription(
29 | "CInject allows code injection into any managed assembly without disassembling and recompiling. It makes the task of injecting any code in single or multiple methods in one or many assemblies! For more information visit http://www.ganshani.com/applications/cinject"
30 | )]
31 | [assembly: AssemblyConfiguration("")]
32 | [assembly: AssemblyCompany("Punit Ganshani [ www.ganshani.com ]")]
33 | [assembly: AssemblyProduct("CInject")]
34 | [assembly: AssemblyCopyright("Copyright © Punit Ganshani 2011-2013")]
35 | [assembly: AssemblyTrademark("")]
36 | [assembly: AssemblyCulture("")]
37 |
38 | // Setting ComVisible to false makes the types in this assembly not visible
39 | // to COM components. If you need to access a type in this assembly from
40 | // COM, set the ComVisible attribute to true on that type.
41 |
42 | [assembly: ComVisible(false)]
43 |
44 | // The following GUID is for the ID of the typelib if this project is exposed to COM
45 |
46 | [assembly: Guid("f9425320-e18f-4f16-a130-f267dbbe38c4")]
47 |
48 | // Version information for an assembly consists of the following four values:
49 | //
50 | // Major Version
51 | // Minor Version
52 | // Build Number
53 | // Revision
54 | //
55 | // You can specify all the values or you can default the Build and Revision Numbers
56 | // by using the '*' as shown below:
57 | // [assembly: AssemblyVersion("1.0.*")]
58 |
59 | [assembly: AssemblyVersion("1.5")]
60 | [assembly: AssemblyFileVersion("1.5")]
--------------------------------------------------------------------------------
/CInject/Properties/DataSources/CInject.Data.InjectionMapping.datasource:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 | CInject.Data.InjectionMapping, CInject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
10 |
--------------------------------------------------------------------------------
/CInject/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34003
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CInject.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CInject.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to There was some error loading plugins.
65 | ///
66 | internal static string PluginLoadError {
67 | get {
68 | return ResourceManager.GetString("PluginLoadError", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// Looks up a localized string similar to Some errors occured while loading plugins: .
74 | ///
75 | internal static string PluginLoadErrorAggregate {
76 | get {
77 | return ResourceManager.GetString("PluginLoadErrorAggregate", resourceCulture);
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/CInject/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | There was some error loading plugins
119 |
120 |
121 | Some errors occured while loading plugins:
122 |
123 |
--------------------------------------------------------------------------------
/CInject/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.237
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace CInject.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/CInject/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CInject/Properties/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
47 |
--------------------------------------------------------------------------------
/CInject/Resolvers/BaseAssemblyResolver.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file BaseAssemblyResolver.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using CInject.Data;
21 |
22 | namespace CInject.Resolvers
23 | {
24 | public abstract class BaseAssemblyResolver
25 | {
26 | private string _path;
27 |
28 | public string Path
29 | {
30 | get { return _path; }
31 | protected set { _path = value; }
32 | }
33 |
34 | public BaseAssemblyResolver(string path)
35 | {
36 | _path = path;
37 | }
38 |
39 | public event EventHandler OnMessageReceived;
40 |
41 | public void SendMessage(string message, MessageType messageType)
42 | {
43 | if (OnMessageReceived != null)
44 | {
45 | OnMessageReceived(this, new MessageEventArgs
46 | {
47 | MessageType = messageType,
48 | Message = message
49 | });
50 | }
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/CInject/Resolvers/ReflectionAssemblyResolver.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file ReflectionAssemblyResolver.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Reflection;
22 | using CInject.Extensions;
23 |
24 | namespace CInject.Resolvers
25 | {
26 | public class ReflectionAssemblyResolver : BaseAssemblyResolver
27 | {
28 | private Assembly _assembly;
29 |
30 | public ReflectionAssemblyResolver(string path) : base(path)
31 | {
32 | _assembly = Assembly.LoadFrom(path);
33 | }
34 |
35 | public Assembly Assembly
36 | {
37 | get { return _assembly; }
38 | private set { _assembly = value; }
39 | }
40 |
41 | internal List FindTypes()
42 | {
43 | return _assembly.GetType();
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/CInject/Utils/CInjectTreeView.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file CInjectTreeView.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System.Windows.Forms;
20 |
21 | namespace CInject.Utils
22 | {
23 | internal class CInjectTreeView : TreeView
24 | {
25 | protected override void WndProc(ref Message m)
26 | {
27 | // Filter WM_LBUTTONDBLCLK
28 | if (m.Msg != 0x203) base.WndProc(ref m);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/CInject/Utils/FileSearch.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file FileSearch.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System.Collections;
20 | using System.IO;
21 |
22 | namespace CInject.Utils
23 | {
24 | public class FileSearch
25 | {
26 | private readonly ArrayList _extensions;
27 | private bool _recursive;
28 |
29 | public FileSearch()
30 | {
31 | _extensions = ArrayList.Synchronized(new ArrayList());
32 | _recursive = true;
33 | }
34 |
35 | public ArrayList SearchExtensions
36 | {
37 | get { return _extensions; }
38 | }
39 |
40 | public bool Recursive
41 | {
42 | get { return _recursive; }
43 | set { _recursive = value; }
44 | }
45 |
46 | public FileInfo[] Search(string path)
47 | {
48 | var root = new DirectoryInfo(path);
49 | var subFiles = new ArrayList();
50 | foreach (FileInfo file in root.GetFiles())
51 | {
52 | if (_extensions.Contains(file.Extension))
53 | {
54 | subFiles.Add(file);
55 | }
56 | }
57 | if (_recursive)
58 | {
59 | foreach (DirectoryInfo directory in root.GetDirectories())
60 | {
61 | subFiles.AddRange(Search(directory.FullName));
62 | }
63 | }
64 | return (FileInfo[]) subFiles.ToArray(typeof (FileInfo));
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/CInject/Utils/MethodInjector.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file MonoExtensions.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 | using CInject.Extensions;
19 | using Mono.Cecil.Cil;
20 | using Mono.Cecil;
21 |
22 | namespace CInject.Utils
23 | {
24 | public class MethodInjector
25 | {
26 | private readonly ILProcessor _ilprocessor;
27 | private readonly MethodBody _methodBody;
28 |
29 | public MethodBody MethodBody
30 | {
31 | get { return _methodBody; }
32 | }
33 |
34 | public MethodInjector(MethodDefinition method)
35 | {
36 | _methodBody = method.Body;
37 | _ilprocessor = method.Body.GetILProcessor();
38 | }
39 |
40 | public Instruction Create(OpCode opcode, VariableDefinition variable)
41 | {
42 | return _ilprocessor.Create(opcode, variable);
43 | }
44 |
45 | public void InsertBefore(Instruction target, Instruction instruction)
46 | {
47 | _ilprocessor.InsertBefore(target, instruction);
48 | UpdateReferences(target, instruction); // shift the instructions and offsets & handlers down
49 | }
50 |
51 | private void UpdateReferences(Instruction instruction, Instruction replaceBy)
52 | {
53 | if (_methodBody.Instructions.Count > 0)
54 | _methodBody.Instructions.UpdateReferences(instruction, replaceBy);
55 |
56 | if (_methodBody.ExceptionHandlers.Count > 0)
57 | _methodBody.ExceptionHandlers.UpdateReferences(instruction, replaceBy);
58 | }
59 |
60 | internal Instruction Create(OpCode opCode, ParameterDefinition parameterDefinition)
61 | {
62 | return _ilprocessor.Create(opCode, parameterDefinition);
63 | }
64 |
65 | internal Instruction Create(OpCode opCode)
66 | {
67 | return _ilprocessor.Create(opCode);
68 | }
69 |
70 | internal Instruction Create(OpCode opCode, int value)
71 | {
72 | return _ilprocessor.Create(opCode, value);
73 | }
74 |
75 | public Instruction Create(OpCode opCode, MethodReference reference)
76 | {
77 | return _ilprocessor.Create(opCode, reference);
78 | }
79 |
80 | public Instruction Create(OpCode opCode, TypeReference reference)
81 | {
82 | return _ilprocessor.Create(opCode, reference);
83 | }
84 |
85 | public Instruction Create(OpCode opCode, FieldReference reference)
86 | {
87 | return _ilprocessor.Create(opCode, reference);
88 | }
89 |
90 | public VariableDefinition AddVariable(TypeReference type)
91 | {
92 | _methodBody.InitLocals = true;
93 |
94 | VariableDefinition variable = new VariableDefinition(type);
95 | _methodBody.Variables.Add(variable);
96 |
97 | return variable;
98 | }
99 |
100 | //public PropertyDefinition AddProperty(string name, TypeReference type)
101 | //{
102 | // PropertyDefinition property = new PropertyDefinition(name, PropertyAttributes.HasDefault, type);
103 | // _ilprocessor.Create(OpCodes.
104 | //}
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/CInject/Utils/ObjectCache.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file frmMain.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 | using System.Text;
23 | using CInject.Data;
24 |
25 | namespace CInject.Utils
26 | {
27 | public static class ObjectCache
28 | {
29 | private static Dictionary _cacheObjects;
30 | static ObjectCache()
31 | {
32 | _cacheObjects = new Dictionary();
33 | }
34 |
35 | public static T Add(string key, T data)
36 | {
37 | lock (_cacheObjects)
38 | {
39 | if (_cacheObjects.ContainsKey(key))
40 | {
41 | lock (_cacheObjects)
42 | {
43 | _cacheObjects[key] = data;
44 | }
45 | }
46 | else
47 | {
48 | lock (_cacheObjects)
49 | {
50 | _cacheObjects.Add(key, data);
51 | }
52 | }
53 | }
54 |
55 | return data;
56 | }
57 |
58 | public static bool ContainsKey(string key)
59 | {
60 | lock (_cacheObjects)
61 | {
62 | return _cacheObjects.ContainsKey(key);
63 | }
64 | }
65 |
66 | public static T Get(string key)
67 | {
68 | if (_cacheObjects.ContainsKey(key))
69 | return (T)_cacheObjects[key];
70 |
71 | throw new KeyNotFoundException(@"Key not found:" + key);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/CInject/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CInject/frmAbout.cs:
--------------------------------------------------------------------------------
1 | #region GNU GPL Version 3 License
2 |
3 | // Copyright 2011 Punit Ganshani
4 | //
5 | // This file frmAbout.cs is part of CInject.
6 | //
7 | // CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
8 | //
9 | // CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
12 | //
13 | // History:
14 | // ______________________________________________________________
15 | // Created 09-2011 Punit Ganshani
16 |
17 | #endregion
18 |
19 | using System;
20 | using System.IO;
21 | using System.Reflection;
22 | using System.Windows.Forms;
23 |
24 | namespace CInject
25 | {
26 | internal partial class frmAbout : Form
27 | {
28 | public frmAbout()
29 | {
30 | InitializeComponent();
31 | Text = String.Format("About {0}", AssemblyTitle);
32 | labelProductName.Text = AssemblyProduct;
33 | labelVersion.Text = String.Format("Version {0}", AssemblyVersion);
34 | labelCopyright.Text = AssemblyCopyright;
35 | labelCompanyName.Text = AssemblyCompany;
36 | textBoxDescription.Text = AssemblyDescription;
37 | }
38 |
39 | #region Assembly Attribute Accessors
40 |
41 | public string AssemblyTitle
42 | {
43 | get
44 | {
45 | object[] attributes =
46 | Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyTitleAttribute), false);
47 | if (attributes.Length > 0)
48 | {
49 | var titleAttribute = (AssemblyTitleAttribute) attributes[0];
50 | if (titleAttribute.Title != "")
51 | {
52 | return titleAttribute.Title;
53 | }
54 | }
55 | return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
56 | }
57 | }
58 |
59 | public string AssemblyVersion
60 | {
61 | get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
62 | }
63 |
64 | public string AssemblyDescription
65 | {
66 | get
67 | {
68 | object[] attributes =
69 | Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyDescriptionAttribute), false);
70 | if (attributes.Length == 0)
71 | {
72 | return "";
73 | }
74 | return ((AssemblyDescriptionAttribute) attributes[0]).Description;
75 | }
76 | }
77 |
78 | public string AssemblyProduct
79 | {
80 | get
81 | {
82 | object[] attributes =
83 | Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyProductAttribute), false);
84 | if (attributes.Length == 0)
85 | {
86 | return "";
87 | }
88 | return ((AssemblyProductAttribute) attributes[0]).Product;
89 | }
90 | }
91 |
92 | public string AssemblyCopyright
93 | {
94 | get
95 | {
96 | object[] attributes =
97 | Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyCopyrightAttribute), false);
98 | if (attributes.Length == 0)
99 | {
100 | return "";
101 | }
102 | return ((AssemblyCopyrightAttribute) attributes[0]).Copyright;
103 | }
104 | }
105 |
106 | public string AssemblyCompany
107 | {
108 | get
109 | {
110 | object[] attributes =
111 | Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyCompanyAttribute), false);
112 | if (attributes.Length == 0)
113 | {
114 | return "";
115 | }
116 | return ((AssemblyCompanyAttribute) attributes[0]).Company;
117 | }
118 | }
119 |
120 | #endregion
121 | }
122 | }
--------------------------------------------------------------------------------
/CInject/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | CodeInject
2 | ==========
3 |
4 | [](https://ci.appveyor.com/project/punitganshani/codeinject)
5 |
6 | CodeInject - Code Inject and Runtime Intelligence
7 |
8 | CInject (or CodeInject) allows code injection into any managed assembly without disassembling and recompiling it. It eases the inevitable task of injecting any code in single or multiple methods in one or many assemblies to intercept code for almost any purpose.
9 |
10 | When using CInject, you do not require any knowledge of the target application. You can create your own injectors very easily and inject them in any target assembly/executable. An example is provided with this application. If you have an existing code which has no logging or no diagnostics, inject it with CInject and execute it as usual to generate log files. **Helps you analyze any code and ease your reverse engineering exercise.**
11 |
12 | Provides **runtime intelligence** such as
13 |
14 | - Values of arguments to the called function
15 | - Object life time of a method / variables called within the method
16 | - Allows customization of logging or diagnostics
17 | - Allows extension of injectors to tailor your own solution as the need be
18 | - Measure the method execution time to check performance
19 |
20 | Build your own **plugins** using CInject information
21 |
22 | * CInject supports building your own plugins
23 | * The plugin receives information from the application such as
24 | * Target assembly & method
25 | * Injector assembly & method
26 | * Processing details, results with timestamp
27 | * Exceptions and errors
28 | * Customized Plugin menu in CInject application
29 |
30 | ## FAQ
31 |
32 | **Can I use it in my organization?**
33 | Yes, you can use it.
34 |
35 | **I have some doubts, how can I ask?**
36 | Please use the 'Issues' tab
37 |
38 | **Do I get to know the value of arguments at runtime?**
39 | Yes, that's the actual beauty of CInject. It lets you know the value of arguments to a function at runtime.
40 |
41 | **Can I inject static methods?**
42 | Yes. In the current release, you can call create a class that implements ICInject interface and call static methods. In later release, provision for calling static methods directly will be added as well.
43 |
44 | **What version of .NET is this built on? Can I use it with other versions?**
45 | CInject is built on .NET 4.0 runtime. To use it with other versions, rebuild the Injectors, or create your own using .NET 2.0, 3.0, 3.5.
46 |
47 | **How do I distribute my plugin?**
48 | You have many alternatives to distribute the plugin
49 |
50 | - Host the source code on CodePlex and link it with this project
51 | - Provide the source code, and get it hosted on this webpage & www.ganshani.com website
52 | - Host the source code on GitHub, or other repository websites and provide us the link for promotion purposes
53 |
54 | **How about code injection at compile time?**
55 | If you are looking at dynamic injection based on the code you have written in an assembly, it would be worth while trying [dI.Hook](https://github.com/punitganshani/dI.Hook) You can define the injections (or called hooks) in configuration file and invoke them wherever required.
56 |
--------------------------------------------------------------------------------