Need to call some code in an arbitrary Windows process (externally) at some time interval. Is there any OS API call for it?

Issue

I want to test my idea, wherein I execute some code in the context of another process at some interval. What API call or kernel functionality or l technique should I look into to execute code in another process at some interval?

Seems like I need to halt the process and modify the instruction pointer value before continuing it, if that’s remotely possible. Alternatively, I could hook into the kernel code which schedules time on the CPU for each process, and run the code each time the next time slot happens for a process. But PatchGuard probably prevents that.
This time interval doesn’t need to be precise.

Solution

The wording of the question tells me you’re fairly new to programming. A remote process doesn’t have AN instruction pointer, it typically has many – one per executing thread. That’s why the normal approach would be to not mess with any of those instruction pointers. Instead, you create a new thread in the remote process CreateRemoteThreadEx.

Since this thread is under your control, it can just run an infinite loop alternating between Sleep and the function you want to call.

Answered By – MSalters

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published