Answered by:
How to inject code into assembly ?

Question
-
Hi
i want to inject some code into .net assemblies. i've used reflector(and reflexil) but it can only change an existing code, wheras i want to add a new class or change class,enum, ... behaviaour.
Any help would be great appreciated.
thanks
this is my Signature
Answers
-
Modifying the assembly directly is not something you should be pursue if you want to get this done before you graduate. Leverage existing .NET tools. Disassemble the assembly first with ildasm.exe, now it becomes a text parsing effort. Put humpty-dumpty back together with ilasm.exe. An open source project that injects code is Spring.NET.
Hans Passant.
All replies
-
How about using extension methods? (see link below)
http://msdn.microsoft.com/en-us/library/bb383977.aspx -
How about using extension methods? (see link below)
http://msdn.microsoft.com/en-us/library/bb383977.aspx
No, i want to create a new class or change an existing code. it's my school project.
this is my Signature -
You can use the Profiling API to add behavior, like this: http://www.codeproject.com/KB/cs/IL_Rewriting.aspx
Mark the best replies as answers! -
You can use the Profiling API to add behavior, like this: http://www.codeproject.com/KB/cs/IL_Rewriting.aspx
Mark the best replies as answers!
Thanks Daniel
But apparently, it used unmanaged code. can u tell me an easier way ? (to inject .net code into assembly)
thanks again
this is my Signature -
Modifying the assembly directly is not something you should be pursue if you want to get this done before you graduate. Leverage existing .NET tools. Disassemble the assembly first with ildasm.exe, now it becomes a text parsing effort. Put humpty-dumpty back together with ilasm.exe. An open source project that injects code is Spring.NET.
Hans Passant. -
Modifying the assembly directly is not something you should be pursue if you want to get this done before you graduate. Leverage existing .NET tools. Disassemble the assembly first with ildasm.exe, now it becomes a text parsing effort. Put humpty-dumpty back together with ilasm.exe. An open source project that injects code is Spring.NET.
Hans Passant.
Thanks Hans
would u plz provide me a link ?
this is my Signature -