如何更改进程或线程的DateTime.UtcNow的值? [英] How to change the value of DateTime.UtcNow for a Process or Thread?

查看:132
本文介绍了如何更改进程或线程的DateTime.UtcNow的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法,甚至是非常偷偷摸摸的方法,可以更改DateTime.UtcNow为进程或线程返回的时间?

Is there a way, even a very sneaky way, to change the time that a DateTime.UtcNow returns for a process or thread?

SetSystemTime() win32 API调用将更改整个系统上的时间。我以前使用过此方法,但我希望该方法对系统上运行的其他进程的危害较小。在自动构建服务器上,时间的混乱是不好的功夫。

The SetSystemTime() win32 API call will change the time on the entire system. I've used this before but I would like a method that is less evil to other processes running on the system. Messing with the time is bad kungfoo on automated build servers.

C#似乎缺少覆盖默认行为所需的语言功能。

C# seems to lack the language features required to override the default behavior.

也许可以通过某种方式代理.Net用于获取当前时间的方法?

Perhaps the method that .Net uses to obtain the current time could be proxied in some way?

推荐答案

DateTime.UtcNow可能会调用Kernel32!GetSystemTimeAsFileTime()或类似的东西。您可能可以使用 Microsoft Research的绕行库来挂接此API,然后在您的hook函数中,检测要重复的进程和线程ID。

The DateTime.UtcNow probably calls into Kernel32!GetSystemTimeAsFileTime() or something similar. You could probably use the Detour library from Microsoft Research to hook this API, then in your hook function, detect the process and thread IDs which you'd like to dupe.

运行该软件祝您好运!

这篇关于如何更改进程或线程的DateTime.UtcNow的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆