clr

modify the assembly on runtime?

戏子无情 提交于 2019-12-02 04:28:35
问题 how can i modify memory loaded methods in given assembly so that clr when instantiates new objects for some class it makes new objects with modified code in it? 回答1: You can use Mono Cecil to modify the assembly before you load it. You can save the modified assembly to a byte array, then call Assembly.Load to load the byte array. 回答2: I don't think you can do that. But you can generate new classes in a new, in-memory assembly using Reflection.Emit. That is a lot of work though. You can get

Linking to static lib with managed components

自闭症网瘾萝莉.ら 提交于 2019-12-02 02:13:33
After creating a GUI for my personal little application, I am trying to compile it as a static library to use in another project. The GUI is created and has other tasks performed with it through a managed public ref class that currently only has 5 functions, but will be added to. This is my header file in the static library that would be included in the other project (well, at least a new one with only the public functions, all the extra stuff would be removed); #ifndef GUIInterface_H #define GUIInterface_H #include #include "MainForm.h" using namespace System; using namespace System:

How you use technique (described) to work with C structures and pointers from .Net?

余生长醉 提交于 2019-12-02 01:42:01
How you use technique described here to work with C structures from .Net? Ofcourse I need a code example - on 3 parts: C declaring parts, C++ wrapping around C and C# acsessing. So what I wonder Is C structture A has as one of its params structure B which consists of at least 2 types one of which is pointer to some variable C which should be declared. We whant to have access from C# .Net to all A and B structures and its params and that variable C. How to do such thing? Hamid Nazari Suppose these are the C structs in a file named structs.h struct StructB { int bMember1; int bMember2; int*

Load assemblies with dependencies in a different AppDomain

左心房为你撑大大i 提交于 2019-12-02 00:21:58
问题 My aim is to make a missing dependency check between 2 given folders. Imagine the following setup. Root\DirA\A.dll Root\DirB\B.dll B depends on A. So given these folders, I want to create a new AppDomain, load B.dll and have the dependency from DirA(A.dll) automatically resolved and isolated in that new AppDomain. Isolation is key here given that when I unload this AppDomain I want to create a new one with potentially DirA as a dependency again but DirC libraries that require it so in the

Read/Get TypeRef table from assembly metadata

…衆ロ難τιáo~ 提交于 2019-12-01 23:46:26
This is a follow-up question to THIS one: To analyze an assembly (or the types it ueses) I would like to read the TypeRef table of such assembly. I got the hint to use Mono.Cecil to do this, but I only found examples reading TypeDef information. Also browsing the source-code of cecil I only found internal classes which seems to me are responsible for reading the metadata, but I found no "public interface". I also found THIS article which uses some COM-library to read metadata, but I couldn't figure out how to use that for my purpose either. Can anyone tell me how I can read the TypeRef table

Iterating through !DumpHeap output to read value at memory offset

我与影子孤独终老i 提交于 2019-12-01 23:17:05
问题 I'm trying to come up with a WinDbg command line expression that takes the output of the !DumpHeap command and for each address, reads a 64-bit value from offset 0x08 after the address. I think this is possible (not sure about it) but every attempt I made so far fails with some error. I searched a lot but most WinDbg articles show simple examples which I can try but my attempts fail. I have a process dump of an ASP.NET worker process. The process has some memory growth but there's no clear

Where does nativeGetUninitializedObject actually exist?

蓝咒 提交于 2019-12-01 22:37:06
问题 I was curious about some serialization stuff so I went poking around FormatterServices and found a method called nativeGetUninitializedObject that actually handles the initialization (without calling the custructor) of a given type. This method is decorated with the extern keyword and the following attribute: [MethodImpl(MethodImplOptions.InternalCall), SecurityCritical] I'm left wondering: where does this method actually exist? What code does the CLR call to get the given type initialized

What should I pin when working on arrays?

送分小仙女□ 提交于 2019-12-01 22:29:58
I'm trying to write a DynamicMethod to wrap the cpblk IL opcode . I need to copy chunks of byte arrays and on x64 platforms, this is supposedly the fastest way to do it. Array.Copy and Buffer.BlockCopy both work, but I'd like to explore all options. My goal is to copy managed memory from one byte array to a new managed byte array. My concern is how do I know how to correctly "pin" memory location. I don't want the garbage collector to move the arrays and break everything. SO far it works but I'm not sure how to test if this is GC safe. // copying 'count' bytes from offset 'index' in 'source'

modify the assembly on runtime?

删除回忆录丶 提交于 2019-12-01 22:14:40
how can i modify memory loaded methods in given assembly so that clr when instantiates new objects for some class it makes new objects with modified code in it? You can use Mono Cecil to modify the assembly before you load it. You can save the modified assembly to a byte array, then call Assembly.Load to load the byte array. I don't think you can do that. But you can generate new classes in a new, in-memory assembly using Reflection.Emit. That is a lot of work though. You can get help from a framework such as Castle DynamicProxy , which allows you to generate proxies for your classes at

Load assemblies with dependencies in a different AppDomain

爱⌒轻易说出口 提交于 2019-12-01 21:32:22
My aim is to make a missing dependency check between 2 given folders. Imagine the following setup. Root\DirA\A.dll Root\DirB\B.dll B depends on A. So given these folders, I want to create a new AppDomain, load B.dll and have the dependency from DirA(A.dll) automatically resolved and isolated in that new AppDomain. Isolation is key here given that when I unload this AppDomain I want to create a new one with potentially DirA as a dependency again but DirC libraries that require it so in the case that DirC has a dependency on DirB as well I want it to throw an exception. Edit: Adding a code