views:

150

answers:

5

I'm not sure how to come across to ask this, but I'm trying to figure out if there is possibly a way by which I can access a running process written purely in .Net and interact with its memory space and active objects.

I do Add-in development for 2 point-of-sale packages, and am trying to figure this out for analysis of data entry in an external window. Any information or insight would be appreciated.

to put a different spin on what I'm asking... basically, is there a way of maybe using the system.diagnostics.processmodule and grab a running process with a particular name, and then instantiate that as an application, and then dig into it to find a particular static object, and work with it?

---- Additional ----

I noticed someone mentioned about reflection... this indeed may be what I am trying to ask... The only thing that I need is to maybe "Reflect" a process, find a particular static class, and then cast that class to an "object", so I could access its properties... maybe this makes more sense.

Unfortunately, the program I'm trying to work with is not going to have any form of Plug-in architecture for some time, and thought that I could do it using some sort of crazy P/Invoke or reflection idea.

A: 

Easily, no.

But it possible to automate WinDBG (or its command line version), alongside the SOS extension library for .NET it might be possible.

Fundamentally you need an application that is designed for extensibility/plug-ins/automation.

Another possibility is to exploit the fact that a .exe is pretty much the same as a .dll and have an application that loads the exe as if it were a class library and then starts it up. Reflection would then be possible.

Richard
+1  A: 

Look up .NET remoting.

Put it simply you can create a window service or console application that creates an object, a custom one you create. You can then register on a TCP port.

Then you have a client server that can access then same TCP port, could even be on 2 different PC's, and interact with the object.

The way to do that is create an interface that the client object knows about and the server implements.

You could have 2 console applications talk to each other. Here is a question about how to do that, it is not exactly right but should get you pointed in the right direction.

David Basarab
A: 

Another option, if you don't need to actually change things but instead are looking purely for stats, is to create some custom performance counters and then monitor those with another application. Monitoring Performance Thresholds

What I need to be able to do is to connect to a process, and get into the STA thread. Once in there, I need to get a static object that is running in the STA thread, and be able to work with it.
Richard B
A: 

There is a namespace in .net specifically designed for this,

System.AddIn

You need to add a reference to the dll (only available in .net 3.5). You can use this class to develop a typesafe plugin architecture which supports versioning and isolation of the foreign code.

Have a look on MSDN for some examples.

Spence
Spence, That would be great if I had control of the base program, but i do not in this case. I'm doing something "like" trying to go into Outlook and send an email, but its against another software package... I don't have access to the source to make changes. I have to work with what I can access
Richard B
A: 

Not sure if it will do exactly what you want but Hawkeye will let you examine & adjust .NET objects at runtime if it is a Windows application you are dealing with:

http://www.acorns.com.au/Projects/Hawkeye/

mundeep
This was not to debug it, but it was to actually work with the in-memory data from an external application.
Richard B