📜 ⬆️ ⬇️

Manual stream cloning. When Assembler + C # or Java = Love

I will go straight to the point. Task: at any point in the code by calling specials. method to create a second thread that will start from the point of calling this method in the parent thread, while retaining the possibility of debugging and the values ​​of all local variables at all levels of method calls.

The implementation does not depend on the final platform (.Net / Java), because written in C ++ / Asm, however, custom code is made in C #, since I write on it.

image
')
Now that I have finally stabilized the example for 32-bit systems, I have the courage to show it to the public as completely ready. And yes, I repeat: when adapting it will work on any platform




Goals


The aim of the work is to build a functional associated with threads, which is not provided by the operating system. For example, the Fork () method of the Linux operating system, corrected for Windows OS realizations, was taken.

So, if we have the Original method, within which the Fork.CloneThread () method is called in some part of it, a second execution thread should occur, the beginning of which will be equal to the call point of the Fork.CloneThread () method and which will be completed at the output of the method Original so that all values ​​of the local variables of the source stream are saved in the second execution thread. In other words, for the CloneThread () call to split the current thread into two.

What is required from the reader



Materials for preparation:


Stream cloning


What do we have initially? There is our stream. It is also possible to create a new thread or schedule a task in the thread pool by executing your code there. We also understand that information on nested calls is stored in the call stack and that, if desired, we can manipulate it (for example, using C ++ / CLI). Moreover, if we follow the agreements and enter the value of the EBP register, the return address for the ret ret and allocate space for the local ones (if necessary) to the top of the stack, this can simulate the method call.
What needs to be done to clone the flow?

Why do it


The most important thing for what it is done is to consolidate understanding of how everything works and that if you know, you can begin to manipulate it.

Resources


Source: https://habr.com/ru/post/238947/


All Articles