A large model-based automated code generation and optimization method and system
By analyzing and symbolizing functional requirements using a large model, and combining it with a vulnerability knowledge graph and a remediation case library, a difference graph is constructed to adjust parameters. This solves the problems of non-real-time generation of code by large models and lack of closed-loop feedback in existing technologies, achieving accurate vulnerability detection and remediation, and improving the security of the generated code.
Patent Information
- Application Number
- CN202511339604.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-19
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2045-09-19
AI Technical Summary
In existing technologies, post-static analysis tools that utilize large language models to generate code cannot meet real-time requirements, are difficult to effectively cover the complex vulnerability patterns unique to code generated by large models, and lack a closed-loop feedback mechanism, resulting in high false negative and false positive rates. Furthermore, the remediation suggestions are too general and cannot continuously improve the security of the generated code.
The system generates an initial logical framework by analyzing functional requirements through a large model and then symbolizes it. It constructs a vulnerability knowledge graph with weighted indexes to perform semantic similarity and path pattern matching. Combined with a historical remediation case library, it generates precise remediation strategies, constructs a difference graph between normal and risky execution modes, and uses adversarial disturbance factors to adjust the parameters of the large model to achieve a closed loop of vulnerability self-remediation.
It enables accurate detection of security vulnerabilities throughout the entire code generation process, generates targeted remediation solutions, dynamically optimizes model parameters, ensures closed-loop security enhancement of remediation effects, and continuously reduces the vulnerability recurrence rate.
Smart Images

Figure CN120850301B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of intelligent code generation and collaborative optimization, in particular to an automatic code generation and optimization method and system based on a large model. BACKGROUND
[0002] In the application scenario of automatically generating code by using a large language model, especially in the DevOps process, low-code platform or AI-assisted programming tool that requires rapid iteration, it is a serious challenge to ensure the security of the generated code. This scenario urgently needs a technical solution that can automatically and accurately identify potential security vulnerabilities during the code generation process or within a very short time after generation, and generate targeted repair strategies or even automatically complete the repair. The ideal technology needs to deeply understand the semantics, control flow and data dependency of the code, correlate the vulnerability knowledge base, and have a closed-loop self-optimization capability, that is, use the detection results to dynamically adjust the generation model to reduce the vulnerability recurrence rate from the source, and realize the closed loop of "generation is safe" or "immediate repair".
[0003] To meet the above needs, a representative technical solution at present is to integrate mature static application security testing tools as a post-processing link into the large model code generation pipeline. The process of this solution is as follows: after the large model generates complete source code, it triggers the static application security testing tool to perform scanning; the static application security testing tool performs security detection on the generated code by pattern matching and taint analysis based on its pre-defined, manually maintained vulnerability feature rule base; and finally outputs a report containing the location, type and risk level of the vulnerability, and sometimes also provides general repair suggestions.
[0004] However, this integration scheme of post-processing static analysis tools has significant defects. The detection process occurs after code generation, which disrupts the continuity of the development process and cannot meet the real-time requirements, causing feedback delay. More importantly, the rule base relied on by the static application security testing tool mainly faces traditional manually written code patterns, and it is difficult to effectively cover the unique, novel or complex vulnerability patterns of large model generated code. The rule update lags behind the evolution of new vulnerabilities and large model capabilities, resulting in high false negative and false positive rates. At the same time, its understanding of the deep semantics, data flow and control flow of the code is limited, especially when facing non-classical structure code that may be generated by the large model, the repair suggestions provided are often too general and coarse-grained, lacking precise understanding of the specific generation context, and it is difficult to achieve reliable self-repair. In addition, this scheme is a one-way process and lacks a closed-loop feedback mechanism, and the detection results cannot be used to optimize the generation strategy of the large model, and the security of the generated code cannot be continuously improved from the root. SUMMARY
[0005] The application provides a large model-based automatic code generation and optimization method and system to solve the problems of non-real-time, poor rule library adaptability, coarse-grained repair suggestions, and lack of closed-loop feedback optimization mechanism of post-static analysis tools in the large model code generation scenario.
[0006] In a first aspect, the application provides a large model-based automatic code generation and optimization method, comprising:
[0007] Receiving a functional requirement description, generating an initial logical framework by analyzing the functional requirement description through a large model, and performing symbolic conversion processing on the initial logical framework to form a symbolic structure;
[0008] Generating a code intermediate representation of reserved variable operation semantics, execution path boundaries, and resource access patterns based on the symbolic structure to generate source code through the code intermediate representation conversion;
[0009] Extracting vulnerability feature vectors from a vulnerability knowledge graph, constructing a weighted index vulnerability knowledge set, using parallel computing resources to scan the instruction sequence of the source code, and performing semantic similarity calculation and path pattern matching between the instruction sequence and the vulnerability feature vectors in the vulnerability knowledge set to mark the target instruction position with security risks and the corresponding vulnerability type code and risk level;
[0010] Retrieving a historical repair case library based on the vulnerability type code and risk level, establishing a matching relationship between vulnerability patterns and repair strategies according to the retrieval results, and generating an optimization strategy set containing repair operation sequences and constraint conditions based on the matching relationship;
[0011] Loading a context semantic analysis model at the target instruction position, analyzing the data dependency relationship and control flow association relationship between instructions, and constructing a difference graph of normal execution mode and risk execution mode based on the optimization strategy set to generate semantic features;
[0012] Based on the semantic features, a vulnerability sample with an adversarial perturbation factor is constructed to adjust the large model parameters through the vulnerability sample, and the source code generated after fine-tuning is rechecked for vulnerabilities.
[0013] Optionally, the vulnerability sample with an adversarial perturbation factor is constructed based on the semantic features to adjust the large model parameters through the vulnerability sample, and the source code generated after fine-tuning is rechecked for vulnerabilities, comprising:
[0014] Generating a numerical offset based on the variable difference feature in the semantic features, generating a path modification point based on the path difference feature in the semantic features, and combining the numerical offset and the path modification point to form a perturbation factor;
[0015] inject the perturbation factor at the corresponding position of the source code instruction sequence to generate a vulnerability sample containing the original instruction sequence and the modified instruction sequence;
[0016] input the vulnerability sample into the large model, adjust the large model parameters according to the difference between the modified instruction sequence and the original instruction sequence, generate a new version of source code using the large model after parameter adjustment, and perform vulnerability rechecking on the new version of source code.
[0017] Optionally, the inputting the vulnerability sample into the large model, adjusting the large model parameters according to the difference between the modified instruction sequence and the original instruction sequence, and generating a new version of source code using the large model after parameter adjustment and performing vulnerability rechecking on the new version of source code, comprises:
[0018] input the vulnerability sample into the large model, compare the running behaviors of the modified instruction sequence and the original instruction sequence, and extract the behavior change value and the result difference value;
[0019] generate a difference degree value based on the behavior change value and the result difference value, perform a reverse update operation to adjust the large model weight, and generate a new version of source code through the adjusted large model;
[0020] perform vulnerability rechecking on the new version of source code, feed back the rechecking result to the vulnerability knowledge graph for continuous updating of the feature vector, and form a continuously evolving code security generation capability.
[0021] Optionally, the loading the context semantic analysis model at the target instruction position, analyzing the data dependency relationship between instructions and the control flow association relationship, combining the optimization strategy set to construct a difference graph of normal execution mode and risk execution mode to generate semantic features, comprises:
[0022] loading the context semantic analysis model at the target instruction position to analyze the instruction sequence, analyzing the data dependency relationship including variable generation position, variable use position and variable transmission path in the instruction sequence, and the control flow relationship including condition judgment point and loop control point;
[0023] based on the data dependency relationship and the control flow relationship, constructing a normal execution mode containing variable change sequence and control flow sequence, and combining the optimization strategy set to simulate a risk execution mode containing variable abnormal sequence and control flow abnormal path when a vulnerability is triggered; comparing the normal execution mode and the risk execution mode to identify variable difference positions and control flow difference positions to construct a difference graph, and extracting semantic features including variable difference features and path difference features from the difference graph.
[0024] Optionally, the vulnerability feature vector is extracted from the vulnerability knowledge graph, a vulnerability knowledge set with weighted index is constructed, parallel computing resources are used to scan the instruction sequence of the source code, semantic similarity calculation and path pattern matching are performed between the instruction sequence and the vulnerability feature vector in the vulnerability knowledge set, the target instruction position with security risks and the corresponding vulnerability type code and risk level are marked, including:
[0025] The vulnerability record is extracted from the vulnerability knowledge graph and converted into a vulnerability feature vector, and a weighted value is assigned to each vulnerability feature vector to construct a vulnerability knowledge set with weighted index;
[0026] The instruction sequence of the source code is divided into multiple instruction segments using parallel computing resources, instruction features are formed for the instruction segments, and the instruction features are converted into numerical features;
[0027] The semantic similarity values of the numerical features corresponding to different instruction segments in the instruction sequence and the vulnerability feature vectors in the vulnerability knowledge set are calculated, and the operation symbol sequence of different instruction segments in the instruction sequence and the path pattern matching degree of the vulnerability feature vectors are detected;
[0028] When the semantic similarity value exceeds the corresponding weight value and the path pattern matching degree reaches a set threshold, the position of the instruction segment is marked as a target position, and the vulnerability type code and risk level corresponding to the target position are extracted.
[0029] Optionally, the historical repair case library is retrieved based on the vulnerability type code and risk level, the matching relationship between the vulnerability pattern and the repair strategy is established according to the retrieval result, and the optimization strategy set containing the repair operation sequence and the constraint condition is generated based on the matching relationship, including:
[0030] The historical repair case library is retrieved according to the vulnerability type code and risk level, the vulnerability repair case containing the vulnerability pattern and the repair strategy is obtained, the corresponding relationship between the vulnerability pattern and the repair strategy is established to form a matching relationship;
[0031] Based on the matching relationship, the repair strategy is analyzed, the operation action sequence composed of multiple operation actions and action objects in execution order and the constraint condition containing execution trigger condition and resource occupation limit are extracted, and the optimization strategy set containing the operation action sequence and the constraint condition is generated.
[0032] Optionally, the code intermediate representation of the reserved variable operation semantics, execution path boundary and resource access pattern is generated based on the symbolic structure, and the source code is generated by converting the code intermediate representation, including:
[0033] Based on the symbolic structure, a reserved variable operation meaning containing an action object identifier, an action type, and an action result identifier is extracted, an execution path boundary containing a path start position and a path end position is extracted, and a resource access mode containing a resource type identifier and an access action type is extracted;
[0034] Based on the reserved variable operation meaning, the execution path boundary, and the resource access mode, a code intermediate representation is constructed.
[0035] The code intermediate representation is traversed, the reserved variable operation meaning is converted into a variable assignment statement, and the resource access mode is converted into a resource call statement.
[0036] According to the position information of the execution path boundary, a flow control statement is added in the variable assignment statement and the resource call statement to form a final source code.
[0037] In a second aspect, the present application provides an automatic code generation and optimization system based on a large model, comprising:
[0038] A parsing module is configured to receive a function requirement description, parse the function requirement description through a large model to generate an initial logic framework, and perform symbolic conversion processing on the initial logic framework to form a symbolic structure.
[0039] A conversion module is configured to generate a code intermediate representation of a reserved variable operation semantic, an execution path boundary, and a resource access mode based on the symbolic structure, and generate a source code through conversion of the code intermediate representation.
[0040] A marking module is configured to extract a vulnerability feature vector from a vulnerability knowledge graph, construct a vulnerability knowledge set with a weighted index, scan an instruction sequence of the source code using parallel computing resources, match the instruction sequence with a vulnerability feature vector in the vulnerability knowledge set based on semantic similarity, and mark a target instruction position with a security risk and a corresponding vulnerability type code and risk level.
[0041] A matching module is configured to retrieve a historical repair case library based on the vulnerability type code and the risk level, establish a matching relationship between a vulnerability pattern and a repair strategy based on a retrieval result, and generate an optimization strategy set containing a repair operation sequence and a constraint condition based on the matching relationship.
[0042] A generation module is configured to load a context semantic analysis model at the target instruction position, analyze an inter-instruction data dependency relationship and a control flow association relationship, construct a difference graph of a normal execution mode and a risk execution mode based on the optimization strategy set, and generate a semantic feature.
[0043] The tuning module is configured to construct a vulnerability sample with an adversarial perturbation factor based on the semantic features, to adjust the large model parameters through the vulnerability sample, and to perform vulnerability re-inspection on the source code generated after fine-tuning.
[0044] In a third aspect, the present application provides a computing device, comprising a processing component and a storage component; the storage component stores one or more computer instructions; the one or more computer instructions are used to be called and executed by the processing component to implement the large model-based automatic code generation and optimization method according to the first aspect.
[0045] In a fourth aspect, the present application provides a computer storage medium storing a computer program, which, when executed by a computer, implements the large model-based automatic code generation and optimization method according to the first aspect.
[0046] In the examples of the present application, a functional requirement description is received, an initial logical framework is generated by analyzing the functional requirement description through a large model, a symbolic conversion process is performed on the initial logical framework to form a symbolic structure; a code intermediate representation of reserved variable operation semantics, execution path boundaries and resource access patterns is generated based on the symbolic structure, to generate source code through the code intermediate representation conversion; a vulnerability feature vector is extracted from a vulnerability knowledge graph, a vulnerability knowledge set with a weighted index is constructed, parallel computing resources are used to scan instruction sequences of the source code, semantic similarity calculation and path pattern matching are performed between the instruction sequences and vulnerability feature vectors in the vulnerability knowledge set, target instruction positions with security risks and corresponding vulnerability type codes and risk levels are marked; a historical repair case library is retrieved based on the vulnerability type code and the risk level, a matching relationship between vulnerability patterns and repair strategies is established according to the retrieval result, an optimization strategy set containing repair operation sequences and constraint conditions is generated based on the matching relationship; a context semantic analysis model is loaded at the target instruction position, data dependency relationships between instructions and control flow association relationships are analyzed, a difference graph of normal execution patterns and risk execution patterns is constructed based on the optimization strategy set to generate semantic features; vulnerability samples with adversarial perturbation factors are constructed based on the semantic features, to adjust large model parameters through the vulnerability samples, and to perform vulnerability re-inspection on the source code generated after fine-tuning.
[0047] The technical scheme of the present application has the following beneficial effects:
[0048] The application generates an initial logical framework and symbolically processes the initial logical framework through a large model analysis function requirement, forms an intermediate representation retaining key program semantics, and then outputs source code; a vulnerability knowledge graph with a weight index and parallel computing resources are used to perform semantic similarity and path pattern matching scanning on the source code instruction sequence, accurately mark the vulnerability position, type, and risk level; a mapping relationship between vulnerability patterns and repair strategies is established based on a historical repair case library, and an optimization strategy containing specific operation sequences and constraint conditions is generated; a context semantic analysis model is loaded at the vulnerability position, a normal and risk execution difference graph is constructed by analyzing data dependency and control flow, and an anti-disturbance factor sample is generated; finally, the sample is used to dynamically adjust the large model parameters, realize a vulnerability self-repairing closed loop, and complete post-repair verification, so as to achieve the closed loop safety enhancement effect of detecting security vulnerabilities in the code generation whole process, intelligently generating accurate repair schemes, dynamically optimizing model parameters, and ensuring the effectiveness of the repair.
[0049] Further, a numerical offset is generated based on the variable difference feature in the semantic feature, and a path modification point is generated based on the path difference feature, and the two are combined to form a disturbance factor; the disturbance factor is injected at the corresponding position of the source code instruction sequence, and a comparative vulnerability sample containing the original instruction sequence and the modified instruction sequence is constructed; the sample is input into the large model, the difference between the modified instruction sequence and the original instruction sequence is analyzed to adjust the large model parameters, and then the fine-tuned large model is used to generate a new version of source code and perform vulnerability rechecking. The anti-disturbance sample is accurately constructed based on the semantic feature, the specific numerical offset and path modification point are injected to simulate the vulnerability triggering condition, and the large model parameters are fine-tuned based on the difference comparison between the modified and unmodified instruction sequences, so as to specifically strengthen the model's cognition and avoidance ability for specific vulnerability patterns, and finally verify the repair effect through the rechecking closed loop after generating new code, effectively improving the security of the model generated code.
[0050] These aspects or other aspects of the application will be more apparent in the following description of the embodiments. BRIEF DESCRIPTION OF DRAWINGS
[0051] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the application, and other drawings can also be obtained by those skilled in the art without any creative effort.
[0052] Figure 1 A flowchart of an automatic code generation and optimization method based on a large model provided by the application is shown;
[0053] Figure 2A scenario diagram of an automatic code generation and optimization method based on a large model provided by the present application is shown.
[0054] Figure 3 A structural schematic diagram of an automatic code generation and optimization system based on a large model provided by the present application is shown.
[0055] Figure 4 A structural schematic diagram of a computing device provided by the present application is shown. DETAILED DESCRIPTION
[0056] In order to enable personnel in the technical field to better understand the present application scheme, the technical solutions in the present application examples will be clearly and completely described below in combination with the drawings in the present application examples.
[0057] In some of the processes described in the specification and claims of the present application and in the above drawings, a plurality of operations are included which occur in a specific order, but it should be clearly understood that these operations can be performed in an order different from that in which they appear or in parallel, and the serial numbers of the operations, such as 101, 102, etc., are only used to distinguish different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes can include more or fewer operations, and the operations can be performed in sequence or in parallel. It should be noted that the "first", "second", etc. described herein are used to distinguish different messages, devices, modules, etc., and do not represent the order of precedence, nor do "first" and "second" represent different types.
[0058] Research shows that the scheme of using a static application program security testing tool as a post-detection link for large model generated code has significant limitations. The detection occurs after code generation, the process is not continuous, and it cannot meet the needs. The pre-defined rule library it relies on is mainly for traditional manual coding and is difficult to cover the complex vulnerability patterns unique to large model generated code, resulting in poor rule adaptability, high false positive and false negative rates. At the same time, the tool has limited understanding of the deep semantics of the code, and the repair suggestions it provides are too general and coarse-grained, making it difficult to support accurate self-repair. Most importantly, this scheme is a one-way process, and the detection results cannot be fed back to optimize the large model itself, lacking a closed-loop evolution mechanism and being unable to continuously improve the security of the generated code.
[0059] To solve the above problems, the application provides an automatic code generation and optimization method based on a large model, which constructs a closed-loop system with deep coupling safety intelligence. The method generates an initial framework by analyzing the demand with a large model and performs symbolic processing to form an intermediate representation that retains key semantics and then outputs source code. Using a vulnerability knowledge graph with weighted indexes and parallel computing, the source code instructions are scanned for semantic similarity and path pattern matching to accurately locate and classify vulnerabilities. Based on the vulnerability information, a historical case database is searched to generate a refined repair strategy containing specific operation sequences. A semantic analysis model is loaded at the risk location to analyze the dependency relationship and construct an execution mode difference graph. Finally, based on the graph features, an adversarial sample is constructed to dynamically fine-tune the large model parameters, and the newly generated code is rechecked for vulnerabilities. This scheme overcomes the lack of understanding by retaining deep semantics through symbolic processing, solves the rule rigidity through semantic path double matching, realizes accurate repair through refined strategies, and innovatively establishes a closed-loop channel for detecting and optimizing model parameters. This not only realizes vulnerability detection and accurate repair, but also continuously reduces the vulnerability rate from the source, completely solving the core defects of existing solutions such as non-real-time, poor rule adaptability, coarse-grained repair, and lack of closed-loop evolution.
[0060] The technical solutions in the embodiments of the application will be described clearly and completely below with reference to the drawings in the embodiments of the application. Obviously, the described embodiments are only part of the embodiments of the application, not all embodiments. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the application.
[0061] Figure 1 A flowchart of an automatic code generation and optimization method based on a large model is provided for the embodiments of the application, as shown in Figure 1 The method comprises:
[0062] 101, receiving a functional requirement description, generating an initial logical framework by analyzing the functional requirement description with a large model, and performing symbolic conversion processing on the initial logical framework to form a symbolic structure;
[0063] In the above scheme, the functional requirement description refers to the software function target expressed in natural language proposed by the user, which contains the intention description and business rule constraints of the operation to be implemented, and is used as the original input to drive the code generation process. The initial logical framework is a semi-structured logical expression generated by the large language model after analyzing the functional requirement, which contains the topological association of conditional judgment nodes, loop control nodes and operation action nodes, and constitutes an abstract blueprint for code implementation. The symbolic structure is a machine-computable logical representation formed by conversion processing, which consists of conditional judgment expressions constructed by mathematical symbols, program variables mapped by uniform identifiers, and encoded execution path sequences, providing unambiguous standardized input for subsequent code generation.
[0064] In the embodiments of the present application, first, the natural language processing technology is used to analyze the functional requirement description, the attention mechanism of the pre-trained large model is used to identify key operation entities such as input data, output data and loop conditions, and an initial logical framework is generated. For example, input "if the user's age is less than 18, then prohibit payment", the model identifies "age" as a judgment variable, "18" as a threshold, and "prohibit payment" as an operation action, and generates an initial logical framework containing a condition node age < 18 and an action node block_payment. Secondly, the framework is executed for symbolic conversion: the abstract syntax tree rule is used to replace the natural language variable with a unified symbol, the logical operator is converted into a mathematical symbol, and a unique path code is assigned to each execution path. Finally, a machine-computable symbolic structure is output. For example, "user age" is replaced by $AGE, "<" is replaced by "<", and a unique path code such as P001 is assigned to the execution path, and finally the symbolic structure .
[0065] In actual application, a development team submits a requirement: "when the user's daily transaction amount exceeds 5000 yuan, it needs to be verified twice". The large model identifies that the core condition is that the transaction amount > 5000 needs to trigger verification, and generates a logical framework: . The symbolic conversion maps "transaction amount" to symbol $TX_AMT, and the numerical constant is kept as a number, generating a symbolic structure: .
[0066] The overall scheme of the above 101 converts the functional requirements described in natural language into a structured initial logical framework through a large model, and further performs symbolic conversion processing. This process eliminates the semantic ambiguity and expression ambiguity in the original requirement description, and generates a machine-resolvable structure composed of mathematical symbol expressions, unified identification variables and coded execution paths. This symbolic structure provides an accurate and unambiguous basis for standardized logical expression, ensuring that the subsequent code generation link can accurately understand and implement the user's intention, and establishing a computable and traceable logical framework basis for the vulnerability detection and analysis stage.
[0067] 102. Generating a code intermediate representation of reserved variable operation semantics, execution path boundaries and resource access patterns based on the symbolic structure, to generate source code through the code intermediate representation conversion;
[0068] Optionally, step 102 can specifically include the following steps:
[0069] 1021. based on the symbolic structure, extracting a reserved variable operation meaning containing an action object identifier, an action type, and an action result identifier, an execution path boundary containing a path start position and a path end position, and a resource access mode containing a resource type identifier and an access action type;
[0070] 1022. based on the reserved variable operation meaning, the execution path boundary, and the resource access mode, constructing a code intermediate representation;
[0071] 1023. traversing the code intermediate representation, converting the reserved variable operation meaning into a variable assignment statement, and converting the resource access mode into a resource call statement;
[0072] 1024. according to the position information of the execution path boundary, adding a flow control statement in the variable assignment statement and the resource call statement to form a final source code.
[0073] In the above scheme, the reserved variable operation semantics refers to the logical description of the operation behavior of the data entity in the program, containing the unique identifier of the action object, the type of the action applied, and the pointing relationship of the operation result, which can be used to ensure that the generated code accurately transmits the data processing intention in the original requirement. The execution path boundary refers to the start and end range of the logical branch in the program control flow, containing the positioning identifier of the path start position and the path end position, which can be used to accurately construct the flow control structure such as branches and loops in the code generation process. The resource access mode refers to the operation specification of the program interacting with the external system, containing the type identifier of the accessed resource and the access action type, which can be used to map the abstract resource operation to the specific system call statement. The code intermediate representation refers to the transitional program expression form between the symbolic logic and the final code, which can be used to realize the reliable conversion bridge from the requirement logic to the executable code. The source code refers to the program text that can be directly compiled or interpreted and executed, which can be used to realize the functional behavior described in the requirement description in the target environment.
[0074] In the embodiment of the present application, in step 1021, the system performs deep scanning and analysis on the input symbolic structure by a semantic parsing engine. First, the reserved variable operation semantics describing the data change in the program are identified and extracted, specifically including the action object identifier indicating the data entity being operated, the action type applied to the object, and the result pointing identifier indicating the result after operation, and these information are combined into structured triple data. Then, the engine locates the key nodes of the program control flow, determines the execution path boundary, i.e., captures the path start position and path end position of the logical branch, and forms the coordinate information identifying the path range. Finally, the engine parses the behavior of the program interacting with the external system, extracts the resource access mode, i.e., identifies the resource type identifier being accessed and the access action type performed on the resource, and generates the resource operation mode. For example, in processing a symbolic structure of an "order payment" function, this step will extract the variable operation triple data , mark the loop boundary as , and identify the resource access mode , thereby completely capturing the core behavior elements of the function block.
[0075] Then, in step 1022, the semantic elements extracted in step 1021 are integrated and structured by a structured assembler, the triple information of the reserved variable operation semantics is encapsulated into an independent node with clear attributes, for example, a node like is generated to accurately describe the data operation logic, the start and end position information of the execution path boundary is used to create a corresponding path container node, for example , which serves as a logical wrapping layer to accommodate other nodes within its scope, then the elements of the resource access mode are combined and mapped into a standardized resource access template node, for example , finally, the system orders the variable operation nodes and resource access template nodes generated before into the corresponding path container nodes according to the context relationship of the program logic, and establishes the necessary reference association, thereby constructing a tree-shaped structure code intermediate representation with clear hierarchy and complete original semantics. For example, in processing the logistics transportation cost calculation logic, this step will construct a container node containing path start and end markers, which internally embeds a variable operation node describing and a resource access node calling an external API.
[0076] Then, step 1023 performs a depth-first traversal of the code intermediate representation generated in step 1022, processing each node in turn to generate executable base code statements. When a variable operation node is encountered, the converter maps it precisely to a corresponding variable operation statement according to the action type and object identifier recorded in the node, combined with the syntax rules of the target programming language; for example, a node with an action type of "decrease" and an object of will be converted to a subtraction assignment statement in Python . Next, when a resource access node is encountered, the converter automatically matches a pre-set code template library according to the resource type identifier and access action type defined in the node, generating a standard resource operation statement that conforms to the target environment call; for example, a node with a resource type of "database" and an action of "insert" will generate a SQL execution statement similar to . During the entire traversal process, the path container node is temporarily retained in its structure but the internal filled child nodes are recursively converted, ensuring that the final output is a discrete base code fragment that retains the original operation semantics but has been converted to the syntax of the target language, preparing for the subsequent step of flow control integration; for example, a variable operation node in a medical system that "increases the patient count" will be directly converted to , while a resource node that "sends an email" generates a call statement .
[0077] Finally, step 1024 uses a control flow integration engine to structurally reorganize the base code statements generated in step 1023. Analyzing the execution path boundary information marked in the code intermediate representation, it determines the control block range to which these base statements logically belong and their physical location interval in the source code; according to the context characteristics of the path boundaries, it automatically determines the required flow control statement type, for example, selecting for or while loops when the start and end points mark a repeated execution area, or if or else when marking conditional branches; then, the engine inserts the corresponding control structure start statement at the path start point position, and embeds all variable assignment statements and resource call statements associated with this path in the control structure in logical order, while automatically adding the necessary indentation levels according to the programming language specifications to reflect the membership relationship; finally, at the path end point position, the engine intelligently adds the closing mark of the control structure, ensuring that the generated code block is syntactically complete and the execution logic is strictly consistent with the original symbolic structure, thus forming a functional complete final source code. For example, in a financial approval scenario, when the path boundary (L5, L10) is detected to correspond to a conditional judgment block, and it contains variable assignment and database saving operations, the system will insert Lines 6-7 contain indented assignment and save statements, and the conditional block ends on line 10, outputting the complete and runnable code segment.
[0078] In practical applications, when a warehouse management system receives a requirement to "shut down the equipment and log when the temperature exceeds the threshold," after generating a symbolic structure through large-scale model parsing, it first extracts the key semantics, and the variable operation semantics are... The execution path boundary is from the start line L15 of the if condition block to the end line L21. The resource access mode is device control interface shutdown and log database insertion. Then, an intermediate representation is constructed: creation. Container nodes, with embedded variable manipulation nodes and two resource nodes , Next, transform the basic statements: traversing the middle indicates converting variable operations into... Transform equipment control into Convert database access to Finally, integrate the process control: insert on line L15. The three transformed statements are indented and embedded within the conditional block, and the logic is closed on line L21 to generate the final source code.
[0079] The overall solution described above (102) fully preserves the core behavioral semantics of the program through the conversion from symbolic structure to intermediate representation. When generating the final code, it ensures that variable operation logic is not lost, execution path boundaries are clear and traceable, and resource access patterns are accurately mapped to actual calls. This process avoids the semantic deviation problems commonly encountered when directly generating code from large models, significantly improving the functional correctness and maintainability of the generated code.
[0080] 103. Extract vulnerability feature vectors from the vulnerability knowledge graph, construct a vulnerability knowledge set with weighted index, scan the instruction sequence of the source code using parallel computing resources, and mark the location of target instructions with security risks and the corresponding vulnerability type code and risk level by calculating the semantic similarity between the instruction sequence and the vulnerability feature vectors in the vulnerability knowledge set and matching the path pattern.
[0081] Optionally, step 103 may specifically include the following steps:
[0082] 1031. Extract vulnerability records from the vulnerability knowledge graph and convert them into vulnerability feature vectors, and assign weight values to each vulnerability feature vector to construct a vulnerability knowledge set with weight index;
[0083] 1032. Using parallel computing resources, the instruction sequence of the source code is divided into multiple instruction segments, instruction features are formed for each instruction segment, and the instruction features are converted into numerical features;
[0084] 1033、calculating semantic similarity values between numerical features corresponding to different instruction segments in the instruction sequence and each vulnerability feature vector in the vulnerability knowledge set, while detecting path pattern matching degrees between operator symbol sequences of different instruction segments in the instruction sequence and the vulnerability feature vector;
[0085] 1034、when the semantic similarity value exceeds the corresponding weight value and the path pattern matching degree reaches a set threshold, marking a position of the instruction segment as a target position, and extracting a vulnerability type code and a risk level corresponding to the target position.
[0086] In the above scheme, the vulnerability feature vector refers to a mathematical expression form representing the core attributes of the vulnerability, including a multi-dimensional numerical combination of key features such as vulnerability trigger conditions and damage levels, which can be used to quantify semantic similarity matching of the vulnerability. The weight value refers to an influence factor reflecting the priority of vulnerability matching, which can be used to dynamically adjust the sensitivity threshold of vulnerability matching. The instruction segment refers to a continuous operation unit of the source code execution logic, which can be used to parallelize vulnerability scanning processing. The numerical feature refers to a quantitative indicator reflecting the behavior pattern of the instruction segment, which can be used for vector calculation of machine learning. The semantic similarity refers to the correlation strength measurement value of the instruction behavior and the vulnerability feature, which can be used to identify the semantic relevance of potential vulnerabilities. The path pattern matching degree refers to an indicator of the degree of agreement between the instruction operation sequence and the vulnerability execution path, which can be used to verify the logical certainty of vulnerability triggering. The set threshold refers to the baseline for determining the existence of the vulnerability, which can be used to filter false positives with low confidence. The target position refers to the identification of the code position confirmed to have risks, which can be used to accurately position the implementation anchor point of the repair operation.
[0087] In the embodiments of the present application, first, specific vulnerability records are extracted from the pre-constructed vulnerability knowledge graph through step 1031, and these records contain text description information of the vulnerability. Then, natural language processing techniques are used to analyze these text descriptions, identify key semantic features therein, and convert these features into fixed-dimensional numerical arrays to form vulnerability feature vectors. Then, a weight value is calculated for each generated vulnerability feature vector, which combines the general risk level of the vulnerability using the standard CVSS score and the frequency of the vulnerability appearing in the historical vulnerability library of a specific enterprise or field, through a pre-defined weighting formula: for example, a vulnerability with a CVSS score of 8.5 and a frequency of 0.9, . Finally, all processed vulnerability feature vectors and their corresponding weight values are combined to form a structured, indexed vulnerability knowledge set in the form of key-value pairs , for example , which provides a fast searchable and matching reference library for subsequent vulnerability scanning.
[0088] Next, the complete instruction sequence generated by compiling the source code using the distributed parallel computing framework is divided into multiple instruction segments of fixed length by step 1032. Then, multi-dimensional behavior feature extraction is performed on each instruction segment: the frequency of statistical operators is calculated, i.e., the proportion of high-risk instructions such as CALL in the segment, the data flow complexity is analyzed, i.e., the maximum depth of the cross-instruction variable transmission path is tracked, and the resource access density is recorded, i.e., the number of triggers of sensitive operations such as file reading and writing or network communication is counted. Then, the original numerical values of these three types of features are linearly mapped to the [0, 1] interval through Min-Max normalization technology, and finally a standardized three-dimensional numerical feature vector is generated, providing a quantifiable behavior description model for subsequent vulnerability matching. For example, in a certain instruction segment of the payment verification module of logistics system B, there are 15 CALL instructions, a data flow depth of 7, and 12 file operations, which are converted into the vector [0.3, 0.7, 0.24] through this process.
[0089] Then, through step 1033, the numerical feature vector of each instruction segment generated in step 1032 is calculated for semantic similarity with all vulnerability feature vectors in the vulnerability knowledge set constructed in step 1031: cosine similarity algorithm is used, and the specific calculation process is as follows: the product sum of the numerical values of each dimension of the two vectors is calculated, and then the square root of the sum of the lengths of each vector is calculated, and finally the similarity value is the product sum divided by the product of the lengths. For example, the instruction segment vector of the payment module of logistics system B is , the buffer overflow vulnerability vector is , the product sum is , the square root of the length is and , and the calculated similarity value is ; at the same time, path pattern matching is performed: the original operator sequence of the instruction segment, such as , is extracted, and the vulnerability standard path, such as , is calculated, and the longest common subsequence is calculated through dynamic programming algorithm, and the matching degree is calculated according to the formula: , for example, the common sequence is , the length is 2, and the matching degree is calculated to be 0.67. This stage completes the double matching of all instruction segments and vulnerability vectors through parallel computing at the same time, and outputs the semantic similarity value and path matching degree value corresponding to each instruction segment, for example, the output of the segment of logistics system B is [similarity 0.98, matching degree 0.67], providing a two-dimensional evidence for vulnerability judgment.
[0090] Finally, after obtaining the semantic similarity value and path pattern matching degree of the instruction segment, the system performs vulnerability judgment through step 1034: the instruction segment is determined to have security risks only when the semantic similarity value of the instruction segment is greater than the weight value of the vulnerability in the knowledge set and the path matching degree exceeds the preset threshold. Subsequently, the system automatically extracts the line number range of the instruction segment in the source code as the target position, and retrieves the associated vulnerability attribute information from the vulnerability knowledge base, including the standard vulnerability type code and the risk level label, and finally generates a structured labeling result containing the position information, the vulnerability type and the risk level. For example, the similarity of a certain instruction segment of the medical system D to the "command injection vulnerability" is 0.95, the path matching degree is 0.67, the similarity exceeds the weight value 0.93, the matching degree exceeds the threshold 0.6, and it is judged that there is a risk. The system immediately extracts the line number range of the instruction 305-355, the vulnerability type code CWE-78 and the risk level label serious, and outputs , which provides accurate target positioning and classification basis for subsequent repair.
[0091] In practical applications, in the complete vulnerability detection of certain access control modules, first, extract the permission check missing vulnerability record from the vulnerability knowledge graph, and use the natural language processing model to convert the text feature description into a three-dimensional numerical vector 0.4, 0.6, 0.2. According to the general risk score of the vulnerability 8.0 points in the ten system, it is converted to 0.8, combined with the historical frequency 0.85, and the weight value is calculated by the weighted formula: the risk coefficient 0.7 multiplied by 0.8 is 0.56, the frequency coefficient 0.3 multiplied by 0.85 is 0.255, and the sum is the maximum weight 0.815, forming a vulnerability feature item with weighted index. Then process the 1500 instruction sequences generated by compilation, and use the parallel computing framework to equally divide them into 30 instruction segments, each containing 50 instructions. Feature extraction is performed on the 5th segment of instructions: 18 function call instructions are counted, normalized by the preset maximum value 50 to get 18 divided by 50 equal to 0.36; the data flow depth is measured to be 12 levels, normalized by the maximum value 20 to get 12 divided by 20 equal to 0.6; 8 permission operation instructions are recorded, normalized by the maximum value 15 to get 8 divided by 15 approximately equal to 0.533, and finally the instruction segment feature vector 0.36, 0.6, 0.533 is generated. Subsequent double matching: calculate the semantic similarity of the instruction segment vector and the vulnerability vector 0.4, 0.6, 0.2, first sum the product of each dimension: 0.36 multiplied by 0.4 is 0.144, 0.6 multiplied by 0.6 is 0.36, 0.533 multiplied by 0.2 is 0.1066, the total sum is 0.6106; then calculate the product of the lengths of the two direction vectors: the length of the instruction segment vector is the square root of the sum of the squares of 0.36, 0.6 and 0.533, which is about 0.786, and the length of the vulnerability vector is the square root of the sum of the squares of 0.4, 0.6 and 0.2, which is about 0.748, and the product is about 0.588; the final similarity is 0.6106 divided by 0.588, which is about 1.038, and the actual value is limited to 1.0. At the same time, the path matching is carried out: the operator sequence of the instruction segment is extracted and verified to obtain the modification, compared with the vulnerability standard path to verify the acquisition and detection, the longest common subsequence is calculated to verify the acquisition, and there are two steps, the matching degree is 2 divided by 3, which is about 0.667. The final judgment stage: when the semantic similarity 1.0 is greater than the vulnerability weight 0.815 and the path matching degree 0.667 exceeds the preset threshold 0.6, it is confirmed that the instruction segment has a vulnerability. The system automatically locates its corresponding source code line numbers 210 to 260, associates the vulnerability type code CWE-862 with the high-risk level, and generates a structured detection result.
[0092] The overall scheme of 103 above realizes millisecond-level scanning of source code by constructing a vulnerability feature library with dynamic weights, combining instruction segmentation and parallel computing technology. Utilizing the dual matching mechanism of semantic similarity and path pattern, the potential vulnerability location and type are accurately identified, significantly reducing the false positive rate. At the same time, the standardized vulnerability code, risk level and line number positioning are output, providing clear evidence for repair. Its closed-loop design ensures that the detection results can directly drive the subsequent repair process, and the security guarantee efficiency of large model generated code is comprehensively improved.
[0093] 104. Retrieving a historical repair case library based on the vulnerability type code and risk level, establishing a matching relationship between vulnerability patterns and repair strategies based on the retrieval results, and generating an optimized strategy set containing repair operation sequences and constraint conditions based on the matching relationship;
[0094] Optionally, step 104 can specifically include the following steps:
[0095] 1041. Retrieving a historical repair case library based on the vulnerability type code and risk level, obtaining a vulnerability repair case containing a vulnerability pattern and a repair strategy, and establishing a corresponding relationship between the vulnerability pattern and the repair strategy to form a matching relationship;
[0096] 1042. Analyzing the repair strategy based on the matching relationship, extracting an operation action sequence composed of multiple operation actions and action objects in execution order and constraint conditions containing execution trigger conditions and resource occupation restrictions, to generate an optimized strategy set containing the operation action sequence and the constraint conditions.
[0097] In the above scheme, the historical repair case library refers to a structured database that stores a large number of past successful vulnerability repair instances, including descriptions of specific manifestations of vulnerabilities, repair methods adopted, and records of their execution effects, which can be used to provide effective repair references verified by practice for similar vulnerabilities currently detected. The vulnerability pattern refers to a feature set describing the specific existence form of a specific type of security vulnerability in the program code, which can be used for pattern matching to identify similar vulnerabilities in code scanning. The repair strategy refers to the overall description of the designed and verified effective solution for a specific vulnerability pattern, which can be used to guide the generation of specific code repair operations. The matching relationship refers to the association mapping between the vulnerability pattern and its corresponding effective repair strategy established in the historical repair case library, which can be used to automatically recommend suitable repair strategies for currently detected vulnerabilities. The repair operation sequence refers to a series of ordered code modification action instructions required to implement specific vulnerability repair, which can be used to guide developers or automated tools to complete code repair step by step. The constraint condition refers to the prerequisite rules or restriction conditions that must be strictly followed when executing the repair operation sequence, which can be used to ensure the safety and correctness of the repair process and avoid introducing new problems or damaging the original function. The optimization strategy set refers to a set of one or more feasible repair schemes generated for the currently detected vulnerability, which is used to provide clear, safe, and executable guidance schemes for subsequent automated repair or manual repair.
[0098] In the embodiments of the present application, first, according to the type code of the currently detected vulnerability and the risk level evaluated, as a retrieval condition, a matching query is performed in the historical repair case library through step 1041. Successful cases in the past that repaired the same or highly similar type of vulnerability and had similar risk levels are found. Valid repair experience is found. For example, the system detects that the current code has a "high-risk" "SQL injection" vulnerability, and the type code is SQLI-HIGH-001. It will find all historical cases that have repaired "SQL injection" vulnerabilities and have a risk level of "high" in the case library. From these matched cases, the specific manifestation of the vulnerability described by each case, i.e., the vulnerability pattern, and the specific repair method adopted at the time, i.e., the repair strategy, are extracted. Finally, the matching relationship between the features of the currently detected vulnerability and the successful repair strategies in the past is established.
[0099] Secondly, based on the matching relationship established by step 1041, each matched effective repair strategy is analyzed in depth through step 1042. The system will carefully analyze these strategy texts or structured data, and extract the core elements that constitute the strategy: first, the repair operation sequence, i.e., a series of specific code modification actions and their objects that need to be executed in a specific order, such as "find the position where the input variable is used", "insert a function call before it" and then "replace the input variable with the function call result". Second, the constraint condition, i.e., the prerequisite rules or restriction conditions that must be strictly followed when executing the repair operation sequence, such as "the function call must be inserted before the input variable is used", "the function call must be inserted in the same function as the input variable", and "the function call must be inserted in the same file as the input variable". Third, the optimization strategy set, i.e., a set of one or more feasible repair schemes generated for the currently detected vulnerability, such as "insert a function call before the input variable is used", "replace the input variable with the function call result", and "insert a function call before the input variable is used and replace the input variable with the function call result". function replacement The second is constraints, i.e. prerequisites or limitations that must be met when performing these operations, such as "the inserted function must be called before any database operation" and "the replacement function must ensure correct parameter binding" and "the entire fix should not add more than 5 new lines of code". The system organizes and encapsulates these extracted operation sequences and constraints, and finally generates an optimized strategy set containing one or more feasible repair plans.
[0100] In practical application, suppose the system is generating a user profile management module for an online shopping website A, and detects a high-risk authentication bypass vulnerability, type coded as AUTH-BYPASS-HIGH-003. According to this vulnerability type and risk level, the historical repair case library is searched. It may find three relevant cases: case B repaired a similar bypass vulnerability, the solution is to add an additional session token verification; case C repaired another variant, the solution is to strengthen the user permission detection logic; case D's solution is to refactor the authentication process. The system analyzes the vulnerability patterns of these cases and finds that the pattern of case B is the most matched to the current vulnerability. Establish a matching relationship, the current vulnerability pattern corresponds to the repair strategy of case B. Then, parse the repair strategy text of case B. It extracts the operation sequence: 1. Locate the session object at the user request processing function entry; 2. Insert a call to the function ; 3. If the return fails, return an error response 401. At the same time, extract the constraints: a. The new verification must occur before any business logic execution; b. The function call time consumption should be less than 50 milliseconds; c. Do not modify the internal structure of the existing session object. Finally, the system generates an optimized strategy set, which contains a specific strategy item that lists the above operation sequence and constraint conditions in detail, for subsequent execution.
[0101] The overall scheme of the above 104, through the vulnerability type and risk level to search the historical repair case library, intelligently matches the repair strategy that has been verified effective in practice. It parses these strategies, generates operation sequences containing specific, ordered code modification instructions, and rule conditions that must be followed when executing these instructions, forming an optimized strategy set. This is equivalent to automatically generating a detailed "repair instructions" and "safety precautions list" for the detected vulnerability, converting abstract repair suggestions into precise guidelines that engineers can directly execute or systems can automatically process, significantly improving the relevance, operability, and security of the repair, and avoiding blind modification or introducing new problems.
[0102] 105. loading a context semantic analysis model at the target instruction position, parsing the inter-instruction data dependency relationship and the control flow association relationship, and constructing a difference atlas of normal execution mode and risk execution mode to generate semantic features in combination with the optimization strategy set;
[0103] Optionally, step 105 can specifically include the following steps:
[0104] 1051. loading a context semantic analysis model at the target instruction position to analyze the instruction sequence, and parsing the data dependency relationship of the variable generation position, variable use position and variable transmission path and the control flow relationship of the conditional judgment point and loop control point in the instruction sequence;
[0105] 1052. based on the data dependency relationship and the control flow relationship, constructing a normal execution mode containing a variable change sequence and a control flow sequence, and simultaneously combining the optimization strategy set to simulate a risk execution mode containing a variable abnormal sequence and a control flow abnormal path when a vulnerability is triggered; 1053. comparing the normal execution mode and the risk execution mode, identifying variable difference positions and control flow difference positions to construct a difference atlas, and extracting semantic features containing variable difference features and path difference features from the difference atlas.
[0106] In the above scheme, the context semantic analysis model refers to an AI tool specially analyzing program code logic, used to track how variables are created, modified and passed, and how the program decides the execution path according to the conditional judgment and loop control. The data dependency relationship refers to the dynamic link reflecting the transmission of variable values in the instruction sequence, containing the complete transmission path from the declaration position to the modification position and then to the use position of the variable, used to identify the risk node of unverified data flow. The control flow relationship refers to the decision logic feature describing the execution path of the program, containing the constraint effect of the conditional judgment point and the loop control point on the execution order of the code, used to locate the abnormal branch of missing permission verification or invalid boundary detection. The normal execution mode refers to the standard running state of the program meeting the functional expectation, constituting the benchmark behavior template of the business logic. The risk execution mode refers to the abnormal running state when the vulnerability is triggered, used to compare the accurate position of exposed security defects. The difference atlas refers to the visualization mapping identifying the deviation features between the normal and risk dual modes, forming the spatial positioning model of the core behavior of the vulnerability. The semantic features refer to the quantitative vulnerability fingerprints extracted from the difference atlas, containing variable difference features and path difference features, providing an operable defect parameter set for the repair strategy generation.
[0107] In the embodiments of the present application, firstly, the system loads the context semantic analysis model to perform deep scanning on the instruction sequence at the identified target instruction position with security risks through step 1051. The model first uses program slicing technology to finely track the complete life cycle of each variable in the instruction sequence: clearly identifies the source position where the variable is initially created or assigned, the key node position where the variable value is modified or operated, and the destination position where the variable is finally passed or used, thereby clearly depicting the complete transmission path of how the variable flows and changes in the code, forming a data dependency relationship network. At the same time, the model applies a control flow graph construction algorithm to systematically scan and mark all key decision points that affect the execution of the program, including the logical condition judgment position for branch selection and the loop control position for controlling the number of loop executions, thereby outlining the possible execution path framework of the program.
[0108] Secondly, based on the detailed data dependency relationship and control flow relationship established in step 1051, the system first constructs a normal execution mode that conforms to the expected business logic, which accurately depicts the legal change sequence of variable values and the correct execution order of control flow that should be followed in a safe running state. Then, the system combines the set of optimization strategies retrieved from the historical repair case library to simulate the abnormal scenario when the vulnerability is triggered, thereby actively constructing a risk execution mode; in this mode, the system intentionally violates the security rules to generate an abnormal sequence of variables containing dangerous values and an abnormal path of control flow deviating from the expected path.
[0109] Finally, after the construction of the normal execution mode and the risk execution mode is completed through step 1053, the system starts deep comparative analysis of the two modes. Specifically, by comparing the variable change sequence line by line, the system identifies the key positions where the variable value abnormally mutates, such as an input variable that should be safely filtered to null in the normal mode, but retains a malicious string in the risk mode; at the same time, by traversing the control flow path, the system marks the key nodes that are illegally bypassed or missing in the risk mode, such as the file type checking step that must exist in the normal flow completely disappearing in the risk flow. Based on these identified variable value mutation points and control flow path breaking points, the system automatically constructs a structured difference map, which visually maps the code positions as nodes and the difference types as edges. Finally, the system extracts semantic features with clear security significance from the difference map, which mainly include variable difference features and path difference features reflecting the core behaviors of vulnerabilities, providing direct operational quantitative basis for subsequent generation of accurate vulnerability repair samples.
[0110] In practical applications, after the code section handling passwords in the social platform user registration module is identified as a security risk location, the system first loads a contextual semantic analysis model to scan this code segment. The model identifies that the password variable originates at the user input receiving point, and this variable is directly passed to the password storage function call point without any processing, forming a critical data dependency chain. Simultaneously, the model discovers a conditional check point in the code, used to check whether the password length meets the minimum requirement. Next, based on these dependencies and control flow relationships, the system constructs a normal execution mode: the password variable obtains a value at the input receiving point, for example, a valid password containing 11 characters. This value is then passed to the length check point. After calculation confirms that its length of 11 is greater than or equal to 8, the condition is met, and the password is then securely passed to the storage point for encryption and conversion before being saved. Simultaneously, the system, combining strategies for plaintext storage vulnerabilities from the historical remediation database, proactively simulates a risky execution mode: At the input receiving point, the password variable receives a short password value, such as an invalid password containing only 3 characters. This value bypasses security processing and is directly passed to the storage point for plaintext storage. Furthermore, the system deliberately tampers with the logic of the length detection point, changing its condition to require a password length greater than or equal to 100. Thus, when the system detects that the calculated length of the input password string is only 3 characters, the condition judgment result is false, causing the length detection step to be completely bypassed. Ultimately, the system compares the two modes: it finds the variable difference lies in the fact that in the risky mode, the password is directly stored at the storage point without encryption, while in the normal mode it is encrypted. The system records this variable difference as a missing encryption conversion feature. It also finds the control flow difference in the risky mode where the verification rules at the length detection point are maliciously modified, causing a short password of 3 characters that should have been blocked to be allowed to pass because the calculated result is less than 100. The system records this path difference as a failed password strength verification. Based on this, the system constructs a difference graph to locate the failed verification point and the unencrypted storage point as core risk nodes, and extracts the aforementioned semantic features for subsequent remediation.
[0111] The overall solution described above, through in-depth analysis of code logic dependencies, accurately constructs normal and risky dual-mode operating scenarios, intuitively exposing variable tampering points and control flow defects when vulnerabilities are triggered; based on semantic features extracted from the difference graph, it provides quantifiable vulnerability behavior fingerprints for subsequent generation of adversarial samples, significantly improving the targeting of remediation strategies, while avoiding misjudgments caused by traditional tools ignoring contextual relationships.
[0112] 106. Construct vulnerability samples with adversarial perturbation factors based on the semantic features, so as to adjust the parameters of the large model through the vulnerability samples, and perform vulnerability re-examination on the source code generated after fine-tuning.
[0113] Optionally, step 106 may specifically include the following steps:
[0114] 1061、generate a numerical offset based on the variable difference feature in the semantic feature, generate a path modification point based on the path difference feature in the semantic feature, combine the numerical offset and the path modification point to form a perturbation factor;
[0115] 1062、inject the perturbation factor at a corresponding position of the source code instruction sequence to generate a vulnerability sample containing an original instruction sequence and a modified instruction sequence;
[0116] 1063、input the vulnerability sample into the large model, adjust the parameters of the large model according to the difference between the modified instruction sequence and the original instruction sequence, generate a new version of source code using the large model after parameter adjustment, and perform vulnerability re-check on the new version of source code.
[0117] Wherein, the step 1063 can specifically include the following process: input the vulnerability sample into the large model, compare the running behaviors of the modified instruction sequence and the original instruction sequence, extract the behavior change value and the result difference value; generate a difference degree value based on the behavior change value and the result difference value, perform a reverse update operation to adjust the weights of the large model, generate a new version of source code through the adjusted large model; perform vulnerability re-check on the new version of source code, feed back the re-checking result to the vulnerability knowledge graph for continuous updating of the feature vector, and form a continuously evolving code security generation capability.
[0118] In the above scheme, the variable difference feature refers to a dynamic data characteristic reflecting the difference in the change rule of the key variable value under the safe execution and risk execution mode of the program, which can be used to identify the numerical boundary condition of vulnerability triggering. The path difference feature refers to a topological structure characteristic reflecting the logical divergence of the normal control flow and the attack path of the program, which can be used to locate the flow breakthrough of the exploit. The perturbation factor refers to a composite instruction unit composed of the numerical offset generated by the variable difference feature and the logical modification point generated by the path difference feature, which can simulate the vulnerability triggering condition to construct the adversarial sample. The behavior change value refers to the dynamic difference characteristic of the resource consumption of the code after injecting the perturbation factor and the original code in the running time, which can quantify the potential harm degree of the vulnerability. The result difference value refers to the deviation degree characteristic of the output result of the perturbed code and the original code, which can verify the effectiveness of the vulnerability repair.
[0119] In the embodiments of the present application, first, the key data reflecting the difference between safe execution and risk execution in the semantic features is extracted through step 1061: the numerical boundary offset rule is parsed from the variable difference feature, and the specific numerical offset is generated accordingly; at the same time, the control flow branch misplacement point is identified from the path difference feature, and the path modification point is generated accordingly. Second, the numerical offset and the path modification point are logically combined to form a composite perturbation factor with vulnerability simulation capability. For example, for SQL injection vulnerabilities, when it is detected that the user input is not filtered and the single quotation mark is directly concatenated with the SQL statement, the offset "input length limit is increased from 50 to 70" and the modification point "insert an escape function before SQL concatenation" are generated, and finally combined into the perturbation factor "lengthen the input and force escape".
[0120] Then, the high-risk instruction position marked in the source code is located through step 1062, and then the perturbation factor generated in step 1061 is accurately injected into the position: for the numerical offset part, the key parameter value in the original instruction is directly modified; for the path modification point part, a logical jump or function call instruction is inserted before the target instruction. After the injection is completed, the system synchronously retains the original instruction sequence, and stores the modified instruction sequence in parallel with it, thereby generating a comparative vulnerability sample containing double version code. For example, when the original code is , the numerical offset and the path modification point are injected to limit the input length to 70 characters and insert the escape function, and then the comparative sample is formed: the original sequence remains , the modified sequence becomes , and the vulnerability repair logic is directly presented by the difference between the two sequences.
[0121] Finally, the comparative vulnerability sample generated in step 1062 is input into the large model through step 1063, and dynamic analysis of the double version code is performed: the original instruction sequence and the modified instruction sequence are monitored in parallel during runtime, the key behavior difference is captured, for example, the memory stable occupancy is 80MB when the original code is executed, and the modified code suddenly increases to 120MB, the behavior change value +40MB is recorded, and the output results are compared, for example, the original code returns the user data list, and the modified code returns the permission error information, and the result difference value 90% is calculated. Based on these difference data, the system calculates the comprehensive difference degree value according to the preset weight, and the calculation formula is as follows: When the value exceeds the set threshold, the reverse adjustment mechanism of the large model parameters is triggered, the vulnerability hazard intensity is quantified by the difference degree value, and the model is guided to reduce the probability of generating similar risk code. Then the large model after fine-tuning is used to regenerate the source code, and the whole process of vulnerability recheck is performed. Finally, the recheck result is fed back to the vulnerability knowledge graph to form a continuously evolving code security generation capability. For example, after a financial system generates a payment interface code, it is found that there is an amount verification vulnerability through this process, and the new code after fine-tuning automatically adds negative number verification logic, and the recheck confirms the repair and updates the knowledge base.
[0122] In practical applications, the order system of an e-commerce platform A uses the payment amount verification code generated by the present scheme to detect that the amount processing function has an overflow vulnerability. The variable difference feature is extracted, the threshold offset is , the numerical offset "reduce the threshold to 9,000 yuan" is generated, and the calculation process is ; at the same time, the path difference feature is extracted, and the path modification point "insert an unconditional jump to payment failure before " is generated. The disturbance factor is injected in the amount verification line: the original instruction is , the modified instruction becomes , and is inserted above, generating a comparison sample containing double sequences. Perform dynamic analysis: the original code allows an order of 20,000 yuan to be passed in, the modified code jumps to refuse payment, and the memory usage is reduced by 15MB and the output result is 100% inconsistent, the comprehensive difference degree value is calculated according to the weight , which exceeds the threshold 50, triggering the model parameter adjustment, reducing the probability of generating unverified amount code. The new code generated by the fine-tuned large model automatically adds double verification logic , the recheck confirms the vulnerability repair, and the "threshold dynamically adjusted to 90% of the original value to block overflow" feature is fed back to the vulnerability knowledge graph.
[0123] The overall scheme of the above 106 constructs an adversarial sample accurately, guides the large model to understand the vulnerability trigger mechanism, quantifies the vulnerability harm by the runtime difference between the modified and unmodified codes, and adjusts the model parameters accordingly. The final generated new code not only immediately fixes the original vulnerability, but also continuously strengthens the knowledge graph through recheck feedback, forming a "vulnerability discovery-model learning-safe generation" closed-loop evolution capability, which reduces the recurrence rate of similar vulnerabilities from the root.
[0124] The following is a complete example for steps 101-106. As shown in Figure 2 , during the development of a certain payment system, the product manager submits a requirement description "implement payment verification function, need to verify account balance, single amount not exceeding 10,000 yuan and record transaction log". The large model parses the requirements to generate an initial logic framework: , then performs symbolic conversion on the framework: convert the amount variable to a symbol $AMT range 0~10,000, convert the database operation to a symbol $DB_INSERT, form a symbolic structure . Based on this structure, generate the intermediate representation: define the amount variable amount to retain the numerical range semantics 0 to 10000, set the execution path boundary, if it exceeds, return an error, declare the database resource access mode as a write operation; finally convert to source code: first detect if amount>10000 in the function, return an error, then query the balance and compare, finally execute .
[0125] Extracting SQL injection feature vector from vulnerability knowledge graph and integer overflow vector [boundary detection: single-point check], using parallel computing resources to scan the source code instruction sequence. The scanning found that the database execution line and the SQL injection vector had a similarity of 92%, and both were not filtered by direct splicing, marked as high-risk vulnerability positions; At the same time, the amount check line was only detected by the front-end single-point detection, and the attacker could bypass 20000, marked as a medium-risk position and associated with vulnerability type code CWE-89 and CWE-190. Subsequently, the historical repair case library was searched, and for the SQL injection type code CWE-89, the operation sequence [replace parameterized query, add filtering] and the constraint condition [keep log compatibility] were matched; For CWE-190, the operation sequence [add server-side check, add type conversion] and the constraint [response time ≤ 50 ms] were matched, forming an optimization strategy set.
[0126] Load semantic analysis model at marked position, parse database execution line and find that amount directly splices SQL string and has no pre-filter function, control flow shows missing call; parse the amount check line and find that there is only one comparison and negative numbers are allowed, and the control flow lacks server-side verification branch. Based on this, build a normal and risk execution mode difference graph, and generate core semantic features: SQL injection points need to be supplemented with escape functions and parameterized transformation, and amount points need to be supplemented with negative number checks and server-side verification.
[0127] Based on semantic features, construct perturbation factors: for SQL injection points, generate numerical offset "add function" from variable difference features, and generate modification point "change splicing to parameterized query" from path difference features; for amount points, generate numerical offset "add amount >= 0 check" and modification point "insert function". Inject perturbation factors into source code, the original amount check line is modified to , and the original database line is replaced by , generate a comparison sample containing the original sequence and the modified sequence. Then perform dynamic analysis: when the incoming attack data amount =-5000, the original code pays successfully, and the modified code returns "illegal amount", the memory occupation is monitored from 35MB to 17MB, the behavior change value is-18MB, and the output result is 100% inconsistent; Calculate the difference degree value according to the formula: the behavior change weight is 0.4x(18 / 35)=0.206, the result difference weight is 0.6x1=0.6, and the total is 0.806, which exceeds the threshold value 0.5. According to this, adjust the large model parameters, and generate new code after fine-tuning: the amount check is upgraded to if not(0<=amount<=10000) and a new call is added, and the database operation is changed to parameterized query+sanitize(amount). Finally, the vulnerability review confirms that amount="1;DROP TABLE logs" is filtered, and 20000 is intercepted by the server, and the "double boundary check blocking overflow" and "parameterization+filtering blocking injection" features are fed back to update the vulnerability knowledge graph, forming a closed-loop security enhancement mechanism.
[0128] Figure 3 A structure diagram of an automatic code generation and optimization system based on a large model is provided for the embodiments of the present application, as shown in Figure 3 The system comprises:
[0129] The parsing module 31 is configured to receive a function requirement description, generate an initial logic framework by parsing the function requirement description through a large model, and perform symbolic conversion processing on the initial logic framework to form a symbolic structure.
[0130] The conversion module 32 is configured to generate a code intermediate representation of a reserved variable operation semantics, an execution path boundary, and a resource access mode based on the symbolic structure, and convert the source code through the code intermediate representation.
[0131] The marking module 33 is configured to extract a vulnerability feature vector from a vulnerability knowledge graph, construct a vulnerability knowledge set with a weighted index, scan an instruction sequence of the source code by using parallel computing resources, match the instruction sequence with a vulnerability feature vector in the vulnerability knowledge set by calculating a semantic similarity, and mark a target instruction position and a corresponding vulnerability type code and risk level with security risks.
[0132] The matching module 34 is configured to retrieve a historical repair case library based on the vulnerability type code and the risk level, establish a matching relationship between a vulnerability pattern and a repair strategy according to a retrieval result, and generate an optimization strategy set containing a repair operation sequence and a constraint condition based on the matching relationship.
[0133] The generating module 35 is configured to load a context semantic analysis model at the target instruction position, parse inter-instruction data dependency relationships and control flow association relationships, and construct a difference graph of normal execution mode and risk execution mode based on the semantic features.
[0134] The tuning module 36 is configured to construct a vulnerability sample with an adversarial disturbance factor based on the semantic features, adjust large model parameters through the vulnerability sample, and perform vulnerability re-inspection on the source code generated after fine-tuning.
[0135] Figure 3 The automatic code generation and optimization system based on a large model can perform Figure 1 The automatic code generation and optimization method based on a large model has the implementation principle and technical effects which will not be repeated. The specific operation manner of each module and unit of the automatic code generation and optimization system based on a large model in the above embodiments has been described in detail in the embodiments of the method, and will not be described in detail here.
[0136] In one possible design, Figure 3 The automatic code generation and optimization system based on a large model can be implemented as a computing device, such as a server. Figure 4 As shown, the computing device can include a storage component 41 and a processing component 42.
[0137] The storage component 41 stores one or more computer instructions, wherein the one or more computer instructions are called and executed by the processing component 42.
[0138] The processing component 42 is configured to perform the above Figure 1 The automatic code generation and optimization method based on a large model.
[0139] The processing component 42 can include one or more processors to execute computer instructions to complete all or part of the steps in the above method. Of course, the processing component can also be one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic elements, for executing the above method.
[0140] The storage component 41 is configured to store various types of data to support the operation of the terminal. The storage component can be implemented by any type of volatile or nonvolatile storage devices or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic or optical disk.
[0141] Of course, the computing device can also necessarily include other components, such as an input / output interface, a display component, a communication component, etc.
[0142] The input / output interface provides an interface between the processing component and peripheral interface modules, which can be output devices, input devices, etc.
[0143] The communication component is configured to facilitate wired or wireless communication between the computing device and other devices, etc.
[0144] The computing device can be a physical device or an elastic computing host provided by a cloud computing platform, and the computing device can be a cloud server, and the processing component, the storage component, etc. can be a basic server resource rented or purchased from the cloud computing platform.
[0145] The embodiment of the application further provides a computer storage medium storing a computer program, and the computer program can implement the above-mentioned Figure 1 The embodiment shown in the figure is an automatic code generation and optimization method based on a large model.
[0146] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-mentioned system, device and unit can refer to the corresponding process in the foregoing method embodiment, which will not be described here.
[0147] The device embodiment described above is only schematic, wherein the units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, i.e. they can be located in one place, or distributed on multiple network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiment. Those skilled in the art can understand and implement without creative labor.
[0148] Those skilled in the art can clearly understand the implementation of the various embodiments by means of software and the necessary general hardware platform from the above description of the embodiments, and of course, the embodiments can also be implemented by hardware. Based on such understanding, the above technical solutions, essentially or in other words, the part of the prior art that contributes to the technical solutions can be embodied in the form of a software product. The computer software product can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for causing a computer device (which can be a personal computer, a server, etc.) to execute the methods described in the various embodiments or some parts of the methods.
[0149] Finally, it should be noted that: the above examples are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing examples, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing examples, or make equivalent replacement for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. An automated code generation and optimization method based on a large model, characterized in that, include: Receive functional requirement description, parse the functional requirement description through a large model to generate an initial logical framework, and perform symbolic transformation processing on the initial logical framework to form a symbolic structure; Based on the symbolic structure, a code intermediate representation is generated that preserves the semantics of variable operations, execution path boundaries, and resource access patterns, and the source code is generated by transforming the code intermediate representation. Vulnerability feature vectors are extracted from the vulnerability knowledge graph, a vulnerability knowledge set with weighted index is constructed, and the instruction sequence of the source code is scanned using parallel computing resources. By calculating the semantic similarity between the instruction sequence and the vulnerability feature vectors in the vulnerability knowledge set and matching the path pattern, the location of the target instruction with security risks and the corresponding vulnerability type code and risk level are marked. Based on the vulnerability type encoding and risk level, a historical remediation case library is retrieved. A matching relationship between vulnerability patterns and remediation strategies is established based on the retrieval results. Based on the matching relationship, an optimization strategy set containing remediation operation sequences and constraints is generated. A contextual semantic analysis model is loaded at the target instruction location to parse the data dependencies and control flow relationships between instructions. Combined with the set of optimization strategies, a difference graph between normal execution mode and risky execution mode is constructed to generate semantic features. Based on the semantic features, vulnerability samples with adversarial perturbation factors are constructed to adjust the parameters of the large model and to re-examine the vulnerability in the fine-tuned source code.
2. The method according to claim 1, characterized in that, The process of constructing vulnerability samples with adversarial perturbation factors based on the semantic features, adjusting the parameters of the large model using the vulnerability samples, and performing vulnerability re-checks on the generated source code after fine-tuning includes: A numerical offset is generated based on the variable difference features in the semantic features, and a path modification point is generated based on the path difference features in the semantic features. The numerical offset and the path modification point are combined to form a perturbation factor. The perturbation factor is injected at the corresponding position in the source code instruction sequence to generate a vulnerability sample containing the original instruction sequence and the modified instruction sequence; The vulnerability sample is input into the large model. The parameters of the large model are adjusted according to the difference between the modified instruction sequence and the original instruction sequence. The large model with adjusted parameters is used to generate a new version of the source code, and the vulnerability is re-checked on the new version of the source code.
3. The method according to claim 2, characterized in that, The process of inputting the vulnerability sample into a large model, adjusting the parameters of the large model based on the differences between the modified instruction sequence and the original instruction sequence, generating a new version of source code using the parameter-adjusted large model, and performing vulnerability re-checking on the new version of source code includes: The vulnerability sample is input into a large model, and the execution behavior of the modified instruction sequence is compared with that of the original instruction sequence. The behavior change value and the result difference value are extracted. Based on the behavioral change value and the result difference value, a difference degree value is generated, a reverse update operation is performed to adjust the weight of the large model, and a new version of the source code is generated from the adjusted large model. The new version of the source code is subjected to vulnerability re-examination, and the re-examination results are fed back to the vulnerability knowledge graph for continuous feature vector updates, forming a continuously evolving code security generation capability.
4. The method according to claim 1, characterized in that, The process involves loading a contextual semantic analysis model at the target instruction location to parse data dependencies and control flow relationships between instructions, and combining this model with the set of optimization strategies to construct a difference graph between normal and risky execution modes to generate semantic features, including: At the target instruction location, a context semantic analysis model is loaded to analyze the instruction sequence, and the data dependencies and control flow relationships containing variable generation locations, variable usage locations, and variable propagation paths in the instruction sequence are parsed; Based on the data dependencies and control flow relationships, a normal execution mode containing variable change sequences and control flow order is constructed. Simultaneously, combined with the optimization strategy set, a risky execution mode containing abnormal variable sequences and abnormal control flow paths when vulnerabilities are triggered is simulated and generated. The normal execution mode and the risky execution mode are compared to identify the variable difference locations and control flow difference locations to construct a difference map. Semantic features containing variable difference characteristics and path difference characteristics are extracted from the difference map.
5. The method according to claim 1, characterized in that, The process of extracting vulnerability feature vectors from a vulnerability knowledge graph, constructing a weighted indexed vulnerability knowledge set, scanning the instruction sequences of the source code using parallel computing resources, and marking the locations of target instructions with security risks and their corresponding vulnerability type codes and risk levels through semantic similarity calculation and path pattern matching between the instruction sequences and the vulnerability feature vectors in the vulnerability knowledge set includes: Vulnerability records are extracted from the vulnerability knowledge graph and converted into vulnerability feature vectors. Weight values are assigned to each vulnerability feature vector to construct a vulnerability knowledge set with weight index. The source code instruction sequence is divided into multiple instruction segments using parallel computing resources, instruction features are formed for each instruction segment, and the instruction features are converted into numerical features. Calculate the semantic similarity between the numerical features corresponding to different instruction segments in the instruction sequence and the semantic similarity between each vulnerability feature vector in the vulnerability knowledge set, and simultaneously detect the path pattern matching degree between the operation symbol sequence of different instruction segments in the instruction sequence and the vulnerability feature vector. When the semantic similarity value exceeds the corresponding weight value and the path pattern matching degree reaches the set threshold, the position of the instruction segment is marked as the target position, and the vulnerability type code and risk level corresponding to the target position are extracted.
6. The method according to claim 1, characterized in that, The process involves retrieving historical remediation case libraries based on the vulnerability type encoding and risk level, establishing a matching relationship between vulnerability patterns and remediation strategies based on the retrieval results, and generating an optimization strategy set containing remediation operation sequences and constraints based on the matching relationship, including: Based on the vulnerability type code and risk level, the historical remediation case library is retrieved to obtain vulnerability remediation cases containing vulnerability patterns and remediation strategies, so as to establish a correspondence between the vulnerability patterns and remediation strategies to form a matching relationship. Based on the matching relationship, the repair strategy is parsed, and the sequence of operation actions consisting of multiple operation actions and objects in the order of execution, along with the constraints containing the execution triggering conditions and resource consumption limits, is extracted to generate an optimization strategy set containing the operation action sequence and the constraints.
7. The method according to claim 1, characterized in that, The process of generating a code intermediate representation based on the symbolic structure, including reserved variable operation semantics, execution path boundaries, and resource access patterns, and then using this intermediate representation to generate source code, includes: Based on the symbolic structure, the meaning of the operation of the retained variables containing the object identifier, action type and result identifier is extracted, including the execution path boundary containing the path start position and the path end position, and the resource access method containing the resource type identifier and access action type. Based on the meaning of the reserved variable operations, the execution path boundaries, and the resource access methods, an intermediate code representation is constructed. Traverse the code intermediate representation, convert the meaning of the reserved variable operation into variable assignment statements, and convert the resource access method into resource call statements; Based on the location information of the execution path boundary, flow control statements are added to the variable assignment statement and the resource call statement to form the final source code.
8. An automated code generation and optimization system based on a large model, characterized in that, include: The parsing module is used to receive the functional requirement description, parse the functional requirement description through the large model to generate an initial logical framework, and perform symbolic transformation processing on the initial logical framework to form a symbolic structure; The conversion module is used to generate an intermediate code representation based on the symbolic structure, which retains the semantics of variable operations, execution path boundaries, and resource access patterns, and then converts the intermediate code representation to generate source code. The tagging module is used to extract vulnerability feature vectors from the vulnerability knowledge graph, construct a vulnerability knowledge set with weighted indexes, scan the instruction sequence of the source code using parallel computing resources, and mark the target instruction locations with security risks and their corresponding vulnerability type codes and risk levels by calculating the semantic similarity between the instruction sequence and the vulnerability feature vectors in the vulnerability knowledge set and matching the path patterns. The matching module is used to retrieve historical remediation case libraries based on the vulnerability type encoding and risk level, establish a matching relationship between vulnerability patterns and remediation strategies based on the retrieval results, and generate an optimization strategy set containing remediation operation sequences and constraints based on the matching relationship. The generation module is used to load a context semantic analysis model at the target instruction location, parse the data dependencies and control flow relationships between instructions, and combine the set of optimization strategies to construct a difference map between normal execution mode and risky execution mode to generate semantic features; The tuning module is used to construct vulnerability samples with adversarial perturbation factors based on the semantic features, so as to adjust the parameters of the large model through the vulnerability samples, and to perform vulnerability re-examination on the source code generated after fine-tuning.
9. A computing device, characterized in that, It includes a processing component and a storage component; the storage component stores one or more computer instructions; the one or more computer instructions are invoked and executed by the processing component to implement an automated code generation and optimization method based on a large model as described in any one of claims 1 to 7.
10. A computer storage medium, characterized in that, The system contains a computer program that, when executed by a computer, implements an automated code generation and optimization method based on a large model as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Vulnerability load classification method and system based on codes and semantic features
CN119442229A
Vulnerability detection method and device based on feature engineering
CN120337223A