CN115033489A - Code resource detection method and device, electronic equipment and storage medium - Google Patents

Code resource detection method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN115033489A
CN115033489A CN202210729972.9A CN202210729972A CN115033489A CN 115033489 A CN115033489 A CN 115033489A CN 202210729972 A CN202210729972 A CN 202210729972A CN 115033489 A CN115033489 A CN 115033489A
Authority
CN
China
Prior art keywords
code
configuration
detection result
file
detection
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210729972.9A
Other languages
Chinese (zh)
Inventor
练金明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN202210729972.9A priority Critical patent/CN115033489A/en
Publication of CN115033489A publication Critical patent/CN115033489A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to a test tool technology, and discloses a code resource detection method, which comprises the following steps: extracting a code file in a code resource file to be detected, and performing compiling detection on the code file to obtain a compiling detection result; analyzing codes of the code file to obtain an abstract syntax tree; carrying out code logic detection on the code file according to the abstract syntax tree to obtain a code logic detection result; extracting a configuration file in a code resource to be detected, and comparing the field consistency by using a preset standard configuration file and the code configuration file to perform code configuration detection to obtain a configuration detection result; and performing logical operation on the configuration detection result, the code logical detection result and the compiling detection result to obtain a target detection result. The invention also relates to a blockchain technique, the abstract syntax tree being storable in block link points. The invention also provides a code resource detection device, equipment and a medium. The invention can improve the accuracy of code resource detection.

Description

Code resource detection method and device, electronic equipment and storage medium
Technical Field
The present invention relates to testing tool technologies, and in particular, to a code resource detection method and apparatus, an electronic device, and a storage medium.
Background
With the application of various automatic code resource file deployment platforms, the detection of code resource files is also receiving more and more attention.
However, the existing code resource file detection method is usually only used for detecting whether the codes in the code resource file can be normally compiled or not, the detection dimension is single, and the accuracy rate of code resource detection is low.
Disclosure of Invention
The invention provides a code resource detection method, a code resource detection device, electronic equipment and a storage medium, and mainly aims to improve the accuracy of code resource detection.
Acquiring a code resource file to be detected;
extracting a code file in the code resource file to be detected, and performing compiling detection on the code file to obtain a compiling detection result;
analyzing the codes of the code file to obtain an abstract syntax tree;
performing traversal query on the nodes in the abstract syntax tree, and querying the nodes of a preset syntax type to obtain target nodes;
acquiring a logic detection rule of the grammar type, and judging whether the target node accords with the logic detection rule to obtain a code logic detection result;
extracting a configuration file in the code resource to be detected, and comparing the field consistency of a preset standard configuration file and the code configuration file to detect code configuration so as to obtain a configuration detection result;
performing logical operation on the configuration detection result, the code logical detection result and the compiling detection result to obtain a target detection result;
and sending the target detection result to preset terminal equipment of an inspector.
Optionally, the performing compilation detection on the code file to obtain a compilation detection result includes:
compiling the code file by using a preset code compiler to obtain a compiling result;
and mapping and converting the compiling result according to a preset mapping relation between the compiling result and the compiling detection result to obtain the compiling detection result.
Optionally, the performing traversal query on the nodes in the abstract syntax tree, and querying the nodes of a preset syntax type to obtain a target node includes:
extracting key words of the preset grammar types;
taking the name and the keywords of the abstract syntax tree as query parameters of a preset query function template to obtain a node query function;
and executing the node query function based on the abstract syntax tree to obtain the target node.
Optionally, the determining whether the target node meets the logic detection rule to obtain a code logic detection result includes:
constructing a detection script according to the logic detection rule;
executing the detection script to detect all codes in the target node to obtain a node logic detection result;
and performing logic operation on all the node logic detection results to obtain the code logic detection result.
Optionally, the performing, by using a preset standard configuration file, field consistency comparison with the code configuration file to perform code configuration detection to obtain a configuration detection result includes:
extracting all configuration fields in the code configuration file to obtain a test configuration field set;
extracting all configuration fields in the standard configuration file to obtain a standard configuration field set;
judging whether the test configuration field set is the same as the standard configuration field set;
when the test configuration field set is different from the standard configuration field set, the configuration detection result is abnormal;
when the test configuration field set is the same as the standard configuration field set, judging whether the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file;
when the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file, the configuration detection result is normal;
and when the field value of the existing configuration field in the code configuration file is not consistent with the field value of the same configuration field in the standard configuration file, determining that the configuration detection result is abnormal.
Optionally, the performing a logical operation on the configuration detection result, the code logic detection result, and the compilation detection result to obtain a target detection result includes:
when the configuration detection result, the code logic detection result and the compiling detection result are all normal, the target detection result is normal;
and when any one of the configuration detection result, the code logic detection result and the compiling detection result is abnormal, the target detection result is abnormal.
In order to solve the above problem, the present invention further provides a code resource detecting apparatus, including:
the code compiling and logic detecting module is used for acquiring a code resource file to be detected; extracting a code file in the code resource file to be detected, and performing compiling detection on the code file to obtain a compiling detection result; analyzing the codes of the code file to obtain an abstract syntax tree; performing traversal query on the nodes in the abstract syntax tree, and querying the nodes of a preset syntax type to obtain target nodes; acquiring a logic detection rule of the grammar type, and judging whether the target node accords with the logic detection rule to obtain a code logic detection result;
the code configuration detection module is used for extracting a configuration file in the code resource to be detected, and performing field consistency comparison by using a preset standard configuration file and the code configuration file to perform code configuration detection so as to obtain a configuration detection result;
the detection feedback module is used for carrying out logical operation on the configuration detection result, the code logical detection result and the compiling detection result to obtain a target detection result; and sending the target detection result to preset terminal equipment of an inspector.
Optionally, the performing, by using a preset standard configuration file, field consistency comparison with the code configuration file to perform code configuration detection to obtain a configuration detection result includes:
extracting all configuration fields in the code configuration file to obtain a test configuration field set;
extracting all configuration fields in the standard configuration file to obtain a standard configuration field set;
judging whether the test configuration field set is the same as the standard configuration field set;
when the test configuration field set is different from the standard configuration field set, the configuration detection result is abnormal;
when the test configuration field set is the same as the standard configuration field set, judging whether the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file;
when the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file, the configuration detection result is normal;
and when the field value of the existing configuration field in the code configuration file is not consistent with the field value of the same configuration field in the standard configuration file, determining that the configuration detection result is abnormal.
In order to solve the above problem, the present invention also provides an electronic device, including:
a memory storing at least one computer program; and
and the processor executes the computer program stored in the memory to realize the code resource detection method.
In order to solve the above problem, the present invention also provides a computer-readable storage medium, in which at least one computer program is stored, the at least one computer program being executed by a processor in an electronic device to implement the code resource detection method described above.
The embodiment of the invention analyzes the code of the code file to obtain an abstract syntax tree; performing traversal query on the nodes in the abstract syntax tree, and querying the nodes of a preset syntax type to obtain target nodes; acquiring a logic detection rule of the grammar type, and judging whether the target node accords with the logic detection rule to obtain a code logic detection result; extracting a configuration file in the code resource to be detected, and performing field consistency comparison by using a preset standard configuration file and the code configuration file to perform code configuration detection to obtain a configuration detection result; performing logical operation on the configuration detection result, the code logical detection result and the compiling detection result to obtain a target detection result; and detecting the code resource file to be detected from three dimensions of compiling, code service logic and code configuration, wherein the detected dimensions are more diverse, and the detection accuracy is higher. Therefore, the code resource detection method, the code resource detection device, the electronic equipment and the readable storage medium provided by the embodiment of the invention improve the accuracy of code resource detection.
Drawings
Fig. 1 is a schematic flowchart of a code resource detection method according to an embodiment of the present invention;
fig. 2 is a schematic block diagram of a code resource detection apparatus according to an embodiment of the present invention;
fig. 3 is a schematic diagram of an internal structure of an electronic device implementing a code resource detection method according to an embodiment of the present invention;
the implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The embodiment of the invention provides a code resource detection method. The execution subject of the code resource detection method includes, but is not limited to, at least one of electronic devices such as a server and a terminal that can be configured to execute the method provided by the embodiments of the present application. In other words, the code resource detection method may be performed by software or hardware installed in the terminal device or the server device, and the software may be a block chain platform. The server includes but is not limited to: the cloud server can be an independent server, or can be a cloud server providing basic cloud computing services such as cloud service, a cloud database, cloud computing, a cloud function, cloud storage, Network service, cloud communication, middleware service, domain name service, security service, a Content Delivery Network (CDN), a big data and artificial intelligence platform, and the like.
Referring to fig. 1, which is a schematic flow diagram of a code resource detection method according to an embodiment of the present invention, in an embodiment of the present invention, the code resource detection method includes:
s1, acquiring a code resource file to be detected;
in the embodiment of the present invention, the code resource file to be detected is a code resource file that needs to be deployed in a server, and includes: the method comprises the following steps of obtaining a code file and a configuration file, wherein the code file is a code to be deployed, the code configuration file is a configuration file of the code file, and the configuration file comprises but is not limited to: the method comprises the steps of environment variable configuration, dependent package version configuration, incremental package upgrade description configuration, code branch configuration and resource version number configuration.
The embodiment of the invention does not limit the type of the code resource file to be detected.
S2, extracting a code file in the code resource file to be detected, and performing compiling detection on the code file to obtain a compiling detection result;
in detail, in the embodiment of the present invention, performing compilation detection on the code file to obtain a compilation detection result includes:
compiling the code file by using a preset code compiler to obtain a compiling result;
and mapping and converting the compiling result according to a preset mapping relation between the compiling result and the compiling detection result to obtain the compiling detection result.
Specifically, in the embodiment of the present invention, the mapping relationship between the compilation result and the compilation detection result is that the compilation detection result corresponding to a passed compilation is normal, and the compilation detection result corresponding to a failed compilation is abnormal.
Further, in the embodiment of the present invention, when the compiling result is that the compiling fails, the compiling feedback log of the code compiler writes in a preset exception report, so as to obtain an updated exception report.
S3, carrying out code analysis on the code file to obtain an abstract syntax tree;
in the embodiment of the invention, the compiling detection of the code file only can detect whether the code file can be normally compiled or not, and cannot detect whether a service logic loophole exists in the code or not. For example: a native page opening and skipping method is arranged in a code file, if the development logic is page 1 skipping according to the condition 1, page 2 skipping according to the condition 2, if the conditions 1 and 2 are both met and the condition 1 has no return, the method can be normally compiled, but a business logic leak still exists, the method can go to the condition 2, and page skipping to the next page is carried out.
In the embodiment of the invention, in order to facilitate the logic vulnerability detection of the code file, the code of the code file is analyzed to obtain the abstract syntax tree.
In the embodiment of the invention, the code file can be analyzed through the syntax analyzer to generate the corresponding abstract syntax tree. Parsers (parsers), which are typically found as components of compilers or interpreters, perform syntax checking and construct data structures (typically hierarchical data structures such as parse trees, abstract syntax trees, etc.) consisting of input words.
In the embodiment of the present invention, a corresponding parser is selected according to a code type in the code file to parse the code file, for example: when the code file is a C language code file, the code file may be parsed by using a C language parser, and the C language parser may be a C language source code parser Pycparser, and the like, which is not limited in this embodiment of the present invention.
In another embodiment of the invention, the abstract syntax tree can be stored in the block link points, and the data access efficiency is improved by utilizing the characteristic of high throughput of the block link points.
S4, performing traversal query on the nodes in the abstract syntax tree, and querying the nodes with preset syntax types to obtain target nodes;
in this embodiment of the present invention, all nodes in the abstract syntax tree are syntax structures of specific syntax types in the code file, such as: and circulating, judging, assigning and the like, so that nodes with preset grammar types are inquired to obtain target nodes.
In detail, in the embodiment of the present invention, performing traversal query on nodes in the abstract syntax tree, and querying nodes of a preset syntax type to obtain a target node includes:
obtaining the grammar type of the node to obtain the node grammar type;
and determining the node with the node grammar type as a preset grammar type as the target node.
In another embodiment of the present invention, performing traversal query on nodes in the abstract syntax tree, and querying nodes of a preset syntax type to obtain a target node, includes:
extracting key words of the preset grammar type;
the grammar type of the embodiment of the invention can be identified by the keyword, if the grammar type is a judgment type, the corresponding keyword is if, and the node containing the keyword is the target node, therefore, the target node can be inquired by the keyword.
Taking the name and the keywords of the abstract syntax tree as query parameters of a preset query function template to obtain a node query function;
and executing the node query function based on the abstract syntax tree to obtain the target node.
Optionally, in the embodiment of the present invention, the query function template is an isinstance function, and the corresponding node in the abstract syntax tree may be found by executing the isinstance function, where: if the keyword is if, the name of the abstract syntax tree is a, then the node query function is exit (a.if), and executing the node query function can find a node containing an if statement in the abstract syntax tree, i.e. a target node S5, obtain a logic detection rule of the syntax type, and judge whether the target node meets the logic detection rule, so as to obtain a code logic detection result;
in the embodiment of the invention, a detection script is constructed according to the logic detection rule; executing the detection script to detect all codes in the target node to obtain a node logic detection result; and performing logic operation on all the node logic detection results to obtain the code logic detection result.
Specifically, the detection script in the embodiment of the present invention is a js file script.
In detail, in the embodiment of the present invention, the node logic detection result is normal or abnormal.
Further, in the embodiment of the present invention, performing a logical operation on all the node logical detection results to obtain the code logical detection result, where the method includes:
when all the node logic detection results are normal, the code logic detection result is normal;
and when any node logic detection result is abnormal, the code logic detection result is abnormal.
S6, extracting a configuration file in the code resource to be detected, and comparing the field consistency of a preset standard configuration file with the code configuration file to detect the code configuration to obtain a configuration detection result;
in the embodiment of the present invention, in order to ensure that the code resource file to be detected can be configured normally after being deployed, it is necessary to determine that the configuration information in the configuration file is correct, and therefore, code configuration detection needs to be performed on the code configuration file.
In detail, in the embodiment of the present invention, performing a field consistency comparison between a preset standard configuration file and the code configuration file to perform code configuration detection, so as to obtain a configuration detection result, where the method includes:
extracting all configuration fields in the code configuration file to obtain a test configuration field set;
extracting all configuration fields in the standard configuration file to obtain a standard configuration field set;
judging whether the test configuration field set is the same as the standard configuration field set or not;
when the test configuration field set is different from the standard configuration field set, the configuration detection result is abnormal;
in the embodiment of the present invention, when the test configuration field set is different from the standard configuration field set, the field with the difference between the test configuration field set and the standard configuration field set is written into the exception report.
When the test configuration field set is the same as the standard configuration field set, judging whether the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file;
when the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file, the configuration detection result is normal;
and when the field value of the existing configuration field in the code configuration file is not consistent with the field value of the same configuration field in the standard configuration file, determining that the configuration detection result is abnormal.
In the embodiment of the invention, when the field value of the existing configuration field in the code configuration file is not consistent with the field value of the same configuration field in the standard configuration file, the configuration field with different field values in the code configuration file and the corresponding field value are written into the exception report.
S7, performing logical operation on the configuration detection result, the code logical detection result and the compiling detection result to obtain a target detection result;
in the embodiment of the invention, in order to comprehensively analyze the code logic detection result and the configuration detection result, the code logic detection result and the configuration detection result are subjected to logic operation to obtain the target detection result.
In detail, in the embodiment of the present invention, the logical operation is an and operation, and thus, the performing a logical operation on the code logic detection result and the configuration detection result to obtain a target detection result includes:
when the configuration detection result, the code logic detection result and the compiling detection result are all normal, the target detection result is normal;
and when any one of the configuration detection result, the code logic detection result and the compiling detection result is abnormal, the target detection result is abnormal.
And S8, sending the target detection result to preset terminal equipment of an inspector.
The terminal device in the embodiment of the present invention includes but is not limited to: intelligent terminals such as cell-phone, computer, panel.
Further, in the embodiment of the present invention, when the target detection result is abnormal, after the target detection result is sent to a terminal device of an inspector, the abnormal report is sent to the terminal device.
FIG. 2 is a functional block diagram of the code resource detecting apparatus according to the present invention.
The code resource detecting apparatus 100 according to the present invention may be installed in an electronic device. According to the implemented functions, the code resource detection apparatus may include a code compiling and logic detection module 101, a code configuration detection module 102, and a detection feedback module 103, which may also be referred to as a unit, and refers to a series of computer program segments that can be executed by a processor of an electronic device and can perform fixed functions, and are stored in a memory of the electronic device.
In the present embodiment, the functions regarding the respective modules/units are as follows:
the code compiling and logic detecting module 101 is used for acquiring a code resource file to be detected; extracting a code file in the code resource file to be detected, and performing compiling detection on the code file to obtain a compiling detection result; analyzing the codes of the code file to obtain an abstract syntax tree; performing traversal query on nodes in the abstract syntax tree, and querying nodes of preset syntax types to obtain target nodes; acquiring a logic detection rule of the grammar type, and judging whether the target node accords with the logic detection rule to obtain a code logic detection result;
the code configuration detection module 102 is configured to extract a configuration file in the code resource to be detected, and perform field consistency comparison between a preset standard configuration file and the code configuration file to perform code configuration detection to obtain a configuration detection result;
the detection feedback module 103 is configured to perform logical operation on the configuration detection result, the code logical detection result, and the compilation detection result to obtain a target detection result; and sending the target detection result to preset terminal equipment of an inspector.
In detail, when the modules in the code resource detection apparatus 100 according to the embodiment of the present invention are used, the same technical means as the code resource detection method described in fig. 1 are adopted, and the same technical effects can be produced, which is not described herein again.
Fig. 3 is a schematic structural diagram of an electronic device implementing the code resource detection method according to the present invention.
The electronic device may comprise a processor 10, a memory 11, a communication bus 12 and a communication interface 13, and may further comprise a computer program, such as a code resource detection program, stored in the memory 11 and executable on the processor 10.
The memory 11 includes at least one type of readable storage medium, which includes flash memory, removable hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device, for example a removable hard disk of the electronic device. The memory 11 may also be an external storage device of the electronic device in other embodiments, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the electronic device. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device. The memory 11 may be used not only to store application software installed in the electronic device and various types of data, such as codes of a code resource detection program, but also to temporarily store data that has been output or will be output.
The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips. The processor 10 is a Control Unit (Control Unit) of the electronic device, connects various components of the electronic device by using various interfaces and lines, and executes various functions and processes data of the electronic device by running or executing programs or modules (e.g., code resource detection programs, etc.) stored in the memory 11 and calling data stored in the memory 11.
The communication bus 12 may be a PerIPheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. The communication bus 12 is arranged to enable connection communication between the memory 11 and at least one processor 10 or the like. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
Fig. 3 shows only an electronic device having components, and those skilled in the art will appreciate that the structure shown in fig. 3 does not constitute a limitation of the electronic device, and may include fewer or more components than those shown, or some components may be combined, or a different arrangement of components.
For example, although not shown, the electronic device may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 10 through a power management device, so that functions such as charge management, discharge management, and power consumption management are implemented through the power management device. The power source may also include any component of one or more dc or ac power sources, recharging devices, power failure classification circuits, power converters or inverters, power status indicators, and the like. The electronic device may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
Optionally, the communication interface 13 may include a wired interface and/or a wireless interface (e.g., WI-FI interface, bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices.
Optionally, the communication interface 13 may further include a user interface, which may be a Display (Display), an input unit (such as a Keyboard (Keyboard)), and optionally, a standard wired interface, or a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable, among other things, for displaying information processed in the electronic device and for displaying a visualized user interface.
It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.
The code resource detection program stored in the memory 11 of the electronic device is a combination of a plurality of computer programs, which when run in the processor 10, can implement:
acquiring a code resource file to be detected;
extracting a code file in the code resource file to be detected, and performing compiling detection on the code file to obtain a compiling detection result;
analyzing the codes of the code file to obtain an abstract syntax tree;
performing traversal query on the nodes in the abstract syntax tree, and querying the nodes of a preset syntax type to obtain target nodes;
acquiring a logic detection rule of the grammar type, and judging whether the target node accords with the logic detection rule to obtain a code logic detection result;
extracting a configuration file in the code resource to be detected, and performing field consistency comparison by using a preset standard configuration file and the code configuration file to perform code configuration detection to obtain a configuration detection result;
performing logical operation on the configuration detection result, the code logical detection result and the compiling detection result to obtain a target detection result;
and sending the target detection result to preset terminal equipment of an inspector.
Specifically, the processor 10 may refer to the description of the relevant steps in the embodiment corresponding to fig. 1 for a specific implementation method of the computer program, which is not described herein again.
Further, the electronic device integrated module/unit, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a computer readable storage medium. The computer readable medium may be non-volatile or volatile. The computer-readable medium may include: any entity or device capable of carrying said computer program code, a recording medium, a usb-disk, a removable hard disk, a magnetic diskette, an optical disk, a computer Memory, a Read-Only Memory (ROM).
Embodiments of the present invention may also provide a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program may implement:
acquiring a code resource file to be detected;
extracting a code file in the code resource file to be detected, and performing compiling detection on the code file to obtain a compiling detection result;
analyzing the codes of the code file to obtain an abstract syntax tree;
performing traversal query on nodes in the abstract syntax tree, and querying nodes of preset syntax types to obtain target nodes;
acquiring a logic detection rule of the grammar type, and judging whether the target node accords with the logic detection rule to obtain a code logic detection result;
extracting a configuration file in the code resource to be detected, and performing field consistency comparison by using a preset standard configuration file and the code configuration file to perform code configuration detection to obtain a configuration detection result;
performing logical operation on the configuration detection result, the code logical detection result and the compiling detection result to obtain a target detection result;
and sending the target detection result to preset terminal equipment of an inspector.
Further, the computer usable storage medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to the use of the blockchain node, and the like.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method can be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
The embodiment of the application can acquire and process related data based on an artificial intelligence technology. Among them, Artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the system claims may also be implemented by one unit or means in software or hardware. The terms second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only intended to illustrate the technical solutions of the present invention and not to limit the same, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims (10)

1. A method for code resource detection, the method comprising:
acquiring a code resource file to be detected;
extracting a code file in the code resource file to be detected, and performing compiling detection on the code file to obtain a compiling detection result;
analyzing the codes of the code file to obtain an abstract syntax tree;
performing traversal query on the nodes in the abstract syntax tree, and querying the nodes of a preset syntax type to obtain target nodes;
acquiring a logic detection rule of the grammar type, and judging whether the target node accords with the logic detection rule to obtain a code logic detection result;
extracting a configuration file in the code resource to be detected, and comparing the field consistency of a preset standard configuration file and the code configuration file to detect code configuration so as to obtain a configuration detection result;
performing logical operation on the configuration detection result, the code logical detection result and the compiling detection result to obtain a target detection result;
and sending the target detection result to preset terminal equipment of an inspector.
2. The method for detecting code resources according to claim 1, wherein the performing compilation detection on the code file to obtain a compilation detection result includes:
compiling the code file by using a preset code compiler to obtain a compiling result;
and mapping and converting the compiling result according to a preset mapping relation between the compiling result and the compiling detection result to obtain the compiling detection result.
3. The method for detecting code resources according to claim 1, wherein the performing a traversal query on the nodes in the abstract syntax tree, querying the nodes of a preset syntax type to obtain a target node, includes:
extracting key words of the preset grammar types;
taking the name and the keywords of the abstract syntax tree as query parameters of a preset query function template to obtain a node query function;
and executing the node query function based on the abstract syntax tree to obtain the target node.
4. The method for detecting code resources according to claim 1, wherein the determining whether the target node complies with the logic detection rule to obtain a code logic detection result comprises:
constructing a detection script according to the logic detection rule;
executing the detection script to detect all codes in the target node to obtain a node logic detection result;
and performing logic operation on all the node logic detection results to obtain the code logic detection result.
5. The method for detecting code resources according to claim 1, wherein the performing field consistency comparison between the preset standard configuration file and the code configuration file to perform code configuration detection to obtain a configuration detection result comprises:
extracting all configuration fields in the code configuration file to obtain a test configuration field set;
extracting all configuration fields in the standard configuration file to obtain a standard configuration field set;
judging whether the test configuration field set is the same as the standard configuration field set;
when the test configuration field set is different from the standard configuration field set, the configuration detection result is abnormal;
when the test configuration field set is the same as the standard configuration field set, judging whether the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file;
when the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file, the configuration detection result is normal;
and when the field value of the existing configuration field in the code configuration file is not consistent with the field value of the same configuration field in the standard configuration file, determining that the configuration detection result is abnormal.
6. The method for detecting code resources according to any one of claims 1 to 6, wherein the performing a logical operation on the configuration detection result, the code logic detection result, and the compilation detection result to obtain a target detection result includes:
when the configuration detection result, the code logic detection result and the compiling detection result are all normal, the target detection result is normal;
and when any one of the configuration detection result, the code logic detection result and the compiling detection result is abnormal, the target detection result is abnormal.
7. A code resource detection apparatus, comprising:
the code compiling and logic detecting module is used for acquiring a code resource file to be detected; extracting a code file in the code resource file to be detected, and performing compiling detection on the code file to obtain a compiling detection result; analyzing the codes of the code file to obtain an abstract syntax tree; performing traversal query on nodes in the abstract syntax tree, and querying nodes of preset syntax types to obtain target nodes; acquiring a logic detection rule of the grammar type, and judging whether the target node accords with the logic detection rule to obtain a code logic detection result;
the code configuration detection module is used for extracting a configuration file in the code resource to be detected, and performing field consistency comparison by using a preset standard configuration file and the code configuration file to perform code configuration detection so as to obtain a configuration detection result;
the detection feedback module is used for carrying out logical operation on the configuration detection result, the code logic detection result and the compiling detection result to obtain a target detection result; and sending the target detection result to preset terminal equipment of an inspector.
8. The apparatus for detecting code resource according to claim 7, wherein the performing a field consistency comparison between the preset standard configuration file and the code configuration file to perform a code configuration detection to obtain a configuration detection result comprises:
extracting all configuration fields in the code configuration file to obtain a test configuration field set;
extracting all configuration fields in the standard configuration file to obtain a standard configuration field set;
judging whether the test configuration field set is the same as the standard configuration field set or not;
when the test configuration field set is different from the standard configuration field set, the configuration detection result is abnormal;
when the test configuration field set is the same as the standard configuration field set, judging whether the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file;
when the field value of each configuration field in the code configuration file is consistent with the field value of the same configuration field in the standard configuration file, the configuration detection result is normal;
and when the field value of the existing configuration field in the code configuration file is not consistent with the field value of the same configuration field in the standard configuration file, determining that the configuration detection result is abnormal.
9. An electronic device, characterized in that the electronic device comprises:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor;
wherein the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the code resource detection method of any one of claims 1 to 6.
10. A computer-readable storage medium storing a computer program, wherein the computer program is configured to implement a code resource detection method according to any one of claims 1 to 6 when executed by a processor.
CN202210729972.9A 2022-06-24 2022-06-24 Code resource detection method and device, electronic equipment and storage medium Pending CN115033489A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210729972.9A CN115033489A (en) 2022-06-24 2022-06-24 Code resource detection method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210729972.9A CN115033489A (en) 2022-06-24 2022-06-24 Code resource detection method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115033489A true CN115033489A (en) 2022-09-09

Family

ID=83126825

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210729972.9A Pending CN115033489A (en) 2022-06-24 2022-06-24 Code resource detection method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115033489A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116126736A (en) * 2023-04-17 2023-05-16 青岛青软晶尊微电子科技有限公司 Chip code optimization method based on user requirements

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116126736A (en) * 2023-04-17 2023-05-16 青岛青软晶尊微电子科技有限公司 Chip code optimization method based on user requirements
CN116126736B (en) * 2023-04-17 2023-07-07 青岛青软晶尊微电子科技有限公司 Chip code optimization method based on user requirements

Similar Documents

Publication Publication Date Title
CN113238929B (en) Code testing method and device based on Mock data, electronic equipment and storage medium
CN112506779A (en) Software interface testing method and device, electronic equipment and storage medium
CN112732567B (en) Mock data testing method and device based on ip, electronic equipment and storage medium
CN113377661A (en) Interface testing method and device, electronic equipment and storage medium
CN112559337A (en) Code coverage rate testing method and device, electronic equipment and storage medium
CN112631903A (en) Task testing method and device, electronic equipment and storage medium
CN113806434A (en) Big data processing method, device, equipment and medium
CN115033489A (en) Code resource detection method and device, electronic equipment and storage medium
CN112579475A (en) Code testing method, device, equipment and readable storage medium
CN113360139A (en) Integration method and device of front-end frame, electronic equipment and storage medium
CN116483888A (en) Program evaluation method and device, electronic equipment and computer readable storage medium
CN114816371B (en) Message processing method, device, equipment and medium
CN113051171B (en) Interface testing method, device, equipment and storage medium
CN114896164A (en) Interface optimization method and device, electronic equipment and storage medium
CN111752600B (en) Code anomaly detection method and device, computer equipment and storage medium
CN114385155A (en) vue project visualization tool generation method, device, equipment and storage medium
CN114510400A (en) Task execution method and device, electronic equipment and storage medium
CN113176993A (en) Case testing method and device, electronic equipment and storage medium
CN112686759A (en) Account checking monitoring method, device, equipment and medium
CN113485711A (en) Task triggering method and device based on dependency relationship, electronic equipment and medium
CN114185797A (en) Front-end code checking method and device, electronic equipment and readable storage medium
CN113064797B (en) Front-end monitoring method and device, electronic equipment and storage medium
CN116610572A (en) Object testing method and device, electronic equipment and storage medium
CN115357474A (en) Local test method, device, equipment and storage medium
CN114564413B (en) Synchronous equipment testing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination