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

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

Info

Publication number
CN116483377B
CN116483377B CN202310706532.6A CN202310706532A CN116483377B CN 116483377 B CN116483377 B CN 116483377B CN 202310706532 A CN202310706532 A CN 202310706532A CN 116483377 B CN116483377 B CN 116483377B
Authority
CN
China
Prior art keywords
code
detection
configuration data
content
scanning
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.)
Active
Application number
CN202310706532.6A
Other languages
Chinese (zh)
Other versions
CN116483377A (en
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.)
Taiping Financial Technology Services Shanghai Co Ltd Shenzhen Branch
Original Assignee
Taiping Financial Technology Services Shanghai Co Ltd Shenzhen Branch
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 Taiping Financial Technology Services Shanghai Co Ltd Shenzhen Branch filed Critical Taiping Financial Technology Services Shanghai Co Ltd Shenzhen Branch
Priority to CN202310706532.6A priority Critical patent/CN116483377B/en
Publication of CN116483377A publication Critical patent/CN116483377A/en
Application granted granted Critical
Publication of CN116483377B publication Critical patent/CN116483377B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/57Certifying or maintaining trusted computer platforms, e.g. secure boots or power-downs, version controls, system software checks, secure updates or assessing vulnerabilities
    • G06F21/577Assessing vulnerabilities and evaluating computer system security
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Storage Device Security (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention discloses a code detection method, a code detection device, electronic equipment and a storage medium. The method comprises the following steps: acquiring code scanning configuration data and code checking configuration data for detecting code matching; scanning the detection codes according to the code scanning configuration data to obtain detection code content of the detection codes; and detecting and checking the content of the detection code according to the code checking configuration data. The technical scheme of the embodiment of the invention can improve the application range of code detection and the flexibility and suitability of code detection.

Description

Code detection method and device, electronic equipment and storage medium
Technical Field
The embodiment of the invention relates to the technical field of computer software application, in particular to a code detection method, a code detection device, electronic equipment and a storage medium.
Background
Code detection may be a solution in software engineering to scan source code directly using some scanning tool to find some semantic flaws and security holes that exist in the code.
In the prior art, code detection is performed on common mainstream programming codes, such as java (door-to-object programming language) codes and fndbugs.php (static analysis tool) codes, so that the programming language supported by each scanning tool is limited, and for cold door programming languages, such as database storage processes, scripts and front-end pages, whether the codes are written correctly can only be known by basic grammar checking in a compiler, so that it is difficult for one scanning tool to detect all programming languages.
Therefore, how to improve the universality of code detection is a problem to be solved.
Disclosure of Invention
The embodiment of the invention provides a code detection method, a device, electronic equipment and a storage medium, which can improve the application range of code detection and the flexibility and suitability of code detection.
According to an aspect of the present invention, there is provided a code detection method including:
acquiring code scanning configuration data and code checking configuration data for detecting code matching;
scanning the detection code according to the code scanning configuration data to acquire detection code content of the detection code;
and carrying out detection verification on the detection code content according to the code verification configuration data.
Optionally, the scanning the detection code according to the code scanning configuration data to obtain detection code content of the detection code includes:
scanning the detection code according to the code placeholder of the code scanning configuration data to obtain a scanning code segment of the detection code;
determining a code verification type and a first code verification identification of the scanning code segment according to the code placeholders matched with the scanning code segment;
And taking the scanning code segment, the code check type and the first code check identifier as detection code content of the detection code.
Optionally, the scanning the detection code according to the code placeholder of the code scanning configuration data to obtain a scanned code segment of the detection code includes:
determining a code placeholder matched with the detection code according to the code scanning configuration data; wherein the code placeholder comprises a start placeholder and an end placeholder;
scanning the detection code according to the initial placeholder to acquire initial code characters of the detection code content;
scanning the detection code according to the end placeholder to acquire an end code character of the detection code content;
and taking code content, located between the start code character and the end code character, in the detection code as the scanning code segment.
Optionally, the detecting and checking the content of the detecting code according to the code checking and configuring data includes:
determining target code check sub-configuration data from the code check configuration data according to the detected code content;
And carrying out detection verification on the detection code content according to the target code syndrome configuration data.
Optionally, the determining the target code syndrome configuration data from the code check configuration data according to the detected code content includes:
matching a second code verification identifier from the code verification configuration data according to the first code verification identifier of the scanning code section of the detection code;
and determining the target code check sub-configuration data from the code check configuration data according to the second code check identifier.
Optionally, the performing detection verification on the detection code content according to the target code syndrome configuration data includes:
determining a verification mode, a verification reference value and error prompt information of the content of the detection code according to the target code syndrome configuration data;
acquiring code content to be verified from the detection code content according to the verification mode;
matching the code content to be checked with the verification reference value;
and determining error prompt information of the detection code content according to the matching result of the code content to be checked and the verification reference value.
Optionally, before the code scan configuration data and the code check configuration data for detecting the code match are obtained, the method further includes:
Acquiring code collection associated information of the detection codes;
generating a code data table of the detection codes according to the code collection association information;
before the scanning of the detection code according to the code scanning configuration data, the method further comprises:
acquiring the detection code according to a code data table of the detection code;
after the detecting and checking the detecting code content according to the code checking configuration data, the method further comprises:
performing association relation matching with the code data table according to the code detection result of the detection code;
and generating a derivative detection result of the detection code according to the association relation matching result.
According to another aspect of the present invention, there is provided a code detection apparatus including:
the configuration data acquisition module is used for acquiring code scanning configuration data and code verification configuration data for detecting code matching;
the detection code content acquisition module is used for scanning the detection code according to the code scanning configuration data so as to acquire the detection code content of the detection code;
and the code content detection and verification module is used for detecting and verifying the detected code content according to the code verification configuration data.
According to another aspect of the present invention, there is provided an electronic apparatus including:
at least one processor; and
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 a code detection method according to any one of the embodiments of the present invention.
According to another aspect of the present invention, there is provided a computer readable storage medium storing computer instructions for causing a processor to execute the code detection method according to any one of the embodiments of the present invention.
According to the embodiment of the invention, the code scanning configuration data and the code verification configuration data matched with the detection code are obtained, so that the detection code is scanned according to the obtained code scanning configuration data to obtain the detection code content of the detection code, and the detection verification is carried out on the detection code content according to the code verification configuration data, so that the problems of small application range, low flexibility, low adaptability and the like of the existing code detection method are solved, the application range of the code detection can be improved, and the flexibility and the adaptability of the code detection are improved.
It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the invention or to delineate the scope of the invention. Other features of the present invention will become apparent from the description that follows.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1a is a flowchart of a code detection method according to a first embodiment of the present invention;
FIG. 1b is a flowchart of another code detection method according to a first embodiment of the present invention;
FIG. 2a is a flowchart of another code detection method according to a second embodiment of the present invention;
FIG. 2b is a flowchart of another code detection method according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a code detection device according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention.
Detailed Description
In order that those skilled in the art will better understand the present invention, a technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in which it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present invention without making any inventive effort, shall fall within the scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present invention and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the invention described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Example 1
Fig. 1a is a flowchart of a code detection method according to an embodiment of the present invention, where the embodiment is applicable to a case of performing code detection on any type of code content, and the method may be performed by a code detection device, where the device may be implemented by software and/or hardware, and may be generally integrated in an electronic device, where the electronic device may be a terminal device or a server device, and the embodiment of the present invention is not limited to a specific device type of the electronic device. Accordingly, as shown in fig. 1a, the method comprises the following operations:
s110, code scanning configuration data and code checking configuration data for detecting code matching are obtained.
The code scanning configuration data in this embodiment may be a coding rule pre-generated by using information such as an identifier, a check type, and a prompt, and scan the detection code according to the coding rule to obtain the corresponding code content. The encoding rule may be used to pre-configure code scan data, where the encoding rule may be understood as a process of converting language descriptions in a canonical document into data, the rule may be formulated according to a current system situation, and the current system situation may be a current system architecture and a used programming language type, which is not limited in this embodiment; the coding rule may include rule formulation, where rule formulation may be understood as mapping a rule by a system, mapping may be understood as coding an identifier, a check type, a hint, and a check type corresponding to a code for a manner to be processed during scanning, and inputting the rule to the system.
Specifically, the identifier may be determined according to the grammar of the programming language, so that when the detection code is detected, the check type to which the code belongs may be determined according to the identifier, further, the identifier may be a start placeholder and an end identifier, and thus, the position of the detection code may be determined by the identifier.
Specifically, the prompt information may be used to prompt the abnormal code that appears after scanning.
The code verification configuration data in the embodiment may be data that converts the specification content into data to be stored using a database table; the development specification can be understood as a rule for restricting the codes of the developer, and when the codes are scanned, the system can determine a programming mode according to the code rule and then perform rule matching according to the development specification.
Optionally, before acquiring the code scan configuration data and the code check configuration data for detecting the code match, the method may further include: acquiring code collection associated information of a detection code; and generating a code data table for detecting the codes according to the code collection association information.
The code collection association information can be file name, code influence scope, file type, use technology, association relation, business logic description and the like. The code data table may be a table for exposing code collection association information and storing it in a database manner.
In this embodiment, the code collection association information of the detection codes in the system may be collected and analyzed, and a corresponding code data table may be established. The code database may also be referred to as a code library, and may include a code storage path through which the content of the detection code and the associated information of the code may be acquired.
The code library can be understood as a code file dictionary of the system, and the initialization is completed by collecting and analyzing the code collection associated information of the detection codes, and the establishment of the code library provides a basis for the subsequent code scanning and data statistics.
Specifically, the collection of the files may be to collect the associated information including the code files, and the collection mode may be according to the actual situation of the system, and may be manual collection or file scanning.
The association information can determine whether the codes are associated with each other, and if the codes are abnormal, the association information can determine whether the codes associated with the codes are affected; the business logic description may be a basic function that the code can implement.
Optionally, before acquiring the code scan configuration data and the code check configuration data for detecting the code match, the method may further include: and acquiring the detection codes according to the code data table of the detection codes.
Further, the code scanning may be to determine a detection code according to path information of the code contained in the code library and scan the detection code.
S120, scanning the detection codes according to the code scanning configuration data to obtain detection code content of the detection codes.
The detected code content may include, but is not limited to, variables, constants, code blocks, execution statements, method names, and the like.
Alternatively, the scanning mode may be performed in a text reading mode, and the pre-written code scanning configuration data is used for scanning the detection code to intercept key information, and the intercepted information may include, but is not limited to, variables, constants, code blocks, execution sentences and method names.
S130, detecting and checking the content of the detection code according to the code checking configuration data.
The embodiment can detect and check the content of the detection code according to the code check configuration data, specifically, the content of the detection code is read row by row and matched, whether the code which does not meet the specification exists or not is judged according to the matching result, and if yes, the code is prompted.
The steps of the technical solution of this embodiment may be as shown in fig. 1b, where the solution may take a database storage process, SQL (Structured Query Language ) and HTML (Hyper Text Markup Language, hypertext markup language) front end codes as examples, and when preparing for operation, all files in the system may be collected and analyzed in advance before scanning the detection code, and a corresponding code library is established, and corresponding rules are configured according to code verification data; after the preparation work is finished, the detection codes are scanned, the scanning sequence can be carried out by referring to the priority in the code library, the scanning mode can be carried out in a text reading mode, key information is intercepted through a preconfigured rule, and the intercepted information can be the content of the detection codes; detecting code content may include, but is not limited to: after obtaining the content of the detection code, checking the detection code according to a preset rule, determining whether the detection code contains code segments which do not meet the requirements according to the checking result, giving prompt and saving, and finally generating a statistical report based on the checking result.
According to the technical scheme, the code scanning configuration data and the code verification configuration data matched with the detection code are obtained, so that the detection code is scanned according to the obtained code scanning configuration data to obtain the detection code content of the detection code, and the detection verification is carried out on the detection code content according to the code verification configuration data, so that the problems of small application range, low flexibility, low adaptability and the like of an existing code detection method are solved, the application range of code detection can be improved, and the flexibility and the adaptability of code detection are improved.
Example two
Fig. 2a is a flowchart of a code detection method according to a second embodiment of the present invention, which is implemented based on the foregoing embodiment, in this embodiment, the detection code is scanned according to the code scanning configuration data to obtain detection code content of the detection code, specifically: scanning the detection code according to the code placeholder of the code scanning configuration data to obtain a scanning code segment of the detection code; determining a code verification type and a first code verification identification of the scanning code segment according to the code placeholders matched with the scanning code segment; taking the scanning code segment, the code check type and the first code check mark as detection code content of the detection code; determining target code syndrome configuration data from the code check configuration data according to the detected code content; and carrying out detection verification on the detection code content according to the target code syndrome configuration data. Accordingly, as shown in fig. 2a, the method of this embodiment may include:
S210, code scanning configuration data and code checking configuration data for detecting code matching are obtained.
In this embodiment, the code base may collect code collection association information in the early stage of scanning and collect the code collection association information to generate a code base, where the code base is used as basic information for storing code files and stored in a database manner, and the basic fields may be as shown in the code data table in table 1 below:
TABLE 1 code data sheet
It should be noted that, the basic information of the code files collected by the code library needs to be ensured to be correct, so as to prevent errors from occurring in the follow-up process.
S220, scanning the detection codes according to the code placeholders of the code scanning configuration data to obtain scanning code segments of the detection codes.
The embodiment can acquire the code scanning data before scanning, traverse the file content according to the code scanning data, and locate the scanning code segment needing to detect the code through the placeholder in the code scanning data.
The code scan configuration data may be as shown in table 2 below:
table 2 code scan configuration data table
Start_ PLACEHOLDER, END _ PLACEHOLDER, HOLDER _type and REMARK in table 2 represent code scan configuration data such as a START placeholder, an end placeholder, a check TYPE, and a hint, respectively.
Optionally, scanning the detection code according to the code placeholder of the code scanning configuration data to obtain the scanned code segment of the detection code may include: determining code placeholders for detecting code matches according to the code scanning configuration data; wherein the code placeholders include a start placeholder and an end placeholder; scanning the detection code according to the initial placeholder to obtain initial code characters of the content of the detection code; scanning the detection code according to the end placeholder to obtain an end code character of the content of the detection code; the code content between the start code character and the end code character in the detection code is used as a scanning code segment.
In this embodiment, the scan code segment of the detection code may be obtained according to the start placeholder and the end placeholder of the code scan configuration data, for example: the detection of variables and/or constants may begin with a start placeholder for a second word, e.g., var i=0, "i," which is determined to be the current variable name and used as the detection content; the code blocks may be started from a start placeholder to an end placeholder, during which a code block is added separately if there is nesting. For example: if (1=1) { print; if (2=2) { print }, the determination detection code content may be: if (1=1) { print, if (2=2) { print }; the execution statement may be a function or formula, and the function may start from a start placeholder to an end placeholder; for the formula, a code block is added independently from the beginning placeholder to the ending placeholder, and for the method name, a row is obtained directly as code detection content.
The identifier may represent the location of the code, so that a code scan segment that needs to be detected can be determined according to the placeholder, where the code scan segment may be in the form of a single code, variable, formula, or the like.
As shown in the code scan configuration data table 2, the scan code segment may be determined by the following code scan configuration data:
var i=0;
If(i==1){
Print(“hello world”) };
if (i= =1) {. The first place requires development specification requirements, entering it into the development specification requirements table may be as shown in table 3 below:
table 3 scan code segment table
The start placeholder may be "if" (the end placeholder may be "}") in table 3, and when scanning is started, a corresponding scan code segment, i.e., an if code block, may be obtained according to the start placeholder and the end placeholder.
S230, determining the code verification type and the first code verification identification of the scanning code segment according to the code placeholder matched with the scanning code segment.
The first code verification identifier may be understood as an ID number configured by the code segment, and is used for correspondingly verifying the configuration data, that is, the corresponding code verification configuration data may be determined through the first code verification identifier.
Optionally, the embodiment of the present invention may convert the specification content into a database table for data use by code checking configuration data, and may specifically be shown in the development specification table of table 4 below:
TABLE 4 development Specification Table
It can be seen that, in the above table 4, the verification manner of the verification type may be determined by the code block ID, where the basic verification manner may be other verification manners such as regular expression, size, and inclusion, and in the above basic verification manner, the stacking 2-level directory may be further developed for the basic verification manner. According to the verification mode, a verification reference value can be determined, and the verification reference value can be understood as value information for verification; when the system acquires the development specification table to read and match the code content row by row, a verification mode of the regular expression is supported, if the matching is successful, the system represents that codes which do not accord with the specification exist in the code blocks, and the system can carry out error prompt and record on the codes.
This embodiment can be illustrated using the code Var Var1, as shown in Table 5 below:
table 5 first check mark
The code check type can be formula; the first code check identifier may be 1, which is not particularly limited in this embodiment.
S240, taking the scanning code segment, the code check type and the first code check mark as detection code content of the detection code.
Optionally, other scan configuration information such as a start placeholder, an end placeholder, a check type, and a hint may also be used as the detection code content of the detection code.
S250, determining target code check sub-configuration data from the code check configuration data according to the detected code content.
The target code syndrome configuration data may be understood as code check configuration data matching the first code check identifier.
It will be appreciated that a variety of different types of code check sub-configuration data may be included in the code check configuration data. Each code syndrome configuration data may specifically perform a detection check on a certain type of code content.
Optionally, determining the target code syndrome configuration data from the code check configuration data based on the detected code content may include: matching a second code verification identifier from the code verification configuration data according to the first code verification identifier of the scanning code segment of the detection code; and determining target code check sub-configuration data from the code check configuration data according to the second code check identifier.
The second code verification identifier may be an identifier in the code verification configuration data, and is used for identifying each specific code verification specification, and may be matched with the first code verification identifier to perform detection verification on the scanned code segment.
In this embodiment, the second code verification identifier is matched from the code verification configuration data according to the first code verification identifier of the scanned code segment of the detection code, which may be shown in table 6 below, and if it is determined that the first code verification identifier is 1 according to table 5 above, the second code verification identifier is correspondingly matched from the code verification data, as shown in table 6 below:
TABLE 6 second code check identifier determination Table
The contents of table 6 can be used as target code syndrome configuration data.
And S260, detecting and checking the content of the detection code according to the configuration data of the target code syndrome.
Optionally, performing detection verification on the content of the detection code according to the target code syndrome configuration data may include: determining a verification mode, a verification reference value and error prompt information of the content of the detection code according to the configuration data of the target code syndrome; acquiring code content to be verified from the detected code content according to the verification mode; matching the code content to be checked with the verification reference value; and determining error prompt information of the detected code content according to the matching result of the code content to be checked and the verification reference value.
The verification reference value may be a character, a numerical value, a formula, a regular expression, etc., and the embodiment of the present invention does not limit a specific value type of the verification reference value.
In this embodiment, the extracted code fragments may be verified. The verification is performed one by one according to a preset development specification table, and four optional verification modes can be adopted to judge according to specific code verification types of the code fragments, including but not limited to whether the code fragments contain, compare the sizes, regular expressions and other verification modes. By way of example, the regular expression may determine whether relevant code data of the load regular expression exists by including determining whether the verification reference value segment is currently included, comparing the target detection value in the extracted code segment to the verification reference value, and comparing the target detection value to the verification reference value. In addition, the verification may be performed according to other verification paradigms. Other verification modes can be judged through background custom logic output, so that error prompt information of the content of the detection code is determined. The error information is determined based on logic, and thus, error expression information is not included in each of the detection code contents.
Optionally, after acquiring the code scan configuration data and the code check configuration data for detecting the code match, the method may further include: performing association relation matching according to a code detection result of the detection code and a code data table; and generating a derivative detection result of the detection code according to the association relation matching result.
In this embodiment, the code verification data after code scanning will detect and verify the content of the detected code, and generate a derivative detection result, i.e. an exception list, according to the code detection result, and in addition, the influence range of the returned code of the code library will be associated. Taking the database container storage as an example, the anomaly list summary table can be as follows in table 7:
TABLE 7 abnormal List summary table
In this embodiment, a prompt may be generated according to the derived detection result, and one type of prompt may be a code warning for prompting a developer to give correction; the other type can be file prompt, which gives prompt to the file with large code influence scope to remind the developer of paying attention to the coding quality, and each prompt can be recorded under the corresponding developer name, so that information is provided for subsequent statistics; the method is convenient for counting the type of codes which are not standardized by the developer and is convenient for the developer to correct errors.
Alternatively, the scanning flow time of the embodiment for detecting the code can be one period from the start of file collection to the end of prompt alarm, and a single file can be used as the minimum scanning unit, so that the scanning is performed while developing, the development time is saved, and the code quality is improved.
The present embodiment may take the flowchart of the code detection method of fig. 2b as an example, and illustrates that the scan code segment is obtained by code verification configuration data; determining detection code content according to the scanning code segment; determining target code syndrome configuration data from the code verification configuration data according to the detected code content, and detecting and verifying the detected code content according to the target code syndrome configuration data; and judging whether to give an error prompt according to the verification result, if so, giving an alarm prompt, otherwise, determining the content of the detection code according to the scanning code segment.
In the embodiment, after detecting and checking the content of the detected code, statistics is required to be performed on the data, wherein the data statistics can be that when the system finishes one-time code scanning, a statistical report is output according to basic information of a code base; the statistical report can be used for summarizing the scanning result in combination with a code library and displaying the times of errors of development under different coding rules, and the summarization is displayed in a data mode for self-checking of developers; form styles are shown in the self-lookup table of table 8 below:
table 8 self-checking table
The embodiment determines the code verification type and the first code verification identification of the scanning code segment through the code placeholders matched with the scanning code segment; taking the scanning code segment, the code check type and the first code check mark as detection code content of the detection code; determining target code syndrome configuration data from the code check configuration data according to the detected code content; the method can solve the problems of small application range, low flexibility and adaptability and the like of the existing code detection method, can improve the application range of code detection and improve the flexibility and adaptability of code detection.
Example III
Fig. 3 is a schematic diagram of a code detection device according to a third embodiment of the present invention, as shown in fig. 3, where the device includes: configuration data acquisition 310, detection code content acquisition module 320, and code content detection verification module 330, wherein:
a configuration data acquisition module 310, configured to acquire code scan configuration data and code check configuration data for detecting code matching;
a detection code content acquisition module 320, configured to scan the detection code according to the code scan configuration data, so as to acquire detection code content of the detection code;
and the code content detection and verification module 330 is configured to perform detection and verification on the detected code content according to the code verification configuration data.
Optionally, the detecting code content obtaining module 320 is specifically configured to:
scanning the detection code according to the code placeholder of the code scanning configuration data to obtain a scanning code segment of the detection code;
determining a code verification type and a first code verification identification of the scanning code segment according to the code placeholders matched with the scanning code segment;
and taking the scanning code segment, the code check type and the first code check identifier as detection code content of the detection code.
Optionally, the detecting code content obtaining module 320 is specifically configured to:
determining a code placeholder matched with the detection code according to the code scanning configuration data; wherein the code placeholder comprises a start placeholder and an end placeholder;
scanning the detection code according to the initial placeholder to acquire initial code characters of the detection code content;
scanning the detection code according to the end placeholder to acquire an end code character of the detection code content;
and taking code content, located between the start code character and the end code character, in the detection code as the scanning code segment.
Optionally, the code content detection and verification module 320 is specifically configured to:
determining target code check sub-configuration data from the code check configuration data according to the detected code content;
and carrying out detection verification on the detection code content according to the target code syndrome configuration data.
Optionally, the code content detection and verification module 330 is specifically configured to:
the determining the target code check sub-configuration data from the code check configuration data according to the detected code content comprises the following steps:
Matching a second code verification identifier from the code verification configuration data according to the first code verification identifier of the scanning code section of the detection code;
and determining the target code check sub-configuration data from the code check configuration data according to the second code check identifier.
Optionally, the code content detection and verification module 330 is specifically configured to:
determining a verification mode, a verification reference value and error prompt information of the content of the detection code according to the target code syndrome configuration data;
acquiring code content to be verified from the detection code content according to the verification mode;
matching the code content to be checked with the verification reference value;
and determining error prompt information of the detection code content according to the matching result of the code content to be checked and the verification reference value.
Optionally, the device further comprises a code data table generating module, configured to obtain code collection association information of the detection code; generating a code data table of the detection codes according to the code collection association information;
the detection code acquisition module is used for: acquiring the detection code according to a code data table of the detection code;
The derivative detection result generation module is used for: performing association relation matching with the code data table according to the code detection result of the detection code; and generating a derivative detection result of the detection code according to the association relation matching result.
The code detection device can execute the code detection method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method. Technical details not described in detail in this embodiment may be referred to a code detection method provided in any embodiment of the present invention.
Since the above-described code detection device is a device capable of executing a code detection method according to an embodiment of the present invention, a person skilled in the art will be able to understand the specific implementation of the code detection device according to the embodiment and various modifications thereof based on the code detection method according to the embodiment of the present invention, so how the code detection device implements a code detection method according to an embodiment of the present invention will not be described in detail herein. The device used by those skilled in the art to implement a code detection method in the embodiments of the present invention is within the scope of protection intended in the present application.
Example IV
Fig. 4 shows a schematic diagram of the structure of an electronic device 10 that may be used to implement an embodiment of the invention. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 4, the electronic device 10 includes at least one processor 11, and a memory, such as a Read Only Memory (ROM) 12, a Random Access Memory (RAM) 13, etc., communicatively connected to the at least one processor 11, in which the memory stores a computer program executable by the at least one processor, and the processor 11 may perform various appropriate actions and processes according to the computer program stored in the Read Only Memory (ROM) 12 or the computer program loaded from the storage unit 18 into the Random Access Memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 may also be stored. The processor 11, the ROM 12 and the RAM 13 are connected to each other via a bus 14. An input/output (I/O) interface 15 is also connected to bus 14.
Various components in the electronic device 10 are connected to the I/O interface 15, including: an input unit 16 such as a keyboard, a mouse, etc.; an output unit 17 such as various types of displays, speakers, and the like; a storage unit 18 such as a magnetic disk, an optical disk, or the like; and a communication unit 19 such as a network card, modem, wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
The processor 11 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various processors running machine learning model algorithms, digital Signal Processors (DSPs), and any suitable processor, controller, microcontroller, etc. The processor 11 performs the various methods and processes described above, such as a code detection method.
In some embodiments, a code detection method may be implemented as a computer program tangibly embodied on a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 10 via the ROM 12 and/or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of one code detection method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform a code detection method in any other suitable way (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
A computer program for carrying out methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions/acts specified in the flowchart and/or block diagram block or blocks to be implemented. The computer program may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a computer-readable storage medium may be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, the computer readable storage medium may be a machine readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which a user can provide input to the electronic device. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), blockchain networks, and the internet.
The computing system may include clients and servers. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical hosts and VPS service are overcome.

Claims (6)

1. A code detection method, comprising:
acquiring code scanning configuration data and code checking configuration data for detecting code matching;
scanning the detection code according to the code scanning configuration data to acquire detection code content of the detection code;
detecting and checking the content of the detection code according to the code checking configuration data; the scanning the detection code according to the code scanning configuration data to obtain the detection code content of the detection code includes:
scanning the detection code according to the code placeholder of the code scanning configuration data to obtain a scanning code segment of the detection code;
determining a code verification type and a first code verification identification of the scanning code segment according to the code placeholders matched with the scanning code segment;
taking the scanning code segment, the code check type and the first code check identifier as detection code content of the detection code;
the code scanning configuration data is a coding rule pre-generated by using an identifier, a check type and prompt information;
before the code scanning configuration data and the code checking configuration data for detecting the code matching are obtained, the method further comprises the following steps:
Acquiring code collection associated information of the detection codes;
generating a code data table of the detection codes according to the code collection association information;
before the scanning of the detection code according to the code scanning configuration data, the method further comprises:
acquiring the detection code according to a code data table of the detection code;
after the detecting and checking the detecting code content according to the code checking configuration data, the method further comprises:
performing association relation matching with the code data table according to the code detection result of the detection code;
generating a derivative detection result of the detection code according to the association relation matching result;
the code collection association information is file name, code influence range, file type, use technology, association relation and service logic description;
the detecting and checking the content of the detecting code according to the code checking and configuring data comprises the following steps:
determining target code check sub-configuration data from the code check configuration data according to the detected code content;
detecting and checking the content of the detection code according to the target code syndrome configuration data;
The detecting and checking the content of the detecting code according to the target code syndrome configuration data comprises the following steps:
determining a verification mode, a verification reference value and error prompt information of the content of the detection code according to the target code syndrome configuration data;
acquiring code content to be verified from the detection code content according to the verification mode;
matching the code content to be checked with the verification reference value;
and determining error prompt information of the detection code content according to the matching result of the code content to be checked and the verification reference value.
2. The method of claim 1, wherein the scanning the detection code according to the code placeholders of the code scan configuration data to obtain scanned code segments of the detection code comprises:
determining a code placeholder matched with the detection code according to the code scanning configuration data; wherein the code placeholder comprises a start placeholder and an end placeholder;
scanning the detection code according to the initial placeholder to acquire initial code characters of the detection code content;
scanning the detection code according to the end placeholder to acquire an end code character of the detection code content;
And taking code content, located between the start code character and the end code character, in the detection code as the scanning code segment.
3. The method of claim 1, wherein said determining target code syndrome configuration data from said code syndrome configuration data based on said detected code content comprises:
matching a second code verification identifier from the code verification configuration data according to the first code verification identifier of the scanning code section of the detection code;
and determining the target code check sub-configuration data from the code check configuration data according to the second code check identifier.
4. A code detection apparatus, comprising:
the configuration data acquisition module is used for acquiring code scanning configuration data and code verification configuration data for detecting code matching;
the detection code content acquisition module is used for scanning the detection code according to the code scanning configuration data so as to acquire the detection code content of the detection code;
the code content detection and verification module is used for detecting and verifying the detected code content according to the code verification configuration data;
The detection code content acquisition module is specifically configured to:
scanning the detection code according to the code placeholder of the code scanning configuration data to obtain a scanning code segment of the detection code;
determining a code verification type and a first code verification identification of the scanning code segment according to the code placeholders matched with the scanning code segment;
taking the scanning code segment, the code check type and the first code check identifier as detection code content of the detection code;
the code scanning configuration data is a coding rule pre-generated by using an identifier, a check type and prompt information;
the code data table generation module is used for acquiring code collection association information of the detection codes; generating a code data table of the detection codes according to the code collection association information;
the detection code acquisition module is used for: acquiring the detection code according to a code data table of the detection code;
the derivative detection result generation module is used for: performing association relation matching with the code data table according to the code detection result of the detection code; generating a derivative detection result of the detection code according to the association relation matching result;
The code collection association information is file name, code influence range, file type, use technology, association relation and service logic description;
the code content detection and verification module is specifically used for:
determining target code check sub-configuration data from the code check configuration data according to the detected code content;
detecting and checking the content of the detection code according to the target code syndrome configuration data;
the code content detection and verification module is specifically used for:
determining a verification mode, a verification reference value and error prompt information of the content of the detection code according to the target code syndrome configuration data;
acquiring code content to be verified from the detection code content according to the verification mode;
matching the code content to be checked with the verification reference value;
and determining error prompt information of the detection code content according to the matching result of the code content to be checked and the verification reference value.
5. An electronic device, the electronic device comprising:
at least one processor; and
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 detection method of any one of claims 1-3.
6. A computer storage medium, characterized in that the computer readable storage medium stores computer instructions for causing a processor to implement the code detection method of any one of claims 1-3 when executed.
CN202310706532.6A 2023-06-15 2023-06-15 Code detection method and device, electronic equipment and storage medium Active CN116483377B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310706532.6A CN116483377B (en) 2023-06-15 2023-06-15 Code detection method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310706532.6A CN116483377B (en) 2023-06-15 2023-06-15 Code detection method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN116483377A CN116483377A (en) 2023-07-25
CN116483377B true CN116483377B (en) 2024-03-01

Family

ID=87215905

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310706532.6A Active CN116483377B (en) 2023-06-15 2023-06-15 Code detection method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116483377B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109165017A (en) * 2018-07-05 2019-01-08 平安科技(深圳)有限公司 Data verification method, device and computer storage medium
CN110309050A (en) * 2019-05-22 2019-10-08 深圳壹账通智能科技有限公司 Detection method, device, server and the storage medium of code specification
WO2019236189A1 (en) * 2018-06-05 2019-12-12 Hewlett-Packard Development Company, L.P. Code correlated scan initiations
CN112527257A (en) * 2020-12-16 2021-03-19 平安国际智慧城市科技股份有限公司 Data object processing method, electronic equipment and storage medium
CN114594933A (en) * 2022-01-20 2022-06-07 广东南方数码科技股份有限公司 Front-end code generation method and device based on file scanning and storage medium
CN116185853A (en) * 2023-02-22 2023-05-30 中银金融科技有限公司 Code verification method and device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019236189A1 (en) * 2018-06-05 2019-12-12 Hewlett-Packard Development Company, L.P. Code correlated scan initiations
CN109165017A (en) * 2018-07-05 2019-01-08 平安科技(深圳)有限公司 Data verification method, device and computer storage medium
CN110309050A (en) * 2019-05-22 2019-10-08 深圳壹账通智能科技有限公司 Detection method, device, server and the storage medium of code specification
CN112527257A (en) * 2020-12-16 2021-03-19 平安国际智慧城市科技股份有限公司 Data object processing method, electronic equipment and storage medium
CN114594933A (en) * 2022-01-20 2022-06-07 广东南方数码科技股份有限公司 Front-end code generation method and device based on file scanning and storage medium
CN116185853A (en) * 2023-02-22 2023-05-30 中银金融科技有限公司 Code verification method and device

Also Published As

Publication number Publication date
CN116483377A (en) 2023-07-25

Similar Documents

Publication Publication Date Title
CN110704304B (en) Application program testing method and device, storage medium and server
CN107145784B (en) Vulnerability scanning method and device and computer readable medium
CN109783356A (en) A kind of automated testing method and terminal
CN113434395B (en) Automatic generation method, device, equipment and medium for test cases
CN115269444B (en) Code static detection method and device and server
CN115186274A (en) IAST-based security test method and device
CN111767213B (en) Database check point testing method and device, electronic equipment and storage medium
CN116483377B (en) Code detection method and device, electronic equipment and storage medium
CN112540925A (en) New characteristic compatibility detection system and method, electronic device and readable storage medium
CN116775488A (en) Abnormal data determination method, device, equipment, medium and product
CN115543832A (en) Software code standard detection method, system, equipment and storage medium
CN110633204B (en) Program defect detection method and device
CN112632174A (en) Data inspection method, device and system
CN107943483B (en) Data forward analysis method in iOS
CN113672512A (en) Code inspection rule generating method, code inspection method, device and medium
CN113037521A (en) Method for identifying state of communication equipment, communication system and storage medium
CN111078538B (en) JMH-based rule automation test method
CN110866557B (en) Data evaluation method and device, storage medium and electronic device
CN117873860A (en) Data automatic testing method and device, electronic equipment and storage medium
CN117610016A (en) Interface management method and device
CN117910030A (en) Log sensitive information detection method, system, electronic equipment and storage medium
CN115357894A (en) Application program bug detection method and system with custom verification function
CN114443086A (en) System software package base maintenance method and system
CN116383058A (en) Conversion method and device of software system model, electronic equipment and medium
CN114817007A (en) Information processing method and device, electronic equipment and computer readable storage medium

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
GR01 Patent grant
GR01 Patent grant