Analysis device, analysis method, and analysis program
The analysis device analyzes script engines' virtual machines using execution traces to determine branch VM instructions and operands, addressing the challenge of unknown specifications and obfuscation, and enhancing tools for software testing and malware analysis.
Patent Information
- Application Number
- PCT/JP2023/015095
- 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 obtain detailed branch information for script engines with unknown internal VM specifications, particularly in the presence of obfuscation, and fail to analyze complex control flows and bytecode generated by malware.
An analysis device and method that analyzes the script engine's virtual machine based on execution traces, determining branch VM instructions, their addressing methods, and operands by executing test scripts and monitoring binary execution, thereby collecting architectural information without manual reverse engineering.
Enables detailed analysis of branch VM instructions for script engines with unknown VM specifications, facilitating control structure elucidation and improving tools like debuggers and taint analysis for software testing, debugging, and malware analysis.
Smart Images

Figure JP2023015095_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 Branch Information] Obtaining branch information is one of the important elements in script analysis. How the script execution branches is important information for understanding the control flow of the script.
[0004] The branch information here refers to the code points in the script from which the script branches to which other code points. To obtain this branch information, the script needs to be analyzed.
[0005] To achieve this analysis, some script engines provide analysis support functions such as debuggers and bytecode disassemblers, and this can sometimes be achieved using these. However, if such functions are not available, it is necessary to analyze the script independently to determine the branches, which is not easy.
[0006] [Analysis techniques] There are two techniques for analyzing programs, including 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] [Branch Instruction] In a script engine, a branch is performed by a VM instruction that performs branching (called a branch VM instruction). A branch VM instruction generally has information about the branch destination in an operand.
[0012] 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.
[0013] 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.
[0014] 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.
[0015] 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.
[0016] Therefore, in order to clarify the branch destination, the following three pieces of information about the branch VM instruction are required:
[0017] The first is a list of the opcodes of the branch VM instruction, the second is the operands of the branch VM instruction, specifically information indicating which operand holds the branch target, and the third is the addressing scheme of the branch target.
[0018] Here, a method has been proposed that can analyze the VM instructions of an unknown script engine using a test script and identify which opcode instructions are branch VM instructions (Non-Patent Document 1).
[0019] Also, a method has been proposed in which VM instructions contained in unknown bytecodes are analyzed using data tracing based on taint analysis, thereby revealing branch VM instructions (Non-Patent Document 2).
[0020] Toshinori Usui, Tomonori Ikuyo, Yuhei Kawakoya, Makoto Iwamura, and Mikita Matsuura, “Automatically Adding Functions to Script Execution Environments to Avoid Execution Delays and Stops,” Proceedings of the Computer Security Symposium 2021, 2021. Monirul Sharif, Andrea Lanzi, Jonathon Giffin, and Wenke Lee, “Automatic Reverse Engineering of Malware Emulators,” 30th IEEE Symposium on Security and Privacy, 2009.
[0021] However, the technique described in Non-Patent Document 1 has a problem in that it only determines the opcode of a branch VM instruction, and does not disclose a technique for analyzing operands.
[0022] Furthermore, the method described in Non-Patent Document 2 targets only information obtained from the actually executed parts of the VM and its bytecode used by malware for obfuscation, and has the problem that it cannot be directly applied to the VM used by a script engine and the bytecode generated from a script.Furthermore, the method described in Non-Patent Document 2 also has the problem that it does not disclose a method for analyzing complex control flows, such as calls using function name symbols, which can be seen in script bytecode.
[0023] 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 obtain detailed information about branch VM instructions for a script engine whose internal specifications of the VM are unknown.
[0024] 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 a second analysis unit that analyzes the instruction set architecture, which is the system of instructions for the virtual machine, to collect virtual machine instructions, determines from the collected virtual machine instructions a branch virtual machine instruction that causes a branch within a script based on the analysis results of the virtual machine of the script engine and the analysis results of the instruction set architecture, and analyzes the addressing method of the branch destination of the branch virtual machine instruction and the operand of the branch virtual machine instruction.
[0025] According to the present invention, detailed information about a branch VM instruction can be obtained for a script engine whose internal specifications of the VM are unknown.
[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 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 used to determine a branch VM instruction. FIG. 6 is a diagram illustrating an example of an execution trace. FIG. 7 is a diagram illustrating an example of a VM execution trace. FIG. 8 is a diagram illustrating processing by a VM instruction boundary detection unit. FIG. 9 is a diagram illustrating processing by a virtual program counter detection unit. FIG. 10 is a diagram illustrating processing by a dispatcher detection unit. FIG. 11 is a diagram illustrating processing by a code cache detection unit. FIG. 12 is a diagram illustrating processing by a branch VM instruction determination unit. FIG. 13 is a diagram illustrating processing by a branch VM instruction analysis unit. FIG. 14 is a diagram illustrating processing by a branch VM instruction analysis unit. FIG. 15 is a diagram illustrating processing by a branch VM instruction analysis unit. FIG. 16 is a flowchart illustrating a processing procedure of analysis processing according to an embodiment. FIG. 17 is a flowchart showing the processing procedure for the execution trace acquisition processing shown in FIG. 16. FIG. 18 is a flowchart showing the processing procedure for the VM instruction boundary detection processing shown in FIG. 16. FIG. 19 is a diagram illustrating the processing of the virtual program counter detection unit shown in FIG. 16. FIG. 20 is a diagram illustrating the processing of the dispatcher detection unit shown in FIG. 16. FIG. 21 is a flowchart showing the processing procedure for the code cache detection processing shown in FIG. 16. FIG. 22 is a diagram illustrating the VM execution trace acquisition processing shown in FIG. 16. FIG. 23 is a flowchart showing the processing procedure for the VM instruction collection processing shown in FIG. 16. FIG. 24 is a flowchart showing the processing procedure for the branch VM instruction determination processing shown in FIG. 16. FIG. 25 is a flowchart showing the processing procedure for the branch VM instruction analysis processing shown in FIG. 16. FIG. 26 is a flowchart showing the processing procedure for the immediate addressing method analysis processing shown in FIG. 25. FIG. 27 is a flowchart showing the processing procedure for the direct addressing method analysis processing shown in FIG. 25. FIG. 28 is a flowchart showing the processing procedure for the relative addressing method analysis processing shown in FIG. 25.FIG. 29 is a diagram illustrating an example of a computer that implements the analysis device by executing a program.
[0027] DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS The present invention will be described in detail below with reference to the accompanying drawings, in which: FIG.
[0028] An analysis device according to an embodiment executes a first 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 traces, and acquires, as architecture information, VM instruction boundaries, a virtual program counter (VPC), and a code cache in which executed VM instructions are stored.
[0029] The analyzer executes the second test script while monitoring the VPC and the dispatcher to acquire a VM execution trace. The analyzer analyzes the VM execution trace to collect VM instructions and determine which of the collected VM instructions are branch VM instructions. The analyzer analyzes the addressing method of the branch destination of the branch VM instruction and the operands of the branch VM instruction.
[0030] 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.
[0031] 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.
[0032] 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.
[0033] 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).
[0034] A branch VM instruction is a VM instruction that causes a branch to occur within a script.
[0035] [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.
[0036] 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 inputs of a test script, a script engine binary, and a seed script.
[0037] 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.
[0038] The test script is a script that is input when dynamically analyzing the script engine to obtain an execution trace and a VM execution trace, and includes a first test script for VM analysis and a second test script for branch VM instruction detection. Details of the test script will be described later. The script engine binary is an executable file that constitutes the script engine. The script engine binary may be composed of multiple executable files.
[0039] [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.
[0040] 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.
[0041] 5 shows an example of a second test script used to detect a branch VM instruction. The second test script uses multiple conditional branches (lines 4 to 8). In the second test script, the branch conditions are controlled so that the multiple conditional branches are either taken or not taken in a specific order pattern (lines 1 and 5). In the second test script, the number of conditional branches and the order pattern of branch success / failure are changed to generate differences.
[0042] 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).
[0043] 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.
[0044] [Configuration of Execution Trace] Next, the execution trace will be described. Fig. 6 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. 6 shows an excerpt of a part of the execution trace. Hereinafter, the configuration of the execution trace will be shown using Fig. 8.
[0045] An execution trace has an element called trace, which indicates whether the log line is a branch trace or a memory access trace.
[0046] A branch trace log line has the format shown in lines 1 to 10 of Figure 6, 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.
[0047] A log line of a memory access trace has the format shown in lines 11 to 13 of Figure 6, 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.
[0048] [Configuration of VM Execution Trace] Next, a VM execution trace will be described. Fig. 7 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. 7 shows a portion of a VM execution trace. The configuration of a VM execution trace will be described below with reference to Fig. 7.
[0049] A log line of a VM execution trace is, for example, in the format shown in FIG. 7 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.
[0050] 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).
[0051] 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.
[0052] 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), and a code cache detection unit 1215 (fourth detection unit).
[0053] The execution trace acquisition unit 1211 receives the first test script and the script engine binary as input, and acquires an execution trace by executing the first test script while monitoring the execution of the script engine binary.
[0054] 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.
[0055] The VM instruction boundary detection unit 1212 clusters the execution traces to detect the boundaries of each VM instruction. The VM instruction boundary detection unit 1212 clusters the execution traces and detects clusters with a threshold or more of execution count as VM instructions. 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 instructions as boundaries. The VM instruction boundaries detected here are used in VPC detection and dispatcher detection.
[0056] 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.
[0057] 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.
[0058] 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.
[0059] 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.
[0060] 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.
[0061] 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.
[0062] 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, from the collected VM instructions, branch VM instructions that cause a branch 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.
[0063] 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 (first determination unit), and a branch VM instruction analysis unit 1224 (third analysis unit).
[0064] The VM execution trace acquisition unit 1221 receives as input a second test script and a script engine binary that use values characteristic of the operation target. The VM execution trace acquisition unit 1221 acquires a VM execution trace by monitoring the VPC and a pointer to a VM instruction handler dispatched by a dispatcher. The VM execution trace acquisition unit 1221 executes the second test script while monitoring the execution of the script engine binary, thereby acquiring a VM execution trace, which is an execution trace executed on the VM. When detecting a branch VM instruction, the VM execution trace acquisition unit 1221 executes a large number of second test scripts to acquire a VM execution trace. 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.
[0065] Like the execution trace acquisition unit 1211, 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 a VPC and a pointer to a VM instruction handler dispatched by a dispatcher. The VM execution trace acquisition unit 1221 acquires a VM execution trace, which is an execution trace executed on a VM, by executing a second test script while monitoring the execution of the script engine binary. When detecting a branch VM instruction, the VM execution trace acquisition unit 1221 executes a large number of second test scripts to acquire a VM execution trace. The VM execution trace acquisition unit 1221 associates a pointer to a VM instruction with the VM instruction and virtually assigns a VM opcode as an identifier to each.
[0066] 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.
[0067] The VM instruction collection unit 1222 receives the VPC and the dispatcher as input, executes the second test script while monitoring the VPC and the dispatcher, and acquires a VM execution trace. The VM instruction collection unit 1222 collects VM instructions from the VM execution trace.
[0068] The branch VM instruction determination unit 1223 determines a branch VM instruction from among the VM instructions collected by the VM instruction collection unit 1222. The branch VM instruction determination unit 1223 determines a branch VM instruction from among the VM instructions collected by the VM instruction collection unit 1222 based on the variation in the amount of change in VPC for each VM opcode in the VM execution trace.
[0069] The branch VM instruction determination unit 1223 retrieves and analyzes the VM execution trace stored in the VM execution trace DB 133 to determine whether the VM instruction is 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.
[0070] 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. 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.
[0071] 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.
[0072] 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.
[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 an external device and the output unit 14, 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. 8 , 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 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. 9 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. 9 , 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. 9 ).
[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. 9 ).
[0079] [Processing of the Dispatcher Detection Unit] Next, the processing of the dispatcher detection unit 1214 will be described. The dispatcher detection unit 1214 detects dispatchers by analyzing the binary of the script engine using a predetermined method. Fig. 10 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. 10 ), 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. 10 ).
[0081] [Code Cache Detector] Next, a description will be given of the processing of the code cache detector 1216. FIG.
[0082] The code cache detection unit 1216 detects the memory area pointed to by the VPC as a code cache from the VM execution trace ((1) in FIG. 11).
[0083] The code cache detection unit 1216 detects the code location that called the memory allocation function that allocated this code cache from the execution trace ((2) in FIG. 11). The code cache detection unit 1216 detects all memory areas allocated at this code location from the VM execution trace as code caches ((3) in FIG. 11).
[0084] The code cache detection unit 1216 detects a code location that writes to the code cache from the execution trace ((4) in FIG. 11). The code cache detection unit 1216 detects the write by this code location from the VM execution trace as an update of the code cache ((5) in FIG. 11).
[0085] [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 (second test script) here is sufficient as long as it contains a branch VM instruction, and is not limited to the example shown in FIG. 5 , 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.
[0086] 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.
[0087] 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.
[0088] 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. 12 ) is a branch VM instruction ((1) in FIG. 12 ).
[0089] 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.
[0090]
[0091]
[0092]
[0093] 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.
[0094] [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.
[0095] 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 13 to 15 are diagrams explaining the processing of the branch VM instruction analysis unit 1224.
[0096] Therefore, the branch VM instruction analysis unit 1224 assigns a taint tag T1 (see FIG. 13) 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. 13).
[0097] 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. 13). 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.
[0098] 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.
[0099] Therefore, the branch VM instruction analysis unit 1224 assigns a first tag T21 (see FIG. 14) 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 analysis unit 1224 assigns a second tag T22 to the referenced data ((1) in FIG. 14).
[0100] 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. 14).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.
[0101] 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.
[0102] Therefore, the branch VM instruction analysis unit 1224 assigns a first tag T31 (see FIG. 15) to the VPC of the branch VM instruction to be analyzed, and assigns a second tag T32 (see FIG. 15) 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.
[0103] 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. 15). 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.
[0104] [Processing Procedure of Analysis Device] Next, a processing procedure of the analysis process by the analysis device 10 will be described. Fig. 16 is a flowchart showing the processing procedure of the analysis process according to the embodiment.
[0105] First, the input unit 11 receives test scripts and script engine binaries as inputs (step S1). The test scripts include a first test script and a second test script.
[0106] Then, the execution trace acquisition unit 1211 executes the first test script while monitoring the binary of the script engine, and performs an execution trace acquisition process to acquire a branch trace and a memory access trace (step S2).
[0107] 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).
[0108] 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).
[0109] Based on the execution trace and the VPC, the code cache detection unit 1215 detects the memory area pointed to by the VPC and the memory area allocated by the same code location as the memory area as code caches, and performs a code cache detection process to detect writing to the code cache as an update to the code cache (step S6).
[0110] 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 S7).
[0111] The VM instruction collection unit 1222 performs a VM instruction collection process to collect VM instructions from the VM execution trace (step S8).
[0112] 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 S9).
[0113] 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 S10).
[0114] The output unit 14 outputs information about the branch VM instruction analyzed in step S10 (step S11).
[0115] [Execution Trace Acquisition Processing Procedure] Next, a flow of the execution trace acquisition processing will be described with reference to Fig. 16. Fig. 17 is a flowchart showing the execution trace acquisition processing procedure shown in Fig. 16.
[0116] First, the execution trace acquisition unit 1211 receives a first 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).
[0117] Then, the execution trace acquisition unit 1211 inputs the first test script received in this state into the script engine to execute it (step S24), and stores the execution trace acquired thereby in the execution trace DB 131 (step S25).
[0118] The execution trace acquisition unit 1211 determines whether all of the input first test scripts have been executed (step S26). If all of the input first 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 first 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.
[0119] [Procedure of VM Instruction Boundary Detection Processing] Next, a flow of the VM instruction boundary detection processing shown in Fig. 16 will be described. Fig. 18 is a flowchart showing the procedure of the VM instruction boundary detection processing shown in Fig. 16 .
[0120] 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.
[0121] 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.
[0122] [Procedure for Virtual Program Counter Detection Processing] Next, a flow of the virtual program counter detection processing shown in Fig. 16 will be described. Fig. 19 is a flowchart showing the procedure for the virtual program counter detection processing shown in Fig. 16.
[0123] First, the virtual program counter detection unit 1213 extracts one execution trace by the first 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).
[0124] The virtual program counter detection unit 1213 receives as input the first 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).
[0125] 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 first 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).
[0126] 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).
[0127] 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.
[0128] [Processing Procedure of Dispatcher Detection Processing] Next, a flow of the dispatcher detection processing shown in Fig. 16 will be described. Fig. 20 is a flowchart showing the processing procedure of the dispatcher detection processing shown in Fig. 16.
[0129] 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).
[0130] 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.
[0131] 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).
[0132] 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.
[0133] [Procedure of Code Cache Detection Processing] Next, a flow of the code cache detection processing shown in Fig. 16 will be described. Fig. 21 is a flowchart showing the procedure of the code cache detection processing shown in Fig. 16.
[0134] 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.
[0135] 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).
[0136] 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.
[0137] [Procedure of VM Execution Trace Acquisition Processing] Next, a flow of the VM execution trace acquisition processing will be described with reference to Fig. 16. Fig. 22 is a flowchart showing the procedure of the VM execution trace acquisition processing shown in Fig. 16.
[0138] First, the VM execution trace acquisition unit 1221 receives the second test script and the script engine binary as input (step S81). Then, the VM execution trace acquisition unit 1221 hooks the received script engine to record the VPC and VM opcode (step S82).
[0139] The VM execution trace acquisition unit 1221 inputs the second test script received in this state into the script engine and executes it (step S83), and stores the VM execution trace acquired thereby in the VM execution trace DB 133 (step S84).
[0140] The VM execution trace acquisition unit 1221 determines whether all of the input second test scripts have been executed (step S85). If all of the input second test scripts have been executed (step S85: Yes), the VM execution trace acquisition unit 1221 ends the process. If all of the input second test scripts have not been executed (step S85: No), the VM execution trace acquisition unit 1221 returns to the execution of the second test script in step S83 and continues the process.
[0141] [Procedure of VM Instruction Collection Processing] Next, a flow of the VM instruction collection processing shown in Fig. 16 will be described. Fig. 23 is a flowchart showing the procedure of the VM instruction collection processing shown in Fig. 16.
[0142] The VM command collection unit 1222 receives a VPC and a dispatcher as input (step S91), acquires various scripts from the Internet (step S92), executes the scripts while monitoring the VPC and the dispatcher, and acquires a VM execution trace (step S93).
[0143] The VM instruction collection unit 1222 acquires VM instructions from the VM execution trace (step S94) and adds them to a list of VM instructions (step S95). If the VM instruction collection unit 1222 finds a VM instruction that is not in the list (step S96: No), the VM instruction collection unit 1222 returns to step S92. If the VM instruction collection unit 1222 finds no VM instructions that are not in the list (step S96: Yes), the VM instruction collection unit 1222 returns the list of VM instructions (step S97) and ends the VM instruction collection process.
[0144] [Branch VM Instruction Determination Processing Procedure] Next, a flow of the branch VM instruction determination processing will be described with reference to Fig. 16. Fig. 24 is a flowchart showing the branch VM instruction determination processing procedure shown in Fig. 16.
[0145] The branch VM instruction determination unit 1223 extracts one VM execution trace from the VM execution trace DB 133 (Step S101). 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 S102). Then, the branch VM instruction determination unit 1223 tallies the amount of change in VPC before and after execution for each VM opcode (Step S103).
[0146] The branch VM instruction determination unit 1223 determines whether all VM execution traces in the VM execution trace DB 133 have been processed (Step S104). If all VM execution traces in the VM execution trace DB 133 have not been processed (Step S104: No), the branch VM instruction determination unit 1223 returns to Step S101 and retrieves and processes the next VM execution trace.
[0147] If all VM execution traces in the VM execution trace DB 133 have been processed (Step S104: Yes), the branch VM instruction determination unit 1223 calculates the variance of the VPC change amount for each VM opcode (Step S105). Then, the branch VM instruction determination unit 1223 receives a threshold as input (Step S106). The branch VM instruction determination unit 1223 narrows down the VM opcodes to only those whose variance is greater than the threshold (Step S107), stores them as branch VM instructions in the architecture information DB 132 (Step S108), and ends the process.
[0148] [Branch VM Instruction Analysis Processing Procedure] Next, a flow of the branch VM instruction analysis processing shown in Fig. 16 will be described. Fig. 25 is a flowchart showing the branch VM instruction analysis processing procedure shown in Fig. 16.
[0149] 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 S111).
[0150] 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 S112).
[0151] 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 S113).
[0152] 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 S114).
[0153] [Procedure of Immediate Addressing Method Analysis Processing] Next, a flow of the immediate addressing method analysis processing shown in Fig. 25 will be described. Fig. 26 is a flowchart showing the procedure of the immediate addressing method analysis processing shown in Fig. 25.
[0154] The branch VM instruction analysis unit 1224 receives the VPC and the code cache as input (step S121). The branch VM instruction analysis unit 1224 receives the script acquired in the VM instruction collection process as input (step S122). The branch VM instruction analysis unit 1224 executes the script (step S123). The branch VM instruction analysis unit 1224 stops execution when writing the bytecode to the code cache (step S124). 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 S125).
[0155] 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 S126).
[0156] 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 S127).
[0157] If there is tagged data moved to the VPC during execution of the branch VM instruction (step S127: 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 S128).
[0158] The branch VM instruction analysis unit 1224 determines that the original data portion, to which the taint tag has been added, moved to the VPC is the operand of the branch destination of the branch VM instruction to be analyzed (step S129).
[0159] On the other hand, if there is no tagged data moved to the VPC during execution of the branch VM instruction (step S127: No), the branch VM instruction analysis unit 1224 determines that the addressing method of the branch destination of the branch VM instruction being analyzed is not the immediate addressing method (step S130).
[0160] 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 S131).
[0161] [Processing Procedure of Direct Addressing Method Analysis Processing] Next, a flow of the direct addressing method analysis processing shown in Fig. 25 will be described. Fig. 27 is a flowchart showing the processing procedure of the direct addressing method analysis processing shown in Fig. 25.
[0162] The branch VM instruction analysis unit 1224 receives the VPC and the code cache as input (step S141). The branch VM instruction analysis unit 1224 receives the script acquired in the VM instruction collection process as input (step S142). The branch VM instruction analysis unit 1224 executes the script (step S143). The branch VM instruction analysis unit 1224 stops execution when writing the bytecode to the code cache (step S144). 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 S145).
[0163] 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 S146).
[0164] 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 S147).
[0165] If the data with the first tag is referenced by a pointer (step S147: Yes), the branch VM instruction analysis unit 1224 assigns a second tag to the referenced data (step S148).
[0166] If the first tagged data is not pointer-referenced (step S147: No), or after processing of step S148, 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 S149).
[0167] If there is second tagged data that has been moved to the VPC during execution of the branch VM instruction being analyzed (step S149: 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 S150).
[0168] 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 S151).
[0169] If there is no second tagged data moved to the VPC during execution of the branch VM instruction (step S149: 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 S152).
[0170] 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 S153).
[0171] [Procedure for Relative Addressing Method Analysis Processing] Next, a flow of the relative addressing method analysis processing shown in Fig. 25 will be described. Fig. 28 is a flowchart showing the procedure for the relative addressing method analysis processing shown in Fig. 25.
[0172] The branch VM instruction analysis unit 1224 receives the VPC and the code cache as input (step S161). The branch VM instruction analysis unit 1224 receives the script acquired in the VM instruction collection process as input (step S162). The branch VM instruction analysis unit 1224 executes the script (step S163). The branch VM instruction analysis unit 1224 stops execution when writing the bytecode to the code cache (step S164). The branch VM instruction analysis unit 1224 assigns a first tag to the VPC of the branch VM instruction to be analyzed (step S165).
[0173] 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 S166).
[0174] 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 S167).
[0175] 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 S168).
[0176] If the first tag and the second tag are added and moved to the VPC during execution of the branch VM instruction (step S168: 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 S169).
[0177] 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 S170).
[0178] If the first tag and the second tag are not added and moved to the VPC during execution of the branch VM instruction (step S168: 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 S171).
[0179] 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 S172).
[0180] [Effects of the embodiment] As described above, the analysis device 10 according to the present embodiment executes the first test script while monitoring the binary of the script engine, and acquires a memory access trace as an execution trace. The analysis device 10 analyzes the VM of the script engine based on the execution trace. The analysis device 10 acquires architecture information of the VPC, dispatcher, and code cache.
[0181] The analysis device 10 analyzes the instruction set architecture, which is the system of instructions for a virtual machine, collects VM instructions, determines which of the collected VM instructions are branch VM instructions, and analyzes the addressing method of the branch destination of the branch VM instruction and the operands of the branch VM instruction.
[0182] Specifically, the analysis device 10 executes the second 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 branch VM instructions, analyze their branch destinations, and acquire the addressing method of the branch destination of the branch VM instruction and the operands of the branch VM instruction as information on the instruction set architecture.
[0183] As a result, 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 detailed information about branch VM instructions without requiring manual reverse engineering.
[0184] Furthermore, the analysis device 10 can automatically analyze branch VM instructions for a variety of script engines as long as a test script is prepared, thereby enabling analysis of the control structure of the script without the need for individual design or execution.
[0185] Therefore, the analysis device 10 can analyze the control structure of scripts written in various script languages, making it possible to understand the behavior in more detail. In this way, the analysis device 10 can analyze the script engine and obtain information about the branch VM instruction, thereby clarifying the control structure of script engines written in a wide variety of script languages.
[0186] As described above, the analysis device 10 according to this embodiment is useful for obtaining information on branch VM instructions in a wide variety of script engines, and is suitable for performing analysis even on scripts whose control structures are difficult to analyze due to the absence of analysis support functions such as a debugger or unknown internal specifications of the VM.
[0187] Therefore, by using the analysis device, analysis method, and analysis program according to the present embodiment to obtain information on branch VM instructions of various script engines, it is possible to realize a tool that analyzes the control structure of a script. For example, the analysis device, analysis method, and analysis program according to the present embodiment can be used to create a debugger or a variable tracer, and can also be expected to be used to enhance taint analysis. As described above, these tools can be used for various purposes, such as software testing and debugging, fuzzing, and malware analysis.
[0188] 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.
[0189] 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.
[0190] 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.
[0191] 29 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 hard disk drive interface 1030, disk drive interface 1040, serial port interface 1050, video adapter 1060, and network interface 1070. These components are connected by bus 1080.
[0192] 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.
[0193] 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).
[0194] 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.
[0195] 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.
[0196] 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.
[0197] 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 1221 VM execution trace acquisition unit 1222 VM instruction collection unit 1223 Branch VM instruction determination unit 1224 Branch 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 a second analysis unit that analyzes an instruction set architecture, which is the system of instructions for the virtual machine, to collect virtual machine instructions, and based on the analysis results of the virtual machine of the script engine and the instruction set architecture, determines which of the collected virtual machine instructions are branch virtual machine instructions that cause a branch within a script, and analyzes the addressing method of the branch destination of the branch virtual machine instruction and the operands of the branch virtual machine instruction.
2. The analysis device according to claim 1, characterized in that the first analysis unit comprises: a first acquisition unit that acquires multiple execution traces by changing execution conditions; a first detection unit that clusters the execution traces and detects boundaries of each virtual machine instruction; a second detection unit that analyzes the multiple 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 that indicates 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 the virtual machine execution trace, which is the execution trace executed in the virtual machine.
3. The analysis device according to claim 2, wherein 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 which of the virtual machine instructions collected by the first collection unit is a branch virtual machine instruction based on variations in the amount of change in the virtual program counter for each virtual machine opcode in the virtual machine execution trace; and a third analysis unit that assigns a tag to a code cache of the branch virtual machine instruction to be analyzed, and analyzes the addressing method of the branch destination of the branch virtual machine instruction and the operands of the branch virtual machine instruction based on the movement state of the tag during execution of the branch virtual machine instruction while propagating the tag in accordance with data movement.
4. The analysis device according to claim 3, wherein the third analysis unit assigns a tag to the code cache of the branch virtual machine instruction to be analyzed, and if there is tagged data moved to the virtual program counter during execution of the branch virtual machine instruction while propagating the tag in accordance with the movement of data, determines that the addressing method for the branch destination of the branch virtual machine instruction is an immediate addressing method, which directly specifies the address of the branch destination, and determines that the original data portion of the data moved to the virtual program counter with the tag assigned is the branch destination operand of the branch virtual machine instruction to be analyzed.
5. The analysis device according to claim 3, wherein the third analysis unit assigns a first tag to the code cache of the branch virtual machine instruction to be analyzed, and if data with the first tag is referenced by a pointer during execution of the branch virtual machine instruction while propagating the first tag as the data moves, assigns a second tag to the referenced data, and if data with the second tag is moved to the virtual program counter during execution of the branch virtual machine instruction to be analyzed, determines that the addressing method for the branch destination of the branch virtual machine instruction to be a direct addressing method, which is a method for specifying a memory area in which the address of the branch destination is stored, and determines that the original data portion to which the first tag was assigned is an operand of the branch destination for the first tag that triggered the assignment of the second tag to the data moved to the virtual program counter.
6. The analysis device according to claim 3, wherein the third analysis unit assigns a first tag to the virtual program counter of the branch virtual machine instruction of the analysis target and assigns a second tag to the code cache of the branch virtual machine instruction of the analysis target, and when the first tag and the second tag are added and moved to the virtual program counter during execution of the branch virtual machine instruction of the analysis target while propagating the first tag and the second tag in accordance with data movement, determines that the addressing method for the branch destination of the branch virtual machine instruction of the analysis target is a relative addressing method, which is a method of specifying an offset from the current virtual program counter, and determines that the original data portion of the second tag added to the first tag is an operand of the offset of the branch destination.
7. An analysis method executed by an analysis device, comprising: a first analysis step of analyzing a 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 a second analysis step of analyzing an instruction set architecture, which is the system of instructions for the virtual machine, to collect virtual machine instructions, and based on the analysis results of the virtual machine of the script engine and the instruction set architecture, determining, from the collected virtual machine instructions, a branch virtual machine instruction that causes a branch within a script, and analyzing the addressing method of the branch destination of the branch virtual machine instruction and the operand of the branch virtual machine instruction.
8. An analysis program for causing a computer to execute the following steps: a first analysis step of analyzing 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 a second analysis step of analyzing the instruction set architecture, which is the system of instructions for the virtual machine, to collect virtual machine instructions, and based on the analysis results of the virtual machine of the script engine and the instruction set architecture, determining from the collected virtual machine instructions which branch virtual machine instructions cause a branch within the script, and analyzing the addressing method of the branch destination of the branch virtual machine instruction and the operand of the branch virtual machine instruction.
Citation Information
Patent Citations
Microcomputer development supporting device
JP1994202874A
Analysis function addition device, analysis function addition program, and analysis function addition method
WO2022180702A1
