JP5387089B2 - Program and program execution device - Google Patents

Program and program execution device Download PDF

Info

Publication number
JP5387089B2
JP5387089B2 JP2009078062A JP2009078062A JP5387089B2 JP 5387089 B2 JP5387089 B2 JP 5387089B2 JP 2009078062 A JP2009078062 A JP 2009078062A JP 2009078062 A JP2009078062 A JP 2009078062A JP 5387089 B2 JP5387089 B2 JP 5387089B2
Authority
JP
Japan
Prior art keywords
program code
code
address
external
external reference
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
JP2009078062A
Other languages
Japanese (ja)
Other versions
JP2010231477A (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.)
Fujifilm Business Innovation Corp
Original Assignee
Fuji Xerox Co Ltd
Fujifilm Business Innovation Corp
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 Fuji Xerox Co Ltd, Fujifilm Business Innovation Corp filed Critical Fuji Xerox Co Ltd
Priority to JP2009078062A priority Critical patent/JP5387089B2/en
Publication of JP2010231477A publication Critical patent/JP2010231477A/en
Application granted granted Critical
Publication of JP5387089B2 publication Critical patent/JP5387089B2/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Devices For Executing Special Programs (AREA)

Description

本発明は、プログラム及びプログラム実行装置に関する。   The present invention relates to a program and a program execution device.

コードの配布方法は、完成されたプログラムの形式だけでない。開発者に対しては、自ら生成したプログラムから配布されたコードを呼び出せるように、ライブラリという形式で渡される方法は、広く用いられている。このライブラリに含まれるコードの形態は、C言語を始めとする一般的なコンパイラ言語においては、オブジェクトコードと呼ばれるコンパイル後でリンク前の中間状態のコードとなっている。   The method of distributing the code is not only in the form of the completed program. For developers, a method of passing in the form of a library is widely used so that a code distributed from a program generated by itself can be called. The form of code included in this library is an intermediate state code after compiling and before linking called object code in a general compiler language such as C language.

またコード内に含まれる秘密を秘匿するためにコードの一部を暗号化しておきたいという要求が存在するが、このオブジェクトコードに対しても、暗号化により、コード内の情報を秘匿したいという要求は存在する。   In addition, there is a request to encrypt a part of the code in order to conceal the secret contained in the code, but also for this object code, a request to conceal the information in the code by encryption Exists.

リンク時に各オブジェクトが割り当てられるアドレスが決定する(アドレス解決)ため、このオブジェクトコードに対して符号化を行おうとした場合には、符号化されたコードに対して、リンク時のアドレス解決の結果としてコードの書き換えが発生し、アドレス解決の結果が正しく実施できない。加えて、符号化されたコードが変更された結果として、復号が正しく行えなくなるという問題を持つ。   Since the address to which each object is assigned at the time of linking is determined (address resolution), when encoding is performed for this object code, the result of address resolution at the time of linking for the encoded code Code rewriting occurs and address resolution results cannot be implemented correctly. In addition, there is a problem that decoding cannot be performed correctly as a result of changing the encoded code.

アドレス解決が不要になる様にコードを作成すると、前記問題は発生しないが、外部のデータやコードを利用する機能を記述できないため、実現できる機能が強く限定されてしまい、実用的な機能は提供できない。   If the code is created so that address resolution is unnecessary, the above problem does not occur, but the function that uses external data and code cannot be described, so the functions that can be realized are strongly limited, and practical functions are provided Can not.

また、実行形式のコードでは、位置独立コード(PIC)と呼ばれるアドレス解決によるコードの書き換えが発生しない方式が用いられているが、この方式はリンク後の実行形式のコードに対する技術であり、オブジェクトコードの段階でこの様なコードを生成する機構は存在しない。   Executable code uses a method called position-independent code (PIC) that does not cause code rewriting by address resolution. This method is a technology for executable code after linking, and is based on object code. There is no mechanism to generate such code at this stage.

特許文献1(特に図1)及び2には、オブジェクトファイルを暗号化して配布し、他のコードとのリンク時に復号して、リンクし、その後再び暗号化を行う方法により、オブジェクトファイル内のコードをディスアセンブルされるのを防ぐ方法が開示されている。当該技術によって作成されたオブジェクトファイルは、リンク作業時に、リンクする直前に、復号部が暗号化されたオブジェクトコードを復号し、リンク後に、復号したコードを再び暗号化するという手順で動作する。   Patent Documents 1 (particularly FIG. 1) and 2 disclose that an object file is encrypted and distributed, decrypted at the time of linking with another code, linked, and then encrypted again to recode the object file. A method for preventing disassembly is disclosed. The object file created by this technique operates in the procedure of decrypting the encrypted object code immediately before linking at the time of linking, and re-encrypting the decrypted code after linking.

また、特許文献3(特に図2)には、実行形式のプログラム、ダイナミックリンクライブラリのコードにおいて、実行中に符号化されたコードを実行する前に、対象コードを復号し、その復号後かつ対象コードを実行する前に、対象コード内のアドレス変更が必要なコードの書き換えを行う方法により、コード内の一部のコードを符号化しておく技術を開示している。   Further, Patent Document 3 (particularly FIG. 2) discloses that an execution format program and a dynamic link library code decode the target code before executing the code encoded during execution, Prior to executing the code, a technique is disclosed in which a part of the code in the code is encoded by a method of rewriting the code that requires an address change in the target code.

特開平4−268924号公報JP-A-4-268924 特開平4−310128号公報JP-A-4-310128 特許第3033562号明細書Japanese Patent No. 3033352

本発明は、通常のリンカでリンクを行っても、外部オブジェクトを参照する原プログラムコードを符号化した符号化プログラムコードを正しく復号できるようにすることを目的とする。   An object of the present invention is to make it possible to correctly decode an encoded program code obtained by encoding an original program code that refers to an external object even when linking is performed using a normal linker.

請求項1に係る発明は、原プログラムコードの符号化結果である符号化プログラムコードと、前記符号化プログラムコードを復号して前記原プログラムコードを復元する処理を前記コンピュータに実行させるための復号プログラムコードと、前記原プログラムコード中で参照される外部オブジェクトのアドレスを表す外部参照情報と、外部プログラムからの呼び出しに応じて、前記復号プログラムコードにより復元された前記原プログラムコードを、前記外部参照情報のアドレスを引数として渡して呼び出す処理を、前記コンピュータに実行させるための呼び出しプログラムコードと、を備え、前記原プログラムコードは、前記外部オブジェクトへの参照を、引数として渡される前記外部参照情報のアドレスを用いて記述したものであり、前記呼び出しプログラムコードから引数として渡された前記外部参照情報のアドレスにアクセスして前記外部オブジェクトのアドレスを取得し、取得したアドレスを用いて前記外部オブジェクトを参照する処理を前記コンピュータに実行させる、ことを特徴とするオブジェクトファイル形式のプログラムである。 The invention according to claim 1 is an encoded program code that is an encoding result of an original program code, and a decoding program for causing the computer to execute a process of decoding the encoded program code and restoring the original program code Code, external reference information indicating the address of an external object referred to in the original program code, and the original program code restored by the decrypted program code in response to a call from the external program. A calling program code for causing the computer to execute a process of calling by passing the address of the external object as an argument , wherein the original program code is an address of the external reference information passed as an argument to the external object It is described using By accessing the address of the external reference information passed as arguments from the calling program code acquires an address of the external object, to execute a process of referring to the external object using the address obtained in the computer, that This is an object file format program.

請求項2に係る発明は、請求項1に係る発明において、前記原プログラムコード中で参照される外部オブジェクトのアドレスを取得し、前記外部参照情報として、取得したアドレスを含んだ情報を生成するための処理を前記コンピュータに実行させるための外部参照情報作成プログラムコード、を更に備えることを特徴とする。   The invention according to claim 2 is the invention according to claim 1, wherein the address of the external object referred to in the original program code is acquired, and information including the acquired address is generated as the external reference information. The computer program further includes external reference information creation program code for causing the computer to execute the above process.

請求項3に係る発明は、請求項1に係る発明において、前記プログラムは、読み出し、書き込み、及び実行が可能なメモリ領域を前記コンピュータのメモリ上に確保する処理を前記コンピュータに実行させるためのプログラムコード、を更に含み、前記復号プログラムコードは、復号の結果である前記原プログラムコードを前記確保されたメモリ領域に書き込むための処理を前記コンピュータに実行させる、ことを特徴とする。   According to a third aspect of the present invention, in the first aspect of the invention, the program causes the computer to execute a process of ensuring a memory area that can be read, written, and executed on the memory of the computer. The decryption program code further causes the computer to execute a process for writing the original program code as a result of decryption into the reserved memory area.

請求項4に係る発明は、請求項1に係る発明において、前記コンピュータを、前記復号プログラムコードが既実行か未実行かを表すフラグを記憶するフラグ記憶手段、前記呼び出しプログラムコードが呼び出された場合に、前記フラグ記憶手段に記憶された前記フラグが未実行を表す場合には前記復号プログラムコードを実行して前記フラグを既実行に変更し、前記フラグが既実行を表す場合には前記復号プログラムコードを実行しないように制御する制御手段、として更に機能させることを特徴とする。   The invention according to claim 4 is the invention according to claim 1, wherein the computer stores flag storage means for storing a flag indicating whether the decoding program code is already executed or not executed, and the calling program code is called In addition, when the flag stored in the flag storage means represents unexecuted, the decoding program code is executed to change the flag to already executed, and when the flag represents already executed, the decoding program It is further characterized by functioning as a control means for controlling not to execute the code.

請求項5に係る発明は、原プログラムコードの符号化結果である符号化プログラムコードを復号して前記原プログラムコードを復元する復号手段と、前記原プログラムコード中で参照される外部オブジェクトのアドレスを表す外部参照情報を記憶する外部参照情報記憶手段と、外部プログラムからの呼び出しに応じて、前記復号手段により復元された前記原プログラムコードを、前記外部参照情報のアドレスを引数として渡して呼び出す呼び出し手段と、前記呼び出し手段により呼び出された前記原プログラムコードを実行する実行手段と、を備え、前記原プログラムコードは、前記外部オブジェクトへの参照を、引数として渡される前記外部参照情報のアドレスを用いて記述したものであり、前記呼び出し手段から引数として渡された前記外部オブジェクトを参照する場合に、前記外部参照情報のアドレスにアクセスして前記外部オブジェクトのアドレスを取得し、取得したアドレスを用いて前記外部オブジェクトを参照する処理を前記実行手段に実行させる、ことを特徴とするプログラム実行装置である。 According to a fifth aspect of the present invention, there is provided decoding means for decoding an encoded program code that is an encoding result of an original program code to restore the original program code, and an address of an external object referred to in the original program code. External reference information storage means for storing external reference information to be represented, and calling means for calling the original program code restored by the decoding means by passing the address of the external reference information as an argument in response to a call from an external program And executing means for executing the original program code called by the calling means, wherein the original program code uses a reference to the external object as an argument and the address of the external reference information passed as an argument. are those described, the passed as arguments from the calling unit When referring to a part object, the address of the external reference information is accessed to acquire the address of the external object, and the execution unit is caused to execute a process of referring to the external object using the acquired address. It is a program execution device characterized.

請求項1又は5に係る発明によれば、通常のリンカでリンクを行っても、外部オブジェクトを参照する原プログラムコードを符号化した符号化プログラムコードを正しく復号できる。   According to the first or fifth aspect of the invention, the encoded program code obtained by encoding the original program code that refers to the external object can be correctly decoded even if linking is performed using a normal linker.

請求項2に係る発明によれば、外部オブジェクトのアドレスが実行時に動的に決定される場合でも、符号化プログラムコードの復号結果である原プログラムコードからその外部オブジェクトにアクセスすることができる。   According to the second aspect of the present invention, even when the address of the external object is dynamically determined at the time of execution, the external object can be accessed from the original program code that is the decoding result of the encoded program code.

請求項3に係る発明によれば、符号化プログラムコードの復号結果の原プログラムコードを、コンピュータが実行できるようにすることができる。   According to the third aspect of the present invention, the original program code as the decoding result of the encoded program code can be executed by the computer.

請求項4に係る発明によれば、外部プログラムが復号コードと呼び出しコードをそれぞれ個別に呼び出す必要をなくすことができる。   According to the fourth aspect of the invention, it is possible to eliminate the need for the external program to call the decryption code and the call code individually.

実施の形態のオブジェクトファイルのデータ構造の例を示す図である。It is a figure which shows the example of the data structure of the object file of embodiment. 外部参照テーブルのデータ構造の例を示す図である。It is a figure which shows the example of the data structure of an external reference table. 実施の形態のオブジェクトファイルの生成及び利用の流れを説明するための図である。It is a figure for demonstrating the flow of the production | generation and utilization of the object file of embodiment. コンパイルによる外部参照テーブルの内容変遷の例を示す図である。It is a figure which shows the example of the content transition of the external reference table by compilation. リンク及びロード・実行による外部参照テーブルの内容変遷の例を示す図である。It is a figure which shows the example of the content transition of the external reference table by a link and load and execution. コンピュータのハードウエア構成の一例を示す図である。It is a figure which shows an example of the hardware constitutions of a computer. リンク後の実行可能プログラムが実行される際の処理の流れの一例を示す図である。It is a figure which shows an example of the flow of a process when the executable program after a link is performed. オブジェクトファイルの実行によりコンピュータが実現するプログラム実行装置の機能的構成の例を示すブロック図である。It is a block diagram which shows the example of a functional structure of the program execution apparatus which a computer implement | achieves by execution of an object file.

以下、図面を参照して本発明の実施の形態を説明する。まず、図1を参照して、実施の形態のオブジェクトファイル100のデータ構造の一例を説明する。このオブジェクトファイル100は、例えばライブラリ関数又はライブラリファイルとして用いられる。   Embodiments of the present invention will be described below with reference to the drawings. First, an example of the data structure of the object file 100 according to the embodiment will be described with reference to FIG. The object file 100 is used as a library function or a library file, for example.

図1に例示するように、オブジェクトファイル100は、オブジェクトヘッダ110、コードセクション120、独自セクション130及びデータセクション140を含んでいる。これら各セクションは、CPU(中央演算ユニット)等のマイクロプロセッサが実行できる機械語で記述されている。   As illustrated in FIG. 1, the object file 100 includes an object header 110, a code section 120, a unique section 130 and a data section 140. Each of these sections is described in a machine language that can be executed by a microprocessor such as a CPU (Central Processing Unit).

オブジェクトヘッダ110は、当該ファイル100のヘッダ情報を記述したセクションである。また、コードセクション120はプログラムコードが含まれるセクションであり、データセクション140はプログラムコードの実行において用いられるデータが含まれるセクションである。これらオブジェクトヘッダ110、コードセクション120及びデータセクション140は、一般的なオブジェクトファイル形式にも存在する。   The object header 110 is a section describing header information of the file 100. The code section 120 is a section including program code, and the data section 140 is a section including data used in executing the program code. These object header 110, code section 120, and data section 140 also exist in a general object file format.

これに対し、独自セクション130は、この実施の形態のオブジェクトファイル独自のものである。独自セクション130は、読み出し、書き込み及び実行が可能なセクションである。独自セクション130には、符号化(例えば暗号化)対象のプログラムコード(原プログラムコードと呼ぶ)の符号化結果である符号化プログラムコード132が置かれる。ここで、原プログラムコードは、このオブジェクトファイル100が他のプログラムに対して提供する機能を記述したプログラムコードである。   On the other hand, the unique section 130 is unique to the object file of this embodiment. The unique section 130 is a section that can be read, written and executed. In the unique section 130, an encoded program code 132 that is an encoding result of a program code (referred to as an original program code) to be encoded (for example, encrypted) is placed. Here, the original program code is a program code describing a function that the object file 100 provides to other programs.

なお、独自セクション130に符号化プログラムコード132が置かれるのは、オブジェクトファイル100が符号化による保護を受けた後の段階(例えば配布時)でのことであり、符号化の前の段階では独自セクション130には原プログラムコードが置かれる。   The encoding program code 132 is placed in the unique section 130 at a stage after the object file 100 is protected by encoding (for example, at the time of distribution). Section 130 contains the original program code.

一般的なオブジェクトファイルでは原プログラムコードはコードセクション120に置かれるのに対し、この実施の形態では、以上のように、原プログラムコードを符号化した符号化プログラムコード132はコードセクション120ではなく独自セクション130に置かれる。   In a general object file, the original program code is placed in the code section 120. In this embodiment, the encoded program code 132 obtained by encoding the original program code is not the code section 120 but unique as described above. Placed in section 130.

一方、この実施の形態のコードセクション120には、独自セクション130に置かれた符号化プログラムコード132を実行するためのプログラムコードが置かれる。すなわち、この例では、コードセクション120には初期化関数122と呼び出しコード128とが置かれる。   On the other hand, in the code section 120 of this embodiment, program code for executing the encoded program code 132 placed in the unique section 130 is placed. That is, in this example, an initialization function 122 and a call code 128 are placed in the code section 120.

初期化関数122は、ライブラリ(オブジェクトファイル100)の初期化処理を表すプログラムである。初期化処理には、符号化プログラムコード132の復号処理と、外部参照テーブル142の作成処理とが含まれる。前者をマイクロプロセッサに実行させるためのプログラムコードが復号コード124であり、後者を実行させるためのプログラムコードが外部参照テーブル作成コード126である。初期化関数122は、例えば、このライブラリを利用するリンク元コード(すなわち外部プログラム)から呼び出される。   The initialization function 122 is a program representing initialization processing of the library (object file 100). The initialization process includes a decoding process for the encoded program code 132 and a process for creating the external reference table 142. The program code for causing the microprocessor to execute the former is the decryption code 124, and the program code for executing the latter is the external reference table creation code 126. The initialization function 122 is called from, for example, a link source code (that is, an external program) that uses this library.

ここで、外部参照テーブル142は、符号化プログラムコード132の復号結果である原プログラムコードが参照する外部オブジェクトのアドレス情報を保持するためのテーブルである。ここで、外部オブジェクトは、例えば、セクション外の関数呼び出しや、スタック外に置かれる静的データなどである。なお、ここで言うセクションは、復号結果の原プログラムコードがロードされた独自セクションのことであり、スタックは、オブジェクトファイル100がメモリにロードされた場合にデータセクションに作成されるスタック領域のことである。   Here, the external reference table 142 is a table for holding the address information of the external object referred to by the original program code that is the decoding result of the encoded program code 132. Here, the external object is, for example, a function call outside a section or static data placed outside the stack. The section mentioned here is a unique section loaded with the original program code of the decoding result, and the stack is a stack area created in the data section when the object file 100 is loaded into the memory. is there.

外部参照テーブル142は、実行時には、図2に概念的に示すように、各外部オブジェクトの実行時のアドレスの配列となる。図では、便宜上、各外部オブジェクトを名前で特定し、その名前に対応づけてアドレスの値を示しているが、実際には、図5に示したメインメモリ上の外部参照テーブルのイメージ例50のように、メインメモリ上での外部参照テーブル142のアドレス範囲内の各アドレス(これらがそれぞれ外部オブジェクトに対応する)に、当該外部オブジェクトの実行時アドレスの値を記憶したものとなる(詳細は後述)。なお、以上に説明した外部参照テーブル142の状態は、当該オブジェクトファイル100が外部プログラムとリンクされ、実行される状態となったときのものである。このような外部参照テーブル142がどのように作成されるかについては、後で図4及び図5を参照して詳しく説明する。   The external reference table 142 is an array of addresses at the time of execution of each external object, as conceptually shown in FIG. In the figure, for convenience, each external object is specified by name, and the address value is shown in association with the name. However, actually, the external reference table image example 50 on the main memory shown in FIG. As described above, each address within the address range of the external reference table 142 on the main memory (which corresponds to the external object) stores the runtime address value of the external object (details will be described later). ). Note that the state of the external reference table 142 described above is the state when the object file 100 is linked to an external program and executed. How such an external reference table 142 is created will be described in detail later with reference to FIGS.

外部参照テーブル作成コード126は、外部参照テーブル142の中で、実行時に動的に作成される部分を作成するための処理を記述したプログラムコードである。外部参照テーブル142のうち、静的な部分のデータは、あらかじめプログラマにより記述されている。すなわち、プログラマが記述した静的な部分の記述がコンパイルにより機械語に変換されるとともに、後のリンク時にリンカがデータセクション140の外部参照テーブル142を構成できるように、再配置情報(例えばリロケーションテーブル)が生成される。オブジェクトファイル100が使用されて、外部プログラムの中にリンクされることにより生成された実行可能ファイルがファイルシステムに保存されている段階では、オブジェクトファイル100のデータセクション140内の外部参照テーブル142には、静的な外部参照情報、すなわちアドレスが静的に定まっている外部オブジェクトについてのアドレス情報のみが含まれている。そして、実行時にならないとアドレスが決まらない外部オブジェクトのアドレス情報は、初期化関数122による初期化処理時に、外部参照テーブル作成コード126の実行により作成される。   The external reference table creation code 126 is a program code describing a process for creating a part that is dynamically created at the time of execution in the external reference table 142. In the external reference table 142, data of a static part is described in advance by a programmer. That is, the relocation information (for example, the relocation table is set so that the description of the static part written by the programmer is converted into machine language by compilation and the linker can construct the external reference table 142 of the data section 140 at the time of subsequent linking. ) Is generated. At the stage where the executable file generated by using the object file 100 and being linked into the external program is stored in the file system, the external reference table 142 in the data section 140 of the object file 100 is stored in the external reference table 142. , Only static external reference information, that is, address information about an external object whose address is statically determined is included. The address information of the external object whose address is not determined unless it is executed is created by executing the external reference table creation code 126 during the initialization process by the initialization function 122.

復号コード124は、符号化されたコードをマイクロプロセッサが実行可能なコードに復号する処理を記述したプログラムコードである。   The decoding code 124 is a program code describing a process of decoding the encoded code into a code that can be executed by the microprocessor.

呼び出しコード128は、符号化プログラムコード132を復号して得られた原プログラムコードを呼び出す機能を記述したプログラムコードである。呼び出しコード128は、復号コード124が符号化プログラムコード132を復号した後かつ、外部参照テーブル作成コード126が外部参照テーブル142を完成させた後に、外部参照テーブル142のアドレス(例えば先頭アドレス)を、スタックないしレジスタを介して、原プログラムコードに渡し、その原プログラムコードを呼び出す機能を記述している。   The call code 128 is a program code describing a function for calling an original program code obtained by decoding the encoded program code 132. After the decoding code 124 decodes the encoded program code 132 and the external reference table creation code 126 completes the external reference table 142, the call code 128 is the address of the external reference table 142 (for example, the top address). It describes the function of passing to the original program code via the stack or register and calling the original program code.

復号結果の原プログラムコードは、呼び出しコード128からの呼び出しに応じて、渡された外部参照テーブル142を用いて外部オブジェクトを利用しながら、外部のプログラム(例えば、後述するリンク元プログラム)に提供する所定の処理を行う機能を持つ。すなわち、原プログラムコードでは、外部オブジェクトの呼び出しの記述は、当該オブジェクトの名前で直接指し示す代わりに、外部参照テーブル142における当該オブジェクトのエントリを指し示す形で記述される。   The original program code of the decoding result is provided to an external program (for example, a link source program described later) while using an external object using the passed external reference table 142 in response to a call from the call code 128. It has a function to perform predetermined processing. That is, in the original program code, the description of the call of the external object is described in the form of pointing to the entry of the object in the external reference table 142 instead of pointing directly to the name of the object.

以下に、オブジェクトファイル100の元になるライブラリのソースコードの具体例を示す。なお、これは外部オブジェクト参照についての本実施の形態の特徴を示す目的の例であり、原プログラムコードの処理内容については特段の意味はない。   A specific example of the source code of the library that is the basis of the object file 100 is shown below. This is an example for the purpose of showing the feature of the present embodiment regarding the external object reference, and the processing content of the original program code has no particular meaning.

// Microsoft社のVisual Studio(登録商標)によりコンパイルされる例
#include <windows.h>
// 独自セクションの作成
#pragma section(".mysect", write, execute )

bool g_isInitialized = false;
char BaseData[1024];

// 外部参照テーブル
struct ExternalObjectReferenceTable {
HANDLE hHeap;
char* pData;
DWORD (WINAPI * pGetLastError)(VOID);
LPVOID (WINAPI * pHeapAlloc)(HANDLE, DWORD, SIZE_T);
BOOL (WINAPI * pHeapFree)(HANDLE, DWORD, LPVOID);
} g_table = { NULL, BaseData, NULL, NULL, NULL };
// 静的に外部参照テーブルを作成する場合には、ここで行う

extern bool DoDecrypt(unsigned char*, BYTE*, BYTE*);

// 初期化関数
int initialize(void)
{
if (g_isInitialized) return 0;
// 復号コード
static unsigned char key[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
BYTE* pFuncTop = reinterpret_cast<BYTE*>(topFunc);
BYTE* pFuncTail= reinterpret_cast<BYTE*>(tailFunc);
if (DoDecrypt(key, pFuncTop, pFuncTail)) return -6;

// 外部参照テーブル作成コード
g_table.hHeap = GetProcessHeap();
if (g_table.hHeap == NULL) return -1;

HINSTANCE hKERNEL32 = LoadLibrary("kernel32.dll");
if (hKERNEL32 == NULL) return -2;
// kernel32.dll
g_table.pGetLastError = (DWORD (WINAPI * )(VOID))
GetProcAddress(hKERNEL32, "GetLastError");
if (g_table.pGetLastError == NULL) return -3;
g_table.pHeapAlloc = (LPVOID (WINAPI *)(HANDLE, DWORD, SIZE_T))
GetProcAddress(hKERNEL32, "HeapAlloc");
if (g_table.pHeapAlloc == NULL) return -4;
g_table.pHeapFree = (BOOL (WINAPI *)(HANDLE, DWORD, LPVOID))
GetProcAddress(hKERNEL32, "HeapFree");
if (g_table.pHeapFree == NULL) return -5;
g_isInitialized = true;
return 0;
}

// 呼び出しコード
int callTopFunc ( unsigned char* x, unsigned int y) {
if (false == g_isInitialized) return -1;
return topFunc(x, y, &g_table);
}

#pragma code_seg(".mysect")
// 原プログラムコード開始
int topFunc(unsigned char* x, unsigned int y,
// 引数(スタックまたはレジスタ経由)で外部参照テーブルのアドレスを渡す例
struct ExternalObjectReferenceTable& pTable) {
// 原プログラムコード内から外部オブジェクトを参照する例
unsigned char* pBuffer = (unsigned char*)(*pTable->pHeapAlloc)(pTable->hHeap, 0, y);

// 機能の提供

// 原プログラムコード内から外部オブジェクトを参照する例
if (pBuffer != NULL) (*pTable->pHeapFree)(pTable->hHeap, 0, pBuffer);
return 0;
}

int tailFunc(int a){ return a; }
// 符号化対象コード終了
#pragma code_seg()
// Example compiled by Microsoft Visual Studio (registered trademark)
#include <windows.h>
// Create your own section
#pragma section (". mysect", write, execute)

bool g_isInitialized = false;
char BaseData [1024];

// External reference table
struct ExternalObjectReferenceTable {
HANDLE hHeap;
char * pData;
DWORD (WINAPI * pGetLastError) (VOID);
LPVOID (WINAPI * pHeapAlloc) (HANDLE, DWORD, SIZE_T);
BOOL (WINAPI * pHeapFree) (HANDLE, DWORD, LPVOID);
} g_table = {NULL, BaseData, NULL, NULL, NULL};
// If you want to create an external reference table statically, do it here

extern bool DoDecrypt (unsigned char *, BYTE *, BYTE *);

// Initialization function
int initialize (void)
{
if (g_isInitialized) return 0;
// Decryption code
static unsigned char key [] = {0, 1, 2, 3, 4, 5, 6, 7};
BYTE * pFuncTop = reinterpret_cast <BYTE *>(topFunc);
BYTE * pFuncTail = reinterpret_cast <BYTE *>(tailFunc);
if (DoDecrypt (key, pFuncTop, pFuncTail)) return -6;

// External reference table creation code
g_table.hHeap = GetProcessHeap ();
if (g_table.hHeap == NULL) return -1;

HINSTANCE hKERNEL32 = LoadLibrary ("kernel32.dll");
if (hKERNEL32 == NULL) return -2;
// kernel32.dll
g_table.pGetLastError = (DWORD (WINAPI *) (VOID))
GetProcAddress (hKERNEL32, "GetLastError");
if (g_table.pGetLastError == NULL) return -3;
g_table.pHeapAlloc = (LPVOID (WINAPI *) (HANDLE, DWORD, SIZE_T))
GetProcAddress (hKERNEL32, "HeapAlloc");
if (g_table.pHeapAlloc == NULL) return -4;
g_table.pHeapFree = (BOOL (WINAPI *) (HANDLE, DWORD, LPVOID))
GetProcAddress (hKERNEL32, "HeapFree");
if (g_table.pHeapFree == NULL) return -5;
g_isInitialized = true;
return 0;
}

// calling code
int callTopFunc (unsigned char * x, unsigned int y) {
if (false == g_isInitialized) return -1;
return topFunc (x, y, &g_table);
}

#pragma code_seg (". mysect")
// Start original program code
int topFunc (unsigned char * x, unsigned int y,
// Example of passing external reference table address by argument (via stack or register)
struct ExternalObjectReferenceTable & pTable) {
// Example of referencing an external object from within the original program code
unsigned char * pBuffer = (unsigned char *) (* pTable-> pHeapAlloc) (pTable-> hHeap, 0, y);

// provide functionality

// Example of referencing an external object from within the original program code
if (pBuffer! = NULL) (* pTable-> pHeapFree) (pTable-> hHeap, 0, pBuffer);
return 0;
}

int tailFunc (int a) {return a;}
// End of encoding target code
#pragma code_seg ()

以上の例は、Microsoft社のVisual Studio(登録商標)のC/C++コンパイラによりコンパイルされることを想定したソースコードである。また、この例は、符号化(暗号化)する関数を指定した指定情報が、オブジェクトコードとは別に生成される関数リストである場合の例である。   The above example is a source code that is assumed to be compiled by a Visual Studio (registered trademark) C / C ++ compiler of Microsoft Corporation. Further, this example is an example in which the specification information specifying the function to be encoded (encrypted) is a function list generated separately from the object code.

上記コード例には、まず独自セクション130を作成するためのコードが記述されている。Microsoft社のVisual StudioのC/C++コンパイラであれば、[#pragma section(“名前”, アトリビュート)]という記述で当該セクションを作成することができる。上述の例では、”.mysect”という名前の独自セクションを作成し、このセクションを書き込み可能かつ実行可能なセクションとして設定している。そして、ソースコード中で、関数定義された関数を[#pragma code_seg(“名前”)]と[#pragma code_seg()]とで挟むことで、その関数を作成した独自セクションに置くことができる(上述のコード例の末尾の原プログラムコードの記述を参照)。また、GNUのGCCコンパイラを用いてコンパイルする場合は、関数の定義に[__attribute__ ((section (“名前”)))]のアトリビュートを付加することで、その関数を設置するセクションを指定できる。   In the above code example, first, a code for creating the unique section 130 is described. If it is a Microsoft Visual Studio C / C ++ compiler, the section can be created with the description [#pragma section (“name”, attribute)]. In the above example, a custom section named “.mysect” is created and set as a writable and executable section. And in the source code, the function defined function can be put in [#pragma code_seg (“name”)] and [#pragma code_seg ()] and placed in the original section that created the function ( (See the description of the original program code at the end of the example code above). When compiling with the GNU GCC compiler, you can specify the section where the function is installed by adding the [__attribute__ ((section (“name”)))] attribute to the function definition.

上述のコード例では、独自セクションの作成を指示するコードの次に外部参照テーブル142(”g_table”)が定義されている。   In the above code example, the external reference table 142 (“g_table”) is defined after the code for instructing the creation of the unique section.

外部参照テーブル142の定義の後に、外部参照テーブル142の静的な部分を記述してもよい。すなわち、外部参照テーブル142のうちラベル名などにより静的に生成可能なデータは、ラベル名を用いてテーブルのエントリを生成し、リンカがそのラベル名に対応するアドレスを解決するようにする。   After the definition of the external reference table 142, a static part of the external reference table 142 may be described. That is, data that can be generated statically by a label name or the like in the external reference table 142 generates a table entry using the label name, and the linker resolves the address corresponding to the label name.

また、外部参照テーブル142についての記述の後に、初期化関数122のコードが記述される。この初期化関数122のコード中には、まず復号コード124が記述され、その次に外部参照テーブル作成コード126が記述されている。   In addition, after the description of the external reference table 142, the code of the initialization function 122 is described. In the code of the initialization function 122, the decryption code 124 is first described, and then the external reference table creation code 126 is described.

上述の例の復号コード124では、復号に用いる情報のうち復号対象とするセクション(すなわち独自セクション130、とくに原プログラムコード)の範囲を示す情報として、当該セクションの先頭アドレスと終了アドレスと、を取得している。ただし、これは一例に過ぎない。この代わりに、先頭アドレスとセクションのサイズとを取得してもよい。また、別の例としてセクションの先頭と末尾にラベルを付与し、これらラベルからセクションの範囲を取得してもよい。また、セクションの先頭と末尾とに、定義した関数(上述のコード例におけるtopFuncとtailFunc)を用いることで、復号コード124がセクションの範囲を取得するようにしてもよい。また、復号コード124が行う処理が暗文復号であれば復号鍵が必要となるが、復号鍵としてはあらかじめ定めておいた値を用いるようにしてもよい。   In the decoding code 124 of the above-described example, the start address and end address of the section are acquired as information indicating the range of the section to be decoded (that is, the original section 130, particularly the original program code) among the information used for decoding. doing. However, this is only an example. Instead, the start address and the section size may be acquired. As another example, labels may be added to the beginning and end of a section, and the section range may be acquired from these labels. Further, by using defined functions (topFunc and tailFunc in the above code example) at the beginning and end of the section, the decoded code 124 may acquire the section range. Further, if the process performed by the decryption code 124 is ciphertext decryption, a decryption key is required. However, a predetermined value may be used as the decryption key.

また、初期化関数のうちの外部参照テーブル作成コード126は、原プログラムコードが参照する外部オブジェクトのうち実行時にアドレスを解決するべきオブジェクトについて、動的に実行時にアドレスを取得し、取得したアドレスを外部参照テーブル142に設定する処理を記述している。例えば、Windows(登録商標)オペレーティングシステムにおいては、GetProcAddressというAPI関数により、外部関数のアドレスが取得できる。例えば、上記コード例では、当該ライブラリ(オブジェクトファイル100)を呼び出すリンク元プログラムのプロセスヒープのアドレスを取得して外部参照テーブルに登録している(g_table.hHeap = GetProcessHeap())。このプロセスヒープは、原プログラムコードにおいて参照される。また、上述のコード例では、原プログラムコードは、例えば、”kernel32.dll”というライブラリファイルに含まれる関数HeapAllocなどを外部オブジェクトとして参照するが、それら外部オブジェクトのメモリ上でのアドレスをGetProcAddress関数により取得し、取得したアドレスを外部参照テーブルg_tableのメンバ(例えばpHeapAlloc)に代入している。   The external reference table creation code 126 in the initialization function dynamically acquires an address at the time of execution for an object whose address should be resolved at the time of execution among the external objects referred to by the original program code, and sets the acquired address. A process to be set in the external reference table 142 is described. For example, in the Windows (registered trademark) operating system, the address of an external function can be acquired by an API function called GetProcAddress. For example, in the above code example, the process heap address of the link source program that calls the library (object file 100) is acquired and registered in the external reference table (g_table.hHeap = GetProcessHeap ()). This process heap is referenced in the original program code. In the above code example, the original program code refers to, for example, the function HeapAlloc included in the library file “kernel32.dll” as an external object. The addresses of these external objects in the memory are obtained by the GetProcAddress function. The acquired address is assigned to a member (eg, pHeapAlloc) of the external reference table g_table.

なお、原プログラムコードが用いるデータによっては、当該データを含んだ外部オブジェクトのアドレスでなく当該オブジェクト中の当該データを直接、外部参照テーブルに設定してもよい。   Depending on the data used by the original program code, the data in the object may be set directly in the external reference table instead of the address of the external object containing the data.

初期化関数122の記述の後には、復号結果の原プログラムコードを呼び出すための呼び出しコード128が記述される。呼び出しコード128は、上述の例では、外部参照テーブルの初期化(作成)が完了していれば(フラグg_isInitializedがtrue)、原プログラムコード中の関数topFuncを呼び出す記述となっている。ここで、関数topFuncは外部参照テーブル構造体のポインタを引数の1つとしており、呼び出しコード128では、その引数に対し、外部参照テーブル作成コードにより完成したテーブルg_tableのアドレスをセットしている。これにより、呼び出された原プログラムコードの関数topFuncが、外部参照テーブルを参照可能となる。   After the description of the initialization function 122, a call code 128 for calling the original program code of the decoding result is described. In the above-described example, the call code 128 is a description for calling the function topFunc in the original program code if the external reference table has been initialized (created) (the flag g_isInitialized is true). Here, the function topFunc takes the pointer of the external reference table structure as one argument, and the call code 128 sets the address of the table g_table completed by the external reference table creation code for the argument. Thus, the function topFunc of the called original program code can refer to the external reference table.

また、上述のコード例では、呼び出しコード128の後に記述された原プログラムコード中の関数topFuncは、引数として外部参照テーブルのアドレス(p_table)を受け取る。また、この関数は、外部オブジェクト(例えば関数HeapAlloc)をその名前で参照するのではなく、外部参照テーブル中の当該オブジェクトに対応するメンバが示すアドレス(p_table->pHeapAlloc)を介してそのオブジェクトを参照する。また、その関数は、呼び出し側の外部関数のプロセスヒープを、外部参照テーブルのメンバpTable->pHeapを介して参照している。   In the above code example, the function topFunc in the original program code described after the call code 128 receives the address (p_table) of the external reference table as an argument. In addition, this function does not refer to an external object (for example, function HeapAlloc) by its name, but refers to that object via the address (p_table-> pHeapAlloc) indicated by the member corresponding to the object in the external reference table. To do. The function refers to the process heap of the calling external function through the member pTable-> pHeap of the external reference table.

上述のコード例では、原プログラムコード中には機能を提供する関数が1つしかなかったが、原プログラムコード中にそのような関数が複数含まれていてもよい。また、この場合、それら関数を個別に呼び出せるように、関数毎に当該関数を呼び出す呼び出しコード128を用意するようにしてもよい。   In the above code example, there is only one function providing a function in the original program code, but a plurality of such functions may be included in the original program code. In this case, a call code 128 for calling the function may be prepared for each function so that the functions can be called individually.

このようなライブラリのソースコードは、例えば次の流れで作成すればよい。すなわち、まず、原プログラムコードを、上述のコード例のように、外部オブジェクトへのアクセスが外部参照テーブルを介して行われる形で記述する。また、原プログラムコードの関数を、独自セクションに置くようにコンパイラに指定するためのコードを記述する。また、独自セクションを復号するための復号コードを実装する。また、外部参照テーブルを定義し、そのうちラベル名などにより静的に生成可能なデータについてはラベル名を用いてテーブルの内容を記述する。また、実行時にアドレスを解決するべき外部オブジェクトについての情報を外部参照テーブルに登録する処理を記述した外部参照テーブル生成コードを実装する。また、外部参照テーブルを引数として原プログラムコード中の関数を呼び出す呼び出しコードを記述する。   What is necessary is just to produce the source code of such a library in the following flow, for example. That is, first, the original program code is described in a form in which access to the external object is performed via the external reference table as in the above code example. Also, code for specifying to the compiler to place the function of the original program code in its own section is written. In addition, a decoding code for decoding the unique section is implemented. Also, an external reference table is defined, and the contents of the table are described using the label name for data that can be generated statically by the label name. In addition, an external reference table generation code describing a process of registering information about an external object whose address should be resolved at the time of execution in the external reference table is implemented. In addition, a call code that calls a function in the original program code with an external reference table as an argument is described.

次に図3を参照して、この実施の形態のオブジェクトファイル100がライブラリとして作成され、配布されて利用される場合の流れの例を説明する。   Next, an example of a flow when the object file 100 of this embodiment is created as a library, distributed, and used will be described with reference to FIG.

この流れでは、まずライブラリ開発者が、自分のコンピュータ200にて、以上のようにしてライブラリのソースコード150を作成した後、次にそのソースコード150をコンパイラにコンパイルさせる。これによりライブラリのオブジェクトファイル100Aが生成される。このオブジェクトファイル100Aの独自セクション130内は、この時点では符号化されていない。次に、オブジェクトファイル100Aのうちの独自セクション130を符号化プログラムにより符号化する。これにより、符号化プログラムコード132を含んだ配布版のオブジェクトファイル100Bが完成する。完成したオブジェクトファイル100Bが、ライブラリを利用する利用者側に配布される。   In this flow, the library developer first creates the source code 150 of the library as described above on his / her computer 200, and then causes the compiler to compile the source code 150. As a result, an object file 100A of the library is generated. The unique section 130 of the object file 100A is not encoded at this point. Next, the unique section 130 of the object file 100A is encoded by the encoding program. As a result, the distribution version of the object file 100B including the encoded program code 132 is completed. The completed object file 100B is distributed to users who use the library.

なお、以上の処理の流れにおいて、独自セクション130の符号化前に、独自セクション130中に外部オブジェクトを直接参照するコードがないか確認し、存在する場合には、コードを修正するように警告する処理を行うようにしてもよい。外部オブジェクトを直接参照するコードがあるかは、例えば、独自セクション130についてのリロケーションテーブルの存在の有無および、エントリ数が1以上であるかによって判定すればよい。すなわち、コンパイラはソースコードをコンパイルする際に、後のリンク又はロードなどの処理のためのリロケーションテーブルを作成するが、独自セクション130についてこのリロケーションテーブルが作成されており、且つこのテーブルの中に1以上のエントリがあれば、独自セクション130中に外部オブジェクトを直接参照するコードがあると判定する。そして、独自セクション130中に外部オブジェクトを直接参照するコードがあると判定した場合には、リロケーションテーブルより参照しているオブジェクトのラベル名、及び、対象コードの位置(デバッグ情報が含まれる場合には、ソースコード上の場所まで)を判別し、判別した情報を警告と共に表示するようにしてもよい。   In the above processing flow, before encoding the unique section 130, it is checked whether there is any code that directly refers to the external object in the unique section 130. If it exists, a warning is given to correct the code. Processing may be performed. Whether there is a code that directly refers to the external object may be determined based on, for example, whether there is a relocation table for the unique section 130 and whether the number of entries is 1 or more. That is, when compiling the source code, the compiler creates a relocation table for later processing such as linking or loading, and this relocation table is created for the unique section 130, and 1 is included in this table. If there is the above entry, it is determined that there is a code directly referring to the external object in the unique section 130. When it is determined that there is a code that directly refers to the external object in the unique section 130, the label name of the object referenced from the relocation table and the position of the target code (if debug information is included) , Up to a place on the source code), and the determined information may be displayed together with a warning.

配布版のライブラリ(オブジェクトファイル100B)の提供を受けた利用者のコンピュータ210では、以下のような作業が行われる。   The user's computer 210 that has received the distribution version of the library (object file 100B) performs the following operations.

すなわち、まずライブラリ利用者は、そのライブラリを利用するリンク元コードをプログラミングする。リンク元コードは、被提供者側がマイクロプロセッサに実行させたい機能を記述するプログラムコードである。リンク元コードは、そのライブラリが提供する機能(複数あってもよい)を呼び出す記述を含む。ここで、リンク元コードは、ライブラリが提供する機能の呼び出しのすべてに先んじて、そのライブラリの初期化関数122を呼び出すようにプログラミングしておく。ここまでが、被提供者による一般のコーディング作業である。   That is, the library user first programs the link source code that uses the library. The link source code is a program code that describes a function that the recipient wants the microprocessor to execute. The link source code includes a description for calling a function (or a plurality of functions) provided by the library. Here, the link source code is programmed so as to call the initialization function 122 of the library prior to calling all the functions provided by the library. This is the general coding work by the recipient.

利用者は、作成したリンク元コードをコンパイルしてオブジェクトコード形式のリンク元コード155を生成する。そして、このリンク元コード155をライブラリのオブジェクトファイル100Bとリンカにリンクさせる。これにより、実行可能ファイル160が生成される。この実行可能ファイル160が、利用者のコンピュータ210のメモリにロードされ、実行される(170)。なお、このリンクは、静的リンクでも動的リンクでもよい。   The user compiles the created link source code to generate a link source code 155 in the object code format. The link source code 155 is linked to the library object file 100B and the linker. As a result, an executable file 160 is generated. This executable file 160 is loaded into the memory of the user's computer 210 and executed (170). This link may be a static link or a dynamic link.

次に、図4及び図5を参照して、外部参照テーブル142の内容変遷の例を説明する。この例では、まず図4に示すように、ソースコード中では外部参照テーブルはコード例10のように記述されているとする。すなわち、このコード例10では、メンバとしてpData、pfunc、pfunc2等を有する外部参照テーブルg_tableが定義され、そのテーブルの第2のメンバが関数funcとして静的に記述されている。また、そのコード例10は、外部参照テーブル作成コード126の例として、外部参照テーブルg_tableのメンバpFunc2に対し、関数func2(のアドレス)を代入するという命令を含んでいる。   Next, an example of content transition of the external reference table 142 will be described with reference to FIGS. In this example, first, as shown in FIG. 4, it is assumed that the external reference table is described as in Code Example 10 in the source code. That is, in this code example 10, an external reference table g_table having pData, pfunc, pfunc2, etc. is defined as a member, and the second member of the table is statically described as a function func. The code example 10 includes, as an example of the external reference table creation code 126, an instruction to substitute the function func2 (address thereof) for the member pFunc2 of the external reference table g_table.

このようなコード例10を含むソースコードをコンパイルすると、コード例20のようなオブジェクトコードを含んだオブジェクトファイルが得られる。この例では、ソースコード中の前述の外部参照テーブル作成コードは、オブジェクトファイル中ではコードセクション内のオフセット1300の位置にある「0番地の8バイト目(これは外部参照テーブル中のpfuncのエントリのアドレス)に、0と記入せよ」という命令(図では便宜上文章で説明したが、実際には当然ながら機械語命令である)へと変換されている。なお、その命令の2つの「0」の箇所には、後で適切なアドレス値がセットされる。また、データセクションのオフセット4100以降には、外部参照テーブルの各エントリが確保されている。ここでオフセット4104の位置には、後のリンク処理の際に関数funcのアドレスがセットされるが、この時点では場所の確保がなされるのみであり、値は0となっている。また、コード例20中のリロケーションセクションには、再配置情報であるリロケーションテーブルの内容が記入されている。リロケーションテーブルの内容は、例えば、コードのどの部分にどのシンボルのアドレスを入れるかを規定している。また、コード中のシンボルセクションには、コード中に現れるg_table等の各シンボルの情報が含まれる。シンボルの情報は、例えば名前、内容(データか、関数名かなど)、及び定義場所(このオブジェクトファイルの中か外か)を含んでいる。   When the source code including the code example 10 is compiled, an object file including the object code like the code example 20 is obtained. In this example, the external reference table creation code in the source code is “the eighth byte at address 0 (this is the entry of the pfunc entry in the external reference table) at the offset 1300 position in the code section in the object file. It is converted into an instruction (enter 0 in the address) (which has been described in text in the drawing for convenience, but is actually a machine language instruction). An appropriate address value is set later in the two “0” locations of the instruction. In addition, each entry of the external reference table is secured after the offset 4100 of the data section. Here, the address of the function func is set at the position of the offset 4104 at the time of the subsequent link processing. At this time, only the location is secured, and the value is 0. In the relocation section in Code Example 20, the contents of the relocation table, which is relocation information, are entered. The contents of the relocation table specify, for example, which part of the code contains which symbol address. The symbol section in the code includes information on each symbol such as g_table that appears in the code. The symbol information includes, for example, a name, contents (data or function name, etc.), and a definition location (inside or outside this object file).

このようなコード例20を含んだオブジェクトファイルが、外部プログラム(リンク元コード)とリンクされると、図5に例示するコード例30を含んだ実行可能ファイルが生成される。このコード例30では、外部プログラムとのリンクにより、オフセット値がオブジェクトファイルの時点から変化している。リンクにより、各オブジェクトのアドレス(この時点ではファイル上にあるのでオフセット値)が決まる。例えば、外部参照テーブルg_table、関数func及びfunc2のアドレスが6100、4800及び4940と決まるので、それらアドレスがコード中の対応する位置にセットされる。   When the object file including the code example 20 is linked with an external program (link source code), an executable file including the code example 30 illustrated in FIG. 5 is generated. In this code example 30, the offset value changes from the time of the object file by linking with the external program. The link determines the address of each object (offset value because it is on the file at this point). For example, since the addresses of the external reference table g_table and the functions func and func2 are determined to be 6100, 4800, and 4940, these addresses are set at corresponding positions in the code.

例えば、関数funcのアドレスは、オフセット6100以降に位置するg_table中の当該関数funcの位置にセットされる。これは、外部参照テーブル142のうちの静的な部分の例である。すなわち、リンクの際、リンカは、オブジェクトファイルのシンボルセクションとリロケーションセクションを参照して、関数funcに対応するシンボルCがオフセット4104に位置することを知ると共に、そのオフセット4104がリンクによりオフセット6104に移動したことを知り、これらに基づきオフセット6104に関数funcのアドレス4800をセットする。   For example, the address of the function func is set at the position of the function func in g_table located after the offset 6100. This is an example of a static part of the external reference table 142. That is, at the time of linking, the linker refers to the symbol section and the relocation section of the object file to know that the symbol C corresponding to the function func is located at the offset 4104, and the offset 4104 is moved to the offset 6104 by the link. Based on these, the address 4800 of the function func is set in the offset 6104.

また、関数func2のアドレス4800は、リンクによりオフセット3300に位置することとなった外部参照テーブル作成コード中にセットされる。この例では、外部参照テーブル作成コードの内容は、外部参照テーブルg_tableの先頭アドレス6100からみて8バイト目に、関数func2のアドレス4940をセットせよと言う命令となる。これは、外部参照テーブルのエントリのアドレスが、外部参照テーブル作成コードの実行により動的にセットされる例である。   The address 4800 of the function func2 is set in the external reference table creation code that is located at the offset 3300 by the link. In this example, the content of the external reference table creation code is an instruction to set the address 4940 of the function func2 at the eighth byte from the start address 6100 of the external reference table g_table. This is an example in which the address of the external reference table entry is dynamically set by executing the external reference table creation code.

なお、データセクション中の外部参照テーブルにあるpData及びfunc2は、まだアドレスがセットされておらず、0のままである。   Note that pData and func2 in the external reference table in the data section are not set yet, and remain 0.

このような実行可能ファイルがメインメモリにロードされ起動されると、外部参照テーブル作成コードの内の一部が実行される。ここでは、実行可能ファイルがメインメモリの0番地にロードされたとする。この場合、コード例40に示すように、データセクション中の外部参照テーブルは、オフセットと同じ値の番地(アドレス)に書き込まれることになる。この例では、コードセクションもデータセクションもロードにより内容は変化しない。   When such an executable file is loaded into the main memory and activated, a part of the external reference table creation code is executed. Here, it is assumed that the executable file is loaded at address 0 of the main memory. In this case, as shown in Code Example 40, the external reference table in the data section is written at an address (address) having the same value as the offset. In this example, neither the code section nor the data section is changed by loading.

そして、外部参照テーブル作成コードが実行されると、例えば3300番地のコードの実行により、6108番地に値4940がセットされることとなる。これにより、外部参照テーブルが完成する。   When the external reference table creation code is executed, the value 4940 is set at address 6108 by executing the code at address 3300, for example. Thereby, the external reference table is completed.

なお、図4及び図5の例では、リンクの時点で判明するfunc2のアドレスを外部参照テーブル作成コードにより、メモリ上の外部参照テーブル中での当該関数のアドレスにセットしたが、これは説明のための便宜的な例に過ぎない。外部参照テーブル作成コードは、典型的には、実行時に動的にアドレスが決定されるようなオブジェクトに対して利用すればよい。   In the examples of FIGS. 4 and 5, the address of func2 determined at the time of linking is set to the address of the function in the external reference table on the memory by the external reference table creation code. It is just a convenient example for. The external reference table creation code is typically used for an object whose address is dynamically determined at the time of execution.

このようにしてメインメモリ上に構成された外部参照テーブルのアドレス(典型的には先頭アドレス)は、復号後の原プログラムコードを実行するマイクロプロセッサ300に対し、呼び出しコード128の実行により引数として(例えばスタックやレジスタを介して)渡される。マイクロプロセッサ300は、その引数の値を用いて、原プログラムコード中の外部オブジェクトへの参照を、メインメモリ上の外部参照テーブル中での当該オブジェクトのエントリのアドレスへと変換する。そして、そのアドレスにアクセスすることで、その外部オブジェクトの実行時アドレスを知り、その外部オブジェクトへとアクセスする。   The address of the external reference table configured in the main memory in this way (typically the start address) is used as an argument by executing the call code 128 to the microprocessor 300 that executes the original program code after decoding ( (For example, via stack or register). The microprocessor 300 converts the reference to the external object in the original program code into the address of the entry of the object in the external reference table on the main memory using the value of the argument. Then, by accessing the address, the runtime address of the external object is known, and the external object is accessed.

開発者及び利用者が用いるコンピュータ200及び210は、図6に例示するような一般的なハードウエア構成を持つものでよい。すなわち、図6に例示するコンピュータは、例えば、CPU等のマイクロプロセッサ300、ランダムアクセスメモリ(RAM)302およびリードオンリメモリ(ROM)304等のメモリ(一次記憶)、HDD(ハードディスクドライブ)コントローラ308を経由して接続されたHDD306、各種I/O(入出力)インタフェース310等が、たとえばバス314を介して接続された回路構成を有する。バス314には、ローカルエリアネットワーク等のネットワークに接続するためのネットワークインタフェース312が接続されていてもよい。また、そのバス314に対し、例えばI/Oインタフェース310経由で、CDやDVDなどの可搬型ディスク記録媒体に対する読み取り及び/又は書き込みのためのディスクドライブ316、フラッシュメモリなどの各種規格の可搬型の不揮発性記録媒体に対する読み取り及び/又は書き込みのためのメモリリーダライタ318などが接続されてもよい。RAM302は、コンピュータ200又は210のメインメモリとして使用される。   The computers 200 and 210 used by developers and users may have a general hardware configuration as illustrated in FIG. That is, the computer illustrated in FIG. 6 includes, for example, a microprocessor 300 such as a CPU, a memory (primary storage) such as a random access memory (RAM) 302 and a read only memory (ROM) 304, and an HDD (hard disk drive) controller 308. The HDD 306, various I / O (input / output) interfaces 310, and the like connected via the network have a circuit configuration connected via a bus 314, for example. A network interface 312 for connecting to a network such as a local area network may be connected to the bus 314. In addition, the bus 314 has various standards such as a disk drive 316 for reading from and / or writing to a portable disk recording medium such as a CD and a DVD and a flash memory via the I / O interface 310, for example. A memory reader / writer 318 for reading from and / or writing to the nonvolatile recording medium may be connected. The RAM 302 is used as a main memory of the computer 200 or 210.

マイクロプロセッサ300が、ロードされた実行可能ファイル160を実行する処理手順を、図7及び図8を参照して説明する。   A processing procedure in which the microprocessor 300 executes the loaded executable file 160 will be described with reference to FIGS.

利用者によりリンク元コードが起動されると、コンピュータ210のメモリ400(図3のRAM302に対応)に実行可能ファイル160がロードされる。図8には、メモリ400にロードされた実行可能イメージのうちライブラリに由来する部分を示している。そして、その実行可能イメージのうちのリンク元コードがマイクロプロセッサ300により実行される。ここで、リンク元コード中にはライブラリの初期化関数122を呼び出すコードが含まれている。マイクロプロセッサ300がこのコードを実行すると(S10)、初期化関数122が呼び出される。すると、マイクロプロセッサ300により復号コード124及び外部参照テーブル作成コード126が実行される。これにより、コンピュータ210は、復号部410及び外部参照テーブル作成部420として機能する。   When the link source code is activated by the user, the executable file 160 is loaded into the memory 400 of the computer 210 (corresponding to the RAM 302 in FIG. 3). FIG. 8 shows a portion derived from the library in the executable image loaded in the memory 400. The link source code in the executable image is executed by the microprocessor 300. Here, the link source code includes a code that calls the library initialization function 122. When the microprocessor 300 executes this code (S10), the initialization function 122 is called. Then, the decoding code 124 and the external reference table creation code 126 are executed by the microprocessor 300. Thereby, the computer 210 functions as the decryption unit 410 and the external reference table creation unit 420.

復号部410は、独自セクション130の符号化プログラムコード132を復号する(S12)。ここで、独自セクション130は書き込み可能及び実行可能なセクションなので、復号部410はそのセクション130内のコード132の復号結果(すなわち原プログラムコード)をそのセクション130内に書き戻すことができる。   The decoding unit 410 decodes the encoded program code 132 of the unique section 130 (S12). Here, since the unique section 130 is a writable and executable section, the decoding unit 410 can write back the decoding result (that is, the original program code) of the code 132 in the section 130 into the section 130.

また、外部参照テーブル作成部420は、動的にアドレスを解決する必要のある各外部オブジェクトのアドレスを(例えばAPI関数を用いてオペレーティングシステムから)取得し、外部参照テーブル142に登録する。これにより、外部参照テーブル142が完成する(S14)。   Also, the external reference table creation unit 420 acquires the address of each external object that needs to dynamically resolve the address (for example, from the operating system using an API function) and registers it in the external reference table 142. Thereby, the external reference table 142 is completed (S14).

初期化関数122の実行が完了すると、リンク元コード側に制御が戻る。マイクロプロセッサ300は、リンク元コードの末尾に達するまで(S16)、リンク元コード内の命令を順番に実行する。この処理の中で、マイクロプロセッサ300で実行されるコードが呼び出しコード128に達すると(S18)、マイクロプロセッサ300は呼び出しコード128を実行する(S20)。これにより、コンピュータ210は呼び出し部430として機能する。呼び出し部430は、独自セクション130内の原プログラムコード中の、当該呼び出しコード128に対応する関数を呼び出す。この呼び出しの際、外部参照テーブル142のアドレスが引数として原プログラムコード側に渡される。   When the execution of the initialization function 122 is completed, control returns to the link source code side. The microprocessor 300 sequentially executes the instructions in the link source code until the end of the link source code is reached (S16). In this process, when the code executed by the microprocessor 300 reaches the call code 128 (S18), the microprocessor 300 executes the call code 128 (S20). Thereby, the computer 210 functions as the calling unit 430. The calling unit 430 calls a function corresponding to the calling code 128 in the original program code in the unique section 130. At the time of this call, the address of the external reference table 142 is passed as an argument to the original program code side.

この呼び出しに応じて、マイクロプロセッサ300は、原プログラムコード内の呼び出された関数を実行する(S22)。この実行により、コンピュータ210は、その関数が表す機能を提供する機能実行部440として機能する。機能実行部440は、呼び出された関数中で参照される外部オブジェクトにアクセスする際に、外部参照テーブル142を介してアクセスする。すなわち、引数として渡された外部参照テーブル142のアドレス(先頭アドレス)をもとに、その外部参照テーブル142内での当該外部オブジェクトのエントリのアドレスにアクセスし、アクセスしたアドレスにある値(すなわち当該外部オブジェクトの実行時アドレス)を用いて当該外部オブジェクトにアクセスする。   In response to this call, the microprocessor 300 executes the called function in the original program code (S22). By this execution, the computer 210 functions as a function execution unit 440 that provides a function represented by the function. The function execution unit 440 accesses the external object referenced in the called function via the external reference table 142. That is, based on the address (start address) of the external reference table 142 passed as an argument, the address of the entry of the external object in the external reference table 142 is accessed, and the value at the accessed address (that is, the relevant address) The external object is accessed using the external object runtime address).

呼び出された関数の実行が完了すると、処理がリンク元コード側に戻される。そして、リンク元コードの末尾に達するまで(S16)、S18〜S22の処理が繰り返される。   When the execution of the called function is completed, the processing is returned to the link source code side. The processes of S18 to S22 are repeated until the end of the link source code is reached (S16).

以上、この実施の形態のオブジェクトファイル100の構成とその利用について説明した。以上の説明から理解されるように、この実施の形態の原プログラムコードには、外部オブジェクトを直接参照する記述は含まれない。この代わりに、原プログラムコード中では、外部オブジェクトへの参照は、呼び出しコード128から引数(上述のコード例ではp_table)として渡される外部参照テーブル142中のエントリを用いる間接参照の形で記述される。引数は、コンパイルの結果生成されるシンボルテーブルにも再配置情報(これらはオブジェクトファイル100内に含まれ、リンクやロードの際に参照される)にも登録されないので、上述のコード例でも、独自セクション130の原プログラムコード内のp_table->pHeapAllocやp_table->pHeapなどといった引数p_tableを介した参照はシンボルテーブルや再配置情報に登録されない。したがって、オブジェクトファイル100がリンク元コードとリンクされる際のアドレス解決処理において、独自セクション130内のシンボル又はアドレスが書き換えられることがない。リンクの時点では、独自セクション130内のコードは符号化されているため(符号化プログラムコード132)、アドレス解決のためにそのコードの一部が書き換えられると復号ができなくなるが、この実施の形態では独自セクション130はアドレス解決時に書き換えられないので、そのような不具合は生じない。すなわち、この実施の形態のオブジェクトファイル100の構成を用いれば、通常のコンパイラ及びリンカを用いた場合でも、符号化プログラムコード132がリンク時に破壊されることが防がれる。   The configuration and use of the object file 100 according to this embodiment has been described above. As can be understood from the above description, the original program code of this embodiment does not include a description that directly refers to an external object. Instead, in the original program code, a reference to an external object is described in the form of an indirect reference using an entry in the external reference table 142 passed as an argument (p_table in the above code example) from the calling code 128. . Arguments are not registered in the symbol table generated as a result of compilation nor in relocation information (these are included in the object file 100 and referred to when linking or loading). References through the argument p_table such as p_table-> pHeapAlloc and p_table-> pHeap in the original program code of the section 130 are not registered in the symbol table or the relocation information. Therefore, in the address resolution process when the object file 100 is linked with the link source code, the symbol or address in the unique section 130 is not rewritten. Since the code in the unique section 130 is encoded at the time of linking (encoded program code 132), decoding cannot be performed when a part of the code is rewritten for address resolution. Since the unique section 130 is not rewritten at the time of address resolution, such a problem does not occur. In other words, if the configuration of the object file 100 of this embodiment is used, the encoded program code 132 can be prevented from being destroyed at the time of linking even when a normal compiler and linker are used.

なお、独自セクション130がリンク時のアドレス解決の際に書き換えられることが防止されるという点は、外部参照テーブル142のエントリが静的に記述されたもの(すなわち静的にアドレスが決まっている外部オブジェクトについてのもの)のみである場合にも成り立つ。   The point that the unique section 130 is prevented from being rewritten at the time of address resolution at the time of linking is that the entries of the external reference table 142 are statically described (that is, external addresses whose addresses are statically determined). This is true even if it is only for objects.

<変形例1>
上述の実施の形態では、復号コード124と外部参照テーブル作成コード126とを含む初期化関数122を、リンク元コードから明示的に呼び出す構成を説明したが、これは一例に過ぎない。リンク元コードから初期化関数122を明示的に呼び出す代わりに、リンク元コードから呼び出しコード128が最初に呼び出された際に、初期化関数122を実行するようにしてもよい。このために、ライブラリの初期化が既に実行されたか未実行であるかを示すフラグを例えばデータセクション140などに用意しておき、呼び出しコード128が呼ばれる毎にそのフラグを確認して、最初の呼び出しであれば、初期化関数122を呼び出す構成にすればよい。フラグが既実行を示す場合には、初期化関数122を呼び出さない。この例では、リンク元コードがライブラリの初期化関数122を呼ぶ手間が省かれる。
<Modification 1>
In the above-described embodiment, the configuration in which the initialization function 122 including the decryption code 124 and the external reference table creation code 126 is explicitly called from the link source code has been described, but this is merely an example. Instead of explicitly calling the initialization function 122 from the link source code, the initialization function 122 may be executed when the call code 128 is first called from the link source code. For this purpose, a flag indicating whether the initialization of the library has already been executed or not executed is prepared in the data section 140, for example, and the flag is checked each time the call code 128 is called, and the first call is made. If so, the initialization function 122 may be called. If the flag indicates already executed, the initialization function 122 is not called. In this example, the trouble of the link source code calling the library initialization function 122 is saved.

<変形例2>
上述の実施の形態では、原プログラムコードから外部オブジェクトへの参照のために外部参照テーブルを用いたが、外部参照のためのデータがテーブルである必要はなく、外部参照に必要な情報が原プログラムコードに渡すことができるものであればどのような方法を用いてもよい。例えば、個々の外部オブジェクト毎に当該オブジェクトのメモリ400上でのアドレスを示す外部参照情報をデータセクション140上に記述又は生成し、外部オブジェクトを参照する関数に対し、そのオブジェクトに対応する外部参照情報のアドレスを引数として渡すようにしてもよい。すなわち、複数の外部オブジェクトのアドレス情報をテーブルの形で一括して原プログラムコードに渡すのではなく、個々の外部オブジェクトのアドレス情報を個別に原プログラムコード中の関数に渡してもよい。特に、原プログラムコードが複数のインタフェースを持つ場合には、すべてのインタフェースに同一の情報(外部参照テーブル)を渡すのではなく、インタフェース毎に、それぞれ必要な外部参照情報を渡すという方法も取れる。
<Modification 2>
In the above-described embodiment, the external reference table is used for reference from the original program code to the external object. However, the data for external reference does not need to be a table, and information necessary for external reference is the original program. Any method that can be passed to the code can be used. For example, for each external object, external reference information indicating the address of the object in the memory 400 is described or generated in the data section 140, and the external reference information corresponding to the object is referred to a function that refers to the external object. May be passed as an argument. That is, the address information of a plurality of external objects may not be collectively transferred to the original program code in the form of a table, but the address information of each external object may be individually transferred to a function in the original program code. In particular, when the original program code has a plurality of interfaces, the same information (external reference table) is not passed to all interfaces, but the necessary external reference information can be passed for each interface.

<変形例3>
上述の実施の形態では、符号化プログラムコード132の復号結果である原プログラムコードを、独自セクション130に格納する例を説明したが、これは一例に過ぎない。実施の形態の手法は、原プログラムコードは外部参照テーブルを介して外部オブジェクトにアクセスするため、原プログラムコードがメモリ400のメモリ空間のどこに置かれても正しく動作する。したがって、変形例として、復号コード124の実行により実現された復号部410が、必要な大きさの、書き込み、読み出し及び実行のすべてが可能なメモリ領域をメモリ400のメモリ空間内に確保し、そのメモリ領域上に復号結果の原プログラムコードを置く構成としてもよい。この場合には、呼び出しコード128が、確保されたメモリ領域上の原プログラムコードを呼び出せるように、アドレス解決を行う必要がある。この場合には、復号部410は、原プログラムコードを置いたメモリ領域のアドレスを知っているので、呼び出しコード128に、関数ポインタを用いるなどの方法で、そのアドレスを原プログラムコード中の関数に渡すことで、そのアドレス解決を実現すればよい。
<Modification 3>
In the above-described embodiment, the example in which the original program code that is the decoding result of the encoded program code 132 is stored in the unique section 130 has been described, but this is only an example. According to the method of the embodiment, since the original program code accesses an external object through the external reference table, the original program code operates correctly regardless of where the original program code is placed in the memory space of the memory 400. Therefore, as a modified example, the decoding unit 410 realized by executing the decoding code 124 secures a memory area in the memory 400 that can be written, read, and executed in a necessary size. The original program code of the decoding result may be placed on the memory area. In this case, it is necessary to perform address resolution so that the calling code 128 can call the original program code in the secured memory area. In this case, since the decoding unit 410 knows the address of the memory area where the original program code is placed, the address is set to the function in the original program code by using a function pointer for the call code 128 or the like. It is only necessary to realize the address resolution by passing.

<変形例4>
上述の実施の形態では、原プログラムコードを一括して符号化する構成を説明したが、原プログラムコードが複数の機能を提供する場合、機能毎に分割して符号化するようにしてもよい。個々の機能は、それぞれ1つ又は複数の関数により提供される。この場合には、機能を提供するコード毎に当該コードがオブジェクトファイル中のどこに置かれたかの情報を、符号化プログラムと復号コード124(復号部410)が把握する必要がある。この情報は、ライブラリのラベル名を用いれば取得することができる。例えば、原プログラムコード中において複数の対象関数をひとかたまりとして符号化する場合を考える(原プログラムコード中には、そのようなかたまりが1以上存在する)。この場合、ひとかたまりとして符号化する対象関数群のうち最初に置かれた関数の関数名をシンボルとするコード位置から、その符号化する対象関数群の直後に置かれた関数名をシンボルとするコード位置の直前までが、ひとかたまりの符号化対象のコード(すなわち原プログラムコード)であると判断される。また、符号化したい対象となる関数が一つの場合(すなわち符号化の単位が1関数)は、その関数の先頭から次の関数の先頭の直前までが、一単位の符号化対象のコードと認識される。また関数の終了位置がシンボルとして定義されるようなコンパイラを用いる場合の別の方法としては、符号化する対象関数(群)で最初に置かれた関数名をシンボルとするコード位置を開始位置として、符号化する対象関数(群)の最後の関数の終了シンボルのコード位置までを、符号化対象のコードであると判断する方法である。関数の置かれる順番は、ソースコード上の定義の順番であることが一般的である。また、関数を置く順番を外から指定できるコンパイラも存在する。これにより符号化対象の関数を置く順番を制御することができる。別の方法では、一般のリンカではその出力情報の一つとして、生成した実行ファイルのどの位置にどのシンボルの関数を置いたかを示す情報(マップ情報と呼ばれる)を出力させることができる。このマップ情報を参照することで、符号化対象のコードがファイル内のどの位置に置かれたかを知ることができる。このように機能単位で符号化すれば、実行時に必要なコードだけ復号するといった使い方が可能となる。
<Modification 4>
In the above-described embodiment, the configuration in which the original program code is collectively encoded has been described. However, when the original program code provides a plurality of functions, the original program code may be divided and encoded for each function. Each individual function is provided by one or more functions. In this case, it is necessary for the encoding program and the decoding code 124 (decoding unit 410) to grasp information about where the code is placed in the object file for each code that provides the function. This information can be obtained by using the library label name. For example, consider a case where a plurality of target functions are encoded as a group in the original program code (one or more such clusters exist in the original program code). In this case, from the code position having the function name of the first function in the target function group to be encoded as a symbol as a symbol, the code having the function name immediately after the target function group to be encoded as a symbol It is determined that the code up to just before the position is a group of codes to be encoded (that is, the original program code). If there is only one function to be encoded (that is, the unit of encoding is one function), the code from the beginning of the function to the immediately preceding head of the next function is recognized as one unit of encoding target code. Is done. As another method when using a compiler in which the end position of a function is defined as a symbol, the code position with the function name first placed in the target function (s) to be encoded as a symbol is used as the start position. This is a method of determining that the code position of the end symbol of the last function of the target function (group) to be encoded is the code to be encoded. The order in which functions are placed is generally the order of definitions in the source code. Some compilers can specify the order in which functions are placed from the outside. As a result, the order in which the functions to be encoded are placed can be controlled. In another method, a general linker can output information (referred to as map information) indicating which symbol function is placed at which position of the generated executable file as one of the output information. By referring to this map information, it is possible to know where in the file the code to be encoded has been placed. When encoding is performed in units of functions in this way, it is possible to use such that only codes necessary for execution are decoded.

<変形例5>
上述の実施の形態では、一度復号した原プログラムコードは実行されるだけであるが、実行された後に再び符号化する構成としてもよい。符号化の目的が暗号化の様に情報の秘匿である場合には、このように再符号化すれば、原プログラムコードがメモリ上に存在する時間を減らすことで、より強固に情報を秘匿することが期待できる。これには、例えば呼び出しコード128を呼び出す直前に復号コード126を実行し、呼び出しコード128の実行終了後に符号化のためのコードを実行して符号化結果を独自セクション130に上書きするようにプログラミングすればよい。
<Modification 5>
In the above-described embodiment, the original program code once decoded is only executed, but may be encoded again after being executed. If the purpose of encoding is information concealment like encryption, re-encoding in this way can conceal information more firmly by reducing the time that the original program code exists in the memory. I can expect that. For example, the decoding code 126 is executed immediately before calling the calling code 128, and the code for encoding is executed after the execution of the calling code 128 is overwritten to overwrite the original section 130 with the encoding result. That's fine.

特に、変形例4と組み合せることが考えられる。この場合、個々の機能毎に、当該機能が実行される前に復号し、機能の実行後に再び符号化し、符号化結果を原プログラムコードに上書きすればよい。   In particular, it can be considered to be combined with Modification 4. In this case, each function may be decoded before the function is executed, encoded again after the function is executed, and the encoded result is overwritten on the original program code.

100 オブジェクトファイル、110 オブジェクトヘッダ、120 コードセクション、122 初期化関数、124 復号コード、126 外部参照テーブル作成コード、128 呼び出しコード、130 独自セクション、132 符号化プログラムコード、140 データセクション、142 外部参照テーブル。   100 object file, 110 object header, 120 code section, 122 initialization function, 124 decoding code, 126 external reference table creation code, 128 calling code, 130 original section, 132 encoding program code, 140 data section, 142 external reference table .

Claims (5)

原プログラムコードの符号化結果である符号化プログラムコードと、
前記符号化プログラムコードを復号して前記原プログラムコードを復元する処理を前記コンピュータに実行させるための復号プログラムコードと、
前記原プログラムコード中で参照される外部オブジェクトのアドレスを表す外部参照情報と、
外部プログラムからの呼び出しに応じて、前記復号プログラムコードにより復元された前記原プログラムコードを、前記外部参照情報のアドレスを引数として渡して呼び出す処理を、前記コンピュータに実行させるための呼び出しプログラムコードと、
を備え、
前記原プログラムコードは、前記外部オブジェクトへの参照を、引数として渡される前記外部参照情報のアドレスを用いて記述したものであり、前記呼び出しプログラムコードから引数として渡された前記外部参照情報のアドレスにアクセスして前記外部オブジェクトのアドレスを取得し、取得したアドレスを用いて前記外部オブジェクトを参照する処理を前記コンピュータに実行させる、
ことを特徴とするオブジェクトファイル形式のプログラム。
An encoded program code which is an encoding result of the original program code;
Decoding program code for causing the computer to execute a process of decoding the encoded program code and restoring the original program code;
External reference information representing the address of an external object referenced in the original program code;
In response to a call from an external program, a calling program code for causing the computer to execute a process of calling the original program code restored by the decryption program code by passing an address of the external reference information as an argument;
With
The original program code describes a reference to the external object using the address of the external reference information passed as an argument, and the address of the external reference information passed as an argument from the calling program code. Obtaining the address of the external object by accessing, causing the computer to execute a process of referring to the external object using the acquired address;
An object file format program characterized by that.
前記原プログラムコード中で参照される外部オブジェクトのアドレスを取得し、前記外部参照情報として、取得したアドレスを含んだ情報を生成するための処理を前記コンピュータに実行させるための外部参照情報作成プログラムコード、
を更に備えることを特徴とする請求項1記載のプログラム。
External reference information creation program code for acquiring an address of an external object referred to in the original program code and causing the computer to execute processing for generating information including the acquired address as the external reference information ,
The program according to claim 1, further comprising:
前記プログラムは、
読み出し、書き込み、及び実行が可能なメモリ領域を前記コンピュータのメモリ上に確保する処理を前記コンピュータに実行させるためのプログラムコード、
を更に含み、
前記復号プログラムコードは、復号の結果である前記原プログラムコードを前記確保されたメモリ領域に書き込むための処理を前記コンピュータに実行させる、
ことを特徴とする請求項1記載のプログラム。
The program is
Program code for causing the computer to execute a process of securing a memory area that can be read, written, and executed on the memory of the computer;
Further including
The decryption program code causes the computer to execute a process for writing the original program code as a result of decryption into the secured memory area.
The program according to claim 1.
前記コンピュータを、
前記復号プログラムコードが既実行か未実行かを表すフラグを記憶するフラグ記憶手段、
前記呼び出しプログラムコードが呼び出された場合に、前記フラグ記憶手段に記憶された前記フラグが未実行を表す場合には前記復号プログラムコードを実行して前記フラグを既実行に変更し、前記フラグが既実行を表す場合には前記復号プログラムコードを実行しないように制御する制御手段、
として更に機能させることを特徴とする請求項1記載のプログラム。
The computer,
Flag storage means for storing a flag indicating whether the decryption program code is already executed or not executed;
When the calling program code is called, if the flag stored in the flag storage means represents unexecuted, the decrypted program code is executed to change the flag to already executed, and the flag is already set. Control means for controlling not to execute the decryption program code when representing execution;
The program according to claim 1, further functioning as:
原プログラムコードの符号化結果である符号化プログラムコードを復号して前記原プログラムコードを復元する復号手段と、
前記原プログラムコード中で参照される外部オブジェクトのアドレスを表す外部参照情報を記憶する外部参照情報記憶手段と、
外部プログラムからの呼び出しに応じて、前記復号手段により復元された前記原プログラムコードを、前記外部参照情報のアドレスを引数として渡して呼び出す呼び出し手段と、
前記呼び出し手段により呼び出された前記原プログラムコードを実行する実行手段と、
を備え、
前記原プログラムコードは、前記外部オブジェクトへの参照を、引数として渡される前記外部参照情報のアドレスを用いて記述したものであり、前記呼び出し手段から引数として渡された前記外部オブジェクトを参照する場合に、前記外部参照情報のアドレスにアクセスして前記外部オブジェクトのアドレスを取得し、取得したアドレスを用いて前記外部オブジェクトを参照する処理を前記実行手段に実行させる、
ことを特徴とするプログラム実行装置。
Decoding means for decoding the encoded program code that is the result of encoding the original program code and restoring the original program code;
External reference information storage means for storing external reference information representing an address of an external object referred to in the original program code;
Calling means for calling the original program code restored by the decoding means by passing an address of the external reference information as an argument in response to a call from an external program;
Execution means for executing the original program code called by the calling means;
With
The original program code describes a reference to the external object by using the address of the external reference information passed as an argument, and refers to the external object passed as an argument from the calling unit. , Obtaining the address of the external object by accessing the address of the external reference information, and causing the execution means to execute a process of referring to the external object using the acquired address.
A program execution device.
JP2009078062A 2009-03-27 2009-03-27 Program and program execution device Expired - Fee Related JP5387089B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2009078062A JP5387089B2 (en) 2009-03-27 2009-03-27 Program and program execution device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2009078062A JP5387089B2 (en) 2009-03-27 2009-03-27 Program and program execution device

Publications (2)

Publication Number Publication Date
JP2010231477A JP2010231477A (en) 2010-10-14
JP5387089B2 true JP5387089B2 (en) 2014-01-15

Family

ID=43047231

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2009078062A Expired - Fee Related JP5387089B2 (en) 2009-03-27 2009-03-27 Program and program execution device

Country Status (1)

Country Link
JP (1) JP5387089B2 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2014147748A1 (en) * 2013-03-19 2014-09-25 株式会社東芝 Code processing device and program
KR101556908B1 (en) * 2013-11-14 2015-10-02 (주)잉카엔트웍스 Apparatus For Protecting Binary Code
JP7123001B2 (en) * 2019-04-26 2022-08-22 ルネサスエレクトロニクス株式会社 system of record

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP3033562B2 (en) * 1998-09-02 2000-04-17 富士ゼロックス株式会社 Method for generating relocatable execution program and execution program generation device
JP2000330768A (en) * 1999-05-19 2000-11-30 Nec Corp Method for setting entrance of executable program
JP4042280B2 (en) * 1999-12-21 2008-02-06 富士ゼロックス株式会社 Execution program generation method and execution program generation apparatus, execution program execution method, and computer-readable program storage medium
JP2005157502A (en) * 2003-11-20 2005-06-16 Sony Corp Information processor and information processing method and computer program
JP4517636B2 (en) * 2003-12-05 2010-08-04 富士ゼロックス株式会社 Execution program creation method, function program, and function program execution method
JP4770425B2 (en) * 2005-11-24 2011-09-14 富士ゼロックス株式会社 Program, method and apparatus for creating protected execution program

Also Published As

Publication number Publication date
JP2010231477A (en) 2010-10-14

Similar Documents

Publication Publication Date Title
US10185837B2 (en) System and method for encapsulating and enabling protection through diverse variations in software libraries
CN101300584B (en) Method for preventing unauthorized modification for software or runtime data
US11748468B2 (en) Dynamic switching between pointer authentication regimes
US8745406B2 (en) Program executable image encryption
Eilam Reversing: secrets of reverse engineering
JP5302202B2 (en) Virtualization for diversified manipulation tolerance
US9207918B2 (en) Firmware extension method and firmware builder
US10635823B2 (en) Compiling techniques for hardening software programs against branching programming exploits
US8090959B2 (en) Method and apparatus for protecting .net programs
CN108932406A (en) Virtualization software guard method and device
GB2438229A (en) Method of moving data in a processing system by specifying the source and target address spaces to a move data instruction.
CN102402451A (en) Compile-time bounds checking for user-defined types
JP2001175466A (en) Method and device for generating execution program, and method for executing execution program and computer-readable program storage medium
US20030051233A1 (en) Code distribution and synthesis
JP5387089B2 (en) Program and program execution device
JP5953867B2 (en) Program and program protection device
US20130275688A1 (en) Data processing device and method
Ramakesavan et al. Intel memory protection extensions enabling guide
US11886839B2 (en) Non-transitory computer-readable recording medium, function generation method, and information processing device
EP4012584A1 (en) Method for creating extended elf files to provide unified and secure deployments
US20090106540A1 (en) Apparatus and method for remanipulating instructions
JP2006072584A (en) Device for creating execution program, method for creating execution program, program processing apparatus, program processing method, and program
WO2022122942A1 (en) Method for generating extended elf files to simplify complex and secure application deployments
Staursky Lambda Calculus for Binary Security and Analysis
Tian et al. Software Information Hiding Algorithm Based on Import Table of Portable Executable File

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20120222

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20130306

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20130326

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20130517

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20130806

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20130822

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: 20130910

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20130923

R150 Certificate of patent or registration of utility model

Ref document number: 5387089

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

Free format text: JAPANESE INTERMEDIATE CODE: R150

LAPS Cancellation because of no payment of annual fees