File processing method and apparatus

By generating a Lua script function tree and processing instructions based on that tree, the problem of function lookup and optimization in Lua script files is solved, improving running efficiency and lookup accuracy.

CN114817470BActive Publication Date: 2025-12-19ZHUHAI KINGSOFT ONLINE GAME TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210462663.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-28
Publication Date
2025-12-19
Estimated Expiration
2042-04-28

AI Technical Summary

Technical Problem

In existing technologies, it is impossible to accurately locate specific functions in Lua script files and there is a lack of static analysis optimization methods, resulting in low efficiency in function optimization.

Method used

By parsing Lua script files to generate script function trees, and processing instructions based on the function trees, including function lookup and optimization, the system can perform these operations.

Benefits of technology

It improves the running efficiency of Lua script files and the accuracy of function lookup, reduces invalid function calls, and enhances game performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114817470B_ABST
    Figure CN114817470B_ABST
Patent Text Reader

Abstract

The application provides a file processing method and device, wherein the file processing method comprises: obtaining a to-be-processed script file; parsing the to-be-processed script file to obtain a script function set and calling information of each script function in the script function set; generating a script function tree corresponding to the to-be-processed script file based on the script function set and the calling information of each script function; receiving a file processing instruction for the to-be-processed script file, and processing the script function tree in response to the file processing instruction. By parsing the to-be-processed script file, generating a script function tree corresponding to the to-be-processed script file, and processing the to-be-processed script file based on the script function tree, the file processing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of Internet, in particular to a file processing method. The present application also relates to a file processing device, a computing device and a computer readable storage medium. BACKGROUND

[0002] With the application and development of Internet technology, a script language named Lua script is often used in the current game industry. Compared with C++ and other high-level languages, Lua script language is easier to master. At the same time, as a language running on a sandbox virtual machine, it is naturally safe due to being isolated from the underlying machine language, but the flexible language brings a series of problems, such as too flexible function definition, which makes it difficult to perform some customized function searching and function optimization. Therefore, how to quickly find the functions in the Lua script and optimize the functions in the Lua script is a problem that needs to be solved at present. SUMMARY

[0003] Therefore, the embodiments of the present application provide a file processing method. The present application also relates to a file processing device, a computing device and a computer readable storage medium to solve the problem that the specific function cannot be accurately found in the Lua script file and the efficiency optimization of the Lua script under static analysis in the prior art.

[0004] According to a first aspect of the embodiments of the present application, a file processing method is provided, comprising:

[0005] obtaining a to-be-processed script file;

[0006] parsing the to-be-processed script file to obtain a script function set and calling information of each script function in the script function set;

[0007] generating a script function tree corresponding to the to-be-processed script file based on the script function set and the calling information of each script function;

[0008] receiving a file processing instruction for the to-be-processed script file, and processing the script function tree in response to the file processing instruction.

[0009] According to a second aspect of the embodiments of the present application, a file processing device is provided, comprising:

[0010] an obtaining module configured to obtain a to-be-processed script file;

[0011] a parsing module configured to parse the to-be-processed script file to obtain a script function set and calling information of each script function in the script function set;

[0012] The generating module is configured to generate a script function tree corresponding to the to-be-processed script file based on the set of script functions and the calling information of each script function.

[0013] The processing module is configured to receive a file processing instruction for the to-be-processed script file, and perform processing on the script function tree in response to the file processing instruction.

[0014] According to a third aspect of an embodiment of the present application, a computing device is provided, which includes a memory, a processor, and computer instructions stored in the memory and executable on the processor, and the processor implements the steps of the file processing method when executing the computer instructions.

[0015] According to a fourth aspect of an embodiment of the present application, a computer readable storage medium is provided, which stores computer instructions, and the computer instructions implement the steps of the file processing method when executed by a processor.

[0016] The file processing method provided by the present application includes: obtaining a to-be-processed script file; parsing the to-be-processed script file to obtain a set of script functions and calling information of each script function in the set of script functions; generating a script function tree corresponding to the to-be-processed script file based on the set of script functions and the calling information of each script function; receiving a file processing instruction for the to-be-processed script file, and performing processing on the script function tree in response to the file processing instruction.

[0017] An embodiment of the present application realizes generating a script function tree corresponding to a to-be-processed script file by parsing the to-be-processed script file, and performing corresponding file processing on the to-be-processed script file based on the script function tree, thereby improving the running efficiency of the to-be-processed script file. BRIEF DESCRIPTION OF DRAWINGS

[0018] Figure 1 is a flowchart of a file processing method provided by an embodiment of the present application;

[0019] Figure 2 is a schematic diagram of a script function tree in an embodiment of the present application;

[0020] Figure 3 is an instruction schematic diagram of a function in an embodiment of the present application;

[0021] Figure 4 is a processing flowchart of a file processing method for optimizing a Lua script file provided by an embodiment of the present application;

[0022] Figure 5 is a structural schematic diagram of a file processing device provided by an embodiment of the present application;

[0023] Figure 6is a structural block diagram of a computing device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0024] In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present application. However, the present application can be practiced without the specific details

[0025] The terminology used in this description of one or more embodiments of the present application is for the purpose of describing particular embodiments only and is not intended to be limiting of one or more embodiments of the present application. As used in this description and the appended claims, the singular forms "a," "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will also be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.

[0026] It will be understood that, although the terms first, second, etc. can be used herein to describe various information, these terms are not intended to denote a temporal sequence, but are used only to distinguish one piece of information from another. For example, without departing from the scope of one or more embodiments of the present application, first can be termed second, and similarly, second can be termed first. Depending on the context, the word "if' as used herein can be interpreted to mean "when" or "upon" or "in response to determining."

[0027] First, the noun terms related to one or more embodiments of the present application are explained.

[0028] Lua script: Lua is a small scripting language designed to be embedded in an application, thereby providing flexible extension and customization functions for the application.

[0029] Lua script is a script language often used in game industry. Compared with high-level languages such as C++, script language is easier to master. Meanwhile, as a language running on a sandbox virtual machine, Lua language is naturally safe due to being isolated from the underlying machine language. However, flexible language brings a series of problems, such as too flexible function definition and variable without declaration, which makes it difficult for us to perform some customized search behaviors, for example, to find functions in some Lua script files that match a special function name and call some specific logic program interface. The above purpose cannot be achieved by existing text search because text search cannot distinguish the boundary between functions. Text search can only be accurate to the function that calls the specified function name and specific logic interface in a certain script. For the specified function name nested call specific logic interface, text search cannot find it. In some special cases, the nested call function name may even be in other Lua script files, and text search cannot find this specified function name.

[0030] Secondly, Lua script language lacks corresponding script detection methods. The industry usually uses dynamic performance analysis and sampling point methods for analysis. That is, the Lua stack is sampled once every x microseconds during running, and then the data distribution is used to count the call conditions of related functions. However, for static analysis, there is no good solution. Regular syntax can even hardly recognize the beginning and end of a function. For a slightly complex function with annotation instructions or a variable assignment in the function but not actually used, it cannot be distinguished.

[0031] Based on this, the present application provides a file processing method for solving the problem of customized search and script detection in Lua script. The present application also relates to a file processing device, a computing device, and a computer readable storage medium, which are described in detail in the following embodiments.

[0032] Figure 1 A flowchart of a file processing method according to an embodiment of the present application is shown, which specifically includes the following steps:

[0033] Step 102: Obtain a script file to be processed.

[0034] The script file to be processed can be understood as a Lua script file to be processed. The subsequent file processing steps are performed for the script file to be processed.

[0035] In actual application, one or more script files to be processed can be obtained. In the case of obtaining multiple Lua script files, the obtained multiple Lua script files are all taken as script files to be processed, and the subsequent file processing steps are performed for the multiple Lua script files.

[0036] In an embodiment of the present application, a to-be-processed script file is obtained, and the to-be-processed script file is a Lua script file.

[0037] In step 104, the to-be-processed script file is parsed to obtain a script function set and calling information of each script function in the script function set.

[0038] The parsing of the to-be-processed script file can be understood as running the to-be-processed script file using a virtual machine, the script function set is all script functions contained in the to-be-processed script file, and the calling information can be understood as information about calling other script functions by a script function. For example, the calling information of the A function is to call the B function, and there is code about calling the B function by the A function in the to-be-processed script file.

[0039] In actual application, after the Lua script file is obtained, the Lua script file is loaded into memory and parsed, the Lua script is parsed according to the Lua syntax defined in advance, the Lua script file is automatically parsed using the Lua virtual machine, all functions are registered in the virtual machine, thereby obtaining the script function set in the Lua script file and pointers of all sub-script functions called by each script function, and meanwhile, the virtual machine also parses to obtain byte code of running each function in the virtual machine and all constants and temporary variable objects involved by each function.

[0040] In an embodiment of the present application, based on the above example, the Lua script file is parsed based on the virtual machine to obtain the script function set in the Lua script file and the calling information of each script function in the script function set. The script function set includes the A script function, the B script function, the C script function and the D script function.

[0041] In step 106, the script function tree corresponding to the to-be-processed script file is generated based on the script function set and the calling information of each script function.

[0042] The script function tree can be understood as a tree structure generated according to each script function in the script function set. Referring to Figure 2 , Figure 2 A schematic diagram of the script function tree in an embodiment of the present application is shown, wherein there are four tree nodes on the script function tree, each tree node represents a function prototype (Proto), each function prototype includes a function object and an instruction list, and the function prototypes are connected through calling relationship, that is, the Lua Proto function object calls the other three Sub Proto sub-objects.

[0043] In actual application, in order to better script detection or function searching of the Lua script file, the Lua script file can be parsed based on the virtual machine, and a script function tree corresponding to the Lua script file is generated, and script analysis or function searching is performed based on the data structure of the script function tree, so that the accuracy and efficiency of file processing are improved.

[0044] In an embodiment of the present application, the above example is followed, and the script function tree corresponding to the Lua script file is generated according to the script function set obtained by parsing the Lua script file and the call information of each script function in the script function set.

[0045] Specifically, the script function tree corresponding to the to-be-processed script file is generated based on the script function set and the call information of each script function, and includes:

[0046] The function node corresponding to each script function is generated according to each script function in the script function set and the call information of each script function.

[0047] The script function tree corresponding to the to-be-processed script text is generated according to the function node corresponding to each script function.

[0048] The function node can be understood as a function prototype on the function tree, that is, a script function, and the function node includes a pointer of the function and all child functions called by the function, bytecode of the function running in the virtual machine, and all constant and temporary variable objects related to the function, and the data structure of each function node is consistent.

[0049] In actual application, the function can be analyzed for efficiency or the desired function can be searched by analyzing the bytecode of the function on the function node and the bytecode of the child function called by the function.

[0050] In an embodiment of the present application, the above example is followed, and the function node corresponding to each script function is generated according to the four script functions in the script function set and the call information of each script function, which are A function node, B function node, C function node and D function node, and the script function tree corresponding to the to-be-processed script file is generated according to the four function nodes, the A function node is a main function, and the B, C and D function nodes are child function nodes called by the A function node.

[0051] Specifically, each function node includes an instruction code list, and the script function tree corresponding to the to-be-processed script text is generated according to the function node corresponding to each script function, and includes:

[0052] The child function node having an association relationship with each function node is determined according to the instruction code list corresponding to each function node.

[0053] The function node and the sub-function node associated with the function node are generated based on each function node and a sub-function node associated with each function node.

[0054] The association between the function node and the sub-function node can be understood as that the script function corresponding to the function node calls the sub-script function corresponding to the sub-function node. For example, the A script function corresponding to the A function node calls the B script function corresponding to the B function node, and the A function node and the B function node have an association relationship, and the B function node is a sub-function node of the A function node.

[0055] In actual application, after the function node corresponding to each script function is generated according to the script function set in the to-be-processed script file and the calling information of each script function in the script function set, the sub-function node associated with the function node can be determined according to the calling pointer in the instruction code list of each function node, and the function nodes are connected according to the association relationship to generate a script function tree.

[0056] In an embodiment of the present application, the sub-function nodes associated with the A function node are the B function node, the C function node and the D function node according to the calling pointer in the instruction code list corresponding to the A function node, and the A function node and the B function node, the C function node and the D function node are connected according to the association relationship to generate a script function tree.

[0057] Specifically, the sub-function node associated with each function node is determined according to the instruction code list corresponding to each function node, comprising:

[0058] determining a target function node corresponding to a target script function;

[0059] determining at least one target sub-function node associated with the target function node according to a target instruction code list of the target function node.

[0060] The target function node can be a function node selected from all function nodes, and the target sub-function node of the target function node is determined for the target function node.

[0061] In actual application, the process of determining the sub-function node associated with each function node is performed once for all generated function nodes, so that the sub-function node corresponding to each function node is determined.

[0062] In an embodiment of the present application, the above example is followed, the target script function is determined to be the A script function, the target function node is determined to be the A function node, and the target sub-function node associated with the A function node is determined according to the calling pointer in the instruction code list of the A function node, and the target sub-function node is the B function node, the C function node and the D function node.

[0063] Step 108: receiving a file processing instruction for the to-be-processed script file, and processing the script function tree in response to the file processing instruction.

[0064] In actual applications, after the script function tree corresponding to the to-be-processed script file is generated, the to-be-processed script file can be processed based on the script function tree.

[0065] The received file processing instruction can be understood as an instruction for processing the to-be-processed script file. The to-be-processed script file is processed based on the file processing instruction. The file processing instruction can be an instruction for efficiency optimization of the to-be-processed script file, that is, a to-be-optimized function determination instruction. The file processing instruction can also be a function search instruction for the to-be-processed script file.

[0066] In an embodiment of the present application, the above example is followed. The file processing instruction for the to-be-processed script file is received. The file processing instruction is a to-be-optimized function determination instruction. The to-be-optimized function is determined in the script function tree in response to the file processing instruction.

[0067] In another embodiment of the present application, the above example is followed. The file processing instruction for the to-be-processed script file is received. The file processing instruction is a function search instruction. The target script function to be searched is determined in the script function tree in response to the file processing instruction.

[0068] In actual applications, when the file processing instruction is a to-be-optimized function determination instruction, the to-be-optimized function needs to be determined based on the script function tree. Specifically, the file processing instruction is a to-be-optimized function determination instruction.

[0069] The script function tree is processed in response to the file processing instruction, including:

[0070] Analyzing the instruction code list of each function node of the script function tree, determining at least one to-be-optimized function node based on each instruction code list;

[0071] Feedback of to-be-optimized function information of the at least one to-be-optimized function node.

[0072] The to-be-optimized function determination instruction can be understood as a detection instruction for the to-be-processed script file. The function that needs to be optimized in the to-be-processed script file is detected, so as to improve the running efficiency of the to-be-processed script file. The to-be-optimized function node can be understood as an invalid function in the to-be-processed script file. For example, when A function calls B function, but B function is an empty function, B function is a to-be-optimized function.

[0073] In practical applications, for game scripts, there are a large number of Lua script calls of the same kind. Taking skills as an example, for a specific skill id, during the skill release process, the specific function corresponding to the skill in the script file will be called. Assuming that the skill starts to release, acts on an enemy target and hits or dodges, and ends to perish. Several script processes that will be fixed will be called. The planner may make annotations on the related functions that have been implemented before but have been abandoned later, indicating that the related functions corresponding to the function have been abandoned. However, if the annotations are not recognized, the game logic will call the function. For example, the skill acts on the target and does not perform subsequent operations, but the game logic still calls the function. During the process of calling the Lua virtual machine from the c++ script language, there will be a series of virtual machine stack and other complex operations. If these losses can be greatly reduced, the game running efficiency will be greatly improved. In actual situations, the number of invalid calls is large, so it is necessary to determine the functions to be optimized from the to-be-processed script files, reduce the loss of running the to-be-processed script files, and improve the running efficiency.

[0074] In an embodiment of the present application, the above example is followed. The instruction code list of each function node on the script function tree is analyzed, and the constants and temporary variable objects involved in each function in the instruction code list are obtained. Based on the constants and temporary variable objects in each instruction code list, it is determined whether there is a to-be-optimized function in each function node. The result is that the D function in the D function node is a to-be-optimized function. The to-be-optimized function information containing the D function node is fed back to the staff, and the staff performs subsequent optimization processing.

[0075] Specifically, the instruction code list of each function node on the script function tree is analyzed, and at least one to-be-optimized function node is determined based on each instruction code list, including:

[0076] Obtaining the instruction code list of each function node;

[0077] Determining whether each function node needs to be optimized according to a preset optimization condition and the instruction code list of each function node;

[0078] Determining at least one to-be-optimized function node according to the determination result.

[0079] The preset optimization condition can be a condition for the staff to determine whether a function needs to be optimized in advance. For example, the preset optimization condition can be that a function only performs a value assignment operation on a local variable and has an operation on a global variable. The local variable is not used subsequently. When the variable information in the instruction code list of the function node meets the preset optimization condition, the function corresponding to the function node is a to-be-optimized function, indicating that the function can be optimized.

[0080] In actual application, the preset optimization condition can further include that the function has been annotated and the function calls a null function. After it is determined according to the relevant information in the instruction code list of the function node that the function node satisfies the preset optimization condition, it is indicated that the function node needs to be optimized.

[0081] In an embodiment of the present application, the instruction code list of four function nodes is obtained, and whether the four function nodes need to be optimized is determined according to the preset optimization condition and the instruction code list of each function node. The determination result is that the D function node is a function node to be optimized, that is, the D script function in the D function node is a function to be optimized.

[0082] Specifically, whether an arbitrary function node needs to be optimized can be determined by the following steps, including:

[0083] Obtaining the function instruction corresponding to each instruction code in the instruction code list of the target function node;

[0084] Determining whether each function instruction satisfies the preset optimization condition;

[0085] In the case that at least one function instruction satisfies the preset optimization condition, determining that the target function node is a function node to be optimized;

[0086] In the case that none of the function instructions satisfies the preset optimization condition, determining that the target function node is a normal function node.

[0087] The function instruction can be understood as an operation instruction, an annotation instruction, a call instruction and the like on a variable in a script function. The instruction code list of each function node can include a plurality of function instructions. Whether each function instruction satisfies the preset optimization condition is determined, so as to determine whether the function node is a function node to be optimized.

[0088] In actual application, by scanning the instruction code list of each function node, it can be known what is done in the function. The function instruction corresponding to each instruction code of each function node is obtained. As long as there is a function instruction in the instruction code list of the function node satisfying the preset optimization condition, it is determined that the function node is a function node to be optimized.

[0089] In an embodiment of the present application, the target function node is determined to be the D function node as in the above example. The function instruction corresponding to each instruction code in the instruction code list of the D function node is obtained. The function instruction is an annotation instruction. The D function is determined based on the annotation instruction, and the D function is as follows:

[0090] Function HItTarget(pCaster, pTarget, nHitValue)

[0091] -- pCaster.AddBuff(111,1)

[0092] End

[0093] The comment instruction in the D function indicates that the line of script has been commented, thus the comment instruction in the D function meets the preset optimization condition, and the D function is the function node to be optimized.

[0094] In another specific embodiment of the present application, the above example is followed, the target function node is determined to be the D function node, the function instruction corresponding to each instruction code in the instruction code list of the D function node is acquired, the function instruction is a variable operation instruction, the D function is judged based on the comment instruction, and the D function is as follows:

[0095] Function HItTarget(pCaster, pTarget, nHitValue)

[0096] Local Buff = pCaster.GetBuff(111,1)

[0097] -- print(Buff.nLevel)

[0098] End

[0099] The variable operation instruction in the D function assigns a local variable buff, but the local variable buff does not perform any other operation subsequently, thus the variable operation instruction in the D function meets the preset optimization condition, and the D function is the function node to be optimized.

[0100] In another specific embodiment of the present application, the above example is followed, the target function node is determined to be the A function node, the function instruction corresponding to each instruction code in the instruction code list of the A function node is acquired, the function instruction is a call instruction, and the call instruction is that the A function calls the D function, and the A function is as follows:

[0101] Function HItTarget(pCaster, pTarget, nHitValue)

[0102] HitTargetSub(nHitValue)

[0103] End

[0104] The D function is as follows:

[0105] Function HitTargetSub(nHitValue)

[0106] End

[0107] The calling instruction in the A function calls the D function, but the D function is an empty function, the calling instruction meets the preset optimization condition, and the A function node is the function node to be optimized.

[0108] In another specific embodiment of the present application, the function instruction corresponding to each instruction code in the instruction code list of the A function node is obtained, referring to Figure 3 , Figure 3 The instruction schematic diagram of the function is shown in an embodiment of the present application, wherein OP_MOVE in the function instruction represents putting the instruction in the register B into the register A, OP_LOADK represents putting the value of Bx in the constant table into the register A, and the value in the register can be regarded as a temporary variable. If the value is not assigned to a global variable, or is not assigned to an input parameter, or is not called outside the white list function, it is regarded as a temporary variable, which can be discarded finally. It is determined that the A function node is the function node to be optimized.

[0109] Specifically, after determining that the target function node is the function node to be optimized, the method further comprises:

[0110] determining a target function corresponding to the target function node;

[0111] in a case where the target function belongs to a preset white list script function set, determining that the target function node is a normal function node;

[0112] in a case where the target function does not belong to the preset white list script function set, determining that the target function node is the function node to be optimized.

[0113] The preset white list script function set can be understood as a set containing a plurality of white list script functions, and the white list script function can be understood as a function that does not have any impact on variables in the function or values in the game world. This kind of function does not need to be optimized. For example, the function contains all interfaces for reading values, interfaces for obtaining a Lua object of a player, and interfaces for obtaining an attribute object. This kind of function is a white list script function.

[0114] In actual application, after the function node instruction code list is scanned to determine the function node to be optimized, the function node to be optimized can be further judged based on the white list script function set. If the function to be optimized in the function node to be optimized is a white list script function, the function node can not be optimized. Based on the preset white list script function set, other aspects can also be extended, for example, some white list script functions require that the value passed in when calling the function has been assigned. If the value passed in when calling the function is not assigned, it can also be determined that the function is a function to be optimized.

[0115] In an embodiment of the present application, the D function node is determined to be the function node to be optimized, and the D function of the D function node pair is determined to be the function to be optimized. If the D function belongs to the preset whitelist script function set, the D function node is a normal function node and does not need to be optimized.

[0116] In another embodiment of the present application, the D function node is determined to be the function node to be optimized, and the D function of the D function node pair is determined to be the function to be optimized. If the D function does not belong to the preset whitelist script function set, the D function node is the function node to be optimized and needs to be optimized.

[0117] In actual applications, after the function node to be optimized is determined, the detection result can be fed back to the staff, and the staff can optimize the script file to be processed. Specifically, after the function information of the at least one function node to be optimized is fed back, the method further includes:

[0118] receiving optimization operation information returned for the function information to be optimized;

[0119] optimizing the function to be optimized of the function node to be optimized according to the optimization operation information.

[0120] The optimization operation information can be understood as the optimization operation of the staff for the function to be optimized. The function to be optimized is optimized according to the optimization operation information, so as to improve the running efficiency of the script file to be processed.

[0121] In an embodiment of the present application, the optimization operation information returned for the D function is received, the optimization operation information is a delete function, and the D function of the D function node is deleted according to the optimization operation information.

[0122] In the case where the file processing instruction is a function to be optimized determination instruction, the script file to be processed is analyzed based on the script function tree to obtain and optimize the abandoned Lua script function in response to the function to be optimized determination instruction. In actual situations, a machine can also be used for scanning analysis to avoid manual intervention and consumption of manpower.

[0123] In another application, the file processing instruction can also be a function search instruction. Specifically, the file processing instruction is a function search instruction.

[0124] The script function tree is processed in response to the file processing instruction, including:

[0125] obtaining a target script function identifier and a target instruction code identifier in the function search instruction;

[0126] According to the target script function identifier and the target instruction code identifier, the target script function is searched in the script function tree.

[0127] The function searching instruction can be understood as an instruction of searching for a specific function in a to-be-processed script file, i.e., an instruction of searching for a target script function. The function searching instruction includes a required script function identifier and an instruction code identifier, and the script function tree is searched according to the script function identifier and the instruction code identifier. The script function identifier can be understood as a function name of the script function, and the instruction code identifier can be understood as an interface name of the instruction code.

[0128] In actual application, a function searching instruction is generated by specifying a function name and a specific function in the function, and the target script function is searched based on the function searching instruction.

[0129] In an embodiment of the present application, the target script function identifier and the target instruction code identifier in the function searching instruction are acquired, and the script function tree is searched according to the target script function identifier and the target instruction code identifier. When the script function identifier is consistent with the target script function identifier and the instruction code identifier is consistent with the target instruction code identifier, the function is determined as the target script function.

[0130] Specifically, according to the target script function identifier and the target instruction code identifier, the target script function is searched in the script function tree, and the target script function is obtained, including:

[0131] According to the target script function identifier, an initial function node corresponding to an initial script function is determined in the script function tree.

[0132] When the target instruction code identifier is included in the instruction code list of the initial function node, the initial script function is determined as the target script function.

[0133] When the target instruction code identifier is not included in the instruction code list of the initial function node, it is judged whether the target instruction code identifier is included in an instruction code list of an initial sub-function node having an association relationship with the initial function node.

[0134] When the target instruction code identifier is included in the instruction code list of the initial sub-function node, the initial script function is determined as the target script function.

[0135] When the target instruction code identifier is not included in the instruction code list of the initial sub-function node, the initial script function is determined as not being the target script function.

[0136] In actual application, the function with the specified function name can be determined in the script function tree according to the specified function name, and the instruction code identifier is searched in the instruction code list of the function. If both meet the requirements, the function is determined as the target script function. If the target instruction code identifier is not found in the instruction code list of the function, the search can be performed in the sub-function corresponding to the function. If the target instruction code identifier is found in the sub-function, the requirements are met.

[0137] In an embodiment of the present application, based on all function nodes in the script function tree, the target script function identifier is compared with the script function identifier of each function node to determine the initial script function with the same script function identifier as the target script function identifier. It is checked whether the target instruction code identifier is included in the constant list in the instruction code list of the initial script function node corresponding to the initial script function, i.e., whether the function references the special logic interface corresponding to the target instruction code identifier. If the function references the special logic interface, the function is determined as the target script function, and the function node corresponding to the target script function is the target function node.

[0138] In another embodiment of the present application, after the initial script function is determined, it is checked whether the target instruction code identifier is included in the constant list in the instruction code list of the initial script function node corresponding to the initial script function, i.e., whether the function references the special logic interface corresponding to the target instruction code identifier. If the function does not reference the special logic interface, it is checked whether the target instruction code identifier is included in the constant list in the instruction code list of the sub-function of the function. If the sub-function references the special logic interface, the function is also determined as the target script function.

[0139] The file processing method provided in the present application includes: obtaining a to-be-processed script file; parsing the to-be-processed script file to obtain a script function set and calling information of each script function in the script function set; generating a script function tree corresponding to the to-be-processed script file based on the script function set and the calling information of each script function; receiving a file processing instruction for the to-be-processed script file, and processing the script function tree in response to the file processing instruction. By parsing the to-be-processed script file, the script function tree corresponding to the to-be-processed script file is constructed, and based on the data structure of the script function tree, the analysis and detection processing of the to-be-processed script file can be implemented, the to-be-optimized function is determined and optimized, the running efficiency of the to-be-processed script file is improved, the function searching and processing in the to-be-processed script file can also be implemented, the demand of the staff for searching and customizing functions is met, the time for searching functions by the staff is reduced, and the searching efficiency and accuracy are improved.

[0140] The following describes the present application in detail with reference to the accompanying drawings Figure 4With the application of the file processing method provided in the present application to optimizing a Lua script file as an example, the file processing method is further described. Wherein, Figure 4 A processing flowchart of a file processing method applied to optimizing a Lua script file is shown, and specifically includes the following steps:

[0141] Step 402: Obtain a Lua script file.

[0142] Step 404: Parse the Lua script file to obtain a script function set and calling information of each script function in the script function set.

[0143] Step 406: Generate a function node corresponding to each script function in the script function set according to each script function and the calling information of each script function.

[0144] Step 408: Determine a sub-function node having an association relationship with each function node according to an instruction code list corresponding to each function node.

[0145] Step 410: Generate a script function tree corresponding to the Lua script file based on each function node and the sub-function node having the association relationship with each function node.

[0146] Step 412: Receive a determination instruction for a function to be optimized in the Lua script file.

[0147] Step 414: Analyze the instruction code list of each function node of the script function tree, and determine a function node to be optimized based on each instruction code list.

[0148] Step 416: Feed back function information to be optimized of at least one function node to be optimized.

[0149] Step 418: Receive optimization operation information returned for the function information to be optimized.

[0150] Step 420: Optimize the function to be optimized of the function node to be optimized according to the optimization operation information.

[0151] The application provides a file processing method applied to Lua script optimization, including: obtaining a Lua script file; parsing the Lua script file to obtain a script function set and calling information of each script function in the script function set; generating a function node corresponding to each script function according to each script function in the script function set and the calling information of each script function; determining a sub-function node having an association relationship with each function node according to an instruction code list corresponding to each function node; generating a script function tree corresponding to the Lua script file based on each function node and the sub-function node having the association relationship with each function node; receiving a to-be-optimized function determination instruction for the Lua script file; analyzing an instruction code list of each function node of the script function tree, and determining a to-be-optimized function node based on each instruction code list; feeding back to-be-optimized function information of at least one to-be-optimized function node; receiving optimization operation information returned for the to-be-optimized function information; and optimizing a to-be-optimized function of the to-be-optimized function node according to the optimization operation information. By parsing the Lua script file, constructing the script function tree corresponding to the Lua script file, and based on the data structure of the script function tree, static analysis of the Lua script file can be realized, and subsequent optimization processing can be realized, the to-be-optimized function is determined and optimized, and the running efficiency of the to-be-processed script file is improved.

[0152] Corresponding to the method embodiments, the application further provides file processing device embodiments, Figure 5 A structural schematic diagram of a file processing device provided by an embodiment of the application is shown. As shown in the figure, Figure 5 The device includes:

[0153] The obtaining module 502 is configured to obtain a to-be-processed script file.

[0154] The parsing module 504 is configured to parse the to-be-processed script file to obtain a script function set and calling information of each script function in the script function set.

[0155] The generating module 506 is configured to generate a script function tree corresponding to the to-be-processed script file based on the script function set and the calling information of each script function.

[0156] The processing module 508 is configured to receive a file processing instruction for the to-be-processed script file, and to process the script function tree in response to the file processing instruction.

[0157] Optionally, the generating module 506 is further configured to:

[0158] generate a function node corresponding to each script function according to each script function in the script function set and the calling information of each script function;

[0159] The script function tree corresponding to the to-be-processed script file is generated according to each function node and the sub-function nodes associated with each function node.

[0160] Optionally, the generation module 506 is further configured to:

[0161] The sub-function nodes associated with each function node are determined according to the instruction code list corresponding to each function node.

[0162] The script function tree corresponding to the to-be-processed script file is generated based on each function node and the sub-function nodes associated with each function node.

[0163] Optionally, the generation module 506 is further configured to:

[0164] The target function node corresponding to the target script function is determined.

[0165] At least one target sub-function node associated with the target function node is determined according to the target instruction code list of the target function node.

[0166] Optionally, the processing module 508 is further configured to:

[0167] The instruction code list of each function node of the script function tree is analyzed, and at least one to-be-optimized function node is determined based on each instruction code list.

[0168] The to-be-optimized function information of the at least one to-be-optimized function node is fed back.

[0169] Optionally, the processing module 508 is further configured to:

[0170] The instruction code list of each function node is obtained.

[0171] It is judged whether each function node needs to be optimized according to the preset optimization condition and the instruction code list of each function node.

[0172] At least one to-be-optimized function node is determined according to the judgment result.

[0173] Optionally, the processing module 508 is further configured to:

[0174] The function instruction corresponding to each instruction code in the instruction code list of the target function node is obtained.

[0175] It is judged whether each function instruction satisfies the preset optimization condition.

[0176] In a case where at least one function instruction satisfies the preset optimization condition, the target function node is determined as a to-be-optimized function node.

[0177] In a case where each function instruction does not satisfy the preset optimization condition, the target function node is determined as a normal function node.

[0178] Optionally, the processing module 508 is further configured to:

[0179] determine the target function corresponding to the target function node;

[0180] In a case where the target function belongs to the preset whitelist script function set, the target function node is determined as a normal function node.

[0181] In a case where the target function does not belong to the preset whitelist script function set, the target function node is determined as a function node to be optimized.

[0182] Further, the apparatus further includes a receiving module configured to:

[0183] receive optimization operation information returned for the function node to be optimized;

[0184] optimize the function to be optimized of the function node to be optimized according to the optimization operation information.

[0185] Optionally, the processing module 508 is further configured to:

[0186] obtain a target script function identifier and a target instruction code identifier in the function searching instruction;

[0187] search in the script function tree according to the target script function identifier and the target instruction code identifier, and obtain a target script function.

[0188] Optionally, the processing module 508 is further configured to:

[0189] determine an initial function node corresponding to an initial script function in the script function tree according to the target script function identifier;

[0190] In a case where the target instruction code identifier is included in the instruction code list of the initial function node, the initial script function is determined as the target script function;

[0191] In a case where the target instruction code identifier is not included in the instruction code list of the initial function node, it is judged whether the target instruction code identifier is included in an instruction code list of an initial child function node having an association relationship with the initial function node;

[0192] In a case where the target instruction code identifier is included in the instruction code list of the initial child function node, the initial script function is determined as the target script function;

[0193] In a case where the target instruction code identifier is not included in the instruction code list of the initial sub-function node, it is determined that the initial script function is not the target script function.

[0194] The file processing apparatus provided in the present application comprises: an obtaining module configured to obtain a to-be-processed script file; an analyzing module configured to analyze the to-be-processed script file to obtain a script function set and calling information of each script function in the script function set; a generating module configured to generate a script function tree corresponding to the to-be-processed script file based on the script function set and the calling information of each script function; and a processing module configured to receive a file processing instruction for the to-be-processed script file and process the script function tree in response to the file processing instruction. By analyzing the to-be-processed script file and constructing the script function tree corresponding to the to-be-processed script file, the analysis and detection processing of the to-be-processed script file can be implemented based on the data structure of the script function tree, the to-be-optimized function can be determined and optimized, the running efficiency of the to-be-processed script file is improved, the function searching and processing in the to-be-processed script file can be implemented, the demand of the staff for searching and customizing functions is met, the time for searching functions by the staff is reduced, and the searching efficiency and accuracy are improved.

[0195] The above is a schematic scheme of the file processing apparatus of the present embodiment. It should be noted that the technical scheme of the file processing apparatus belongs to the same concept as the technical scheme of the file processing method described above, and the details of the technical scheme of the file processing apparatus which are not described in detail can be seen from the description of the technical scheme of the file processing method.

[0196] Figure 6 A structural block diagram of a computing device 600 according to an embodiment of the present application is shown. The components of the computing device 600 include, but are not limited to, a memory 610 and a processor 620. The processor 620 is connected to the memory 610 through a bus 630, and a database 650 is used to save data.

[0197] The computing device 600 further comprises an access device 640, which enables the computing device 600 to communicate via one or more networks 660. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 640 can include one or more of any type of network interface (e.g., network interface card (NIC)) such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a worldwide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like, either wired or wireless.

[0198] In an embodiment of the present application, the above-mentioned components of the computing device 600, and Figure 6 other components not shown in FIG. 6 can also be connected to each other through the bus. It should be understood that, Figure 6 The computing device structure diagram shown is merely for the purpose of example, and is not a limitation on the scope of the present application. Those skilled in the art can add or replace other components as needed.

[0199] The computing device 600 can be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smartwatch, smart glasses, etc.), or other type of mobile device, or a stationary computing device such as a desktop computer or PC. The computing device 600 can also be a mobile or stationary server.

[0200] wherein the processor 620 implements the steps of the file processing method when executing the computer instructions.

[0201] The above is a schematic scheme of a computing device according to the present embodiment. It should be noted that the technical scheme of the computing device belongs to the same concept as the technical scheme of the file processing method described above, and the details of the technical scheme of the computing device that are not described in detail can be referred to the description of the technical scheme of the file processing method.

[0202] The present embodiment also provides a computer readable storage medium storing computer instructions, which when executed by a processor, implement the steps of the file processing method as described above.

[0203] The above is a schematic scheme of a computer readable storage medium according to the present embodiment. It should be noted that the technical scheme of the storage medium belongs to the same concept as the technical scheme of the file processing method described above, and the details of the technical scheme of the storage medium that are not described in detail can be referred to the description of the technical scheme of the file processing method.

[0204] The above describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the acts or steps recited in the claims can be performed in a different order than the order in which they are recited and still achieve desirable results. In addition, the processes depicted in the figures do not necessarily require the particular order shown, or sequential order to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous.

[0205] The computer instructions include computer program code, which may be in the form of source code, object code, executable file, or certain intermediate forms. The computer-readable medium may include any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium may be appropriately added to or subtracted according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media may not include electrical carrier signals and telecommunication signals.

[0206] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0207] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0208] The preferred embodiments disclosed above are merely illustrative of this application. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the content of this application. These embodiments are selected and specifically described in this application to better explain the principles and practical applications of this application, thereby enabling those skilled in the art to better understand and utilize this application. This application is limited only by the claims and their full scope and equivalents.

Claims

1. A file processing method characterized by, The method comprises the following steps: acquiring a to-be-processed script file; resolving the to-be-processed script file by using a virtual machine, registering all functions obtained by the resolving into the virtual machine, obtaining a script function set and calling information of each script function in the script function set; generating a script function tree corresponding to the to-be-processed script file based on the script function set and the calling information of each script function, comprising: generating a function node corresponding to each script function in the script function set and each script function based on the calling information; and generating the script function tree corresponding to the to-be-processed script file based on an instruction code list corresponding to each function node, wherein the script function tree comprises the function node and a sub-function node, the function node and the sub-function node have an association relationship, and the function node comprises bytecode of the function running in the virtual machine; receiving a file processing instruction for the to-be-processed script file, and processing the script function tree in response to the file processing instruction, wherein the file processing instruction comprises a to-be-optimized function determination instruction and a function searching instruction, and processing the script function tree in response to the file processing instruction comprises: performing efficiency analysis on a function on a function node and bytecode of a sub-function called by the function in response to the to-be-optimized function determination instruction, and determining a to-be-optimized function node; determining a target script function to be searched in the script function tree in response to the function searching instruction.

2. The method of claim 1, wherein, Each function node comprises an instruction code list. The script function tree corresponding to the to-be-processed script file is generated based on the instruction code list corresponding to each function node, comprising: determining a sub-function node having an association relationship with each function node based on the instruction code list corresponding to each function node; generating the script function tree corresponding to the to-be-processed script file based on each function node and the sub-function node having an association relationship with each function node.

3. The method of claim 2, wherein, Determining a sub-function node having an association relationship with each function node based on the instruction code list corresponding to each function node comprises: determining a target function node corresponding to a target script function; determining at least one target sub-function node having an association relationship with the target function node based on a target instruction code list of the target function node.

4. The method of claim 1, wherein, The file processing instruction is a to-be-optimized function determination instruction. Processing the script function tree in response to the file processing instruction comprises: analyzing the instruction code list of each function node of the script function tree, determining at least one to-be-optimized function node based on each instruction code list; feeding back to-be-optimized function information of the at least one to-be-optimized function node.

5. The method of claim 4, wherein, Analyzing the instruction code list of each function node on the script function tree, and determining at least one to-be-optimized function node based on each instruction code list comprises: acquiring the instruction code list of each function node; determining whether each function node needs to be optimized based on a preset optimization condition and the instruction code list of each function node; determining at least one to-be-optimized function node based on the determination result.

6. The method of claim 5, wherein, Whether each function node needs to be optimized can be determined by the following steps, comprising: obtaining a function instruction corresponding to each instruction code in the instruction code list of the target function node; determining whether each function instruction satisfies the preset optimization condition; in a case where at least one function instruction satisfies the preset optimization condition, determining that the target function node is a function node to be optimized; in a case where none of the function instructions satisfies the preset optimization condition, determining that the target function node is a normal function node.

7. The method of claim 6, wherein, after determining that the target function node is a function node to be optimized, the method further comprises: determining a target function corresponding to the target function node; in a case where the target function belongs to a preset whitelist script function set, determining that the target function node is a normal function node; in a case where the target function does not belong to the preset whitelist script function set, determining that the target function node is a function node to be optimized.

8. The method of claim 4, wherein, after feeding back the optimization function information of the at least one function node to be optimized, the method further comprises: receiving optimization operation information returned in response to the optimization function information; optimizing the optimization function of the function node to be optimized according to the optimization operation information.

9. The method of claim 1, wherein, the file processing instruction is a function searching instruction; in response to the function searching instruction, determining a target script function to be searched in the script function tree, comprising: obtaining a target script function identifier and a target instruction code identifier in the function searching instruction; searching in the script function tree according to the target script function identifier and the target instruction code identifier, and obtaining a target script function.

10. The method of claim 9, wherein, searching in the script function tree according to the target script function identifier and the target instruction code identifier, and obtaining a target script function, comprising: determining an initial function node corresponding to an initial script function in the script function tree according to the target script function identifier; in a case where the target instruction code identifier is included in the instruction code list of the initial function node, determining that the initial script function is the target script function; in a case where the target instruction code identifier is not included in the instruction code list of the initial function node, determining whether the target instruction code identifier is included in an instruction code list of an initial child function node associated with the initial function node; in a case where the target instruction code identifier is included in the instruction code list of the initial child function node, determining that the initial script function is the target script function; in a case where the target instruction code identifier is not included in the instruction code list of the initial child function node, determining that the initial script function is not the target script function.

11. A file processing apparatus characterized by comprising: comprising: an obtaining module configured to obtain a script file to be processed; a parsing module configured to parse the script file to be processed using a virtual machine, register all functions obtained by parsing in the virtual machine, obtain a script function set and calling information of each script function in the script function set; The generating module is configured to generate a script function tree corresponding to the to-be-processed script file based on the set of script functions and the calling information of each script function. The generating module is further configured to: generate a function node corresponding to each script function in the set of script functions and the calling information of each script function; and generate the script function tree corresponding to the to-be-processed script file according to the instruction code list corresponding to each function node, wherein the script function tree includes the function node and a sub-function node, the function node and the sub-function node have an association relationship, and the function node includes bytecode of the function running in a virtual machine. The processing module is configured to receive a file processing instruction for the to-be-processed script file, and perform processing on the script function tree in response to the file processing instruction. The file processing instruction includes a to-be-optimized function determination instruction and a function searching instruction. The processing module is further configured to perform efficiency analysis on a function on a function node and bytecode of a sub-function called by the function in response to the to-be-optimized function determination instruction, to determine a to-be-optimized function node; and to determine a target script function to be searched in the script function tree in response to the function searching instruction.

12. A computing device comprising a memory, a processor, and computer instructions stored on the memory and executable on the processor, wherein, The processor executes the computer instructions to implement the steps of the method in any one of claims 1-10.

13. A computer-readable storage medium storing computer instructions, wherein, The computer instructions are executed by the processor to implement the steps of the method in any one of claims 1-10.

14. A computer program product, characterised in that, The computer instructions are executed by the processor to implement the steps of the method in any one of claims 1-10. The computer instructions are executed by the processor to implement the steps of the method in any one of claims 1-10.

Citation Information

Patent Citations

  • Function call chain acquisition method and device and storage medium

    CN112148392A

  • Visual script execution method and device and electronic equipment

    CN114089987A

  • Game script optimization method and device

    CN114159799A