Analysis function-imparting device, analysis function-imparting method, and analysis function-imparting program
The analysis function imparting device analyzes script engine virtualization to enable dynamic bytecode instrumentation, overcoming the challenge of unknown internal specifications and lack of support functions, allowing for detailed script analysis across multiple scripting languages.
Patent Information
- Application Number
- PCT/JP2023/015094
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-04-13
- Publication Date
- 2024-10-17
AI Technical Summary
Current dynamic binary instrumentation technologies require manual analysis, design, and implementation for each script engine, which is impractical due to the lack of support functions like debuggers and unknown internal specifications, making it difficult to add dynamic bytecode instrumentation functionality without extensive effort.
An analysis function imparting device and method that analyzes the script engine's virtualization based on execution traces to detect symbol tables and instruction sets, allowing for the extraction and porting of instrumentation bytecodes and symbol tables, enabling dynamic bytecode instrumentation without manual analysis for script engines without debugger support.
Enables the addition of dynamic bytecode instrumentation to script engines with unknown internal specifications, facilitating detailed script analysis and instrumentation without requiring individual manual design or implementation, supporting various scripting languages.
Smart Images

Figure JP2023015094_17102024_PF_FP_ABST
Abstract
Description
Analysis function providing device, analysis function providing method, and analysis function providing program
[0001] The present invention relates to an analytical function providing device, an analytical function providing method, and an analytical function providing program.
[0002] Script analysis techniques are used for a variety of purposes, including compiler optimization for just-in-time (JIT) compilation, software testing and debugging, fuzzing, and malware analysis.
[0003] [Program Instrumentation] One of the techniques for dynamically analyzing programs is instrumentation, which is a technique for obtaining information about the execution state of a program during execution by adding code with analytical functions to the program being analyzed and then executing it.
[0004] For example, instrumentation can insert logging code after each execution of a program to determine the total number of instructions executed, and similarly inserting logging code after each execution of a branch to determine the control flow that was followed.
[0005] This type of instrumentation is an important technology that is widely used for software testing as well as cybersecurity purposes such as malware analysis and vulnerability detection.
[0006] There are two types of instrumentation: dynamic instrumentation and static instrumentation. Dynamic instrumentation is a technique for dynamically adding analytical code during program execution using a technique for dynamically changing the program's behavior. Static instrumentation is a technique for statically adding analytical code before the program is executed using a technique for rewriting the program.
[0007] Furthermore, the targets of instrumentation are diverse, including source code, scripts, executable binaries (hereafter referred to as binaries), bytecode, etc. Nowadays, not only is testing for scripts important, but the opportunities for malicious scripts to be used in attacks are also increasing, making instrumentation for scripts important.
[0008] One of the most common instrumentation techniques is dynamic binary instrumentation. Dynamic binary instrumentation is a technique for obtaining information about the execution state by dynamically adding analytical code to the binary program being analyzed at runtime. In dynamic binary instrumentation, the injection of analytical code is mainly achieved by using hooks.
[0009] Specifically, the injection of analysis code follows the following process: First, the code to be injected is placed in memory. Then, when a specific, predetermined command or function is executed, a hook is placed so that a branch is made to the injected code. The code is then executed. At the end of the code, execution is returned to the branch source and the original processing is resumed.
[0010] In current dynamic binary instrumentation technology, this is generally achieved by a technique called inline hooks or by hooks during conversion called dynamic binary conversion in a virtual machine (VM).
[0011] [The need to address obfuscation] One technique for hindering analysis is obfuscation. Obfuscation involves applying conversions to programs that make them difficult to interpret, primarily to hinder static analysis. In the case of script obfuscation, for example, parts of the script are encoded or encrypted, and then dynamically decoded or decrypted before execution. In such cases, the type of script that will be executed is not clear until it is executed. This makes static analysis of the script difficult.
[0012] Malicious scripts and protected scripts are generally obfuscated, making static analysis difficult. Software protection is an important technique for protecting the intellectual property rights of creators. Reverse engineering is a technique for revealing the technology used to implement software. This is a technique for analyzing a program to understand its structure and specifications. Software protection is a technique for protecting software from program analysis used for reverse engineering.
[0013] Therefore, there are two main methods used to instrument scripts: a method in which analytical scripts are statically added to scripts before execution, and a method in which analytical bytecodes are dynamically added when the script is converted into bytecodes by a script engine at runtime.
[0014] [Script Execution Method] Scripts are executed by a script engine (also called an interpreter). Scripts are generally converted into bytecode at runtime, and the bytecode is interpreted and executed by a virtual machine (VM). For this reason, the script is analyzed before execution, and the bytecode is analyzed at runtime.
[0015] As mentioned above, if a script is obfuscated, static analysis before execution becomes difficult. Therefore, it is necessary to dynamically analyze the bytecode and obtain variable information from the information obtained at runtime.
[0016] From the above, in order to implement instrumentation for scripts, dynamic instrumentation for bytecode, i.e., dynamic bytecode instrumentation, is required.
[0017] Here, a method for implementing dynamic instrumentation for Java bytecode has been proposed (Non-Patent Document 1), and a method for implementing dynamic instrumentation for ActionScript 3 bytecode has also been proposed (Non-Patent Document 2).
[0018] W. Binder, J. Hulaas, and P. Moret, “Advanced Java Bytecode Instrumentation”, In Proceedings of the 5th International Symposium on Principles and Practice of Programming in Java, pp. 135-144, 2007. Jarkko Turkulainen, “Reflash: practical ActionScript3 instrumentation with RABCDAsm”, 2016
[0019] However, the techniques described in Non-Patent Documents 1 and 2 use information specific to each VM, and have the problem of requiring individual design and implementation for various script languages.
[0020] Dynamic bytecode instrumentation in scripts generally requires the use of support functions such as a debugger provided by the script engine. This is because the internal specifications of the VM in the script engine that controls the execution of the script are often not publicly available, making it difficult to monitor the execution state or change the execution required for instrumentation without support functions.
[0021] However, if such support functions are not provided, it is necessary to reverse engineer the VM to reveal its internal specifications, independently observe its execution state, analyze its bytecode, and obtain the information necessary for instrumentation.
[0022] It is not realistic to manually analyze, design, and implement this individually for each script engine, in view of the amount of work required.
[0023] The present invention has been made in consideration of the above, and aims to provide an analysis function-imparting device, an analysis function-imparting method, and an analysis function-imparting program that can realize the addition of dynamic bytecode instrumentation functions, even for script engines that do not have support functions such as a debugger and whose internal specifications are unknown, without requiring manual individual analysis, design, and implementation.
[0024] In order to solve the above-mentioned problems and achieve the object, the analysis function-imparting device of the present invention is characterized by having: a first analysis unit that analyzes the virtual machine of the script engine based on an execution trace obtained by executing a test script while monitoring the binary of the script engine, and detects a symbol table that holds information about variables based on the analysis results; a second analysis unit that analyzes the instruction set architecture, which is the instruction system of the virtual machine, to collect virtual machine instructions, and analyzes the collected virtual machine instructions based on the analysis results of the virtual machine of the script engine and the analysis results of the instruction set architecture; an extraction unit that extracts instrumentation bytecode and symbol table by executing a transplantation script based on the analysis results of the virtual machine and the analysis results of the instruction set architecture; and a transplantation unit that transplants the instrumentation bytecode and symbol table extracted by the extraction unit into the bytecode and symbol table generated by the script engine in the memory space of the script engine based on the script to be analyzed.
[0025] According to the present invention, even for script engines that do not have support functions such as a debugger and whose internal specifications are unknown, it is possible to provide dynamic bytecode instrumentation functions without requiring individual manual analysis, design, and implementation.
[0026] FIG. 1 is a diagram illustrating an example of the configuration of a script engine. FIG. 2 is a diagram illustrating pseudocode of a VM included in the script engine. FIG. 3 is a diagram illustrating an example of instrumentation using bytecode porting. FIG. 4 is a diagram illustrating an example of the configuration of an analysis function providing device according to an embodiment. FIG. 5 is a diagram illustrating an example of a first test script used to detect a virtual program counter (VPC). FIG. 6 is a diagram illustrating an example of a second test script. FIG. 7 is a diagram illustrating an example of a third test script. FIG. 8 is a diagram illustrating an example of a fourth test script. FIG. 9 is a diagram illustrating an example of a fifth test script. FIG. 10 is a diagram illustrating an example of the fifth test script. FIG. 11 is a diagram illustrating an example of a porting script. FIG. 12 is a diagram illustrating bytecode and a symbol table generated by executing the porting script illustrated in FIG. 11. FIG. 13 is a diagram illustrating an example of bytecode. FIG. 14 is a diagram illustrating an example of an execution trace. FIG. 15 is a diagram illustrating an example of a VM execution trace. FIG. 16 is a diagram illustrating an example of the structure of a symbol table. FIG. 17 is a diagram illustrating processing by a VM instruction boundary detection unit. FIG. 18 is a diagram illustrating processing by a virtual program counter detection unit. FIG. 19 is a diagram illustrating processing by a dispatcher detection unit. FIG. 20 is a diagram illustrating processing by a code cache detection unit. FIG. 21 is a diagram illustrating processing by a branch VM instruction determination unit. FIG. 22 is a diagram illustrating processing by a branch VM instruction analysis unit. FIG. 23 is a diagram illustrating processing by a branch VM instruction analysis unit. FIG. 24 is a diagram illustrating processing by a branch VM instruction analysis unit. FIG. 25 is a diagram illustrating processing by an extraction unit. FIG. 26 is a diagram illustrating processing by an extraction unit. FIG. 27 is a flowchart illustrating a processing procedure for analysis processing according to an embodiment. FIG. 28 is a flowchart illustrating a processing procedure for execution trace acquisition processing shown in FIG. 27. FIG. 29 is a flowchart illustrating a processing procedure for VM instruction boundary detection processing shown in FIG. 27. FIG. 30 is a flowchart illustrating a processing procedure for virtual program counter detection processing shown in FIG. 27. FIG. 31 is a flowchart illustrating a processing procedure for dispatcher detection processing shown in FIG. 27. FIG. 32 is a flowchart illustrating a processing procedure for code cache detection processing shown in FIG. 27.FIG. 33 is a flowchart showing the processing procedure for symbol table detection processing shown in FIG. 27. FIG. 34 is a flowchart showing the processing procedure for VM execution trace acquisition processing shown in FIG. 27. FIG. 35 is a flowchart showing the processing procedure for VM instruction collection processing shown in FIG. 27. FIG. 36 is a flowchart showing the processing procedure for branch VM instruction determination processing shown in FIG. 27. FIG. 37 is a flowchart showing the processing procedure for branch VM instruction analysis processing shown in FIG. 27. FIG. 38 is a flowchart showing the processing procedure for immediate addressing method analysis processing shown in FIG. 37. FIG. 39 is a flowchart showing the processing procedure for direct addressing method analysis processing shown in FIG. 37. FIG. 40 is a flowchart showing the processing procedure for relative addressing method analysis processing shown in FIG. 37. FIG. 41 is a flowchart showing the processing procedure for symbol table VM instruction determination processing shown in FIG. 27. FIG. 42 is a flowchart showing the processing procedure for symbol table VM instruction analysis processing shown in FIG. 27. FIG. 43 is a flowchart showing the processing procedure for symbol table VM instruction analysis processing shown in FIG. 27. FIG. 44 is a flowchart showing the processing procedure for extraction processing shown in FIG. 27. FIG. 45 is a flowchart showing the processing procedure for bytecode extraction processing shown in FIG. 44. Fig. 46 is a flowchart showing the processing steps of the symbol table extraction processing shown in Fig. 44. Fig. 47 is a flowchart showing the processing steps of the porting processing shown in Fig. 27. Fig. 48 is a flowchart showing the processing steps of the bytecode porting processing shown in Fig. 47. Fig. 49 is a flowchart showing the processing steps of the symbol table porting processing shown in Fig. 47. Fig. 50 is a flowchart showing the processing steps of the execution processing shown in Fig. 27. Fig. 51 is a diagram showing an example of a computer in which an analysis function providing device is realized by executing a program.
[0027] Hereinafter, embodiments of an analytical function providing device, an analytical function providing method, and an analytical function providing program according to the present application will be described in detail with reference to the accompanying drawings. However, the present invention is not limited to the embodiments described below.
[0028] [Embodiment] An analysis function-adding device according to an embodiment first analyzes the VM of a script engine. The analysis function-adding device executes a test script while monitoring the binary of the script engine, and acquires branch traces and memory access traces as execution traces. The analysis function-adding device analyzes a virtual machine (VM) based on the execution trace, and acquires, as architecture information, VM instruction boundaries, a virtual program counter (VPC), and a code cache in which executed VM instructions are stored. Then, based on the analysis results of the VM of the script engine, the analysis function-adding device detects a symbol table that stores information about variables.
[0029] The analysis function adding device analyzes the instruction set architecture, which is the system of VM instructions of the script engine. The analysis function adding device executes a test script while monitoring the VPC and dispatcher, and acquires a VM execution trace. The analysis function adding device collects VM instructions by analyzing the VM execution trace. The analysis function adding device then determines branch VM instructions that cause branches to occur in the script, and analyzes the addressing method of the branch destination of the branch VM instruction and the operands of the branch VM instruction. Furthermore, the analysis function adding device determines symbol table VM instructions that access a symbol table, and analyzes the access destination of the symbol table VM instruction. In this way, the analysis function adding device acquires information on variables managed by the symbol table.
[0030] The analysis function adding device adds a dynamic bytecode instrumentation function to the script engine based on the analysis results of the VM and the analysis results of the instruction set architecture.The analysis function adding device executes a porting script based on the acquired architecture information to extract bytecode and symbol tables for instrumentation, and ports the extracted bytecode and symbol tables to the bytecode and symbol tables generated by the script engine in its memory space based on the script to be analyzed, thereby adding dynamic bytecode instrumentation to the script engine.The script to be analyzed is the target of analysis by the script engine with dynamic bytecode instrumentation function.
[0031] The configuration and function of a typical script engine will be described with reference to Figures 1 and 2. Figure 1 is a diagram illustrating an example of the configuration of a script engine. As shown in Figure 1, the script engine 1 has a bytecode compiler 2 and a VM 3. The bytecode compiler 2 also has a syntax analysis unit 4 and a bytecode generation unit 5. The VM 3 also has a code cache unit 6, a fetch unit 7, a decode unit 8, and an execution unit 9. The fetch unit 7, the decode unit 8, and the execution unit 9 are executed repeatedly and are called an interpreter loop. The script engine 1 then accepts a script as input.
[0032] The syntax analysis unit 4 receives a script as input, performs lexical analysis and syntax analysis, generates an Abstract Syntax Tree (AST), and outputs it to the bytecode generation unit 5. The bytecode generation unit 5 receives the AST as input, converts it into bytecode, and stores it in the code cache unit 6.
[0033] The fetch unit 7 fetches a VM opcode from the code cache unit 6 and outputs it to the decode unit 8. Here, the VM opcode refers to the opcode portion of a VM instruction. The decode unit 8 receives the VM opcode as input, interprets the VM opcode using a decoder / dispatcher, and dispatches it to the corresponding program. The execution unit 9 executes the program corresponding to the VM instruction. The contents written in the script are executed by executing the VM instructions one after another through repeated interpreter loops.
[0034] The functions of the components of the script engine will be described with reference to FIG. 2. FIG. 2 is a diagram showing pseudocode for the VM of the script engine. As shown in FIG. 2, the pseudocode first initializes the VPC (line 1). In the pseudocode, the while loop is the interpreter loop (lines 2 to 7). In the pseudocode, the fetch unit 7 obtains the VM opcode of the VM instruction at the location pointed to by the VPC in the code cache that holds the bytecode (line 3). The decoder uses a Switch statement to interpret the VM instruction (line 4), and the dispatcher invokes an instruction handler based on the VM opcode (lines 5 and onward). Then, in the pseudocode, the instruction handler performs the operation corresponding to the instruction. Input and output are performed using a virtual stack and virtual registers (line 6), and constants and variables are referenced via a symbol table (line 7).
[0035] [An example of instrumentation by bytecode porting] The analysis function-imparting device according to the embodiment analyzes a script engine whose internal specifications are unknown, acquires information for dynamic bytecode instrumentation, and realizes the addition of dynamic bytecode instrumentation to the script engine.
[0036] The analysis function providing device provides the script engine with, for example, an instrumentation function based on bytecode porting as a dynamic bytecode instrumentation function.
[0037] 3 is a diagram illustrating an example of instrumentation using bytecode porting. In this instrumentation, the script engine executes the script to be analyzed, and if there is a process that meets the hook condition, it saves and stores the process that meets the hook condition ((1) in FIG. 3).
[0038] In this instrumentation, the processing part corresponding to the hook condition is overwritten with a branch instruction to the stub, and the stub is executed ((2) and (3) in Figure 3). The stub includes a process to obtain a predetermined variable from the symbol table using a symbol table VM instruction, a process to call the ported bytecode using a branch VM instruction after passing the obtained variable, and a process to branch back to the original location after executing the ported bytecode.
[0039] Next, the stub calls the ported bytecode, executes it ((4) in Figure 3), and branches back to the original location after the ported bytecode is executed. After branching back to the original location by executing the stub, the saved processing is restored and processing resumes ((5) in Figure 3).
[0040] The analysis function adding device executes a test script while monitoring the binary of a script engine in a stage prior to the process of adding the analysis function, and acquires architecture information including a VPC, a dispatcher, a code cache, and a symbol table. Furthermore, the analysis function adding device executes a test script while monitoring the VPC and the dispatcher, and analyzes a VM execution trace acquired, thereby determining the VM instructions of the script engine and acquiring information on the instruction set architecture. In particular, the analysis function adding device analyzes branch VM instructions and symbol table VM instructions for a script engine whose internal specifications are unknown in a stage prior to the process of adding the analysis function.
[0041] In this way, the analysis function-imparting device can detect various architectural information through analysis based on the execution trace and VM execution trace, even for script engines whose VM internal specifications are unknown, thereby enabling the addition of dynamic bytecode instrumentation functions to script engines without the need for manual reverse engineering or the use of support functions such as a debugger.
[0042] [Configuration of the analysis function-imparting device] Next, the configuration of the analysis function-imparting device 10 according to the embodiment will be specifically described with reference to Fig. 4. Fig. 4 is a diagram illustrating an example of the configuration of the analysis function-imparting device 10 according to the embodiment.
[0043] 4, the analysis function-imparting device 10 includes an input unit 11, a control unit 12, a storage unit 13, and an output unit 14. The analysis function-imparting device 10 receives inputs of a test script, a script engine binary, and a seed script.
[0044] The input unit 11 is composed of input devices such as a keyboard and a mouse, and accepts input of information from outside and inputs it to the control unit 12. The input unit 11 also has a communication interface for sending and receiving various information to and from other devices connected via a wired connection or a network, etc., and accepts input of information sent from other devices. The input unit 11 accepts input of test scripts, script engine binaries, porting scripts, analysis target scripts, and hook settings, and outputs them to the control unit 12.
[0045] The test scripts are scripts that are input when dynamically analyzing the script engine to obtain an execution trace and a VM execution trace. The test scripts include a first test script for VM analysis, a second test script for symbol table detection, a third test script for branch VM instruction detection, and a fourth test script and a fifth test script for symbol table VM instruction analysis. The script engine binary is an executable file that constitutes the script engine. The script engine binary may be composed of multiple executable files.
[0046] [Test Script Configuration] This section explains test scripts. Test scripts are input when dynamically analyzing a script engine. These test scripts focus on the number of branch instruction executions and memory read / writes, and are used to capture differences in the behavior of the script engine that occur when the test script is executed a different number of times. These test scripts are prepared in advance of the analysis and are created manually. Creating them requires knowledge of the specifications of the target script language.
[0047] 5 shows an example of a first test script used to detect VPCs. The first test script uses a repetitive process (line 2). The first test script changes the execution conditions and generates differences by increasing or decreasing the number of repetitions (line 2) and the number of repeated statements (lines 3 to 5) in the test script. The first test script is the target of processes from the execution trace acquisition process to the code cache detection process, which will be described later.
[0048] FIG. 6 is a diagram showing an example of a second test script. In the second test script, a characteristic value is used to enable value matching in order to detect a symbol table. For example, in the example of FIG. 6, the characteristic value is "3735928559." By including the characteristic value in the second test script, it becomes possible to detect the storage location of this characteristic value by matching the characteristic value from a memory access trace during symbol table detection. Note that the second test script is subject to the execution trace acquisition process and symbol table detection process, which will be described later.
[0049] FIG. 7 is a diagram showing an example of a third test script. The third test script is used to detect branch VM instructions. The third test script uses multiple conditional branches (lines 4 to 8). In the third test script, the branch conditions are controlled so that the multiple conditional branches are taken or not taken in a specific order pattern (lines 1 and 5). The third test script changes the number of conditional branches and the order pattern of branch success or failure to generate differences. The third test script is subject to the execution trace acquisition process, VM execution trace acquisition process, branch VM instruction determination process, and branch VM instruction analysis process, which will be described later.
[0050] 8 is a diagram showing an example of a fourth test script. The fourth test script is a test script that accesses variables (e.g., "a" and "b") of two different scopes (e.g., "func1" and "func2"). From the access trace by the fourth test script, the difference between each part accessed during execution of each symbol table VM instruction of the first combination is compared with the position of the operand, and it is determined whether the difference is an operand specifying a symbol table.
[0051] 9 and 10 are diagrams showing an example of a fifth test script. The fifth test script is a test script that accesses two different variables (e.g., "a" and "b") within the same scope. From the access trace by the fifth test script, the difference between each part accessed during execution of each symbol table VM instruction of the second combination is compared with the position of the operand, and it is determined whether the difference is an operand that specifies a variable. Note that both the fourth and fifth test scripts are subject to the execution trace acquisition process, VM execution trace acquisition process, and symbol table VM instruction analysis process, which will be described later.
[0052] [Porting Script] Figure 11 is a diagram showing an example of a porting script. By executing the porting script, bytecode and symbol table to be ported during dynamic bytecode instrumentation are extracted. Figure 12 is a diagram showing the bytecode and symbol table generated by executing the porting script shown in Figure 11.
[0053] As shown in Fig. 11, the porting script includes a function 202 to be ported and a call section 204 for the function to be ported. The function 202 to be ported includes processing content 203 to be ported. When the porting script is executed, bytecode 205 (see Fig. 12) corresponding to the processing portion of the processing content 203 to be ported is extracted and ported to bytecode generated by the script engine in its own memory space based on the script to be analyzed. By describing various processes for analyzing the behavior of the script in this section, the analysis target script to which the script will be ported can be analyzed.
[0054] Then, a caller 204 of the function to be ported calls the function to be ported 202, generating bytecode and a symbol table 210 (see FIG. 12), which enables extraction. The symbol table 210 is ported to a symbol table generated by the script engine in its own memory space based on the script to be analyzed.
[0055] FIG. 13 is a diagram showing an example of a bytecode. Bytecode 205 is an example, and each routine has its own bytecode. As shown in bytecode 205, the bytecode has a data structure including an opcode 2051 and an operand 2052. The opcode 2051 is a value that specifies the type of operation, and is actually specified by a corresponding hexadecimal value. The operand 2052 is a value that is the target of the operation, and is generally specified by an ordinal number in a symbol table.
[0056] The storage unit 13 is realized by a semiconductor memory element such as a RAM (Random Access Memory) or a flash memory, or a storage device such as a hard disk or an optical disk, and stores processing programs that operate the analysis function providing device 10, data used during execution of the processing programs, etc. The storage unit 13 has an execution trace database (DB) 131, a VM execution trace DB 133, and an architecture information DB 132 that stores architecture information acquired by the virtual machine analysis unit 121 and the instruction set architecture analysis unit 122 (described later).
[0057] The execution trace DB 131 and the VM execution trace DB 133 store the execution traces and VM execution traces acquired by the execution trace acquisition unit 1211 and the VM execution trace acquisition unit 1221, respectively. The execution trace DB 131 and the VM execution trace DB 133 are managed by the analysis function-imparting device 10. Of course, the execution trace DB 131 and the VM execution trace DB 133 may be managed by another device (such as a server). In this case, the execution trace acquisition unit 1211 (described later) and the VM execution trace acquisition unit 1221 (described later) output the acquired execution traces and VM execution traces to a management server or the like for the execution trace DB 131 and the VM execution trace DB 133 via the communication interface of the output unit 14, and store them in the execution trace DB 131 and the VM execution trace DB 133.
[0058] [Configuration of Execution Trace] Next, the execution trace will be described. Fig. 14 is a diagram showing an example of an execution trace. As mentioned above, the execution trace is made up of a branch trace and a memory access trace. Fig. 14 shows an excerpt of a part of the execution trace. The configuration of the execution trace will be explained below using Fig. 14.
[0059] An execution trace has an element called trace, which indicates whether the log line is a branch trace or a memory access trace.
[0060] A branch trace log line has the format shown in lines 1 to 10 of Figure 14, and consists of three elements: type, src, and dst. type indicates whether the executed branch instruction was a call instruction, a jmp instruction, or a ret instruction. src indicates the address of the branch source, and dst indicates the address of the branch destination.
[0061] A log line of a memory access trace has the format shown in lines 11 to 13 of FIG. 14, for example, and consists of three elements: type, target, and value. type indicates whether the memory access is a read or write. target indicates the memory address that is the target of the memory access. value stores the value resulting from the memory access.
[0062] [Configuration of VM Execution Trace] Next, a VM execution trace will be described. Fig. 15 is a diagram showing an example of a VM execution trace. As described above, a VM execution trace is a record of a VM opcode and a VPC. Fig. 15 shows a portion of a VM execution trace. The configuration of a VM execution trace will be described below with reference to Fig. 15.
[0063] A log line of a VM execution trace is, for example, in the format shown in FIG. 15 and consists of two elements: vpc and vmop (vm opcode). vpc indicates the value of the VPC. Also, vmop indicates the value of the VM opcode virtually assigned to each pointer that points to the beginning of the VM instruction handler to be executed, obtained from the pointer cache.
[0064] Returning to FIG. 4 , the control unit 12 will be described. The control unit 12 has an internal memory for storing programs that define various processing procedures and required data, and executes various processes using these. For example, the control unit 12 is an electronic circuit such as a CPU (Central Processing Unit) or an MPU (Micro Processing Unit). The control unit 12 has a virtual machine analysis unit 121 (first analysis unit), an instruction set architecture analysis unit 122 (second analysis unit), an extraction unit 1231, a transplantation unit 1232, and an execution unit 1233.
[0065] The virtual machine analysis unit 121 analyzes the VM of the script engine. The virtual machine analysis unit 121 acquires multiple execution traces by changing runtime conditions, analyzes the multiple execution traces using differential execution analysis, and acquires VPCs. The virtual machine analysis unit 121 also analyzes the script engine binary to acquire VM instruction boundaries and dispatchers. The virtual machine analysis unit 121 detects a code cache from the VM execution trace. The code cache stores VM instructions to be executed. The virtual machine analysis unit 121 detects a symbol table.
[0066] The virtual machine analysis unit 121 has an execution trace acquisition unit 1211 (first acquisition unit), a VM instruction boundary detection unit 1212 (first detection unit), a virtual program counter detection unit 1213 (second detection unit), a dispatcher detection unit 1214 (third detection unit), a code cache detection unit 1215 (fourth detection unit), and a symbol table detection unit 1216 (fifth detection unit).
[0067] The execution trace acquisition unit 1211 receives the first to fifth test scripts and the script engine binary as input. The execution trace acquisition unit 1211 acquires an execution trace by executing the first to fifth test scripts while monitoring the execution of the script engine binary.
[0068] An execution trace is composed of a branch trace and a memory access trace. The branch trace records the type of branch instruction at the time of execution, the branch source address, and the branch destination address. The memory access trace records the type of memory operation at the time of execution (read / write), and the memory address and value of the operation target. It is known that branch traces and memory access traces can be acquired by hooking a memory operation instruction, inserting code for log output, and executing it. The execution trace acquired by the execution trace acquisition unit 1211 is stored in the execution trace DB 131.
[0069] Furthermore, when acquiring an execution trace, the execution trace acquisition unit 1211 acquires an API (Application Programming Interface) trace and stores it in the execution trace DB 131. The API trace is a record of the system API called during execution and its arguments.
[0070] The VM instruction boundary detection unit 1212 clusters the execution trace for the first test script to detect the boundaries of each VM instruction. The VM instruction boundary detection unit 1212 clusters the execution trace and detects clusters with a threshold or more of execution count as VM instructions. The clustering detects consecutive code regions that are executed multiple times. For example, this may be done by grouping executed instructions that are close in code distance to each other, by searching for common subsequences of executed code blocks, or by other methods. The analysis function providing device 10 detects the start and end points of consecutive instruction sequences that make up the detected VM instruction as boundaries. The VM instruction boundaries detected here are used in VPC detection and dispatcher detection.
[0071] The virtual program counter detection unit 1213 extracts and analyzes the execution trace for the first test script stored in the execution trace DB 131 to detect the VPC. The virtual program counter detection unit 1213 detects the VPC by analyzing multiple execution traces using differential execution analysis focusing on the number of memory reads and the boundaries of each VM instruction detected by the VM instruction boundary detection unit 1212. The virtual program counter detection unit 1213 utilizes the fact that a read into memory that holds the VPC always occurs after the execution of each VM instruction, and detects the VPC by finding the destination of this read.
[0072] For this reason, the virtual program counter detection unit 1213 uses differential execution analysis, focusing on the number of memory reads, to detect VPCs. The virtual program counter detection unit 1213 compares execution traces of multiple test scripts acquired using the first test script and finds memories whose memory read counts change in proportion to both the number of repetitions and the number of repeated statements. The virtual program counter detection unit 1213 then references the boundaries of each VM instruction detected by the VM instruction boundary detection unit 1212 and narrows down the memory values that are read to those that always point to the start point of the VM instruction. The virtual program counter detection unit 1213 detects this memory as a VPC.
[0073] The dispatcher detection unit 1214 extracts each VM instruction portion from the script engine binary based on the VM instruction boundaries detected by the VM instruction boundary detection unit 1212, and detects the portion with high similarity between each VM instruction as a dispatcher. As a premise, the dispatcher is realized by referencing a pointer cache and jumping to the pointer of the next VM instruction handler. Dispatchers are distributed and located behind each VM instruction handler, and their code is generally highly identical. The analysis function providing device detects dispatchers using a predetermined method by searching for code that exists behind such VM instruction handlers and has high similarity. The detection of the portion with high similarity may use, for example, a sequence alignment algorithm or other methods.
[0074] The code cache detection unit 1215 detects a code cache, which is a cache that stores virtual machine instructions to be executed, from the VM execution trace based on the execution trace, VPC, and VM execution trace.
[0075] The code cache detection unit 1215 detects the memory area pointed to by the VPC as a code cache from the VM execution trace.The code cache detection unit 1215 detects the code location of the caller of the memory allocation function that allocated this code cache from the execution trace.The code cache detection unit 1215 detects all memory areas allocated at this code location from the VM execution trace as code caches.
[0076] The code cache detection unit 1215 detects a code location that writes to the code cache from the execution trace, and detects the write by this code location in the VM execution trace as an update of the code cache.
[0077] The symbol table detection unit 1216 detects architecture information of a symbol table that holds information about variables based on the analysis result of the VM of the script engine.
[0078] A symbol table exists for each scope. Fig. 16 is a diagram showing an example of the structure of a symbol table. As shown in the symbol table 210 in Fig. 16, the symbol table has information about variables and constants, and information about functions. For example, in the symbol table 210, the first column shows an ordinal number, the second column shows information identifying a variable, constant, or function, and the third row shows the address of the object entity.
[0079] To clarify the information about the variables used by the script, the following four pieces of information about the symbol table are required:
[0080] The first is the location of the symbol table in memory and the code portion that allocates the memory area for the symbol table. The second is the structure of the symbol table. The third is a list of opcodes for the symbol table VM instruction. And the fourth is the operands (targets of the instruction) of the symbol table VM instruction, in particular which operands are responsible for identifying the scope and variables. The symbol table detection unit 1216 detects the first and second pieces of information related to the symbol table, namely the location of the symbol table in memory and the structure of the symbol table.
[0081] The symbol table detection unit 1216 detects the location of the symbol table in the memory area and the structure of the symbol table using a second test script in which the characteristic value is used and a memory access trace by the second test script. From the memory access trace of the second test script, the symbol table detection unit 1216 detects the location of the symbol table in the memory area and a structure that references the characteristic value based on the storage location of the characteristic value in the memory area and the reference source to the characteristic value. From the API trace, the symbol table detection unit 1216 detects a code portion that allocates memory area for the symbol table. The symbol table detection unit 1216 outputs the location of the symbol table in the memory area and the code portion that allocates that area. The symbol table detection unit 1216 detects the first and second pieces of information out of four pieces of information related to the symbol table.
[0082] The instruction set architecture analysis unit 122 analyzes the instruction set architecture, which is a system of VM instructions. The instruction set architecture analysis unit 122 collects VM instructions. Based on the analysis results of the VM and the instruction set architecture of the script engine, the instruction set architecture analysis unit 122 determines, among the collected VM instructions, a branch VM instruction that causes a branch in the script, and analyzes the addressing method of the branch destination of the branch VM instruction and the operand of the branch VM instruction. Based on the analysis results of the VM and the instruction set architecture of the script engine, the instruction set architecture analysis unit 122 determines, among the collected VM instructions, a symbol table VM instruction that accesses a symbol table, and analyzes the access destination of the symbol table VM instruction.
[0083] The instruction set architecture analysis unit 122 has a VM execution trace acquisition unit 1221 (second acquisition unit), a VM instruction collection unit 1222 (first collection unit), a branch VM instruction determination unit 1223 (first determination unit), a branch VM instruction analysis unit 1224 (third analysis unit), a symbol table VM instruction determination unit 1225 (second determination unit), and a symbol table VM instruction analysis unit 1226 (fourth analysis unit).
[0084] The VM execution trace acquisition unit 1221 receives a test script and a script engine binary as input. The VM execution trace acquisition unit 1221 acquires a VM execution trace by monitoring the VPC and the pointer of the VM instruction handler dispatched by the dispatcher. The VM execution trace acquisition unit 1221 executes the third to fifth test scripts while monitoring the execution of the script engine binary, thereby acquiring a VM execution trace, which is an execution trace executed on the VM. The VM execution trace acquisition unit 1221 associates a pointer to the VM instruction with the VM instruction and virtually assigns a VM opcode as an identifier to each.
[0085] The VM execution trace is an execution trace executed in a VM, to which a VM opcode is virtually assigned as an identifier, and which records a pointer to the executed VM handler and a VPC. The VM execution trace records a pointer to the executed VM instruction handler and a VPC. Specifically, the VM execution trace is composed of a VPC and a VM opcode for each executed VM instruction. The VPC can be recorded by monitoring the memory of the VPC detected by the virtual program counter detection unit 1213. The VM opcode is an identifier virtually assigned to each of a pointer to a VM instruction and a VM instruction that are linked to each other. The VM execution trace acquired by the VM execution trace acquisition unit 1221 is stored in the VM execution trace DB 133.
[0086] The VM instruction collection unit 1222 receives the VPC and the dispatcher as input, executes the test script while monitoring the VPC and the dispatcher, and acquires the VM execution trace. The VM instruction collection unit 1222 collects VM instructions from the VM execution trace.
[0087] In the script engine, a branch is performed by a branch VM instruction that carries out the branch. A branch VM instruction generally has information about the branch destination in an operand.
[0088] There are several ways to specify the branch destination in an operand. Each of these methods differs in how it calculates the actual branch destination. In the VM of a script engine, there are three main methods: immediate addressing, direct addressing, and relative addressing.
[0089] In the immediate addressing method, the address of the branch destination is directly specified, and therefore the virtual program counter (VPC) after the branch becomes this specified value.
[0090] In the direct addressing method, a memory area where the branch destination address is stored is specified. This memory area may be a variable, a virtual stack, or a virtual register. In the direct addressing method, the address stored at the destination of the specified address becomes the value of the VPC.
[0091] In the relative addressing method, an offset from the current VPC is specified, so the value of the VPC after branching is the sum of the offset and the current VPC value.
[0092] Therefore, to determine the branch destination, three pieces of information about the branch VM instruction are required: 1) a list of the opcode of the branch VM instruction; 2) information indicating the operands of the branch VM instruction, specifically which operands hold the branch destination; and 3) the addressing scheme of the branch destination.
[0093] The branch VM instruction determination unit 1223 determines branch VM instructions from among the VM instructions collected by the VM instruction collection unit 1222, and acquires a list of opcodes of the branch VM instructions. The branch VM instruction determination unit 1223 determines branch VM instructions from among the VM instructions collected by the VM instruction collection unit 1222, based on variations in the amount of change in VPC for each VM opcode in the VM execution trace for the third test script.
[0094] The branch VM instruction determination unit 1223 extracts and analyzes the VM execution trace for the third test script stored in the VM execution trace DB 133 to determine a branch VM instruction. The branch VM instruction determination unit 1223 collects the amount of change in VPC before and after execution of each VM opcode assigned as an identifier. If the VM opcode is other than a branch VM instruction, the amount of change in VPC is approximately constant. On the other hand, if the VM opcode is a branch VM instruction, the VPC varies depending on the branch destination.
[0095] Therefore, the branch VM instruction determination unit 1223 determines a branch VM instruction based on the variation in the amount of change in the virtual program counter for each VM opcode in the VM execution trace for the third test script. The branch VM instruction determination unit 1223 focuses on the fact that the amount of variation in the VPC value differs between branch VM instructions and other VM instructions, determines a threshold value, and determines instructions with larger variations in the VPC value as branch VM instructions. Specifically, the branch VM instruction determination unit 1223 evaluates the variation in the amount of change in the VPC for each VM opcode using variance, and determines instructions with variance equal to or greater than a certain threshold as branch VM instructions.
[0096] The branch VM instruction analysis unit 1224 analyzes the addressing method of the branch destination of the branch VM instruction determined by the branch VM instruction determination unit 1223 and the operands of the branch VM instruction based on the analysis results of the VM of the script engine and the analysis results of the instruction set architecture.
[0097] The branch VM instruction analysis unit 1224 analyzes whether the addressing method of the branch destination of the branch VM instruction is one of the three methods: immediate addressing, direct addressing, or relative addressing, and determines the operand of the branch destination of the branch VM instruction being analyzed.
[0098] The symbol table VM instruction determination unit 1225 determines, among the VM instructions collected by the VM instruction collection unit 1222, a VM instruction that accessed a memory area of the symbol table during VM execution as a symbol table VM instruction. The symbol table VM instruction determination unit 1225 determines, among the VM instructions that accessed the memory area of the symbol table, a VM instruction that commands a read as a read symbol table VM instruction. The symbol table VM instruction determination unit 1225 determines, among the VM instructions that accessed the memory area of the symbol table, a VM instruction that commands a write as a write symbol table VM instruction. Based on the determination result for each VM instruction, the symbol table VM instruction determination unit 1225 outputs a list indicating the VM instructions determined to be symbol table VM instructions and their types. The symbol table VM instruction determination unit 1225 acquires a list of opcodes of symbol table VM instructions, which is the third piece of information related to the symbol table.
[0099] The symbol table VM instruction analyzer 1226 acquires information on the operand (target of the instruction) of the symbol table VM instruction, which is the fourth piece of information related to the symbol table.
[0100] The symbol table VM instruction analyzer 1226 retrieves and analyzes the VM execution trace stored in the VM execution trace DB 133. For a combination of two symbol table VM instructions retrieved from the VM execution trace, if a difference between portions accessed during execution of each symbol table VM instruction of the combination in the memory access trace exists at the position of an operand, the symbol table VM instruction analyzer 1226 determines that the difference is the operand of the symbol table VM instruction. The operand of the VM instruction can be determined from the VPC and opcode of the VM instruction. Operands are generally located next to the opcode in memory, i.e., between the current opcode and the next opcode, such as "[opcode A][operand 1][operand 2][opcode B]...". Therefore, the position of the operand can be determined if the VPC and opcode are known.
[0101] The symbol table VM instruction analyzer 1226 determines an operand that specifies a symbol table by using a memory access trace by the fourth test script that accesses variables in two different scopes and a VM execution trace.
[0102] For a first combination of two symbol table VM instructions extracted from the VM execution trace by the fourth test script, the symbol table VM instruction analyzer 1226 extracts, from the memory access trace by the fourth test script, portions accessed during execution of each symbol table VM instruction of the first combination. If a difference between the two extracted portions exists at the position of an operand, the symbol table VM instruction analyzer 1226 determines that the difference is an operand that specifies a symbol table.
[0103] The symbol table VM instruction analyzer 1226 determines the operand that specifies the variable by using the memory access trace and the VM execution trace by the fifth test script that accesses two different variables in the same scope.
[0104] For a second combination of two symbol table VM instructions extracted from the VM execution trace by the fifth test script, the symbol table VM instruction analyzer 1226 extracts, from the memory access trace by the fifth test script, portions accessed during execution of each symbol table VM instruction of the second combination. If a difference between the two extracted portions exists at the position of an operand, the symbol table VM instruction analyzer 1226 determines that the difference is an operand that specifies a variable.
[0105] The symbol table VM instruction analyzer 1226 outputs information on operands that specify a symbol table and information on operands that specify a variable.
[0106] The instrumentation unit 123 provides the script engine with a dynamic bytecode instrumentation function. The instrumentation unit 123 receives a porting script, a script to be analyzed, and hook settings as input. The instrumentation unit 123 then ported the instrumentation bytecode and symbol table extracted by executing the porting script to the bytecode and symbol table generated by the script engine in its memory space based on the script to be analyzed, and set it to branch to a stub each time a process matching a hook condition is executed, thereby executing the script to be analyzed. The instrumentation unit 123 includes an extraction unit 1231, a porting unit 1232, and an execution unit 1233.
[0107] The extraction unit 1231 extracts instrumentation bytecode and symbol table by executing a porting script based on information about the architecture obtained by analysis by the virtual machine analysis unit 121 and information about the instruction set architecture obtained by analysis by the instruction set architecture analysis unit 122.
[0108] Specifically, the extraction unit 1231 executes the porting script while monitoring the writing and execution of the code cache detected by the code cache detection unit 1215, and extracts the data written to the code cache as bytecode for instrumentation. The extraction unit 1231 extracts the entry point of a subroutine in the bytecode. The extraction unit 1231 executes the porting script while monitoring the writing of the symbol table detected by the symbol table detection unit 1216, and extracts the data written to the symbol table as a symbol table.
[0109] The transplantation unit 1232 transplants the instrumentation bytecode and symbol table extracted by executing the transplantation script into the bytecode and symbol table generated by the script engine in the memory space of the script engine based on the script to be analyzed.
[0110] Specifically, the transplantation unit 1232 receives as input the bytecode and symbol table extracted by the execution of the analysis target script. When the analysis target script reaches a process that satisfies the hook condition during execution, the transplantation unit 1232 sets a branch to a stub that executes the extracted bytecode. In this way, the transplantation unit 1232 performs bytecode transplantation.
[0111] When the analysis target script is executed, the transplantation unit 1232 adds a reference to the extracted symbol table to the symbol table of the analysis target script to ensure consistency. In this way, the transplantation unit 1232 performs symbol table transplantation.
[0112] The porting unit 1232 temporarily stops the execution of the script to be analyzed when executing a VM instruction and maps (deploys) the extracted bytecode into memory space. If there is a branch using immediate / direct addressing, the porting unit 1232 updates the address of the operand to match the address of the mapped destination. During porting, the address of the bytecode for porting mapped into memory is generally different from the address of the porting source. Therefore, to ensure consistency between the two, the porting unit 1232 updates the address of the operand to match the mapped destination of the bytecode.
[0113] The transplantation unit 1232 adds instrumentation processing to the stub by transplanting bytecode, and sets it so that branching to the stub occurs every time processing that satisfies the hook condition is executed.
[0114] The porting unit 1232 then maps the extracted symbol table into memory space, adds a reference to the extracted symbol table to the symbol table of the analysis target script, and then ensures consistency. This is because, during porting, the symbol table for porting mapped onto memory generally differs from the symbol table of the porting source. Next, if there is a symbol table VM instruction, the porting unit 1232 updates the operand to match the consistent symbol table.
[0115] The execution unit 1233 executes, in a script engine, the analysis target script that has been ported by the porting unit 1232. That is, the execution unit 1233 executes the analysis target script that has been set so that execution transitions to a stub every time a process that satisfies the hook condition described in the hook setting is executed. The execution unit 1233 outputs the execution result to the output unit 14.
[0116] The output unit 14 is, for example, a liquid crystal display or a printer, and outputs various information including information related to the analysis function imparting device 10. The output unit 14 may also be an interface that controls input and output of various data between an external device and the output unit 14, and may output various information to the external device.
[0117] [Processing of VM instruction boundary detection unit] Next, a description will be given of the processing of the VM instruction boundary detection unit 1212. FIG.
[0118] The VM instruction boundary detection unit 1212 detects the boundaries of each VM instruction. At this time, the VM instruction boundary detection unit 1212 detects VM instructions and their boundaries for threaded code VMs, which do not have an interpreter loop and therefore make it difficult to grasp the boundaries of VM instructions. Specifically, the VM instruction boundary detection unit 1212 extracts execution traces from the execution trace DB 131. Then, as shown in FIG. 17 , the VM instruction boundary detection unit 1212 clusters the execution traces using a predetermined method and detects clusters whose execution counts are equal to or greater than a threshold as VM instructions (e.g., VM instruction handlers 1 to 3). The VM instruction boundary detection unit 1212 detects the start and end points of consecutive instruction sequences that make up a VM instruction as boundaries.
[0119] [Processing of the Virtual Program Counter Detection Unit] Next, the processing of the virtual program counter detection unit 1213 will be described. The virtual program counter detection unit 1213 detects the VPC and pointer cache. The detection of the virtual program counter is achieved by analyzing the memory access trace log of the acquired execution trace. The virtual program counter detection unit 1213 uses differential execution analysis that focuses on the number of times memory is read. FIG. 18 is a diagram explaining the processing of the virtual program counter detection unit 1213.
[0120] The virtual program counter detection unit 1213 extracts one execution trace by the first test script from the execution trace DB 131. The number of VPC reads is proportional to the number of repetitions in the test script and the number of statements in the repetitive process. When the number of repetitions is N and the number of repeated statements is M, approximately MN VPC reads occur. Therefore, the virtual program counter detection unit 1213 extracts memory areas that have increased by 4MN and 9MN in the execution trace for the first test script in which N and M have been increased to 2N and 2M, respectively, and 3N and 3M. Specifically, as shown in FIG. 18 , the virtual program counter detection unit 1213 extracts memory areas that have a monotonically increasing read / write for each VM instruction execution ((1) in FIG. 18 ).
[0121] The virtual program counter detection unit 1213 then detects, as a VPC, a memory value that always points to the start point of a VM instruction. Specifically, the virtual program counter detection unit 1213 compares the VPC pointer with the address of the VM instruction handler, and narrows down the memory area to the matching memory area ((2) in FIG. 18 ).
[0122] [Processing of the Dispatcher Detection Unit] Next, a description will be given of the processing of the dispatcher detection unit 1214. The dispatcher detection unit 1214 detects dispatchers by analyzing the binary of the script engine using a predetermined method. Fig. 19 is a diagram illustrating the processing of the dispatcher detection unit 1214.
[0123] The dispatcher detection unit 1214 detects dispatchers. Based on the boundaries of the VM instructions detected by the VM instruction boundary detection unit 1212, the dispatcher detection unit 1214 extracts each VM instruction portion from the script engine binary. Then, based on the assumption that the similarity of the dispatcher code is high ((1) in FIG. 19 ), the dispatcher detection unit 1214 calculates the similarity between the codes of each VM instruction, and detects the portion with high similarity among all VM instructions as a dispatcher. The dispatcher detection unit 1214 can detect the code that is commonly executed in the latter half of the VM instructions as a dispatcher ((1) in FIG. 19 ).
[0124] [Code Cache Detector] Next, a description will be given of the processing of the code cache detector 1215. FIG.
[0125] The code cache detection unit 1215 detects the memory area pointed to by the VPC as a code cache from the VM execution trace ((1) in FIG. 20).
[0126] The code cache detection unit 1215 detects the code location that called the memory allocation function that allocated this code cache from the execution trace ((2) in FIG. 20). The code cache detection unit 1215 detects all memory areas allocated at this code location from the VM execution trace as code caches ((3) in FIG. 20).
[0127] The code cache detection unit 1215 detects a code location that writes to the code cache from the execution trace ((4) in FIG. 20). The code cache detection unit 1215 detects the write by this code location from the VM execution trace as an update of the code cache ((5) in FIG. 20).
[0128] [Branch VM Instruction Determination Unit] Next, the processing of the branch VM instruction determination unit 1223 will be described. The branch VM instruction determination unit 1223 first determines a branch VM instruction by analyzing the acquired VM execution trace log. The test script (third test script) here is sufficient as long as it contains a branch VM instruction, and is not limited to the example shown in FIG. 7 , and may be any script that includes a branch control syntax. For example, the test script is prepared by collecting information from the Internet or official documents.
[0129] First, the branch VM instruction determination unit 1223 associates a pointer to the VM instruction with the VM instruction for each VM execution trace in the VM execution trace DB 133, and virtually assigns a VM opcode as an identifier to each VM instruction.
[0130] Here, when a VM instruction is a branch instruction, the advance of the VPC changes depending on the branch destination. On the other hand, when the instruction is not a branch instruction, the advance of the VPC changes depending on the size of the VM instruction. Therefore, when pairs of VM instruction opcodes and pointers to VM instructions are collected and the advance of the VPC is examined for each opcode, if the instruction is a branch instruction, the advance of the VPC will vary depending on the branch destination.
[0131] Therefore, the branch VM instruction determination unit 1223 uses variance to evaluate the variance of the pointer to this VM instruction. The branch VM instruction determination unit 1223 calculates the variance of the VPC change amount for each VM opcode and narrows down the VM opcodes to only those for which the calculated variance is greater than a threshold. In this way, the branch VM instruction determination unit 1223 associates the pointer with the VM instruction and determines that the VM instruction with variance in the VPC advance (VM instruction handler 3 in the example of FIG. 21 ) is a branch VM instruction ((1) in FIG. 21 ).
[0132] A set O of VPC advances for a certain opcode is O={o 0 , o 1 , ..., o N} (see equation (1) for the average of VPCo), and t is a threshold, whether or not it is a branch instruction is determined based on the variance s (see equation (2)) as shown in equation (3). In this way, the branch VM instruction determination unit 1223 determines whether the instruction is a branch VM instruction.
[0133]
[0134]
[0135]
[0136] In addition, for VM instructions other than branches, almost no variation is observed, and the boundary between branch VM instructions and other VM instructions is often clear. For this reason, for example, the obtained variance value is plotted on a number line, and a value that can divide the resulting two groups is set as the threshold.
[0137] [Branch VM Instruction Analysis Unit] Next, a description will be given of the processing of the branch VM instruction analysis unit 1224. The branch VM instruction analysis unit 1224 analyzes whether the addressing method of the branch destination of the branch VM instruction is one of the three methods: immediate addressing, direct addressing, or relative addressing, and determines the operand of the branch destination of the branch VM instruction being analyzed.
[0138] The immediate addressing method is a method in which the address of the branch destination is directly specified. In the immediate addressing method, the VPC after the branch becomes this specified value. Figures 22 to 24 are diagrams explaining the processing of the branch VM instruction analysis unit 1224.
[0139] Therefore, the branch VM instruction analysis unit 1224 assigns a taint tag T1 (see FIG. 22) to the code cache of the branch VM instruction to be analyzed, and executes the branch VM instruction while propagating the taint tag in accordance with data movement. Execution of the branch VM instruction changes the VPC, causing a transition in execution ((1) in FIG. 22).
[0140] Then, if there is data with a tag (taint tag T1) moved to the VPC of the branch VM instruction being analyzed during execution of the branch VM instruction being analyzed, the branch VM instruction analyzer 1224 determines that the addressing method of the branch destination of this branch VM instruction is the immediate addressing method. In other words, if the taint tag T1 is propagated to the VPC by execution of the branch VM instruction, the branch VM instruction analyzer 1224 determines that the addressing method of the branch destination of the branch VM instruction is the immediate addressing method ((2) in FIG. 22). Then, the branch VM instruction analyzer 1224 determines that the original data portion of the data moved to the VPC with the taint tag T1 added is the branch destination operand of the branch VM instruction being analyzed.
[0141] The direct addressing method is a method of specifying a memory area where a branch destination address is stored. In the direct addressing method, the address stored at the destination of reference to the specified address becomes the value of the VPC.
[0142] Therefore, the branch VM instruction analyzer 1224 assigns a first tag T21 (see FIG. 23) to the code cache of the branch VM instruction to be analyzed, and executes the branch VM instruction while propagating the first tag T21 in accordance with data movement. If data with the first tag T21 is referenced by a pointer during execution of the branch VM instruction to be analyzed, the branch VM instruction analyzer 1224 assigns a second tag T22 to the referenced data ((1) in FIG. 23).
[0143] If there is data with a second tag T22 that has been moved (propagated) to the VPC of the branch VM instruction during execution of the branch VM instruction to be analyzed, the branch VM instruction analyzer 1224 determines that the addressing method of the branch destination of this branch VM instruction is the direct addressing method ((2) in FIG. 23). Then, for the first tag T21 that triggered the assignment of the second tag T22 to the data moved to the VPC, the branch VM instruction analyzer 1224 determines that the original data portion that assigned the first tag T21 is the operand of the branch destination.
[0144] The relative addressing method is a method of specifying an offset from the current VPC, so that the value of the VPC after branching is the value of the current VPC plus this offset.
[0145] Therefore, the branch VM instruction analysis unit 1224 assigns a first tag T31 (see FIG. 24) to the VPC of the branch VM instruction to be analyzed, and assigns a second tag T32 (see FIG. 24) to the code cache of the branch VM instruction to be analyzed. Then, the branch VM instruction analysis unit 1224 executes the branch VM instruction to be analyzed while propagating the tags (the first tag T31 and the second tag T32) in accordance with the movement of data.
[0146] When the first tag T31 and the second tag T32 are added during execution of the branch VM instruction to be analyzed and moved (propagated) to the VPC of the branch VM instruction to be analyzed, the branch VM instruction analyzer 1224 determines that the addressing method of the branch destination of the branch VM instruction to be analyzed is the relative addressing method ((1) in FIG. 24). Then, the branch VM instruction analyzer 1224 determines that the original data portion of the second tag added to the first tag is the offset operand of the branch destination.
[0147] 25 and 26 are diagrams explaining the processing of the extraction unit. First, the extraction unit 1231 executes the porting script while monitoring the writing and execution of the code cache detected by the code cache detection unit 1215, and extracts the data written to the code cache as bytecode for instrumentation.
[0148] Specifically, the extraction unit 1231 causes the script engine to generate, for example, bytecode 225 ((1) in FIG. 25 ) by calling the function to be ported via the call unit 204 of the function to be ported 207 in the porting script 201. The extraction unit 1231 monitors the writing of the bytecode 225 to the code cache by the script engine ((2) in FIG. 25 ) and the execution of the VM instruction ((4) in FIG. 25 ) of the function call by the script engine ((3) in FIG. 25 ), and extracts the entry point of the subroutine in the bytecode ((4) in FIG. 25 ).
[0149] The extraction unit 1231 executes the porting script 201 while monitoring the writing of the symbol table detected by the symbol table detection unit 1216, and extracts the data written to the symbol table as a symbol table. The script engine generates, for example, the symbol table 210 by executing the function 202 to be ported ((1) in FIG. 26). The extraction unit 1231 monitors the code portion where the script engine allocates a memory area for the symbol table 210 and the writing by the script engine in response to a symbol table VM command ((2) in FIG. 26), and extracts the symbol table ((3) in FIG. 26).
[0150] [Processing Procedure of Analysis Function-Providing Device] Next, a processing procedure of the analysis processing by the analysis function-providing device 10 will be described. Fig. 27 is a flowchart showing the processing procedure of the analysis processing according to the embodiment.
[0151] First, the input unit 11 receives the test scripts and script engine binary as input (step S1). The test scripts include first to fifth test scripts.
[0152] Then, the execution trace acquisition unit 1211 executes the test script while monitoring the binary of the script engine, thereby performing an execution trace acquisition process to acquire a branch trace and a memory access trace (step S2).
[0153] The VM instruction boundary detection unit 1212 detects VM instructions and performs VM instruction boundary detection processing to detect VM instruction boundaries (step S3). The virtual program counter detection unit 1213 extracts and analyzes the execution trace for the first test script stored in the execution trace DB 131 and performs virtual program counter detection processing to find VPCs (step S4).
[0154] The dispatcher detection unit 1214 performs dispatcher detection processing to extract each VM instruction portion from the script engine binary and detect a portion with high similarity between each VM instruction as a dispatcher (step S5).
[0155] Based on the execution trace and VPC, the code cache detection unit 1215 detects the area of the code location from which the memory allocation function was called as a code cache, and performs a code cache detection process to detect the area that is being written to the code location area as an update to the code cache (step S6).
[0156] The symbol table detection unit 1216 performs a symbol table detection process to detect architecture information of the symbol table using the second test script and the memory access trace by the second test script (step S7).
[0157] The VM execution trace acquisition unit 1221 receives the test script and the script engine binary as input, and executes the test script while monitoring the execution of the script engine binary, thereby performing a VM execution trace acquisition process to acquire the VM execution trace (step S8).
[0158] The VM instruction collection unit 1222 performs a VM instruction collection process to collect VM instructions from the VM execution trace (step S9).
[0159] The branch VM instruction determination unit 1223 performs a branch VM instruction determination process to determine a branch VM instruction from among the VM instructions collected by the VM instruction collection unit 1222 (step S10).
[0160] The branch VM instruction analysis unit 1224 performs a branch VM instruction analysis process to analyze the addressing method of the branch destination of the branch VM instruction to be analyzed and the operands of the branch VM instruction (step S11).
[0161] The symbol table VM instruction determination unit 1225 performs a symbol table VM instruction determination process to determine that a VM instruction that accessed the memory area of the symbol table during VM execution is a symbol table VM instruction among the VM instructions collected by the VM instruction collection unit 1222 (step S12).
[0162] The symbol table VM instruction analysis unit 1226 analyzes the operands of the symbol table VM instruction to be analyzed, and performs a symbol table VM instruction analysis process to determine the operands that specify the symbol table and the operands that specify the variables (step S13).
[0163] The extraction unit 1231 performs an extraction process to extract instrumentation bytecode and symbol table by executing a porting script based on the architecture information and instruction set architecture information obtained by the virtual machine analysis unit 121 and the instruction set architecture analysis unit 122 (step S14).
[0164] The transplantation unit 1232 performs a transplantation process in which the instrumentation bytecode and symbol table extracted by executing the transplantation script are transplanted into the bytecode and symbol table generated by the script engine in the memory space of the script engine based on the script to be analyzed (step S15).
[0165] The execution unit 1233 performs an execution process to execute the analysis target script for which the porting process has been executed (step S16).
[0166] The output unit 14 outputs the information obtained by the instrumentation (step S17).
[0167] [Execution Trace Acquisition Processing Procedure] Next, a flow of the execution trace acquisition processing will be described with reference to Fig. 27. Fig. 28 is a flowchart showing the execution trace acquisition processing procedure shown in Fig. 27.
[0168] First, the execution trace acquisition unit 1211 receives a test script and a script engine binary as input (step S21). Then, the execution trace acquisition unit 1211 hooks the received script engine to acquire a branch trace (step S22). The execution trace acquisition unit 1211 also hooks the received script engine to acquire a memory access trace (step S23).
[0169] The execution trace acquisition unit 1211 then inputs the received test script into the script engine for execution (step S24), and stores the execution trace acquired thereby in the execution trace DB 131 (step S25).
[0170] The execution trace acquisition unit 1211 determines whether all of the input test scripts have been executed (step S26). If all of the input test scripts have been executed (step S26: Yes), the execution trace acquisition unit 1211 ends the process. On the other hand, if all of the input test scripts have not been executed (step S26: No), the execution trace acquisition unit 1211 returns to the execution of the first test script in step S24 and continues the process.
[0171] [Procedure for VM Instruction Boundary Detection Processing] Next, a flow of the VM instruction boundary detection processing shown in Fig. 27 will be described. Fig. 29 is a flowchart showing the procedure for the VM instruction boundary detection processing shown in Fig. 27.
[0172] First, the VM instruction boundary detection unit 1212 extracts execution traces from the execution trace DB 131 (step S31). The VM instruction boundary detection unit 1212 clusters the execution traces using a predetermined method (step S32). Any method may be used for clustering.
[0173] The VM instruction boundary detection unit 1212 detects clusters whose execution count is equal to or greater than a threshold as VM instructions (step S33).The VM instruction boundary detection unit 1212 then determines the start and end points of a continuous instruction sequence that constitutes a VM instruction as boundaries (step S34).The VM instruction boundary detection unit 1212 outputs the VM instruction boundaries as return values (step S35), and ends the VM instruction boundary detection process.
[0174] [Procedure for Virtual Program Counter Detection Processing] Next, a flow of the virtual program counter detection processing shown in Fig. 27 will be described. Fig. 30 is a flowchart showing the procedure for the virtual program counter detection processing shown in Fig. 27.
[0175] First, the virtual program counter detection unit 1213 extracts one execution trace by a test script from the execution trace DB 131 (step S41). Next, the virtual program counter detection unit 1213 focuses on memory access traces among the execution traces, and counts the number of reads for each memory read destination (step S42).
[0176] The virtual program counter detection unit 1213 receives as input the test script used to acquire the execution trace (step S43), and analyzes the first test script to acquire the number of repetitions and the number of repeated statements (step S44).
[0177] Next, the virtual program counter detection unit 1213 extracts another execution trace by the first test script, which has a different number of repetitions and number of repeated statements, from the execution trace DB 131 (step S45).The virtual program counter detection unit 1213 then focuses on the memory access trace and counts the number of reads for each memory read destination (step S46).The virtual program counter detection unit 1213 also receives as input the test script used to acquire the execution trace (step S47), analyzes the first test script, and acquires the number of repetitions and the number of repeated statements (step S48).
[0178] Here, the virtual program counter detection unit 1213 narrows down the memory read destinations to only those whose read counts change in proportion to the increase or decrease in the number of repetitions or repeated statements (step S49).Furthermore, the virtual program counter detection unit 1213 narrows down the memory read destinations narrowed down in step S49 to those whose read memory values always point to the start point of the VM instruction (step S50).
[0179] The virtual program counter detection unit 1213 then determines whether the memory read destinations have been narrowed down to only one (step S51). If the virtual program counter detection unit 1213 has not been able to narrow down the memory read destinations to only one (step S51: No), the unit returns to step S45, retrieves the next execution trace, and continues processing. On the other hand, if the virtual program counter detection unit 1213 has been able to narrow down the memory read destinations to only one (step S51: Yes), the unit 1213 stores the narrowed down memory read destination as a virtual program counter in the architecture information DB 132 (step S52), and ends processing.
[0180] [Processing Procedure of Dispatcher Detection Processing] Next, a flow of dispatcher detection processing will be described with reference to Fig. 27. Fig. 31 is a flowchart showing the processing procedure of dispatcher detection processing shown in Fig. 27.
[0181] First, the dispatcher detection unit 1214 receives a script engine binary as an input (step S61), and receives VM instruction boundaries from the VM instruction boundary detection unit 1212 (step S62).
[0182] The dispatcher detection unit 1214 extracts each VM instruction portion from the script engine binary based on the boundaries of the VM instructions received from the VM instruction boundary detection unit 1212 (step S63). The dispatcher detection unit 1214 calculates the similarity between the codes of each VM instruction using a predetermined method (step S64). Any method for calculating the similarity may be used as long as it is capable of calculating the similarity between the codes.
[0183] The dispatcher detection unit 1214 extracts a part with a high degree of similarity among all VM instructions based on the similarity calculated in step S64 (step S65).The dispatcher detection unit 1214 then determines whether the part is the end of the VM instruction (step S66).
[0184] If the extracted portion is not the end of the VM instruction (step S66: No), the dispatcher detection unit 1214 returns to step S65 and continues the process. If the extracted portion is the end of the VM instruction (step S66: Yes), the dispatcher detection unit 1214 outputs the extracted portion as a dispatcher (step S67) and ends the process.
[0185] [Processing Procedure of Code Cache Detection Processing] Next, a flow of the code cache detection processing shown in Fig. 27 will be described. Fig. 32 is a flowchart showing the processing procedure of the code cache detection processing shown in Fig. 27.
[0186] The code cache detection unit 1215 receives an execution trace and a VM execution trace as input (step S71), and acquires a memory area indicated by a VPC from the VM execution trace (step S72). The VM execution trace is acquired by the VM execution trace acquisition unit 1221.
[0187] The code cache detection unit 1215 acquires, from the execution trace, the code location of the caller of the memory allocation function that allocated the memory area acquired in step S72 (step S73).The code cache detection unit 1215 detects, from the VM execution trace, all areas allocated at the code location acquired in step S73 as code caches (step S74).
[0188] The code cache detection unit 1215 acquires the code location that is writing to the code cache from the execution trace (step S75). The code cache detection unit 1215 detects all areas in the VM execution trace that have been written to at the code location acquired in step S75 as code cache updates (step S76). The code cache detection unit 1215 returns the detected code cache and its updated location (step S77), and ends the code cache detection process.
[0189] [Procedure for Symbol Table Detection Processing] Next, a flow of the symbol table detection processing will be described with reference to Fig. 27. Fig. 33 is a flowchart showing the procedure for the symbol table detection processing shown in Fig. 27.
[0190] The symbol table detection unit 1216 receives as input a second test script and a memory access trace by the second test script (step S81), and extracts characteristic values used in the second test script (step S82).
[0191] The symbol table detection unit 1216 detects the storage location in memory of the characteristic value extracted in step S82 by matching the characteristic value from the memory access trace received in step S81 (step S83).
[0192] The symbol table detection unit 1216 detects structures that reference the characteristic values detected in step S83 from the memory access trace (step S84). Since it is possible to determine which pointers reference which areas from the memory access trace, the symbol table detection unit 1216 can detect the structure by connecting the reference relationships between the values in the memory access trace. Furthermore, the symbol table detection unit 1216 may detect structures by adopting an existing method for analyzing the structure of a structure.
[0193] The symbol table detection unit 1216 detects a memory area where references to multiple values are grouped together as a position in the memory area of the symbol table (step S85).
[0194] The symbol table detection unit 1216 extracts function calls for memory allocation from the API trace (step S86). By detecting code locations that make "function calls for memory allocation" as "code that allocates symbol table memory," and by monitoring these code locations and recording the addresses of the allocated memory, the memory location of the symbol table can be determined every time a new symbol table is created.
[0195] The symbol table detection unit 1216 detects from the API trace the code that reserves a memory area for the symbol table, i.e., the code portion that reserves the memory area for the symbol table (step S87).The symbol table detection unit 1216 makes the location of the symbol table in the memory area and the code portion that reserves that area identifiable, and outputs the result as a symbol table (step S88).
[0196] [Procedure of VM Execution Trace Acquisition Processing] Next, a flow of the VM execution trace acquisition processing will be described with reference to Fig. 27. Fig. 34 is a flowchart showing the procedure of the VM execution trace acquisition processing shown in Fig. 27.
[0197] First, the VM execution trace acquisition unit 1221 receives a test script and a script engine binary as input (step S91). Then, the VM execution trace acquisition unit 1221 hooks the received script engine to record VPCs and VM opcodes (step S92).
[0198] The VM execution trace acquisition unit 1221 inputs the received test script into the script engine and executes it (step S93), and stores the VM execution trace acquired thereby in the VM execution trace DB 133 (step S94).
[0199] The VM execution trace acquisition unit 1221 determines whether all of the input test scripts have been executed (step S95). If all of the input second test scripts have been executed (step S95: Yes), the VM execution trace acquisition unit 1221 ends the process. If all of the input second test scripts have not been executed (step S95: No), the VM execution trace acquisition unit 1221 returns to the execution of the test script in step S93 and continues the process.
[0200] [Procedure of VM Instruction Collection Processing] Next, a flow of the VM instruction collection processing shown in Fig. 27 will be described. Fig. 35 is a flowchart showing the procedure of the VM instruction collection processing shown in Fig. 27.
[0201] The VM command collection unit 1222 receives a VPC and a dispatcher as input (step S101), and acquires various scripts from the Internet (step S102). The VM command collection unit 1222 executes the scripts while monitoring the VPC and the dispatcher, and acquires a VM execution trace (step S103).
[0202] The VM instruction collection unit 1222 acquires VM instructions from the VM execution trace (step S104) and adds them to a list of VM instructions (step S105). If the VM instruction collection unit 1222 finds a VM instruction that is not in the list (step S106: No), the VM instruction collection unit 1222 returns to step S102. If the VM instruction collection unit 1222 finds no VM instructions that are not in the list (step S106: Yes), the VM instruction collection unit 1222 returns the list of VM instructions (step S107) and ends the VM instruction collection process.
[0203] [Branch VM Instruction Determination Processing Procedure] Next, a flow of the branch VM instruction determination processing shown in Fig. 27 will be described. Fig. 36 is a flowchart showing the branch VM instruction determination processing procedure shown in Fig. 27.
[0204] The branch VM instruction determination unit 1223 extracts one VM execution trace for the third test script from the VM execution trace DB 133 (step S111). The branch VM instruction determination unit 1223 associates a pointer to the VM instruction with the VM instruction and assigns a VM opcode as an identifier to each of them (step S112). Then, the branch VM instruction determination unit 1223 tallies the amount of change in VPC before and after execution for each VM opcode (step S113).
[0205] The branch VM instruction determination unit 1223 determines whether or not the processing of the VM execution traces for all the third test scripts in the VM execution trace DB 133 has been completed (step S114). If the processing of all the VM execution traces in the VM execution trace DB 133 has not been completed (step S114: No), the branch VM instruction determination unit 1223 returns to step S111 and extracts and processes one VM execution trace for the next third test script.
[0206] If all VM execution traces in the VM execution trace DB 133 have been processed (Step S114: Yes), the branch VM instruction determination unit 1223 calculates the variance of the VPC change amount for each VM opcode (Step S115). Then, the branch VM instruction determination unit 1223 receives a threshold as input (Step S116). The branch VM instruction determination unit 1223 narrows down the VM opcodes to only those whose variance is greater than the threshold (Step S117), stores them as a list of opcodes of branch VM instructions in the architecture information DB 132 (Step S118), and terminates the process.
[0207] [Branch VM Instruction Analysis Processing Procedure] Next, a flow of branch VM instruction analysis processing will be described, which is shown in Fig. 27. Fig. 37 is a flowchart showing the branch VM instruction analysis processing procedure shown in Fig. 27.
[0208] The branch VM instruction analysis unit 1224 performs an immediate addressing method analysis process to analyze whether the addressing method of the branch destination of the branch VM instruction is the immediate addressing method (step S121).
[0209] The branch VM instruction analysis unit 1224 performs a direct addressing method analysis process to analyze whether the addressing method of the branch destination of the branch VM instruction is the direct addressing method (step S122).
[0210] The branch VM instruction analysis unit 1224 performs a relative addressing method analysis process to analyze whether the addressing method of the branch destination of the branch VM instruction is a relative addressing method (step S123).
[0211] The branch VM instruction analysis unit 1224 outputs the analysis result, ie, the addressing method of the branch destination of the branch VM instruction and the operand of the branch VM instruction (step S124).
[0212] [Processing Procedure of Immediate Addressing Method Analysis Processing] Next, a flow of the immediate addressing method analysis processing shown in Fig. 37 will be described. Fig. 38 is a flowchart showing the processing procedure of the immediate addressing method analysis processing shown in Fig. 37.
[0213] The branch VM instruction analysis unit 1224 receives the VPC and the code cache as input (step S131). The branch VM instruction analysis unit 1224 receives the script acquired in the VM instruction collection process as input (step S132). The branch VM instruction analysis unit 1224 executes the script (step S133). The branch VM instruction analysis unit 1224 stops execution when writing the bytecode to the code cache (step S134). The branch VM instruction analysis unit 1224 assigns a taint tag to the bytecode in the code cache of the branch VM instruction to be analyzed (step S135).
[0214] Then, the branch VM instruction analysis unit 1224 resumes execution of the branch VM instruction to be analyzed while propagating the taint tag in accordance with the movement of data (step S136).
[0215] The branch VM instruction analysis unit 1224 determines whether or not there is tagged data that has been moved to the VPC during the execution of the branch VM instruction to be analyzed (step S137).
[0216] If there is tagged data moved to the VPC during execution of the branch VM instruction (step S137: Yes), the branch VM instruction analysis unit 1224 determines that the addressing method for the branch destination of the branch VM instruction being analyzed is the immediate addressing method (step S138).
[0217] The branch VM instruction analysis unit 1224 determines that the original data portion to which the taint tag has been added and which has been moved to the VPC is the operand of the branch destination of the branch VM instruction to be analyzed (step S139).
[0218] On the other hand, if there is no tagged data moved to the VPC during execution of the branch VM instruction (step S137: No), the branch VM instruction analysis unit 1224 determines that the addressing method for the branch destination of the branch VM instruction being analyzed is not the immediate addressing method (step S140).
[0219] The branch VM instruction analysis unit 1224 outputs the addressing method of the branch VM instruction as the analysis result and the operands of the branch VM instruction (step S141).
[0220] [Processing Procedure of Direct Addressing Method Analysis Processing] Next, a flow of the direct addressing method analysis processing shown in Fig. 37 will be described. Fig. 39 is a flowchart showing the processing procedure of the direct addressing method analysis processing shown in Fig. 37.
[0221] The branch VM instruction analysis unit 1224 receives the VPC and the code cache as input (step S151). The branch VM instruction analysis unit 1224 receives the script acquired in the VM instruction collection process as input (step S152). The branch VM instruction analysis unit 1224 executes the script (step S153). The branch VM instruction analysis unit 1224 stops execution when writing the bytecode to the code cache (step S154). The branch VM instruction analysis unit 1224 assigns a first tag to the bytecode in the code cache of the branch VM instruction to be analyzed (step S155).
[0222] The branch VM instruction analysis unit 1224 resumes execution of the branch VM instruction to be analyzed while propagating the tag in accordance with the movement of data (step S156).
[0223] The branch VM instruction analysis unit 1224 determines whether or not the data with the first tag is referenced by a pointer when the branch VM instruction to be analyzed is executed (step S157).
[0224] If the data with the first tag is referenced by a pointer (step S157: Yes), the branch VM instruction analysis unit 1224 assigns a second tag to the referenced data (step S158).
[0225] If the first tagged data is not pointer-referenced (step S157: No), or after processing of step S158, the branch VM instruction analysis unit 1224 determines whether there is second tagged data that has been moved to the VPC during execution of the branch VM instruction being analyzed (step S159).
[0226] If there is second tagged data that has been moved to the VPC during execution of the branch VM instruction being analyzed (step S159: Yes), the branch VM instruction analysis unit 1224 determines that the addressing method for the branch destination of this branch VM instruction is the direct addressing method (step S160).
[0227] The branch VM instruction analysis unit 1224 determines that the original data portion that was assigned the first tag that triggered the assignment of the second tag to the data moved to the VPC is the branch destination operand (step S161).
[0228] If there is no second tagged data moved to the VPC during execution of the branch VM instruction (step S159: No), the branch VM instruction analysis unit 1224 determines that the addressing method for the branch destination of this branch VM instruction is not the direct addressing method (step S162).
[0229] The branch VM instruction analysis unit 1224 outputs the addressing method of the branch VM instruction as the analysis result and the operands of the branch VM instruction (step S163).
[0230] [Procedure for Relative Addressing Method Analysis Processing] Next, a flow of the relative addressing method analysis processing will be described with reference to Fig. 37. Fig. 40 is a flowchart showing the procedure for the relative addressing method analysis processing shown in Fig. 37.
[0231] The branch VM instruction analysis unit 1224 receives the VPC and the code cache as input (step S171). The branch VM instruction analysis unit 1224 receives the script acquired in the VM instruction collection process as input (step S172). The branch VM instruction analysis unit 1224 executes the script (step S173). The branch VM instruction analysis unit 1224 stops execution when writing the bytecode to the code cache (step S174). The branch VM instruction analysis unit 1224 assigns a first tag to the VPC of the branch VM instruction to be analyzed (step S175).
[0232] The branch VM instruction analysis unit 1224 assigns a second tag to the bytecode in the code cache of the branch VM instruction to be analyzed (step S176).
[0233] The branch VM instruction analysis unit 1224 resumes the execution of the branch VM instruction to be analyzed while propagating the tag in accordance with the movement of data (step S177).
[0234] The branch VM instruction analysis unit 1224 determines whether the first tag and the second tag have been added and moved to the VPC during the execution of the branch VM instruction to be analyzed (step S178).
[0235] If the first tag and the second tag are added and moved to the VPC during execution of the branch VM instruction (step S178: Yes), the branch VM instruction analysis unit 1224 determines that the addressing method of the branch destination of the branch VM instruction being analyzed is a relative addressing method (step S179).
[0236] Then, the branch VM instruction analyzer 1224 determines that the original data portion of the second tag added to the first tag is the operand of the offset of the branch destination (step S180).
[0237] If the first tag and the second tag are not added and moved to the VPC during execution of the branch VM instruction (step S178: No), the branch VM instruction analysis unit 1224 determines that the addressing method for the branch destination of this branch VM instruction is not a relative addressing method (step S181).
[0238] The branch VM instruction analysis unit 1224 outputs the addressing method of the branch VM instruction as the analysis result and the operands of the branch VM instruction (step S182).
[0239] [Procedure for Symbol Table VM Command Determination Processing] Next, a flow of the symbol table VM command determination processing will be described with reference to Fig. 27. Fig. 41 is a flowchart showing the procedure for the symbol table VM command determination processing shown in Fig. 27.
[0240] The symbol table VM instruction determination unit 1225 receives as input a VM execution trace and a memory access trace from the VM execution trace DB 133 (step S191). The symbol table VM instruction determination unit 1225 receives as input the position of the symbol table in the memory area detected in the symbol table detection process (step S192).
[0241] The symbol table VM instruction determination unit 1225 extracts one VM instruction from the VM execution trace (step S193). The VM instruction consists of a VPC value and a VM opcode value. The symbol table VM instruction determination unit 1225 checks the memory area accessed during execution of the extracted VM instruction (step S194) and determines whether the memory area in the symbol table was accessed (step S195).
[0242] If the symbol table memory area is not accessed (step S195: No), the symbol table VM instruction determination unit 1225 determines that the VM instruction extracted in step S193 is not a symbol table VM instruction (step S196).
[0243] If the symbol table memory area is accessed (step S195: Yes), the symbol table VM instruction determination unit 1225 determines whether the VM instruction extracted in step S193 is a read instruction out of read and write instructions (step S197).
[0244] If it is a read command (step S197: Yes), the symbol table VM command determination unit 1225 determines that the VM command extracted in step S193 is a read symbol table VM command (step S198).
[0245] On the other hand, if the VM instruction is not a read instruction (step S197: No), the symbol table VM instruction determination unit 1225 determines that the VM instruction extracted in step S193 is a write symbol table VM instruction (step S199).
[0246] The symbol table VM instruction determination unit 1225 determines whether or not all VM instructions in the VM execution trace have been confirmed to be symbol table VM instructions (step S200).
[0247] If it has not been confirmed whether all VM instructions are symbol table VM instructions (step S200: No), the symbol table VM instruction determination unit 1225 extracts the next VM instruction from the VM execution trace (step S201), proceeds to step S194, and continues processing.
[0248] If it has been confirmed that all VM instructions are symbol table VM instructions (step S200: Yes), the symbol table VM instruction determination unit 1225 outputs a list of the opcodes of the VM instructions determined to be symbol table VM instructions (step S202) and terminates the symbol table VM instruction determination process.
[0249] [Procedure for Symbol Table VM Command Analysis Processing] Next, a flow of the symbol table VM command analysis processing will be described with reference to Fig. 27. Figs. 42 and 43 are flowcharts showing the procedure for the symbol table VM command analysis processing shown in Fig. 27.
[0250] The symbol table VM command analysis unit 1226 receives as input the memory access trace and the VM execution trace according to the fourth test script (step S211).
[0251] The symbol table VM instruction analysis unit 1226 extracts a combination of two symbol table VM instructions from the VM execution trace received in step S211 (step S212). The symbol table VM instruction analysis unit 1226 extracts the combination of symbol table VM instructions by referring to the list of VM instructions determined to be symbol table VM instructions output in the symbol table VM instruction determination process.
[0252] The symbol table VM instruction analysis unit 1226 extracts the portions accessed during the execution of each symbol table VM instruction from the memory access trace received in step S211 (step S213).
[0253] The symbol table VM command analysis unit 1226 compares the parts extracted in step S213 and extracts the differences (step S214).
[0254] The symbol table VM instruction analyzer 1226 determines whether or not a difference exists at the position of the operand (step S215).
[0255] If the difference does not exist at the operand position (step S215: No), the symbol table VM instruction analysis unit 1226 determines whether all symbol table VM instructions of the VM execution trace received as input in step S211 have been processed (step S216).
[0256] If all the symbol table VM instructions in the VM execution trace have not been processed (step S216: No), the symbol table VM instruction analyzer 1226 extracts the next combination of symbol table VM instructions from the VM execution trace received in step S211 (step S217).Then, the symbol table VM instruction analyzer 1226 proceeds to the processing of step S213.
[0257] If the difference exists at the operand position (step S215: Yes), the symbol table VM instruction analyzer 1226 determines that the difference is an operand that specifies a symbol table (step S218).
[0258] If the symbol table VM command analysis unit 1226 has not processed all of the symbol table VM commands of the VM execution trace received as input in step S211 (step S216: Yes), or after processing step S218, it receives the memory access trace and VM execution trace by the fifth test script as input (step S219).
[0259] The symbol table VM instruction analyzer 1226 extracts a combination of two symbol table VM instructions from the VM execution trace received in step S219 (step S220).The symbol table VM instruction analyzer 1226 extracts portions accessed during the execution of each symbol table VM instruction from the memory access trace received in step S219 (step S221).
[0260] The symbol table VM command analysis unit 1226 compares the parts extracted in step S221 and extracts the differences (step S222).
[0261] The symbol table VM instruction analyzer 1226 determines whether or not a difference exists at the position of the operand (step S223).
[0262] If the difference does not exist at the operand position (step S223: No), the symbol table VM instruction analysis unit 1226 determines whether all symbol table VM instructions of the VM execution trace received as input in step S219 have been processed (step S224).
[0263] If all the symbol table VM instructions in the VM execution trace have not been processed (step S224: No), the symbol table VM instruction analyzer 1226 extracts the next combination of symbol table VM instructions from the VM execution trace received in step S219 (step S225).Then, the symbol table VM instruction analyzer 1226 proceeds to the process of step S221.
[0264] If the difference exists at the operand position (step S223: Yes), the symbol table VM command analyzer 1226 determines that the difference is an operand that specifies a variable (step S226).
[0265] When all symbol table VM commands have been processed (step S224: Yes), or after processing step S226, the symbol table VM command analysis unit 1226 outputs information on operands that specify symbol tables and information on operands that specify variables based on the determination results of steps S218 and S226 (step S227).
[0266] [Extraction Process Procedure] Next, a flow of the extraction process shown in Fig. 27 will be described. Fig. 44 is a flowchart showing the extraction process procedure shown in Fig. 27.
[0267] The extraction unit 1231 receives a porting script as input (step S231). The extraction unit 1231 executes the porting script while monitoring writing and execution of the code cache, and performs a bytecode extraction process to extract data written to the code cache as bytecode (step S232).
[0268] The extraction unit 1231 executes the porting script while monitoring the writing of the symbol table detected by the symbol table detection unit 1216, and performs a symbol table extraction process to extract the data written to the symbol table as a symbol table (step S233).
[0269] The extraction unit 1231 outputs the extracted bytecode and symbol table (step S234).
[0270] [Processing Procedure of Bytecode Extraction Processing] Next, a flow of the bytecode extraction processing will be described with reference to Fig. 44. Fig. 45 is a flowchart showing the processing procedure of the bytecode extraction processing shown in Fig. 44.
[0271] The extraction unit 1231 receives a porting script (step S241). The extraction unit 1231 executes the porting script (step S243) while monitoring writing and execution of the code cache (step S242).
[0272] The extraction unit 1231 determines whether or not writing to the code cache has occurred during execution of the porting script (step S244). If writing to the code cache has occurred (step S244: Yes), the extraction unit 1231 extracts the written data as bytecode (step S245).
[0273] If there is no writing to the code cache (step S244: No), or after processing of step S245, the extraction unit 1231 determines whether a subroutine in the written bytecode is called during execution of the porting script (step S246).
[0274] If a subroutine in the written bytecode is called (step S246: Yes), the extraction unit 1231 extracts the entry point of this subroutine (step S247).
[0275] If the subroutine in the written bytecode is not called (step S246: No), or after the processing of step S247, the extraction unit 1231 determines whether the execution of the porting script has ended (step S248).
[0276] If the execution of the porting script has not ended (step S248: No), the extraction unit 1231 continues the execution of the porting script (step S250) and performs the determination process of step S244.
[0277] If the execution of the porting script has finished (step S248: Yes), the extraction unit 1231 outputs the bytecode and entry point extracted in step S245 and step S247 (step S249).
[0278] [Procedure of Symbol Table Extraction Processing] Next, a description will be given of the flow of the symbol table extraction processing shown in Fig. 44. Fig. 46 is a flowchart showing the procedure of the symbol table extraction processing shown in Fig. 44.
[0279] The extraction unit 1231 receives a porting script (step S261). The extraction unit 1231 executes the porting script (step S263) while monitoring writing to the symbol table (step S262).
[0280] The extraction unit 1231 determines whether or not writing to the symbol table has occurred during execution of the porting script (step S264). If writing to the symbol table has occurred (step S264: Yes), the extraction unit 1231 extracts the written data as the symbol table (step S265).
[0281] If there is no writing to the code cache (step S264: No), or after the process of step S265, the extraction unit 1231 determines whether the execution of the porting script has finished (step S266).
[0282] If the execution of the porting script has not ended (step S266: No), the extraction unit 1231 continues the execution of the porting script (step S267) and performs the determination process of step S264.
[0283] If the execution of the porting script has been completed (step S266: Yes), the extraction unit 1231 outputs the symbol table extracted in step S265 (step S268).
[0284] [Processing Procedure of Porting Process] Next, a flow of the porting process shown in Fig. 27 will be described. Fig. 47 is a flowchart showing the processing procedure of the porting process shown in Fig. 27.
[0285] The porting unit 1232 receives the bytecode and symbol table extracted from the porting script in the extraction process (step S271), and receives the analysis target script as input (step S272).
[0286] The transplantation unit 1232 executes the analysis target script (step S274) while monitoring the execution of the VM command based on the dispatcher (step S273).
[0287] The transplantation unit 1232 stops execution upon execution of the first VM instruction (step S275). The transplantation unit 1232 performs a bytecode transplantation process in which the bytecode for instrumentation is transplanted into the bytecode generated by the script engine in its memory space based on the script to be analyzed, and the bytecode is set to branch to a stub each time a process corresponding to a hook condition is executed (step S276). The transplantation unit 1232 performs a symbol table transplantation process in which the symbol table for instrumentation is transplanted into the symbol table generated by the script engine in its memory space based on the script to be analyzed (step S277).
[0288] [Procedure of Bytecode Porting] Next, a description will be given of the flow of the bytecode porting process shown in Fig. 47. Fig. 48 is a flowchart showing the procedure of the bytecode porting process shown in Fig. 47.
[0289] The porting unit 1232 receives the bytecode extracted by executing the porting script (step S281), and receives the hook condition (step S282).
[0290] The porting unit 1232 maps the bytecode to the memory space of the script engine (step S283). Then, the porting unit 1232 scans the bytecode (step S284) and determines whether or not there is a branch using immediate / direct addressing (step S285).
[0291] If there is a branch of immediate / direct addressing method (step S285: Yes), the transplantation unit 1232 updates the address of the operand to match the address of the mapping destination (step S286).
[0292] If there is no branch using immediate / direct addressing (step S285: No), or after processing step S286, the porting unit 1232 determines whether scanning has been completed up to the return VM instruction at the end of the bytecode (step S287).
[0293] If the return VM instruction has not been scanned (step S287: No), the transplantation unit 1232 continues the scanning (step S288) and proceeds to the determination process of step S285.
[0294] If the return VM instruction has been scanned (step S287: Yes), the transplantation unit 1232 reserves an area for a stub in the memory space of the script engine (step S289).
[0295] The porting unit 1232 adds the instrumentation process by bytecode porting to the stub (step S290). The instrumentation process by bytecode porting is, for example, the process shown in FIG.
[0296] The transplanting unit 1232 sets the program so that it branches to the stub every time a process that satisfies the hook condition is executed (step S291), and then ends the bytecode transplantation process.
[0297] [Procedure for Symbol Table Porting Processing] Next, a description will be given of the flow of the symbol table porting processing shown in Fig. 47. Fig. 49 is a flowchart showing the procedure for the symbol table porting processing shown in Fig. 47.
[0298] The porting unit 1232 receives the symbol table extracted by executing the porting script (step S301).
[0299] The transplantation unit 1232 maps the extracted symbol table to the memory space of the script engine (step S302).
[0300] The transplantation unit 1232 adds a reference to the extracted symbol table to the symbol table of the script to be analyzed (step S303), and ensures consistency between the symbol table of the script to be analyzed and the extracted symbol table (step S304).
[0301] Then, the transplanting unit 1232 scans the bytecode (step S305) and determines whether or not there is a symbol table VM instruction (step S306).
[0302] If there is a symbol table VM command (step S306: Yes), the transplanting unit 1232 updates the operand in accordance with the consistent symbol table (step S307).
[0303] If there is no symbol table VM instruction (step S306: No), or after the process of step S307, the porting unit 1232 determines whether scanning has been completed up to the return VM instruction at the end of the bytecode (step S308).
[0304] If the scanning has not reached the return VM instruction (step S308: No), the transplanting unit 1232 continues the scanning (step S309) and proceeds to the determination process of step S306.
[0305] If scanning has been completed up to the return VM instruction (step S308: Yes), the transplantation unit 1232 ends the symbol table transplantation process.
[0306] [Procedure of Execution Processing] Next, a flow of the execution processing shown in Fig. 27 will be described. Fig. 50 is a flowchart showing the procedure of the execution processing shown in Fig. 27.
[0307] The execution unit 1233 receives the hook setting as an input (step S311), and sets the execution to transition to the stub every time a process that satisfies the hook condition described in the hook setting is executed (step S312).
[0308] The execution unit 1233 resumes the execution of the analysis target script (step S313), and determines whether the execution of the analysis target script has ended (step S314).
[0309] If the execution of the analysis target script has not ended (step S314: No), the execution unit 1233 continues the execution (step S315) and proceeds to the determination process of step S314.
[0310] If the execution of the analysis target script has been completed (step S314: Yes), the execution unit 1233 outputs the execution result (step S316) and ends the execution process.
[0311] [Effects of the embodiment] As described above, in the analysis function-adding device 10 of this embodiment, the virtual machine analysis unit 121 analyzes the VM of the script engine, acquires information about the architecture of the script engine, and acquires architecture information of the symbol table based on the analysis results. In the analysis function-adding device 10, the instruction set architecture analysis unit 122 analyzes the instruction set architecture, which is the system of instructions for the VM, collects VM instructions, and analyzes the VM instructions. Based on the analysis results of the VM and the analysis results of the instruction set architecture, the analysis function-adding device 10 executes a porting script to extract instrumentation bytecode and symbol table, and port them to the bytecode and symbol table generated by the script engine in its memory space based on the script to be analyzed when the script to be analyzed is executed.
[0312] As a result, the analysis function-imparting device 10 can detect various architectural information through analysis based on the acquisition of execution traces and VM execution traces, even for script engines whose VM internal specifications are unknown, thereby enabling the imposition of dynamic bytecode instrumentation functions even for script engines whose internal specifications are unknown and which do not have support functions such as a debugger, without the need for manual individual analysis, design, and implementation.
[0313] The analysis function providing device 10 also transfers the instrumentation bytecode and symbol table extracted by executing the transfer script to the bytecode and symbol table generated by the script engine in its memory space based on the script to be analyzed, thereby enabling analysis of the script executed on the script engine.
[0314] Furthermore, the analysis function providing device 10 can automatically provide dynamic bytecode instrumentation functionality to a variety of script engines by simply providing a test script, thereby realizing dynamic bytecode instrumentation without the need for individual design and execution. This makes dynamic bytecode instrumentation possible for scripts written in various script languages, enabling fine-grained analysis.
[0315] In this way, according to the analysis function-imparting device 10 of this embodiment, by analyzing the script engine and retrofitting it with the function of realizing dynamic bytecode instrumentation, it is possible to automatically impart dynamic bytecode instrumentation functionality to script engines of a wide variety of script languages.
[0316] As described above, this embodiment is useful for analyzing scripts written in a wide variety of scripting languages, and is suitable for implementing dynamic bytecode instrumentation even for scripts for which it is difficult to implement dynamic bytecode instrumentation due to the absence of support functions such as a debugger or unknown internal specifications of the VM.
[0317] Therefore, by using the analysis function-imparting device, analysis function-imparting method, and analysis function-imparting program of this embodiment to impart dynamic bytecode instrumentation functions to various script engines, it is possible to analyze the behavior of scripts in detail and use this information for understanding the behavior of malicious scripts in cybersecurity and for debugging in software development.
[0318] [System Configuration of the Embodiment] The components of the analysis function-imparting device 10 shown in Fig. 4 are conceptual functional components and do not necessarily have to be physically configured as shown. In other words, the specific form of distribution and integration of the functions of the analysis function-imparting device 10 is not limited to that shown, and all or part of the functions can be functionally or physically distributed or integrated in any unit depending on various loads, usage conditions, etc.
[0319] Furthermore, all or any part of the processes performed in the analysis function-imparting device 10 may be realized by a CPU and a program analyzed and executed by the CPU. Furthermore, each process performed in the analysis function-imparting device 10 may be realized as hardware using wired logic.
[0320] Furthermore, among the processes described in the embodiments, all or part of the processes described as being performed automatically can be performed manually. Alternatively, all or part of the processes described as being performed manually can be performed automatically using a known method. In addition, the processing procedures, control procedures, specific names, and information including various data and parameters described above and illustrated can be changed as appropriate unless otherwise specified.
[0321] [Program] Figure 51 is a diagram showing an example of a computer in which the analysis function-imparting device 10 is realized by executing a program. The computer 1000 has, for example, a memory 1010 and a CPU 1020. The computer 1000 also has a hard disk drive interface 1030, a disk drive interface 1040, a serial port interface 1050, a video adapter 1060, and a network interface 1070. These components are connected by a bus 1080.
[0322] The memory 1010 includes a ROM 1011 and a RAM 1012. The ROM 1011 stores a boot program such as a BIOS (Basic Input Output System). The hard disk drive interface 1030 is connected to a hard disk drive 1090. The disk drive interface 1040 is connected to a disk drive 1100. A removable storage medium such as a magnetic disk or optical disk is inserted into the disk drive 1100. The serial port interface 1050 is connected to a mouse 1110 and a keyboard 1120, for example. The video adapter 1060 is connected to a display 1130, for example.
[0323] The hard disk drive 1090 stores, for example, an OS 1091, an application program 1092, a program module 1093, and program data 1094. That is, the program that defines each process of the analysis function-imparting device 10 is implemented as a program module 1093 in which code executable by the computer 1000 is written. The program module 1093 is stored, for example, in the hard disk drive 1090. For example, the program module 1093 for executing the same process as the functional configuration of the analysis function-imparting device 10 is stored in the hard disk drive 1090. The hard disk drive 1090 may be replaced by an SSD (Solid State Drive).
[0324] Furthermore, setting data used in the processing of the above-described embodiment is stored as program data 1094, for example, in memory 1010 or hard disk drive 1090. Then, CPU 1020 reads out program module 1093 or program data 1094 stored in memory 1010 or hard disk drive 1090 into RAM 1012 as necessary and executes them.
[0325] The program module 1093 and program data 1094 may not necessarily be stored in the hard disk drive 1090, but may also be stored in a removable storage medium and read by the CPU 1020 via the disk drive 1100 or the like. Alternatively, the program module 1093 and program data 1094 may be stored in another computer connected via a network (such as a local area network (LAN) or a wide area network (WAN)). The program module 1093 and program data 1094 may then be read by the CPU 1020 from the other computer via the network interface 1070.
[0326] Although the present invention has been described above as an embodiment, the present invention is not limited to the description and drawings that form part of the disclosure of the present invention. In other words, other embodiments, examples, and operational techniques that can be made by those skilled in the art based on the present invention are all included in the scope of the present invention.
[0327] DESCRIPTION OF SYMBOLS 10 Analysis function providing device 11 Input unit 12 Control unit 13 Memory unit 14 Output unit 121 Virtual machine analysis unit 122 Instruction set architecture analysis unit 123 Instrumentation unit 131 Execution trace database (DB) 132 Architecture information DB 133 VM execution trace DB 1211 Execution trace acquisition unit 1212 VM instruction boundary detection unit 1213 Virtual program counter detection unit 1214 Dispatcher detection unit 1215 Code cache detection unit 1216 Symbol table detection unit 1221 VM execution trace acquisition unit 1222 VM instruction collection unit 1223 Branch VM instruction determination unit 1224 Branch VM instruction analysis unit 1225 Symbol table VM instruction determination unit 1226 Symbol table VM instruction analysis unit 1231 Extraction unit 1232 Porting unit 1233 Executive Department
Claims
1. An analysis function-imparting device comprising: a first analysis unit that analyzes a virtual machine of a script engine based on an execution trace obtained by executing a test script while monitoring the binary of the script engine, and detects a symbol table that holds information about variables based on the analysis results; a second analysis unit that analyzes an instruction set architecture, which is the instruction system of the virtual machine, to collect virtual machine instructions, and analyzes the collected virtual machine instructions based on the analysis results of the virtual machine of the script engine and the analysis results of the instruction set architecture; an extraction unit that extracts instrumentation bytecode and symbol table by executing a transplantation script based on the analysis results of the virtual machine and the analysis results of the instruction set architecture; and a transplantation unit that transplants the instrumentation bytecode and symbol table extracted by the extraction unit into the bytecode and symbol table generated by the script engine in the memory space of the script engine based on the script to be analyzed.
2. The analysis function providing device described in claim 1, characterized in that the second analysis unit analyzes, among the collected virtual machine instructions, branch virtual machine instructions that cause a branch within a script and symbol table virtual machine instructions that access the symbol table based on the analysis results of the virtual machine of the script engine and the analysis results of the instruction set architecture.
3. The first analysis unit includes a first acquisition unit that changes the conditions for executing a test script and acquires, as the execution trace, a memory access trace that records the type of memory read or write operation during execution and the memory address and value of the operation target; a first detection unit that clusters the execution trace and detects the boundaries of each virtual machine instruction; a second detection unit that analyzes a plurality of the execution traces using differential execution analysis focusing on the number of memory reads and the boundaries of each virtual machine instruction detected by the first detection unit, and detects a virtual program counter which is a variable indicating the next instruction of the virtual machine to be executed; a third detection unit that analyzes the binary of the script engine based on the boundaries of each virtual machine instruction detected by the first detection unit, and detects a dispatcher; and a fourth detection unit that detects a code cache which is a cache in which virtual machine instructions to be executed are stored from the virtual machine execution trace based on the execution trace, the virtual program counter, and a virtual machine execution trace which is the execution trace executed in the virtual machine. and a fifth detection unit that detects a position in the memory area of the symbol table and a structure that references the characteristic value based on a storage location in the memory area of the characteristic value and a reference source to the characteristic value from the memory access trace of a second test script in which a characteristic value is used, and detects a code location that allocates the memory area of the symbol table from an API trace.
4. The second analysis unit includes: a second acquisition unit that acquires the virtual machine execution trace; a first collection unit that executes a test script while monitoring the virtual program counter and the dispatcher to acquire the virtual machine execution trace, and collects virtual machine instructions from the virtual machine execution trace; a first determination unit that determines, among the virtual machine instructions collected by the first collection unit, a branch virtual machine instruction based on a variation in a change amount of the virtual program counter for each virtual machine opcode of the virtual machine execution trace; a third analysis unit that assigns a tag to a code cache of at least the branch virtual machine instruction to be analyzed, and analyzes an addressing method of the branch destination of the branch virtual machine instruction and an operand of the branch virtual machine instruction based on a movement state of the tag during execution of the branch virtual machine instruction while propagating the tag in accordance with data movement; and a second determination unit that determines, among the virtual machine instructions collected by the first collection unit, a virtual machine instruction that accessed a memory area of the symbol table during execution of the virtual machine instruction, to be a symbol table virtual machine instruction. and a fourth analysis unit that, for a combination of two of the symbol table virtual machine instructions extracted from the virtual machine execution trace, determines that a difference between a portion accessed during execution of each symbol table virtual machine instruction of the combination in the memory access trace is an operand of the symbol table virtual machine instruction, when the difference exists in the position of an operand.
5. The analysis function providing device described in claim 4, characterized in that the extraction unit executes the porting script while monitoring the writing and execution of the code cache, extracts the data written to the code cache as bytecode for instrumentation, executes the porting script while monitoring the writing of the symbol table, and extracts the data written to the symbol table as a symbol table; if the branch virtual machine instruction is present in the binary of the script engine, the porting unit updates the address of the operand according to the address designation method of the branch destination of the branch virtual machine instruction, adds instrumentation processing by bytecode porting to a stub, and sets it to branch to the stub every time a processing corresponding to a hook condition is executed; the porting unit adds a reference to the symbol table extracted by the extraction unit to the script of the script to be analyzed to ensure consistency, and if the symbol table virtual machine instruction is present in the script to be analyzed, updates the operand to match the consistent symbol table.
6. An analysis function providing method executed by an analysis function providing device, comprising: a first analysis step of analyzing a virtual machine of a script engine based on an execution trace obtained by executing a test script while monitoring the binary of the script engine, and detecting a symbol table that holds information about variables based on the analysis result; a second analysis step of analyzing an instruction set architecture, which is the instruction system of the virtual machine, to collect virtual machine instructions, and analyzing the collected virtual machine instructions based on the analysis result of the virtual machine of the script engine and the analysis result of the instruction set architecture; an extraction step of extracting instrumentation bytecode and symbol table by executing a transplantation script based on the analysis result of the virtual machine and the analysis result of the instruction set architecture; and a transplantation step of transplanting the instrumentation bytecode and symbol table extracted in the extraction step into the bytecode and symbol table generated by the script engine in the memory space of the script engine based on the script to be analyzed.
7. A program for providing an analysis function to cause a computer to execute the following steps: a first analysis step of analyzing a virtual machine of a script engine based on an execution trace obtained by executing a test script while monitoring the binary of the script engine, and detecting a symbol table that holds information about variables based on the analysis results; a second analysis step of analyzing an instruction set architecture, which is the instruction system of the virtual machine, to collect virtual machine instructions, and analyzing the collected virtual machine instructions based on the analysis results of the virtual machine of the script engine and the analysis results of the instruction set architecture; an extraction step of extracting instrumentation bytecode and symbol table by executing a transplantation script based on the analysis results of the virtual machine and the analysis results of the instruction set architecture; and a transplantation step of transplanting the instrumentation bytecode and symbol table extracted in the extraction step into the bytecode and symbol table generated by the script engine in the memory space of the script engine based on the script to be analyzed.
Citation Information
Patent Citations
Method and apparatus for detecting and preventing unsafe operation of javascript programs
JP2009521737A
Dynamic instrumentation based on detected errors
US20170102981A1
Analysis function addition device, analysis function addition method, and analysis function addition program
WO2021070393A1
Analysis function addition device, analysis function addition program, and analysis function addition method
WO2022180702A1
Cited By
control system
JP7843957B1
