JP4945296B2 - Code detection apparatus and code detection method - Google Patents

Code detection apparatus and code detection method Download PDF

Info

Publication number
JP4945296B2
JP4945296B2 JP2007107482A JP2007107482A JP4945296B2 JP 4945296 B2 JP4945296 B2 JP 4945296B2 JP 2007107482 A JP2007107482 A JP 2007107482A JP 2007107482 A JP2007107482 A JP 2007107482A JP 4945296 B2 JP4945296 B2 JP 4945296B2
Authority
JP
Japan
Prior art keywords
code
analysis
detection
information
unit
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
JP2007107482A
Other languages
Japanese (ja)
Other versions
JP2008217751A (en
Inventor
拓 藤本
晃 金野
敬 鈴木
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
NTT Docomo Inc
Original Assignee
NTT Docomo Inc
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by NTT Docomo Inc filed Critical NTT Docomo Inc
Priority to JP2007107482A priority Critical patent/JP4945296B2/en
Publication of JP2008217751A publication Critical patent/JP2008217751A/en
Application granted granted Critical
Publication of JP4945296B2 publication Critical patent/JP4945296B2/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Description

本発明は、複数のコードを含むプログラムコードを解析することで検出対象コードを検出するコード検出装置及びコード検出方法に関する。 The present invention relates to a code detection apparatus and a code detection method for detecting a detection target code by analyzing a program code including a plurality of codes.

複数のコード(命令)を含むプログラムコードの解析をプログラム実行中に行う動的解析技術が知られている。動的解析技術は、プログラムコード中の少なくとも1つのコードからなるブロック単位で各コードを変換及び実行するインタプリンタ実行を利用することで実現される。また、プログラムコード中の特定のコードを実行させるか否かを制御するプログラム実行制御技術が知られている。   There is known a dynamic analysis technique for analyzing a program code including a plurality of codes (instructions) during program execution. The dynamic analysis technique is realized by using an interpreter execution that converts and executes each code in a block unit including at least one code in the program code. Further, a program execution control technique for controlling whether or not to execute a specific code in the program code is known.

さらに、インタプリンタ実行を用いるプログラム実行制御技術が提案されている(非特許文献1及び2参照)。インタプリンタ実行を用いるプログラム実行制御技術では、図1に示すように、プログラムコードをブロック単位で解析することで検出対象コードが検出される。   Furthermore, a program execution control technique using execution of an interpreter has been proposed (see Non-Patent Documents 1 and 2). In the program execution control technique using interpreter execution, as shown in FIG. 1, the detection target code is detected by analyzing the program code in units of blocks.

検出された検出対象コードには、プログラム実行制御用のコードであるフックコードが追加される。フックコードの追加されたコードは、プログラム実行時に、当該コードを実行するか否かを制御する実行制御コードへ分岐させられる。フックコードは検出対象コードの直前に追加されるため、フックコードをバイパスすることは不可能であり、検出対象コードの実行を確実に制御することができる。   A hook code, which is a code for controlling program execution, is added to the detected code to be detected. The code to which the hook code is added is branched to an execution control code for controlling whether or not to execute the code at the time of program execution. Since the hook code is added immediately before the detection target code, it is impossible to bypass the hook code, and the execution of the detection target code can be reliably controlled.

なお、インタプリンタ実行の実行単位であるブロックとしては、例えば、プログラムコード中の2つの分岐命令に挟まれた領域が用いられる。分岐が発生するまでは、メモリのアドレス降順でプログラムコードが実行されるので、通常の動作から逸脱することはない。また、分岐命令まで実行されれば、分岐先のアドレスが判明し、次に読み込むブロックが特定される。このため、プログラムコードをブロック単位で順次解析及び実行可能となる。   As a block that is an execution unit of interpreter execution, for example, an area sandwiched between two branch instructions in a program code is used. Until the branch occurs, the program code is executed in descending order of the memory addresses, so that there is no deviation from the normal operation. If the branch instruction is executed, the branch destination address is determined, and the next block to be read is specified. Therefore, the program code can be sequentially analyzed and executed in units of blocks.

非特許文献1は、インタプリンタ実行を用いるプログラム実行制御技術を利用したmobile code実行の安全化方法を開示している。ここでmobile codeとは、ネットワーク経由で取得したプログラムコードである。   Non-Patent Document 1 discloses a method for securing mobile code execution using a program execution control technique using interpreter execution. Here, mobile code is a program code acquired via a network.

非特許文献1の方法は、信頼されたプログラムコードの実行中に、当該プログラムコードのメモリ領域に非信頼mobile codeを展開して実行するシステムに適用される。また、非特許文献1の方法は、mobile codeから不正な分岐命令が発行され、本来のリターンアドレスとは異なるコードへ実行制御が移動し、意図しないコードが実行されることを脅威として想定している。   The method of Non-Patent Document 1 is applied to a system that develops and executes an untrusted mobile code in a memory area of the program code during execution of the trusted program code. The method of Non-Patent Document 1 assumes that an illegal branch instruction is issued from mobile code, execution control moves to a code different from the original return address, and an unintended code is executed as a threat. Yes.

非特許文献1の方法は、上記の脅威を防止するために、mobile codeから分岐命令を検出する。検出された分岐命令の直前には、当該分岐分岐命令の実行可否を判定するためのフックコードが追加される。これにより、mobile codeの解析及び変換後にmobile codeを実行する際、不正な分岐命令が実行されることが防止される。   The method of Non-Patent Document 1 detects a branch instruction from the mobile code in order to prevent the above threat. A hook code for determining whether or not to execute the branch branch instruction is added immediately before the detected branch instruction. This prevents an illegal branch instruction from being executed when the mobile code is executed after the analysis and conversion of the mobile code.

一方、非特許文献2は、インタプリンタ実行を用いるプログラム実行制御技術を利用したリソースアクセス制御方法を開示している。当該リソースアクセス制御手法では、プログラムが呼ぶシステムコールに対してアクセス制御が実行される。例えば、特定のファイルの読み出しは許可するが、書き込みは禁止するといったリソースアクセス制御の用途が考えられる。   On the other hand, Non-Patent Document 2 discloses a resource access control method using a program execution control technique using interpreter execution. In the resource access control method, access control is executed for a system call called by a program. For example, it is possible to use the resource access control such that reading of a specific file is permitted but writing is prohibited.

非特許文献2の方法は、プログラムバイナリをブロック毎に読み込み、読み込まれたブロックをStrataと呼ばれるVM(Virtual Machine)上でインタプリンタ実行する。その際、特定のシステムコールを呼ぶコードが検出された場合、当該コードの直前に、Strataが予め備えるアクセス制御コードを呼出すフックコードが追加される。これにより、プログラムコードにアクセス制御対象のシステムコールが含まれる場合には、当該システムコールの実行を許可するか否かを判定可能となる。   In the method of Non-Patent Document 2, a program binary is read for each block, and the read block is executed by an interpreter on a VM (Virtual Machine) called Strata. At this time, when a code that calls a specific system call is detected, a hook code that calls an access control code provided in advance by Strata is added immediately before the code. Thereby, when a system call subject to access control is included in the program code, it is possible to determine whether or not to permit execution of the system call.

上記のように、非特許文献1及び2の手法は、プログラムコード内での関数呼出等、プログラムコード外部からの監視が不可能なコードについても制御可能である点で、他のプログラム制御技術やアクセス制御技術よりも優れている。   As described above, the methods of Non-Patent Documents 1 and 2 are capable of controlling even a code that cannot be monitored from outside the program code, such as a function call in the program code. Better than access control technology.

さらにStrataは、インタプリンタ実行のオーバヘッドを削減する技術として、一度インタプリンタ実行を行ったブロックをメモリ上にキャッシュとして保持する機能を備えている。キャッシュは、ブロックのアドレスと、解析済み(コンパイル済み)コードとの組で蓄積される。Strataでは、図2に示すように、実行中のプログラムコードのアドレスをカウントするプログラムカウンタを参照することで、現時点でのプログラムコードのアドレスが特定され、現時点でのプログラムコードのアドレスをキーとしてキャッシュが検索される。   Furthermore, Strata has a function of holding blocks that have been executed once as a cache in a memory as a cache as a technique for reducing the overhead of execution of the interpreter. The cache is stored in pairs of block addresses and parsed (compiled) code. As shown in FIG. 2, in Strata, the address of the current program code is specified by referring to the program counter that counts the address of the program code being executed, and cached using the current program code address as a key. Is searched.

キャッシュされている場合、現時点でのプログラムコードのアドレスに対応する解析済みコードが実行される。一方、キャッシュされていない場合、通常のインタプリンタ実行が行われる。これにより、同一のプログラムコードを複数回インタプリンタ実行する場合に、2回目以降のインタプリンタ実行に要するオーバヘッドが削減される。
Robert Wahbe et.al., “Efficient software-based fault isolation”, In Proc. of the fourteenth ACM Symposium on Operating Systems Principals, 1994. Kevin Scott et.al., “Safe virtual execution using software dynamic translation”, In Proc. of 18th Annual Computer Security Applications Conference, 2002.
If cached, the analyzed code corresponding to the current program code address is executed. On the other hand, if not cached, normal interpreter execution is performed. As a result, when the same program code is executed by the printer a plurality of times, the overhead required for the second and subsequent executions of the printer is reduced.
Robert Wahbe et.al., “Efficient software-based fault isolation”, In Proc. Of the fourteenth ACM Symposium on Operating Systems Principals, 1994. Kevin Scott et.al., “Safe virtual execution using software dynamic translation”, In Proc. Of 18th Annual Computer Security Applications Conference, 2002.

上述した非特許文献1及び、Strataのキャッシュ機能を利用しない場合の非特許文献2の手法では、次の(1)〜(5)のプロセスが実行される。   In the methods of Non-Patent Document 1 and Non-Patent Document 2 when the Strata cache function is not used, the following processes (1) to (5) are executed.

(1)プログラムコードからあるブロックが読み込まれる。   (1) A block is read from the program code.

(2)当該ブロックを構成するコードが解析される。   (2) The code constituting the block is analyzed.

(3)解析により検出対象コードが検出された場合には、当該検出対象コードにフックコードが追加される。   (3) When a detection target code is detected by analysis, a hook code is added to the detection target code.

(4)ブロック内のコード解析後、当該ブロックが実行される。   (4) After analyzing the code in the block, the block is executed.

(5)当該ブロックの実行中にフックコードが検出されると、実行制御コードが呼出される。   (5) If a hook code is detected during execution of the block, the execution control code is called.

しかしながら、プロセス(2)、(3)及び(5)は、通常のプログラム実行では発生しないプロセスであり、オーバヘッド増加の要因となり得る。特に、プロセス(2)において各ブロック内のコードを解析する処理や、プロセス(3)においてフックコードを追加する処理にコストを要する。   However, processes (2), (3), and (5) are processes that do not occur in normal program execution, and may cause an increase in overhead. In particular, the process of analyzing the code in each block in the process (2) and the process of adding the hook code in the process (3) require a cost.

一方、非特許文献2においてStrataのキャッシュ機能を利用した場合でも、キャッシュミスの発生時には、上記と同等のオーバヘッドが発生する。 キャッシュミスは、あるブロックが最初に実行される際には必ず発生する。あるいは、搭載メモリ容量の少ない計算機(例えば、携帯型デバイス)では、キャッシュ領域に割り当て可能なメモリ容量が限られるので、キャッシュミスの発生を避けることは困難である。   On the other hand, even when the Strata cache function is used in Non-Patent Document 2, an overhead equivalent to the above occurs when a cache miss occurs. A cache miss always occurs when a block is first executed. Alternatively, in a computer with a small installed memory capacity (for example, a portable device), since the memory capacity that can be allocated to the cache area is limited, it is difficult to avoid the occurrence of a cache miss.

以上のように、複数のコードを含むプログラムコードを解析することで検出対象コードを検出するプログラム解析システムでは、オーバヘッドを削減することが困難であった。   As described above, it is difficult to reduce overhead in a program analysis system that detects a detection target code by analyzing a program code including a plurality of codes.

上記問題点に鑑み、本発明は、複数のコードを含むプログラムコードを解析することで検出対象コードを検出するプログラム解析システムにおいて、オーバヘッドを削減可能なコード検出装置及びコード検出方法を提供することを目的とする。   In view of the above problems, the present invention provides a code detection apparatus and a code detection method capable of reducing overhead in a program analysis system for detecting a detection target code by analyzing a program code including a plurality of codes. Objective.

上記目的を達成するために、本発明の第1の特徴は、複数のコードを含むプログラムコードを解析することで検出対象コードを検出するコード検出装置であって、前記プログラムコードを解析する第1解析部と、前記第1解析部による解析結果を用いて前記プログラムコードを解析する第2解析部とを備え、前記第1解析部は、前記プログラムコードから前記検出対象コードを検出する第1検出部と、前記第1検出部による検出結果に基づき、前記プログラムコードのうち前記第2解析部が解析対象とする領域である解析対象領域を特定するための解析情報を生成する解析情報生成部とを備え、前記第2解析部は、前記解析情報を参照することで前記プログラムコード中の前記解析対象領域を特定する特定部と、前記特定部によって特定された前記解析対象領域から前記検出対象コードを検出する第2検出部とを備えることを要旨とする。   In order to achieve the above object, a first feature of the present invention is a code detection apparatus for detecting a detection target code by analyzing a program code including a plurality of codes, the first code analyzing the program code An analysis unit; and a second analysis unit that analyzes the program code using an analysis result obtained by the first analysis unit, wherein the first analysis unit detects the detection target code from the program code. And an analysis information generation unit that generates analysis information for specifying an analysis target region that is a region to be analyzed by the second analysis unit in the program code based on a detection result by the first detection unit. The second analysis unit is specified by the specifying unit that specifies the analysis target region in the program code by referring to the analysis information, and the specifying unit. And summarized in that and a second detector for detecting the detection target code from said analysis target area.

このような特徴によれば、特定部は、解析情報を参照することでプログラムコード中の解析対象領域を特定する。第2検出部は、特定部によって特定された解析対象領域から検出対象コードを検出する。第2検出部は、プログラムコードの一部に対して検出対象コードの検出処理を行うので、第2解析部の処理負荷が削減され、オーバヘッドが削減する。   According to such a feature, the specifying unit specifies an analysis target region in the program code by referring to the analysis information. The second detection unit detects a detection target code from the analysis target region specified by the specifying unit. Since the second detection unit performs a detection target code detection process on a part of the program code, the processing load on the second analysis unit is reduced and the overhead is reduced.

本発明の第2の特徴は、本発明の第1の特徴に係り、前記第1解析部は、前記プログラムコードの実行前に前記プログラムコードを解析し、前記第2解析部は、前記プログラムコードの実行中に前記プログラムコードを解析することを要旨とする。   A second feature of the present invention relates to the first feature of the present invention, wherein the first analysis unit analyzes the program code before execution of the program code, and the second analysis unit includes the program code. The gist is to analyze the program code during the execution of the program.

このような特徴によれば、第1解析部がプログラムコードの実行前にプログラムコードを解析し(静的解析)、第2解析部がプログラムコードの実行中にプログラムコードを解析する(動的解析)。第2検出部は、プログラムコードの一部に対して検出対象コードの検出処理を行うので、動的解析の処理負荷が削減される。   According to such a feature, the first analysis unit analyzes the program code before execution of the program code (static analysis), and the second analysis unit analyzes the program code during execution of the program code (dynamic analysis). ). Since the second detection unit performs the detection process of the detection target code for a part of the program code, the processing load of the dynamic analysis is reduced.

本発明の第3の特徴は、本発明の第1の特徴に係り、前記検出対象コードの実行を制御するためのコードであるフックコードを含むプログラム制御情報を記憶する制御情報記憶部をさらに備え、前記第2解析部は、前記解析対象領域から検出された前記検出対象コードに前記フックコードを追加することを要旨とする。   A third feature of the present invention relates to the first feature of the present invention, and further includes a control information storage unit that stores program control information including a hook code that is a code for controlling the execution of the detection target code. The second analysis unit is characterized in that the hook code is added to the detection target code detected from the analysis target region.

このような特徴によれば、第2解析部は、解析対象領域から検出された検出対象コードに、検出対象コードの実行を制御するためのコードであるフックコードを追加する。第2検出部は、プログラムコードの一部に対して検出対象コードの検出処理を行うので、フックコード追加処理の処理負荷が削減される。   According to such a feature, the second analysis unit adds a hook code that is a code for controlling execution of the detection target code to the detection target code detected from the analysis target region. Since the second detection unit performs the detection target code detection process on a part of the program code, the processing load of the hook code addition process is reduced.

本発明の第4の特徴は、本発明の第1の特徴に係り、前記検出対象コードの実行を制御するためのコードであるフックコードを含むプログラム制御情報を記憶する制御情報記憶部をさらに備え、前記第1解析部は、前記プログラムコードから検出された前記検出対象コードに前記フックコードを追加し、前記特定部は、前記第1解析部により前記フックコードの追加されていない領域を前記解析対象領域として特定することを要旨とする。   A fourth feature of the present invention relates to the first feature of the present invention, and further includes a control information storage unit that stores program control information including a hook code that is a code for controlling the execution of the detection target code. The first analysis unit adds the hook code to the detection target code detected from the program code, and the specifying unit analyzes the region where the hook code is not added by the first analysis unit. The gist is to identify the target area.

このような特徴によれば、第1解析部は、検出対象コードにフックコードを追加する。第2解析部の特定部は、フックコードの追加されていない領域を解析対象領域として特定するので、フックコードの追加されている領域は解析対象外とすることができ、第2解析部におけるフックコード追加処理の処理負荷が削減される。   According to such a feature, the first analysis unit adds a hook code to the detection target code. Since the specifying unit of the second analysis unit specifies an area to which no hook code is added as an analysis target area, the area to which the hook code is added can be excluded from the analysis target, and the hook in the second analysis unit can be excluded. The processing load of code addition processing is reduced.

本発明の第5の特徴は、本発明の第4の特徴に係り、前記第1解析部は、所定の条件に応じて、前記プログラムコードから検出された前記検出対象コードに前記フックコードを追加するか否かを判定することを要旨とする。   A fifth feature of the present invention relates to the fourth feature of the present invention, wherein the first analysis unit adds the hook code to the detection target code detected from the program code according to a predetermined condition. The gist is to determine whether or not to do so.

このような特徴によれば、第1解析部は、所定の条件(例えば、プログラムコードのサイズ、処理負荷)に応じて、プログラムコードから検出された検出対象コードにフックコードを追加するか否かを判定する。このため、第1解析部においてフックコードを追加するか否かを適応的に決定できる。   According to such a feature, the first analysis unit determines whether or not to add the hook code to the detection target code detected from the program code according to a predetermined condition (for example, the size of the program code and the processing load). Determine. For this reason, it can be determined adaptively whether a hook code is added in a 1st analysis part.

本発明の第6の特徴は、本発明の第4の特徴に係り、前記第1解析部は、前記フックコードを含むフック専用関数へ分岐する分岐命令を、前記フックコードとして前記検出対象コードに追加することを要旨とする。   A sixth feature of the present invention relates to the fourth feature of the present invention, wherein the first analysis unit uses a branch instruction for branching to a hook dedicated function including the hook code as the hook code in the detection target code. The gist is to add.

このような特徴によれば、第1解析部は、フックコードを直接追加するのではなく、フック専用関数によりフックコードを検出対象コードへ間接的に追加する。これにより、フックコードを直接追加するよりもコードサイズを削減できる。   According to such a feature, the first analysis unit does not directly add the hook code, but indirectly adds the hook code to the detection target code by the hook dedicated function. Thereby, the code size can be reduced as compared with the case where the hook code is directly added.

本発明の第7の特徴は、本発明の第1の特徴に係り、前記検出対象コードを特定する情報を含むプログラム制御情報を記憶する制御情報記憶部をさらに備え、前記第1検出部は、前記プログラム制御情報が更新された場合、更新後の検出対象コードを特定する情報に基づいて前記プログラムコードから前記更新後の検出対象コードを検出し、前記解析情報生成部は、前記第1検出部による前記更新後の検出対象コードの検出結果に基づき、前記解析情報を更新することを要旨とする。   A seventh feature of the present invention relates to the first feature of the present invention, and further includes a control information storage unit that stores program control information including information for specifying the detection target code, and the first detection unit includes: When the program control information is updated, the updated detection target code is detected from the program code based on information for specifying the updated detection target code, and the analysis information generating unit is configured to detect the first detection unit. The gist is to update the analysis information based on the detection result of the detection target code after the update.

このような特徴によれば、検出対象コードが更新された場合に、第1検出部が更新後の検出対象コードを検出し、解析情報生成部が第1検出部による更新後の検出対象コードの検出結果に基づいて解析情報を更新する。これにより、検出対象コードが更新された場合にも対応可能となる。   According to such a feature, when the detection target code is updated, the first detection unit detects the updated detection target code, and the analysis information generation unit detects the detection target code updated by the first detection unit. The analysis information is updated based on the detection result. Thereby, it is possible to cope with the case where the detection target code is updated.

本発明の第8の特徴は、本発明の第1の特徴に係り、前記検出対象コードを特定する情報と、前記検出対象コードの変更先候補のコードである候補コードを特定する情報を含むプログラム制御情報を記憶する制御情報記憶部をさらに備え、前記第1検出部は、前記プログラム制御情報に基づき、前記プログラムコードから前記検出対象コード及び前記候補コードを検出し、前記解析情報生成部は、前記第1検出部による検出結果に基づき、前記プログラムコードのうち前記候補コードを含む領域を特定する再生成情報を生成し、前記第1検出部は、前記プログラム制御情報中の前記検出対象コードを特定する情報が変更された場合、前記再生成情報によって特定される領域から、変更された検出対象コードを検出することを要旨とする。   An eighth feature of the present invention relates to the first feature of the present invention, and is a program that includes information for specifying the detection target code and information for specifying a candidate code that is a code to be changed to the detection target code. A control information storage unit for storing control information; and the first detection unit detects the detection target code and the candidate code from the program code based on the program control information, and the analysis information generation unit includes: Based on the detection result by the first detection unit, the regeneration information for specifying the region including the candidate code in the program code is generated, and the first detection unit generates the detection target code in the program control information. When the information to be specified is changed, the gist is to detect the changed detection target code from the area specified by the regeneration information.

このような特徴によれば、第1検出部は、検出対象コードだけでなく、候補コードも検出する。解析情報生成部は、候補コードを含む領域を特定する再生成情報を生成する。そして、第1検出部は、検出対象コードがいずれかの候補コードに変更された場合に、再生成情報によって特定されるプログラムコードの領域から変更された検出対象コードを検出する。これにより、検出対象コードが変更された場合でも直ちに対応可能となる。   According to such a feature, the first detection unit detects not only the detection target code but also the candidate code. The analysis information generation unit generates regeneration information that identifies an area including the candidate code. Then, when the detection target code is changed to any candidate code, the first detection unit detects the changed detection target code from the program code area specified by the regeneration information. As a result, even when the detection target code is changed, it is possible to cope immediately.

本発明の第9の特徴は、本発明の第1の特徴に係り、前記検出対象コードは、前記プログラムコード中の特定のコードを呼出す制御移動命令であり、前記第1検出部及び前記第2検出部は、前記プログラムコードから制御移動命令を検出した場合、検出された制御移動命令の呼出先コードが前記特定のコードであるか否かを判定し、前記検出された制御移動命令の呼出先コードが前記特定のコードである場合、前記検出された制御移動命令が前記検出対象コードであると判定することを要旨とする。   A ninth feature of the present invention relates to the first feature of the present invention, wherein the detection target code is a control movement command for calling a specific code in the program code, and the first detection unit and the second detection unit When detecting a control movement instruction from the program code, the detection unit determines whether a call destination code of the detected control movement instruction is the specific code, and calls the detected control movement instruction When the code is the specific code, the gist is to determine that the detected control movement command is the detection target code.

このような特徴によれば、検出対象コードがプログラムコード中の特定のコードを呼出す制御移動命令である場合に、当該制御移動命令が確実に検出される。   According to such a feature, when the detection target code is a control movement instruction for calling a specific code in the program code, the control movement instruction is reliably detected.

本発明の第10の特徴は、本発明の第1の特徴に係り、前記第2解析部は、解析済みのコードである解析済みコードを記憶するキャッシュ記憶部をさらに備え、前記第2検出部は、前記解析対象領域から前記検出対象コードが検出された場合、前記検出対象コードを含む前記解析対象領域に対応する解析済みコードを前記キャッシュ記憶部から取得することを要旨とする。   A tenth feature of the present invention relates to the first feature of the present invention, wherein the second analysis unit further includes a cache storage unit that stores an analyzed code that is an analyzed code, and the second detection unit Is summarized in that, when the detection target code is detected from the analysis target area, the analyzed code corresponding to the analysis target area including the detection target code is acquired from the cache storage unit.

このような特徴によれば、検出対象コードを含む検出対象領域に対応する解析済コードを再利用することで、第2解析部の処理負荷が削減される。   According to such a feature, the processing load of the second analysis unit is reduced by reusing the analyzed code corresponding to the detection target area including the detection target code.

本発明の第11の特徴は、本発明の第1の特徴に係り、前記第1解析部は、前記プログラムコードのうち前記検出対象コードを含まない領域を非解析対象領域として検出し、前記解析情報は、前記非解析対象領域を特定する情報を含み、前記第2解析部の前記特定部は、前記非解析対象領域を特定する情報が示す領域を除いた前記プログラムコードの領域を前記解析対象領域として特定することを要旨とする。   An eleventh feature of the present invention relates to the first feature of the present invention, wherein the first analysis unit detects a region that does not include the detection target code in the program code as a non-analysis target region, and performs the analysis The information includes information for specifying the non-analysis target region, and the specification unit of the second analysis unit includes the region of the program code excluding the region indicated by the information for specifying the non-analysis target region. The gist is to specify the area.

本発明の第12の特徴は、本発明の第11の特徴に係り、前記非解析対象領域を特定する情報は、前記非解析対象領域の開始アドレスを含むことを要旨とする。   A twelfth feature of the present invention relates to the eleventh feature of the present invention, and is summarized in that the information specifying the non-analysis target area includes a start address of the non-analysis target area.

本発明の第13の特徴は、本発明の第11の特徴に係り、前記第1解析部は、前記プログラムコードを2つの分岐命令で挟まれた領域毎に分割し、分割された領域毎に前記検出対象コードの検出処理を行うことで前記非解析対象領域を検出することを要旨とする。   A thirteenth feature of the present invention is according to the eleventh feature of the present invention, wherein the first analysis unit divides the program code into regions sandwiched between two branch instructions, and for each divided region. The gist is to detect the non-analysis target region by performing detection processing of the detection target code.

このような特徴によれば、2つの分岐命令で挟まれた領域毎に検出対象コードの検出処理を行うので、プログラムコード内で重複する領域が発生することなく、1つの検出対象コードが複数の領域で検出されることが回避される。   According to such a feature, the detection target code detection process is performed for each area sandwiched between two branch instructions, so that one detection target code includes a plurality of detection areas without generating an overlapping area in the program code. Detection in the region is avoided.

本発明の第14の特徴は、本発明の第11の特徴に係り、前記第1解析部は、前記非解析対象領域を特定する情報を含む前記解析情報を記憶する解析情報記憶部をさらに備え、前記第2解析部は、前記非解析対象領域を特定する情報と、前記非解析対象領域が実行された回数とを対応付けた履歴情報を記憶する履歴情報記憶部をさらに備え、前記解析情報生成部は、前記履歴情報記憶部に記憶されている前記履歴情報に基づき、前記解析情報記憶部に記憶されている前記解析情報を更新することを要旨とする。   A fourteenth feature of the present invention relates to the eleventh feature of the present invention, wherein the first analysis unit further includes an analysis information storage unit that stores the analysis information including information for specifying the non-analysis target region. The second analysis unit further includes a history information storage unit that stores history information in which the information specifying the non-analysis target region is associated with the number of times the non-analysis target region is executed, and the analysis information The gist of the generation unit is to update the analysis information stored in the analysis information storage unit based on the history information stored in the history information storage unit.

このような特徴によれば、実行された非解析対象領域が履歴情報として記録されるので、解析情報生成部は、実際に実行された非解析対象領域を優先的に解析情報に含めるなど、解析情報をより効率的に生成することが可能となる。   According to such a feature, since the executed non-analysis target region is recorded as history information, the analysis information generation unit analyzes the pre-executed non-analysis target region by including it in the analysis information preferentially. Information can be generated more efficiently.

本発明の第15の特徴は、本発明の第14の特徴に係り、前記履歴情報記憶部に記憶される前記非解析対象領域を特定する情報は、少なくとも前記非解析対象領域の開始アドレスを含むことを要旨とする。   A fifteenth feature of the present invention relates to the fourteenth feature of the present invention, wherein the information specifying the non-analysis target area stored in the history information storage unit includes at least a start address of the non-analysis target area. This is the gist.

このような特徴によれば、履歴情報として、非解析対象領域の開始アドレスが記録されるため、非解析対象領域が一意に特定される。   According to such a feature, since the start address of the non-analysis target area is recorded as history information, the non-analysis target area is uniquely specified.

本発明の第16の特徴は、本発明の第14の特徴に係り、前記特定部は、前記解析情報記憶部中の上位から下位へ前記非解析対象領域を特定する情報を参照することで、前記次に実行されるプログラムコードの領域が前記非解析対象領域であるか否かを特定し、前記解析情報生成部は、前記履歴情報において一定回数以上に対応する前記非解析対象領域を特定する情報を、前記解析情報記憶部中の上位に設定し、前記履歴情報において一定回数未満に対応する前記非解析対象領域を特定する情報を、前記解析情報記憶部中の下位に設定することを要旨とする。   A sixteenth feature of the present invention relates to the fourteenth feature of the present invention, wherein the specifying unit refers to information for specifying the non-analysis target region from higher to lower in the analysis information storage unit, Specify whether the area of the program code to be executed next is the non-analysis target area, and the analysis information generation unit specifies the non-analysis target area corresponding to a certain number of times or more in the history information The information is set at a higher level in the analysis information storage unit, and the information specifying the non-analysis target region corresponding to less than a certain number of times in the history information is set at the lower level in the analysis information storage unit And

このような特徴によれば、解析情報生成部は、履歴情報を利用して、過去に実行された非解析対象領域を(線形)検索順序の上位に配置することで、特定部が非解析対象領域を参照(検索)する時間が短縮される。   According to such a feature, the analysis information generation unit uses the history information to place the non-analysis target region that has been executed in the past in the higher order of the (linear) search order, so that the specifying unit can perform the non-analysis target. Time to refer to (search) an area is shortened.

本発明の第17の特徴は、本発明の第1の特徴に係り、前記検出対象コードは、分岐命令であり、前記第2解析部は、解析済みコードに所定の分岐命令が含まれる場合に、前記所定の分岐命令を特定する情報、及び前記所定の分岐命令の分岐先を分岐先情報として記憶する分岐先情報記憶部をさらに備え、前記第1検出部は、前記分岐先情報記憶部に記憶される前記分岐先情報に基づき、前記検出対象コードを検出することを要旨とする。   A seventeenth feature of the present invention relates to the first feature of the present invention, wherein the detection target code is a branch instruction, and the second analysis unit is configured to include a predetermined branch instruction in the analyzed code. A branch destination information storage unit that stores information specifying the predetermined branch instruction and a branch destination of the predetermined branch instruction as branch destination information; and the first detection unit is stored in the branch destination information storage unit. The gist is to detect the detection target code based on the stored branch destination information.

このような特徴によれば、第1検出部は、分岐先情報を利用することで、分岐先の特定が困難であることにより検出漏れが生じていたプログラムコードまで解析可能となり、検出対象コードの検出漏れが削減される。   According to such a feature, the first detection unit can analyze even the program code in which the detection omission has occurred due to the difficulty of specifying the branch destination by using the branch destination information. Misdetection is reduced.

本発明の第18の特徴は、本発明の第17の特徴に係り、前記所定の分岐命令は、他の命令の実行結果に応じて分岐先が定まる間接分岐命令であり、前記分岐先情報記憶部は、前記解析済みコードが実行される際に前記分岐先情報を記憶することを要旨とする。   An eighteenth feature of the present invention relates to the seventeenth feature of the present invention, wherein the predetermined branch instruction is an indirect branch instruction in which a branch destination is determined according to an execution result of another instruction, and the branch destination information storage The gist is to store the branch destination information when the analyzed code is executed.

このような特徴によれば、間接分岐命令についての分岐先を検出することが可能となる。   According to such a feature, it is possible to detect a branch destination for an indirect branch instruction.

本発明の第19の特徴は、複数のコードを含むプログラムコードを解析することで検出対象コードを検出するコード検出方法であって、前記プログラムコードを解析する第1ステップと、前記第1ステップによる解析結果を用いて前記プログラムコードを解析する第2ステップとを備え、前記第1ステップは、前記プログラムコードから前記検出対象コードを検出するステップと、前記検出対象コードの検出結果に基づき、前記プログラムコードのうち前記第2ステップが解析対象とする領域である解析対象領域を特定するための解析情報を生成するステップとを備え、前記第2ステップは、前記解析情報を参照することで前記プログラムコード中の前記解析対象領域を特定するステップと、前記特定部によって特定された前記解析対象領域から前記検出対象コードを検出するステップとを備えることを要旨とする。   A nineteenth feature of the present invention is a code detection method for detecting a detection target code by analyzing a program code including a plurality of codes, the first step of analyzing the program code, and the first step A second step of analyzing the program code using an analysis result, wherein the first step detects the detection target code from the program code, and the program is based on the detection result of the detection target code. Generating analysis information for specifying an analysis target area, which is an area to be analyzed in the second step of the code, wherein the second step refers to the analysis information and the program code A step of specifying the analysis target region in the analysis target region specified by the specifying unit And summarized in that it comprises the step of detecting al the detected code.

本発明によれば、複数のコードを含むプログラムコードを解析することで検出対象コードを検出するプログラム解析システムにおいて、オーバヘッドを削減可能なコード検出装置及びコード検出方法を提供できる。   According to the present invention, it is possible to provide a code detection apparatus and a code detection method that can reduce overhead in a program analysis system that detects a detection target code by analyzing a program code including a plurality of codes.

次に、図面を参照して、本発明の第1〜第6実施形態を説明する。以下の第1〜第6実施形態における図面の記載において、同一又は類似の部分には同一又は類似の符号を付している。   Next, first to sixth embodiments of the present invention will be described with reference to the drawings. In the description of the drawings in the following first to sixth embodiments, the same or similar parts are denoted by the same or similar reference numerals.

<第1実施形態>
(プログラム解析システムの構成)
先ず、本実施形態に係るプログラム解析システムの構成について説明する。図3は、本実施形態に係るプログラム解析システムの機能ブロック図である。
<First Embodiment>
(Configuration of program analysis system)
First, the configuration of the program analysis system according to the present embodiment will be described. FIG. 3 is a functional block diagram of the program analysis system according to the present embodiment.

図3に示すように、プログラム解析システムは、コード検出装置100、コード実行装置200、プログラムコード記憶部300、動的解析済みコード記憶部320及び制御情報記憶部400を備える。   As illustrated in FIG. 3, the program analysis system includes a code detection device 100, a code execution device 200, a program code storage unit 300, a dynamically analyzed code storage unit 320, and a control information storage unit 400.

プログラムコード記憶部300は、複数のコードを含むプログラムコードを記憶する。本実施形態では、プログラムコードを構成する各コードが、命令、当該命令のアドレス、及び当該命令の引数で構成されるアセンブリ言語で記述されている場合を例に説明する。   The program code storage unit 300 stores a program code including a plurality of codes. In the present embodiment, an example will be described in which each code constituting a program code is described in an assembly language including an instruction, an address of the instruction, and an argument of the instruction.

(コード検出装置の構成)
コード検出装置100は、プログラムコードを解析することで検出対象コードを検出する。コード検出装置100は、第1解析部110及び第2解析部120を備える。
(Configuration of code detection device)
The code detection apparatus 100 detects the detection target code by analyzing the program code. The code detection device 100 includes a first analysis unit 110 and a second analysis unit 120.

第1解析部110は、プログラム実行前にプログラムコードを解析する「静的解析」を実行する。第2解析部120は、プログラム実行中にプログラムコードを解析する「動的解析」を実行する。本実施形態では、第2解析部120は、インタプリンタ実行のように、プログラムコードをブロック単位で読み込んで解析する。   The first analysis unit 110 executes “static analysis” for analyzing the program code before executing the program. The second analysis unit 120 executes “dynamic analysis” for analyzing the program code during program execution. In the present embodiment, the second analysis unit 120 reads and analyzes the program code in units of blocks, as in the case of interpreter execution.

第1解析部110は、ブロック生成部111、第1検出部112、解析情報生成部113及び解析情報記憶部114を備える。   The first analysis unit 110 includes a block generation unit 111, a first detection unit 112, an analysis information generation unit 113, and an analysis information storage unit 114.

ブロック生成部111は、プログラムコード記憶部300に記憶されたプログラムコードからブロックを順次生成する。   The block generation unit 111 sequentially generates blocks from the program code stored in the program code storage unit 300.

第1検出部112は、ブロック生成部111によって生成されたブロックに対してブロック解析処理を行う。具体的には、第1検出部112は、ブロック生成部111によって生成されたブロック内に検出対象コードが含まれているか否かを判定する。   The first detection unit 112 performs block analysis processing on the block generated by the block generation unit 111. Specifically, the first detection unit 112 determines whether or not the detection target code is included in the block generated by the block generation unit 111.

なお、制御情報記憶部400は、検出対象コードを特定する情報と、当該検出対象コードに追加すべきフックコードを特定する情報とを記憶する。第1検出部112は、制御情報記憶部400を参照することでブロック内の検出対象コードを検出する。   The control information storage unit 400 stores information for specifying the detection target code and information for specifying the hook code to be added to the detection target code. The first detection unit 112 detects the detection target code in the block by referring to the control information storage unit 400.

解析情報生成部113は、第1検出部112による検出結果に基づき、第2解析部120が解析対象とするブロック(領域)である解析対象ブロックを特定するための解析情報を生成する。解析情報生成部113によって生成された解析情報は、解析情報記憶部114内に記憶される。   The analysis information generation unit 113 generates analysis information for specifying an analysis target block that is a block (region) to be analyzed by the second analysis unit 120 based on the detection result by the first detection unit 112. The analysis information generated by the analysis information generation unit 113 is stored in the analysis information storage unit 114.

第2解析部120は、特定部121、第2検出部122、コード出力部123、コンパイル部124、フックコード追加部125及びキャッシュ記憶部126を備える。   The second analysis unit 120 includes a specification unit 121, a second detection unit 122, a code output unit 123, a compilation unit 124, a hook code addition unit 125, and a cache storage unit 126.

特定部121は、解析情報記憶部114に記憶された解析情報を参照することで、プログラムコードから解析対象ブロックを特定する。   The specifying unit 121 specifies the analysis target block from the program code by referring to the analysis information stored in the analysis information storage unit 114.

第2検出部122は、特定部121によって特定された解析対象ブロックから検出対象コードを検出する。解析対象ブロックから検出対象コードが検出されると、第2検出部122は、当該解析対象ブロックの動的解析済みコードがキャッシュ記憶部126に存在するか否かを判定する。   The second detection unit 122 detects the detection target code from the analysis target block specified by the specifying unit 121. When the detection target code is detected from the analysis target block, the second detection unit 122 determines whether the dynamically analyzed code of the analysis target block exists in the cache storage unit 126.

当該解析対象ブロックの動的解析済みコードがキャッシュ記憶部126に存在する場合、第2検出部122は、キャッシュされている動的解析済みコードを取得する。キャッシュ記憶部126から取得された動的解析済みコードは、コード出力部123によって動的解析済みコード記憶部320に格納される。当該解析対象ブロックの動的解析済みコードがキャッシュ記憶部126に存在しない場合、第2検出部122は、当該解析対象ブロックを、コード出力部123を介してコンパイル部124に出力する。   When the dynamically analyzed code of the analysis target block exists in the cache storage unit 126, the second detection unit 122 acquires the cached dynamically analyzed code. The dynamically analyzed code acquired from the cache storage unit 126 is stored in the dynamically analyzed code storage unit 320 by the code output unit 123. When the dynamically analyzed code of the analysis target block does not exist in the cache storage unit 126, the second detection unit 122 outputs the analysis target block to the compilation unit 124 via the code output unit 123.

コンパイル部124及びフックコード追加部125は、検出対象コードの直前にフックコードを追加すると共に、解析対象ブロックをコンパイル処理する。コンパイル処理後の解析対象ブロックは、キャッシュ記憶部126内に記憶される。   The compiling unit 124 and the hook code adding unit 125 add the hook code immediately before the detection target code and compile the analysis target block. The analysis target block after the compile processing is stored in the cache storage unit 126.

コード出力部123は、コンパイル処理後の解析対象ブロックを動的解析済みコードとして出力する。コード出力部123によって出力された動的解析済みコードは、動的解析済みコード記憶部320内に記憶される。   The code output unit 123 outputs the analysis target block after the compile processing as dynamically analyzed code. The dynamically analyzed code output by the code output unit 123 is stored in the dynamically analyzed code storage unit 320.

(コード実行装置の構成)
コード実行装置200は、動的解析済みコード記憶部320に記憶された動的解析済みコードを実行する。コード実行装置200は、コード実行部210、コード制御部220及び制御ポリシー記憶部800を備える。
(Configuration of code execution device)
The code execution device 200 executes the dynamically analyzed code stored in the dynamically analyzed code storage unit 320. The code execution device 200 includes a code execution unit 210, a code control unit 220, and a control policy storage unit 800.

コード実行部210は、動的解析済みコードをブロック単位で実行する。また、コード実行部210は、各ブロックの実行によって、次に実行されるべきプログラムコードのアドレスを特定し、当該アドレスを解析対象ブロックアドレスとして特定部121に出力する。このプロセスを繰り返すことで、第2解析部120による解析を伴うインタプリンタ実行を行うことが可能となる。   The code execution unit 210 executes the dynamically analyzed code in units of blocks. Further, the code execution unit 210 specifies the address of the program code to be executed next by executing each block, and outputs the address to the specifying unit 121 as the analysis target block address. By repeating this process, it is possible to execute the interpreter with analysis by the second analysis unit 120.

コード実行部210は、動的解析済みコードからフックコードが検出された場合には、その旨をコード制御部220に通知する。コード制御部220は、フックコードが検出された旨の通知を受けると、制御ポリシー記憶部800に記憶されている制御ポリシーに従って、フックコードが追加されている検出対象コードを実行するか否か判定する。   When the hook code is detected from the dynamically analyzed code, the code execution unit 210 notifies the code control unit 220 to that effect. When receiving the notification that the hook code has been detected, the code control unit 220 determines whether to execute the detection target code to which the hook code is added according to the control policy stored in the control policy storage unit 800. To do.

(解析情報の構成)
次に、解析情報記憶部114に記憶される解析情報について説明する。解析情報は、プログラムコードを記憶するメモリ領域のうち検出対象コードを含まない部分のメモリ領域を特定する情報である。
(Structure of analysis information)
Next, analysis information stored in the analysis information storage unit 114 will be described. The analysis information is information that identifies a memory area of a memory area that stores the program code and does not include the detection target code.

図4は、解析情報の一例を示す図である。図4に示すように、解析情報は、検出対象コードを含まないブロックのブロックIDと、当該ブロックの開始アドレスと、当該ブロックの終了アドレスとを対応付けた構成を有している。「ブロック」とは、開始アドレスと終了アドレスとにより表現されるプログラムコードの一部である。以下においては、解析情報記憶部114に登録されたブロックを「登録ブロック」と呼ぶ。   FIG. 4 is a diagram illustrating an example of analysis information. As shown in FIG. 4, the analysis information has a configuration in which a block ID of a block not including the detection target code, a start address of the block, and an end address of the block are associated with each other. A “block” is a part of a program code expressed by a start address and an end address. Hereinafter, a block registered in the analysis information storage unit 114 is referred to as a “registered block”.

(解析情報生成処理)
次に、図5〜図7を参照して、解析情報の生成処理について説明する。
(Analysis information generation process)
Next, analysis information generation processing will be described with reference to FIGS.

図5に示すように、ブロックは、開始命令から始まり、無条件分岐命令で終了する。無条件分岐命令は、無条件に特定のコードへ分岐する命令であり、例えば次のような命令が該当する。   As shown in FIG. 5, the block begins with a start instruction and ends with an unconditional branch instruction. An unconditional branch instruction is an instruction that unconditionally branches to a specific code, and includes the following instructions, for example.

B PC+xxxx ;アドレスPC+xxxxへの分岐
BL PC+yyyy ;アドレスPC+yyyyへの分岐
MOV PC,lr ;lrレジスタに格納されたアドレスへの分岐
逆に、条件付き分岐命令とは、次に示すように、条件フィールドを伴い、条件が満たされる場合に特定の分岐先へ制御を移すような命令である。
B PC + xxxx; Branch to address PC + xxxx BL PC + yyyy; Branch to address PC + yyyy MOV PC, lr; Branch to address stored in lr register Conversely, a conditional branch instruction has a condition field as Accordingly, it is an instruction that transfers control to a specific branch destination when the condition is satisfied.

CMP lr,r1 ;lrレジスタの値とr1レジスタの値とを比較
BEQ PC+yyyy ;比較結果に応じて指定アドレスへ分岐
一方、開始命令とは、mainや_Startといったシンボルで特定される関数の先頭コードである。mainや_Startを含むブロックを「ブロック1」と呼び、以降N番目に生成されるブロックを「ブロックN」と呼ぶ。ブロック1以外のブロックの開始地点は、あるブロックからの分岐先コードに等しい。
CMP lr, r1; compares the value of the lr register with the value of the r1 register is there. A block including main and _Start is referred to as “block 1”, and an Nth generated block is hereinafter referred to as “block N”. The starting point of blocks other than block 1 is equal to the branch destination code from a certain block.

図6は、複数のブロック間の関係を示す図である。図6では、ブロック1に含まれる分岐命令の分岐先はブロック2及びブロック3である。さらに、ブロック3に含まれる分岐命令の分岐先はブロック4である。   FIG. 6 is a diagram illustrating a relationship between a plurality of blocks. In FIG. 6, the branch destinations of the branch instruction included in block 1 are block 2 and block 3. Further, the branch destination of the branch instruction included in block 3 is block 4.

(解析情報生成処理の処理フロー)
次に、解析情報生成処理の処理フローについて説明する。図7は、解析情報生成処理の処理フローを示すフローチャートである。
(Processing flow of analysis information generation process)
Next, the processing flow of the analysis information generation process will be described. FIG. 7 is a flowchart showing a process flow of the analysis information generation process.

ステップS1000において、第1解析部110は、プログラムコードの先頭ブロック(ブロック1)の開始アドレスを取得する。   In step S1000, the first analysis unit 110 acquires the start address of the first block (block 1) of the program code.

ステップS1001において、第1解析部110は、ステップS1000で取得した開始アドレスからブロック解析処理を実行する。ブロック解析処理の詳細については後述する。   In step S1001, the first analysis unit 110 executes block analysis processing from the start address acquired in step S1000. Details of the block analysis processing will be described later.

ステップS1002において、第1解析部110は、ステップS1001で解析したブロックを解析済みブロックリストへ登録する。解析済みブロックリストは、解析済みのブロックのブロックID、開始アドレス及び終了アドレスを含む。一度でもブロック解析処理が実行されたブロックは、解析済みブロックリストに登録される。   In step S1002, the first analysis unit 110 registers the block analyzed in step S1001 in the analyzed block list. The analyzed block list includes the block ID, start address, and end address of the analyzed block. Blocks that have been subjected to block analysis processing once are registered in the analyzed block list.

ステップS1003において、第1解析部110は、ステップS1001で解析したブロックの分岐先アドレスをすべて取得する。取得される分岐先アドレスとしては、以下の4つのパターンが考えられる。   In step S1003, the first analysis unit 110 acquires all branch destination addresses of the blocks analyzed in step S1001. The following four patterns can be considered as the acquired branch destination addresses.

(1)分岐先アドレスが特定され、分岐先のブロックが存在し、当該アドレスがいずれの解析済みブロックにも含まれない。   (1) A branch destination address is specified, a branch destination block exists, and the address is not included in any analyzed block.

(2)分岐先アドレスが特定され、分岐先のブロックが存在しない。   (2) A branch destination address is specified, and there is no branch destination block.

(3)分岐先アドレスが不特定(分岐がないか分岐先が不明)。   (3) The branch destination address is unspecified (there is no branch or the branch destination is unknown).

(4)分岐先アドレスが特定され、分岐先のブロックが存在し、当該アドレスがいずれかの解析済みブロックに含まれる。   (4) A branch destination address is specified, a branch destination block exists, and the address is included in any analyzed block.

パターン(1)及び(4)は、通常の分岐である。パターン(2)としては、例えば動的リンクライブラリ関数への分岐が該当する。パターン(3)としては、例えば、プログラム実行時の外部入力により分岐先が決定するような場合が該当する。あるいは、当該ブロックでプログラムが終了するような場合もパターン(3)に含まれる。   Patterns (1) and (4) are normal branches. As the pattern (2), for example, a branch to a dynamic link library function is applicable. As the pattern (3), for example, a case where a branch destination is determined by an external input at the time of program execution is applicable. Alternatively, the case where the program ends in the block is also included in the pattern (3).

パターン(1)及び(4)では、分岐先のブロックを取得可能であるが、パターン(2)及び(3)では、分岐先のブロックを取得できず、その後の解析は不可能である。   In the patterns (1) and (4), the branch destination block can be acquired. However, in the patterns (2) and (3), the branch destination block cannot be acquired, and the subsequent analysis is impossible.

パターン(1)及び(4)の違いは、分岐先アドレスを開始アドレスとするブロックが解析済みであるか否かである。これは、当該分岐先アドレスがいずれかの解析済みブロックに含まれるか否かにより判定される。   The difference between the patterns (1) and (4) is whether or not the block having the branch destination address as the start address has been analyzed. This is determined by whether or not the branch destination address is included in any analyzed block.

ステップS1004において、第1解析部110は、分岐先のブロックを取得可能であるか否かを判定する。具体的には、取得したすべての分岐先アドレスがパターン(1)又は(4)であった場合、ステップS1005に進む。一方、取得したすべての分岐先アドレスがパターン(2)又は(3)であった場合、ステップS1008に進む。   In step S1004, the first analysis unit 110 determines whether it is possible to acquire a branch destination block. Specifically, if all the acquired branch destination addresses are pattern (1) or (4), the process proceeds to step S1005. On the other hand, if all the acquired branch destination addresses are the pattern (2) or (3), the process proceeds to step S1008.

ステップS1005において、第1解析部110は、パターン(1)とパターン(4)との判別を行う。すなわち、取得したすべての分岐先アドレスがいずれかの解析済みブロックに含まれていれば、パターン(4)であり、ステップS1008へ進む。一方、取得したすべての分岐先アドレスがいずれの析済みブロックにも含まれていなければ、分岐先アドレスを開始アドレスとするブロックは未解析であり、ステップS1006へ進む。   In step S1005, the first analysis unit 110 determines the pattern (1) and the pattern (4). That is, if all the acquired branch destination addresses are included in any analyzed block, the pattern is (4), and the process proceeds to step S1008. On the other hand, if all the acquired branch destination addresses are not included in any analyzed block, the block having the branch destination address as the start address has not been analyzed, and the process proceeds to step S1006.

ここで、パターン(4)の条件は、分岐先アドレスと解析済みブロックの開始アドレスとが一致する必要はなく、開始アドレスと終了アドレスとに挟まれていればよい。一例として、図8において、矢印を各ブロックの分岐元と分岐先とし、ブロック1からブロック2に分岐し、ブロック2を解析しているものとする。ブロック2の開始アドレスはx、かつ終了アドレスはyであり、解析済みブロックリストに登録されている。その後、ブロック3から、ブロック2のxとyに挟まれるアドレスzに分岐した場合、zから始まるブロックの終了アドレスはyであり、当該ブロックはブロック2に含まれるため、既に解析済みであると判定される。   Here, the condition of the pattern (4) does not need to match the branch destination address and the start address of the analyzed block, and it is only necessary to be sandwiched between the start address and the end address. As an example, in FIG. 8, it is assumed that an arrow is a branch source and a branch destination of each block, branch from block 1 to block 2, and block 2 is analyzed. The start address of block 2 is x and the end address is y, which is registered in the analyzed block list. After that, when branching from block 3 to an address z sandwiched between x and y of block 2, the end address of the block starting from z is y, and since this block is included in block 2, it has already been analyzed. Determined.

ステップS1006において、第1解析部110は、すべての未解析ブロックの開始(先頭)アドレスを解析候補スタックに積む。解析候補スタックは、次回の解析対象となるブロックの開始アドレスを格納するFIFOのスタックである。   In step S1006, the first analysis unit 110 accumulates the start (head) addresses of all unanalyzed blocks in the analysis candidate stack. The analysis candidate stack is a FIFO stack that stores the start address of the block to be analyzed next time.

ステップS1007において、第1解析部110は、解析候補スタックから解析対象開始アドレスを1つ取り出す。その後、解析対象開始アドレスから始まるブロックに対して、再びステップS1001が適用されることとなる。   In step S1007, the first analysis unit 110 extracts one analysis target start address from the analysis candidate stack. Thereafter, step S1001 is applied again to the block starting from the analysis target start address.

一方、ステップS1008において、第1解析部110は、解析候補スタックを検査する。解析候補スタックが空であれば、ステップS1099へ進み、プログラムコードに対する静的解析を終了する。一方、解析候補スタックが積まれていれば、ステップS1009へ進む。   On the other hand, in step S1008, the first analysis unit 110 checks the analysis candidate stack. If the analysis candidate stack is empty, the process advances to step S1099 to end the static analysis for the program code. On the other hand, if an analysis candidate stack is stacked, the process proceeds to step S1009.

ステップS1009において、第1解析部110は、当該アドレスを1つ取り出す。   In step S1009, the first analysis unit 110 extracts one of the addresses.

ステップS1010において、第1解析部110は、当該アドレスがいずれかの解析済みブロックに含まれるか否かを判定する。   In step S1010, the first analysis unit 110 determines whether the address is included in any analyzed block.

なお、解析対象開始アドレスとして解析候補スタックに積まれた時点では、当該アドレスから始まるブロックは静的解析済みではないが、スタックで解析待ちとなっている間に別のブロックからの分岐により当該ブロックが解析される可能性があるため、ステップS1010が必要となる。   Note that when the analysis target start address is loaded on the analysis candidate stack, the block starting from that address has not been statically analyzed, but the block is blocked by another block while waiting for analysis in the stack. May be analyzed, so step S1010 is required.

例えば、図9の例で、ブロック1を解析後、ブロック2,4の開始アドレスy、wが解析候補として解析候補スタックに積まれる。しかし、ブロック2が先に解析された場合、ブロック3,4へ解析が進み、ブロック3の分岐先として再びwが解析候補スタックに積まれる。   For example, in the example of FIG. 9, after analyzing the block 1, the start addresses y and w of the blocks 2 and 4 are put on the analysis candidate stack as analysis candidates. However, if block 2 is analyzed first, the analysis proceeds to blocks 3 and 4, and w is again added to the analysis candidate stack as the branch destination of block 3.

このように、解析候補スタックに同じ解析対象開始アドレスが複数積まれる可能性があるため、ステップS1010における解析済みブロックリストによる重複検査は必要である。ステップS1010において当該アドレスが解析済みでなければ、ステップS1001により実際に解析が実行される。   As described above, since there is a possibility that a plurality of the same analysis target start addresses may be stacked on the analysis candidate stack, it is necessary to perform a duplicate check using the analyzed block list in step S1010. If the address has not been analyzed in step S1010, the analysis is actually executed in step S1001.

(ブロック解析処理の処理フロー)
次に、ブロック解析処理の処理フローについて説明する。ブロック解析処理では、与えられたアドレスから始まるブロックに検出対象コードが含まれない場合に、当該ブロックを解析情報記憶部114に登録する。検出対象コードの具体例や検出方法については後述する。
(Block analysis processing flow)
Next, the processing flow of block analysis processing will be described. In the block analysis process, when a detection target code is not included in a block starting from a given address, the block is registered in the analysis information storage unit 114. Specific examples of detection target codes and detection methods will be described later.

図10は、ブロック解析処理の処理フローを示すフローチャートである。   FIG. 10 is a flowchart showing a processing flow of the block analysis processing.

ステップS2000において、第1解析部110は、解析対象ブロックの開始アドレスを取得する。   In step S2000, the first analysis unit 110 acquires the start address of the analysis target block.

ステップS2001において、第1解析部110は、終了アドレスを特定することで解析対象ブロックを生成する。   In step S2001, the first analysis unit 110 generates an analysis target block by specifying an end address.

ここで、終了アドレスとは、基本的には最後に検出された無条件分岐命令のアドレスであるが、例外がある。例外が発生する例について、図11を用いて説明する。図11において、現在解析対象となっているブロックの開始アドレスをxとし、当該開始アドレスから検索して最初に検出された無条件分岐命令のアドレスがyであるとする。また、開始アドレスz、かつ終了アドレスyのブロック2は、既に解析済みブロックリストに登録されているものとする。この場合、xで開始し、yで終了するブロックは、ブロック2と一部重複してしまう。   Here, the end address is basically the address of the unconditional branch instruction detected last, but there is an exception. An example in which an exception occurs will be described with reference to FIG. In FIG. 11, it is assumed that the start address of the block currently being analyzed is x, and the address of the unconditional branch instruction that is first detected from the start address is y. It is assumed that the block 2 having the start address z and the end address y is already registered in the analyzed block list. In this case, the block starting with x and ending with y partially overlaps with block 2.

この状況を防ぐため、ステップS2001において無条件分岐命令を検出することで、取得した終了アドレスが、生成済みブロックの開始アドレス(ここではw)を当該ブロックの終了アドレスとする。したがって、この例では、開始アドレスxのブロック4の終了アドレスはwとなる。当然、当該ブロックの終了アドレスは無条件分岐命令ではない。   In order to prevent this situation, by detecting an unconditional branch instruction in step S2001, the acquired end address sets the start address of the generated block (here, w) as the end address of the block. Therefore, in this example, the end address of the block 4 of the start address x is w. Of course, the end address of the block is not an unconditional branch instruction.

ステップS2002において、第1解析部110は、当該ブロックからコードを読み込む。   In step S2002, the first analysis unit 110 reads a code from the block.

ステップS2003において、第1解析部110は、ステップS2002で読み込んだコードが、検出対象コードに該当するか否かを判定する。ステップS2002で読み込んだコードが検出対象コードに該当する場合、当該ブロックは登録ブロックとして解析情報記憶部114に登録されず、処理が終了する。一方、ステップS2002で読み込んだコードが検出対象コードに該当する場合、ステップS2004に進む。   In step S2003, the first analysis unit 110 determines whether the code read in step S2002 corresponds to the detection target code. If the code read in step S2002 corresponds to the detection target code, the block is not registered in the analysis information storage unit 114 as a registered block, and the process ends. On the other hand, if the code read in step S2002 corresponds to the detection target code, the process proceeds to step S2004.

ステップS2004において、第1解析部110は、ブロックに存在するコードをすべて読み込んだか否かを判定する。ブロック内に未読み込み(未解析)のコードが存在する場合、ステップS2002に処理が戻る。ブロック内に未読み込みのコードが存在しない場合、ステップS2005に進み、当該ブロックが解析情報記憶部114に登録される。   In step S2004, the first analysis unit 110 determines whether all codes existing in the block have been read. If there is an unread (unanalyzed) code in the block, the process returns to step S2002. If there is no unread code in the block, the process proceeds to step S2005, and the block is registered in the analysis information storage unit 114.

(ブロック解析処理の具体例)
次に、図12及び図13を参照して、ブロック解析処理の具体例について説明する。
(Specific example of block analysis processing)
Next, a specific example of the block analysis process will be described with reference to FIGS.

図12において、各ブロック内のアルファベットは開始アドレス及び終了アドレスを表し、矢印はブロック間の関係を表している。ハッチングの付されている各ブロックは、解析情報記憶部114に登録すべきブロックであるものとする。また、ブロック6の分岐先ブロックは、上述したパターン(2)又はパターン(3)の分岐先であるものとしている。   In FIG. 12, the alphabet in each block represents the start address and the end address, and the arrows represent the relationship between the blocks. It is assumed that each hatched block is a block to be registered in the analysis information storage unit 114. Further, the branch destination block of the block 6 is assumed to be the branch destination of the pattern (2) or the pattern (3) described above.

図12では、解析可能なブロックは7個であり、解析の重複は起こり得ないため、図7のステップS1001から始まる過程が必ず7回発生する。各過程終了時の解析情報、解析候補スタック及び解析済みブロックリストを図13に示す。図13では、解析情報、解析済みブロックリストは、ブロックIDで示し、アドレスは省略している。   In FIG. 12, the number of blocks that can be analyzed is seven, and duplication of analysis cannot occur. Therefore, the process starting from step S1001 in FIG. 7 always occurs seven times. FIG. 13 shows analysis information, an analysis candidate stack, and an analyzed block list at the end of each process. In FIG. 13, the analysis information and the analyzed block list are indicated by block IDs, and addresses are omitted.

ブロック1に対する1回目のステップS1001〜ステップS1007を適用後、解析候補スタックには、アドレスmとアドレスcが積まれ、解析済みブロックリストにはブロック1が登録される。   After applying the first step S1001 to step S1007 for block 1, address m and address c are stacked in the analysis candidate stack, and block 1 is registered in the analyzed block list.

次に、解析候補スタックからアドレスcが取り出され、アドレスcを開始アドレスとするブロック2に対して、2回目の解析が行われる。ブロック2は、解析情報記憶部114に登録すべきブロックであるため、登録ブロックはブロック2となり、解析候補スタックにはブロック2の分岐先アドレスm,i,eが登録され、解析済みブロックリストにはブロック1,2が登録される。   Next, the address c is extracted from the analysis candidate stack, and the second analysis is performed on the block 2 having the address c as a start address. Since block 2 is a block to be registered in the analysis information storage unit 114, the registered block is block 2, and the branch destination addresses m, i, and e of block 2 are registered in the analysis candidate stack, and are stored in the analyzed block list. Blocks 1 and 2 are registered.

同様に、eを開始アドレスとするブロック3の解析後は、解析候補スタックにm,i,gが積まれる。ブロック4の解析後は、分岐先のアドレスは既に解析済みブロックリストに存在するブロック3に含まれるため、解析候補スタックには積まれない。同様の手順を繰り返すことで、図13に示す解析情報が生成される。   Similarly, after the analysis of block 3 with e as the start address, m, i, and g are stacked on the analysis candidate stack. After the analysis of the block 4, the branch destination address is included in the block 3 that already exists in the analyzed block list, and thus is not stacked on the analysis candidate stack. By repeating the same procedure, the analysis information shown in FIG. 13 is generated.

(動的解析処理の処理フロー)
次に、動的解析処理、つまり第2解析部120の動作について説明する。上述したように、第2解析部120は、コード実行部210から提示される解析対象ブロックアドレスを元に、プログラムコードから解析すべきプログラムコードを特定し、解析情報を元に当該プログラムコードが検出対象であるか否かを判定する。
(Dynamic analysis process flow)
Next, the dynamic analysis process, that is, the operation of the second analysis unit 120 will be described. As described above, the second analysis unit 120 identifies the program code to be analyzed from the program code based on the analysis target block address presented from the code execution unit 210, and detects the program code based on the analysis information. It is determined whether or not it is a target.

さらに、第2解析部120は、検出対象コードを検出すると共に、検出された検出対象コードに対してフックコードを追加する。以下では、第2解析部120が一回毎に出力する動的解析済みコードを、第1解析部110の動作説明時と同様にブロックと呼ぶ。   Furthermore, the second analysis unit 120 detects the detection target code and adds a hook code to the detected detection target code. Hereinafter, the dynamically analyzed code output by the second analysis unit 120 every time is referred to as a block, similar to the description of the operation of the first analysis unit 110.

図14は、第2解析部120の動作を示すフローチャートである。   FIG. 14 is a flowchart showing the operation of the second analysis unit 120.

ステップS3000において、第2解析部120は、プログラムコードの先頭ブロックの開始アドレス(main関数の先頭ブロックの開始アドレス)を取得する。なお、解析開始時にはプログラムコードの先頭ブロックの開始アドレスが取得されるが、その後の処理ではコード実行部210によって解析対象ブロックの開始アドレスが与えられる。   In step S3000, the second analysis unit 120 acquires the start address of the first block of the program code (start address of the first block of the main function). At the start of analysis, the start address of the first block of the program code is acquired. In the subsequent processing, the start address of the analysis target block is given by the code execution unit 210.

ステップS3001において、第2解析部120は、ステップS3000で取得された開始アドレスが、解析情報に登録されたいずれかの登録ブロックに含まれるか否かを判定する。開始アドレスが登録ブロックに含まれる場合、ステップS3099に進む。一方、開始アドレスが登録ブロックに含まれない場合、ステップS3002に進む。 In step S3001, the second analysis unit 120 determines whether the start address acquired in step S3000 is included in any registered block registered in the analysis information. If the start address is included in the registration block, the process proceeds to step S3099. On the other hand, if the start address is not included in the registration block, the process proceeds to step S3002.

ステップS3099において、第2解析部120は、当該解析対象ブロックの動的解析が不要であると判断し、当該解析対象ブロックを動的解析済みコードとしてそのまま出力する。   In step S3099, the second analysis unit 120 determines that dynamic analysis of the analysis target block is unnecessary, and outputs the analysis target block as it is as a dynamically analyzed code.

ステップS3002において、第2解析部120は、当該解析対象ブロックがキャッシュに存在するか否かを判定する。当該解析対象ブロックがキャッシュに存在する場合、ステップS3199に進む。当該解析対象ブロックがキャッシュに存在しない場合、ステップS3003に進む。   In step S3002, the second analysis unit 120 determines whether or not the analysis target block exists in the cache. When the analysis target block exists in the cache, the process proceeds to step S3199. If the analysis target block does not exist in the cache, the process proceeds to step S3003.

なお、キャッシュの検索方法は、キャッシュの構成方法により異なる。キャッシュが開始アドレス及び終了アドレスを含む場合、解析情報に対する検索と同様に、解析対象ブロックの開始アドレス及び終了アドレスで検索すればよい。   Note that the cache search method differs depending on the cache configuration method. When the cache includes a start address and an end address, the search may be performed using the start address and the end address of the analysis target block as in the search for the analysis information.

ステップS3199において、第2解析部120は、キャッシュに存在する動的解析済みコードを解析対象ブロックの動的解析済みコードとして出力する。   In step S3199, the second analysis unit 120 outputs the dynamically analyzed code existing in the cache as the dynamically analyzed code of the analysis target block.

ステップS3003において、第2解析部120は、解析対象ブロックの終了アドレスを特定し、解析対象ブロックをプログラムコード記憶部から読み込む。なお、ステップS3003では、図10のステップS2001と同様に、当該ブロックから検出された無条件分岐命令のアドレスが、解析情報の終了アドレスに一致するか再び検査する。一致する場合には、当該ブロックの終了アドレスは一致したブロックの開始アドレスの1つ前となる。一致しない場合には、当該無条件分岐命令のアドレスが当該ブロックの終了アドレスとなる。   In step S3003, the second analysis unit 120 specifies the end address of the analysis target block, and reads the analysis target block from the program code storage unit. In step S3003, as in step S2001 of FIG. 10, it is checked again whether the address of the unconditional branch instruction detected from the block matches the end address of the analysis information. When they match, the end address of the block is one before the start address of the matched block. If they do not match, the address of the unconditional branch instruction becomes the end address of the block.

ステップS3004において、第2解析部120は、ステップS3003で読み込んだ解析対象ブロックをコンパイル処理する。ステップS3004では、当該ブロックから検出された検出対象コードへフックコードが追加される。   In step S3004, the second analysis unit 120 compiles the analysis target block read in step S3003. In step S3004, a hook code is added to the detection target code detected from the block.

(動的解析処理の具体例)
図14のステップS3099、ステップS3199及びステップS3299で停止した場合の動作概要図を図15〜図17に示す。図15〜図17では、上段にプログラムコードのメモリ空間を示し、中段にコード検出装置100(第2解析部120)の実行メモリ空間を示し、下段にコード実行装置200の実行メモリ空間を示している。
(Specific example of dynamic analysis processing)
The operation | movement outline | summary figure at the time of stopping at step S3099 of FIG. 14, step S3199, and step S3299 is shown in FIGS. 15 to 17, the memory space for program code is shown in the upper part, the execution memory space for the code detection apparatus 100 (second analysis unit 120) is shown in the middle part, and the execution memory space for the code execution apparatus 200 is shown in the lower part. Yes.

図15では、第2解析部120は、ブロックを読み込み、解析情報を元に当該ブロックが非解析対象のブロックであると判定し、当該ブロックをそのまま出力する(ステップS3001、ステップS3099)。この場合、当該ブロックにはフックコードが追加されないため、コード制御部220が呼出されることはない。   In FIG. 15, the second analysis unit 120 reads a block, determines that the block is a non-analysis target block based on the analysis information, and outputs the block as it is (steps S3001 and S3099). In this case, since the hook code is not added to the block, the code control unit 220 is not called.

図16では、第2解析部120は、ブロックを読み込み、解析情報を元に当該ブロックが解析対象ブロックであると判定する(ステップS3001)。第2解析部120は、キャッシュ記憶部126を検索し(ステップS3002)、キャッシュ記憶部126から動的解析済みブロックを出力する(ステップS3199)。当該ブロックにフックコードが追加されている場合には、当該ブロックの実行時にコード制御部220が呼出される。   In FIG. 16, the second analysis unit 120 reads a block and determines that the block is an analysis target block based on the analysis information (step S3001). The second analysis unit 120 searches the cache storage unit 126 (step S3002), and outputs the dynamically analyzed block from the cache storage unit 126 (step S3199). When a hook code is added to the block, the code control unit 220 is called when the block is executed.

図17では、第2解析部120は、各ブロックを読み込み、解析情報を元に当該ブロックが解析対象ブロックであると判定する(ステップS3001)。第2解析部120は、キャッシュ記憶部126を検索する(ステップS3002)。しかし、当該ブロックがキャッシュ記憶部126に存在しないために、プログラムコードからブロックを読み込み(ステップS3003)、読み込んだブロックをコンパイル処理し(ステップS3004)、コンパイル済みのブロックを出力する(ステップS3299)。   In FIG. 17, the second analysis unit 120 reads each block and determines that the block is an analysis target block based on the analysis information (step S3001). The second analysis unit 120 searches the cache storage unit 126 (step S3002). However, since the block does not exist in the cache storage unit 126, the block is read from the program code (step S3003), the read block is compiled (step S3004), and a compiled block is output (step S3299).

最後に、プログラム実行時には確実に分岐先を特定可能であるため、コード実行装置200は、図15〜図17のいずれの場合においても、次に実行される解析対象ブロックアドレスを第2解析部120に通知する。   Finally, since the branch destination can be reliably specified at the time of program execution, the code execution device 200 sets the second analysis unit 120 for the analysis target block address to be executed next in any case of FIGS. 15 to 17. Notify

(作用・効果)
本実施形態によれば、第1解析部110は、静的解析によって、第2解析部120が解析すべきメモリ領域を指定する。プログラムコードの動的解析を行う第2解析部120は、静的解析の結果に応じて、プログラムコードの一部に対して検出対象コードの検出処理を行う。このため、プログラムコードの動的解析を行う第2解析部120の処理負荷が削減され、システム全体の処理速度が向上する。
(Action / Effect)
According to this embodiment, the 1st analysis part 110 designates the memory area which the 2nd analysis part 120 should analyze by static analysis. The second analysis unit 120 that performs dynamic analysis of the program code performs detection processing of the detection target code for a part of the program code according to the result of the static analysis. For this reason, the processing load of the second analysis unit 120 that performs dynamic analysis of the program code is reduced, and the processing speed of the entire system is improved.

また、本実施形態に係るコード検出方法と、キャッシュ記憶部126を用いた手法とを併用することで、動的解析処理に要するコストを大幅に削減可能となる。また、解析対象ブロックが解析情報に存在した場合とキャッシュに存在した場合の両方において、フックコードを追加するためのコンパイル処理を省略可能である。このため、両方式を用いたインタプリンタ実行は、既存技術と比較して、動的解析処理コストの削減効果が大きい。さらに、キャッシュ記憶部126には、解析済みの解析対象ブロックのみが記憶されるので、携帯型デバイス等のメモリ容量が小さい場合に好適である。   Further, by using the code detection method according to this embodiment in combination with the technique using the cache storage unit 126, the cost required for the dynamic analysis process can be greatly reduced. Also, the compilation process for adding the hook code can be omitted both when the analysis target block exists in the analysis information and when it exists in the cache. For this reason, interpreter execution using both methods has a great effect of reducing dynamic analysis processing costs compared to existing technologies. Furthermore, since only the analyzed analysis target block is stored in the cache storage unit 126, it is suitable when the memory capacity of a portable device or the like is small.

<第2実施形態>
本実施形態では、第1解析部110及び第2解析部120が検出する検出対象コードが、特定のコードへの制御移動命令(分岐命令)である場合について説明する。
Second Embodiment
In the present embodiment, a case will be described in which the detection target code detected by the first analysis unit 110 and the second analysis unit 120 is a control transfer instruction (branch instruction) to a specific code.

ここで、検出対象コードが特定のコードへの制御移動命令(分岐命令)である場合としては、例えば特定の関数の呼出しが該当する。すなわち、検出対象コードがプログラムコード中の特定のアドレスへ分岐する分岐命令であり、分岐先が予め定められた特定の関数ということになる。特定の関数とは、例えば、プログラムコードからの呼出が許可されない関数である。   Here, as a case where the detection target code is a control transfer instruction (branch instruction) to a specific code, for example, a specific function call is applicable. That is, the detection target code is a branch instruction that branches to a specific address in the program code, and the branch destination is a specific function that is determined in advance. The specific function is, for example, a function that is not allowed to be called from program code.

本実施形態では、制御情報記憶部400は、検出対象コードを特定する情報及びフックコードを特定する情報に加えて、特定の関数のシンボル名を記憶する。具体的には、制御情報記憶部400は、検出対象コードと特定の関数のシンボル名とを対応付けて記憶する。   In the present embodiment, the control information storage unit 400 stores a symbol name of a specific function in addition to information specifying a detection target code and information specifying a hook code. Specifically, the control information storage unit 400 stores a detection target code and a symbol name of a specific function in association with each other.

なお、分岐命令には、分岐先のアドレスが直接指定される分岐命令と、分岐先のアドレスがレジスタで指定される分岐命令とがある。分岐先のアドレスが直接指定される分岐命令では、分岐先のアドレスが、プログラムコードが有するシンボルテーブルと比較される。   The branch instruction includes a branch instruction in which a branch destination address is directly designated and a branch instruction in which a branch destination address is designated by a register. In a branch instruction in which a branch destination address is directly specified, the branch destination address is compared with a symbol table included in the program code.

また、分岐先のアドレスがレジスタで指定される場合、プログラムコードを解析することで、レジスタへアドレスがコピーされるコードが検出され、当該アドレスがシンボルテーブルと比較される。分岐先のアドレスがレジスタで指定される場合の例としては、例えば次のような分岐命令が該当する。   When the branch destination address is specified by a register, the program code is analyzed to detect a code whose address is copied to the register, and the address is compared with the symbol table. For example, the following branch instruction corresponds to the case where the branch destination address is specified by a register.

MOV 0x12 lr
B lr
この分岐命令では、分岐命令(B)の分岐先であるlrレジスタの値が、MOV命令から導出される。この場合、lrレジスタの値は、アドレス0x12である。
MOV 0x12 lr
B lr
In this branch instruction, the value of the lr register that is the branch destination of the branch instruction (B) is derived from the MOV instruction. In this case, the value of the lr register is the address 0x12.

(検出対象コードの検出処理フロー)
次に、検出対象コードの検出処理フロー、具体的には、図10のステップS2003の詳細について説明する。図18は、検出対象コードの検出処理フローを示すフローチャートである。
(Detection target code detection process flow)
Next, the detection process flow for the detection target code, specifically, details of step S2003 in FIG. 10 will be described. FIG. 18 is a flowchart showing a detection process flow of the detection target code.

ステップS4001において、第1解析部110は、読み込んだコードが分岐命令であるか否かを判定する。読み込んだコードが分岐命令である場合、ステップS4002に進む。一方、読み込んだコードが分岐命令でない場合、ステップS4099に進む。   In step S4001, the first analysis unit 110 determines whether the read code is a branch instruction. If the read code is a branch instruction, the process advances to step S4002. On the other hand, if the read code is not a branch instruction, the process advances to step S4099.

ステップS4099において、第1解析部110は、読み込んだコードが検出対象コードではないと判定する。   In step S4099, the first analysis unit 110 determines that the read code is not a detection target code.

ステップS4002において、第1解析部110は、分岐命令の分岐先アドレスから呼出し対象の関数のシンボル名を取得する。   In step S4002, the first analysis unit 110 acquires the symbol name of the function to be called from the branch destination address of the branch instruction.

ステップS4003において、第1解析部110は、ステップS4002で取得されたシンボル名が、制御情報記憶部400に記憶されているシンボル名と一致するか否かを判定する。一致する場合はステップS4199に進み、一致しない場合はステップS4099に進む。   In step S4003, the first analysis unit 110 determines whether the symbol name acquired in step S4002 matches the symbol name stored in the control information storage unit 400. If they match, the process proceeds to step S4199, and if they do not match, the process proceeds to step S4099.

ステップS4199において、第1解析部110は、読み込んだコードが検出対象コードであると判定する。   In step S4199, the first analysis unit 110 determines that the read code is a detection target code.

なお、図18で説明した検出対象コード検出処理は、第1解析部110だけでなく、第2解析部120においても実行される。   The detection target code detection process described with reference to FIG. 18 is executed not only in the first analysis unit 110 but also in the second analysis unit 120.

(作用・効果)
本実施形態によれば、検出対象コードがプログラムコード中の呼出が許可されない関数を呼出す分岐命令である場合に、当該制御移動命令が確実に検出される。したがって、プログラム実行時に、呼出が許可されない関数を呼出す分岐命令が実行されないように制御することで、特定の関数や共有ライブラリが呼出されないようにすることができる。
(Action / Effect)
According to this embodiment, when the detection target code is a branch instruction that calls a function that is not permitted to be called in the program code, the control movement instruction is reliably detected. Therefore, it is possible to prevent a specific function or shared library from being called by performing control so that a branch instruction that calls a function that is not allowed to be called is not executed during program execution.

<第3実施形態>
(プログラム解析システムの構成)
本実施形態では、第1解析部110が、検出対象コードにフックコードを追加する構成について説明する。図19は、本実施形態に係るプログラム解析システムの構成を示す機能ブロック図である。
<Third Embodiment>
(Configuration of program analysis system)
In the present embodiment, a configuration in which the first analysis unit 110 adds a hook code to the detection target code will be described. FIG. 19 is a functional block diagram showing the configuration of the program analysis system according to this embodiment.

図19に示すように、第1解析部110は、フックコード追加部115及び静的解析済みコード記憶部116を備える点で、図3とは異なる。   As shown in FIG. 19, the first analysis unit 110 is different from FIG. 3 in that it includes a hook code addition unit 115 and a statically analyzed code storage unit 116.

フックコード追加部115は、プログラムコード中の検出対象コードに対してフックコードを追加する。   The hook code adding unit 115 adds a hook code to the detection target code in the program code.

解析情報記憶部114には、検出対象コードを含まないブロックに加えて、フックコードが追加されたブロックを登録ブロックとして登録する。   In the analysis information storage unit 114, a block to which a hook code is added in addition to a block that does not include a detection target code is registered as a registration block.

静的解析済みコード記憶部116は、フックコードの追加された静的解析済みコードを記憶する。   The statically analyzed code storage unit 116 stores the statically analyzed code with the hook code added.

特定部121は、解析情報記憶部114に記憶された解析情報に基づき、静的解析済みコード記憶部116に記憶された静的解析済みコードから解析対象ブロックを特定する。その他の構成については、上述した第1実施形態と同様である。   The identifying unit 121 identifies the analysis target block from the statically analyzed code stored in the statically analyzed code storage unit 116 based on the analysis information stored in the analysis information storage unit 114. About another structure, it is the same as that of 1st Embodiment mentioned above.

なお、プログラムコードが組込み機器向けに開発されたものである場合、プログラムコードのサイズがシステムの許容する最大サイズ程度であることが多い。このため、プログラムコードのサイズがシステムの許容する最大のサイズ程度である場合には、静的解析時にフックコードを追加しないようにしてもよい。   If the program code is developed for an embedded device, the size of the program code is often about the maximum size allowed by the system. For this reason, when the size of the program code is about the maximum size allowed by the system, the hook code may not be added during the static analysis.

また、プログラムコードのサイズがシステムの許容する最大サイズ程度である場合には、静的解析時にフックコードを追加しないことにより、静的解析済みコードのサイズがシステムの許容する最大のサイズを超えることが防止される。   Also, if the size of the program code is about the maximum size allowed by the system, the size of the statically analyzed code will exceed the maximum size allowed by the system by not adding hook code during static analysis. Is prevented.

(ブロック解析処理の処理フロー)
次に、本実施形態に係るブロック解析処理の処理フローについて説明する。図20は、本実施形態に係るブロック解析処理の処理フローを示すフローチャートである。図20に示すように、ステップS2006が追加されている点で、図10とは異なる。
(Block analysis processing flow)
Next, a processing flow of block analysis processing according to the present embodiment will be described. FIG. 20 is a flowchart showing a processing flow of block analysis processing according to the present embodiment. As shown in FIG. 20, it differs from FIG. 10 in that step S2006 is added.

ステップS2006では、当該コードが検出対象コードである場合に、第1解析部110は、プログラム制御情報を参照することでフックコードを追加する。   In step S2006, when the code is a detection target code, the first analysis unit 110 adds a hook code by referring to the program control information.

また、ステップS2005では、当該ブロックに検出対象コードが検出された場合、及び当該ブロックに検出対象コードが検出されなかった場合の両方で、当該ブロックは解析情報に登録される。   In step S2005, the block is registered in the analysis information both when the detection target code is detected in the block and when the detection target code is not detected in the block.

(作用・効果)
本実施形態によれば、解析情報記憶部114は、検出対象コードを含まないブロックに加えて、フックコードが追加されたブロックを登録する。特定部121は、解析情報記憶部114に記憶された解析情報に基づき、静的解析済みコード記憶部116に記憶された静的解析済みコードから解析対象領域を特定する。
(Action / Effect)
According to the present embodiment, the analysis information storage unit 114 registers a block to which a hook code is added in addition to a block that does not include a detection target code. Based on the analysis information stored in the analysis information storage unit 114, the specification unit 121 specifies an analysis target region from the statically analyzed code stored in the statically analyzed code storage unit 116.

したがって、静的解析時にフックコードの追加されたブロックについては動的解析(コンパイル)の対象外とすることで、動的解析時におけるコンパイル処理回数が削減される。   Therefore, the block to which the hook code is added at the time of the static analysis is excluded from the target of the dynamic analysis (compilation), thereby reducing the number of compilation processes at the time of the dynamic analysis.

<第3実施形態の変更例>
上述した第3実施形態では、プログラムコードのサイズがシステムの許容する最大のサイズ程度である場合には、静的解析時にフックコードを追加しない一例について説明した。静的解析済みコードにフックコードを追加する場合、コードサイズが増加する。
<Modified example of the third embodiment>
In the third embodiment described above, an example in which no hook code is added at the time of static analysis when the size of the program code is about the maximum size allowed by the system has been described. When hook code is added to statically analyzed code, the code size increases.

そこで、本変更例では、検出対象コードが分岐命令である場合に、フックコードを含むフック専用関数を使用する構成について説明する。フック専用関数は、例えば動的ライブラリ関数として、プログラム実行時にプログラムコードと連結される。   Therefore, in this modified example, a configuration in which a hook dedicated function including a hook code is used when the detection target code is a branch instruction will be described. The hook dedicated function is linked with the program code at the time of program execution, for example, as a dynamic library function.

第1解析部110は、ブロックから検出対象コードを検出する。その際、プログラムコードのサイズ制限が発生していた場合、第1解析部110は、検出対象コードの分岐先を書き換える。つまり、検出対象コードが分岐命令である場合に、当該分岐命令の分岐先をフック専用関数へ書き換えることとなる。   The first analysis unit 110 detects a detection target code from the block. At this time, if the program code size limit has occurred, the first analysis unit 110 rewrites the branch destination of the detection target code. That is, when the detection target code is a branch instruction, the branch destination of the branch instruction is rewritten to the hook dedicated function.

一方で、フック専用関数は、図21に示すように、フックコード及び分岐命令を含む。これにより、検出対象コード(分岐命令)から呼出されたフック専用関数は、フックコードの実行後に本来の分岐先である特定の関数へ分岐し、当該特定の関数が実行された後は元のブロックへとリターンされる。なお、フック専用関数は、検出対象コード毎に用意される。   On the other hand, the hook dedicated function includes a hook code and a branch instruction as shown in FIG. As a result, the hook dedicated function called from the detection target code (branch instruction) branches to the specific function that is the original branch destination after the hook code is executed, and the original block is executed after the specific function is executed. Returned to A hook dedicated function is prepared for each detection target code.

図21では、矢印が分岐元と分岐先を表し、点線がフックコードを伴わない通常の分岐を表し、実線がフックコードを伴う分岐を表している。元のコードにおいて、関数呼出しにより、検出対象コードから特定のコードへ分岐していたとする。この場合、検出対象コードからアドレスxに分岐し、特定のコードの実行後、アドレスyから元のブロックに分岐する。   In FIG. 21, arrows indicate a branch source and a branch destination, a dotted line indicates a normal branch without a hook code, and a solid line indicates a branch with a hook code. It is assumed that the original code branches from the detection target code to a specific code by a function call. In this case, the branch is made from the detection target code to the address x, and after execution of the specific code, the branch is made from the address y to the original block.

第1解析部110は、検出対象コードの分岐先を書き換え、分岐先をフック専用関数の開始アドレスzとする。フック専用関数では、フックコードの後に特定のコードへの分岐命令が埋め込まれている。特定のコードの実行後は、元のブロックへ戻る。   The first analysis unit 110 rewrites the branch destination of the detection target code, and sets the branch destination as the start address z of the hook dedicated function. In the hook dedicated function, a branch instruction to a specific code is embedded after the hook code. After executing the specific code, return to the original block.

フック専用関数により、特定のコードが実行される前に必ずフックコードが実行され、検出対象コードの実行を制御することが可能となる。なお、フック専用関数を使用することで、プログラム実行時の処理負荷が増加するので、コードサイズの問題が生じた場合に本変更例を適用することが好ましい。   By the hook dedicated function, the hook code is always executed before the specific code is executed, and the execution of the detection target code can be controlled. In addition, since the processing load at the time of program execution increases by using a hook exclusive function, it is preferable to apply this change example when the problem of a code size arises.

<第4実施形態>
本実施形態では、制御情報記憶部400が記憶するプログラム制御情報が更新される場合に対応可能な構成について説明する。プログラム制御情報に含まれる検出対象コードが更新された場合、解析情報記憶部114が記憶する解析情報も更新される必要がある。
<Fourth embodiment>
In the present embodiment, a configuration that can be used when the program control information stored in the control information storage unit 400 is updated will be described. When the detection target code included in the program control information is updated, the analysis information stored in the analysis information storage unit 114 needs to be updated.

第2解析部120が動的解析を実行中にプログラム制御情報が更新された場合、動的解析を停止し、解析情報の再生成が完了するまで動的解析が中断される。このため、解析情報の再生成は、できるだけ短時間で行う必要がある。   When the program control information is updated while the second analysis unit 120 is executing the dynamic analysis, the dynamic analysis is stopped and the dynamic analysis is suspended until the regeneration of the analysis information is completed. For this reason, it is necessary to regenerate the analysis information in as short a time as possible.

(プログラム解析システムの構成)
図22は、本実施形態に係るプログラム解析システムの構成を示す機能ブロック図である。図22に示すように、制御情報記憶部400は候補コードを記憶する点で、図3とは異なる。候補コードは、プログラム制御除法の更新により、検出対象コードとなる可能性のあるコードである。
(Configuration of program analysis system)
FIG. 22 is a functional block diagram showing the configuration of the program analysis system according to this embodiment. As shown in FIG. 22, the control information storage unit 400 is different from FIG. 3 in that candidate codes are stored. The candidate code is a code that may become a detection target code by updating the program control division method.

例えば、特定のユーザがプログラムを利用する場合にのみプログラムの機能制限を行う場合、当該機能を呼出すコードは、候補コードとなり、当該プログラムが利用される場合には検出対象コードとなる。プログラム制御情報の更新により検出対象コードが更新される場合でも、新たな検出対象コードは、候補コードの中から選択される。   For example, when the function of a program is restricted only when a specific user uses the program, the code that calls the function becomes a candidate code, and when the program is used, the code becomes a detection target code. Even when the detection target code is updated by updating the program control information, a new detection target code is selected from the candidate codes.

また、第1解析部110は、再生成情報記憶部117を備える点で、図3とは異なる。本実施形態に係る解析情報生成部113は、解析情報に加えて、再生成情報を生成する。解析情報生成部113は、候補コードを含むブロックを登録ブロックとする。再生成情報は、解析情報と同様に、ブロックID、開始アドレス及び終了アドレスを含む。   Moreover, the 1st analysis part 110 differs from FIG. 3 by the point provided with the regeneration information storage part 117. FIG. The analysis information generation unit 113 according to the present embodiment generates regeneration information in addition to the analysis information. The analysis information generation unit 113 sets a block including the candidate code as a registered block. Similar to the analysis information, the regeneration information includes a block ID, a start address, and an end address.

プログラム制御情報の更新により、解析情報を更新する際、第1解析部110(具体的には、第1検出部112)によって解析しなければならないブロックは、再生成情報記憶部117に登録されたブロックのみとなる。具体的には、再生成情報に登録されたすべてのブロックに対してブロック解析処理を実行し、解析情報を更新する。   When the analysis information is updated by updating the program control information, the blocks that must be analyzed by the first analysis unit 110 (specifically, the first detection unit 112) are registered in the regeneration information storage unit 117. Only blocks. Specifically, block analysis processing is executed for all the blocks registered in the regeneration information, and the analysis information is updated.

本実施形態に係るブロック解析処理では、ブロックを次の3つに分類する。   In the block analysis processing according to the present embodiment, the blocks are classified into the following three types.

(1)検出対象コードを含むブロック
(2)検出対象コードではない候補コードのみを含むブロック
(3)候補コードを含まないブロック
上記(1)に分類されるブロックは、再生成情報にのみ登録されるべきブロックである。上記(2)に分類されるブロックは、解析情報及び再生成情報の両方に登録されるべきブロックである。上記(3)に分類されるブロックは、解析情報にのみ登録されるべきブロックである。
(1) Blocks including detection target codes (2) Blocks including only candidate codes that are not detection target codes (3) Blocks not including candidate codes Blocks classified in (1) above are registered only in regeneration information It should be a block. The blocks classified as (2) are blocks that should be registered in both analysis information and regeneration information. The blocks classified as (3) above are blocks that should be registered only in the analysis information.

(再生成情報の生成方法)
次に、ブロック解析処理における再生成情報の生成方法について説明する。図23は、ブロック解析処理における再生成情報の生成方法を示すフローチャートである。図23では、上述した第1実施形態に係る処理フローから、新たにステップS2007〜ステップS2010が追加されている。
(Regeneration information generation method)
Next, a method for generating regeneration information in block analysis processing will be described. FIG. 23 is a flowchart illustrating a method for generating regeneration information in block analysis processing. In FIG. 23, steps S2007 to S2010 are newly added from the processing flow according to the first embodiment described above.

ステップS2007において、第1解析部110は、検出対象コードを含むブロックを再生成情報に登録する。   In step S2007, the first analysis unit 110 registers a block including the detection target code in the regeneration information.

ステップS2008において、第1解析部110は、当該コードが検出対象コードではない場合に、当該コードが候補コードに該当するか否かを判定する。当該コードが候補コードに該当しない場合、ステップS2004に進む。一方、当該コードが候補コードに該当する場合は、ステップS2009に進み、当該コードが再生成情報に既に登録されているか否かが判定される。当該コードが再生成情報に登録されていなければ、ステップS2010において、当該ブロックが再生成情報に登録される。
なお、ステップS2009が必要な理由は、当該ブロックに複数の候補コードが存在した場合に、当該ブロックの解析処理中は複数回ステップS2010に進む可能性があり、再生成情報の重複登録が発生する可能性があるためである。
In step S2008, the first analysis unit 110 determines whether or not the code corresponds to a candidate code when the code is not a detection target code. If the code does not correspond to a candidate code, the process proceeds to step S2004. On the other hand, if the code corresponds to a candidate code, the process proceeds to step S2009, and it is determined whether or not the code is already registered in the regeneration information. If the code is not registered in the regeneration information, the block is registered in the regeneration information in step S2010.
The reason why step S2009 is necessary is that when there are a plurality of candidate codes in the block, there is a possibility that the process proceeds to step S2010 a plurality of times during the analysis processing of the block, and duplicate registration of regenerated information occurs. This is because there is a possibility.

(作用・効果)
本実施形態によれば、第1解析部110は、検出対象コードがいずれかの候補コードに変更された場合に、再生成情報に登録されたブロックから新たな検出対象コードを検出する。したがって、再生成情報を予め生成しておくことで、プログラム制御情報が更新されてもプログラムコード全体を再解析する必要が無くなる。
(Action / Effect)
According to the present embodiment, when the detection target code is changed to any candidate code, the first analysis unit 110 detects a new detection target code from the blocks registered in the regeneration information. Therefore, by generating the regeneration information in advance, it is not necessary to re-analyze the entire program code even if the program control information is updated.

<第5実施形態>
本実施形態では、図14のステップS3001の処理、すなわち、解析対象ブロックの登録ブロック内検索処理に着目する。解析対象ブロックは、コード実行装置200が出力する解析対象ブロックアドレスにより決定される。この解析対象ブロックアドレスは、プログラムカウンタが指すアドレス、すなわち次に実行されるべきコードのアドレスである。
<Fifth Embodiment>
In the present embodiment, attention is focused on the processing in step S3001 in FIG. The analysis target block is determined by the analysis target block address output from the code execution device 200. This analysis target block address is an address indicated by the program counter, that is, an address of a code to be executed next.

一般的に、プログラム内で実行されるコードは局所性を持ち、プログラム全体のコードが一様に実行されるわけではなく、一部のコードが集中的に実行されることが多い。従って、出力される解析対象ブロックアドレスにも局所性が存在し、一部のアドレスが多く該当する可能性が高い。   In general, code executed in a program has locality, and the code of the entire program is not executed uniformly, and part of the code is often executed intensively. Therefore, there is a locality in the output block address to be analyzed, and there is a high possibility that a part of the addresses will correspond.

一部のコードが集中的に実行される場合、解析対象ブロック(解析情報記憶部114)においても同様に、一部のブロックが繰り返し検索されることとなり、検索結果として、同じ登録ブロックが頻繁にアクセスされることとなる。   When some codes are executed intensively, some blocks are similarly searched in the analysis target block (analysis information storage unit 114), and the same registered block is frequently found as a search result. Will be accessed.

(プログラム解析システムの構成)
図24は、本実施形態に係るプログラム解析システムの構成図である。図24に示すように、第2解析部120は、履歴情報記憶部127を備える点で、図3とは異なっている。履歴情報記憶部127は、図25に示すように、登録ブロック(検出対象コードを含まないブロック)のブロックIDと、当該登録ブロックの開始アドレスと、当該登録ブロックの終了アドレスと、当該登録ブロックがコード実行部210によって実行された回数とを対応付けた履歴情報を記憶する。
(Configuration of program analysis system)
FIG. 24 is a configuration diagram of the program analysis system according to the present embodiment. As shown in FIG. 24, the second analysis unit 120 is different from FIG. 3 in that it includes a history information storage unit 127. As shown in FIG. 25, the history information storage unit 127 includes a block ID of a registration block (a block that does not include a detection target code), a start address of the registration block, an end address of the registration block, and the registration block. History information in which the number of times executed by the code execution unit 210 is associated is stored.

履歴情報記憶部127に記憶される履歴情報は、第1解析部110の解析情報生成部113によって利用される。解析情報生成部113は、履歴情報に基づき、解析情報記憶部114に記憶されている解析情報を更新する。   The history information stored in the history information storage unit 127 is used by the analysis information generation unit 113 of the first analysis unit 110. The analysis information generation unit 113 updates the analysis information stored in the analysis information storage unit 114 based on the history information.

具体的には、解析情報生成部113は、特定部121によってアクセスされる頻度の高い登録ブロックが、より短い時間で検索されるように解析情報記憶部114のデータ構造を変更する。こうすることで、ステップS3001の処理、すなわち、特定部121が解析情報記憶部114中の登録ブロックを検索する際に実行される処理が高速化される。   Specifically, the analysis information generation unit 113 changes the data structure of the analysis information storage unit 114 so that registered blocks that are frequently accessed by the specifying unit 121 are searched in a shorter time. This speeds up the process in step S3001, that is, the process executed when the specifying unit 121 searches for the registered block in the analysis information storage unit 114.

例えば、初回のプログラム実行時において、特定部121は、解析情報記憶部114に記憶される解析情報を利用して、プログラムコード中の解析対象ブロック(登録ブロック)を特定するとともに、コード実行部210によって実行された登録ブロックを記録した履歴情報を生成する。   For example, at the time of the first program execution, the specifying unit 121 uses the analysis information stored in the analysis information storage unit 114 to specify the analysis target block (registered block) in the program code, and the code execution unit 210. The history information recording the registration block executed by is generated.

プログラムの実行終了後、解析情報生成部113は、生成された履歴情報を用いて、解析情報記憶部114に記憶される解析情報を更新する。例えば、解析情報記憶部114に記憶される各データが、エントリの上位から線形検索される場合、解析情報記憶部114は、履歴情報により、実行回数が多い登録ブロックをより上位に配置する。図25の例では、ブロックID2のブロックが、ブロックID1のブロックよりも上位に配置される。   After the execution of the program is completed, the analysis information generation unit 113 updates the analysis information stored in the analysis information storage unit 114 using the generated history information. For example, when each piece of data stored in the analysis information storage unit 114 is linearly searched from the top of the entry, the analysis information storage unit 114 arranges a registration block with a large number of executions at a higher level based on history information. In the example of FIG. 25, the block with the block ID2 is arranged higher than the block with the block ID1.

尚、データ検索に利用されるデータ構造は、ハッシュテーブルを利用したインデックスを持つのが一般的である。この場合、インデックスにより検索されるデータは、O(1)で探索可能であり、理想的には上述したような線形検索は発生しない。   The data structure used for data search generally has an index using a hash table. In this case, the data searched by the index can be searched by O (1), and ideally the linear search as described above does not occur.

しかし、実際には同一インデックスに射影される複数のデータが存在するために、一度インデックスによりデータを絞った後は、線形検索が実行される。そのため、ハッシュテーブルを利用して解析情報を実現した場合でも、履歴情報を利用した解析情報の更新は有用であると言える。   However, since there are actually a plurality of data projected to the same index, linear search is executed after the data is narrowed down once by the index. Therefore, even when analysis information is realized using a hash table, it can be said that updating analysis information using history information is useful.

(作用・効果)
本実施形態によれば、初回のプログラム実行結果に応じて、解析情報が更新される。第2解析部は、次回のプログラム実行時においては、更新された解析情報を利用して、プログラムコードが解析される。これにより、初回のプログラム実行と比較して、次回のプログラム実行時においては、短時間でプログラムの解析を行うことが可能となる。
(Action / Effect)
According to this embodiment, analysis information is updated according to the first program execution result. In the next program execution, the second analysis unit analyzes the program code using the updated analysis information. As a result, the program can be analyzed in a shorter time when the next program is executed than when the first program is executed.

<第6実施形態>
本実施形態では、図7のステップS1003の処理、すなわち、解析したブロックの分岐先アドレスを全て取得する処理に注目する。このような処理を実現するためには、当該ブロックに含まれる分岐命令を検出し、分岐先を取得する必要がある。
<Sixth Embodiment>
In the present embodiment, attention is focused on the process in step S1003 of FIG. 7, that is, the process of acquiring all branch destination addresses of the analyzed block. In order to realize such processing, it is necessary to detect a branch instruction included in the block and acquire a branch destination.

ここで、実行可能形式のプログラムコードを解析対象とした場合、分岐命令は、大きく直接分岐命令と間接分岐命令に分けられる。直接分岐命令は、命令中に分岐先アドレスが明記されているため、分岐先の取得が容易である。   Here, when an executable program code is an analysis target, branch instructions are roughly divided into direct branch instructions and indirect branch instructions. In the direct branch instruction, the branch destination is easily obtained because the branch destination address is specified in the instruction.

一方で、間接分岐命令は、プログラムカウンタを利用した分岐である。間接分岐命令におけるプログラムカウンタの値は、当該命令とは別の命令により決定されており、プログラム実行時以外での値の特定は困難である。そのため、ステップS1003において、解析対象ブロックが間接分岐命令を含む場合、第1解析部110は、間接分岐命令の分岐先の取得が非常に困難である。   On the other hand, the indirect branch instruction is a branch using a program counter. The value of the program counter in the indirect branch instruction is determined by an instruction different from the instruction, and it is difficult to specify a value other than during program execution. Therefore, when the analysis target block includes an indirect branch instruction in step S1003, it is very difficult for the first analysis unit 110 to acquire the branch destination of the indirect branch instruction.

一方で、間接分岐命令の分岐先は、プログラム実行時には容易に特定可能である。なぜなら、プログラム実行時には、プログラムカウンタに分岐先の値が代入されるので、当該分岐命令を解析するだけで、分岐先を特定可能となるためである。   On the other hand, the branch destination of an indirect branch instruction can be easily specified during program execution. This is because the branch destination value is assigned to the program counter when the program is executed, so that the branch destination can be specified only by analyzing the branch instruction.

そこで、本実施形態では、ブロックに間接分岐命令が存在した場合に、第2解析部120の第2検出部122は、プログラム実行時において間接分岐命令の分岐先を記録する。   Therefore, in this embodiment, when an indirect branch instruction exists in the block, the second detection unit 122 of the second analysis unit 120 records the branch destination of the indirect branch instruction at the time of program execution.

(プログラム解析システムの構成)
図26は、本実施形態に係るプログラム解析システムの構成図である。図26に示す通り、第2解析部120は、分岐先情報記憶部128を備える点で、図3とは異なっている。
(Configuration of program analysis system)
FIG. 26 is a configuration diagram of the program analysis system according to the present embodiment. As shown in FIG. 26, the second analysis unit 120 is different from FIG. 3 in that it includes a branch destination information storage unit 128.

第2解析部120の第2検出部122は、プログラム実行時に、間接分岐命令を検出し、分岐元のブロックを特定可能な情報(当該ブロックID、当該ブロックアドレス)と、当該分岐命令による分岐先とを分岐先情報として分岐先情報記憶部128に格納する。   The second detection unit 122 of the second analysis unit 120 detects an indirect branch instruction at the time of program execution, information that can specify the branch source block (the block ID, the block address), and the branch destination by the branch instruction Are stored in the branch destination information storage unit 128 as branch destination information.

上記述べた通り、間接分岐命令が検出できれば、プログラム実行時の分岐先の特定は容易である。また、アーキテクチャ依存ではあるが、間接分岐命令は高々数種類に限定されるため、第2検出部122による間接分岐命令の検出は容易である。例えば、ARMTMアーキテクチャにおけるアセンブラコードの場合の間接分岐命令は、例えば、図27に示す通りとなる。 As described above, if an indirect branch instruction can be detected, it is easy to specify a branch destination during program execution. Moreover, although it depends on the architecture, the number of indirect branch instructions is limited to several types at most, so that the indirect branch instruction can be easily detected by the second detection unit 122. For example, an indirect branch instruction in the case of an assembler code in the ARM architecture is as shown in FIG. 27, for example.

(分岐先検出処理)
次に、本実施形態に係る分岐先検出処理について説明する。図28は、分岐先検出処理の概要を示す図である。図28において、ブロック0は、間接分岐命令によりブロック1に分岐する。分岐先情報がない場合、このブロック0からの分岐先であるブロック1のアドレスを特定することは非常に困難である。このため、図28(a)に示すように、ブロック1〜3において検出漏れが生じる。
(Branch destination detection processing)
Next, branch destination detection processing according to the present embodiment will be described. FIG. 28 is a diagram showing an outline of the branch destination detection process. In FIG. 28, block 0 branches to block 1 by an indirect branch instruction. When there is no branch destination information, it is very difficult to specify the address of block 1 which is a branch destination from this block 0. For this reason, as shown in FIG. 28A, detection omission occurs in the blocks 1 to 3.

一方、分岐先情報を用いることで、ブロック0からの分岐先であるブロック1のアドレスが特定され、ブロック0を解析後にブロック1が特定される。さらに、図28(b)に示すように、ブロック1の分岐先のプログラムコード(ブロック2,3)が解析可能となる。   On the other hand, by using the branch destination information, the address of the block 1 that is the branch destination from the block 0 is specified, and after analyzing the block 0, the block 1 is specified. Further, as shown in FIG. 28B, the branch destination program code of block 1 (blocks 2 and 3) can be analyzed.

なお、図28に示すように、分岐先情報記憶部128は、分岐先のブロックIDと、分岐元のブロックIDと、分岐先アドレスとを対応付けた分岐先情報を記憶する。   As shown in FIG. 28, the branch destination information storage unit 128 stores branch destination information in which a branch destination block ID, a branch source block ID, and a branch destination address are associated with each other.

図29は、解析情報生成処理の処理フローを示すフローチャートである。図29では、ステップS1011が追加されている点で、図7とは異なっている。ステップS1011及びステップS1003では、第1検出部112は、分岐先情報を用いて、分岐先アドレスをすべて取得する。   FIG. 29 is a flowchart showing a processing flow of analysis information generation processing. 29 is different from FIG. 7 in that step S1011 is added. In Step S1011 and Step S1003, the first detection unit 112 acquires all branch destination addresses using the branch destination information.

(作用・効果)
本実施形態によれば、第1検出部122において検出対象コードの検出漏れが存在していた場合に、第1検出部122は、分岐先情報を利用することで、検出漏れが生じていた検出対象コードが検出可能となる。
(Action / Effect)
According to the present embodiment, when there is a detection failure of the detection target code in the first detection unit 122, the first detection unit 122 uses the branch destination information to detect the detection failure. The target code can be detected.

<その他の実施形態>
上記のように、本発明は第1〜第6実施形態によって記載したが、この開示の一部をなす論述及び図面はこの発明を限定するものであると理解すべきではない。この開示から当業者には様々な代替実施形態、実施例及び運用技術が明らかとなる。
<Other embodiments>
As described above, the present invention has been described according to the first to sixth embodiments. However, it should not be understood that the description and drawings constituting a part of this disclosure limit the present invention. From this disclosure, various alternative embodiments, examples and operational techniques will be apparent to those skilled in the art.

上述した実施形態では、検出対象コードが分岐命令である場合について説明したが、検出対象コードが分岐命令以外の命令であってもよい。   In the embodiment described above, the case where the detection target code is a branch instruction has been described, but the detection target code may be an instruction other than the branch instruction.

また、上述した実施形態では、コード実行装置200を備えるプログラム解析システムについて説明したが、本発明は、コード実行装置を備えないプログラム解析システムにも応用可能である。   In the above-described embodiment, the program analysis system including the code execution device 200 has been described. However, the present invention can also be applied to a program analysis system that does not include the code execution device.

このように本発明は、ここでは記載していない様々な実施形態等を包含するということを理解すべきである。したがって、本発明はこの開示から妥当な特許請求の範囲の発明特定事項によってのみ限定されるものである。   Thus, it should be understood that the present invention includes various embodiments and the like not described herein. Therefore, the present invention is limited only by the invention specifying matters in the scope of claims reasonable from this disclosure.

本発明の背景技術を説明するための図である(その1)。It is a figure for demonstrating the background art of this invention (the 1). 本発明の背景技術を説明するための図である(その2)。It is a figure for demonstrating the background art of this invention (the 2). 本発明の第1実施形態に係るプログラム解析システムの機能ブロック図である。It is a functional block diagram of the program analysis system concerning a 1st embodiment of the present invention. 本発明の第1実施形態に係る解析情報の一例を示す図である。It is a figure which shows an example of the analysis information which concerns on 1st Embodiment of this invention. 本発明の第1実施形態に係る解析情報生成処理を説明するための図である(その1)。It is a figure for demonstrating the analysis information generation process which concerns on 1st Embodiment of this invention (the 1). 本発明の第1実施形態に係る解析情報生成処理を説明するための図である(その2)。It is a figure for demonstrating the analysis information generation process which concerns on 1st Embodiment of this invention (the 2). 本発明の第1実施形態に係る解析情報生成処理の処理フローを示すフローチャートである。It is a flowchart which shows the processing flow of the analysis information generation process which concerns on 1st Embodiment of this invention. 本発明の第1実施形態に係る解析情報生成処理を説明するための図である(その3)。It is a figure for demonstrating the analysis information generation process which concerns on 1st Embodiment of this invention (the 3). 本発明の第1実施形態に係る解析情報生成処理を説明するための図である(その4)。It is a figure for demonstrating the analysis information generation process which concerns on 1st Embodiment of this invention (the 4). 本発明の第1実施形態に係るブロック解析処理の処理フローを示すフローチャートである。It is a flowchart which shows the processing flow of the block analysis process which concerns on 1st Embodiment of this invention. 本発明の第1実施形態に係るブロック解析処理を説明するための図である(その1)。It is a figure for demonstrating the block analysis process which concerns on 1st Embodiment of this invention (the 1). 本発明の第1実施形態に係るブロック解析処理を説明するための図である(その2)。It is a figure for demonstrating the block analysis process which concerns on 1st Embodiment of this invention (the 2). 本発明の第1実施形態に係るブロック解析処理を説明するための図である(その3)。It is a figure for demonstrating the block analysis process which concerns on 1st Embodiment of this invention (the 3). 本発明の第1実施形態に係る動的解析処理の処理フローを示すフローチャートである。It is a flowchart which shows the processing flow of the dynamic analysis process which concerns on 1st Embodiment of this invention. 本発明の第1実施形態に係る動的解析処理の具体例を示す図である(その1)。It is a figure which shows the specific example of the dynamic analysis process which concerns on 1st Embodiment of this invention (the 1). 本発明の第1実施形態に係る動的解析処理の具体例を示す図である(その2)。It is a figure which shows the specific example of the dynamic analysis process which concerns on 1st Embodiment of this invention (the 2). 本発明の第1実施形態に係る動的解析処理の具体例を示す図である(その3)。It is a figure which shows the specific example of the dynamic analysis process which concerns on 1st Embodiment of this invention (the 3). 本発明の第2実施形態に係る検出対象コードの検出処理フローを示すフローチャートである。It is a flowchart which shows the detection processing flow of the detection target code which concerns on 2nd Embodiment of this invention. 本発明の第3実施形態に係るプログラム解析システムの構成を示す機能ブロック図である。It is a functional block diagram which shows the structure of the program analysis system which concerns on 3rd Embodiment of this invention. 本発明の第3実施形態に係るブロック解析処理の処理フローを示すフローチャートである。It is a flowchart which shows the processing flow of the block analysis process which concerns on 3rd Embodiment of this invention. 本発明の第3実施形態に係るブロック解析処理を説明するための図である。It is a figure for demonstrating the block analysis process which concerns on 3rd Embodiment of this invention. 本発明の第4実施形態に係るプログラム解析システムの構成を示す機能ブロック図である。It is a functional block diagram which shows the structure of the program analysis system which concerns on 4th Embodiment of this invention. 本発明の第4実施形態に係るブロック解析処理における再生成情報の生成方法を示すフローチャートである。It is a flowchart which shows the production | generation method of the regeneration information in the block analysis process which concerns on 4th Embodiment of this invention. 本発明の第5実施形態に係るプログラム解析システムの構成を示す機能ブロック図である。It is a functional block diagram which shows the structure of the program analysis system which concerns on 5th Embodiment of this invention. 本発明の第5実施形態に係る履歴情報の一例を示す図である。It is a figure which shows an example of the historical information which concerns on 5th Embodiment of this invention. 本発明の第6実施形態に係るプログラム解析システムの構成を示す機能ブロック図である。It is a functional block diagram which shows the structure of the program analysis system which concerns on 6th Embodiment of this invention. 間接分岐命令の一例を示す図である。It is a figure which shows an example of an indirect branch instruction. 本発明の第6実施形態に係る分岐先検出処理の概要を示す図である。It is a figure which shows the outline | summary of the branch destination detection process which concerns on 6th Embodiment of this invention. 本発明の第6実施形態に係る解析情報生成処理の処理フローを示すフローチャートである。It is a flowchart which shows the processing flow of the analysis information generation process which concerns on 6th Embodiment of this invention.

符号の説明Explanation of symbols

100…コード検出装置、110…第1解析部、111…ブロック生成部、112…第1検出部、113…解析情報生成部、114…解析情報記憶部、115…フックコード追加部、116…静的解析済みコード記憶部、117…再生成情報記憶部、120…第2解析部、121…特定部、122…第2検出部、123…コード出力部、124…コンパイル部、125…フックコード追加部、126…キャッシュ記憶部、127…履歴情報記憶部、128…分岐先情報記憶部、200…コード実行装置、210…コード実行部、220…コード制御部、300…プログラムコード記憶部、320…動的解析済みコード記憶部、400…制御情報記憶部、800…制御ポリシー記憶部   DESCRIPTION OF SYMBOLS 100 ... Code detection apparatus 110 ... 1st analysis part 111 ... Block generation part 112 ... 1st detection part 113 ... Analysis information generation part 114 ... Analysis information storage part 115 ... Hook code addition part, 116 ... Static Analyzed code storage unit, 117 ... regeneration information storage unit, 120 ... second analysis unit, 121 ... identification unit, 122 ... second detection unit, 123 ... code output unit, 124 ... compilation unit, 125 ... addition of hook code 126: Cache storage unit, 127 ... History information storage unit, 128 ... Branch destination information storage unit, 200 ... Code execution device, 210 ... Code execution unit, 220 ... Code control unit, 300 ... Program code storage unit, 320 ... Dynamically analyzed code storage unit, 400 ... control information storage unit, 800 ... control policy storage unit

Claims (17)

複数のコードを含むプログラムコードを解析することで検出対象コードを検出するコード検出装置であって、
前記プログラムコードの実行前に、前記プログラムコードを解析する第1解析部と、
前記プログラムコードの実行中に、前記第1解析部による解析結果を用いて前記プログラムコードを解析する第2解析部とを備え、
前記第1解析部は、
前記プログラムコードから前記検出対象コードを検出する第1検出部と、
前記第1検出部による検出結果に基づき、前記プログラムコードのうち前記第2解析部が解析対象としない領域である解析対象領域を特定するための解析情報を生成する解析情報生成部とを備え、
前記第2解析部は、
前記解析情報を参照し、前記解析情報が示す非解析対象領域を除いた領域を前記プログラムコード中の前記解析対象領域として特定する特定部と、
前記特定部によって特定された前記解析対象領域から前記検出対象コードを検出する第2検出部とを備え
前記第1解析部が生成する前記解析情報は、前記プログラムコードのうち前記検出対象コードを含まない領域を非解析対象領域として特定する情報を含み、
前記第2解析部は、前記プログラムコードの実行中に、前記プログラムコードを実行するコード実行部によって与えられる次に実行されるべきプログラムコードのアドレスに基づいて、前記プログラムコードのうち解析すべきプログラムコードを特定し、前記解析情報を元に当該プログラムコードが解析対象領域であるか否かを判定することを特徴とするコード検出装置。
A code detection device for detecting a detection target code by analyzing a program code including a plurality of codes,
A first analysis unit for analyzing the program code before executing the program code ;
A second analysis unit that analyzes the program code using an analysis result by the first analysis unit during execution of the program code ;
The first analysis unit includes:
A first detection unit for detecting the detection target code from the program code;
An analysis information generation unit configured to generate analysis information for specifying a non- analysis target region that is a region not to be analyzed by the second analysis unit based on a detection result by the first detection unit; ,
The second analysis unit includes
A reference unit that refers to the analysis information , and specifies a region excluding the non-analysis target region indicated by the analysis information as the analysis target region in the program code;
A second detection unit that detects the detection target code from the analysis target region specified by the specification unit ;
The analysis information generated by the first analysis unit includes information for specifying a region that does not include the detection target code in the program code as a non-analysis target region,
The second analysis unit is a program to be analyzed among the program codes based on an address of a program code to be executed next given by a code execution unit that executes the program code during the execution of the program code. A code detection apparatus characterized by identifying a code and determining whether or not the program code is an analysis target area based on the analysis information .
前記検出対象コードの実行を制御するためのコードであるフックコードを含むプログラム制御情報を記憶する制御情報記憶部をさらに備え、
前記第2解析部は、前記解析対象領域から検出された前記検出対象コードに前記フックコードを追加することを特徴とする請求項1に記載のコード検出装置。
A control information storage unit that stores program control information including a hook code that is a code for controlling execution of the detection target code;
The code detection apparatus according to claim 1, wherein the second analysis unit adds the hook code to the detection target code detected from the analysis target region.
前記検出対象コードの実行を制御するためのコードであるフックコードを含むプログラム制御情報を記憶する制御情報記憶部をさらに備え、
前記第1解析部は、前記プログラムコードから検出された前記検出対象コードに前記フックコードを追加し、
前記特定部は、前記第1解析部により前記フックコードの追加されていない領域を前記解析対象領域として特定することを特徴とする請求項1に記載のコード検出装置。
A control information storage unit that stores program control information including a hook code that is a code for controlling execution of the detection target code;
The first analysis unit adds the hook code to the detection target code detected from the program code,
The code detection apparatus according to claim 1, wherein the specifying unit specifies a region where the hook code is not added by the first analysis unit as the analysis target region.
前記第1解析部は、前記プログラムコードのサイズまたは処理負荷に応じて、前記プログラムコードから検出された前記検出対象コードに前記フックコードを追加するか否かを判定することを特徴とする請求項に記載のコード検出装置。 The said 1st analysis part determines whether the said hook code is added to the said detection object code detected from the said program code according to the size or processing load of the said program code. 4. The code detection device according to 3 . 前記第1解析部は、前記フックコードを含むフック専用関数へ分岐する分岐命令を、前記フックコードとして前記検出対象コードに追加することを特徴とする請求項に記載のコード検出装置。 The code detection apparatus according to claim 3 , wherein the first analysis unit adds a branch instruction for branching to a hook dedicated function including the hook code as the hook code to the detection target code. 前記検出対象コードを特定する情報を含むプログラム制御情報を記憶する制御情報記憶部をさらに備え、
前記第1検出部は、前記プログラム制御情報が更新された場合、更新後の検出対象コードを特定する情報に基づいて前記プログラムコードから前記更新後の検出対象コードを検出し、
前記解析情報生成部は、前記第1検出部による前記更新後の検出対象コードの検出結果に基づき、前記解析情報を更新することを特徴とする請求項1に記載のコード検出装置。
A control information storage unit for storing program control information including information for specifying the detection target code;
When the program control information is updated, the first detection unit detects the updated detection target code from the program code based on information for specifying the updated detection target code,
The code detection apparatus according to claim 1, wherein the analysis information generation unit updates the analysis information based on a detection result of the detection target code after the update by the first detection unit.
前記検出対象コードを特定する情報と、前記検出対象コードの変更先候補のコードである候補コードを特定する情報を含むプログラム制御情報を記憶する制御情報記憶部をさらに備え、
前記第1検出部は、前記プログラム制御情報に基づき、前記プログラムコードから前記検出対象コード及び前記候補コードを検出し、
前記解析情報生成部は、前記第1検出部による検出結果に基づき、前記プログラムコードのうち前記候補コードを含む領域を特定する再生成情報を生成し、
前記第1検出部は、前記プログラム制御情報中の前記検出対象コードを特定する情報が変更された場合、前記再生成情報によって特定される領域から、変更された検出対象コードを検出することを特徴とする請求項1に記載のコード検出装置。
A control information storage unit for storing program control information including information for specifying the detection target code and information for specifying a candidate code that is a code of a change destination candidate of the detection target code;
The first detection unit detects the detection target code and the candidate code from the program code based on the program control information,
The analysis information generation unit generates regeneration information for specifying a region including the candidate code in the program code based on the detection result by the first detection unit,
The first detection unit detects the changed detection target code from an area specified by the regeneration information when information for specifying the detection target code in the program control information is changed. The code detection device according to claim 1.
前記検出対象コードは、前記プログラムコード中の特定のコードを呼出す制御移動命令であり、
前記第1検出部及び前記第2検出部は、
前記プログラムコードから制御移動命令を検出した場合、検出された制御移動命令の呼出先コードが前記特定のコードであるか否かを判定し、
前記検出された制御移動命令の呼出先コードが前記特定のコードである場合、前記検出された制御移動命令が前記検出対象コードであると判定することを特徴とする請求項1に記載のコード検出装置。
The detection target code is a control movement instruction for calling a specific code in the program code,
The first detector and the second detector are
When a control movement command is detected from the program code, it is determined whether a call destination code of the detected control movement command is the specific code,
2. The code detection according to claim 1, wherein when the call destination code of the detected control movement instruction is the specific code, it is determined that the detected control movement instruction is the detection target code. apparatus.
前記第2解析部は、前記解析対象領域から検出された前記検出対象コードに前記フックコードを追加すると共に、前記解析対象領域をコンパイル処理し、コンパイル処理後の前記解析対象領域である解析済みコードを記憶するキャッシュ記憶部をさらに備え、
前記第2検出部は、前記解析対象領域から前記検出対象コードが検出された場合であって、前記検出対象コードを含む前記解析対象領域に対応する解析済みコード前記キャッシュ記憶部に記憶されている場合、前記コンパイル処理を省略し、前記解析済みコードを出力することを特徴とする請求項1に記載のコード検出装置。
The second analysis unit adds the hook code to the detection target code detected from the analysis target area, compiles the analysis target area, and the analyzed code that is the analysis target area after the compile processing A cache storage unit for storing
The second detector is a case where the detection target code from said analysis target area is detected, the analyzed code corresponding to the analysis target area including the detected code is stored in the cache storage unit The code detection apparatus according to claim 1 , wherein the compiling process is omitted and the analyzed code is output .
前記非解析対象領域を特定する情報は、前記非解析対象領域の開始アドレスを含むことを特徴とする請求項に記載のコード検出装置。 The code detection device according to claim 9 , wherein the information for specifying the non-analysis target area includes a start address of the non-analysis target area. 前記第1解析部は、前記プログラムコードを2つの分岐命令で挟まれた領域毎に分割し、分割された領域毎に前記検出対象コードの検出処理を行うことで前記非解析対象領域を検出することを特徴とする請求項に記載のコード検出装置。 The first analysis unit divides the program code into regions sandwiched between two branch instructions, and detects the non-analysis target region by performing detection processing of the detection target code for each of the divided regions. The code detection device according to claim 1 . 前記第1解析部は、前記非解析対象領域を特定する情報を含む前記解析情報を記憶する解析情報記憶部をさらに備え、
前記第2解析部は、前記非解析対象領域を特定する情報と、前記非解析対象領域が実行された回数とを対応付けた履歴情報を記憶する履歴情報記憶部をさらに備え、
前記解析情報生成部は、前記履歴情報記憶部に記憶されている前記履歴情報に基づき、前記解析情報記憶部に登録されているとともに、前記特定部によってアクセスされる頻度の高い登録領域が、より短い時間で検索されるように前記解析情報記憶部のデータ構造を変更することによって、前記解析情報記憶部に記憶されている前記解析情報を更新することを特徴とする請求項に記載のコード検出装置。
The first analysis unit further includes an analysis information storage unit that stores the analysis information including information specifying the non-analysis target region,
The second analysis unit further includes a history information storage unit that stores history information in which the information for specifying the non-analysis target region is associated with the number of times the non-analysis target region is executed,
The analysis information generation unit is registered in the analysis information storage unit based on the history information stored in the history information storage unit, and more frequently registered areas accessed by the specifying unit by changing the data structure of the analysis information storage unit as retrieved in a short time, cord according to claim 1, characterized in that updating the analysis information stored in the analysis information storage unit Detection device.
前記履歴情報記憶部に記憶される前記非解析対象領域を特定する情報は、少なくとも前記非解析対象領域の開始アドレスを含むことを特徴とする請求項12に記載のコード検出装置。 The code detection device according to claim 12 , wherein the information specifying the non-analysis target area stored in the history information storage unit includes at least a start address of the non-analysis target area. 前記特定部は、前記解析情報記憶部中の上位から下位へ前記非解析対象領域を特定する情報を参照することで、前記次に実行されるプログラムコードの領域が前記非解析対象領域であるか否かを特定し、
前記解析情報生成部は、
前記履歴情報において一定回数以上に対応する前記非解析対象領域を特定する情報を、前記解析情報記憶部中の上位に設定し、
前記履歴情報において一定回数未満に対応する前記非解析対象領域を特定する情報を、前記解析情報記憶部中の下位に設定することを特徴とする請求項12に記載のコード検出装置。
Whether the area of the program code to be executed next is the non-analysis target area by referring to information for specifying the non-analysis target area from higher to lower in the analysis information storage unit. Whether or not
The analysis information generation unit
Information specifying the non-analysis target area corresponding to a certain number of times or more in the history information is set in the upper order in the analysis information storage unit,
The code detection device according to claim 12 , wherein information specifying the non-analysis target region corresponding to less than a certain number of times in the history information is set in a lower order in the analysis information storage unit.
前記検出対象コードは、分岐命令であり、
前記第2解析部は、コンパイル処理後の前記解析対象領域である解析済みコードに所定の分岐命令が含まれる場合に、前記所定の分岐命令を特定する情報、及び前記所定の分岐命令の分岐先を分岐先情報として記憶する分岐先情報記憶部をさらに備え、
前記第1検出部は、前記分岐先情報記憶部に記憶される前記分岐先情報を参照し、前記分岐先情報を用いて前記検出対象コードを検出することを特徴とする請求項1に記載のコード検出装置。
The detection target code is a branch instruction;
The second analysis unit, when a predetermined branch instruction is included in the analyzed code that is the analysis target area after the compile processing , and information for specifying the predetermined branch instruction, and a branch destination of the predetermined branch instruction Is further provided with a branch destination information storage unit for storing as branch destination information,
The said 1st detection part detects the said detection object code using the said branch destination information with reference to the said branch destination information memorize | stored in the said branch destination information storage part. Code detection device.
前記所定の分岐命令は、他の命令の実行結果に応じて分岐先が定まる間接分岐命令であり、
前記分岐先情報記憶部は、前記解析済みコードが実行される際に前記分岐先情報を記憶することを特徴とする請求項15に記載のコード検出装置。
The predetermined branch instruction is an indirect branch instruction in which a branch destination is determined according to an execution result of another instruction,
The code detection device according to claim 15 , wherein the branch destination information storage unit stores the branch destination information when the analyzed code is executed.
複数のコードを含むプログラムコードを解析することで検出対象コードを検出するコード検出方法であって、
前記プログラムコードの実行前に、前記プログラムコードを解析する第1ステップと、
前記プログラムコードの実行中に、前記第1解析ステップによる解析結果を用いて前記プログラムコードを解析する第2ステップとを備え、
前記第1ステップは、
前記プログラムコードから前記検出対象コードを検出する第1検出ステップと、
前記第1検出ステップによる検出結果に基づき、前記プログラムコードのうち前記第2ステップが解析対象としない領域である解析対象領域を特定するための解析情報を生成する解析情報生成ステップとを備え、
前記第2ステップは、
前記解析情報を参照し、前記解析情報が示す非解析対象領域を除いた領域を前記プログラムコード中の前記解析対象領域として特定する特定ステップと、
前記特定ステップによって特定された前記解析対象領域から前記検出対象コードを検出する第2検出ステップとを備え
前記第1ステップが生成する前記解析情報は、前記プログラムコードのうち前記検出対象コードを含まない領域を非解析対象領域として特定する情報を含み、
前記第2ステップは、前記プログラムコードの実行中に与えられる次に実行されるべきプログラムコードのアドレスに基づいて、前記プログラムコードのうち解析すべきプログラムコードを特定し、前記解析情報を元に当該プログラムコードが解析対象領域であるか否かを判定することを特徴とするコード検出方法。
A code detection method for detecting a detection target code by analyzing a program code including a plurality of codes,
A first step of analyzing the program code before executing the program code ;
A second step of analyzing the program code using the analysis result of the first analysis step during the execution of the program code ,
The first step includes
A first detection step of detecting the detection target code from the program code;
The first based on the detection result by the detecting step, and an analysis information generating step in which the second step is to generate the analysis information for identifying the non-analysis target area is an area which is not analyzed among the program code,
The second step includes
A specifying step of the reference to the analysis information, identifies a region excluding the non-analysis target area in which the analysis information indicates as the analysis target area in the program code,
A second detection step of detecting the detection target code from the analysis target region specified by the specification step ,
The analysis information generated by the first step includes information for specifying a region that does not include the detection target code in the program code as a non-analysis target region,
The second step identifies a program code to be analyzed among the program codes based on an address of a program code to be executed next given during execution of the program code, and based on the analysis information, A code detection method for determining whether or not a program code is an analysis target area .
JP2007107482A 2007-02-09 2007-04-16 Code detection apparatus and code detection method Expired - Fee Related JP4945296B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2007107482A JP4945296B2 (en) 2007-02-09 2007-04-16 Code detection apparatus and code detection method

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
JP2007031190 2007-02-09
JP2007031190 2007-02-09
JP2007107482A JP4945296B2 (en) 2007-02-09 2007-04-16 Code detection apparatus and code detection method

Publications (2)

Publication Number Publication Date
JP2008217751A JP2008217751A (en) 2008-09-18
JP4945296B2 true JP4945296B2 (en) 2012-06-06

Family

ID=39837673

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2007107482A Expired - Fee Related JP4945296B2 (en) 2007-02-09 2007-04-16 Code detection apparatus and code detection method

Country Status (1)

Country Link
JP (1) JP4945296B2 (en)

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH01216441A (en) * 1988-02-24 1989-08-30 Hitachi Ltd Method for analyzing program traveling
JPH04287134A (en) * 1991-03-15 1992-10-12 Nec Corp Simplified trace information acquisition system
JP3199013B2 (en) * 1998-01-26 2001-08-13 日本電気株式会社 Language processing method, language processing apparatus, and storage medium storing language processing program
JP2007004516A (en) * 2005-06-24 2007-01-11 Hitachi Software Eng Co Ltd Program debugging method of built-in system

Also Published As

Publication number Publication date
JP2008217751A (en) 2008-09-18

Similar Documents

Publication Publication Date Title
Xu et al. Designing new operating primitives to improve fuzzing performance
US10698668B1 (en) Custom code transformations during compilation process
JP3220055B2 (en) An optimizing device for optimizing a machine language instruction sequence or an assembly language instruction sequence, and a compiler device for converting a source program described in a high-level language into a machine language or an assembly language instruction sequence.
US8250559B2 (en) Supporting per-program classpaths with class sharing in a multi-tasking virtual machine
US8615735B2 (en) System and method for blurring instructions and data via binary obfuscation
WO2010010678A1 (en) Program optimization method
CN102279765A (en) Pre-compiling hosted managed code
US5960197A (en) Compiler dispatch function for object-oriented C
US7793266B2 (en) Method, apparatus and computer program product for optimizing access to the content of a virtual application container on a fixed, read-only medium
CN102099781A (en) Branch predicting device, branch predicting method thereof, compiler, compiling method thereof, and medium for storing branch predicting program
JP5966509B2 (en) Program, code generation method, and information processing apparatus
JP2015511041A (en) Nest structured emulation and dynamic linking environment
KR970066865A (en) Optimizer for eliminating transmission commands by analyzing bandlike equivalence relationship
US20100095102A1 (en) Indirect branch processing program and indirect branch processing method
US8296742B2 (en) Automatic native generation
JP2004303114A (en) Interpreter and native code execution method
CN113176926B (en) API dynamic monitoring method and system based on virtual machine introspection technology
KR20070087400A (en) Method and system for test coverage analysis of operating system software
KR102209151B1 (en) Method and device for patching security vulnerable executable binaries
JP4945296B2 (en) Code detection apparatus and code detection method
US20180173728A1 (en) Information processing apparatus and method
US8091079B2 (en) Implementing shadow versioning to improve data dependence analysis for instruction scheduling
JP2022150518A (en) Test processing program, test processing method, and information processing apparatus
Dong et al. Cadecff: Compiler-agnostic deobfuscator of control flow flattening
JP2004171064A (en) Buffer overflow static analysys method and program

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20100225

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20110516

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20110607

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20110808

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20120221

A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20120305

R150 Certificate of patent or registration of utility model

Ref document number: 4945296

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

Free format text: JAPANESE INTERMEDIATE CODE: R150

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20150309

Year of fee payment: 3

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

LAPS Cancellation because of no payment of annual fees