Anti-debugging method, device, electronic device and storage medium for Hook debugging

By obtaining and comparing the execution time and address of the target method in the client program code, determining whether it is debugged by Hook, the problem of existing anti-debug methods being cracked is solved, effectively protecting Hook debugging, and enhancing client security performance.

CN115114594BActive Publication Date: 2024-11-01BEIJING 58 INFORMATION TTECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210689255.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-17
Publication Date
2024-11-01
Estimated Expiration
2042-06-17

AI Technical Summary

Technical Problem

The existing anti-debugging methods are well known and cracked by reverse developers, and cannot effectively prevent Hook debugging, resulting in reduced client security performance.

Method used

By obtaining the execution time and real-time address of the target method in the client program code, comparing its consistency with the address in the case of not being debugged, if it is inconsistent, it is judged as Hook debugging and exiting the client, increasing the difficulty of the attacker's analysis and debugging .

Benefits of technology

Accurately determine the target method to be debugged by Hook, prevent attackers from debugging clients without running capabilities, enhance client security performance, and save computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115114594B_ABST
    Figure CN115114594B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides an anti-debugging method, device, electronic device and storage medium for Hook debugging. The anti-debugging method includes: starting a client, executing the program code of the client, obtaining the execution time of the target method in the program code; determining whether the execution time exceeds a preset time threshold; when it is determined that the execution time exceeds the time threshold, obtaining the real-time address of the target method; comparing the real-time address of the target method with the address of the target method when it is not debugged; when the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, determining that the target method is Hook debugged and exiting the client. Through the anti-debugging method of this embodiment, it is possible to accurately determine the target method that is Hooked in the client and exit the client, so that the attacker cannot debug the client that has no running capability, which increases the difficulty of analysis and debugging for the attacker and strengthens the security performance of the client.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an anti-debugging method, device, electronic device and storage medium for Hook debugging. Background Art

[0002] With the continuous development of computer technology, the application of clients on terminal devices is becoming more and more widespread. In order to ensure the security performance of the client and prevent it from being easily debugged or cracked by attackers, anti-debugging is a common and important protection method.

[0003] At present, the anti-debugging methods in related technologies are basically known and cracked by the majority of reverse developers. These anti-debugging methods can be bypassed by using code injection without causing any impact on the entire anti-debugging process, thereby bypassing security protection and debugging the client, greatly reducing the security performance of the client. Summary of the invention

[0004] The embodiments of the present invention provide an anti-debugging method, device, electronic device and storage medium for Hook debugging, so as to increase the difficulty of analysis and debugging for attackers and strengthen the security performance of a client.

[0005] A first aspect of an embodiment of the present invention provides an anti-debugging method for Hook debugging, which is applied to a client. The anti-debugging method includes:

[0006] Starting the client, executing the program code of the client, and obtaining the execution time of the target method in the program code;

[0007] Determine whether the execution time exceeds a preset time threshold, where the time threshold is the longest execution time of the target method when it is not debugged;

[0008] When it is determined that the execution time exceeds the time threshold, obtaining a real-time address of the target method, the real-time address being a storage location of an executable file corresponding to the target method during the execution of the program code;

[0009] Comparing the real-time address of the target method with the address of the target method when it is not debugged to see whether they are consistent;

[0010] When the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, it is determined that the target method is hook debugged, and the client is exited.

[0011] Optionally, before executing the program code of the client, the anti-debugging method further includes:

[0012] Obtain all methods in the program code, and obtain relevant information of the target method to be hooked and debugged; wherein the relevant information of the target method to be hooked and debugged includes: a method identifier of the target method to be hooked and debugged, a client identifier of a client to which the target method to be hooked and debugged belongs, and a terminal identifier of a terminal device where the client belongs;

[0013] Determine whether the target method to be hooked and debugged is included in all the methods according to the method identifiers corresponding to all the methods, the client identifier of the client, the terminal identifier of the terminal device where the client is located, and the relevant information of the target method to be hooked and debugged;

[0014] If the target method to be debugged by Hook is included in all the methods, directly exit the client;

[0015] The program code for executing the client includes:

[0016] If the target method to be debugged by Hook is not included in all the methods, the program code of the client is executed.

[0017] Optionally, after determining that the target method is hooked for debugging, the relevant information of the target method to be hooked for debugging is associated and stored in the client to which the target method to be hooked for debugging belongs, and is reported to the server;

[0018] The obtaining of relevant information of the target method being hooked and debugged includes:

[0019] Obtain relevant information of the target method being Hooked and debugged stored in the client;

[0020] In the case where the local data of the client is cleared or the client is uninstalled and then reinstalled, before obtaining the relevant information of the target method to be Hooked and debugged stored in the client, the anti-debugging method further includes:

[0021] Requesting the server for relevant information of a target method to be hooked and debugged that matches the client identifier of the client and the terminal identifier of the terminal device where the client is located;

[0022] The relevant information of the matched target method to be hooked and debugged returned by the server is stored in the client.

[0023] Optionally, in the program code of the client, a first code is inserted at the start position and the end position of the target method respectively, and the first code is used to count the execution time of the program code from the start of execution to the insertion position of the first code;

[0024] The obtaining the execution time of the target method in the program code includes:

[0025] Obtaining a first execution time of the program code from the start of execution to the start position of the target method, and obtaining a second execution time of the program code from the start of execution to the end position of the target method;

[0026] An execution time of a target method in the program code is determined according to the first execution time and the second execution time.

[0027] Optionally, the program code includes a second code for calculating the real-time address of the target method, and the server stores in advance the addresses corresponding to all methods in the program code when they are not debugged;

[0028] The obtaining the real-time address of the target method comprises: obtaining the real-time address of the target method through the second code;

[0029] The anti-debugging method further includes:

[0030] The address of the target method when it is not debugged is obtained from the server.

[0031] Optionally, the anti-debugging method further includes:

[0032] Detecting whether the terminal device where the client is located is an abnormal device;

[0033] When the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, determining that the target method is Hook debugged includes:

[0034] When it is detected that the terminal device is an abnormal device, and the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, it is determined that the target method is Hook debugged.

[0035] A second aspect of an embodiment of the present invention provides an anti-debugging device for Hook debugging, which is applied to a client. The anti-debugging device includes:

[0036] A time acquisition module, used to start the client, execute the program code of the client, and obtain the execution time of the target method in the program code;

[0037] A time comparison module, used to determine whether the execution time exceeds a preset time threshold, where the time threshold is the longest execution time of the target method when it is not debugged;

[0038] An address acquisition module, configured to acquire a real-time address of the target method when it is determined that the execution time exceeds the time threshold, wherein the real-time address is a storage location of an executable file corresponding to the target method during the execution of the program code;

[0039] An address comparison module, used for comparing whether the real-time address of the target method is consistent with the address of the target method when it is not debugged;

[0040] The debugging determination module is used to determine that the target method is hook debugged and exit the client when the real-time address of the target method is inconsistent with the address of the target method when it is not debugged.

[0041] Optionally, the anti-debugging device further includes:

[0042] A first acquisition module is used to acquire all methods in the program code before executing the program code of the client, and to acquire relevant information of a target method to be debugged by hook; wherein the relevant information of the target method to be debugged by hook includes: a method identifier of the target method to be debugged by hook, a client identifier of a client to which the target method to be debugged by hook belongs, and a terminal identifier of a terminal device where the client belongs;

[0043] A method comparison module, used to determine whether all the methods include the target method to be hooked and debugged according to the method identifiers corresponding to all the methods, the client identifier of the client, the terminal identifier of the terminal device where the client is located, and the relevant information of the target method to be hooked and debugged;

[0044] A first exit module, used for directly exiting the client if the target method being debugged by Hook is included in all the methods;

[0045] The time acquisition module comprises:

[0046] The code execution submodule is used to execute the program code of the client if the target method to be debugged by Hook is not included in all the methods.

[0047] Optionally, after determining that the target method is hooked for debugging, the relevant information of the target method to be hooked for debugging is associated and stored in the client to which the target method to be hooked for debugging belongs, and is reported to the server;

[0048] The first acquisition module includes:

[0049] A first acquisition submodule is used to acquire relevant information of the target method to be Hooked and debugged stored in the client;

[0050] When the local data of the client is cleared or the client is uninstalled and then reinstalled, the anti-debugging device further includes:

[0051] A request module, used for requesting, from the server, the relevant information of the target method to be hooked and debugged that matches the client identifier of the client and the terminal identifier of the terminal device where the client is located, before obtaining the relevant information of the target method to be hooked and debugged stored in the client;

[0052] The storage module is used to store the relevant information of the matched target method to be hooked and debugged returned by the server in the client.

[0053] Optionally, in the program code of the client, a first code is inserted at the start position and the end position of the target method respectively, and the first code is used to count the execution time of the program code from the start of execution to the insertion position of the first code;

[0054] The time acquisition module comprises:

[0055] A time acquisition submodule, used to acquire a first execution time of the program code from the start of execution to the start position of the target method, and to acquire a second execution time of the program code from the start of execution to the end position of the target method;

[0056] The time determination submodule is used to determine the execution time of the target method in the program code according to the first execution time and the second execution time.

[0057] Optionally, the program code includes a second code for calculating the real-time address of the target method, and the server stores in advance the addresses corresponding to all methods in the program code when they are not debugged;

[0058] The address acquisition module comprises:

[0059] A first address acquisition submodule, used for acquiring the real-time address of the target method through the second code;

[0060] The anti-debugging device also includes:

[0061] The second address acquisition module acquires the address of the target method before debugging from the server.

[0062] Optionally, the anti-debugging device further includes:

[0063] A device detection module, used to detect whether the terminal device where the client is located is an abnormal device;

[0064] The debugging determination module includes:

[0065] The debugging determination submodule is used to determine that the target method is hook debugged when it is detected that the terminal device is an abnormal device and the real-time address of the target method is inconsistent with the address of the target method when it is not debugged.

[0066] A third aspect of an embodiment of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the anti-debugging method for Hook debugging described in the first aspect of the present invention are implemented.

[0067] A fourth aspect of an embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the anti-debugging method for Hook debugging as described in the first aspect of the present invention are implemented.

[0068] By adopting the anti-debugging method for Hook debugging provided by the embodiment of the present invention, the execution time of the target method in the program code is obtained during the execution of the client program code, and it is determined whether the execution time of the target method exceeds the time threshold. If it exceeds the time threshold, the real-time address of the target method is further obtained, and the real-time address of the target method is compared with the address of the target method when it is not debugged. When the addresses are inconsistent, it can be determined that the target method is Hook debugged, and the client is exited. In this way, through the method of this embodiment, the target method that is Hooked in the client can be accurately determined and the client can be exited, so that the attacker cannot debug the client without running ability, which increases the difficulty of analysis and debugging for the attacker and strengthens the security performance of the client; there is no need to analyze all the target methods in the program code, and the initial screening is performed by the length of the target method execution time. It is only necessary to analyze the address of the abnormal target method to determine whether the target method is Hook debugged, thereby saving computing resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0069] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0070] Figure 1 It is a flow chart of an anti-debugging method for Hook debugging shown in one embodiment of the present invention;

[0071] Figure 2It is a schematic diagram of an anti-debugging method for Hook debugging shown in an embodiment of the present invention;

[0072] Figure 3 It is a structural block diagram of an anti-debugging device for Hook debugging provided by an embodiment of the present invention;

[0073] Figure 4 It is a schematic diagram of an electronic device shown in an embodiment of the present invention. DETAILED DESCRIPTION

[0074] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0075] At present, the debugging of the client in the existing technology can be divided into: static analysis and dynamic debugging. Among them, static analysis mainly uses IDA, MachOView, HexFiend software to convert the existing client (such as APP) into assembly code or binary through disassembly. This process is the process of converting high-level language into low-level language and analyzing the logic of the original code; while dynamic debugging is to use Xcode and lldb tools to run the client (such as APP), check the internal parameters and variable information of the program and analyze the logic process by setting breakpoints.

[0076] As mentioned above, anti-debugging is a common and important means of protection. Anti-debugging is to add anti-debugging code and detect debugging status during the program running phase to increase the cost and difficulty of debugging and analysis for attackers and ensure the security of the client. For the anti-debugging methods of the client, the anti-debugging methods in the existing technology are mainly divided into two categories: one is to prevent the attachment of the debugger, and the other is to detect whether the debugger exists. For example, the common anti-debugging methods are as follows:

[0077] 1. Implement anti-debugging by calling ptrace: ptrace is a method of tracking and controlling a running process, mainly to facilitate client development and debugging. Through ptrace, you can debug another process. At the same time, ptrace provides a very useful parameter PT_DENY_ATTACH, which can tell the system to prevent the debugger from attaching.

[0078] 2. Implement anti-debugging through sysctl: When a process is being debugged, there will be a flag in the process to mark it as being debugged. Use the sysctl function to view the information of the current process and check the status of this flag to check the current debugging status.

[0079] 3. Implement anti-debugging by calling syscall: In order to achieve the switch from user mode to kernel mode, the system provides a system call function syscall, and the corresponding number can be found in KernelSyscalls.

[0080] The above existing anti-debugging technologies have all been cracked by a large number of reverse developers. By using code injection, the above anti-debugging can be bypassed without any impact on the entire anti-debugging process, which greatly reduces the security performance of the client and causes the client to still be debugged or cracked.

[0081] In order to at least partially solve one or more of the above-mentioned problems and other potential problems, an embodiment of the present invention proposes a new anti-debugging method, namely, an anti-debugging method for Hook debugging. The anti-debugging method makes a comprehensive judgment by combining the execution time and address of the target method in the program code to determine whether the target method is Hook debugged. This not only saves computing resources, but also can accurately determine the Hooked target method in the client and exit the client, so that the attacker cannot debug the client that has no running capability, thereby increasing the difficulty of analysis and debugging for the attacker and strengthening the security performance of the client.

[0082] Please refer to Figure 1 , Figure 1 This is a flowchart of an anti-debugging method for Hook debugging shown in an embodiment of the present invention. The anti-debugging method for Hook debugging provided in this embodiment can be applied to a client, which can be applicable to an Android system or an iOS system. The client in this embodiment can be a program that provides local services to users. The client can implement the same software function in different program forms: for example, the client can be an application software APP, a small program, a web browser, etc. Figure 1 As shown, the anti-debugging method for Hook debugging in this embodiment may include the following steps:

[0083] Step S11: start the client, execute the program code of the client, and obtain the execution time of the target method in the program code.

[0084] In this embodiment, the client may start (open) the client in response to the user's operation of starting the client. For example, the user may touch the client control displayed on the terminal device (such as a mobile phone, computer, tablet, car computer, smart watch, etc.) where the client is located (such as a mobile phone, computer, tablet, car computer, smart watch, etc.) to open the client. The client starts the client in response to the operation of starting the client. After the client is started, the program code of the client is executed to obtain the execution time of the target method in the program code during the execution of the program code. Among them, the target method of this embodiment is any function or method in the program code of the client, for example, it can be a method and function in a language such as Object-C, C++ or C. In the process of executing the program code in this embodiment, the execution time of each function or method can be obtained after the execution of a function or method.

[0085] Among them, a function in a program code refers to a section of a program or code in a program code that can be directly referenced by another section of a program or code. It is an independent code block used to implement a certain function. A method in a program code is a special function. Methods are related to objects. Methods are a common term in object-oriented programming languages. Methods must be defined in a class and called through the object that holds it. A method can access various members of the object that holds it.

[0086] Step S12: Determine whether the execution time exceeds a preset time threshold, where the time threshold is the longest execution time of the target method when it is not debugged.

[0087] When the client's program code is executed, the execution time of the target method (i.e., any function or method in the program code) is very fast under normal circumstances (i.e., when not debugged), almost at the nanosecond or microsecond level; and if a method or function is debugged (such as being hooked, debugged by breakpoints, etc.), its execution time will far exceed the reasonable threshold. Therefore, after obtaining the execution time of the target method, this embodiment can determine whether the execution time exceeds the preset time threshold to preliminarily determine whether the target method in the program code is debugged.

[0088] In this embodiment, a time threshold is preset, and the preset time threshold is stored locally on the client and / or in a server connected to the client. The set time threshold can be flexibly modified by the server, and the server in this embodiment can be a backend server of the client, such as a computer connected to the client.

[0089] The time threshold of this embodiment is the longest execution time of the target method in the process of executing the program code without being debugged. The time threshold of this embodiment can be set in advance according to manual experience, such as setting the time threshold to microsecond or millisecond level, and this embodiment does not impose any restrictions on the specific value of the time threshold. In addition, for the pre-set time threshold, any function or method in the program code can correspond to the same time threshold, or each function or method in the program code can have a time threshold corresponding to it, and this embodiment does not impose any restrictions on this. In one of the optional methods, since the execution time of the target method in the debugged state and the non-debugged state is quite different, the use of the same time threshold can meet the time definition requirements, so the target methods in the program code only correspond to the same time threshold.

[0090] Step S13: when it is determined that the execution time exceeds the time threshold, the real-time address of the target method is obtained, where the real-time address is the storage location of the executable file corresponding to the target method during the execution of the program code.

[0091] In this embodiment, when the client determines that the execution time of the target method in the program code does not exceed the time threshold, it can be determined that the target method has not been debugged, and the subsequent program code can continue to be executed. When it is determined that the execution time of the target method in the program code exceeds the time threshold, it can be preliminarily determined that the target method is hooked for debugging. Therefore, in the case of determining that the execution time of the target method in the program code exceeds the time threshold, the client can further obtain the real-time address of the target method. Among them, the real-time address of the target method refers to the storage location of the executable file corresponding to the target method during the execution of the program code.

[0092] Step S14: comparing the real-time address of the target method with the address of the target method when it is not debugged to see if they are consistent.

[0093] In this embodiment, in the case where the target method is hooked and debugged, in addition to the execution time of the target method exceeding the time threshold, the address of the target method will also change. Therefore, after the initial suspected hooked method is screened out by the execution time of the target method, it is possible to further determine whether the target method is hooked and debugged by comparing the real-time address of the target method with the address of the target method when it is not debugged (i.e., the storage location of the executable file corresponding to the target method when it is not hooked and debugged during the execution of the program code).

[0094] Step S15: When the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, it is determined that the target method is hook debugged, and the client is exited.

[0095] In this embodiment, when the client determines that the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, that is, the address of the target method has changed, then it can be determined that the target method has been hooked for debugging, and it can also be considered that the process has been hooked for debugging, that is, the client has been hooked for debugging, and the client is immediately exited to prevent the client from continuing to run, preventing the attacker from continuing to debug the client and cracking the client.

[0096] In addition, when the client determines that the real-time address of the target method is exactly the same as the address of the target method when it is not debugged, it can be determined that the target method is debugged, but not debugged by Hook. At this time, it can also be determined that the client is debugged and the client is exited immediately, thereby preventing the client from continuing to run and preventing the attacker from continuing to debug the client and cracking the client.

[0097] In this embodiment, unlike the existing anti-debugging scheme, this embodiment does not require the system to obtain the process debugging state through the bottom layer, but can flexibly adjust the judgment through the time threshold and address. In the process of executing the client program code, the execution time of the target method in the program code is obtained, and it is judged whether the execution time of the target method exceeds the time threshold. If it exceeds the time threshold, the real-time address of the target method is further obtained, and the real-time address of the target method is compared with the address of the target method when it is not debugged. When the address is inconsistent, it can be determined that the target method is Hook debugged and exit the client. Through the anti-debugging method in this embodiment, there is no need to analyze the addresses of all target methods, and the initial screening is performed by the length of the target method execution time. It is only necessary to analyze the address of the abnormal target method to determine whether the target method is Hook debugged. This not only saves computing resources, but also can accurately determine the target method that is Hooked in the client and exit the client, so that the attacker cannot debug the client without running ability, thereby increasing the difficulty of analysis and debugging of the attacker, reducing the loss of own project resources, and strengthening the security performance of the client.

[0098] In combination with the above embodiments, in one implementation, the embodiment of the present invention further provides an anti-debugging method for Hook debugging. In this method, before "executing the program code of the client" in the above step S11, the anti-debugging method may also include steps S21-S24:

[0099] Step S21: Obtain all methods in the program code, and obtain relevant information of the target method to be hooked and debugged.

[0100] In this embodiment, after starting the client and before executing the client program code, the client can also obtain all methods in the client program code, and obtain the relevant information of the target method to be hooked and debugged that is stored in advance. Among them, all methods in the program code refer to all methods or functions included in the client program code. The client in this step obtains all methods in the client program code: it can be that the developer records all methods involved in the program code during the process of writing the client program code, and stores the method identifiers of all methods in the client, so that the client can directly read from the local to obtain all methods in the client program code; it can also be that the client obtains all methods contained in the client program code through a script specifically used to determine the methods in the program code.

[0101] The relevant information of the target method to be hooked and debugged includes: the method identifier of the target method to be hooked and debugged, the client identifier of the client to which the target method to be hooked and debugged belongs, and the terminal identifier of the terminal device where the client is located; and for each target method to be hooked and debugged, the method identifier of each target method to be hooked and debugged corresponds one-to-one with the client identifier of the client to which the target method to be hooked and debugged, and the terminal identifier of the terminal device where the client is located.

[0102] Step S22: Determine whether all the methods include the target method to be hooked and debugged according to the method identifiers corresponding to all the methods, the client identifier of the client, the terminal identifier of the terminal device where the client is located, and the relevant information of the target method to be hooked and debugged.

[0103] In this embodiment, after the client obtains all the methods in the program code and the relevant information of the target method to be hooked and debugged, it can determine whether all the methods in the client program code include the target method to be hooked and debugged based on the method identifiers corresponding to all the methods in the client program code, the client identifier of the client, the terminal identifier of the terminal device where the client is located, and the relevant information of the target method to be hooked and debugged.

[0104] Since the debugging of a target method in the client program code is linked to the client and the terminal device where the client is located: for example, the debugging of method C in client B on terminal device A does not mean that all clients containing method C are debugged, nor does it mean that method C in all clients B are debugged. It is also possible that method C in client B on terminal device D is not debugged.

[0105] Therefore, when the client is started, it can query the obtained relevant information of the target method to be hooked and debugged according to the client's own client identification, the terminal identification of the terminal device where the client is located, and the method identification corresponding to all the methods in the client program code, to determine whether the relevant information of the target method to be hooked and debugged contains the method identification of the target method to be hooked and debugged, the client identification of the client to which the target method to be hooked and debugged belongs, and the terminal identification of the terminal device where the client is located, which correspond one-to-one with the client's own client identification, the terminal identification of the terminal device where the client is located, and the method identification corresponding to all the methods in the client program code.

[0106] Step S23: If the target method to be debugged by Hook is included in all the methods, directly exit the client.

[0107] In this embodiment, if the client determines that the relevant information of the target method to be hooked and debugged contains the method identifier of the target method to be hooked and debugged, the client identifier of the client to which the target method to be hooked and debugged belongs, and the terminal identifier of the terminal device where the client belongs, which corresponds one to one with the client identifier of the client itself, the terminal identifier of the terminal device where the client is located, and the method identifiers of one or more methods among all the methods in the client program code, then the client determines that all the methods of the client program code include the target method to be hooked and debugged. At this time, it can be proved that the terminal device where the client is located is a risky device or a debugged device. At this time, the client is directly closed, that is, the client is directly exited to prohibit the client from being debugged.

[0108] In this embodiment, the “executing the program code of the client” in step S11 may specifically include the following step S24:

[0109] Step S24: If the target method to be debugged by Hook is not included in all the methods, the program code of the client is executed.

[0110] When the client determines that its own client identifier, the terminal identifier of the terminal device where the client is located, and the method identifiers corresponding to all methods in the client program code cannot correspond one-to-one with the method identifier of the target method to be hooked and debugged, the client identifier of the client to which the target method to be hooked and debugged belongs, and the terminal identifier of the terminal device where the client is located in the relevant information of the target method to be hooked and debugged, then it can be determined that the target method to be hooked and debugged is not included in all methods in the client program code, and the program code of the client can be executed.

[0111] In this embodiment, after the client is started, all methods in the program code are first obtained, and it is determined whether the previously recorded target method to be hooked and debugged exists in all methods. If it does, it can be proved that the terminal device where the client is located is a risky device or a debugged device. At this time, the client is directly exited and the client's program code is no longer executed to prohibit the client from being debugged, and at the same time support the server to issue a method or function opening and closing scheme. Through the anti-debugging method of this embodiment, it is possible to directly determine whether the client is hooked and debugged based on the recorded method information to be hooked and debugged after the client is started, thereby preventing the work of repeatedly detecting hook debugging and improving the detection efficiency.

[0112] In combination with the above embodiments, in one implementation, an embodiment of the present invention further provides an anti-debugging method for Hook debugging. In this method, after the client determines that the target method is Hook debugged, the relevant information of the target method being Hook debugged is associated and stored in the client to which the target method being Hook debugged belongs, and reported to the server. In this method, the "obtaining relevant information of the target method being Hook debugged" in the above step S21 may include step S31:

[0113] Step S31: Obtain relevant information of the target method to be hooked and debugged stored in the client.

[0114] In this embodiment, after the client determines that the target method in the client program code is hooked and debugged, the client will also associate and store the relevant information of the hooked and debugged target method (i.e., the method identifier of the hooked and debugged target method, the client identifier of the client to which the hooked and debugged target method belongs, and the terminal identifier of the terminal device where the client belongs) in the client and report it to the server. Based on this, when the client needs to obtain the relevant information of the hooked and debugged target method, the relevant information of the hooked and debugged target method stored in the client can be pulled from the client locally.

[0115] When the local data of the client is cleared or the client is uninstalled and then reinstalled, before obtaining the relevant information of the target method to be Hooked and debugged stored in the client, the anti-debugging method of this embodiment may further include step S32 and step S33:

[0116] Step S32: Request the server for relevant information of the target method to be hooked and debugged that matches the client identifier of the client and the terminal identifier of the terminal device where the client is located.

[0117] In this embodiment, when the local data of the client is cleared (i.e., the local cache of the client is cleared), or when the client is uninstalled and then reinstalled, if the client previously stored the relevant information of the target method to be hooked and debugged, it has also been lost. Therefore, at this time, the client can request the server for the relevant information of the target method to be hooked and debugged that matches the client identifier of the client and the terminal identifier of the terminal device where the client is located.

[0118] Among them, the server in this embodiment can communicate with multiple clients, so the server can store relevant information of the target method to be hooked and debugged, which is reported by multiple clients and is related to the client identifiers of the multiple clients and the terminal identifiers of the terminal devices where the multiple clients are located. Therefore, in step S32, specifically, the client can send a request carrying the client identifier of the client and the terminal identifier of the terminal device where the client is located to the server, so as to request the server for relevant information of the target method to be hooked and debugged, which matches the client identifier of the client and the terminal identifier of the terminal device where the client is located.

[0119] Step S33: storing the relevant information of the matched target method to be hooked and debugged returned by the server in the client.

[0120] In this embodiment, after receiving the request sent by the client, the server will return to the client the relevant information of the target method to be hooked and debugged that matches the client identifier of the client and the terminal identifier of the terminal device where the client is located. After the client receives the relevant information of the matching target method to be hooked and debugged returned by the server, the client can store the relevant information of the matching target method to be hooked and debugged in the client, so that the client can subsequently pull the relevant information of the target method to be hooked and debugged stored by the client locally.

[0121] In addition, in another embodiment, the relevant information of the target method to be hooked and debugged stored in the client may also include: relevant information of the target method to be debugged. Among them, the relevant information of the target method to be debugged refers to the relevant information of the target method to be debugged but not hooked. The relevant information of the target method to be debugged may include: the method identifier of the target method to be debugged but not hooked, the client identifier of the client to which the target method to be debugged but not hooked belongs, and the terminal identifier of the terminal device where the client belongs. Specifically, for example, when the client determines that the real-time address of the target method is exactly the same as the address of the target method when it is not debugged, it can be determined that the target method is debugged but not hooked. At this time, the relevant information of the target method to be debugged is stored locally on the client and reported to the server.

[0122] In this embodiment, after the client determines that the target method is hooked and debugged, it will also mark the method identifier of the target method to be hooked and debugged, the client identifier of the client, and the terminal identifier of the terminal where the client is located, that is, the relevant information of the target method to be hooked and debugged is stored locally and reported to the server. This embodiment records and stores the determined abnormal methods, and after the client is opened, it directly determines whether the client is hooked and debugged based on the recorded hooked and debugged method information, thereby avoiding duplication of work and improving detection efficiency.

[0123] In combination with the above embodiments, in one implementation, an embodiment of the present invention further provides an anti-debugging method for Hook debugging. In this method, in the program code of the client, a first code is inserted at the start position and the end position of the target method, respectively, and the first code is used to count the execution time of the client program code from the start to the execution to the insertion position of the first code. Specifically, the developer may insert the first code at the start position and the end position of each function or method in the program code in the process of writing the program code of the client. In this method, the "obtaining the execution time of the target method in the program code" in the above step S11 may specifically include steps S41 and S42:

[0124] Step S41: obtaining a first execution time of the program code from the start of execution to the start position of the target method, and obtaining a second execution time of the program code from the start of execution to the end position of the target method.

[0125] In this embodiment, during the process of executing the program code by the client, the execution time of the program code from the start of execution to the insertion position of the first code can be obtained each time the first code is executed. Therefore, during the process of executing the program code, each time a target method (i.e., any function or method in the program code) is executed, the first execution time of the client's program code from the start of execution to the start position of the target method can be obtained, and the second execution time of the client's program code from the start of execution to the end position of the target method can be obtained.

[0126] Step S42: Determine the execution time of the target method in the program code according to the first execution time and the second execution time.

[0127] In this embodiment, after the client obtains the first execution time and the second execution time corresponding to the target method, the execution time of the target method in the client program code can be determined according to the first execution time and the second execution time. In one implementation, the execution time of the target method in the program code can be obtained by subtracting the first execution time from the obtained second execution time.

[0128] In this embodiment, the first code is inserted in advance at the start and end positions of the target method in the program code, and the execution time of the target function during the execution of the program code is quickly obtained by calling the first code, thereby providing a basis for subsequent preliminary screening of whether the target method is hooked for debugging based on the execution time of the target method.

[0129] In combination with any of the above embodiments, in one implementation, an embodiment of the present invention further provides an anti-debugging method for Hook debugging. In this method, the client program code includes a second code, and the second code is used to calculate the real-time address of the target method in the client program code.

[0130] In this method, the "obtaining the real-time address of the target method" in the above step S13 may specifically include step S51: obtaining the real-time address of the target method through the second code. That is, the client in this embodiment may obtain the storage location of the executable file corresponding to the target method when the current program code is running through the second code included in the program code.

[0131] In addition to the above steps, the anti-debugging method of this embodiment further includes step S52: obtaining the address of the target method before debugging from the server.

[0132] In this embodiment, the server end that is connected to the client in communication has stored in advance the addresses of all methods in the client program code when they are not debugged (i.e., the storage locations of the executable files corresponding to all methods in the program code when they are not Hooked during the execution of the client program code). When obtaining the real-time address of the target method and the address of the target method when they are not debugged, the operating environment of the client program code execution process (such as the installation location of the client, etc.) must be consistent, so as to avoid the situation where the addresses are inconsistent due to the different installation locations of the client installation package, and further ensure the detection result of being Hooked and debugged in this embodiment.

[0133] Before executing step S14, step S52 can be implemented to obtain the address of the target method when it is not debugged (that is, obtain the storage location of the executable file corresponding to the target method when it is not Hook debugged during the execution of the program code) from the server that communicates with the client to perform address comparison.

[0134] In this embodiment, the real-time address of the target method is obtained through the second code included in the program code, and compared with the address of the target method in a non-debugging state pre-stored in the server, so as to determine whether the target method is hooked for debugging, and accurately determine whether there is a method hooked in the client's program code. If so, the client is exited to prevent the attacker from further debugging the client that has no running capability, thereby increasing the difficulty of analysis and debugging for the attacker and improving the security performance of the client.

[0135] In combination with any of the above embodiments, in one implementation, the embodiment of the present invention further provides an anti-debugging method for Hook debugging. In the anti-debugging method provided in this embodiment, in addition to the above steps, it also includes step S61:

[0136] Step S61: Detect whether the terminal device where the client is located is an abnormal device.

[0137] In general, there are two ways to debug the client: one is to use a jailbroken device to reach the debugging state, and the other is to use a normal device without a jailbroken device, but reach the debugging state by using a re-signed APP. Therefore, in this embodiment, the client can also detect the terminal device where the client is located to detect whether the terminal device where the client is located is an abnormal device, where the abnormal device can refer to a jailbroken device or a risky device.

[0138] It should be noted that, in this embodiment, there is no restriction on the order of executing the step of "detecting whether the terminal device where the client is located is an abnormal device" and executing the step of "determining whether the execution time exceeds a preset time threshold; when it is determined that the execution time exceeds the time threshold, obtaining the real-time address of the target method; comparing the real-time address of the target method with the address of the target method when it is not debugged to see if they are consistent": for example, in this embodiment, detecting whether it is an abnormal device may be performed first, and detecting the execution time and address may be performed later; or detecting the execution time and address may be performed first, and detecting whether it is an abnormal device may be performed later.

[0139] In one implementation mode, the client may collect device information of the terminal device where the client is located and network-related information through the server, and analyze whether the terminal device in this network is an abnormal device. For example, it may analyze whether the current network is a risky network based on network-related information, and make a response strategy for the devices on the risky network in a timely manner, and then judge the terminal device parameters in the risky network to determine whether the terminal device is a risky abnormal device.

[0140] In this embodiment, the above step S15 of “when the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, determining that the target method is Hook debugged” may specifically include step S62:

[0141] Step S62: when it is detected that the terminal device is an abnormal device, and the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, it is determined that the target method is hook debugged.

[0142] In this embodiment, when the client detects that the terminal device where the client is located is an abnormal device, and the client determines that the real-time address of the target method in the program code is inconsistent with the address of the target method when it is not debugged, it can be accurately determined that the target method in the client program code must have been hooked and debugged, and the target method is the target method that is hooked and debugged.

[0143] In addition, when the client detects that the terminal device where the client is located is an abnormal device, and the client determines that the execution time of the target method in the program code does not exceed the time threshold, it can be determined that although the device where the current client is located is an abnormal device, the target method in the client program code has not been debugged, so the subsequent program code can continue to be executed to determine whether there is a target method in the client program code that is hooked and debugged.

[0144] When the client detects that the terminal device where the client is located is an abnormal device, and the client determines that the execution time of the target method in the program code exceeds the time threshold, but the real-time address of the target method is exactly the same as the address of the target method when it is not debugged, then it can be determined that the target method has been debugged, but not debugged by Hook.

[0145] When the client detects that the terminal device where the client is located is not an abnormal device, and the client determines that the real-time address of the target method in the program code is inconsistent with the address of the target method when it is not debugged, it can be determined that although the device where the current client is located is not an abnormal device (such as a jailbroken device or a risky device), the target method is still hooked and debugged, indicating that the target method may be debugged using a re-signed APP.

[0146] When the client detects that the terminal device where the client is located is not an abnormal device, and the client determines that the execution time of the target method in the program code does not exceed the time threshold, it can be determined that the device where the current client is located is not jailbroken, and the target method in the client program code has not been debugged. Therefore, the subsequent program code can continue to be executed to determine whether there is a target method in the client program code that is hooked and debugged.

[0147] When the client detects that the terminal device where the client is located is not an abnormal device, and the client determines that the execution time of the target method in the program code exceeds the time threshold, but the real-time address of the target method is exactly the same as the address of the target method when it is not debugged, then it can be determined that although the device where the current client is located is not an abnormal device (such as a jailbroken device or a risky device), the target method is still debugged, but not debugged by Hook.

[0148] In this embodiment, by adding device verification, that is, by adding a client to detect whether the terminal device where the client is located is an abnormal device, it is possible to accurately identify whether the target method in the client program code is hooked and debugged. Because when it is detected that the execution time of the target method exceeds the time threshold, the address changes, and the terminal device is a jailbroken device, the client must be debugged and the target method must be hooked and debugged, thereby immediately exiting the client, increasing the difficulty of analysis and debugging for attackers and enhancing the security performance of the client.

[0149] In one embodiment, see Figure 2 , Figure 2 FIG. 1 is a schematic diagram of an anti-debugging method for Hook debugging according to an embodiment of the present invention. Figure 2 As shown, after starting the client, determine whether all methods in the client program code include methods marked as abnormal to be debugged. If included, exit the client directly to prohibit debugging the client. If not included, pull the pre-set time threshold from the client or the server, start executing the client program code and detect whether the terminal device where the client is located is an abnormal device:

[0150] If it is detected that the terminal device where the client is located is an abnormal device, then in the process of executing the client program code, after each method or function is executed, it is determined whether the execution time of the method or function exceeds the preset time threshold. When the execution time of the method or function does not exceed the preset time threshold, it proves that the terminal device is an abnormal device but the current method or function in the client program code has not been debugged. The program code can continue to be executed, and the terminal device where the client is located is detected again to see if it is an abnormal device, and the execution time of the next function or method can be compared; or the program code can be continued to be executed, and the terminal device where the client is located is no longer detected to see if it is an abnormal device, and the execution time of the next function or method can be directly compared. When the execution time of the method or function exceeds the preset time threshold, it is determined whether the address of the method or function has changed. If it has changed, it indicates that the function or method must be debugged by Hook. At this time, the client stores data (i.e., stores relevant information of the target method being debugged by Hook) locally, reports it to the server, and exits the client to prohibit debugging the client. When the execution time of the method or function exceeds the preset time threshold and the address of the method or function has not changed, it can be proved that the function or method is debugged, but not debugged by Hook. At this time, you can exit the client to prohibit debugging the client.

[0151] If the terminal device where the client is located is not an abnormal device, in the process of executing the client program code, after each method or function is executed, it is determined whether the execution time of the method or function exceeds the preset time threshold. When the execution time of the method or function does not exceed the preset time threshold, it proves that the method or function has not been debugged, and the program code can be continued to be executed, and the terminal device where the client is located is detected again to be an abnormal device, and the execution time of the next function or method is compared; or the program code can be continued to be executed, and the terminal device where the client is located is no longer detected to be an abnormal device, and the execution time of the next function or method is directly compared. When the execution time of the method or function exceeds the preset time threshold, it is determined whether the address of the method or function has changed. If it has changed, it indicates that the function or method is Hook debugged. At this time, the client stores data (i.e., stores relevant information of the target method being Hook debugged) locally, reports it to the server, and exits the client to prohibit debugging the client. When the execution time of the method or function exceeds the preset time threshold, and the address of the method or function has not changed, it can be proved that the function or method is debugged, but not Hook debugged. At this time, the client can be exited to prohibit debugging the client.

[0152] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0153] Based on the same inventive concept, an embodiment of the present invention provides an anti-debugging device 300 for Hook debugging, and the anti-debugging device 300 can be applied to a client. Figure 3 , Figure 3 FIG. 1 is a structural block diagram of an anti-debugging device for Hook debugging provided by an embodiment of the present invention. Figure 3 As shown, the anti-debugging device 300 includes:

[0154] The time acquisition module 301 is used to start the client, execute the program code of the client, and obtain the execution time of the target method in the program code;

[0155] A time comparison module 302 is used to determine whether the execution time exceeds a preset time threshold, where the time threshold is the longest execution time of the target method when it is not debugged;

[0156] An address acquisition module 303, for acquiring a real-time address of the target method when it is determined that the execution time exceeds the time threshold, the real-time address being a storage location of an executable file corresponding to the target method during the execution of the program code;

[0157] An address comparison module 304 is used to compare whether the real-time address of the target method is consistent with the address of the target method when it is not debugged;

[0158] The debugging determination module 305 is used to determine that the target method is hook debugged and exit the client when the real-time address of the target method is inconsistent with the address of the target method when it is not debugged.

[0159] Optionally, the anti-debugging device 300 further includes:

[0160] A first acquisition module is used to acquire all methods in the program code before executing the program code of the client, and to acquire relevant information of a target method to be debugged by hook; wherein the relevant information of the target method to be debugged by hook includes: a method identifier of the target method to be debugged by hook, a client identifier of a client to which the target method to be debugged by hook belongs, and a terminal identifier of a terminal device where the client belongs;

[0161] A method comparison module, used to determine whether all the methods include the target method to be hooked and debugged according to the method identifiers corresponding to all the methods, the client identifier of the client, the terminal identifier of the terminal device where the client is located, and the relevant information of the target method to be hooked and debugged;

[0162] A first exit module, used for directly exiting the client if the target method being debugged by Hook is included in all the methods;

[0163] The time acquisition module 301 includes:

[0164] The code execution submodule is used to execute the program code of the client if the target method to be debugged by Hook is not included in all the methods.

[0165] Optionally, after determining that the target method is hooked for debugging, the relevant information of the target method to be hooked for debugging is associated and stored in the client to which the target method to be hooked for debugging belongs, and is reported to the server;

[0166] The first acquisition module includes:

[0167] A first acquisition submodule is used to acquire relevant information of the target method to be Hooked and debugged stored in the client;

[0168] When the local data of the client is cleared or the client is uninstalled and then reinstalled, the anti-debugging device 300 further includes:

[0169] A request module, used for requesting, from the server, the relevant information of the target method to be hooked and debugged that matches the client identifier of the client and the terminal identifier of the terminal device where the client is located, before obtaining the relevant information of the target method to be hooked and debugged stored in the client;

[0170] The storage module is used to store the relevant information of the matched target method to be hooked and debugged returned by the server in the client.

[0171] Optionally, in the program code of the client, a first code is inserted at the start position and the end position of the target method respectively, and the first code is used to count the execution time of the program code from the start of execution to the insertion position of the first code;

[0172] The time acquisition module 301 includes:

[0173] A time acquisition submodule, used to acquire a first execution time of the program code from the start of execution to the start position of the target method, and to acquire a second execution time of the program code from the start of execution to the end position of the target method;

[0174] The time determination submodule is used to determine the execution time of the target method in the program code according to the first execution time and the second execution time.

[0175] Optionally, the program code includes a second code for calculating the real-time address of the target method, and the server stores in advance the addresses corresponding to all methods in the program code when they are not debugged;

[0176] The address acquisition module 303 includes:

[0177] A first address acquisition submodule, used for acquiring the real-time address of the target method through the second code;

[0178] The anti-debugging device 300 also includes:

[0179] The second address acquisition module acquires the address of the target method before debugging from the server.

[0180] Optionally, the anti-debugging device 300 further includes:

[0181] A device detection module, used to detect whether the terminal device where the client is located is an abnormal device;

[0182] The debugging determination module 305 includes:

[0183] The debugging determination submodule is used to determine that the target method is hook debugged when it is detected that the terminal device is an abnormal device and the real-time address of the target method is inconsistent with the address of the target method when it is not debugged.

[0184] Based on the same inventive concept, another embodiment of the present invention provides an electronic device 400, such as Figure 4 shown. Figure 4 4 is a schematic diagram of an electronic device according to an embodiment of the present invention. The electronic device includes a memory 402, a processor 401, and a computer program stored in the memory and executable on the processor, and when executed by the processor, the steps in the anti-debugging method for Hook debugging according to any of the above embodiments of the present invention are implemented.

[0185] Based on the same inventive concept, another embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the anti-debugging method for Hook debugging as described in any of the above embodiments of the present invention are implemented.

[0186] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0187] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0188] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0189] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.

[0190] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of the present invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0191] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0192] In the embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0193] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0194] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0195] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical disks.

[0196] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. An anti-debugging method for Hook debugging, applied to the client, characterized in that: The anti-debugging method comprises: Starting the client, executing the program code of the client, and obtaining the execution time of the target method in the program code; Determine whether the execution time exceeds a preset time threshold, where the time threshold is the longest execution time of the target method when it is not debugged; When it is determined that the execution time exceeds the time threshold, obtaining a real-time address of the target method, the real-time address being a storage location of an executable file corresponding to the target method during the execution of the program code; Comparing the real-time address of the target method with the address of the target method when it is not debugged to see whether they are consistent; When the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, it is determined that the target method is hook debugged, and the client is exited.

2. The anti-debugging method for Hook debugging according to claim 1, characterized in that: Before executing the program code of the client, the anti-debugging method further includes: Obtain all methods in the program code, and obtain relevant information of the target method to be hooked and debugged; wherein the relevant information of the target method to be hooked and debugged includes: a method identifier of the target method to be hooked and debugged, a client identifier of a client to which the target method to be hooked and debugged belongs, and a terminal identifier of a terminal device where the client belongs; Determine whether the target method to be hooked and debugged is included in all the methods according to the method identifiers corresponding to all the methods, the client identifier of the client, the terminal identifier of the terminal device where the client is located, and the relevant information of the target method to be hooked and debugged; If the target method to be debugged by Hook is included in all the methods, directly exit the client; The program code for executing the client includes: If the target method to be debugged by Hook is not included in all the methods, the program code of the client is executed.

3. The anti-debugging method for Hook debugging according to claim 2, characterized in that: The relevant information of the target method being hooked and debugged is stored in association in the client to which the target method being hooked and debugged belongs after determining that the target method is being hooked and debugged, and reported to the server; The obtaining of relevant information of the target method being hooked and debugged includes: Obtain relevant information of the target method being Hooked and debugged stored in the client; In the case where the local data of the client is cleared or the client is uninstalled and then reinstalled, before obtaining the relevant information of the target method to be Hooked and debugged stored in the client, the anti-debugging method further includes: Requesting the server for relevant information of a target method to be hooked and debugged that matches the client identifier of the client and the terminal identifier of the terminal device where the client is located; The relevant information of the matched target method to be hooked and debugged returned by the server is stored in the client.

4. The anti-debugging method for Hook debugging according to claim 1, characterized in that: In the program code of the client, a first code is inserted at the start position and the end position of the target method respectively, and the first code is used to count the execution time of the program code from the start of execution to the insertion position of the first code; The obtaining the execution time of the target method in the program code includes: Obtaining a first execution time of the program code from the start of execution to the start position of the target method, and obtaining a second execution time of the program code from the start of execution to the end position of the target method; An execution time of a target method in the program code is determined according to the first execution time and the second execution time.

5. The anti-debugging method for Hook debugging according to claim 1, characterized in that: The program code includes a second code for calculating the real-time address of the target method, and the server stores in advance the addresses corresponding to all methods in the program code when they are not debugged; The obtaining the real-time address of the target method comprises: obtaining the real-time address of the target method through the second code; The anti-debugging method further comprises: The address of the target method when it is not debugged is obtained from the server.

6. The anti-debugging method for Hook debugging according to any one of claims 1 to 5, characterized in that: The anti-debugging method further comprises: Detecting whether the terminal device where the client is located is an abnormal device; When the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, determining that the target method is Hook debugged includes: When it is detected that the terminal device is an abnormal device, and the real-time address of the target method is inconsistent with the address of the target method when it is not debugged, it is determined that the target method is Hook debugged.

7. An anti-debugging device for Hook debugging, applied to a client, characterized in that: The anti-debugging device comprises: A time acquisition module, used to start the client, execute the program code of the client, and obtain the execution time of the target method in the program code; A time comparison module, used to determine whether the execution time exceeds a preset time threshold, where the time threshold is the longest execution time of the target method when it is not debugged; An address acquisition module, configured to acquire a real-time address of the target method when it is determined that the execution time exceeds the time threshold, wherein the real-time address is a storage location of an executable file corresponding to the target method during the execution of the program code; An address comparison module, used for comparing whether the real-time address of the target method is consistent with the address of the target method when it is not debugged; The debugging determination module is used to determine that the target method is hook debugged and exit the client when the real-time address of the target method is inconsistent with the address of the target method when it is not debugged.

8. The anti-debugging device for Hook debugging according to claim 7, characterized in that: The anti-debugging device also includes: A first acquisition module is used to acquire all methods in the program code before executing the program code of the client, and to acquire relevant information of a target method to be debugged by hook; wherein the relevant information of the target method to be debugged by hook includes: a method identifier of the target method to be debugged by hook, a client identifier of a client to which the target method to be debugged by hook belongs, and a terminal identifier of a terminal device where the client belongs; A method comparison module, used to determine whether all the methods include the target method to be hooked and debugged according to the method identifiers corresponding to all the methods, the client identifier of the client, the terminal identifier of the terminal device where the client is located, and the relevant information of the target method to be hooked and debugged; A first exit module, used for directly exiting the client if the target method being debugged by Hook is included in all the methods; The time acquisition module comprises: The code execution submodule is used to execute the program code of the client if the target method to be debugged by Hook is not included in all the methods.

9. The anti-debugging device for Hook debugging according to claim 8, characterized in that: The relevant information of the target method being hooked and debugged is stored in association in the client to which the target method being hooked and debugged belongs after determining that the target method is being hooked and debugged, and reported to the server; The first acquisition module includes: A first acquisition submodule is used to acquire relevant information of the target method to be Hooked and debugged stored in the client; When the local data of the client is cleared or the client is uninstalled and then reinstalled, the anti-debugging device further includes: A request module, used for requesting, from the server, the relevant information of the target method to be hooked and debugged that matches the client identifier of the client and the terminal identifier of the terminal device where the client is located, before obtaining the relevant information of the target method to be hooked and debugged stored in the client; The storage module is used to store the relevant information of the matched target method to be hooked and debugged returned by the server in the client.

10. The anti-debugging device for Hook debugging according to claim 7, characterized in that: In the program code of the client, a first code is inserted at the start position and the end position of the target method respectively, and the first code is used to count the execution time of the program code from the start of execution to the insertion position of the first code; The time acquisition module comprises: A time acquisition submodule, used to acquire a first execution time of the program code from the start of execution to the start position of the target method, and to acquire a second execution time of the program code from the start of execution to the end position of the target method; The time determination submodule is used to determine the execution time of the target method in the program code according to the first execution time and the second execution time.

11. The anti-debugging device for Hook debugging according to claim 7, characterized in that: The program code includes a second code for calculating the real-time address of the target method, and the server stores in advance the addresses corresponding to all methods in the program code when they are not debugged; The address acquisition module comprises: A first address acquisition submodule, used for acquiring the real-time address of the target method through the second code; The anti-debugging device also includes: The second address acquisition module acquires the address of the target method before debugging from the server.

12. The anti-debugging device for Hook debugging according to any one of claims 7 to 11, characterized in that: The anti-debugging device also includes: A device detection module, used to detect whether the terminal device where the client is located is an abnormal device; The debugging determination module includes: The debugging determination submodule is used to determine that the target method is hook debugged when it is detected that the terminal device is an abnormal device and the real-time address of the target method is inconsistent with the address of the target method when it is not debugged.

13. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the anti-debugging method for Hook debugging as described in any one of claims 1 to 6 are implemented.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the anti-debugging method for Hook debugging as claimed in any one of claims 1 to 6 are implemented.