P
P
Porohkun2013-12-19 21:14:09
Programming
Porohkun, 2013-12-19 21:14:09

How to have a running application in C#?

Such is the situation. There is some application written in Sharpe. And there is me who wants, using the same sharp, to somehow connect to the process of this application and change something in it. There are no sources for this application.
Tell me which way to google?))

Answer the question

In order to leave comments, you need to log in

7 answer(s)
E
Eugene Obrezkov, 2013-12-19
@ghaiklor

This is called disassembling (since there are no source codes). And with this style of question, I can answer - you will need to google for a very long time.
Essentially. In the case of Sharp - ReSharper. It will help to restore some of the source codes and the project. I would even say that he restores the entire project.

A
Avery007, 2013-12-20
@Avery007

.NET and C# sources can be obtained using the ShowMyCode decompiler

A
Anton Martsen, 2013-12-21
@martsen

If you want to get the source of the application, then I advise dotPeek . It can export source codes to the Visual Studio project.

N
Nikolai Turnaviotov, 2013-12-19
@foxmuldercp

The ability to work with a debugger is very useful. You seem to be doing just that.

A
Alexey Buraikin, 2013-12-20
@bstdman

If you need to simulate user behavior - press buttons, enter data into fields - then you can get by with WinAPI (get the window handle and send commands via SendMesssage). If you need to change data in memory, then without a debugger you can’t go anywhere.

B
BlindShot96, 2013-12-20
@BlindShot96

You can use WinApi to write to process memory. To do this, you need to know the process ID. In my opinion, the most convenient way to do this is knowing the name of the process (the name of the executable file without the EXE extension or path).

public static uint GetProcessID(string name)
        {
          return (uint)Process.GetProcessesByName(name)[0].Id;
        }

After the process ID is found, it must be opened for reading / writing. To do this, you need to use the WinApi OpenProcess function. dwDesiredAccess - process access modifier ( 0x001F0FFF - full access to the process) dwProcessId - process id
[DllImport("kernel32.dll")]
        public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32    dwProcessId);

IntPtr process_handle = OpenProcess(0x001F0FFF,1,process_id);

The process opening function returns the process handle (as I understand it, the pointer to it). process_handle should then be used to read and write data to the process's memory.
To write data to process memory, you can use the function WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte [] lpBuffer, uint nSize, out int lpNumberOfBytesWritten);
hProcess is the handle of the process, lpBaseAddress is the memory address from which to write data, lpBuffer is the data to write, nSize is the number of bytes to write, lpNumberOfBytesWritten - I don't know exactly what it means, it can be left at UIntPtr.Zero
After work with the process you need to close the connection to it. hObject - process handle.
[DllImport("kernel32.dll")]
        public static extern Int32 CloseHandle(IntPtr hObject);

V
varus, 2013-12-22
@varus

The idea is this: if you have a reference to the AppDomain , you can call your code in it . The problem is how to get the domain of the remote process. This is just what popped up . If I understand you correctly, you need something like this. However, I'm not sure that DoCallback can be called for the domain of another process. And that it is possible to get domains by ProcessID is also not a fact. Alternatives: as already said, SendMessage. Maybe there is something in System.Reflection.Emit.
Here's another article googled, maybe it will be interesting, or maybe it's not quite in the topic. In any case, find a solution - unsubscribe, very interesting!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question