WO2023159920A1 - Script error processing method and apparatus, device, and storage medium - Google Patents

Script error processing method and apparatus, device, and storage medium Download PDF

Info

Publication number
WO2023159920A1
WO2023159920A1 PCT/CN2022/119025 CN2022119025W WO2023159920A1 WO 2023159920 A1 WO2023159920 A1 WO 2023159920A1 CN 2022119025 W CN2022119025 W CN 2022119025W WO 2023159920 A1 WO2023159920 A1 WO 2023159920A1
Authority
WO
WIPO (PCT)
Prior art keywords
error
source code
syntax tree
original
name
Prior art date
Application number
PCT/CN2022/119025
Other languages
French (fr)
Chinese (zh)
Inventor
谢雪彦
田娟
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2023159920A1 publication Critical patent/WO2023159920A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/32Monitoring with visual or acoustical indication of the functioning of the machine
    • G06F11/324Display of status information
    • G06F11/327Alarm or error message display
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3624Software debugging by performing operations on the source code, e.g. via a compiler
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/53Decompilation; Disassembly

Definitions

  • the embodiment of the present application relates to the technical field of financial technology (Fintech) data processing, and relates to but not limited to a script error processing method, device, device and storage medium.
  • Financial technology Fetech
  • the existing front-end system performance and errors are usually performance analysis platforms, monitoring platforms, and operation platforms.
  • the monitoring platform is most closely related to script errors.
  • the monitoring platform in the related art has a script processing flow as shown in Figure 1, which is divided into four steps: the first step is to collect errors; the second step is to store errors; the third step is to analyze/locate errors.
  • the most original error message so after the user gets the original error message, he only knows that the script has made an error, and needs to reproduce it in the test environment and locate the error specifically. In addition, no more effective information can be obtained. Further, the user needs to artificially Judging and checking the location of the error in the source file is inefficient; the fourth step is error warning.
  • Embodiments of the present application provide a script error processing method, device, device, and storage medium to solve the problem in the related art that intelligent and precise repairs cannot be made for script errors.
  • the embodiment of the present application provides a script error processing method, including:
  • the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the The corresponding relationship between the parameter name of the unobfuscated source code and the parameter name of the obfuscated source code;
  • the error row and column number, and the original syntax tree Based on the error type, the error row and column number, and the original syntax tree, locate the occurrence location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output a repair suggestion for the error.
  • An embodiment of the present application provides a script error processing device, including:
  • the obtaining module is used to obtain the error row and column number when an error occurs in the execution process of the executable code; wherein, the executable code is generated by the obfuscated source code processed by source mapping;
  • the obtaining module is used to obtain the error type obtained by performing gradient diagnosis on the error
  • a processing module configured to generate an original syntax tree based on the abstract syntax tree and the hash table converted from the obfuscated source code; wherein, the hash table stores the function method name of the unobfuscated source code and the function method name of the obfuscated source code Correspondence, and the corresponding relationship between the parameter name of the unobfuscated source code and the parameter name of the obfuscated source code;
  • the processing module is configured to locate the occurrence position of the error in the unobfuscated source code corresponding to the obfuscated source code based on the error type, the error row and column number, and the original syntax tree, and output the error for Suggested fixes for the errors described.
  • An embodiment of the present application provides a script error processing device, including: a memory, configured to store executable instructions; and a processor, configured to implement the above method when executing the executable instructions stored in the memory.
  • An embodiment of the present application provides a storage medium, which stores executable instructions, and is used to cause a processor to implement the above method when executed.
  • the executable code is generated by the obfuscated source code processed by the source map; the error type obtained by gradient diagnosis for the error is obtained; based on the obfuscated source code conversion, it is obtained
  • the abstract syntax tree and hash table generate the original syntax tree; among them, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the parameter name of the unobfuscated source code and the parameter of the obfuscated source code Name correspondence; based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output a repair suggestion for the error; that is, combine gradient diagnosis and reverse Compile and give a solution.
  • FIG. 1 is a schematic diagram of a processing flow of a script in the related art
  • FIG. 2 is a schematic diagram of an optional architecture of a server provided by an embodiment of the present application.
  • FIG. 3 is a first schematic flow diagram of a script error processing method provided by an embodiment of the present application.
  • FIG. 4 is a schematic diagram of the processing flow of a script in an achievable scenario provided by an embodiment of the present application
  • FIG. 5 is a second schematic flow diagram of a script error processing method provided by the embodiment of the present application.
  • Fig. 6 is a schematic diagram of the gradient diagnosis structure provided by the embodiment of the present application.
  • FIG. 7 is a third schematic flow diagram of a script error processing method provided by an embodiment of the present application.
  • Fig. 8 is a schematic diagram of a flow chart for accurately locating errors in an achievable scenario provided by the embodiment of the present application.
  • FIG. 9 is a second schematic flow diagram of accurately locating errors in an achievable scenario provided by the embodiment of the present application.
  • FIG. 10 is a schematic diagram of prompt information for error output provided by the embodiment of the present application.
  • the script error processing device provided by the embodiment of the present application can be implemented as a notebook computer, a tablet computer, a desktop computer, a mobile device (for example, a mobile phone, a portable Music players, personal digital assistants, special message devices, portable game devices), intelligent robots and other terminals with screen display functions can also be implemented as servers.
  • a mobile device for example, a mobile phone, a portable Music players, personal digital assistants, special message devices, portable game devices
  • intelligent robots and other terminals with screen display functions can also be implemented as servers.
  • FIG. 2 is a schematic structural diagram of a server 100 provided by an embodiment of the present application.
  • the server 100 shown in FIG. Various components in the server 100 are coupled together through the bus system 140 .
  • the bus system 140 is used to realize connection and communication between these components.
  • the bus system 140 also includes a power bus, a control bus and a status signal bus.
  • the various buses are labeled as bus system 140 in FIG. 2 .
  • Processor 110 can be a kind of integrated circuit chip, has signal processing capability, such as general-purpose processor, digital signal processor (DSP, Digital Signal Processor), or other programmable logic device, discrete gate or transistor logic device, discrete hardware Components, etc., wherein the general-purpose processor can be a microprocessor or any conventional processor, etc.
  • DSP digital signal processor
  • DSP Digital Signal Processor
  • User interface 130 includes one or more output devices 131 that enable presentation of media content, including one or more speakers and/or one or more visual displays.
  • the user interface 130 also includes one or more input devices 132, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
  • Memory 150 may be removable, non-removable or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, and the like. Memory 150 optionally includes one or more storage devices located physically remote from processor 110 . Memory 150 includes volatile memory or nonvolatile memory, and may include both volatile and nonvolatile memory. The non-volatile memory can be read-only memory (Read Only Memory, ROM), and the volatile memory can be random access memory (Random Access Memory, RAM). The memory 150 described in the embodiment of the present application is intended to include any suitable type of memory. In some embodiments, the memory 150 is capable of storing data to support various operations, examples of which include programs, modules, and data structures, or subsets or supersets thereof, as exemplified below.
  • Operating system 151 including system programs for processing various basic system services and performing hardware-related tasks, such as framework layer, core library layer, driver layer, etc., for implementing various basic services and processing hardware-based tasks;
  • Network communication module 152 for reaching other computing devices via one or more (wired or wireless) network interfaces 120
  • exemplary network interfaces 120 include: Bluetooth, Wireless Compatibility Authentication (Wi-Fi), and Universal Serial Bus (Universal Serial Bus, USB), etc.;
  • the input processing module 153 is configured to detect one or more user inputs or interactions from one or more of the input devices 132 and translate the detected inputs or interactions.
  • the device provided by the embodiment of the present application can be realized by software.
  • FIG. 2 shows a script error processing device 154 stored in the memory 150.
  • the script error processing device 154 can be the server 100
  • the device for processing script errors in the script can be software in the form of programs and plug-ins, and includes the following software modules: an acquisition module 1541 and a processing module 1542. These modules are logical, so any combination can be made according to the functions implemented or split further. The function of each module will be explained below.
  • the device provided in the embodiment of the present application may be implemented in hardware.
  • the device provided in the embodiment of the present application may be a processor in the form of a hardware decoding processor, which is programmed to execute the The script error processing method provided by the embodiment, for example, the processor in the form of hardware decoding processor can adopt one or more application-specific integrated circuits (Application Specific Integrated Circuit, ASIC), DSP, programmable logic device (Programmable Logic Device) , PLD), Complex Programmable Logic Device (Complex Programmable Logic Device, CPLD), Field Programmable Gate Array (Field-Programmable Gate Array, FPGA) or other electronic components.
  • ASIC Application Specific Integrated Circuit
  • DSP digital signal processor
  • programmable logic device Programmable Logic Device
  • PLD Complex Programmable Logic Device
  • CPLD Complex Programmable Logic Device
  • Field Programmable Gate Array Field-Programmable Gate Array
  • FPGA Field-Programmable Gate Array
  • Fig. 3 is an optional schematic flow chart of the script error processing method provided by the embodiment of the present application, which will be described in conjunction with the steps shown in Fig. 3,
  • Step S201 obtaining the error line and column number when an error occurs during the execution of the executable code.
  • the executable code is generated by the obfuscated source code processed by SourceMap.
  • SourceMap is a data format that stores the location mapping relationship between source code and generated code.
  • scripts such as JavaScript scripts are packaged and built into compressed and obfuscated production environment codes during the construction process using a module packager such as webpack.
  • the source map generally uses the .map extension.
  • a map file will be generated, and the map file
  • the location correspondence between the compressed production code and the original code is stored in .
  • JavaScript scripts will be referred to as JS scripts for description.
  • the processing device is equipped with a monitoring and analysis platform, and the map files in the packaging process can be uploaded to the monitoring and analysis platform through a plug-in provided by the processing device, and version management is performed on each map file.
  • the monitoring and analysis platform analyzes the map file to obtain the error line number of the error message, that is, the original line number information.
  • SourceMap to devisate the error row and column number
  • webpack packs and outputs the map file uses the plugin to upload the map file to the monitoring and analysis platform without publishing it; parses the map file Error information, get the specific original row and column numbers in the source code.
  • map files can be managed using version management rules.
  • the electronic device provided by the embodiment of the present application can be implemented as any computer such as a notebook computer, a tablet computer, a desktop computer, a mobile device (for example, a mobile phone, a portable music player, a personal digital assistant, a dedicated messaging device, a portable game device), an intelligent robot, etc.
  • a terminal with screen display function can also be implemented as a server.
  • an electronic device is implemented as a server as an example for description.
  • Step S202 acquiring the error type obtained by performing gradient diagnosis on the error.
  • the smallest granularity error type can be obtained through gradient diagnosis.
  • Gradient diagnosis refers to multi-level analysis and diagnosis, in which, the analysis and diagnosis of the nth level depends on the results of the analysis and diagnosis of the mth level, n and m are positive integers, and n is greater than m, and there is a progressive relationship between levels, until the gradient diagnosis At the final level, the most specific and accurate cause of the error was basically located.
  • step S203 an original syntax tree is generated based on the abstract syntax tree and the hash table converted from the obfuscated source code.
  • the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the corresponding relationship between the parameter name of the unobfuscated source code and the parameter name of the obfuscated source code.
  • the abstract syntax tree can be obtained by converting the obfuscated source code through a code parser such as esprima; then the original syntax tree can be generated based on the abstract syntax tree and HashMap.
  • Step S204 based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output a repair suggestion for the error.
  • this application when the JS script is deployed in the production environment, it is compressed and obfuscated code. After the multi-level error diagnosis of gradient diagnosis, the error location and context of the error cannot be accurately given. Therefore, it is necessary to accurately locate through the delocation and decompilation stages. After obtaining the original row and column number information, that is, the error row and column number when an error occurs, because the code is obfuscated, no effective information can be obtained at this time to help quickly locate the problem and give repair suggestions. Therefore, it is also necessary to obtain unobfuscated information through decompilation to locate the source code. In this regard, this application locates the location of the error in the unobfuscated source code corresponding to the obfuscated source code based on the error type, error row and column number, and the original syntax tree.
  • the method for handling script errors provided by the present application can be implemented through the following steps: First, errors are collected through an event processing function.
  • the gradient diagnosis is performed on the original error, and the precise error information of the smallest granularity obtained by the multi-level error diagnosis is obtained.
  • precise error information is called a quasi-diagnostic result.
  • SourceMap to perform source code delocation, that is, to locate the position of the error row and column number in the real source code when an error occurs.
  • the script error processing method obtains the row and column number of the error report when an error occurs in the running process of the executable code; wherein, the executable code is generated by the obfuscated source code processed by source mapping; The error type obtained by the gradient diagnosis; the original syntax tree is generated based on the abstract syntax tree and the hash table converted from the obfuscated source code; wherein, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and The corresponding relationship between the parameter names of the unobfuscated source code and the parameter names of the obfuscated source code; based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output the error-specific Repair suggestions; that is to say, a solution is given by
  • the gradient diagnosis may be a three-level analysis and diagnosis, wherein the analysis and diagnosis at the nth level depends on the results of the analysis and diagnosis at the mth level, n and m are positive integers, and n is greater than m. That is to say, this application diagnoses the error types of the script at the first, second, and third levels in sequence. There is a progressive relationship between the levels. When the error type of the third level is basically located, the most specific and accurate error Because of this, developers can go straight to fixing bugs. Regarding the step S202 to obtain the error type obtained by performing gradient diagnosis on the error, it can be realized through the steps shown in Figure 5:
  • Step S2021 analyzing the function type of the event processing function corresponding to the error, and classifying the error collected/reported by the event processing function conforming to the preset type as a first-level error.
  • the first-level error can be understood as a conventional front-end error classification, including three dimensions of script errors such as JS script errors, resource loading errors, and interface request errors.
  • This application takes JS script errors as an example to illustrate the three levels involved in gradient diagnosis. For the diagnosis of first-level errors, it is usually distinguished in the link of collecting/reporting errors.
  • Event processing functions include: (1) window.onerror: When there is a JS runtime error such as synchronous or asynchronous triggering, window will trigger the error event and execute window.onerror, and window cannot prevent the execution of the default event processing function;
  • addEventListener('unhandledrejection') When the promise is rejected and an exception is thrown without catch, use addEventListener('unhandledrejection') to capture and process;
  • console.error In some special cases, console.error needs to be captured and processed. The implementation method is to rewrite window.console.error to report error information.
  • Step S2022 perform regular keyword matching on the first-level errors, and classify the first-level errors into one of the five second-level errors.
  • the second-level error can be understood as classifying the second-level error for the JS script error in the first-level error.
  • syntax error SyntaxError
  • typeError type error
  • ReferenceError reference error
  • range error RangeError
  • URIError a syntax error during parsing.
  • SyntaxError refers to type error during parsing. Generally, SyntaxError will be found during the construction phase, or even the local development phase. The diagnosis may be made regardless of the type.
  • TypeError refers to type error. Value is not of the expected type.
  • ReferenceError refers to a reference type error, which will be reported when a variable that does not exist is referenced.
  • RangeError refers to a range error. This error will be reported when the set value exceeds the corresponding range.
  • URIError refers to a URL error, which is used to indicate an error caused by using a global Uniform Resource Locator (Uniform Resource Locator, URL) handler in a wrong way. Errors thrown when the parameters of related functions are incorrect, mainly involving six functions: encodeURI, decodeURI, encodeURIComponent, decodeURIComponent, escape, and unescape.
  • the JS script error information enters the second-level error diagnosis.
  • classification can be achieved through keyword regularization in the original error message.
  • Step S2023 calling the third-level error configuration table for each classified second-level error, and searching for the third-level error rule matching each classified second-level error in the third-level error configuration table.
  • the third-level errors can be understood as targeting the five types of the second-level errors, each category contains p third-level error types, and p is a positive integer.
  • the three-level error type is directly mapped to the specific error information of the JS script.
  • the third-level error type analysis will be performed. For each second-level error type, maintain a corresponding third-level error configuration table, which stores all enumerable third-level error rules and specific error information after classification under this second-level error type, and supports continuous expansion .
  • generating the three-level error configuration table can be realized in the following manner: according to a large amount of original JS script error information of the existing monitoring platform, first classify errors according to JS keywords, key related words, and key sentences successively, and then After classification, the integration of one type of errors is generalized as a rule of general three-level error rules.
  • This general rule represents a class of errors, mapping a common specific error message.
  • TypeError As an example, its third-level error configuration table is as follows:
  • Step S2024 determining the error types that have a mapping relationship with the third-level error rules in the three-level error configuration table.
  • the gradient diagnosis is a three-level error type diagnosis
  • the function type of the event processing function corresponding to the error analyze the function type of the event processing function corresponding to the error, and classify the error collected/reported by the event processing function conforming to the preset type as a first-level error. For example, errors collected by window.onerror, addEventListener, try...catch..., and console.error event processing functions are classified as first-level errors.
  • the second-level error type diagnosis stage the first-level error is classified into one of five second-level errors such as TypeError, ReferenceError, RangeError, and URIError by matching regular expressions with the second-level error keywords.
  • the third-level error type diagnosis stage the third-level error configuration table is invoked, and a third-level error rule matching each classified second-level error in the third-level error configuration table is found.
  • step S203 generates an original syntax tree based on the abstract syntax tree and hash table converted from the obfuscated source code, which can be implemented through the steps shown in Figure 7:
  • Step S2031 loop through the syntax tree and the hash table, and compare the object name of the object in an expression node in the abstract syntax tree with the key in the hash table.
  • Step S2032 if the object name is the same as a key in the hash table, reset the object name in an expression node to the value corresponding to a key in the hash table, and calculate the identification parameter of the property in an expression node Changed from the first parameter to the second parameter.
  • the first parameter related to the computed property (Computed) may be true, and the second parameter may be false.
  • Step S2033 if the object name is different from a key, compare the object name with another key in the hash table until the identification parameters of the calculated attributes in all expression nodes are changed from the first parameter to the second parameter, and the original syntax tree.
  • step S204 if the error type belongs to a reference type error or a type error, in step S204, based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, which can be It is achieved through the following steps:
  • the error type is a reference type error or a type error
  • convert the original syntax tree into unobfuscated source code
  • locate the location of the error in the unobfuscated source code based on the error row and column number.
  • the error type is a reference type error or a type error, as shown in Figure 8, the code processed by SourceMap is called "obfuscated source code"; when the error type hits "type error” and "reference Type error', the process for parsing errors and obtaining unobfuscated method names and parameter names in the source code is as follows:
  • Step S401 caching the error row and column number information in the 'obfuscated source code'.
  • Step S402 esprima converts the 'obfuscated source code' into a syntax tree.
  • Step S403 acquiring the HashMap in the map.
  • HashMap is generated in the code through the webpack construction phase and reported by the Software Development Kit (Sdk); HashMap stores the correspondence between the source code function method name and parameter name in the obfuscation phase and the obfuscated function method name and parameter name relation.
  • Step S404 loop through the syntax tree and HashMap, compare the name of the object in the MemberExpression node with the key in the HashMap, and if it hits, reset the name of the object in the MemberExpression node to the value of the corresponding key in the HashMap, and change Computed from true to is false.
  • Step S405 if there is no hit, continue traversing until all Computed are set to false.
  • Step S406 obtaining the original syntax tree.
  • Step S407 cache the original syntax tree into the sourceAST object.
  • Step S408 esprima converts the original syntax tree into "true source code”, writes the "real source code” into a file using fs.writeFile and caches it in the server.
  • step S204 based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, which can be realized by the following steps :
  • the error type belongs to the range error
  • obtain the original call stack based on the call stack information and the original syntax tree; where, the original call
  • the stack is an array that caches the location of errors located in the unobfuscated source code.
  • the original call stack can be obtained through the following steps:
  • the first step is to convert the call stack information into the first array stackArr, and delete the first item of the first array stackArr;
  • the second step is to traverse the first array stackArr and regularly match each item, take out the calling function names in the call stack that meet the matching conditions, and obtain the second array stackFnArr;
  • the third step is to traverse the original syntax tree and compare the object name of an expression node object with each item in the second array stackFnArr;
  • the fifth step is to cache all the expression nodes found by the loop comparison as the third array stackMEArr; wherein, the object names of all expression nodes are the same as an item in the second array stackFnArr;
  • the sixth step is to loop through the hash table and the third array stackMEArr, replace the object name of the object in the expression node in the third array stackMEArr with the value corresponding to the key in the hash table, and obtain the original call stack; among them, the original call stack An array of cached expression nodes.
  • Step S501 is the same as the execution flow from step S401 to step S406 of 'type error' and 'reference type error' to obtain the original syntax tree.
  • Step S502 cache to SourceAST object.
  • stack is a string and needs to be converted to an object; convert the stack string to an array stackArr through str.split('/n'), and delete the first item of the array.
  • Step S503 iterating through stackArr and matching each item, taking out the name of the calling function in the call stack, and caching it as an array stackFnArr.
  • the calling function names taken out are all obfuscated and need to be converted into real function names.
  • Step S504 traversing the original syntax tree, comparing the name of the object in the MemberExpression node with each item in stackFnArr, and caching the MemberExpression node after being hit.
  • Step S505 cache the found MemberExpression nodes as an array stackMEArr.
  • Step S506 loop through the HashMap and stackMEArr, and replace the name of the MemberExpression node in the stackMEArr array with the value matching the key in the HashMap.
  • Step S507 cache the newly obtained MemberExpression node as an array, which is called "original call stack”. Hints and fix suggestions are given in order of "raw call stack”.
  • the SourceMap technology and the self-developed decompilation technology are combined with the HashMap to achieve efficient accurate error location and the ability to quickly decompile to obtain the original error information.
  • the output of the repair suggestion for the error in step S204 can be achieved through the following steps:
  • the repair suggestion configuration table is obtained based on the three-level error configuration table of the gradient diagnosis of the three-level error type, and each third-level error rule corresponds to a repair suggestion.
  • Early warning remediation The essence of early warning repair is to presuppose the condition that an error may occur, and when the condition is triggered, the error does not actually occur. Through the early warning, the user behavior can be checked and repaired before the error occurs, so as to avoid the error. How to achieve early warning repair?
  • a statistical clustering process Make statistics on the errors that occurred in history, make statistics from different dimensions such as time, region, and user, find out the rules, and automatically add these rules to the early warning conditions through the algorithm predictor. When it is triggered next time, combined with "gradient diagnosis” ", "Precise Positioning", and "Repair Suggestion” processes provide timely warnings.
  • the script error processing method can obtain accurate error location and accurate repair suggestions after gradient diagnosis, delocation and decompilation, and repair suggestions for the original error information. See Figure 10 for the main information contained in the prompt information notified to the user.
  • the main information includes but is not limited to the original error, the second-level error, the third-level error, source code location, repair suggestions, and additional information.
  • the user can directly locate the problem and fix the problem according to the suggestion, which greatly shortens the impact area of the bug and ensures better availability of the front-end system.
  • problems can be exposed and avoided in advance, providing a strong guarantee for the continuous stability of the system.
  • the script error processing device 154 provided by the embodiment of the present application is implemented as a software module.
  • the software stored in the script error processing device 154 of the memory 150 A module may be a script error handling device in the server 100, including:
  • the obtaining module 1541 is used to obtain the error line and column number when an error occurs during the execution of the executable code; wherein, the executable code is generated by the obfuscated source code processed by source mapping;
  • An acquisition module 1541 configured to acquire the error type obtained by performing gradient diagnosis on the error
  • the processing module 1542 is used to generate the original syntax tree based on the abstract syntax tree and the hash table converted from the obfuscated source code; wherein, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the unobfuscated source code. The corresponding relationship between the parameter name of the obfuscated source code and the parameter name of the obfuscated source code;
  • the processing module 1542 is configured to locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code based on the error type, error row and column number, and the original syntax tree, and output a repair suggestion for the error.
  • the processing module 1542 is used to loop through the syntax tree and the hash table, and compare the object name of the object in an expression node in the abstract syntax tree with the key in the hash table; If a key in the hash table is the same, the object name in an expression node is reset to the value corresponding to a key in the hash table, and in an expression node, the identification parameter of the calculated attribute is changed from the first parameter to the second Two parameters; if the object name is different from a key, compare the object name with another key in the hash table until the identification parameters of the computed properties in all expression nodes are changed from the first parameter to the second parameter, and the original syntax tree.
  • the processing module 1542 is used to convert the original syntax tree into unobfuscated source code if the error type belongs to the reference type error or type error; locate the occurrence of the error in the unobfuscated source code based on the row and column number of the error report Location.
  • the processing module 1542 is used to obtain the call stack information of the location of the error captured by the software development kit based on the error row and column number if the error type belongs to the range error; based on the call stack information and the original syntax tree, The original call stack is obtained; wherein, the original call stack is an array of locations where errors located in the unobfuscated source code are cached.
  • the processing module 1542 is used to convert the call stack information into the first array, and delete the first item of the first array; traverse the first array and match each item content regularly, and take out the call stack information Call the function name that meets the matching conditions to get the second array; traverse the original syntax tree to compare the object name of an expression node object with each item in the second array; if the object name is the same as the second array If one item is the same, an expression node is cached; all expression nodes found by the loop comparison are cached as the third array; wherein, the object names of all expression nodes are the same as one item in the second array; looping through the array list and the third array, replace the object name of the object in the expression node in the third array with the value corresponding to the key in the hash table, and get the original call stack; where the original call stack is the cached expression node with replacement array of .
  • the processing module 1542 is used to analyze the function type of the event processing function corresponding to the error, and classify the error collected/reported by the event processing function conforming to the preset type as a first-level error; Perform keyword regular matching on errors, and classify the first-level errors into one of the five second-level errors; call the third-level error configuration table for each classified second-level error, and find the third-level error configuration table The three-level error rule that matches each of the classified two-level errors; the error type that has a mapping relationship with the three-level error rule is determined in the three-level error configuration table.
  • the processing module 1542 is configured to search the repair suggestion configuration table for a repair suggestion matching the three-level error rule, and output the repair suggestion.
  • the script error processing device obtains the error line number when an error occurs in the execution process of the executable code; wherein, the executable code is generated by the obfuscated source code processed by source mapping; The error type obtained by the gradient diagnosis; the original syntax tree is generated based on the abstract syntax tree and the hash table converted from the obfuscated source code; wherein, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and The corresponding relationship between the parameter names of the unobfuscated source code and the parameter names of the obfuscated source code; based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output the error-specific Repair suggestions; that is to say, a solution is given by combining gradient diagnosis and de
  • the embodiment of the present application provides a storage medium storing executable instructions, and the executable instruction is stored therein.
  • the executable instruction When executed by the processor, it will cause the processor to execute the method provided in the embodiment of the present application, for example, as shown in FIG. 3 shows the method.
  • the storage medium provided by the embodiment of the present application is obtained by obtaining the error row and column number when an error occurs in the execution of the executable code; wherein, the executable code is generated by the obfuscated source code that has been processed by source mapping; and the gradient diagnosis for the error is obtained.
  • the error type the original syntax tree is generated based on the abstract syntax tree and the hash table converted from the obfuscated source code; the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the unobfuscated
  • the corresponding relationship between the parameter name of the source code and the parameter name of the obfuscated source code based on the error type, error row and column number and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output the repair suggestions for the error; That is to say, a solution is given by combining gradient diagnosis and decompilation.
  • the gradient diagnosis method is first used to accurately diagnose the original error, and then the smallest granularity error type diagnosed according to the gradient and decompilation As a result, accurate repair suggestions are obtained, and finally the accurate diagnosis results and accurate repair suggestions are notified to the user.
  • the storage medium can be a computer-readable storage medium, for example, a ferroelectric memory (FRAM, Ferromagnetic Random Access Memory), a read-only memory (ROM, Read Only Memory), a programmable read-only memory (PROM, Programmable Read Only Memory), Erasable Programmable Read Only Memory (EPROM, Erasable Programmable Read Only Memory), Electrically Erasable Programmable Read Only Memory (EEPROM, Electrically Erasable Programmable Read Only Memory), flash memory, magnetic surface memory, optical disc, Or memory such as CD-ROM (Compact Disk-Read Only Memory); It can also be various devices including one or any combination of the above-mentioned memories.
  • FRAM Ferroelectric memory
  • ROM Read Only Memory
  • PROM programmable read-only memory
  • EPROM Erasable Programmable Read Only Memory
  • EEPROM Electrically Erasable Programmable Read Only Memory
  • flash memory magnetic surface memory
  • optical disc Or memory such as CD-ROM (Compact Disk-Read Only Memory); It can also be various
  • executable instructions may take the form of programs, software, software modules, scripts, or code written in any form of programming language, including compiled or interpreted languages, or declarative or procedural languages, and its Can be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
  • executable instructions may, but do not necessarily correspond to files in a file system, may be stored as part of a file that holds other programs or data, for example, in Hyper Text Markup Language (HTML, Hyper Text Markup Language) in one or more scripts in a document, in a single file dedicated to the program in question, or in multiple cooperating files (for example, a file that stores one or more modules, subroutines, or sections of code )middle.
  • executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or alternatively, on multiple computing devices distributed across multiple sites and interconnected by a communication network. to execute.
  • the embodiment of the present application provides a script error processing method, device, device, and storage medium, by obtaining the error row and column number when an error occurs in the execution of the executable code; wherein, the executable code is processed by source mapping Obfuscated source code generation; obtain the error type obtained by gradient diagnosis for errors; generate the original syntax tree based on the abstract syntax tree and hash table converted from the obfuscated source code; among them, the hash table stores the function method name and obfuscated source code of the unobfuscated source code The corresponding relationship between the function and method names of the source code, and the corresponding relationship between the parameter names of the unobfuscated source code and the parameter names of the obfuscated source code; based on the error type, error row and column number and the original syntax tree, locate the error in the unobfuscated source code corresponding to the obfuscated source code The position where the error occurs, and output the repair suggestion for the error; that is, combine

Landscapes

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

Abstract

The present application provides a script error processing method and apparatus, a device, and a storage medium. The method comprises: obtaining an error report row and column number when an error occurs during the operation of an executable code, wherein the executable code is generated from a source-mapped obfuscated source code; obtaining an error type obtained by performing gradient diagnosis on the error; generating an original syntax tree on the basis of an abstract syntax tree and a hash table obtained by converting the obfuscated source code, wherein the hash table stores the correspondence between a function method name of an unobfuscated source code and a function method name of the obfuscated source code and the correspondence between a parameter name of the unobfuscated source code and a parameter name of the obfuscated source code; on the basis of the error type, the error report row and column number, and the original syntax tree, locating an error occurrence location in the unobfuscated source code corresponding to the obfuscated source code, and outputting a repair suggestion for the error.

Description

一种脚本错误的处理方法、装置、设备及存储介质A script error processing method, device, equipment and storage medium
相关申请的交叉引用Cross References to Related Applications
本申请要求在2022年02月25日提交中国专利局、申请号为202210178711.2、申请名称为“一种脚本错误的处理方法、装置、设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202210178711.2 and the application name "A Method, Device, Equipment and Storage Medium for Handling Script Errors" submitted to the China Patent Office on February 25, 2022, the entire content of which Incorporated in this application by reference.
技术领域technical field
本申请实施例涉及金融科技(Fintech)的数据处理技术领域,涉及但不限于一种脚本错误的处理方法、装置、设备及存储介质。The embodiment of the present application relates to the technical field of financial technology (Fintech) data processing, and relates to but not limited to a script error processing method, device, device and storage medium.
背景技术Background technique
随着计算机计算的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,但由于金融行业的安全性、实时性要求,也对技术提出了更高的要求。With the development of computer computing, more and more technologies are applied in the financial field, and the traditional financial industry is gradually transforming into Fintech. However, due to the security and real-time requirements of the financial industry, higher requirements are placed on technology. requirements.
金融科技领域下,现有的与前端***性能、错误相关的通常是性能分析平台、监控平台、运营平台,其中,与脚本错误最密切的是监控平台。相关技术中的监控平台对于脚本的处理流程如图1所示,分为四步:第一步,采集错误;第二步,存储错误;第三步,分析/定位错误,该步骤只是给出最原始的错误信息,所以用户拿到原始错误信息后只知道脚本出错了,需要到测试环境复现并且具体定位错误,此外得不到更多的有效信息,进一步地,还需要用户人为地进行判断和排查错误在源文件中的位置,效率低下;第四步,错误预警,该步骤只是告诉用户错了,但是怎么修复需要参考问题再次复现后的具体分析。可见,相关技术中脚本错误的处理流程至少存在如下问题,无法针对脚本错误做出智能化地精准修复。In the field of financial technology, the existing front-end system performance and errors are usually performance analysis platforms, monitoring platforms, and operation platforms. Among them, the monitoring platform is most closely related to script errors. The monitoring platform in the related art has a script processing flow as shown in Figure 1, which is divided into four steps: the first step is to collect errors; the second step is to store errors; the third step is to analyze/locate errors. The most original error message, so after the user gets the original error message, he only knows that the script has made an error, and needs to reproduce it in the test environment and locate the error specifically. In addition, no more effective information can be obtained. Further, the user needs to artificially Judging and checking the location of the error in the source file is inefficient; the fourth step is error warning. This step only tells the user that the error is wrong, but how to fix it needs to refer to the specific analysis after the problem reappears. It can be seen that there are at least the following problems in the processing flow of script errors in related technologies, and it is impossible to intelligently and accurately repair script errors.
发明内容Contents of the invention
本申请实施例提供一种脚本错误的处理方法、装置、设备及存储介质,以解决相关技术中无法针对脚本错误做出智能化地精准修复的问题。Embodiments of the present application provide a script error processing method, device, device, and storage medium to solve the problem in the related art that intelligent and precise repairs cannot be made for script errors.
本申请实施例的技术方案是这样实现的:The technical scheme of the embodiment of the application is realized in this way:
本申请实施例提供一种脚本错误的处理方法,包括:The embodiment of the present application provides a script error processing method, including:
获取可执行代码在运行过程中发生错误时的报错行列号;其中,所述可执行代码是由经过源映射处理的混淆源码生成的;Obtaining the error line and column number when an error occurs during the execution of the executable code; wherein, the executable code is generated by the obfuscated source code processed through source mapping;
获取针对所述错误进行梯度诊断得到的错误类型;Obtain the error type obtained by performing gradient diagnosis on the error;
基于所述混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,所述散列表存储有未混淆的源码的函数方法名与所述混淆源码的函数方法名的对应关系,以及所述未混淆的源码的参数名与所述混淆源码的参数名的对应关系;Generate an original syntax tree based on the abstract syntax tree and hash table converted from the obfuscated source code; wherein, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the The corresponding relationship between the parameter name of the unobfuscated source code and the parameter name of the obfuscated source code;
基于所述错误类型、所述报错行列号和所述原始语法树,在所述混淆源码对应的所述未混淆的源码中定位所述错误的发生位置,并输出针对所述错误的修复建议。Based on the error type, the error row and column number, and the original syntax tree, locate the occurrence location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output a repair suggestion for the error.
本申请实施例提供一种脚本错误的处理装置,包括:An embodiment of the present application provides a script error processing device, including:
获取模块,用于获取可执行代码在运行过程中发生错误时的报错行列号;其中,所述可执行代码是由经过源映射处理的混淆源码生成的;The obtaining module is used to obtain the error row and column number when an error occurs in the execution process of the executable code; wherein, the executable code is generated by the obfuscated source code processed by source mapping;
所述获取模块,用于获取针对所述错误进行梯度诊断得到的错误类型;The obtaining module is used to obtain the error type obtained by performing gradient diagnosis on the error;
处理模块,用于基于所述混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,所述散列表存储有未混淆的源码的函数方法名与所述混淆源码的函数方法名的对应关系,以及所述未混淆的源码的参数名与所述混淆源码的参数名的对应关系;A processing module, configured to generate an original syntax tree based on the abstract syntax tree and the hash table converted from the obfuscated source code; wherein, the hash table stores the function method name of the unobfuscated source code and the function method name of the obfuscated source code Correspondence, and the corresponding relationship between the parameter name of the unobfuscated source code and the parameter name of the obfuscated source code;
所述处理模块,用于基于所述错误类型、所述报错行列号和所述原始语法树,在所述混淆源码对应的所述未混淆的源码中定位所述错误的发生位置,并输出针对所述错误的修复建议。The processing module is configured to locate the occurrence position of the error in the unobfuscated source code corresponding to the obfuscated source code based on the error type, the error row and column number, and the original syntax tree, and output the error for Suggested fixes for the errors described.
本申请实施例提供一种脚本错误的处理设备,包括:存储器,用于存储可执行指令;处理器,用于执行存储器中存储的可执行指令时,实现上述的方法。An embodiment of the present application provides a script error processing device, including: a memory, configured to store executable instructions; and a processor, configured to implement the above method when executing the executable instructions stored in the memory.
本申请实施例提供一种存储介质,存储有可执行指令,用于引起处理器执行时,实现上述的方法。An embodiment of the present application provides a storage medium, which stores executable instructions, and is used to cause a processor to implement the above method when executed.
本申请实施例具有以下有益效果:The embodiment of the present application has the following beneficial effects:
通过获取可执行代码在运行过程中发生错误时的报错行列号;其中,可执行代码是由经过源映射处理的混淆源码生成的;获取针对错误进行梯度诊断得到的错误类型;基于混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,散列表存储有未混淆的源码的函数方法名与混淆源码的函数方法名的对应关系,以及未混淆的源码的参数名与混淆源码的参数名的对应关系;基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置,并输出针对错误的修复建议;也就是说,结合梯度诊断和反编译给出解决方案,在每次获得到原始错误信息后,首先采用梯度诊断方法对原始错误进行精准诊断,然后根据梯度诊断出的最小粒度错误类型以及反编译结果得到精准修复建议,最后将精准诊断结果、精准修复建议通知给用户。By obtaining the error row and column number when an error occurs in the execution of the executable code; wherein, the executable code is generated by the obfuscated source code processed by the source map; the error type obtained by gradient diagnosis for the error is obtained; based on the obfuscated source code conversion, it is obtained The abstract syntax tree and hash table generate the original syntax tree; among them, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the parameter name of the unobfuscated source code and the parameter of the obfuscated source code Name correspondence; based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output a repair suggestion for the error; that is, combine gradient diagnosis and reverse Compile and give a solution. After obtaining the original error information each time, first use the gradient diagnosis method to accurately diagnose the original error, and then get accurate repair suggestions based on the smallest granularity error type and decompilation results detected by the gradient diagnosis. Finally, the accurate Diagnosis results and precise repair suggestions are notified to users.
附图说明Description of drawings
图1是相关技术中的脚本的处理流程示意图;FIG. 1 is a schematic diagram of a processing flow of a script in the related art;
图2是本申请实施例提供的服务器的一个可选的架构示意图;FIG. 2 is a schematic diagram of an optional architecture of a server provided by an embodiment of the present application;
图3是本申请实施例提供的脚本错误的处理方法的流程示意图一;FIG. 3 is a first schematic flow diagram of a script error processing method provided by an embodiment of the present application;
图4是本申请实施例提供的一个可实现的场景中的脚本的处理流程示意图;FIG. 4 is a schematic diagram of the processing flow of a script in an achievable scenario provided by an embodiment of the present application;
图5是本申请实施例提供的脚本错误的处理方法的流程示意图二;FIG. 5 is a second schematic flow diagram of a script error processing method provided by the embodiment of the present application;
图6是本申请实施例提供的梯度诊断结构的示意图;Fig. 6 is a schematic diagram of the gradient diagnosis structure provided by the embodiment of the present application;
图7是本申请实施例提供的脚本错误的处理方法的流程示意图三;FIG. 7 is a third schematic flow diagram of a script error processing method provided by an embodiment of the present application;
图8是本申请实施例提供的一个可实现的场景中的对错误进行精准定位的流程示意图一;Fig. 8 is a schematic diagram of a flow chart for accurately locating errors in an achievable scenario provided by the embodiment of the present application;
图9是本申请实施例提供的一个可实现的场景中的对错误进行精准定位的流程示意图二;FIG. 9 is a second schematic flow diagram of accurately locating errors in an achievable scenario provided by the embodiment of the present application;
图10是本申请实施例提供的针对错误输出的提示信息的示意图。FIG. 10 is a schematic diagram of prompt information for error output provided by the embodiment of the present application.
具体实施方式Detailed ways
为了使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请作进一步地详细描述,所描述的实施例不应视为对本申请的限制,本领域普 通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本申请保护的范围。In order to make the purpose, technical solutions and advantages of the application clearer, the application will be further described in detail below in conjunction with the accompanying drawings. All other embodiments obtained under the premise of creative labor belong to the scope of protection of this application.
在以下的描述中,涉及到“一些实施例”,其描述了所有可能实施例的子集,但是可以理解,“一些实施例”可以是所有可能实施例的相同子集或不同子集,并且可以在不冲突的情况下相互结合。除非另有定义,本申请实施例所使用的所有的技术和科学术语与属于本申请实施例的技术领域的技术人员通常理解的含义相同。本申请实施例所使用的术语只是为了描述本申请实施例的目的,不是旨在限制本申请。In the following description, references to "some embodiments" describe a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or a different subset of all possible embodiments, and Can be combined with each other without conflict. Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meaning as commonly understood by those skilled in the technical field of the embodiments of the present application. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application, and are not intended to limit the present application.
下面说明本申请实施例提供的脚本错误的处理设备的示例性应用,本申请实施例提供的脚本错误的处理设备可以实施为笔记本电脑,平板电脑,台式计算机,移动设备(例如,移动电话,便携式音乐播放器,个人数字助理,专用消息设备,便携式游戏设备),智能机器人等任意具有屏幕显示功能的终端,也可以实施为服务器。下面,将说明脚本错误的处理设备实施为服务器时的示例性应用。The following illustrates the exemplary application of the script error processing device provided by the embodiment of the present application. The script error processing device provided by the embodiment of the present application can be implemented as a notebook computer, a tablet computer, a desktop computer, a mobile device (for example, a mobile phone, a portable Music players, personal digital assistants, special message devices, portable game devices), intelligent robots and other terminals with screen display functions can also be implemented as servers. Next, an exemplary application when the script error processing device is implemented as a server will be described.
参见图2,图2是本申请实施例提供的服务器100的结构示意图,图2所示的服务器100包括:至少一个处理器110、至少一个网络接口120、用户接口130和存储器150。服务器100中的各个组件通过总线***140耦合在一起。可理解,总线***140用于实现这些组件之间的连接通信。总线***140除包括数据总线之外,还包括电源总线、控制总线和状态信号总线。但是为了清楚说明起见,在图2中将各种总线都标为总线***140。Referring to FIG. 2, FIG. 2 is a schematic structural diagram of a server 100 provided by an embodiment of the present application. The server 100 shown in FIG. Various components in the server 100 are coupled together through the bus system 140 . It can be understood that the bus system 140 is used to realize connection and communication between these components. In addition to the data bus, the bus system 140 also includes a power bus, a control bus and a status signal bus. However, for clarity of illustration, the various buses are labeled as bus system 140 in FIG. 2 .
处理器110可以是一种集成电路芯片,具有信号的处理能力,例如通用处理器、数字信号处理器(DSP,Digital Signal Processor),或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等,其中,通用处理器可以是微处理器或者任何常规的处理器等。Processor 110 can be a kind of integrated circuit chip, has signal processing capability, such as general-purpose processor, digital signal processor (DSP, Digital Signal Processor), or other programmable logic device, discrete gate or transistor logic device, discrete hardware Components, etc., wherein the general-purpose processor can be a microprocessor or any conventional processor, etc.
用户接口130包括使得能够呈现媒体内容的一个或多个输出装置131,包括一个或多个扬声器和/或一个或多个视觉显示屏。用户接口130还包括一个或多个输入装置132,包括有助于用户输入的用户接口部件,比如键盘、鼠标、麦克风、触屏显示屏、摄像头、其他输入按钮和控件。User interface 130 includes one or more output devices 131 that enable presentation of media content, including one or more speakers and/or one or more visual displays. The user interface 130 also includes one or more input devices 132, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
存储器150可以是可移除的,不可移除的或其组合。示例性地硬件设备包括固态存储器,硬盘驱动器,光盘驱动器等。存储器150可选地包括在物理位置上远离处理器110的一个或多个存储设备。存储器150包括易失性存储器或 非易失性存储器,也可包括易失性和非易失性存储器两者。非易失性存储器可以是只读存储器(Read Only Memory,ROM),易失性存储器可以是随机存取存储器(Random Access Memory,RAM)。本申请实施例描述的存储器150旨在包括任意适合类型的存储器。在一些实施例中,存储器150能够存储数据以支持各种操作,这些数据的示例包括程序、模块和数据结构或者其子集或超集,下面示例性说明。Memory 150 may be removable, non-removable or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, and the like. Memory 150 optionally includes one or more storage devices located physically remote from processor 110 . Memory 150 includes volatile memory or nonvolatile memory, and may include both volatile and nonvolatile memory. The non-volatile memory can be read-only memory (Read Only Memory, ROM), and the volatile memory can be random access memory (Random Access Memory, RAM). The memory 150 described in the embodiment of the present application is intended to include any suitable type of memory. In some embodiments, the memory 150 is capable of storing data to support various operations, examples of which include programs, modules, and data structures, or subsets or supersets thereof, as exemplified below.
操作***151,包括用于处理各种基本***服务和执行硬件相关任务的***程序,例如框架层、核心库层、驱动层等,用于实现各种基础业务以及处理基于硬件的任务;Operating system 151, including system programs for processing various basic system services and performing hardware-related tasks, such as framework layer, core library layer, driver layer, etc., for implementing various basic services and processing hardware-based tasks;
网络通信模块152,用于经由一个或多个(有线或无线)网络接口120到达其他计算设备,示例性地网络接口120包括:蓝牙、无线相容性认证(Wi-Fi)、和通用串行总线(Universal Serial Bus,USB)等;Network communication module 152 for reaching other computing devices via one or more (wired or wireless) network interfaces 120, exemplary network interfaces 120 include: Bluetooth, Wireless Compatibility Authentication (Wi-Fi), and Universal Serial Bus (Universal Serial Bus, USB), etc.;
输入处理模块153,用于对一个或多个来自一个或多个输入装置132之一的一个或多个用户输入或互动进行检测以及翻译所检测的输入或互动。The input processing module 153 is configured to detect one or more user inputs or interactions from one or more of the input devices 132 and translate the detected inputs or interactions.
在一些实施例中,本申请实施例提供的装置可以采用软件方式实现,图2示出了存储在存储器150中的一种脚本错误的处理装置154,该脚本错误的处理装置154可以是服务器100中的脚本错误的处理装置,其可以是程序和插件等形式的软件,包括以下软件模块:获取模块1541、处理模块1542,这些模块是逻辑上的,因此根据所实现的功能可以进行任意的组合或进一步拆分。将在下文中说明各个模块的功能。In some embodiments, the device provided by the embodiment of the present application can be realized by software. FIG. 2 shows a script error processing device 154 stored in the memory 150. The script error processing device 154 can be the server 100 The device for processing script errors in the script can be software in the form of programs and plug-ins, and includes the following software modules: an acquisition module 1541 and a processing module 1542. These modules are logical, so any combination can be made according to the functions implemented or split further. The function of each module will be explained below.
在另一些实施例中,本申请实施例提供的装置可以采用硬件方式实现,作为示例,本申请实施例提供的装置可以是采用硬件译码处理器形式的处理器,其被编程以执行本申请实施例提供的脚本错误的处理方法,例如,硬件译码处理器形式的处理器可以采用一个或多个应用专用集成电路(Application Specific Integrated Circuit,ASIC)、DSP、可编程逻辑器件(Programmable Logic Device,PLD)、复杂可编程逻辑器件(Complex Programmable Logic Device,CPLD)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或其他电子元件。In other embodiments, the device provided in the embodiment of the present application may be implemented in hardware. As an example, the device provided in the embodiment of the present application may be a processor in the form of a hardware decoding processor, which is programmed to execute the The script error processing method provided by the embodiment, for example, the processor in the form of hardware decoding processor can adopt one or more application-specific integrated circuits (Application Specific Integrated Circuit, ASIC), DSP, programmable logic device (Programmable Logic Device) , PLD), Complex Programmable Logic Device (Complex Programmable Logic Device, CPLD), Field Programmable Gate Array (Field-Programmable Gate Array, FPGA) or other electronic components.
下面将结合本申请实施例提供的服务器100的示例性应用和实施,说明本申请实施例提供的脚本错误的处理方法。参见图3,图3是本申请实施例提供的脚本错误的处理方法的一个可选的流程示意图,将结合图3示出的步骤进行 说明,The method for handling script errors provided by the embodiment of the present application will be described below in conjunction with the exemplary application and implementation of the server 100 provided in the embodiment of the present application. Referring to Fig. 3, Fig. 3 is an optional schematic flow chart of the script error processing method provided by the embodiment of the present application, which will be described in conjunction with the steps shown in Fig. 3,
步骤S201,获取可执行代码在运行过程中发生错误时的报错行列号。Step S201, obtaining the error line and column number when an error occurs during the execution of the executable code.
其中,可执行代码是由经过源映射(SourceMap)处理的混淆源码生成的。SourceMap是一种数据格式,它存储了源代码和生成代码之间的位置映射关系。Among them, the executable code is generated by the obfuscated source code processed by SourceMap. SourceMap is a data format that stores the location mapping relationship between source code and generated code.
本申请实施例中,脚本如JavaScript脚本在构建过程中使用模块打包器如webpack打包构建为压缩和混淆过的生产环境代码,源映射一般使用.map扩展名,此时会生成map文件,map文件中存储了压缩后的生产代码和原始代码的位置对应关系。下文将JavaScript脚本简称为JS脚本进行说明。In the embodiment of this application, scripts such as JavaScript scripts are packaged and built into compressed and obfuscated production environment codes during the construction process using a module packager such as webpack. The source map generally uses the .map extension. At this time, a map file will be generated, and the map file The location correspondence between the compressed production code and the original code is stored in . Hereinafter, JavaScript scripts will be referred to as JS scripts for description.
本申请实施例中,处理设备安装有监控分析平台,可以通过处理设备提供的插件(plugin)将打包过程中的map文件上传至监控分析平台,对每个map文件进行版本管理。监控分析平台通过对map文件解析,得到报错信息的报错行列号即原始行列号信息。In the embodiment of the present application, the processing device is equipped with a monitoring and analysis platform, and the map files in the packaging process can be uploaded to the monitoring and analysis platform through a plug-in provided by the processing device, and version management is performed on each map file. The monitoring and analysis platform analyzes the map file to obtain the error line number of the error message, that is, the original line number information.
在一个可实现的场景中,通过SourceMap反定位错误的报错行列号可以基于如下步骤实现:webpack打包输出map文件;使用plugin将map文件在不发布的情况下上传到监控分析平台;通过map文件解析错误信息,得到源码中具体的原始行列号。该场景中,可以采用版本管理规则对map文件进行管理。In an achievable scenario, using SourceMap to delocate the error row and column number can be realized based on the following steps: webpack packs and outputs the map file; uses the plugin to upload the map file to the monitoring and analysis platform without publishing it; parses the map file Error information, get the specific original row and column numbers in the source code. In this scenario, map files can be managed using version management rules.
本申请实施例提供的电子设备可以实施为笔记本电脑,平板电脑,台式计算机,移动设备(例如,移动电话,便携式音乐播放器,个人数字助理,专用消息设备,便携式游戏设备),智能机器人等任意具有屏幕显示功能的终端,也可以实施为服务器。本申请实施例中以电子设备实施为服务器为例进行说明。The electronic device provided by the embodiment of the present application can be implemented as any computer such as a notebook computer, a tablet computer, a desktop computer, a mobile device (for example, a mobile phone, a portable music player, a personal digital assistant, a dedicated messaging device, a portable game device), an intelligent robot, etc. A terminal with screen display function can also be implemented as a server. In the embodiment of the present application, an electronic device is implemented as a server as an example for description.
步骤S202,获取针对错误进行梯度诊断得到的错误类型。Step S202, acquiring the error type obtained by performing gradient diagnosis on the error.
本申请实施例中,通过梯度诊断可以得到最小粒度错误类型。梯度诊断指的是多级分析诊断,其中,第n层级分析诊断依赖第m层级分析诊断的结果,n和m为正整数,且n大于m,层级之间是递进关系,到梯度诊断的最终层级的时候基本定位到了最具体、最准确的错误原因。In the embodiment of the present application, the smallest granularity error type can be obtained through gradient diagnosis. Gradient diagnosis refers to multi-level analysis and diagnosis, in which, the analysis and diagnosis of the nth level depends on the results of the analysis and diagnosis of the mth level, n and m are positive integers, and n is greater than m, and there is a progressive relationship between levels, until the gradient diagnosis At the final level, the most specific and accurate cause of the error was basically located.
步骤S203,基于混淆源码转换得到的抽象语法树和散列表生成原始语法树。In step S203, an original syntax tree is generated based on the abstract syntax tree and the hash table converted from the obfuscated source code.
其中,散列表(HashMap)存储有未混淆的源码的函数方法名与混淆源码的函数方法名的对应关系,以及未混淆的源码的参数名与混淆源码的参数名的对应关系。Wherein, the hash table (HashMap) stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the corresponding relationship between the parameter name of the unobfuscated source code and the parameter name of the obfuscated source code.
这里,可以通过代码解析器如esprima转换混淆源码得到抽象语法树;进而基于抽象语法树和HashMap生成原始语法树。Here, the abstract syntax tree can be obtained by converting the obfuscated source code through a code parser such as esprima; then the original syntax tree can be generated based on the abstract syntax tree and HashMap.
步骤S204,基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置,并输出针对错误的修复建议。Step S204, based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output a repair suggestion for the error.
本申请实施例中,由于JS脚本在生产环境部署时,都是压缩和混淆过的代码。经过梯度诊断的多级错误诊断后,并不能精确给出错误的报错位置和上下文联系,所以,还需要通过反定位和反编译阶段进行精确定位。得到原始行列号信息即发生错误时的报错行列号后,由于代码是经过混淆的,此时并不能得出有效信息帮助快速定位问题和给出修复建议。所以还需要通过反编译手段获取未经混淆的信息,来定位源码。对此,本申请基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置。In the embodiment of this application, when the JS script is deployed in the production environment, it is compressed and obfuscated code. After the multi-level error diagnosis of gradient diagnosis, the error location and context of the error cannot be accurately given. Therefore, it is necessary to accurately locate through the delocation and decompilation stages. After obtaining the original row and column number information, that is, the error row and column number when an error occurs, because the code is obfuscated, no effective information can be obtained at this time to help quickly locate the problem and give repair suggestions. Therefore, it is also necessary to obtain unobfuscated information through decompilation to locate the source code. In this regard, this application locates the location of the error in the unobfuscated source code corresponding to the obfuscated source code based on the error type, error row and column number, and the original syntax tree.
在一个可实现的场景中,结合图4所示,本申请提供的脚本错误的处理方法可以通过如下步骤实现:首先,通过事件处理函数采集错误。In an achievable scenario, as shown in FIG. 4 , the method for handling script errors provided by the present application can be implemented through the following steps: First, errors are collected through an event processing function.
其次,对原始错误进行梯度诊断,得到多级错误诊断得到的最小粒度的精准错误信息。这里,精准错误信息称为准诊断结果。Secondly, the gradient diagnosis is performed on the original error, and the precise error information of the smallest granularity obtained by the multi-level error diagnosis is obtained. Here, precise error information is called a quasi-diagnostic result.
然后,通过SourceMap进行源码反定位,即定位发生错误时的报错行列号在真实源码中的位置。Then, use SourceMap to perform source code delocation, that is, to locate the position of the error row and column number in the real source code when an error occurs.
接着,通过反编译解析源码上下文逻辑和调用关系,得到反编译结果。Then, analyze the source code context logic and calling relationship through decompilation, and obtain the decompilation result.
再次,结合三级错误类型、修复建议配置表以及反编译结果,得到精准修复建议。Thirdly, combined with the three-level error type, repair suggestion configuration table, and decompilation results, accurate repair suggestions are obtained.
最后,将精准诊断结果和精准修复建议通知用户。Finally, the user is notified of the accurate diagnosis results and accurate repair suggestions.
本申请实施例提供的脚本错误的处理方法,通过获取可执行代码在运行过程中发生错误时的报错行列号;其中,可执行代码是由经过源映射处理的混淆源码生成的;获取针对错误进行梯度诊断得到的错误类型;基于混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,散列表存储有未混淆的源码的函数方法名与混淆源码的函数方法名的对应关系,以及未混淆的源码的参数名与混淆源码的参数名的对应关系;基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置,并输出针对错误的修复建议;也就是说,结合梯度诊断和反编译给出解决方案,在每次获得到原始错误信息后,首先采用梯度诊断方法对原始错误进行精准诊断,然后根据梯度诊断出的最小粒度错误类型以及反编译结果得到精准修复建议,最后将精准诊断结果、精准修复建议通知给用户。The script error processing method provided by the embodiment of the present application obtains the row and column number of the error report when an error occurs in the running process of the executable code; wherein, the executable code is generated by the obfuscated source code processed by source mapping; The error type obtained by the gradient diagnosis; the original syntax tree is generated based on the abstract syntax tree and the hash table converted from the obfuscated source code; wherein, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and The corresponding relationship between the parameter names of the unobfuscated source code and the parameter names of the obfuscated source code; based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output the error-specific Repair suggestions; that is to say, a solution is given by combining gradient diagnosis and decompilation. After obtaining the original error information each time, first use the gradient diagnosis method to accurately diagnose the original error, and then diagnose the smallest granular error type according to the gradient And the decompilation results get accurate repair suggestions, and finally the accurate diagnosis results and accurate repair suggestions are notified to the user.
本申请其他实施例中,梯度诊断可以是三级分析诊断,其中,第n层级分 析诊断依赖第m层级分析诊断的结果,n和m为正整数,且n大于m。也就是说,本申请针对脚本的错误,依次进行一级、二级、三级错误类型诊断,层级之间是递进关系,到三级错误类型的时候基本定位到了最具体、最准确的错误原因,开发者能直接着手修复错误了。关于步骤S202获取针对错误进行梯度诊断得到的错误类型,可以通过如图5所示的步骤实现:In other embodiments of the present application, the gradient diagnosis may be a three-level analysis and diagnosis, wherein the analysis and diagnosis at the nth level depends on the results of the analysis and diagnosis at the mth level, n and m are positive integers, and n is greater than m. That is to say, this application diagnoses the error types of the script at the first, second, and third levels in sequence. There is a progressive relationship between the levels. When the error type of the third level is basically located, the most specific and accurate error Because of this, developers can go straight to fixing bugs. Regarding the step S202 to obtain the error type obtained by performing gradient diagnosis on the error, it can be realized through the steps shown in Figure 5:
步骤S2021,对错误对应的事件处理函数的函数类型进行分析,将符合预设类型的事件处理函数采集/上报的错误归类为一级错误。Step S2021, analyzing the function type of the event processing function corresponding to the error, and classifying the error collected/reported by the event processing function conforming to the preset type as a first-level error.
本申请实施例中,一级错误可以理解为常规的前端错误归类,包括脚本错误如JS脚本错误、资源加载错误、接口请求错误三个维度。本申请以JS脚本错误为例,对梯度诊断所涉及的三个层级进行说明,对于一级错误的诊断,通常在采集/上报错误环节区分出来。In the embodiment of this application, the first-level error can be understood as a conventional front-end error classification, including three dimensions of script errors such as JS script errors, resource loading errors, and interface request errors. This application takes JS script errors as an example to illustrate the three levels involved in gradient diagnosis. For the diagnosis of first-level errors, it is usually distinguished in the link of collecting/reporting errors.
示例性的,通过以下事件处理函数采集的错误,可归类为一级错误的"JS脚本错误"。事件处理函数包括:(1)window.onerror:当有JS运行时错误如同步、异步触发时,window会触发error事件并执行window.onerror,window不能阻止默认事件处理函数的执行;Exemplarily, the errors collected through the following event processing functions can be classified as "JS script errors" of the first-level errors. Event processing functions include: (1) window.onerror: When there is a JS runtime error such as synchronous or asynchronous triggering, window will trigger the error event and execute window.onerror, and window cannot prevent the execution of the default event processing function;
(2)addEventListener('error'):与window.onerror功能大体类似。error参数保存了所有错误信息,且不能阻止默认事件处理函数的执行;(2) addEventListener('error'): roughly similar to the function of window.onerror. The error parameter saves all error information and cannot prevent the execution of the default event handler;
(3)try...catch...:将代码块进行try-catch包装,当代码块出错时catch捕捉错误信息上报;(3) try...catch...: wrap the code block with try-catch, and when the code block makes an error, the catch captures the error message and reports it;
(4)addEventListener('unhandledrejection'):当promise被reject抛出异常且没有catch捕获时,用addEventListener('unhandledrejection')来捕获处理;(4) addEventListener('unhandledrejection'): When the promise is rejected and an exception is thrown without catch, use addEventListener('unhandledrejection') to capture and process;
(5)console.error:一些特殊情况下,需要捕获处理console.error。实现方式就是重写window.console.error上报错误信息。(5) console.error: In some special cases, console.error needs to be captured and processed. The implementation method is to rewrite window.console.error to report error information.
步骤S2022,对一级错误进行关键字正则匹配,并将一级错误归类至五种二级错误中对应的一种。Step S2022, perform regular keyword matching on the first-level errors, and classify the first-level errors into one of the five second-level errors.
本申请实施例中,二级错误可以理解为针对一级错误中的JS脚本错误进行二级错误分类。示例性的,分为语法错误(SyntaxError)、类型错误(TypeError)、引用错误(ReferenceError)、范围错误(RangeError)、URIError五种类型。其中,SyntaxError指的是解析时发生语法错误。一般SyntaxError在构建阶段,甚至本地开发阶段就会被发现。诊断可不考虑该类型。TypeError指的是 类型错误。值不是所期待的类型。ReferenceError指的是引用类型错误,引用不存在的变量时会报此错。RangeError指的是范围错误。当设置的数值超出相应的范围会报这个错。URIError指的是URL错误,用来表示以一种错误的方式使用全局统一资源定位符(Uniform Resource Locator,URL)处理函数而产生的错误。相关函数的参数不正确时抛出的错误,主要涉及encodeURI、decodeURI、encodeURIComponent、decodeURIComponent、escape、unescape六个函数。In the embodiment of the present application, the second-level error can be understood as classifying the second-level error for the JS script error in the first-level error. Exemplarily, it is divided into five types: syntax error (SyntaxError), type error (TypeError), reference error (ReferenceError), range error (RangeError), and URIError. Among them, SyntaxError refers to a syntax error during parsing. Generally, SyntaxError will be found during the construction phase, or even the local development phase. The diagnosis may be made regardless of the type. TypeError refers to type error. Value is not of the expected type. ReferenceError refers to a reference type error, which will be reported when a variable that does not exist is referenced. RangeError refers to a range error. This error will be reported when the set value exceeds the corresponding range. URIError refers to a URL error, which is used to indicate an error caused by using a global Uniform Resource Locator (Uniform Resource Locator, URL) handler in a wrong way. Errors thrown when the parameters of related functions are incorrect, mainly involving six functions: encodeURI, decodeURI, encodeURIComponent, decodeURIComponent, escape, and unescape.
本申请实施例中,通过一级错误归类之后,JS脚本错误信息进入二级错误诊断。针对二级错误包含的上述五种类型,在原始错误信息里面通过关键字正则可实现归类。In the embodiment of the present application, after the first-level error classification, the JS script error information enters the second-level error diagnosis. For the above five types of secondary errors, classification can be achieved through keyword regularization in the original error message.
步骤S2023,针对归类后的每一二级错误调用三级错误配置表,并查找三级错误配置表中与归类后的每一二级错误匹配的三级错误规则。Step S2023, calling the third-level error configuration table for each classified second-level error, and searching for the third-level error rule matching each classified second-level error in the third-level error configuration table.
三级错误可以理解为针对二级错误中的五种类型,每一类都包含p条三级错误类型,p为正整数。三级错误类型直接与JS脚本具体错误信息相映射。The third-level errors can be understood as targeting the five types of the second-level errors, each category contains p third-level error types, and p is a positive integer. The three-level error type is directly mapped to the specific error information of the JS script.
本申请实施例中,二级错误类型归类后,会进行三级错误类型解析。针对每个二级错误类型,维护一个对应的三级错误配置表,该配置表存储着这个二级错误类型下,归类后所有可枚举的三级错误规则和具体错误信息,支持持续扩展。In the embodiment of the present application, after the second-level error type is classified, the third-level error type analysis will be performed. For each second-level error type, maintain a corresponding third-level error configuration table, which stores all enumerable third-level error rules and specific error information after classification under this second-level error type, and supports continuous expansion .
本申请实施例中,生成三级错误配置表可以通过如下方式实现:根据现有监控平台的大量原始JS脚本错误信息,首先依次按照JS关键字、关键关联语、关键句归类错误,然后将归类后的一类错误整合概括为一条规则的通用三级错误规则。该条通用规则代表一类错误,映射一种常见的具体错误信息。以二级错误类型TypeError为例,其三级错误配置表如下:In the embodiment of the present application, generating the three-level error configuration table can be realized in the following manner: according to a large amount of original JS script error information of the existing monitoring platform, first classify errors according to JS keywords, key related words, and key sentences successively, and then After classification, the integration of one type of errors is generalized as a rule of general three-level error rules. This general rule represents a class of errors, mapping a common specific error message. Taking the second-level error type TypeError as an example, its third-level error configuration table is as follows:
Figure PCTCN2022119025-appb-000001
Figure PCTCN2022119025-appb-000001
TypeError对应的三级错误配置表Three-level error configuration table corresponding to TypeError
步骤S2024,在三级错误配置表中确定与三级错误规则具有映射关系的错误类型。Step S2024, determining the error types that have a mapping relationship with the third-level error rules in the three-level error configuration table.
示例性的,在一些场景中,梯度诊断为三级错误类型诊断时,参见图6所示三级诊断的结构图,一级错误类型诊断阶段:将错误信息采集阶段采集的错误进行一级诊断,对错误对应的事件处理函数的函数类型进行分析,将符合预设类型的事件处理函数采集/上报的错误归类为一级错误。例如,将window.onerror、addEventListener、try...catch...以及console.error事件处理函数采集的错误归类为一级错误。二级错误类型诊断阶段,采用正则匹配二级错误关键字的方式,将一级错误归类至五种二级错误如TypeError、ReferenceError、RangeError、URIError中对应的一种。三级错误类型诊断阶段,调用三级错误配置表,并查找三级错误配置表中与归类后的每一二级错误匹配的三级错误规则。Exemplarily, in some scenarios, when the gradient diagnosis is a three-level error type diagnosis, refer to the structure diagram of the three-level diagnosis shown in FIG. , analyze the function type of the event processing function corresponding to the error, and classify the error collected/reported by the event processing function conforming to the preset type as a first-level error. For example, errors collected by window.onerror, addEventListener, try...catch..., and console.error event processing functions are classified as first-level errors. In the second-level error type diagnosis stage, the first-level error is classified into one of five second-level errors such as TypeError, ReferenceError, RangeError, and URIError by matching regular expressions with the second-level error keywords. In the third-level error type diagnosis stage, the third-level error configuration table is invoked, and a third-level error rule matching each classified second-level error in the third-level error configuration table is found.
本申请其他实施例中,步骤S203基于混淆源码转换得到的抽象语法树和散列表生成原始语法树,可以通过如图7所示的步骤实现:In other embodiments of the present application, step S203 generates an original syntax tree based on the abstract syntax tree and hash table converted from the obfuscated source code, which can be implemented through the steps shown in Figure 7:
步骤S2031,循环遍历语法树及散列表,将抽象语法树中的一个表达式节点中对象的对象名与散列表中的键进行比对。Step S2031, loop through the syntax tree and the hash table, and compare the object name of the object in an expression node in the abstract syntax tree with the key in the hash table.
步骤S2032,若对象名与散列表中的一个键相同,则将一个表达式节点中的对象名重置为散列表中对应于一个键的值,在一个表达式节点中将计算属性的标识参数由第一参数改为第二参数。Step S2032, if the object name is the same as a key in the hash table, reset the object name in an expression node to the value corresponding to a key in the hash table, and calculate the identification parameter of the property in an expression node Changed from the first parameter to the second parameter.
这里,计算属性(Computed)相关的第一参数可以是true,第二参数可以是false。Here, the first parameter related to the computed property (Computed) may be true, and the second parameter may be false.
步骤S2033,若对象名与一个键不同,将对象名与散列表中的另一个键进行比对,直至所有表达式节点中的计算属性的标识参数由第一参数改为第二参数,得到原始语法树。Step S2033, if the object name is different from a key, compare the object name with another key in the hash table until the identification parameters of the calculated attributes in all expression nodes are changed from the first parameter to the second parameter, and the original syntax tree.
本申请其他实施例中,若错误类型属于引用类型错误或者类型错误,步骤S204中基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置,可以通过如下步骤实现:In other embodiments of the present application, if the error type belongs to a reference type error or a type error, in step S204, based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, which can be It is achieved through the following steps:
首先,若错误类型属于引用类型错误或者类型错误,则将原始语法树转为未混淆的源码;其次,基于报错行列号在未混淆的源码中定位错误的发生位置。First, if the error type is a reference type error or a type error, convert the original syntax tree into unobfuscated source code; secondly, locate the location of the error in the unobfuscated source code based on the error row and column number.
在一个可实现的场景中,若错误类型属于引用类型错误或者类型错误,参见图8所示,经过SourceMap处理的代码我们称之为‘混淆源码’;当错误类 型命中‘类型错误’和‘引用类型错误’时,解析错误需要获取到源码中未混淆的方法名和参数名的流程如下:In an achievable scenario, if the error type is a reference type error or a type error, as shown in Figure 8, the code processed by SourceMap is called "obfuscated source code"; when the error type hits "type error" and "reference Type error', the process for parsing errors and obtaining unobfuscated method names and parameter names in the source code is as follows:
步骤S401,缓存‘混淆源码’中的报错行列号信息。Step S401, caching the error row and column number information in the 'obfuscated source code'.
步骤S402,esprima转换‘混淆源码’为语法树。Step S402, esprima converts the 'obfuscated source code' into a syntax tree.
步骤S403,获取map中的HashMap。Step S403, acquiring the HashMap in the map.
其中,HashMap在代码通过webpack构建阶段生成,由软件开发工具包(Software Development Kit,Sdk)上报;HashMap存储了混淆阶段的源码函数方法名及参数名与混淆后的函数方法名及参数名的对应关系。Among them, HashMap is generated in the code through the webpack construction phase and reported by the Software Development Kit (Sdk); HashMap stores the correspondence between the source code function method name and parameter name in the obfuscation phase and the obfuscated function method name and parameter name relation.
步骤S404,循环遍历语法树及HashMap,将MemberExpression节点中object的name对比HashMap中的key,命中则将MemberExpression节点中object的name重置为HashMap中对应key的value,MemberExpression节点中将Computed由true改为false。Step S404, loop through the syntax tree and HashMap, compare the name of the object in the MemberExpression node with the key in the HashMap, and if it hits, reset the name of the object in the MemberExpression node to the value of the corresponding key in the HashMap, and change Computed from true to is false.
步骤S405,如果未命中则继续遍历,直到所有Computed置为false。Step S405, if there is no hit, continue traversing until all Computed are set to false.
步骤S406,得到原始语法树。Step S406, obtaining the original syntax tree.
步骤S407,将原始语法树缓存到sourceAST对象中。Step S407, cache the original syntax tree into the sourceAST object.
步骤S408,esprima转换原始语法树为‘真实源码’,将‘真实源码’使用fs.writeFile写成文件缓存在服务器中。Step S408, esprima converts the original syntax tree into "true source code", writes the "real source code" into a file using fs.writeFile and caches it in the server.
最终,根据‘混淆源码’中报错行列号信息定位到‘真实源码’中,给出修复建议。Finally, according to the error row and column number information in the "obfuscated source code", locate the "true source code" and give repair suggestions.
本申请其他实施例中,若错误类型属于范围错误,步骤S204中基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置,可以通过如下步骤实现:In other embodiments of the present application, if the error type belongs to a range error, in step S204, based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, which can be realized by the following steps :
首先,若错误类型属于范围错误,则获取软件开发工具包基于报错行列号捕获的错误的发生位置的调用栈信息;其次,基于调用栈信息和原始语法树,得到原始调用栈;其中,原始调用栈为缓存有未混淆的源码中定位的错误的发生位置的数组。Firstly, if the error type belongs to the range error, then obtain the call stack information of the location of the error captured by the software development kit based on the error row and column number; secondly, obtain the original call stack based on the call stack information and the original syntax tree; where, the original call The stack is an array that caches the location of errors located in the unobfuscated source code.
进一步地,在错误类型属于范围错误的情况下,基于调用栈信息和原始语法树,得到原始调用栈可以通过如下步骤实现:Furthermore, when the error type belongs to a range error, based on the call stack information and the original syntax tree, the original call stack can be obtained through the following steps:
第一步,将调用栈信息转换为第一数组stackArr,并删除第一数组stackArr的第一项;The first step is to convert the call stack information into the first array stackArr, and delete the first item of the first array stackArr;
第二步,遍历第一数组stackArr并正则匹配每一项内容,取出调用栈中的 满足匹配条件的调用函数名,得到第二数组stackFnArr;The second step is to traverse the first array stackArr and regularly match each item, take out the calling function names in the call stack that meet the matching conditions, and obtain the second array stackFnArr;
第三步,遍历原始语法树将一个表达式节点的对象的对象名与第二数组stackFnArr中的每一项进行循环比对;The third step is to traverse the original syntax tree and compare the object name of an expression node object with each item in the second array stackFnArr;
第四步,若对象名与第二数组stackFnArr中的一项相同,则将一个表达式节点缓存;In the fourth step, if the object name is the same as an item in the second array stackFnArr, an expression node is cached;
第五步,将循环比对找到的所有表达式节点缓存为第三数组stackMEArr;其中,所有表达式节点的对象名与第二数组stackFnArr中的一项相同;The fifth step is to cache all the expression nodes found by the loop comparison as the third array stackMEArr; wherein, the object names of all expression nodes are the same as an item in the second array stackFnArr;
第六步,循环遍历散列表与第三数组stackMEArr,将第三数组stackMEArr中表达式节点中对象的对象名替换为散列表中匹配到键对应的值,得到原始调用栈;其中,原始调用栈为缓存有替换后的表达式节点的数组。The sixth step is to loop through the hash table and the third array stackMEArr, replace the object name of the object in the expression node in the third array stackMEArr with the value corresponding to the key in the hash table, and obtain the original call stack; among them, the original call stack An array of cached expression nodes.
在一个可实现的场景中,若错误类型属于范围错误,参见图9所示,当错误命中‘范围错误’时,简单的给出行列号和原始的方法名并不能提供帮助,此时需要解析代码中的上下文逻辑,流程如下:In an achievable scenario, if the error type belongs to a range error, as shown in Figure 9, when the error hits 'range error', simply giving the row and column numbers and the original method name cannot provide help, and it needs to be parsed at this time The context logic in the code, the flow is as follows:
步骤S501,与‘类型错误’和‘引用类型错误’的步骤S401至步骤S406步的执行发流程相同,得到原始语法树。Step S501 is the same as the execution flow from step S401 to step S406 of 'type error' and 'reference type error' to obtain the original syntax tree.
步骤S502,缓存到SourceAST对象。Step S502, cache to SourceAST object.
这里,通过Sdk获取错误信息中的stack调用栈信息。stack是字符串,需要转换为object;将stack字符串通过str.split('/n')转换为数组stackArr,并删除数组第一项。Here, the stack call stack information in the error message is obtained through Sdk. stack is a string and needs to be converted to an object; convert the stack string to an array stackArr through str.split('/n'), and delete the first item of the array.
步骤S503,遍历stackArr并正则匹配每一项内容,取出调用栈中调用函数名,缓存为数组stackFnArr。Step S503, iterating through stackArr and matching each item, taking out the name of the calling function in the call stack, and caching it as an array stackFnArr.
此时取出的调用函数名都是混淆后的,需要转换为真实函数名。At this time, the calling function names taken out are all obfuscated and need to be converted into real function names.
步骤S504,遍历原始语法树将MemberExpression节点中object的name循环对比stackFnArr中的每一项,命中后将此MemberExpression节点缓存。Step S504, traversing the original syntax tree, comparing the name of the object in the MemberExpression node with each item in stackFnArr, and caching the MemberExpression node after being hit.
步骤S505,将找到的MemberExpression节点缓存为数组stackMEArr。Step S505, cache the found MemberExpression nodes as an array stackMEArr.
步骤S506,循环遍历HashMap与stackMEArr,将stackMEArr数组中MemberExpression节点的name替换为HashMap中匹配到key的value值。Step S506, loop through the HashMap and stackMEArr, and replace the name of the MemberExpression node in the stackMEArr array with the value matching the key in the HashMap.
这里,通过HashMap可以做到只反混淆调用栈中的信息,而不需要还原整个代码文件。Here, only the information in the call stack can be deobfuscated through HashMap, without restoring the entire code file.
步骤S507,将新得到的MemberExpression节点缓存为数组,称为“原始调用栈”。按照“原始调用栈”的顺序给出提示和修复建议。Step S507, cache the newly obtained MemberExpression node as an array, which is called "original call stack". Hints and fix suggestions are given in order of "raw call stack".
由上述内容可知,本申请实施例中,通过SourceMap技术和自研的反编译技术,通过结合HashMap实现了高效的错误精准定位和快速反编译获取错误原始信息的能力。It can be seen from the above that in the embodiment of this application, the SourceMap technology and the self-developed decompilation technology are combined with the HashMap to achieve efficient accurate error location and the ability to quickly decompile to obtain the original error information.
本申请其他实施例中,步骤S204中输出针对所述错误的修复建议,可以通过如下步骤实现:In other embodiments of the present application, the output of the repair suggestion for the error in step S204 can be achieved through the following steps:
在修复建议配置表中查找与三级错误规则匹配的修复建议,并输出修复建议。本申请实施例中,通过三级错误配置表,给出精准有价值的错误修复建议,提高开发者定位和修复生产代码错误的效率。Find the repair suggestion matching the three-level error rule in the repair suggestion configuration table, and output the repair suggestion. In the embodiment of this application, accurate and valuable error repair suggestions are given through the three-level error configuration table, which improves the efficiency of developers in locating and repairing production code errors.
JS脚本错误信息通过梯度诊断、反定位、反编译之后,我们已经可以知道精准错误信息和精准定位信息,然后结合修复建议配置表可以给出告警修复和预警修复两种。其中修复建议配置表就是基于梯度诊断三级错误类型的三级错误配置表得来的,每一条三级错误规则都对应一个修复建议。After the JS script error information has passed gradient diagnosis, anti-location, and decompilation, we can already know the precise error information and precise location information, and then combined with the repair suggestion configuration table, two types of alarm repair and early warning repair can be given. The repair suggestion configuration table is obtained based on the three-level error configuration table of the gradient diagnosis of the three-level error type, and each third-level error rule corresponds to a repair suggestion.
Figure PCTCN2022119025-appb-000002
Figure PCTCN2022119025-appb-000002
三级错误配置表Level 3 Misconfiguration Table
在错误信息拿到修复建议配置表的具体修复建议之后,我们可以通过现在的短信、邮件、微信等渠道给开发者用户综合的错误信息及修复建议通知。After the error information has received the specific repair suggestions from the repair suggestion configuration table, we can notify developers and users of the comprehensive error information and repair suggestions through the current SMS, email, WeChat and other channels.
对修复建议的进一步使用:预警修复。预警修复的本质是预设可能出现错误的条件,当触发该条件时错误并没有真实发生。通过预警可以赶在错误发生之前对用户行为进行检查和修复,避免错误。如何实现预警修复?一个统计聚类的过程。将历史中发生错误的情况进行统计,从时间、地域、用户等不同维度加以统计,找出规律,并将这些规律通过算法预测器自动加入到预警条件中,当下次触发时,结合"梯度诊断"、"精准定位"、"修复建议"流程及时预警。A further use of remediation suggestions: Early warning remediation. The essence of early warning repair is to presuppose the condition that an error may occur, and when the condition is triggered, the error does not actually occur. Through the early warning, the user behavior can be checked and repaired before the error occurs, so as to avoid the error. How to achieve early warning repair? A statistical clustering process. Make statistics on the errors that occurred in history, make statistics from different dimensions such as time, region, and user, find out the rules, and automatically add these rules to the early warning conditions through the algorithm predictor. When it is triggered next time, combined with "gradient diagnosis" ", "Precise Positioning", and "Repair Suggestion" processes provide timely warnings.
由上述内容可知,本申请实施例提供的脚本错误的处理方法,对原始错误信息经过梯度诊断、反定位反编译、修复建议之后,能获得精准的错误定位和 精准的修复建议。通知给用户的提示信息包含的主要信息参见图10,主要信息包括但不限于原始错误、二级错误、三级错误、源码定位、修复意见以及额外信息。用户拿到这些信息之后可以直接定位问题、根据建议修复问题,大大缩短bug的影响面和保证前端***可用性更优。预警修复实现之后更是可以提前暴露问题、规避问题,对***持续稳定性提供强保障。It can be seen from the above that the script error processing method provided by the embodiment of the present application can obtain accurate error location and accurate repair suggestions after gradient diagnosis, delocation and decompilation, and repair suggestions for the original error information. See Figure 10 for the main information contained in the prompt information notified to the user. The main information includes but is not limited to the original error, the second-level error, the third-level error, source code location, repair suggestions, and additional information. After getting the information, the user can directly locate the problem and fix the problem according to the suggestion, which greatly shortens the impact area of the bug and ensures better availability of the front-end system. After the early warning repair is implemented, problems can be exposed and avoided in advance, providing a strong guarantee for the continuous stability of the system.
下面继续说明本申请实施例提供的脚本错误的处理装置154实施为软件模块的示例性结构,在一些实施例中,如图2所示,存储在存储器150的脚本错误的处理装置154中的软件模块可以是服务器100中的脚本错误的处理装置,包括:Continue to illustrate the exemplary structure that the script error processing device 154 provided by the embodiment of the present application is implemented as a software module. In some embodiments, as shown in FIG. 2 , the software stored in the script error processing device 154 of the memory 150 A module may be a script error handling device in the server 100, including:
获取模块1541,用于获取可执行代码在运行过程中发生错误时的报错行列号;其中,可执行代码是由经过源映射处理的混淆源码生成的;The obtaining module 1541 is used to obtain the error line and column number when an error occurs during the execution of the executable code; wherein, the executable code is generated by the obfuscated source code processed by source mapping;
获取模块1541,用于获取针对错误进行梯度诊断得到的错误类型;An acquisition module 1541, configured to acquire the error type obtained by performing gradient diagnosis on the error;
处理模块1542,用于基于混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,散列表存储有未混淆的源码的函数方法名与混淆源码的函数方法名的对应关系,以及未混淆的源码的参数名与混淆源码的参数名的对应关系;The processing module 1542 is used to generate the original syntax tree based on the abstract syntax tree and the hash table converted from the obfuscated source code; wherein, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the unobfuscated source code. The corresponding relationship between the parameter name of the obfuscated source code and the parameter name of the obfuscated source code;
处理模块1542,用于基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置,并输出针对错误的修复建议。The processing module 1542 is configured to locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code based on the error type, error row and column number, and the original syntax tree, and output a repair suggestion for the error.
本申请其他实施例中,处理模块1542,用于循环遍历语法树及散列表,将抽象语法树中的一个表达式节点中对象的对象名与散列表中的键进行比对;若对象名与散列表中的一个键相同,则将一个表达式节点中的对象名重置为散列表中对应于一个键的值,在一个表达式节点中将计算属性的标识参数由第一参数改为第二参数;若对象名与一个键不同,将对象名与散列表中的另一个键进行比对,直至所有表达式节点中的计算属性的标识参数由第一参数改为第二参数,得到原始语法树。In other embodiments of the present application, the processing module 1542 is used to loop through the syntax tree and the hash table, and compare the object name of the object in an expression node in the abstract syntax tree with the key in the hash table; If a key in the hash table is the same, the object name in an expression node is reset to the value corresponding to a key in the hash table, and in an expression node, the identification parameter of the calculated attribute is changed from the first parameter to the second Two parameters; if the object name is different from a key, compare the object name with another key in the hash table until the identification parameters of the computed properties in all expression nodes are changed from the first parameter to the second parameter, and the original syntax tree.
本申请其他实施例中,处理模块1542,用于若错误类型属于引用类型错误或者类型错误,则将原始语法树转为未混淆的源码;基于报错行列号在未混淆的源码中定位错误的发生位置。In other embodiments of the present application, the processing module 1542 is used to convert the original syntax tree into unobfuscated source code if the error type belongs to the reference type error or type error; locate the occurrence of the error in the unobfuscated source code based on the row and column number of the error report Location.
本申请其他实施例中,处理模块1542,用于若错误类型属于范围错误,则获取软件开发工具包基于报错行列号捕获的错误的发生位置的调用栈信息;基于调用栈信息和原始语法树,得到原始调用栈;其中,原始调用栈为缓存有未 混淆的源码中定位的错误的发生位置的数组。In other embodiments of the present application, the processing module 1542 is used to obtain the call stack information of the location of the error captured by the software development kit based on the error row and column number if the error type belongs to the range error; based on the call stack information and the original syntax tree, The original call stack is obtained; wherein, the original call stack is an array of locations where errors located in the unobfuscated source code are cached.
本申请其他实施例中,处理模块1542,用于将调用栈信息转换为第一数组,并删除第一数组的第一项;遍历第一数组并正则匹配每一项内容,取出调用栈中的满足匹配条件的调用函数名,得到第二数组;遍历原始语法树将一个表达式节点的对象的对象名与第二数组中的每一项进行循环比对;若对象名与第二数组中的一项相同,则将一个表达式节点缓存;将循环比对找到的所有表达式节点缓存为第三数组;其中,所有表达式节点的对象名与第二数组中的一项相同;循环遍历散列表与第三数组,将第三数组中表达式节点中对象的对象名替换为散列表中匹配到键对应的值,得到原始调用栈;其中,原始调用栈为缓存有替换后的表达式节点的数组。In other embodiments of the present application, the processing module 1542 is used to convert the call stack information into the first array, and delete the first item of the first array; traverse the first array and match each item content regularly, and take out the call stack information Call the function name that meets the matching conditions to get the second array; traverse the original syntax tree to compare the object name of an expression node object with each item in the second array; if the object name is the same as the second array If one item is the same, an expression node is cached; all expression nodes found by the loop comparison are cached as the third array; wherein, the object names of all expression nodes are the same as one item in the second array; looping through the array list and the third array, replace the object name of the object in the expression node in the third array with the value corresponding to the key in the hash table, and get the original call stack; where the original call stack is the cached expression node with replacement array of .
本申请其他实施例中,处理模块1542,用于对错误对应的事件处理函数的函数类型进行分析,将符合预设类型的事件处理函数采集/上报的错误归类为一级错误;对一级错误进行关键字正则匹配,并将一级错误归类至五种二级错误中对应的一种;针对归类后的每一二级错误调用三级错误配置表,并查找三级错误配置表中与归类后的每一二级错误匹配的三级错误规则;在三级错误配置表中确定与三级错误规则具有映射关系的错误类型。In other embodiments of the present application, the processing module 1542 is used to analyze the function type of the event processing function corresponding to the error, and classify the error collected/reported by the event processing function conforming to the preset type as a first-level error; Perform keyword regular matching on errors, and classify the first-level errors into one of the five second-level errors; call the third-level error configuration table for each classified second-level error, and find the third-level error configuration table The three-level error rule that matches each of the classified two-level errors; the error type that has a mapping relationship with the three-level error rule is determined in the three-level error configuration table.
本申请其他实施例中,处理模块1542,用于在修复建议配置表中查找与三级错误规则匹配的修复建议,并输出修复建议。In other embodiments of the present application, the processing module 1542 is configured to search the repair suggestion configuration table for a repair suggestion matching the three-level error rule, and output the repair suggestion.
本申请实施例提供的脚本错误的处理装置,通过获取可执行代码在运行过程中发生错误时的报错行列号;其中,可执行代码是由经过源映射处理的混淆源码生成的;获取针对错误进行梯度诊断得到的错误类型;基于混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,散列表存储有未混淆的源码的函数方法名与混淆源码的函数方法名的对应关系,以及未混淆的源码的参数名与混淆源码的参数名的对应关系;基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置,并输出针对错误的修复建议;也就是说,结合梯度诊断和反编译给出解决方案,在每次获得到原始错误信息后,首先采用梯度诊断方法对原始错误进行精准诊断,然后根据梯度诊断出的最小粒度错误类型以及反编译结果得到精准修复建议,最后将精准诊断结果、精准修复建议通知给用户。The script error processing device provided by the embodiment of the present application obtains the error line number when an error occurs in the execution process of the executable code; wherein, the executable code is generated by the obfuscated source code processed by source mapping; The error type obtained by the gradient diagnosis; the original syntax tree is generated based on the abstract syntax tree and the hash table converted from the obfuscated source code; wherein, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and The corresponding relationship between the parameter names of the unobfuscated source code and the parameter names of the obfuscated source code; based on the error type, error row and column number, and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output the error-specific Repair suggestions; that is to say, a solution is given by combining gradient diagnosis and decompilation. After obtaining the original error information each time, first use the gradient diagnosis method to accurately diagnose the original error, and then diagnose the smallest granular error type according to the gradient And the decompilation results get accurate repair suggestions, and finally the accurate diagnosis results and accurate repair suggestions are notified to the user.
需要说明的是,本申请实施例装置的描述,与上述方法实施例的描述是类似的,具有同方法实施例相似的有益效果,因此不做赘述。对于本装置实施例 中未披露的技术细节,请参照本申请方法实施例的描述而理解。It should be noted that the description of the device in the embodiment of the present application is similar to the description of the above-mentioned method embodiment, and has similar beneficial effects to the method embodiment, so details are not repeated here. For technical details not disclosed in the device embodiments of this application, please refer to the description of the method embodiments of this application for understanding.
本申请实施例提供一种存储有可执行指令的存储介质,其中存储有可执行指令,当可执行指令被处理器执行时,将引起处理器执行本申请实施例提供的方法,例如,如图3示出的方法。The embodiment of the present application provides a storage medium storing executable instructions, and the executable instruction is stored therein. When the executable instruction is executed by the processor, it will cause the processor to execute the method provided in the embodiment of the present application, for example, as shown in FIG. 3 shows the method.
本申请实施例提供的存储介质,通过获取可执行代码在运行过程中发生错误时的报错行列号;其中,可执行代码是由经过源映射处理的混淆源码生成的;获取针对错误进行梯度诊断得到的错误类型;基于混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,散列表存储有未混淆的源码的函数方法名与混淆源码的函数方法名的对应关系,以及未混淆的源码的参数名与混淆源码的参数名的对应关系;基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置,并输出针对错误的修复建议;也就是说,结合梯度诊断和反编译给出解决方案,在每次获得到原始错误信息后,首先采用梯度诊断方法对原始错误进行精准诊断,然后根据梯度诊断出的最小粒度错误类型以及反编译结果得到精准修复建议,最后将精准诊断结果、精准修复建议通知给用户。The storage medium provided by the embodiment of the present application is obtained by obtaining the error row and column number when an error occurs in the execution of the executable code; wherein, the executable code is generated by the obfuscated source code that has been processed by source mapping; and the gradient diagnosis for the error is obtained. The error type; the original syntax tree is generated based on the abstract syntax tree and the hash table converted from the obfuscated source code; the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the unobfuscated The corresponding relationship between the parameter name of the source code and the parameter name of the obfuscated source code; based on the error type, error row and column number and the original syntax tree, locate the location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output the repair suggestions for the error; That is to say, a solution is given by combining gradient diagnosis and decompilation. After obtaining the original error information each time, the gradient diagnosis method is first used to accurately diagnose the original error, and then the smallest granularity error type diagnosed according to the gradient and decompilation As a result, accurate repair suggestions are obtained, and finally the accurate diagnosis results and accurate repair suggestions are notified to the user.
在一些实施例中,存储介质可以是计算机可读存储介质,例如,铁电存储器(FRAM,Ferromagnetic Random Access Memory)、只读存储器(ROM,Read Only Memory)、可编程只读存储器(PROM,Programmable Read Only Memory)、可擦除可编程只读存储器(EPROM,Erasable Programmable Read Only Memory)、带电可擦可编程只读存储器(EEPROM,Electrically Erasable Programmable Read Only Memory)、闪存、磁表面存储器、光盘、或光盘只读存储器(CD-ROM,Compact Disk-Read Only Memory)等存储器;也可以是包括上述存储器之一或任意组合的各种设备。In some embodiments, the storage medium can be a computer-readable storage medium, for example, a ferroelectric memory (FRAM, Ferromagnetic Random Access Memory), a read-only memory (ROM, Read Only Memory), a programmable read-only memory (PROM, Programmable Read Only Memory), Erasable Programmable Read Only Memory (EPROM, Erasable Programmable Read Only Memory), Electrically Erasable Programmable Read Only Memory (EEPROM, Electrically Erasable Programmable Read Only Memory), flash memory, magnetic surface memory, optical disc, Or memory such as CD-ROM (Compact Disk-Read Only Memory); It can also be various devices including one or any combination of the above-mentioned memories.
在一些实施例中,可执行指令可以采用程序、软件、软件模块、脚本或代码的形式,按任意形式的编程语言(包括编译或解释语言,或者声明性或过程性语言)来编写,并且其可按任意形式部署,包括被部署为独立的程序或者被部署为模块、组件、子例程或者适合在计算环境中使用的其它单元。In some embodiments, executable instructions may take the form of programs, software, software modules, scripts, or code written in any form of programming language, including compiled or interpreted languages, or declarative or procedural languages, and its Can be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
作为示例,可执行指令可以但不一定对应于文件***中的文件,可以可被存储在保存其它程序或数据的文件的一部分,例如,存储在超文本标记语言(超文本标记语言,Hyper Text Markup Language)文档中的一个或多个脚本中,存储在专用于所讨论的程序的单个文件中,或者,存储在多个协同文件(例如, 存储一个或多个模块、子程序或代码部分的文件)中。作为示例,可执行指令可被部署为在一个计算设备上执行,或者在位于一个地点的多个计算设备上执行,又或者,在分布在多个地点且通过通信网络互连的多个计算设备上执行。As an example, executable instructions may, but do not necessarily correspond to files in a file system, may be stored as part of a file that holds other programs or data, for example, in Hyper Text Markup Language (HTML, Hyper Text Markup Language) in one or more scripts in a document, in a single file dedicated to the program in question, or in multiple cooperating files (for example, a file that stores one or more modules, subroutines, or sections of code )middle. As an example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or alternatively, on multiple computing devices distributed across multiple sites and interconnected by a communication network. to execute.
以上所述,仅为本申请的实施例而已,并非用于限定本申请的保护范围。凡在本申请的精神和范围之内所作的任何修改、等同替换和改进等,均包含在本申请的保护范围之内。The above descriptions are merely examples of the present application, and are not intended to limit the protection scope of the present application. Any modifications, equivalent replacements and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
工业实用性Industrial Applicability
本申请实施例提供了一种脚本错误的处理方法、装置、设备及存储介质,通过获取可执行代码在运行过程中发生错误时的报错行列号;其中,可执行代码是由经过源映射处理的混淆源码生成的;获取针对错误进行梯度诊断得到的错误类型;基于混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,散列表存储有未混淆的源码的函数方法名与混淆源码的函数方法名的对应关系,以及未混淆的源码的参数名与混淆源码的参数名的对应关系;基于错误类型、报错行列号和原始语法树,在混淆源码对应的未混淆的源码中定位错误的发生位置,并输出针对错误的修复建议;也就是说,结合梯度诊断和反编译给出解决方案,在每次获得到原始错误信息后,首先采用梯度诊断方法对原始错误进行精准诊断,然后根据梯度诊断出的最小粒度错误类型以及反编译结果得到精准修复建议,最后将精准诊断结果、精准修复建议通知给用户。The embodiment of the present application provides a script error processing method, device, device, and storage medium, by obtaining the error row and column number when an error occurs in the execution of the executable code; wherein, the executable code is processed by source mapping Obfuscated source code generation; obtain the error type obtained by gradient diagnosis for errors; generate the original syntax tree based on the abstract syntax tree and hash table converted from the obfuscated source code; among them, the hash table stores the function method name and obfuscated source code of the unobfuscated source code The corresponding relationship between the function and method names of the source code, and the corresponding relationship between the parameter names of the unobfuscated source code and the parameter names of the obfuscated source code; based on the error type, error row and column number and the original syntax tree, locate the error in the unobfuscated source code corresponding to the obfuscated source code The position where the error occurs, and output the repair suggestion for the error; that is, combine the gradient diagnosis and decompilation to give a solution. After obtaining the original error information each time, first use the gradient diagnosis method to accurately diagnose the original error, and then Accurate repair suggestions are obtained according to the smallest granularity error type diagnosed by the gradient and the decompilation results, and finally the accurate diagnosis results and accurate repair suggestions are notified to the user.

Claims (10)

  1. 一种脚本错误的处理方法,包括:A method for handling script errors, including:
    获取可执行代码在运行过程中发生错误时的报错行列号;其中,所述可执行代码是由经过源映射处理的混淆源码生成的;Obtaining the error line and column number when an error occurs during the execution of the executable code; wherein, the executable code is generated by the obfuscated source code processed through source mapping;
    获取针对所述错误进行梯度诊断得到的错误类型;Obtain the error type obtained by performing gradient diagnosis on the error;
    基于所述混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,所述散列表存储有未混淆的源码的函数方法名与所述混淆源码的函数方法名的对应关系,以及所述未混淆的源码的参数名与所述混淆源码的参数名的对应关系;Generate an original syntax tree based on the abstract syntax tree and hash table converted from the obfuscated source code; wherein, the hash table stores the corresponding relationship between the function method name of the unobfuscated source code and the function method name of the obfuscated source code, and the The corresponding relationship between the parameter name of the unobfuscated source code and the parameter name of the obfuscated source code;
    基于所述错误类型、所述报错行列号和所述原始语法树,在所述混淆源码对应的所述未混淆的源码中定位所述错误的发生位置,并输出针对所述错误的修复建议。Based on the error type, the error row and column number, and the original syntax tree, locate the occurrence location of the error in the unobfuscated source code corresponding to the obfuscated source code, and output a repair suggestion for the error.
  2. 根据权利要求1中所述的方法,其中,所述基于所述混淆源码转换得到的抽象语法树和散列表生成原始语法树,包括:The method according to claim 1, wherein said generating an original syntax tree based on the abstract syntax tree and hash table converted from said obfuscated source code comprises:
    循环遍历语法树及散列表,将抽象语法树中的一个表达式节点中对象的对象名与所述散列表中的键进行比对;Looping through the syntax tree and the hash table, comparing the object name of the object in an expression node in the abstract syntax tree with the key in the hash table;
    若所述对象名与所述散列表中的一个键相同,则将所述一个表达式节点中的所述对象名重置为散列表中对应于所述一个键的值,在所述一个表达式节点中将计算属性的标识参数由第一参数改为第二参数;If the object name is identical to a key in the hash table, then reset the object name in the one expression node to the value corresponding to the one key in the hash table, and in the one expression Change the identification parameter of the calculated attribute from the first parameter to the second parameter in the formula node;
    若所述对象名与所述一个键不同,将所述对象名与所述散列表中的另一个键进行比对,直至所有表达式节点中的计算属性的标识参数由所述第一参数改为第二参数,得到所述原始语法树。If the object name is different from the one key, compare the object name with another key in the hash table until the identification parameters of the computed properties in all expression nodes are changed from the first parameter to As the second parameter, get the original syntax tree.
  3. 根据权利要求1或2所述的方法,其中,所述基于所述错误类型、所述报错行列号和所述原始语法树,在所述混淆源码对应的所述未混淆的源码中定位所述错误的发生位置,包括:The method according to claim 1 or 2, wherein, based on the error type, the error line number and the original syntax tree, locate the Where the error occurred, including:
    若所述错误类型属于引用类型错误或者类型错误,则将所述原始语法树转为所述未混淆的源码;If the error type is a reference type error or a type error, converting the original syntax tree into the unobfuscated source code;
    基于所述报错行列号在所述未混淆的源码中定位所述错误的发生位置。The position where the error occurs is located in the unobfuscated source code based on the row and column number of the error report.
  4. 根据权利要求1所述的方法,其中,所述基于所述错误类型、所述报错行列号和所述原始语法树,在所述混淆源码对应的所述未混淆的源码中定位所 述错误的发生位置,包括:The method according to claim 1, wherein, based on the error type, the error row and column number, and the original syntax tree, locate the error in the unobfuscated source code corresponding to the obfuscated source code Where it occurs, including:
    若所述错误类型属于范围错误,则获取软件开发工具包基于所述报错行列号捕获的所述错误的发生位置的调用栈信息;If the error type belongs to a range error, then obtain the call stack information of the occurrence location of the error captured by the software development kit based on the error line number;
    基于所述调用栈信息和所述原始语法树,得到原始调用栈;其中,所述原始调用栈为缓存有所述未混淆的源码中定位的所述错误的发生位置的数组。Based on the call stack information and the original syntax tree, an original call stack is obtained; wherein, the original call stack is an array that caches the location of the error located in the unobfuscated source code.
  5. 根据权利要求4所述的方法,其中,所述基于所述调用栈信息和所述原始语法树,得到原始调用栈,包括:The method according to claim 4, wherein said obtaining an original call stack based on said call stack information and said original syntax tree comprises:
    将所述调用栈信息转换为第一数组,并删除所述第一数组的第一项;converting the call stack information into a first array, and deleting the first item of the first array;
    遍历所述第一数组并正则匹配每一项内容,取出调用栈中的满足匹配条件的调用函数名,得到第二数组;Traverse the first array and regularly match each item of content, take out the calling function name in the call stack that meets the matching condition, and obtain the second array;
    遍历所述原始语法树将一个表达式节点的对象的对象名与所述第二数组中的每一项进行循环比对;Traversing the original syntax tree and comparing the object name of an object of an expression node with each item in the second array;
    若所述对象名与所述第二数组中的一项相同,则将所述一个表达式节点缓存;If the object name is the same as an item in the second array, cache the one expression node;
    将循环比对找到的所有表达式节点缓存为第三数组;其中,所述所有表达式节点的对象名与所述第二数组中的一项相同;Cache all the expression nodes found by the loop comparison as a third array; wherein, the object names of all the expression nodes are the same as an item in the second array;
    循环遍历所述散列表与所述第三数组,将所述第三数组中表达式节点中对象的对象名替换为所述散列表中匹配到键对应的值,得到原始调用栈;其中,所述原始调用栈为缓存有替换后的表达式节点的数组。Looping through the hash table and the third array, replacing the object name of the object in the expression node in the third array with the value corresponding to the key in the hash table to obtain the original call stack; wherein, The original call stack is cached with an array of replaced expression nodes.
  6. 根据权利要求1至5中任一项所述的方法,其中,所述获取针对所述错误进行梯度诊断得到的错误类型,包括:The method according to any one of claims 1 to 5, wherein said obtaining the error type obtained by performing gradient diagnosis on said error comprises:
    对所述错误对应的事件处理函数的函数类型进行分析,将符合预设类型的事件处理函数采集/上报的错误归类为一级错误;Analyzing the function type of the event processing function corresponding to the error, and classifying the error collected/reported by the event processing function conforming to the preset type as a first-level error;
    对所述一级错误进行关键字正则匹配,并将所述一级错误归类至五种二级错误中对应的一种;performing regular keyword matching on the first-level errors, and classifying the first-level errors into one of the five second-level errors;
    针对归类后的每一二级错误调用三级错误配置表,并查找所述三级错误配置表中与所述归类后的每一二级错误匹配的三级错误规则;Invoking the three-level error configuration table for each second-level error after classification, and looking for the three-level error rule that matches each second-level error after the classification in the third-level error configuration table;
    在所述三级错误配置表中确定与所述三级错误规则具有映射关系的所述错误类型。The error type that has a mapping relationship with the third-level error rule is determined in the third-level error configuration table.
  7. 根据权利要求6所述的方法,其中,所述输出针对所述错误的修复建议,包括:The method according to claim 6, wherein said outputting a repair suggestion for said error comprises:
    在修复建议配置表中查找与所述三级错误规则匹配的修复建议,并输出所述修复建议。Find a repair suggestion matching the three-level error rule in the repair suggestion configuration table, and output the repair suggestion.
  8. 一种脚本错误的处理装置,包括:A script error handling device, comprising:
    获取模块,用于获取可执行代码在运行过程中发生错误时的报错行列号;其中,所述可执行代码是由经过源映射处理的混淆源码生成的;The obtaining module is used to obtain the error row and column number when an error occurs in the execution process of the executable code; wherein, the executable code is generated by the obfuscated source code processed by source mapping;
    所述获取模块,用于获取针对所述错误进行梯度诊断得到的错误类型;The obtaining module is used to obtain the error type obtained by performing gradient diagnosis on the error;
    处理模块,用于基于所述混淆源码转换得到的抽象语法树和散列表生成原始语法树;其中,所述散列表存储有未混淆的源码的函数方法名与所述混淆源码的函数方法名的对应关系,以及所述未混淆的源码的参数名与所述混淆源码的参数名的对应关系;A processing module, configured to generate an original syntax tree based on the abstract syntax tree and the hash table converted from the obfuscated source code; wherein, the hash table stores the function method name of the unobfuscated source code and the function method name of the obfuscated source code Correspondence, and the corresponding relationship between the parameter name of the unobfuscated source code and the parameter name of the obfuscated source code;
    所述处理模块,用于基于所述错误类型、所述报错行列号和所述原始语法树,在所述混淆源码对应的所述未混淆的源码中定位所述错误的发生位置,并输出针对所述错误的修复建议。The processing module is configured to locate the occurrence position of the error in the unobfuscated source code corresponding to the obfuscated source code based on the error type, the error row and column number, and the original syntax tree, and output the error for Suggested fixes for the errors described.
  9. 一种脚本错误的处理设备,包括:A script error handling facility comprising:
    存储器,用于存储可执行指令;处理器,用于执行所述存储器中存储的可执行指令时,实现权利要求1至7任一项所述的方法。The memory is used to store executable instructions; the processor is used to implement the method according to any one of claims 1 to 7 when executing the executable instructions stored in the memory.
  10. 一种存储介质,存储有可执行指令,用于引起处理器执行时,实现权利要求1至7任一项所述的方法。A storage medium storing executable instructions for causing a processor to implement the method according to any one of claims 1 to 7.
PCT/CN2022/119025 2022-02-25 2022-09-15 Script error processing method and apparatus, device, and storage medium WO2023159920A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210178711.2 2022-02-25
CN202210178711.2A CN114661290A (en) 2022-02-25 2022-02-25 Script error processing method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
WO2023159920A1 true WO2023159920A1 (en) 2023-08-31

Family

ID=82027954

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/119025 WO2023159920A1 (en) 2022-02-25 2022-09-15 Script error processing method and apparatus, device, and storage medium

Country Status (2)

Country Link
CN (1) CN114661290A (en)
WO (1) WO2023159920A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114661290A (en) * 2022-02-25 2022-06-24 深圳前海微众银行股份有限公司 Script error processing method, device, equipment and storage medium
CN116305131B (en) * 2023-05-20 2023-08-11 北京长亭科技有限公司 Static confusion removing method and system for script

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9459848B1 (en) * 2015-05-29 2016-10-04 International Business Machines Corporation Obtaining correct compile results by absorbing mismatches between data types representations
CN106897211A (en) * 2015-12-21 2017-06-27 阿里巴巴集团控股有限公司 For the localization method and system of obscuring script
CN114661290A (en) * 2022-02-25 2022-06-24 深圳前海微众银行股份有限公司 Script error processing method, device, equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9459848B1 (en) * 2015-05-29 2016-10-04 International Business Machines Corporation Obtaining correct compile results by absorbing mismatches between data types representations
CN106897211A (en) * 2015-12-21 2017-06-27 阿里巴巴集团控股有限公司 For the localization method and system of obscuring script
CN114661290A (en) * 2022-02-25 2022-06-24 深圳前海微众银行股份有限公司 Script error processing method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN114661290A (en) 2022-06-24

Similar Documents

Publication Publication Date Title
WO2023159920A1 (en) Script error processing method and apparatus, device, and storage medium
You et al. Profuzzer: On-the-fly input type probing for better zero-day vulnerability discovery
Kabinna et al. Examining the stability of logging statements
US10789054B2 (en) Methods, systems, apparatuses and devices for facilitating change impact analysis (CIA) using modular program dependency graphs
Zhang et al. Towards automatic generation of security-centric descriptions for android apps
US10095602B2 (en) Automated code analyzer
Herzig et al. Predicting defects using change genealogies
US20080313616A1 (en) Methods and systems for testing tool with comparative testing
US9880832B2 (en) Software patch evaluator
US9244510B1 (en) Bug report checks in a modeling system
CN110704297B (en) Code review method, device, computer equipment and storage medium
US20130061211A1 (en) Systems, methods, and computer-readable media for measuring quality of application programming interfaces
Nguyen et al. Automated oracles: An empirical study on cost and effectiveness
Padhye et al. Travioli: A dynamic analysis for detecting data-structure traversals
CN112328259A (en) Compiling time length processing method and device
Zheng et al. An empirical study of high-impact factors for machine learning-based vulnerability detection
CN111709026B (en) Static security detection method, device, computer equipment and storage medium
Wang et al. Demystifying regular expression bugs: A comprehensive study on regular expression bug causes, fixes, and testing
Viotti et al. A Benchmark of JSON-compatible Binary Serialization Specifications
Juliet Thessalonica et al. Intelligent mining of association rules based on nanopatterns for code smells detection
Herzig et al. Classifying code changes and predicting defects using changegenealogies
CN114691197A (en) Code analysis method and device, electronic equipment and storage medium
CN113778852A (en) Code analysis method based on regular expression
Zhang et al. Automatic generation of security-centric descriptions for android apps
Wang et al. Microservice architecture recovery based on intra-service and inter-service features

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22928186

Country of ref document: EP

Kind code of ref document: A1