Summary of the invention
The object of the embodiment of the present invention is to provide a kind of method and the device that prevent from distorting system time, in case the locking system time is tampered.
For achieving the above object, the embodiment of the invention discloses a kind of method preventing from distorting system time, be pre-created that system for tracking starts together, for detection system, the invoked service routine of local zone time function is set; Described method comprises:
Obtain the described entrance function address that local zone time function is set;
By described service routine, detect the described local zone time function that arranges and whether be called, if local zone time function being set described and being called, representing for distorting system time;
If so, then obtained described entrance function address is revised as the address of default do-nothing function.
Optionally, that described establishment system for tracking starts together, for detection system, the invoked service routine of local zone time function is set, comprising:
Open Service Control Manager function by calling system, be linked to Service Control Manager;
By calling establishment service function, establishment arranges the invoked service routine of local zone time function for detection system;
Controlling handles function by calling registration service, registering the control function of this service routine;
By calling described control function, the state of this service routine is set to starting state.
Optionally, the described entrance function address arranging local zone time function of described acquisition, comprising:
Be loaded in the process space of described service routine by comprising the described built-in function arranging local zone time function;
Obtaining program address function by calling, from the importing address table of described built-in function, obtaining the described entrance function address that local zone time function is set.
Optionally, comprise in described service routine for catching the described Hook function arranging the invoked information of local zone time function;
Described by described service routine, detect the described local zone time function that arranges and whether be called, comprising:
By the described Hook function in described service routine, described information is caught, if capture described information, represent that the described local zone time function that arranges is called.
Optionally, also comprise:
After receiving the delete instruction of user for described Hook function, delete described Hook function.
Optionally, also comprise:
After receiving the halt instruction of user for described service routine, by calling described control function, the state of described service routine is set to halted state.
For achieving the above object, the embodiment of the invention discloses a kind of device preventing from distorting system time, comprising: creation module, acquisition module, detection module and modified module, wherein,
Described creation module, for be pre-created that system for tracking starts together, for detection system, the invoked service routine of local zone time function is set;
Described acquisition module, for obtaining the described entrance function address arranging local zone time function;
Whether described detection module, for the service routine created by described creation module, detected the described local zone time function that arranges and be called, and arranging local zone time function and be called, representing for distorting system time if described;
Described modified module, for detect at described detection module described the invoked situation of local zone time function is set under, obtained described entrance function address is revised as the address of default do-nothing function.
Optionally, described creation module, specifically for:
Open Service Control Manager function by calling system, be linked to Service Control Manager;
By calling establishment service function, establishment arranges the invoked service routine of local zone time function for detection system;
Controlling handles function by calling registration service, registering the control function of this service routine;
By calling described control function, the state of this service routine is set to starting state.
Optionally, described acquisition module, specifically for:
Be loaded in the process space of described service routine by comprising the described built-in function arranging local zone time function;
Obtaining program address function by calling, from the importing address table of described built-in function, obtaining the described entrance function address that local zone time function is set.
Optionally, comprise in described service routine for catching the described Hook function arranging the invoked information of local zone time function;
Described detection module, specifically for:
Described Hook function in the service routine created by described creation module is caught described information, if capture described information, represents that the described local zone time function that arranges is called.
Optionally, also comprise: removing module,
Described removing module, for after receiving the delete instruction of user for described Hook function, deletes described Hook function.
Optionally, described creation module, also for:
After receiving the halt instruction of user for described service routine, by calling described control function, the state of described service routine is set to halted state.
As seen from the above technical solutions, embodiments provide a kind of method and the device that prevent from distorting system time, be pre-created that system for tracking starts together, for detection system, the invoked service routine of local zone time function is set; Method comprises: obtain the described entrance function address arranging local zone time function; By described service routine, detect the described local zone time function that arranges and whether be called, if local zone time function being set described and being called, representing for distorting system time; If so, then obtained described entrance function address is revised as the address of default do-nothing function.
The technical scheme that the application embodiment of the present invention provides, arranging in the invoked situation of local zone time function, the entrance function address arranging local zone time function being revised as the address of do-nothing function, and then calling do-nothing function, any amendment is not made to system time, prevent system time to be tampered.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, be clearly and completely described the technical scheme in the embodiment of the present invention, obviously, described embodiment is only the present invention's part embodiment, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to the scope of protection of the invention.
In order to solve prior art problem, embodiments provide a kind of method and the device that prevent from distorting system time.First a kind of method of distorting system time that prevents that the embodiment of the present invention provides is introduced below.
A kind of schematic flow sheet preventing from distorting the method for system time that Fig. 1 provides for the embodiment of the present invention, can comprise:
S101: obtain the entrance function address that local zone time function is set;
Whether S102: by service routine, detect the described local zone time function that arranges and be called, and if so, performs S103;
Arranging local zone time function to be called if described, representing for distorting system time,
S103: the address of obtained described entrance function address being revised as default do-nothing function.
Concrete, above-mentioned service routine be that the system for tracking be pre-created starts together, for detection system, the invoked service routine of local zone time function is set.
Concrete, in actual applications, arranging local zone time function can be SetLocalTime function.
Concrete, create that system for tracking starts together, for detection system, the invoked service routine of local zone time function is set, Service Control Manager function can be opened by calling system, be linked to Service Control Manager; By calling establishment service function, establishment arranges the invoked service routine of local zone time function for detection system; Controlling handles function by calling registration service, registering the control function of this service routine; By calling described control function, the state of this service routine is set to starting state.
Exemplary, by the OpenSCManager function link in calling system API (ApplicationProgrammingInterface, application programming interface) function to Service Control Manager; By calling CreateService function creation for monitoring the invoked service routine MyService.exe of SetLocalTime function, by calling the control function of RegisterServiceCtrlHandler function registration service routine MyService.exe, by calling this control function, the state of service routine MyService.exe is set to starting state.
Concrete, in actual applications, the ChangeServiceStatus function that can also be provided by call operation system, is set to 4 by the state value of service routine MyService.exe, and the state value of service is that 4 expression services are in running status (i.e. starting state).
Concrete, obtaining the entrance function address that local zone time function is set, can being loaded in the process space of described service routine by comprising the described built-in function arranging local zone time function; Obtaining program address function by calling, from the importing address table of described built-in function, obtaining the described entrance function address that local zone time function is set.
In actual applications, SetLocalTime function is a function in API calls, API calls is all be encapsulated with DLL (built-in function), therefore, the built-in function comprising SetLocalTime function is needed to be loaded in the process space of service routine MyService.exe of above-mentioned establishment, by calling GetProcAddress function, the entrance function address of SetLocalTime function is obtained from the importing address table of built-in function, wherein, the preassigned load address of function (function true address) is stored in importing address table.Suppose that the entrance function address of SetLocalTime function obtained is 00030100H.
Concrete, comprise for catching the described Hook function arranging the invoked information of local zone time function in above-mentioned service routine; By described service routine, detect the described local zone time function that arranges and whether be called, by the described Hook function in described service routine, described information can be caught, if capture described information, represent that the described local zone time function that arranges is called.
In actual applications, the platform that Hook (hook) is windows messaging treatment mechanism, application program can monitor certain message of specified window above, and the window monitored can be that other processes create.When message arrive after, target window process function pre-treatment it.Hook Mechanism allows application program to intercept and capture process windows messaging or particular event.Hook is actually the program segment of a processing messages, by system call, it is linked into system.Whenever specific message sends, before not arriving object window, hook program just first catches this message, that is Hook Function first obtains control.At this moment namely Hook Function can process this message, also can not deal with and continue to transmit this message, can also force the transmission of end
Above-mentioned Hook function, can be created by the SetWindowsHookEx function in calling system api function, and utilize the types of variables HOOKPROC in SetWindowsHookEx function to be SetLocalTime function, namely above-mentioned Hook function is used for catching the invoked information of SetLocalTime function.When capturing the invoked information of SetLocalTime function, representing that SetLocalTime function is called, now, the entry address of SetLocalTime function being revised as the address of default do-nothing function, suppose that the address of default do-nothing function is 003514D0H.Now, call do-nothing function, any amendment is not made to system time, prevent system time to be tampered.
In actual applications, there is the situation that user initiatively revises system time, now user can send halt instruction for described service routine; The state of described service routine, after receiving the halt instruction of user for described service routine, can be set to halted state by calling described control function by system.Make service routine not be in running status, user can modify to system time.
In actual applications, there is the situation that user initiatively revises system time, now user can send delete instruction for above-mentioned Hook function; System, after receiving the delete instruction of user for above-mentioned Hook function, deletes above-mentioned Hook function.Even if make service routine be in running status, SetLocalTime function is called, and can not capture the invoked information of SetLocalTime function, user can modify to system time.
Concrete, delete Hook function, unloading deletion can be carried out by the UnhookWindowsHookEx function in calling system api function.
The present invention is embodiment illustrated in fig. 1 in application, arranging in the invoked situation of local zone time function, the entrance function address arranging local zone time function being revised as the address of do-nothing function, and then calling do-nothing function, any amendment is not made to system time, prevent system time to be tampered.
Corresponding with above-mentioned embodiment of the method, the embodiment of the present invention also provides a kind of device preventing from distorting system time.
A kind of structural representation preventing from distorting the device of system time that Fig. 2 provides for the embodiment of the present invention, can comprise: creation module 201, acquisition module 202, detection module 203 and modified module 204, wherein,
Creation module 201, for be pre-created that system for tracking starts together, for detection system, the invoked service routine of local zone time function is set;
The creation module 201 of illustrated embodiment of the present invention, specifically may be used for:
Open Service Control Manager function by calling system, be linked to Service Control Manager;
By calling establishment service function, establishment arranges the invoked service routine of local zone time function for detection system;
Controlling handles function by calling registration service, registering the control function of this service routine;
By calling described control function, the state of this service routine is set to starting state.
The creation module 201 of illustrated embodiment of the present invention, can also be used for:
After receiving the halt instruction of user for described service routine, by calling described control function, the state of described service routine is set to halted state.
Obtain module 202, for obtaining the described entrance function address arranging local zone time function;
The acquisition module 202 of illustrated embodiment of the present invention, specifically may be used for:
Be loaded in the process space of described service routine by comprising the described built-in function arranging local zone time function;
Obtaining program address function by calling, from the importing address table of described built-in function, obtaining the described entrance function address that local zone time function is set.
Whether detection module 203, for the service routine created by creation module 201, detected the described local zone time function that arranges and be called, and arranging local zone time function and be called, representing for distorting system time if described;
Comprise Hook function in the service routine that creation module 201 creates, this Hook function is for catching the described function arranging the invoked information of local zone time function; The detection module 203 of illustrated embodiment of the present invention, specifically may be used for:
Described Hook function in the service routine created by described creation module is caught described information, if capture described information, represents that the described local zone time function that arranges is called.
Modified module 204, for detect at detection module 203 described the invoked situation of local zone time function is set under, obtained described entrance function address is revised as the address of default do-nothing function.
In actual applications, a kind of device preventing from distorting system time that the embodiment of the present invention provides, can also comprise: removing module (not shown),
Removing module, for after receiving the delete instruction of user for described Hook function, deletes the above-mentioned Hook function comprised in the service routine of creation module 201 establishment.
The present invention is embodiment illustrated in fig. 2 in application, arranging in the invoked situation of local zone time function, the entrance function address arranging local zone time function being revised as the address of do-nothing function, and then calling do-nothing function, any amendment is not made to system time, prevent system time to be tampered.
It should be noted that, in this article, the such as relational terms of first and second grades and so on is only used for an entity or operation to separate with another entity or operational zone, and not necessarily requires or imply the relation that there is any this reality between these entities or operation or sequentially.And, term " comprises ", " comprising " or its any other variant are intended to contain comprising of nonexcludability, thus make to comprise the process of a series of key element, method, article or equipment and not only comprise those key elements, but also comprise other key elements clearly do not listed, or also comprise by the intrinsic key element of this process, method, article or equipment.When not more restrictions, the key element limited by statement " comprising ... ", and be not precluded within process, method, article or the equipment comprising described key element and also there is other identical element.
Each embodiment in this instructions all adopts relevant mode to describe, between each embodiment identical similar part mutually see, what each embodiment stressed is the difference with other embodiments.Especially, for device embodiment, because it is substantially similar to embodiment of the method, so description is fairly simple, relevant part illustrates see the part of embodiment of the method.
One of ordinary skill in the art will appreciate that all or part of step realized in said method embodiment is that the hardware that can carry out instruction relevant by program has come, described program can be stored in computer read/write memory medium, here the alleged storage medium obtained, as: ROM/RAM, magnetic disc, CD etc.
The foregoing is only preferred embodiment of the present invention, be not intended to limit protection scope of the present invention.All any amendments done within the spirit and principles in the present invention, equivalent replacement, improvement etc., be all included in protection scope of the present invention.