Script language escape method and device based on large language model, computer readable storage medium and computer program product
Through the script language escape method based on the large language model, escape rules are generated dynamically and code escaped, solving the problems of low execution efficiency, limited resource access, poor portability and insufficient security in the existing technology, and achieving the adaptability and execution efficiency of efficient, secure and compatible script language programs in multi-platform and multi-language environments.
Patent Information
- Application Number
- CN202411910617.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-18
AI Technical Summary
Existing scripting language programs have shortcomings in terms of execution efficiency, resource access, portability and security, especially in multi-platform and multi-language environments, where traditional methods are difficult to break the dependence on specific engines or interpreters.
The script language escape method based on the large language model is adopted. By obtaining the original script code, preprocessing, calling the large language model for context analysis, generating script language escape strategy schemes, dynamically generating escape rules, code escape the original script code, generating target escape code, and performing security and compatibility verification.
It significantly improves the compatibility and portability efficiency of scripting language programs in multi-platform and multi-language environments, optimizes execution efficiency, enhances security, reduces maintenance costs, and improves user experience.
Smart Images

Figure CN119847595A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer languages, and in particular relates to a script language escaping method, device, computer-readable storage medium and computer program product based on a large language model. Background Art
[0002] With the continuous development of informatization, scripting languages play a vital role. With its convenient development features and short iteration cycles, scripting languages have been widely used in many technical fields such as web development and automated tasks. Scripting languages are mostly carried in text format and converted into executable code by interpreters or just-in-time compilation technology. However, although this operating mechanism gives scripting languages a high degree of flexibility and dynamism, it also causes problems such as limited ability to interact with underlying system resources, poor execution efficiency, poor cross-platform portability, and increased security risks.
[0003] Specifically, the existing script language escape methods have the following main problems:
[0004] Efficiency issues: Existing scripting language programs usually use interpreted execution or Just-In-Time Compilation (JIT Compilation), and their execution efficiency is lower than that of compiled execution programs. When interpreting execution, the source code needs to be re-parsed each time the script is executed, resulting in a slower execution speed; while JIT compilation can improve execution efficiency, its compilation process will occupy additional memory resources, and dynamic compilation during script execution may produce unstable effects.
[0005] Resource limitations: Scripting language programs usually run in virtual machines or interpreters, and their access to underlying resources is limited. For example, in Web applications, scripting language programs may not be able to directly access underlying hardware resources, such as hard disks and network interfaces. This makes scripting language programs incapable of handling tasks that require a lot of computing or access to underlying resources.
[0006] Portability issues: Although scripting language programs are highly portable, the implementation of the same scripting language program may differ on different platforms. This means that in cross-platform applications, developers need to adapt and adjust for different platforms, increasing development difficulty and cost.
[0007] Security issues: Due to their openness and flexibility, scripting languages may lead to the spread and execution of malicious code. Especially in Web applications, scripting language programs are vulnerable to security threats such as cross-site scripting (XSS).
[0008] In the face of these existing problems, the traditional solution is to use static analysis and optimization techniques to improve the execution efficiency of script language programs, and to improve the security of script language programs through sandbox mechanisms and code isolation technologies. However, these technologies and methods still have certain limitations in solving the above problems. The main challenge is to break the dependence of script language programs on specific engines or interpreters when executing. For example, when an environment is only equipped with a Lua scripting engine, and the project requirements involve Python scripts, traditional methods face execution barriers. In addition, how to improve the adaptability and execution performance of scripts in a variety of execution environments without sacrificing ease of use and flexibility has become a key issue that needs to be solved urgently. Summary of the invention
[0009] In order to solve the above problems, a script language escape method, device, computer-readable storage medium and computer program product based on a large language model are proposed, aiming to innovate the execution paradigm of script language programs.
[0010] On the one hand, a script language escape method based on a large language model is provided, comprising:
[0011] Get the original script code;
[0012] Call the large language model to perform context analysis and obtain the script language escape strategy solution;
[0013] Based on the script language escape strategy scheme, generating a script escape rule for the original script code;
[0014] According to the script escape rule, the original script code is escaped to obtain a target escape code.
[0015] Furthermore, after obtaining the original script code, the method further includes preprocessing the original script code.
[0016] Further, a large language model training sample is created, the large language model is trained, and the required callable large language model is obtained.
[0017] Furthermore, calling the large language model to perform context analysis and obtain the script language escape strategy solution includes:
[0018] Based on the context information of the original script code, identifying the language type and logical structure of the original script code;
[0019] Based on the logical structure, the functional intent of the original script code is parsed to construct a functional structure tree;
[0020] Based on the function structure tree, the corresponding script language escape strategy solution is generated.
[0021] Further, the script escape rule for the original script code is generated based on the script language escape strategy scheme, including:
[0022] Determine the escape rule corresponding to the logical structure according to the script language escape strategy scheme;
[0023] According to the script language escape strategy scheme, the escape rules corresponding to the functional modules are determined.
[0024] Further, it includes: entering security and compatibility verification on the target escape code.
[0025] Further, the security and compatibility verification includes using a static code analysis method to check the security of the target escape code;
[0026] The target escape code is simulated and executed in a virtual execution environment to verify the compatibility of the target escape code.
[0027] On the one hand, a script language escape device based on a large language model is provided, comprising:
[0028] Acquisition module, used to obtain the original script code;
[0029] The model calling module is used to call the large language model for context analysis and obtain the script language escape strategy solution;
[0030] A rule generation module, used for generating a script escape rule for the original script code based on the script language escape strategy scheme;
[0031] The escape module is used to perform code escape on the original script code according to the script escape rule to obtain a target escape code.
[0032] On the one hand, a script language escaping system based on a large language model is provided, the system comprising a processor and a memory, the processor executing computer instructions stored in the memory to implement the above-mentioned script language escaping method based on a large language model.
[0033] On the one hand, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer system to execute the above-mentioned script language escaping method based on a large language model.
[0034] The solution provided by the present disclosure solves the deficiencies of the prior art and has the following beneficial effects:
[0035] Improved compatibility and migration efficiency: In the face of multi-platform and multi-language environments, this technology achieves smooth code migration by dynamically generating escape rules. For example, in the conversion instance from Python to JavaScript, the successful case shows that the code migration success rate has increased to more than 95%, which greatly shortens the cross-platform development cycle, reduces the workload of manual debugging, and improves the productivity of the development team;
[0036] Intelligent optimization and adaptability: With the learning and reasoning capabilities of the large language model, this solution can intelligently adjust the escape strategy according to the actual purpose of the script and the target environment, which not only ensures the correctness of the function, but also further optimizes the execution efficiency. In an actual application, the execution time of the escaped script was shortened by 20% on average, especially when processing large amounts of data and complex logic;
[0037] Reduce maintenance costs and improve user experience: By automating the escape and verification process, errors introduced by manual conversion are reduced, reducing later maintenance costs. At the same time, the output escape report helps developers quickly locate and understand changes, promoting communication and cooperation between teams. Significantly improve the end-user experience satisfaction;
[0038] Promoting technological innovation and sustainable development: The open interface design facilitates integration with other development tool chains, promoting the co-construction and sharing of the technology ecosystem. By continuously collecting user feedback and iterating and optimizing the model, a virtuous cycle is formed, constantly pushing the boundaries of technological innovation and building a sustainable competitive advantage for the enterprise.
[0039] To sum up, the technical solution disclosed in the present invention not only solves the key problems in the prior art such as low script escape efficiency, insufficient security, and poor compatibility, but also significantly improves development efficiency, enhances application security and user experience through intelligent and automated methods, and wins a significant advantage for the company in the fierce technological competition.
[0040] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 A flowchart of script language escape based on a large language model according to an embodiment of the present invention is shown;
[0043] Figure 2 A structural diagram of a script language escape device based on a large language model according to an embodiment of the present invention is shown;
[0044] Figure 3 A structural diagram of a script language escape system based on a large language model according to an embodiment of the present invention is shown;
[0045] Figure 4 A diagram showing a computer-readable storage medium structure according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0047] In the face of efficiency problems, resource limitation problems, poor portability problems, security problems, etc. in script language escape methods, the traditional solution is to use static analysis and optimization techniques to improve the execution efficiency of script language programs, and to improve the security of script language programs through sandbox mechanisms and code isolation technologies. However, these technologies and methods still have certain limitations in solving the above problems. The main challenge is to break the dependence of script language programs on specific engines or interpreters when they are executed. For example, when an environment is only equipped with a Lua script engine, and project requirements involve Python scripts, traditional methods face execution barriers. In addition, how to improve the adaptability and execution efficiency of scripts in a variety of execution environments without sacrificing ease of use and flexibility has become a key problem to be solved. In response to this technical problem, the present invention provides the following technical solution.
[0048] On the one hand, the present disclosure provides a script language escape method based on a large language model, such as Figure 1 As shown, including:
[0049] First, get the original script code.
[0050] In one embodiment, the submitted script code is received via an API. The script code can be a code of any scripting language, such as Lua, Python, JavaScript, Bash, PowerShell, Perl, Ruby, PHP, Swift, Shell, and other scripting languages.
[0051] In one embodiment, the obtained original script code is preprocessed, for example, irrelevant comments and blank characters are removed, preliminary syntax error checking and other data preprocessing operations are performed.
[0052] Second, call the large language model to perform context analysis and obtain the script language escape strategy solution.
[0053] In one embodiment, based on the context information of the original script code, a trained large language model is called to perform deep context understanding. The large language model is a deep learning model trained with a large amount of text data, and the deep learning algorithms used include recursive neural network RNN, long short-term memory network LSTM, gated recurrent unit GRU, and other deep learning algorithms.
[0054] In one embodiment, training a large language model includes:
[0055] Deep learning algorithm selection: The deep learning algorithm used in this embodiment is the long short-term memory network (LSTM), which is particularly suitable for context analysis of scripting languages due to its superior performance in processing sequence data. LSTM can effectively solve the gradient vanishing and gradient exploding problems in traditional RNN.
[0056] Training sample selection: Training samples are selected from multiple open source script code libraries, covering multiple script languages (such as Python, JavaScript, Lua, etc.) to ensure the generalization ability of the model. Samples include normally executed script codes and their corresponding escape codes, as well as script codes containing common errors and security vulnerabilities.
[0057] Loss function definition: Large language model training uses the cross entropy loss function to measure the accuracy of model prediction. The cross entropy loss function is defined as:
[0058]
[0059] Calculation formula: The calculation formula of the LSTM unit includes the calculation of the input gate, forget gate, candidate memory and output gate. The specific formula is as follows:
[0060] i t =σ(W ix x t +W ih h t-1 +bi )
[0061] f t =σ(W fx x t +W fh h t-1 +b f )
[0062]
[0063] o t =σ(W ox x t +W oh h t-1 +b o )
[0064] h t =o t *tanh(C t )
[0065] Among them, i t 、f t , o t are the activation values of the input gate, forget gate, and output gate, respectively. is the candidate memory, C t is the current memory, h t is the current hidden state, σ represents the sigmoid activation function, and * represents element-wise multiplication.
[0066] Constraints for the end of training: Constraints for the end of training include reaching the preset maximum number of iterations or the loss function value falling below a certain threshold. In addition, the performance on the validation set can also be used to decide whether to terminate training early to prevent overfitting.
[0067] In one embodiment, after the large language model is trained, the large language model is called to identify the language type and logical structure of the original script code based on the context information of the original script code; wherein, by identifying the language type of the original script code, the scripting language used to write the original script code is determined. Based on the identified language type, the large language model further identifies and determines the logical structure included in the original script code, including the structured representation of the script, variable type inference, function call relationship, etc.
[0068] In one embodiment, based on the logical structure identified by the large language model, the functional intent of the original script code is parsed to construct a functional structure tree; the functional structure tree reflects the association relationship between various functional structures.
[0069] In one embodiment, the large language model generates the corresponding script language escape strategy scheme based on the function structure tree. The script language escape strategy scheme includes at least one of the escape mode of the logical structure, the escape mode of the functional structure unit, the special processing of the escape and other annotations. The special processing or annotation is used to avoid security risks or adapt to the target execution environment.
[0070] Third, based on the script language escape strategy, a script escape rule for the original script code is generated.
[0071] In one embodiment, a dynamic escape engine is used to generate escape rules for the original script code based on the script language escape strategy generated by the large language model, wherein the escape rules are used to escape a specific script code into a target script code, such as escaping a Python script code into a JavaScript script code, or escaping a Lua script code into a Python script code, etc.
[0072] In one embodiment, based on the script language escape strategy generated by the large language model, special processing rules for specific script codes are generated. Specifically, the special processing rules are generated based on the special processing or annotation instructions in the script language escape strategy scheme. For example, if the original script code is JavaScript script code, if it is recognized that there is an SQL query string in the JavaScript script, special processing or annotation instructions will be given in the script language escape strategy scheme, and the generated special processing rules will automatically apply SQL injection protection escape rules, such as escaping single quotes. In addition, for cross-language transplantation scenarios, such as when converting Python script code to JavaScript script code, it is necessary to convert the grammatical structure, such as converting Python's indentation to JavaScript's curly brace structure. These are generated by special processing or annotation instructions in the script language escape strategy scheme to generate the special processing rules.
[0073] Fourth, according to the script escape rule, the original script code is escaped to obtain a target escape code.
[0074] In one embodiment, the generated script escape rules constitute a script escape rule set, and according to the script escape rule set, the original script code is subjected to code escape to obtain a target escape code.
[0075] In one embodiment, the generated script escape rules constitute an intelligent escape strategy library, and the corresponding script escape rules are selected from the intelligent escape strategy library to perform code escape on the original script code to obtain the target escape code.
[0076] In one embodiment, the escaped script enters the security and compatibility verification stage. The target escape code enters the security and compatibility verification. The static code analysis method is used to check the security of the target escape code; the target escape code is simulated and executed in a virtual execution environment to verify the compatibility of the target escape code. The system uses static code analysis tools and preset security rule sets to check whether there are potential security vulnerabilities, such as command injection, cross-site scripting attacks, etc. At the same time, the script operation is simulated through the virtual execution environment to ensure that the escaped code can work normally on the target platform without compatibility issues.
[0077] In one embodiment, the target escape script code that has passed the escape and verification will be output to a specified location, along with a detailed escape report that describes the changes before and after the escape and security improvements. The system also provides an optional feedback loop mechanism to collect feedback on the escape results for continuous optimization of model performance and escape strategies.
[0078] On the one hand, an embodiment of the present invention provides a script language escape device based on a large language model, such as Figure 2 As shown, including:
[0079] Acquisition module, used to obtain the original script code;
[0080] The model calling module is used to call the large language model for context analysis and obtain the script language escape strategy solution;
[0081] A rule generation module, used for generating a script escape rule for the original script code based on the script language escape strategy scheme;
[0082] The escape module is used to perform code escape on the original script code according to the script escape rule to obtain a target escape code.
[0083] In one embodiment, the system architecture further includes the following main modules, which work together to achieve efficient and intelligent script language escape.
[0084] (1) Input interface module:
[0085] Receives the original script code to be escaped.
[0086] In one embodiment, an API interface is also provided for integration with other systems.
[0087] (2) Contextual Understanding Module:
[0088] Use natural language processing technology and deep learning algorithms to perform semantic analysis on script codes. Identify key elements in script codes, such as variables, function calls, special characters, etc. Understand the contextual meaning of script codes and provide a basis for the selection of subsequent escape strategies.
[0089] (3) Intelligent escape strategy library:
[0090] Contains a variety of pre-defined and dynamically learned escape rules. According to the analysis results of the context understanding module, the most appropriate escape strategy is intelligently selected.
[0091] (4) Escape execution module:
[0092] According to the instructions in the intelligent escape strategy library, the script is escaped, including character escape, command injection protection, dynamic code injection detection and other functions.
[0093] (5) Output interface module:
[0094] The target escaped script code obtained after the escape process is output through this module. The output can be returned to the requester or written to a specified storage location for subsequent system use.
[0095] (6) Learning and Optimization Module:
[0096] Collect feedback information during the escape process, including success and failure cases. Use machine learning algorithms to optimize the escape strategy library to improve the accuracy and efficiency of escape.
[0097] On the one hand, if Figure 3 As shown, an embodiment of the present invention provides a script language escaping system based on a large language model, the system comprising a processor and a memory, the processor executing computer instructions stored in the memory to implement the above-mentioned script language escaping method based on a large language model.
[0098] On the one hand, if Figure 4 As shown, the embodiment of the present disclosure provides a computer-readable storage medium 40 on which non-transitory computer-readable instructions 41 are stored. When the non-transitory computer-readable instructions 41 are executed by a processor, a script language escape method based on a large language model in the above-mentioned embodiments of the present disclosure is executed.
[0099] The following advantages are achieved through the above disclosed embodiments:
[0100] Improved compatibility and migration efficiency: In the face of multi-platform and multi-language environments, this technology achieves smooth code migration by dynamically generating escape rules. For example, in the conversion instance from Python to JavaScript, the successful case shows that the code migration success rate has increased to more than 95%, which greatly shortens the cross-platform development cycle, reduces the workload of manual debugging, and improves the productivity of the development team;
[0101] Intelligent optimization and adaptability: With the learning and reasoning capabilities of the large language model, this solution can intelligently adjust the escape strategy according to the actual purpose of the script and the target environment, which not only ensures the correctness of the function, but also further optimizes the execution efficiency. In an actual application, the execution time of the escaped script was shortened by 20% on average, especially when processing large amounts of data and complex logic;
[0102] Reduce maintenance costs and improve user experience: By automating the escape and verification process, errors introduced by manual conversion are reduced, reducing later maintenance costs. At the same time, the output escape report helps developers quickly locate and understand changes, promoting communication and cooperation between teams. Significantly improve the end-user experience satisfaction;
[0103] Promoting technological innovation and sustainable development: The open interface design facilitates integration with other development tool chains, promoting the co-construction and sharing of the technology ecosystem. By continuously collecting user feedback and iterating and optimizing the model, a virtuous cycle is formed, constantly pushing the boundaries of technological innovation and building a sustainable competitive advantage for the enterprise.
[0104] To sum up, the technical solution disclosed in the present invention not only solves the key problems in the prior art such as low script escape efficiency, insufficient security, and poor compatibility, but also significantly improves development efficiency, enhances application security and user experience through intelligent and automated methods, and wins a significant advantage for the company in the fierce technological competition.
[0105] Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent substitutions for some of the technical features therein; and these modifications or substitutions 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 invention.
Claims
1. A script language escape method based on a large language model, characterized by: Get the original script code; Call the large language model to perform context analysis and obtain the script language escape strategy solution; Based on the script language escape strategy scheme, generating a script escape rule for the original script code; According to the script escape rule, the original script code is escaped to obtain a target escape code.
2. The method according to claim 1, further comprising preprocessing the original script code after obtaining the original script code.
3. According to the method of claim 1, further, a large language model training sample is created, the large language model is trained, and the required callable large language model is obtained.
4. According to the method of claim 1, further, calling a large language model to perform context analysis and obtain a script language escape strategy solution comprises: Based on the context information of the original script code, identifying the language type and logical structure of the original script code; Based on the logical structure, the functional intent of the original script code is parsed to construct a functional structure tree; Based on the function structure tree, the corresponding script language escape strategy solution is generated.
5. According to the method of claim 1, further, generating a script escape rule for the original script code based on the script language escape strategy scheme comprises: Determine the escape rule corresponding to the logical structure according to the script language escape strategy scheme; According to the script language escape strategy scheme, the escape rules corresponding to the functional modules are determined.
6. The method according to claim 1, further comprising: The target escape code enters security and compatibility verification.
7. The method according to claim 6, further, the security and compatibility verification includes using a static code analysis method to check the security of the target escape code; The target escape code is simulated and executed in a virtual execution environment to verify the compatibility of the target escape code.
8. A script language escape device based on a large language model, characterized in that: Acquisition module, used to obtain the original script code; The model calling module is used to call the large language model for context analysis and obtain the script language escape strategy solution; A rule generation module, used for generating a script escape rule for the original script code based on the script language escape strategy scheme; The escape module is used to perform code escape on the original script code according to the script escape rule to obtain a target escape code.
9. A script language escaping system based on a large language model, the system comprising a processor and a memory, the processor executing computer instructions stored in the memory to implement any of the methods of claims 1-7.
10. A computer-readable storage medium storing computer instructions for causing a computer system to execute the method of any one of claims 1 to 7.