Analysis device, analysis method, and analysis program
The analysis device analyzes virtual machines and execution traces to extract variable information from symbol tables, addressing the challenge of obfuscated scripts and unknown scripting languages, enabling detailed variable analysis in diverse script engines.
Patent Information
- Application Number
- PCT/JP2023/015088
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-04-13
- Publication Date
- 2024-10-17
AI Technical Summary
Existing methods struggle to analyze variable information in scripts, particularly when scripts are obfuscated, as they fail to effectively handle unknown scripting languages and lack support functions like debuggers, making it difficult to obtain necessary information about variable scopes, counts, values, and access points during static analysis.
An analysis device and method that monitors the script engine's binary execution, analyzes the virtual machine, and collects execution traces to detect and analyze symbol tables, even for unknown scripting languages, by executing test scripts and identifying VM instructions that access symbol tables, thereby extracting variable information.
Enables the acquisition of variable information from symbol tables in various script engines, even without known internal specifications, facilitating detailed behavior understanding and variable analysis, especially in cases where traditional analysis support is absent.
Smart Images

Figure JP2023015088_17102024_PF_FP_ABST
Abstract
Description
Analysis device, analysis method, and analysis program
[0001] The present invention relates to an analysis device, an analysis method, and an analysis 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] [Importance of Obtaining Variable Information] Obtaining variable information is one of the important elements in analyzing a script. What variables a script holds when it is executed is important information for understanding the functionality of the script.
[0004] The variable information here includes information such as how many variables exist in what scope, what values each variable holds, which code part reads and writes to which variable, etc. To obtain such variable information, it is necessary to analyze the script.
[0005] To achieve this analysis, analysis support functions such as debuggers and bytecode disassemblers are provided, and they can sometimes be used. However, if such functions are not available, it is necessary to analyze the script independently to obtain variable information, which is not easy.
[0006] [Analysis techniques] There are two techniques for analyzing programs that contain scripts: static analysis and dynamic analysis. Dynamic analysis is a technique that analyzes the behavior of the program by actually executing it and observing its behavior. Static analysis is a technique that analyzes the function of the program by interpreting its meaning without executing it. These analysis techniques are used to obtain branching information.
[0007] [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.
[0008] 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.
[0009] [Script execution method] Scripts are executed by a crypto 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.
[0010] 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.
[0011] [About Symbol Tables] In script engines, variables are generally managed by symbol tables. Symbol tables are tables that store information such as the names of variables and subroutines, and are created in the semantic analysis phase. Symbol tables in script engines generally hold information such as name, type (variable, subroutine, etc.), scope, attributes (depending on the type, for example, whether it is a constant or variable, or type), and value. Access to such symbol tables is realized through VM commands (hereafter referred to as symbol table VM commands) prepared for this purpose.
[0012] Therefore, in order to clarify the information about the variables used by the script, the following four pieces of information about the symbol table are required:
[0013] The first is the memory location of the symbol table and the code that allocates the memory for the symbol table. The second is the structure of the symbol table. The third is a list of the opcodes of the symbol table VM instructions. The fourth is the operands of the symbol table VM instructions, specifically which operands identify the scope and variables.
[0014] A method has been proposed for analyzing executable binary programs and restoring their data structures (Non-Patent Document 1). According to the method described in Non-Patent Document 1, it is possible to restore part of the symbol table and obtain variable information.
[0015] Asia Slowinska, Traian Stancescu, and Herbert Bos, “Howard: a Dynamic Excavator for Reverse Engineering Data Structures”, In Proceedings of the 18 the Network and Distributed Systems Security Symposium, 2011.
[0016] However, the technique described in Non-Patent Document 1 does not target the symbol table held by the script engine, and does not realize the structure of the symbol table specific to scripts or the analysis of the aforementioned symbol table VM commands, so there is a problem that it cannot be directly applied.
[0017] The present invention has been made in consideration of the above, and aims to provide an analysis device, an analysis method, and an analysis program that can analyze a VM symbol table and analyze VM commands that access the symbol table, even for script engines of a wide variety of script languages whose specifications are unknown, and can obtain information about variables managed by the symbol table.
[0018] In order to solve the above-mentioned problems and achieve the object, the analysis 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, and a second analysis unit that analyzes the virtual machine of the script engine, collects virtual machine instructions based on the analysis results, and analyzes the collected virtual machine instructions based on the analysis results.
[0019] According to the present invention, even for script engines of a wide variety of script languages whose specifications are unknown, it is possible to analyze the symbol table of a VM and analyze the VM instructions that access the symbol table to obtain information on variables managed by the symbol table.
[0020] 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 the configuration of an analysis device according to an embodiment. FIG. 4 is a diagram illustrating an example of a first test script used to detect a virtual program counter (VPC). FIG. 5 is a diagram illustrating an example of a second test script. FIG. 6 is a diagram illustrating an example of a third test script. FIG. 7 is a diagram illustrating an example of a fourth test script. FIG. 8 is a diagram illustrating an example of a fourth test script. FIG. 9 is a diagram illustrating an example of an execution trace. FIG. 10 is a diagram illustrating an example of a VM execution trace. FIG. 11 is a diagram illustrating an example of a symbol table structure. FIG. 12 is a diagram illustrating processing by a symbol table detection unit. FIG. 13 is a diagram illustrating processing by a symbol table VM instruction analysis unit. FIG. 14 is a diagram illustrating processing by a symbol table VM instruction analysis unit. FIG. 15 is a diagram illustrating processing by a VM instruction boundary detection unit. FIG. 16 is a diagram illustrating processing by a virtual program counter detection unit. FIG. 17 is a diagram illustrating processing by a dispatcher detection unit. FIG. 18 is a diagram illustrating processing by a code cache detection unit. FIG. 19 is a flowchart showing the processing procedure for analysis processing according to an embodiment. FIG. 20 is a flowchart showing the processing procedure for execution trace acquisition processing shown in FIG. 19. FIG. 21 is a flowchart showing the processing procedure for VM instruction boundary detection processing shown in FIG. 19. FIG. 22 is a diagram illustrating processing by the virtual program counter detection unit shown in FIG. 19. FIG. 23 is a diagram illustrating processing by the dispatcher detection unit shown in FIG. 19. FIG. 24 is a flowchart showing the processing procedure for code cache detection processing shown in FIG. 19. FIG. 25 is a flowchart showing the processing procedure for symbol table detection processing shown in FIG. 19. FIG. 26 is a flowchart showing the processing procedure for VM execution trace acquisition processing shown in FIG. 19. FIG. 27 is a flowchart showing the processing procedure for VM instruction collection processing shown in FIG. 19. FIG. 28 is a flowchart showing the processing procedure for symbol table VM instruction determination processing shown in FIG. 19. FIG. 29 is a flowchart showing the processing procedure for symbol table VM instruction analysis processing shown in FIG. 19. FIG. 30 is a flowchart showing the processing procedure for symbol table VM instruction analysis processing shown in FIG. 19.FIG. 31 is a diagram illustrating an example of a computer that implements the analysis device by executing a program.
[0021] DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS The present invention will be described in detail below with reference to the accompanying drawings, in which: FIG.
[0022] [Embodiment] An analysis device according to an embodiment executes a test script while monitoring the binary of a script engine, and acquires branch traces and memory access traces as execution traces. The analysis device analyzes a virtual machine (VM) based on the execution trace, and acquires, as architecture information, VM instruction boundaries, a virtual program counter (VPC), a dispatcher, 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 device detects a symbol table that stores information about variables.
[0023] The analysis device analyzes the instruction set architecture, which is the system of instructions for the virtual machine. The analysis device executes a test script while monitoring the VPC and the dispatcher, and acquires a VM execution trace. The analysis device collects VM instructions by analyzing the VM execution trace. Of the collected VM instructions, the analysis device determines which symbol table VM instructions access a symbol table based on the VM analysis results of the script engine, and analyzes the access destination of the symbol table VM instruction. In this way, the analysis device acquires information on variables managed by the symbol table.
[0024] 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.
[0025] 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.
[0026] 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.
[0027] 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).
[0028] [Configuration of Analysis Apparatus] Next, the configuration of the analysis apparatus 10 according to the embodiment will be specifically described with reference to Fig. 3. Fig. 3 is a diagram illustrating an example of the configuration of the analysis apparatus 10 according to the embodiment.
[0029] 3, the analysis device 10 includes an input unit 11, a control unit 12, a storage unit 13, and an output unit 14. The analysis device 10 receives input of a test script and a script engine binary.
[0030] The input unit 11 is composed of input devices such as a keyboard and a mouse, and receives 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 receives input of information transmitted from other devices. The input unit 11 receives input of test scripts and script engine binaries and outputs them to the control unit 12.
[0031] The test scripts are scripts that are input when dynamically analyzing the script engine to obtain an execution trace and a VM execution trace, and include a first test script for VM analysis, a second test script for symbol table detection, and a third test script and a fourth test script for symbol table VM command 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.
[0032] [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.
[0033] 4 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.
[0034] FIG. 5 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. 5, 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.
[0035] 6 is a diagram showing an example of a third test script. The third test script accesses variables (e.g., "a" and "b") in two different scopes (e.g., "func1" and "func2"). From the memory access trace by the third 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.
[0036] 7 and 8 are diagrams showing an example of a fourth test script. The fourth test script is a test script that accesses two different variables (e.g., "a" and "b") within the same scope. From the memory access trace obtained by the fourth test script, differences between the parts accessed during execution of each symbol table VM instruction of the second combination are compared with the operand positions to determine whether the differences are operands that specify variables. Note that both the third and fourth 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.
[0037] 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 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).
[0038] 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 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.
[0039] [Configuration of Execution Trace] Next, an execution trace will be described. Fig. 9 is a diagram showing an example of an execution trace. An execution trace is made up of a branch trace and a memory access trace. Fig. 9 shows an excerpt of a part of an execution trace. Hereinafter, the configuration of an execution trace will be shown using Fig. 6.
[0040] An execution trace has an element called trace, which indicates whether the log line is a branch trace or a memory access trace.
[0041] A branch trace log line has the format shown in lines 1 to 10 of Figure 9, 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.
[0042] A log line of a memory access trace has the format shown in lines 11 to 13 of Figure 9, 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.
[0043] [Configuration of VM Execution Trace] Next, a VM execution trace will be described. Fig. 10 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. 10 shows a portion of a VM execution trace. The configuration of a VM execution trace will be described below with reference to Fig. 10.
[0044] A log line of a VM execution trace is, for example, in the format shown in FIG. 10 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.
[0045] A symbol table exists for each scope. Fig. 11 is a diagram showing an example of the structure of a symbol table. As shown in the symbol table 210 in Fig. 11, 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 indicating a variable, constant, or function, and the third row shows the address of the object entity.
[0046] Returning to Fig. 3, 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) and an instruction set architecture analysis unit 122 (second analysis unit).
[0047] 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 the VPC. 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 execution trace. The code cache stores the VM instructions to be executed. The virtual machine analysis unit 121 detects a symbol table.
[0048] 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).
[0049] The execution trace acquisition unit 1211 receives the first to fourth test scripts and the script engine binary as input. The execution trace acquisition unit 1211 acquires an execution trace by executing the first to fourth test scripts while monitoring the execution of the script engine binary.
[0050] 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.
[0051] 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.
[0052] 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, by searching for common subsequences of executed code blocks, or by other methods. The analysis 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.
[0053] 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.
[0054] 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.
[0055] 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 generally has high similarity. The analysis 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.
[0056] 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.
[0057] 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.
[0058] The code cache detection unit 1215 detects code locations that write to the code cache from the execution trace. The code cache detection unit 1215 detects writing by these code locations in the execution trace as updates to the code cache. Note that in this embodiment, the code cache is not directly used for detecting the symbol table and analyzing the symbol table VM instructions, so the code cache detection unit 1215 and the code cache detection process described below can be omitted.
[0059] 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.
[0060] FIG. 12 is a diagram illustrating the processing of the symbol table detection unit 1216. 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 the 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. Since values appear in the memory access trace when the symbol table is created ((1) in FIG. 12), the symbol table detection unit 1216 detects variables in the symbol table by matching the characteristic value of the second test script ((2) in FIG. 12). The symbol table detection unit 1216 detects areas in the structure that reference the characteristic value and where the references are concentrated as the symbol table ((3) in FIG. 12). Specifically, the symbol table detection unit 1216 detects code locations that allocate memory space for the symbol table from the API trace. The symbol table detection unit 1216 outputs the location of the symbol table in the memory area and the code portion that reserves that area.
[0061] The instruction set architecture analysis unit 122 analyzes the instruction set architecture, which is the system of instructions for the VM of the script engine. The instruction set architecture analysis unit 122 analyzes the VM of the script engine and collects VM instructions based on the analysis results of the VM of the script engine. The instruction set architecture analysis unit 122 determines, among the collected VM instructions based on the analysis results of the VM of the script engine, symbol table VM instructions that access a symbol table, and analyzes the access destination of the symbol table VM instruction.
[0062] 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 symbol table VM instruction determination unit 1223 (first determination unit), and a symbol table VM instruction analysis unit 1224 (second analysis unit).
[0063] 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 and fourth 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.
[0064] 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.
[0065] 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.
[0066] The symbol table VM instruction determination unit 1223 determines, among the VM instructions collected by the VM instruction collection unit 1222, a VM instruction that accessed a memory area of a symbol table during VM execution as a symbol table VM instruction. Among the VM instructions that accessed the memory area of the symbol table, the symbol table VM instruction determination unit 1223 determines a VM instruction that commands a read as a read symbol table VM instruction. Among the VM instructions that accessed the memory area of the symbol table, the symbol table VM instruction determination unit 1223 determines 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 1223 outputs a list indicating the VM instructions determined to be symbol table VM instructions and their types.
[0067] The symbol table VM instruction analyzer 1224 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 1224 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]...", so the position of the operand can be determined if the VPC and opcode are known.
[0068] 13 is a diagram illustrating the processing of the symbol table VM instruction analyzer 1224. The symbol table VM instruction analyzer 1224 determines an operand that specifies a symbol table by using a memory access trace by a third test script that accesses variables in two different scopes ((1) in FIG. 13) and a VM execution trace.
[0069] For a first combination of two symbol table VM instructions extracted from the VM execution trace by the third test script, the symbol table VM instruction analyzer 1224 extracts, from the memory access trace by the third 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 1224 determines that the difference is an operand specifying a symbol table ((2) in FIG. 13 ).
[0070] 14 is a diagram illustrating the processing of the symbol table VM instruction analyzer 1224. The symbol table VM instruction analyzer 1224 determines the operand that specifies the variable by using the memory access trace and the VM execution trace by the fourth test script that accesses two different variables in the same scope ((1) in FIG. 14).
[0071] For a second combination of two symbol table VM instructions extracted from the VM execution trace by the fourth test script, the symbol table VM instruction analyzer 1224 extracts, from the memory access trace by the fourth 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 1224 determines that the difference is an operand specifying a variable ((2) in FIG. 14 ).
[0072] The symbol table VM instruction analyzer 1224 outputs information on operands that specify a symbol table and information on operands that specify a variable.
[0073] The output unit 14 is, for example, a liquid crystal display or a printer, and outputs various information including information related to the analysis device 10. The output unit 14 may also be an interface that controls input and output of various data between the output unit 14 and an external device, and may output various information to the external device.
[0074] [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.
[0075] 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. 15 , 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 a continuous instruction sequence that constitutes a VM instruction as boundaries.
[0076] [Processing of 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. 16 is a diagram explaining the processing of the virtual program counter detection unit 1213.
[0077] 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. 16 , 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. 16 ).
[0078] 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. 16 ).
[0079] [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. 17 is a diagram illustrating the processing of the dispatcher detection unit 1214.
[0080] 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. 17), 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. 17).
[0081] [Code Cache Detector] Next, a description will be given of the processing of the code cache detector 1215. FIG.
[0082] 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. 18).
[0083] 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. 18). 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. 18).
[0084] The code cache detection unit 1215 detects a code location that writes to the code cache from the execution trace ((4) in FIG. 18). 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. 18).
[0085] [Processing Procedure of Analysis Device] Next, a processing procedure of the analysis process by the analysis device 10 will be described. Fig. 19 is a flowchart showing the processing procedure of the analysis process according to the embodiment.
[0086] First, the input unit 11 receives a test script and a script engine binary as input (step S1). The test script includes a test script.
[0087] 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).
[0088] 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).
[0089] 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).
[0090] 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).
[0091] 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).
[0092] 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).
[0093] The VM instruction collection unit 1222 performs a VM instruction collection process to collect VM instructions from the VM execution trace (step S9).
[0094] The symbol table VM instruction determination unit 1223 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 S10).
[0095] The symbol table VM instruction analysis unit 1224 analyzes the operands of the symbol table VM instruction to be analyzed, and performs symbol table VM instruction analysis processing to determine the operands that specify the symbol table and the operands that specify the variables (step S11).
[0096] The output unit 14 outputs the symbol table detected in step S7 and information on the symbol table VM instructions analyzed in steps S10 and S11 (step S12).
[0097] [Execution Trace Acquisition Processing Procedure] Next, a flow of the execution trace acquisition processing will be described with reference to Fig. 19. Fig. 20 is a flowchart showing the execution trace acquisition processing procedure shown in Fig. 19.
[0098] 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).
[0099] 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).
[0100] 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.
[0101] [Procedure for VM Instruction Boundary Detection Processing] Next, a flow of the VM instruction boundary detection processing shown in Fig. 19 will be described. Fig. 21 is a flowchart showing the procedure for the VM instruction boundary detection processing shown in Fig. 19 .
[0102] 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.
[0103] 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.
[0104] [Procedure for Virtual Program Counter Detection Processing] Next, a flow of the virtual program counter detection processing shown in Fig. 19 will be described. Fig. 22 is a flowchart showing the procedure for the virtual program counter detection processing shown in Fig. 19.
[0105] 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).
[0106] The virtual program counter detection unit 1213 receives as input the test script used to acquire the execution trace (step S43), analyzes the test script, and acquires the number of repetitions and the number of repeated statements (step S44).
[0107] Next, the virtual program counter detection unit 1213 extracts another execution trace from the execution trace DB 131, which is a test script with a different number of repetitions and number of repeated statements (step S45).The virtual program counter detection unit 1213 then focuses on memory access traces 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 obtain the execution trace (step S47), analyzes the test script, and obtains the number of repetitions and the number of repeated statements (step S48).
[0108] 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).
[0109] 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.
[0110] [Processing Procedure of Dispatcher Detection Processing] Next, a flow of dispatcher detection processing will be described with reference to Fig. 19. Fig. 23 is a flowchart showing the processing procedure of dispatcher detection processing shown in Fig. 19.
[0111] 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).
[0112] 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.
[0113] 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).
[0114] 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.
[0115] [Processing Procedure of Code Cache Detection Processing] Next, a flow of the code cache detection processing shown in Fig. 19 will be described. Fig. 24 is a flowchart showing the processing procedure of the code cache detection processing shown in Fig. 19.
[0116] 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.
[0117] 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).
[0118] 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.
[0119] [Procedure of Symbol Table Detection Processing] Next, a flow of the symbol table detection processing will be described with reference to Fig. 19. Fig. 25 is a flowchart showing the procedure of the symbol table detection processing shown in Fig. 19.
[0120] 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).
[0121] 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).
[0122] 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.
[0123] 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).
[0124] 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.
[0125] 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).
[0126] [Procedure of VM Execution Trace Acquisition Processing] Next, a flow of the VM execution trace acquisition processing will be described with reference to Fig. 19. Fig. 26 is a flowchart showing the procedure of the VM execution trace acquisition processing shown in Fig. 19.
[0127] 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).
[0128] 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).
[0129] 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 test scripts have been executed (step S95: Yes), the VM execution trace acquisition unit 1221 ends the process. If all of the input test scripts have not been executed (step S95: No), the VM execution trace acquisition unit 1221 returns to the execution of the test scripts in step S93 and continues the process.
[0130] [Procedure of VM Instruction Collection Processing] Next, a flow of the VM instruction collection processing shown in Fig. 1 will be described. Fig. 27 is a flowchart showing the procedure of the VM instruction collection processing shown in Fig. 19 .
[0131] 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).
[0132] 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.
[0133] [Procedure of Symbol Table VM Command Determination Processing] Next, a flow of the symbol table VM command determination processing will be described with reference to Fig. 19. Fig. 28 is a flowchart showing the procedure of the symbol table VM command determination processing shown in Fig. 19.
[0134] The symbol table VM instruction determination unit 1223 receives as input a VM execution trace and a memory access trace from the VM execution trace DB 133 (step S111). The symbol table VM instruction determination unit 1223 receives as input the position of the symbol table in the memory area detected in the symbol table detection process (step S112).
[0135] The symbol table VM instruction determination unit 1223 extracts one VM instruction from the VM execution trace (step S113). The VM instruction consists of a VPC value and a VM opcode value. The symbol table VM instruction determination unit 1223 checks the memory area accessed during execution of the extracted VM instruction (step S114) and determines whether the memory area in the symbol table was accessed (step S115).
[0136] If the symbol table memory area is not accessed (step S115: No), the symbol table VM instruction determination unit 1223 determines that the VM instruction extracted in step S113 is not a symbol table VM instruction (step S116).
[0137] If the symbol table memory area is accessed (step S115: Yes), the symbol table VM instruction determination unit 1223 determines whether the VM instruction extracted in step S113 is a read instruction out of read and write instructions (step S117).
[0138] If it is a read command (step S117: Yes), the symbol table VM command determination unit 1223 determines that the VM command extracted in step S113 is a read symbol table VM command (step S118).
[0139] On the other hand, if the VM instruction is not a read instruction (step S117: No), the symbol table VM instruction determination unit 1223 determines that the VM instruction extracted in step S113 is a write symbol table VM instruction (step S119).
[0140] After the process of step S116, step S118, or step S119, the symbol table VM instruction determination unit 1223 determines whether or not it has been confirmed that all VM instructions in the VM execution trace are symbol table VM instructions (step S120).
[0141] If it has not been confirmed whether all VM instructions are symbol table VM instructions (step S120: No), the symbol table VM instruction determination unit 1223 extracts the next VM instruction from the VM execution trace (step S121), proceeds to step S114, and continues processing.
[0142] If it has been confirmed that all VM instructions are symbol table VM instructions (step S120: Yes), the symbol table VM instruction determination unit 1223 outputs a list of the opcodes of the VM instructions determined to be symbol table VM instructions (step S122) and terminates the symbol table VM instruction determination process.
[0143] [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. 19. Figs. 29 and 30 are flowcharts showing the procedure for the symbol table VM command analysis processing shown in Fig. 19.
[0144] The symbol table VM command analysis unit 1224 receives as input a memory access trace and a VM execution trace according to the third test script (step S131).
[0145] The symbol table VM instruction analysis unit 1224 extracts a combination of two symbol table VM instructions from the VM execution trace received in step S131 (step S132). The symbol table VM instruction analysis unit 1224 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.
[0146] The symbol table VM instruction analysis unit 1224 extracts the portions accessed during the execution of each symbol table VM instruction from the memory access trace received in step S131 (step S133).
[0147] The symbol table VM command analysis unit 1224 compares the parts extracted in step S133 and extracts the differences (step S134).
[0148] The symbol table VM instruction analyzer 1224 determines whether or not a difference exists at the position of the operand (step S135).
[0149] If the difference does not exist at the operand position (step S135: No), the symbol table VM instruction analysis unit 1224 determines whether all symbol table VM instructions of the VM execution trace received as input in step S131 have been processed (step S136).
[0150] If all the symbol table VM instructions in the VM execution trace have not been processed (step S136: No), the symbol table VM instruction analyzer 1224 extracts the next combination of symbol table VM instructions from the VM execution trace received in step S131 (step S137).Then, the symbol table VM instruction analyzer 1224 proceeds to the process of step S133.
[0151] If the difference exists at the operand position (step S135: Yes), the symbol table VM instruction analyzer 1224 determines that the difference is an operand that specifies a symbol table (step S138).
[0152] If the symbol table VM command analysis unit 1224 has not processed all of the symbol table VM commands of the VM execution trace received as input in step S131 (step S136: Yes), or after processing step S138, it receives the memory access trace and VM execution trace by the fourth test script as input (step S139).
[0153] The symbol table VM instruction analyzer 1224 extracts a combination of two symbol table VM instructions from the VM execution trace received in step S139 (step S140).The symbol table VM instruction analyzer 1224 extracts a portion accessed during execution of each symbol table VM instruction from the memory access trace received in step S139 (step S141).
[0154] The symbol table VM command analysis unit 1224 compares the parts extracted in step S141 and extracts the differences (step S142).
[0155] The symbol table VM instruction analyzer 1224 determines whether or not a difference exists at the position of the operand (step S143).
[0156] If the difference does not exist at the operand position (step S143: No), the symbol table VM instruction analysis unit 1224 determines whether all symbol table VM instructions of the VM execution trace received as input in step S139 have been processed (step S144).
[0157] If all the symbol table VM instructions in the VM execution trace have not been processed (step S144: No), the symbol table VM instruction analyzer 1224 extracts the next combination of symbol table VM instructions from the VM execution trace received in step S139 (step S145).Then, the symbol table VM instruction analyzer 1224 proceeds to the process of step S141.
[0158] If the difference exists at the operand position (step S143: Yes), the symbol table VM command analyzer 1224 determines that the difference is an operand that specifies a variable (step S146).
[0159] When all symbol table VM commands have been processed (step S144: Yes), or after processing step S146, the symbol table VM command analysis unit 1224 outputs information on operands that specify symbol tables and information on operands that specify variables based on the determination results of steps S138 and S146 (step S147).
[0160] As described above, the analysis device 10 according to the present embodiment executes a test script while monitoring the binary of the script engine, and acquires branch traces and memory access traces as execution traces. Based on the execution traces, the analysis device 10 analyzes the VM of the script engine and acquires architecture information of the VPC, dispatcher, code cache, and symbol table.
[0161] Specifically, the analysis device 10 detects the location in the memory area of the symbol table and the structure that references the characteristic value based on the storage location in the memory area of the characteristic value and the reference source of the characteristic value from the memory access trace of the second test script in which the characteristic value is used.The analysis device 10 then detects the code location that allocates the memory area for the symbol table from the API trace.
[0162] In this way, the analysis device 10 acquires the location of the symbol table in the memory area, the code portion that reserves the memory area for the symbol table, and the structure of the symbol table as architecture information of the symbol table.
[0163] The analysis device 10 then analyzes the instruction set architecture, which is a system of instructions for the virtual machine. For example, the analysis device 10 collects VM instructions based on the analysis result of the VM of the script engine, identifies symbol table VM instructions from the collected VM instructions, and analyzes the access destinations of the symbol table VM instructions.
[0164] Specifically, the analysis device 10 executes the test script while monitoring the VPC and the dispatcher to acquire a VM execution trace. The analysis device 10 analyzes the VM execution trace to collect VM instructions, determine which VM instructions access the symbol table, and analyze the access destination.
[0165] Specifically, for a combination of two symbol table VM instructions extracted from the VM execution trace, if a difference between parts accessed during execution of each symbol table VM instruction in the memory access trace exists at the position of an operand, the analysis device 10 determines that the difference is the operand of the symbol table VM instruction. Based on this determination, the analysis device 10 obtains a list of opcodes of the symbol table VM instructions, operands that specify symbol tables, information about the operands that specify symbol tables, and information about the operands that specify variables.
[0166] In this way, the analysis device 10 can detect various architectural information by analyzing the execution trace and VM execution trace obtained, even for script engines whose VM internal specifications are unknown, and can obtain symbol table information without requiring manual reverse engineering.
[0167] Furthermore, the analysis device 10 can automatically analyze symbol tables for a variety of script engines as long as test scripts are prepared, so variable information can be obtained without the need for individual design or execution.
[0168] This enables the analysis device 10 to analyze variables even for scripts written in various script languages, enabling more detailed behavior understanding. In this way, the analysis device 10 according to the present embodiment can clarify variable information for script engines written in a wide variety of script languages by analyzing the script engine and acquiring symbol table information.
[0169] As described above, the analysis device 10 according to this embodiment is useful for obtaining symbol table information for a wide variety of script engines, and is suitable for performing analysis even on scripts for which analyzing variable information is difficult due to the absence of analysis support functions such as a debugger or unknown internal specifications of the VM.
[0170] Therefore, by using the analysis device, analysis method, and analysis program according to this embodiment to obtain information on the symbol tables of various script engines, it is possible to realize a tool for analyzing script variables.
[0171] 3 are conceptual functional components of the analysis device 10 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 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.
[0172] Furthermore, all or any part of the processes performed by analysis device 10 may be realized by a CPU and a program analyzed and executed by the CPU. Furthermore, each process performed by analysis device 10 may be realized as hardware using wired logic.
[0173] 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.
[0174] 31 is a diagram showing an example of a computer in which analysis device 10 is realized by executing a program. Computer 1000 has, for example, memory 1010 and CPU 1020. 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.
[0175] 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.
[0176] 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 device 10 is implemented as a program module 1093 in which code that can be executed 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 device 10 is stored in the hard disk drive 1090. Note that the hard disk drive 1090 may be replaced with an SSD (Solid State Drive).
[0177] 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.
[0178] 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.
[0179] 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.
[0180] 10 Analysis device 11 Input unit 12 Control unit 13 Memory unit 14 Output unit 121 Virtual machine analysis unit 122 Instruction set architecture analysis 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 Symbol table VM instruction determination unit 1224 Symbol table VM instruction analysis unit
Claims
1. An analysis 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; and a second analysis unit that analyzes the virtual machine of the script engine, collects virtual machine instructions based on the analysis results, and analyzes the collected virtual machine instructions based on the analysis results.
2. The analysis device described in claim 1, characterized in that the second analysis unit determines, based on the analysis results of the virtual machine of the script engine, among the collected virtual machine instructions, which symbol table virtual machine instructions access the symbol table, and analyzes the access destination of the symbol table virtual machine instructions.
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 analysis device according to claim 3, characterized in that the second analysis unit comprises: 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 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 second analysis unit that, for a combination of two of the symbol table virtual machine instructions extracted from the virtual machine execution trace, if a difference between a portion accessed during execution of each symbol table virtual machine instruction of the combination in the memory access trace exists at an operand position, determines that the difference is an operand of the symbol table virtual machine instruction.
5. The analysis device described in claim 4, characterized in that the second analysis unit extracts, for a first combination of two of the symbol table virtual machine instructions extracted from the virtual machine execution trace by the third test script that accesses variables of two different scopes, from the memory access trace by the third test script, the parts accessed during execution of each symbol table virtual machine instruction of the first combination, and if a difference between the two extracted parts exists at an operand position, determines that the difference is an operand that specifies the symbol table.
6. The analysis device described in claim 4, characterized in that the second analysis unit extracts, for a second combination of two of the symbol table virtual machine instructions extracted from the virtual machine execution trace by the fourth test script that accesses two different variables within the same scope, the parts accessed during execution of each symbol table virtual machine instruction of the second combination from the memory access trace by the fourth test script, and if the difference between the two extracted parts exists at the position of an operand, determines that the difference is an operand that specifies the variable.
7. An analysis method executed by an analysis 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; and a second analysis step of analyzing the virtual machine of the script engine, collecting virtual machine instructions based on the analysis result, and analyzing the collected virtual machine instructions based on the analysis result.
8. An analysis program for causing 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 result; and a second analysis step of analyzing a virtual machine of the script engine, collecting virtual machine instructions based on the analysis result, and analyzing the collected virtual machine instructions based on the analysis result.
Citation Information
Patent Citations
Execution trace display device, execution trace display method, and execution trace display program
JP2013254320A
Analysis function imparting device, analysis function imparting method, and analysis function imparting program
WO2022079840A1
Analysis function addition device, analysis function addition program, and analysis function addition method
WO2022180702A1
