A file virus detection method, device, terminal and storage medium

By using feature substring comparison and byte probability library in file virus detection, the virus feature matching process is optimized, the problem of time-consuming virus detection in the existing technology is solved, and the efficiency of virus detection is improved.

CN111177721BActive Publication Date: 2024-11-12TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910749584.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-08-14
Publication Date
2024-11-12
Estimated Expiration
2040-08-17

AI Technical Summary

Technical Problem

In the prior art, file virus detection takes a long time, resulting in low virus detection and killing efficiency.

Method used

By comparing the target file with the first feature substring in the virus feature string, and then comparing it with the second feature substring when matching, the probability value of the feature substring is determined using the byte probability library, and the most preferred match is the most Possible feature substrings are used to filter mismatch cases to avoid subsequent feature substrings.

Benefits of technology

The process of virus feature matching is accelerated, the time-consuming process of virus feature matching is shortened, and the efficiency of virus detection is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111177721B_ABST
    Figure CN111177721B_ABST
Patent Text Reader

Abstract

The present invention discloses a virus detection method, device, terminal and storage medium for a file, wherein the virus detection method for a file comprises: obtaining a target file; comparing the target file with a first characteristic substring in a virus characteristic string; the first characteristic substring is a continuous string in the virus characteristic string that satisfies a preset condition; when the target file includes the first characteristic substring, comparing the target file with a second characteristic substring in the virus characteristic string; the second characteristic substring is a continuous string in the virus characteristic string except the first characteristic substring; and performing virus detection on the target file according to the comparison result with the second characteristic substring. The present invention accelerates the feature matching of viruses, shortens the time consumption of the feature matching of viruses, and improves the efficiency of virus detection and killing.
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 a file virus detection method, device, terminal and storage medium. Background Art

[0002] A network virus (also known as a virus) refers to a computer instruction or program code that is compiled or inserted into a computer program to destroy computer functions or data, affect computer use, and is capable of self-replication.

[0003] When performing virus detection on a file, the related art generally performs virus feature matching on the file to be detected. If the file to be detected contains a virus feature string, the file to be detected is determined to be a virus file. However, the virus feature matching process in the related art takes a long time, which results in a long time for the entire file virus detection process and low file virus detection efficiency. Summary of the invention

[0004] In order to solve the problems of the prior art, the embodiments of the present invention provide a file virus detection method, device, terminal and storage medium. The technical solution is as follows:

[0005] In one aspect, a method for detecting viruses in a file is provided, the method comprising:

[0006] Get the target file;

[0007] Compare the target file with the first characteristic substring in the virus characteristic string; the first characteristic substring is a continuous string in the virus characteristic string that meets a preset condition;

[0008] In the case where the target file includes the first characteristic substring, the target file is compared with a second characteristic substring in the virus characteristic string; the second characteristic substring is a continuous string in the virus characteristic string except the first characteristic substring;

[0009] According to the comparison result with the second characteristic substring, virus detection is performed on the target file.

[0010] On the other hand, a file virus detection device is provided, the device comprising:

[0011] A first acquisition module, used for acquiring a target file;

[0012] A first comparison module, used to compare the target file with a first characteristic substring in the virus characteristic string; the first characteristic substring is a continuous string in the virus characteristic string that meets a preset condition;

[0013] A second comparison module is used to compare the target file with a second characteristic substring in the virus characteristic string when the target file includes the first characteristic substring; the second characteristic substring is a continuous character string in the virus characteristic string except the first characteristic substring;

[0014] The virus detection module is used to perform virus detection on the target file according to the comparison result with the second characteristic substring.

[0015] Optionally, the continuous character string satisfying the preset condition includes a characteristic substring having the smallest total probability value among multiple characteristic substrings; and the device further includes:

[0016] A first determination module is used to determine the probability value of the byte corresponding to the character in the virus feature string based on the byte probability library;

[0017] A second determination module is used to determine a plurality of character substrings included in the virus characteristic character string according to a preset character string length;

[0018] A calculation module, used for summing the probability values ​​of bytes corresponding to the characters in the character substring to obtain a total probability value corresponding to each character substring in the multiple character substrings;

[0019] The third determination module is used to determine the character substring with the smallest total probability value among the multiple character substrings as the first characteristic substring of the virus characteristic string.

[0020] Optionally, the first determining module includes:

[0021] A fourth determination module, used to determine the file type of the target file;

[0022] A fifth determination module, used to determine a target byte in the byte probability library that matches a byte corresponding to a character in the virus feature string;

[0023] A sixth determination module, configured to determine a target correspondence relationship matching the file type of the target file based on the correspondence relationship among the target bytes, the file type and the probability value in the byte probability library;

[0024] The second acquisition module is used to acquire the probability value in the target corresponding relationship, and use the probability value in the target corresponding relationship as the probability value of the byte corresponding to the character.

[0025] Optionally, the device further comprises:

[0026] A third acquisition module is used to acquire sample files of different file types;

[0027] A seventh determination module, used to determine the number of occurrences of the same byte in the sample files of the same file type, and the total number of occurrences of all bytes in the sample files of the same file type;

[0028] An eighth determination module determines a ratio of the number of occurrences of the same byte to the total number of occurrences of all bytes to obtain a probability value;

[0029] A corresponding relationship establishing module, used to establish a corresponding relationship between the bytes, file types and probability values;

[0030] A creation module is used to create the byte probability library based on the correspondence between the bytes, file types and probability values.

[0031] Optionally, the device further comprises:

[0032] A priority setting module, used to set the comparison priority of the first feature substring to be higher than that of the second feature substring;

[0033] The adjustment module is used to arrange the first characteristic substring and the second characteristic substring from high to low according to the comparison priority to obtain the adjusted virus characteristic string.

[0034] Optionally, the second characteristic substring includes a third characteristic substring and a fourth characteristic substring separated by the first characteristic substring;

[0035] The second comparison module comprises:

[0036] A ninth determination module, configured to determine data in the target file other than the data corresponding to the first characteristic substring as data to be detected; the data to be detected includes first data to be detected and second data to be detected separated by the data corresponding to the first characteristic substring;

[0037] A first comparison submodule, used for comparing the first to-be-detected data with the third characteristic substring;

[0038] The second comparison submodule compares the second data to be detected with the fourth characteristic substring when the first data to be detected includes the third characteristic substring.

[0039] Optionally, the virus detection module is used to determine that the target file is a virus file when the comparison result is that the second data to be detected includes the fourth characteristic substring.

[0040] On the other hand, a terminal is provided, including a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the virus detection method for the above-mentioned file.

[0041] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction, at least one program, a code set or an instruction set is stored in the storage medium, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by a processor to implement the virus detection method for the file as described above.

[0042] The embodiment of the present invention compares the target file with a first characteristic substring that meets a preset condition in a virus characteristic string. When the target file includes the first characteristic substring, the target file is compared with a second characteristic substring in the virus characteristic string except the first characteristic substring, and whether the target file is a virus file is determined according to the comparison result with the second characteristic substring. Thus, in the first comparison (i.e., the comparison with the first characteristic substring), the mismatch can be filtered out with the highest probability, and the remaining characteristic substrings (i.e., the second characteristic substring) are avoided from participating in the subsequent matching process, thereby accelerating the virus characteristic matching, shortening the time consumption of the virus characteristic matching, and facilitating improving the efficiency of virus detection and killing. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0044] Figure 1 It is a flowchart of a file virus detection method provided by an embodiment of the present invention;

[0045] Figure 2 It is a flowchart of another file virus detection method provided by an embodiment of the present invention;

[0046] Figure 3 It is a flow chart of a method for determining the probability value of bytes corresponding to characters in a virus feature string based on a byte probability library provided by an embodiment of the present invention;

[0047] Figure 4 It is a schematic diagram of comparing a virus feature string with a target file provided by an embodiment of the present invention;

[0048] Figure 5 The embodiment of the present invention provides Figure 4 A flowchart of another method for detecting virus in a file;

[0049] Figure 6 It is a structural schematic diagram of a file virus detection device provided by an embodiment of the present invention;

[0050] Figure 7 is a schematic structural diagram of another file virus detection device provided by an embodiment of the present invention;

[0051] Figure 8 is a schematic structural diagram of another file virus detection device provided by an embodiment of the present invention;

[0052] Fig. 9 The present invention provides a hardware structure block diagram of a terminal. DETAILED DESCRIPTION

[0053] 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 only 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 making creative work are within the scope of protection of the present invention.

[0054] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.

[0055] See also Figure 1 , which shows a flowchart of a file virus detection method provided by an embodiment of the present invention. The file virus detection method can be applied to the file virus detection device of the embodiment of the present invention. The file virus detection device can be configured in a computer device, which can be a terminal or a server. Among them, the terminal can include but is not limited to a smart phone, a desktop computer, a tablet computer, a laptop computer and other hardware devices with various operating systems. The server can include an independently running server, a distributed server, or a server cluster composed of multiple servers.

[0056] It should be noted that this specification provides method operation steps as described in the embodiments or flow charts, but more or fewer operation steps may be included based on routine or non-creative work. The order of steps listed in the embodiments is only one way of executing the steps among many orders, and does not represent the only order of execution. When the actual system or product is executed, it can be executed in the order of the method shown in the embodiments or the drawings or in parallel (for example, in a parallel processor or multi-threaded processing environment). Specifically, Figure 1 As shown, the method may include:

[0057] S101, obtaining a target file.

[0058] The target file is the file that needs to be scanned for viruses to determine whether it is a virus file. In actual applications, the user can select a file for virus scanning as needed, and the selected file that needs to be scanned for viruses is the target file; of course, the user can also select a disk partition or directory as needed and start a global virus detection command, which can traverse all files under the disk partition or directory and use each traversed file as the target file.

[0059] S103, comparing the target file with a first characteristic substring in the virus characteristic string; the first characteristic substring is a continuous string in the virus characteristic string that meets a preset condition.

[0060] Among them, the virus feature string is a string sequence that can reflect the characteristics of a computer virus, and can be a string extracted from an identified virus file to represent the virus. The virus feature string can be stored in a virus feature library, which can store multiple virus feature strings corresponding to different viruses.

[0061] The first characteristic substring is a continuous string that meets the preset conditions in the virus characteristic string. Specifically, the continuous string that meets the preset conditions may include a characteristic substring with the smallest total probability value among multiple characteristic substrings, such as Figure 2 As shown, the method may also include:

[0062] S201, determining probability values ​​of bytes corresponding to characters in the virus feature string based on a byte probability library.

[0063] The byte probability library stores the correspondence between bytes, file types and probability values. The bytes in the correspondence can use byte values ​​to uniquely identify a byte, and the value range of the byte value is an integer between 0 and 255. Specifically, the creation of the byte probability library may include but is not limited to the following steps:

[0064] Obtain sample files of different file types. The file types of sample files may include, but are not limited to, text files (such as txt, Doc, XLS, WPS, etc.), picture files (Bmp, GIF, Jpg, PSD, etc.), video files (AVI, Mpg, etc.), compressed files, executable files exe, log files log, and command files Com, etc. Specifically, sample files of different file types may be obtained from a designated storage space such as a sample library. The designated storage space may be a local storage space or a cloud storage space. A large number of sample files of different file types are stored in the designated storage space.

[0065] Determine the number of occurrences of the same byte in the sample files of the same file type and the total number of occurrences of all bytes in the sample files of the same file type. That is, count the bytes in the sample files contained in each file type to determine the total number of occurrences of all bytes and the number of occurrences of the same byte.

[0066] The ratio of the number of occurrences of the same byte to the total number of occurrences of all bytes is determined to obtain a probability value.

[0067] A correspondence between the byte, the file type and the probability value is established. That is, in the correspondence, one byte may correspond to multiple file types, and each file type corresponds to a probability value, which is the probability value of the byte in the file type.

[0068] The byte probability library is created based on the correspondence between the bytes, file types and probability values.

[0069] The embodiment of the present invention fully considers the data composition differences of different file types when creating the byte probability library. The correspondence between bytes, file types and probability values ​​obtained based on the data composition differences is conducive to further accelerating virus feature matching in the future.

[0070] In the embodiment of this specification, the probability value of the byte corresponding to the character in the virus feature string can be determined based on the byte probability library. Figure 3 Methods such as Figure 3 As shown, the method may include:

[0071] S301, determining the file type of the target file.

[0072] S303: Determine a target byte in the byte probability library that matches a byte corresponding to a character in the virus feature string.

[0073] Specifically, the target bytes that match the bytes corresponding to the characters in the virus feature string are searched in the byte probability library.

[0074] S305: Determine a target correspondence that matches the file type of the target file based on the correspondence between the target bytes, the file type, and the probability value in the byte probability library.

[0075] Specifically, after finding the target byte, the corresponding relationship of the target byte in the byte probability library can be obtained, and the corresponding relationship includes multiple file types corresponding to the target byte, and each file type corresponds to a probability value. Based on the file type of the target file, a target corresponding relationship matching the file type of the target file in the corresponding relationship is determined.

[0076] S307: Obtain the probability value in the target corresponding relationship, and use the probability value in the target corresponding relationship as the probability value of the byte corresponding to the character.

[0077] S203: Determine multiple character substrings included in the virus feature character string according to a preset character string length.

[0078] Among them, the preset string length means that the string contains a preset number of consecutive characters. In the embodiment of this specification, the preset string length does not exceed the length of the virus feature string. The preset string length can be set according to actual needs. For example, it can be set to 1 / 3 or 1 / 2 of the length of the virus feature string, etc.

[0079] Specifically, a continuous string of a preset string length is selected from the virus feature string, and the continuous string of the preset string length is a character substring. For example, if the virus feature string is "abcde" and the preset string length is 3, the following character substrings can be obtained: "abc", "bcd", "cde".

[0080] S205, summing the probability values ​​of the bytes corresponding to the characters in the character substring to obtain a total probability value corresponding to each character substring in the multiple character substrings.

[0081] Specifically, the probability value of the byte corresponding to each character in the virus feature string has been determined through the search in step S201. In step S205, taking each character substring as the calculation unit, the probability values ​​of the bytes corresponding to the characters in each character substring are added and summed to obtain the total probability value corresponding to each character substring.

[0082] S207: Determine the character substring with the smallest total probability value among the multiple character substrings as the first characteristic substring of the virus characteristic character string.

[0083] That is, in the embodiment of this specification, the character substring with the smallest probability of appearing in the virus feature string is taken as the first feature substring.

[0084] In a specific embodiment, in order to match the target file with the first feature substring in the virus feature string first when performing virus feature matching, after determining the first feature substring, the comparison priority can also be set, that is, the comparison priority of the first feature substring is set higher than the second feature substring, and the first feature substring and the second feature substring are arranged from high to low according to the comparison priority to obtain an adjusted virus feature string. When all virus feature strings in the original virus feature library are adjusted, the adjusted virus feature library can be obtained. Among them, the second feature substring is a continuous string in the virus feature string except the above-mentioned first feature substring.

[0085] like Figure 4 The virus feature string including the first feature substring shown has a length of L (assuming that the last character of the virus feature string is L), and the first feature substring starts at the Mth character and ends at the M+Nth character, that is, the length of the first feature substring is N. The second feature substring includes two feature substrings separated by the first feature substring, namely, the [0,M] segment string starting at the first character 0 and ending at the Mth character, i.e., the third feature substring, and the [M+N,L] segment string starting at the M+Nth character and ending at the Lth character, i.e., the fourth feature substring.

[0086] In actual applications, when scanning a target file for viruses, the current data position in the target file can be located through the data pointer, such as Figure 4 The current data position X in the target file is shown in , and the located data is compared with the virus feature string. The located data has the same length as the virus feature string. During the comparison, the [X, X+N] data segment in the located data is first compared with the first feature substring, and step S105 is executed when the two match, that is, the [X, X+N] data segment in the located data is consistent with the first feature substring.

[0087] S105: When the target file includes the first characteristic substring, compare the target file with a second characteristic substring in the virus characteristic string.

[0088] Specifically, when comparing the target file with the second characteristic substring of the virus characteristic string, the data in the target file except the data corresponding to the first characteristic substring can be first determined as the data to be detected. It can be understood that the data to be detected includes the first data to be detected and the second data to be detected separated by the data corresponding to the first characteristic substring; assuming that the first data to be detected corresponds to the third characteristic substring and the second data to be detected corresponds to the fourth characteristic substring, the first data to be detected can be compared with the third characteristic substring, and when the first data to be detected includes the third characteristic substring, the second data to be detected can be compared with the fourth characteristic substring.

[0089] It should be noted that in the present embodiment, when comparing the target file with the first feature substring and the target file with the second feature substring, the specific comparison method used may include but is not limited to KMP algorithm, BM algorithm, AC algorithm, etc.

[0090] Among them, the KMP algorithm is an improved string matching algorithm, which was discovered by DEKnuth, JHMorris and VRPratt at the same time, so it is called Knuth-Morris-Pratt operation, or KMP algorithm for short. The key of the KMP algorithm is to use the information after the match fails to minimize the number of matches between the virus feature string and the target file to achieve the purpose of fast matching.

[0091] The BM algorithm, namely the Boyer-Moore string search algorithm, uses a tail comparison method. Specifically, the target file is aligned with the head of the virus feature string, the search starts from the tail of the virus feature string, and then the comparison is directly from the tail.

[0092] The AC algorithm, or Aho–Corasick algorithm, is implemented by constructing a finite state machine (similar to adding mismatch pointers in a trie tree). These additional mismatch pointers allow for fallback when a string search fails (for example, if the word cat in the trie tree fails to match, but there is another word cart in the trie tree, the mismatch pointer will point to the prefix ca), turning to other branches of a prefix to avoid repeated prefix matching and improve algorithm efficiency.

[0093] S107: Perform virus detection on the target file according to the comparison result with the second characteristic substring.

[0094] In the embodiment of this specification, when the comparison result is that the target file includes the second characteristic substring, it indicates that the target file matches the entire virus characteristic string, that is, the virus characteristic string exists in the target file, and the target file can be determined to be a virus file.

[0095] In a specific embodiment, when the first data to be detected includes the third characteristic substring and the second data to be detected includes the fourth characteristic substring, it can be determined that the comparison result is that the target file includes the second characteristic substring, and the target file is determined to be a virus file.

[0096] It can be seen from the above technical scheme of the embodiment of the present invention that the embodiment of the present invention compares the target file with the first feature substring in the virus feature string that meets the preset conditions. When the target file includes the first feature substring, the target file is compared with the second feature substring in the virus feature string except the first feature substring, and whether the target file is a virus file is determined according to the comparison result with the second feature substring, so that the mismatch can be filtered out with the highest probability in the first comparison (i.e., the comparison with the first feature substring), and the remaining feature substrings (i.e., the second feature substring) are avoided from participating in the subsequent matching process, thereby accelerating the feature matching of the virus, shortening the time consumption of the virus feature matching, and helping to improve the efficiency of virus detection.

[0097] Combine the following Figure 4 , the above technical solution of the embodiment of the present invention is described in detail, such as Figure 5 A flowchart of another method for detecting virus in a file is shown, and the method may include:

[0098] S501, starting from the current data position X of the target file, the data segment [X, X+N] in the located data is compared with the first characteristic substring.

[0099] Among them, the current data position X of the target file is the data position in the target file pointed to by the data pointer. During the entire virus scanning process of the target file, the data pointer moves from the data header of the target file to the data tail of the target file; the length of the located data is the same as the virus feature string, such as Figure 4 It includes data segment A, [X,X+N] data segment and data segment B.

[0100] Specifically, when the comparison result between the data segment [X, X+N] in the located data and the first characteristic substring is that the two match, i.e., are consistent, it indicates that the target file includes the first characteristic substring, and step S503 can be executed at this time; when the comparison result between the data segment [X, X+N] in the located data and the first characteristic substring is that the two do not match, step S509 is executed.

[0101] S503, starting from the data position X+N of the target file, compare the data segment A with the [M+N, L] characteristic substring.

[0102] Specifically, if the comparison result is that data segment A matches the [M+N,L] feature substring, that is, the two are consistent, it means that the target file includes the [M+N,L] feature substring, and step S505 can be executed. If the comparison result is that data segment A does not match the [M+N,L] feature substring, step S509 is executed.

[0103] S505, starting from the data position XM of the target file, compare the data segment B with the [0, M] characteristic substring.

[0104] Specifically, if the comparison result is that data segment B matches the [0,M] feature substring, that is, the two are consistent, it means that the target file includes the entire virus feature string, and step S507 can be executed to determine that the target file is a virus file and end; if the comparison result is that data segment B does not match the [0,M] feature substring, step S509 is executed.

[0105] S507: Determine whether the target file is a virus file.

[0106] S509, judging whether the sum of the current data position X and the length N of the first characteristic substring exceeds the data tail of the target file, if the judgment result is no, executing step S511; if the judgment result is yes, executing step S513.

[0107] S511, sliding the data pointer to the next data position of the target file according to a preset sliding distance, and taking the next data position of the target file as the current data position X, and executing step S501 again.

[0108] The preset sliding distance may correspond to a specific comparison method involved in the comparison process, and the preset sliding distance may include but is not limited to one character, two characters, and the like.

[0109] S513, determine that the target file does not include a virus signature string, and the target file is not a virus file, and end.

[0110] In summary, the embodiment of the present invention compares the target file with the first characteristic substring first, and only when the comparison result of the two is that the target file includes the first characteristic substring, does it compare the target file with the remaining characteristic substrings in the virus characteristic string, so that in the first comparison (i.e., the comparison with the first characteristic substring), the mismatch situation can be filtered out with the maximum probability, avoiding the continued comparison with the corresponding remaining characteristic substrings, accelerating the virus feature matching, effectively shortening the time of virus feature matching, and improving the virus detection efficiency.

[0111] Corresponding to the virus detection methods for files provided in the above-mentioned embodiments, an embodiment of the present invention further provides a virus detection device for files. Since the virus detection device for files provided in the embodiment of the present invention corresponds to the virus detection methods for files provided in the above-mentioned embodiments, the implementation methods of the virus detection methods for files described above are also applicable to the virus detection device for files provided in this embodiment and will not be described in detail in this embodiment.

[0112] See also Figure 6 , which is a schematic diagram of the structure of a file virus detection device provided by an embodiment of the present invention, the device has the function of implementing the file virus detection method in the above method embodiment, and the function can be implemented by hardware or by hardware executing corresponding software. Figure 6 As shown, the device may include:

[0113] A first acquisition module 610, used to acquire a target file;

[0114] A first comparison module 620 is used to compare the target file with a first characteristic substring in the virus characteristic string; the first characteristic substring is a continuous string in the virus characteristic string that meets a preset condition;

[0115] A second comparison module 630 is used to compare the target file with a second characteristic substring in the virus characteristic string when the target file includes the first characteristic substring; the second characteristic substring is a continuous character string in the virus characteristic string except the first characteristic substring;

[0116] The virus detection module 640 is used to perform virus detection on the target file according to the comparison result with the second characteristic substring.

[0117] In a specific embodiment, the continuous character string satisfying the preset condition includes a characteristic substring with the smallest total probability value among multiple characteristic substrings;

[0118] Correspondingly, such as Figure 7 A schematic diagram of the structure of another file virus detection device provided, the device may also include:

[0119] A first determination module 650 is used to determine the probability value of the byte corresponding to the character in the virus feature string based on the byte probability library;

[0120] A second determination module 660 is used to determine a plurality of character substrings included in the virus characteristic character string according to a preset character string length;

[0121] A calculation module 670, configured to sum the probability values ​​of the bytes corresponding to the characters in the character substring to obtain a total probability value corresponding to each character substring in the multiple character substrings;

[0122] The third determination module 680 is configured to determine the character substring with the smallest total probability value among the multiple character substrings as the first characteristic substring of the virus characteristic string.

[0123] Optionally, the first determining module 650 may include:

[0124] A fourth determination module, used to determine the file type of the target file;

[0125] A fifth determination module, used to determine a target byte in the byte probability library that matches a byte corresponding to a character in the virus feature string;

[0126] A sixth determination module, configured to determine a target correspondence relationship matching the file type of the target file based on the correspondence relationship among the target bytes, the file type and the probability value in the byte probability library;

[0127] The second acquisition module is used to acquire the probability value in the target corresponding relationship, and use the probability value in the target corresponding relationship as the probability value of the byte corresponding to the character.

[0128] In another specific embodiment, the device may further include:

[0129] A third acquisition module is used to acquire sample files of different file types;

[0130] A seventh determination module, used to determine the number of occurrences of the same byte in the sample files of the same file type, and the total number of occurrences of all bytes in the sample files of the same file type;

[0131] An eighth determination module determines a ratio of the number of occurrences of the same byte to the total number of occurrences of all bytes to obtain a probability value;

[0132] A corresponding relationship establishing module, used to establish a corresponding relationship between the bytes, file types and probability values;

[0133] A creation module is used to create the byte probability library based on the correspondence between the bytes, file types and probability values.

[0134] In another specific embodiment, the device may further include:

[0135] A priority setting module, used to set the comparison priority of the first feature substring to be higher than that of the second feature substring;

[0136] The adjustment module is used to arrange the first characteristic substring and the second characteristic substring from high to low according to the comparison priority to obtain the adjusted virus characteristic string.

[0137] Optionally, the second characteristic substring includes a third characteristic substring and a fourth characteristic substring separated by the first characteristic substring;

[0138] Accordingly, the second comparison module 630 may include:

[0139] A ninth determination module, configured to determine data in the target file other than the data corresponding to the first characteristic substring as data to be detected; the data to be detected includes first data to be detected and second data to be detected separated by the data corresponding to the first characteristic substring;

[0140] A first comparison submodule, used for comparing the first to-be-detected data with the third characteristic substring;

[0141] The second comparison submodule compares the second data to be detected with the fourth characteristic substring when the first data to be detected includes the third characteristic substring.

[0142] Optionally, the virus detection module 640 is specifically configured to determine that the target file is a virus file when the comparison result is that the second data to be detected includes the fourth characteristic substring.

[0143] It should be noted that the virus detection device for files in the embodiments of the present invention can be deployed on a terminal, can be deployed on a server, or can be deployed jointly on a terminal and a server. The device provided in the above embodiments, when implementing its functions, only uses the division of the above functional modules as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In another specific embodiment, the virus detection device for files is jointly deployed on a terminal and a server, such as Figure 8 A schematic diagram of the structure of another file virus detection device is provided, the device includes: a sample library 810, a probability statistics module 820, a byte probability library 830, an original virus feature library 840, a feature adjustment module 850, an adjusted virus feature library 860 and a feature matching module 870, wherein the sample library 810, the probability statistics module 820, the byte probability library 830, the original virus feature library 840, the feature adjustment module 850 and the adjusted feature library 860 are deployed on the server side, and the feature matching module 870 is deployed on the terminal side. Specifically:

[0144] The sample library 810 stores a large amount of sample texts of different text types; the probability statistics module 820 may include the aforementioned third acquisition module, the seventh determination module, the eighth determination module, the correspondence establishment module and the creation module to realize the functions of the corresponding modules; the byte probability library 830 is associated with the probability statistics module 820 and is used to store the correspondence between bytes, file types and probability values; the original virus feature library 840 is used to store virus feature strings of different viruses; the feature adjustment module 850 may include the aforementioned first determination module 650, the second determination module 660, the calculation module 670, the third determination module 680, as well as the priority setting module and the adjustment module to realize the functions of the corresponding modules; the adjusted virus feature library 860 is used to store the adjusted virus feature string; the feature matching module 870 may include the aforementioned first acquisition module 610, the first comparison module 620, the second comparison module 630 and the virus detection module 640 to realize the functions of the corresponding modules.

[0145] In addition, the device and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation processes are detailed in the method embodiments, which will not be repeated here.

[0146] The virus detection device for files in the embodiment of the present invention first compares the target file with the first feature substring, and only when the comparison result is that the target file includes the first feature substring, compares the target file with the remaining feature substrings in the virus feature string, thereby filtering out mismatches with the highest probability during the first comparison (i.e., comparison with the first feature substring), avoiding continued comparison with the corresponding remaining feature substrings, accelerating virus feature matching, effectively shortening the time consumption of virus feature matching, and improving virus detection efficiency.

[0147] An embodiment of the present invention provides a terminal, which includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement a virus detection method for a file provided in the above method embodiment.

[0148] The memory can be used to store software programs and modules. The processor executes virus detection of various functional applications and files by running the software programs and modules stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs required for functions, etc.; the data storage area can store data created according to the use of the device, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory can also include a memory controller to provide the processor with access to the memory.

[0149] The method embodiments provided in the embodiments of the present invention can be executed in a computer terminal, a server or a similar computing device. Taking running on a terminal as an example, Fig. 9 : is a hardware structure block diagram of a terminal for running a file virus detection method provided by an embodiment of the present invention, specifically:

[0150] The terminal 900 may include an RF (Radio Frequency) circuit 910, a memory 920 including one or more computer-readable storage media, an input unit 930, a display unit 940, a sensor 950, an audio circuit 960, a WiFi (wireless fidelity) module 970, a processor 980 including one or more processing cores, and a power supply 90. Those skilled in the art will appreciate that Fig. 9 The terminal structure shown in the figure does not constitute a limitation on the terminal, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0151] The RF circuit 910 can be used for receiving and sending signals during information transmission or calls. In particular, after receiving the downlink information of the base station, it is handed over to one or more processors 980 for processing; in addition, the data related to the uplink is sent to the base station. Generally, the RF circuit 910 includes but is not limited to an antenna, at least one amplifier, a tuner, one or more oscillators, a user identity module (SIM) card, a transceiver, a coupler, an LNA (Low Noise Amplifier), a duplexer, etc. In addition, the RF circuit 910 can also communicate with the network and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to GSM (Global System of Mobile communication), GPRS (General Packet Radio Service), CDMA (Code Division Multiple Access), WCDMA (Wideband Code Division Multiple Access), LTE (Long Term Evolution), email, SMS (Short Messaging Service), etc.

[0152] The memory 920 can be used to store software programs and modules, and the processor 980 executes various functional applications and data processing by running the software programs and modules stored in the memory 920. The memory 920 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the terminal 900 (such as video data, a phone book, etc.), etc. In addition, the memory 920 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 920 may also include a memory controller to provide the processor 980 and the input unit 930 with access to the memory 920.

[0153] The input unit 930 may be used to receive input digital or character information, and to generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control. Specifically, the input unit 930 may include an image input device 931 and other input devices 932. The image input device 931 may be a camera or a photoelectric scanning device. In addition to the image input device 931, the input unit 930 may also include other input devices 932. Specifically, other input devices 932 may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, etc.

[0154] The display unit 940 may be used to display information input by a user or information provided to a user and various graphical user interfaces of the terminal 900, which may be composed of graphics, text, icons, videos, and any combination thereof. The display unit 940 may include a display panel 941, and the display panel 941 may be configured in the form of an LCD (Liquid Crystal Display), an OLED (Organic Light-Emitting Diode), or the like.

[0155] The terminal 900 may include at least one sensor 950, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 941 according to the brightness of the ambient light, and the proximity sensor may turn off the display panel 941 and / or the backlight when the terminal 900 is moved to the ear. As a type of motion sensor, the gravity acceleration sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors that the terminal 900 can also be configured with, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be repeated here.

[0156] The audio circuit 960, the speaker 961, and the microphone 962 can provide an audio interface between the user and the terminal 900. The audio circuit 960 can transmit the received audio data to the speaker 961 after converting the received audio data into an electrical signal, which is converted into a sound signal for output by the speaker 961; on the other hand, the microphone 962 converts the collected sound signal into an electrical signal, which is received by the audio circuit 960 and converted into audio data, and then the audio data is output to the processor 980 for processing, and then sent to another terminal through the RF circuit 910, or the audio data is output to the memory 920 for further processing. The audio circuit 960 may also include an earplug jack to provide communication between an external earphone and the terminal 900.

[0157] WiFi is a short-range wireless transmission technology. The terminal 900 can help users send and receive emails, browse web pages, and access streaming media through the WiFi module 970. It provides users with wireless broadband Internet access. Fig. 9 A WiFi module 970 is shown, but it is understandable that it is not an essential component of the terminal 900 and can be omitted as needed without changing the essence of the invention.

[0158] The processor 980 is the control center of the terminal 900. It uses various interfaces and lines to connect various parts of the entire mobile phone. By running or executing software programs and / or modules stored in the memory 920, and calling data stored in the memory 920, it executes various functions of the terminal 900 and processes data, thereby monitoring the mobile phone as a whole. Optionally, the processor 980 may include one or more processing cores; preferably, the processor 980 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 980.

[0159] The terminal 900 also includes a power supply 90 (such as a battery) for supplying power to each component. Preferably, the power supply can be logically connected to the processor 980 through a power management system, so that the power management system can manage charging, discharging, and power consumption management. The power supply 90 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0160] Although not shown, the terminal 900 may further include a Bluetooth module, etc., which will not be described in detail here.

[0161] Specifically in this embodiment, the terminal 900 also includes a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors. The one or more programs include instructions for executing the virus detection method for files provided in the above method embodiment.

[0162] An embodiment of the present invention also provides a computer-readable storage medium, which can be set in a terminal to store at least one instruction, at least one program, code set or instruction set related to a virus detection method for a file. The at least one instruction, the at least one program, the code set or instruction set is loaded and executed by the processor to implement the virus detection method for a file provided by the above method embodiment.

[0163] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.

[0164] It should be noted that the sequence of the embodiments of the present invention described above is for description only and does not represent the advantages and disadvantages of the embodiments. The above describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0165] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0166] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0167] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for detecting virus in a file, characterized in that: The method comprises: Get the target file; Based on the byte probability library, determine the probability value of the byte corresponding to the character in the virus feature string; determine multiple character substrings contained in the virus feature string according to the preset string length; sum the probability values ​​of the bytes corresponding to the characters in the character substring to obtain the total probability value corresponding to each character substring in the multiple character substrings; determine the character substring with the smallest total probability value in the multiple character substrings as the first feature substring of the virus feature string; Compare the target file with the first characteristic substring in the virus characteristic string; In the case where the target file includes the first characteristic substring, the target file is compared with a second characteristic substring in the virus characteristic string; the second characteristic substring is a continuous string in the virus characteristic string except the first characteristic substring; According to the comparison result with the second characteristic substring, virus detection is performed on the target file.

2. The method for detecting virus in a file according to claim 1, characterized in that: Determining the probability value of the byte corresponding to the character in the virus feature string based on the byte probability library includes: Determine the file type of the target file; Determine a target byte in the byte probability library that matches a byte corresponding to a character in the virus signature string; Determine a target correspondence relationship that matches the file type of the target file based on the correspondence relationship between the target byte, the file type and the probability value in the byte probability library; The probability value in the target corresponding relationship is obtained, and the probability value in the target corresponding relationship is used as the probability value of the byte corresponding to the character.

3. The method for detecting virus in a file according to claim 1, characterized in that: The method further comprises: Get sample files of different file types; Determining the number of occurrences of the same byte in sample files of the same file type, and the total number of occurrences of all bytes in the sample files of the same file type; Determine the ratio of the number of occurrences of the same byte to the total number of occurrences of all bytes to obtain a probability value; Establishing a correspondence between the bytes, file types and probability values; The byte probability library is created based on the correspondence between the bytes, file types and probability values.

4. The method for detecting virus in a file according to claim 1, characterized in that: After determining the character substring with the smallest total probability value among the multiple character substrings as the first characteristic substring of the virus characteristic string, the method further includes: Setting the comparison priority of the first feature substring to be higher than that of the second feature substring; The first characteristic substring and the second characteristic substring are arranged from high to low according to the comparison priority to obtain the adjusted virus characteristic string.

5. The method for detecting virus in a file according to claim 1, characterized in that: The second characteristic substring includes a third characteristic substring and a fourth characteristic substring separated by the first characteristic substring; The comparing the target file with the second characteristic substring in the virus characteristic string comprises: Determine the data in the target file other than the data corresponding to the first characteristic substring as the data to be detected; The data to be detected includes first data to be detected and second data to be detected separated by data corresponding to the first characteristic substring; Comparing the first to-be-detected data with the third characteristic substring; In the case where the first data to be detected includes the third characteristic substring, the second data to be detected is compared with the fourth characteristic substring.

6. The method for detecting virus in a file according to claim 5, characterized in that: The performing virus detection on the target file according to the comparison result with the second characteristic substring includes: When the comparison result is that the second to-be-detected data includes the fourth characteristic substring, it is determined that the target file is a virus file.

7. A file virus detection device, characterized in that: The device comprises: A first acquisition module, used for acquiring a target file; A first determination module is used to determine the probability value of the byte corresponding to the character in the virus feature string based on the byte probability library; A second determination module is used to determine a plurality of character substrings included in the virus characteristic character string according to a preset character string length; A calculation module, used for summing the probability values ​​of bytes corresponding to the characters in the character substring to obtain a total probability value corresponding to each character substring in the multiple character substrings; A third determination module, configured to determine the character substring with the smallest total probability value among the multiple character substrings as the first characteristic substring of the virus characteristic string; A first comparison module, used for comparing the target file with a first characteristic substring in a virus characteristic string; A second comparison module is used to compare the target file with a second characteristic substring in the virus characteristic string when the target file includes the first characteristic substring; the second characteristic substring is a continuous character string in the virus characteristic string except the first characteristic substring; The virus detection module is used to perform virus detection on the target file according to the comparison result with the second characteristic substring.

8. A terminal, characterized in that: The method comprises a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the virus detection method for a file according to any one of claims 1 to 6.

9. A computer-readable storage medium, wherein at least one instruction, at least one program, a code set or an instruction set is stored in the storage medium, wherein the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by a processor to implement the virus detection method for a file as described in any one of claims 1 to 6.