Question

I was wondering if it is possible to use hooking (like Detours) to remove non-determinism in an arbitrary application.

We can assume single-thread applications (to ignore non-determinism caused by races and scheduling).

My first guess was to override rand() in order to have predictable and repeatable output for any function asking for pseudo-random numbers, regardless of the seed.

Are there any other commonly used functions that I should consider overriding?

I know that there is no flawless solution here, but one that works for most applications will probably do. Also if there is another way to solve this problem, I will be interesting in reading about it.

Was it helpful?

Solution

You don't need to actually remove rand() and friends because they are pseudo-random-number generators. For the same seed, rand() will yield the same results, so what you actually need to catch is the call to time() that is used to initialize the RNG.

The key insight is that non-deterministic effects happen mostly due to scheduling (which has no influence for a large part of the single-threaded applications), the result of system calls and non-initialized memory in the program. You need to control the results of system calls to control the input of your program. strace is a very good tool for determining which function calls need overriding. To check if any memory is used uninitialized, use valgrind.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top