ホーム › System.SystemServices › IMAGE_OS2_HEADER
IMAGE_OS2_HEADER
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| ne_magic | WORD | 2 | +0 | +0 | NEヘッダーのマジック値。'NE'を示す。 |
| ne_ver | CHAR | 1 | +2 | +2 | リンカのメジャーバージョン番号。 |
| ne_rev | CHAR | 1 | +3 | +3 | リンカのマイナーバージョン番号。 |
| ne_enttab | WORD | 2 | +4 | +4 | エントリテーブルのオフセット。 |
| ne_cbenttab | WORD | 2 | +6 | +6 | エントリテーブルのバイトサイズ。 |
| ne_crc | INT | 4 | +8 | +8 | ファイル全体のCRC32チェックサム。 |
| ne_flags | WORD | 2 | +12 | +12 | モジュール属性のフラグ。 |
| ne_autodata | WORD | 2 | +14 | +14 | 自動データセグメント番号。 |
| ne_heap | WORD | 2 | +16 | +16 | ローカルヒープの初期サイズ。 |
| ne_stack | WORD | 2 | +18 | +18 | スタックの初期サイズ。 |
| ne_csip | INT | 4 | +20 | +20 | 初期CS:IP値。 |
| ne_sssp | INT | 4 | +24 | +24 | 初期SS:SP値。 |
| ne_cseg | WORD | 2 | +28 | +28 | セグメントテーブルのエントリ数。 |
| ne_cmod | WORD | 2 | +30 | +30 | モジュール参照テーブルのエントリ数。 |
| ne_cbnrestab | WORD | 2 | +32 | +32 | 非常駐名テーブルのバイトサイズ。 |
| ne_segtab | WORD | 2 | +34 | +34 | セグメントテーブルのオフセット。 |
| ne_rsrctab | WORD | 2 | +36 | +36 | リソーステーブルのオフセット。 |
| ne_restab | WORD | 2 | +38 | +38 | 常駐名テーブルのオフセット。 |
| ne_modtab | WORD | 2 | +40 | +40 | モジュール参照テーブルのオフセット。 |
| ne_imptab | WORD | 2 | +42 | +42 | インポート名テーブルのオフセット。 |
| ne_nrestab | INT | 4 | +44 | +44 | 非常駐名テーブルのファイルオフセット。 |
| ne_cmovent | WORD | 2 | +48 | +48 | 移動可能エントリポイント数。 |
| ne_align | WORD | 2 | +50 | +50 | セグメントアライメントのシフト量(2の対数)。 |
| ne_cres | WORD | 2 | +52 | +52 | リソースセグメント数。 |
| ne_exetyp | BYTE | 1 | +54 | +54 | 対象OSの種別(実行可能形式)。 |
| ne_flagsothers | BYTE | 1 | +55 | +55 | その他のEXE属性フラグ。 |
| ne_pretthunks | WORD | 2 | +56 | +56 | リターンスランクのオフセット。 |
| ne_psegrefbytes | WORD | 2 | +58 | +58 | セグメント参照バイトのオフセット。 |
| ne_swaparea | WORD | 2 | +60 | +60 | 最小コードスワップ領域のサイズ。 |
| ne_expver | WORD | 2 | +62 | +62 | 想定するWindowsのバージョン。 |
各言語での定義
#include <windows.h>
// IMAGE_OS2_HEADER (x64 64 / x86 64 バイト)
#pragma pack(push, 2)
typedef struct IMAGE_OS2_HEADER {
WORD ne_magic;
CHAR ne_ver;
CHAR ne_rev;
WORD ne_enttab;
WORD ne_cbenttab;
INT ne_crc;
WORD ne_flags;
WORD ne_autodata;
WORD ne_heap;
WORD ne_stack;
INT ne_csip;
INT ne_sssp;
WORD ne_cseg;
WORD ne_cmod;
WORD ne_cbnrestab;
WORD ne_segtab;
WORD ne_rsrctab;
WORD ne_restab;
WORD ne_modtab;
WORD ne_imptab;
INT ne_nrestab;
WORD ne_cmovent;
WORD ne_align;
WORD ne_cres;
BYTE ne_exetyp;
BYTE ne_flagsothers;
WORD ne_pretthunks;
WORD ne_psegrefbytes;
WORD ne_swaparea;
WORD ne_expver;
} IMAGE_OS2_HEADER;
#pragma pack(pop)using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 2, CharSet = CharSet.Unicode)]
public struct IMAGE_OS2_HEADER
{
public ushort ne_magic;
public sbyte ne_ver;
public sbyte ne_rev;
public ushort ne_enttab;
public ushort ne_cbenttab;
public int ne_crc;
public ushort ne_flags;
public ushort ne_autodata;
public ushort ne_heap;
public ushort ne_stack;
public int ne_csip;
public int ne_sssp;
public ushort ne_cseg;
public ushort ne_cmod;
public ushort ne_cbnrestab;
public ushort ne_segtab;
public ushort ne_rsrctab;
public ushort ne_restab;
public ushort ne_modtab;
public ushort ne_imptab;
public int ne_nrestab;
public ushort ne_cmovent;
public ushort ne_align;
public ushort ne_cres;
public byte ne_exetyp;
public byte ne_flagsothers;
public ushort ne_pretthunks;
public ushort ne_psegrefbytes;
public ushort ne_swaparea;
public ushort ne_expver;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Unicode)>
Public Structure IMAGE_OS2_HEADER
Public ne_magic As UShort
Public ne_ver As SByte
Public ne_rev As SByte
Public ne_enttab As UShort
Public ne_cbenttab As UShort
Public ne_crc As Integer
Public ne_flags As UShort
Public ne_autodata As UShort
Public ne_heap As UShort
Public ne_stack As UShort
Public ne_csip As Integer
Public ne_sssp As Integer
Public ne_cseg As UShort
Public ne_cmod As UShort
Public ne_cbnrestab As UShort
Public ne_segtab As UShort
Public ne_rsrctab As UShort
Public ne_restab As UShort
Public ne_modtab As UShort
Public ne_imptab As UShort
Public ne_nrestab As Integer
Public ne_cmovent As UShort
Public ne_align As UShort
Public ne_cres As UShort
Public ne_exetyp As Byte
Public ne_flagsothers As Byte
Public ne_pretthunks As UShort
Public ne_psegrefbytes As UShort
Public ne_swaparea As UShort
Public ne_expver As UShort
End Structureimport ctypes
from ctypes import wintypes
class IMAGE_OS2_HEADER(ctypes.Structure):
_pack_ = 2
_fields_ = [
("ne_magic", ctypes.c_ushort),
("ne_ver", ctypes.c_byte),
("ne_rev", ctypes.c_byte),
("ne_enttab", ctypes.c_ushort),
("ne_cbenttab", ctypes.c_ushort),
("ne_crc", ctypes.c_int),
("ne_flags", ctypes.c_ushort),
("ne_autodata", ctypes.c_ushort),
("ne_heap", ctypes.c_ushort),
("ne_stack", ctypes.c_ushort),
("ne_csip", ctypes.c_int),
("ne_sssp", ctypes.c_int),
("ne_cseg", ctypes.c_ushort),
("ne_cmod", ctypes.c_ushort),
("ne_cbnrestab", ctypes.c_ushort),
("ne_segtab", ctypes.c_ushort),
("ne_rsrctab", ctypes.c_ushort),
("ne_restab", ctypes.c_ushort),
("ne_modtab", ctypes.c_ushort),
("ne_imptab", ctypes.c_ushort),
("ne_nrestab", ctypes.c_int),
("ne_cmovent", ctypes.c_ushort),
("ne_align", ctypes.c_ushort),
("ne_cres", ctypes.c_ushort),
("ne_exetyp", ctypes.c_ubyte),
("ne_flagsothers", ctypes.c_ubyte),
("ne_pretthunks", ctypes.c_ushort),
("ne_psegrefbytes", ctypes.c_ushort),
("ne_swaparea", ctypes.c_ushort),
("ne_expver", ctypes.c_ushort),
]#[repr(C, packed(2))]
pub struct IMAGE_OS2_HEADER {
pub ne_magic: u16,
pub ne_ver: i8,
pub ne_rev: i8,
pub ne_enttab: u16,
pub ne_cbenttab: u16,
pub ne_crc: i32,
pub ne_flags: u16,
pub ne_autodata: u16,
pub ne_heap: u16,
pub ne_stack: u16,
pub ne_csip: i32,
pub ne_sssp: i32,
pub ne_cseg: u16,
pub ne_cmod: u16,
pub ne_cbnrestab: u16,
pub ne_segtab: u16,
pub ne_rsrctab: u16,
pub ne_restab: u16,
pub ne_modtab: u16,
pub ne_imptab: u16,
pub ne_nrestab: i32,
pub ne_cmovent: u16,
pub ne_align: u16,
pub ne_cres: u16,
pub ne_exetyp: u8,
pub ne_flagsothers: u8,
pub ne_pretthunks: u16,
pub ne_psegrefbytes: u16,
pub ne_swaparea: u16,
pub ne_expver: u16,
}import "golang.org/x/sys/windows"
type IMAGE_OS2_HEADER struct {
ne_magic uint16
ne_ver int8
ne_rev int8
ne_enttab uint16
ne_cbenttab uint16
ne_crc int32
ne_flags uint16
ne_autodata uint16
ne_heap uint16
ne_stack uint16
ne_csip int32
ne_sssp int32
ne_cseg uint16
ne_cmod uint16
ne_cbnrestab uint16
ne_segtab uint16
ne_rsrctab uint16
ne_restab uint16
ne_modtab uint16
ne_imptab uint16
ne_nrestab int32
ne_cmovent uint16
ne_align uint16
ne_cres uint16
ne_exetyp byte
ne_flagsothers byte
ne_pretthunks uint16
ne_psegrefbytes uint16
ne_swaparea uint16
ne_expver uint16
}type
IMAGE_OS2_HEADER = packed record
ne_magic: Word;
ne_ver: Shortint;
ne_rev: Shortint;
ne_enttab: Word;
ne_cbenttab: Word;
ne_crc: Integer;
ne_flags: Word;
ne_autodata: Word;
ne_heap: Word;
ne_stack: Word;
ne_csip: Integer;
ne_sssp: Integer;
ne_cseg: Word;
ne_cmod: Word;
ne_cbnrestab: Word;
ne_segtab: Word;
ne_rsrctab: Word;
ne_restab: Word;
ne_modtab: Word;
ne_imptab: Word;
ne_nrestab: Integer;
ne_cmovent: Word;
ne_align: Word;
ne_cres: Word;
ne_exetyp: Byte;
ne_flagsothers: Byte;
ne_pretthunks: Word;
ne_psegrefbytes: Word;
ne_swaparea: Word;
ne_expver: Word;
end;const IMAGE_OS2_HEADER = extern struct {
ne_magic: u16,
ne_ver: i8,
ne_rev: i8,
ne_enttab: u16,
ne_cbenttab: u16,
ne_crc: i32,
ne_flags: u16,
ne_autodata: u16,
ne_heap: u16,
ne_stack: u16,
ne_csip: i32,
ne_sssp: i32,
ne_cseg: u16,
ne_cmod: u16,
ne_cbnrestab: u16,
ne_segtab: u16,
ne_rsrctab: u16,
ne_restab: u16,
ne_modtab: u16,
ne_imptab: u16,
ne_nrestab: i32,
ne_cmovent: u16,
ne_align: u16,
ne_cres: u16,
ne_exetyp: u8,
ne_flagsothers: u8,
ne_pretthunks: u16,
ne_psegrefbytes: u16,
ne_swaparea: u16,
ne_expver: u16,
};type
IMAGE_OS2_HEADER {.packed.} = object
ne_magic: uint16
ne_ver: int8
ne_rev: int8
ne_enttab: uint16
ne_cbenttab: uint16
ne_crc: int32
ne_flags: uint16
ne_autodata: uint16
ne_heap: uint16
ne_stack: uint16
ne_csip: int32
ne_sssp: int32
ne_cseg: uint16
ne_cmod: uint16
ne_cbnrestab: uint16
ne_segtab: uint16
ne_rsrctab: uint16
ne_restab: uint16
ne_modtab: uint16
ne_imptab: uint16
ne_nrestab: int32
ne_cmovent: uint16
ne_align: uint16
ne_cres: uint16
ne_exetyp: uint8
ne_flagsothers: uint8
ne_pretthunks: uint16
ne_psegrefbytes: uint16
ne_swaparea: uint16
ne_expver: uint16align(2)
struct IMAGE_OS2_HEADER
{
ushort ne_magic;
byte ne_ver;
byte ne_rev;
ushort ne_enttab;
ushort ne_cbenttab;
int ne_crc;
ushort ne_flags;
ushort ne_autodata;
ushort ne_heap;
ushort ne_stack;
int ne_csip;
int ne_sssp;
ushort ne_cseg;
ushort ne_cmod;
ushort ne_cbnrestab;
ushort ne_segtab;
ushort ne_rsrctab;
ushort ne_restab;
ushort ne_modtab;
ushort ne_imptab;
int ne_nrestab;
ushort ne_cmovent;
ushort ne_align;
ushort ne_cres;
ubyte ne_exetyp;
ubyte ne_flagsothers;
ushort ne_pretthunks;
ushort ne_psegrefbytes;
ushort ne_swaparea;
ushort ne_expver;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; IMAGE_OS2_HEADER サイズ: 64 バイト(x64)
dim st, 16 ; 4byte整数×16(構造体サイズ 64 / 4 切り上げ)
; ne_magic : WORD (+0, 2byte) wpoke st,0,値 / 値 = wpeek(st,0)
; ne_ver : CHAR (+2, 1byte) poke st,2,値 / 値 = peek(st,2)
; ne_rev : CHAR (+3, 1byte) poke st,3,値 / 値 = peek(st,3)
; ne_enttab : WORD (+4, 2byte) wpoke st,4,値 / 値 = wpeek(st,4)
; ne_cbenttab : WORD (+6, 2byte) wpoke st,6,値 / 値 = wpeek(st,6)
; ne_crc : INT (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; ne_flags : WORD (+12, 2byte) wpoke st,12,値 / 値 = wpeek(st,12)
; ne_autodata : WORD (+14, 2byte) wpoke st,14,値 / 値 = wpeek(st,14)
; ne_heap : WORD (+16, 2byte) wpoke st,16,値 / 値 = wpeek(st,16)
; ne_stack : WORD (+18, 2byte) wpoke st,18,値 / 値 = wpeek(st,18)
; ne_csip : INT (+20, 4byte) st.5 = 値 / 値 = st.5 (lpoke/lpeek も可)
; ne_sssp : INT (+24, 4byte) st.6 = 値 / 値 = st.6 (lpoke/lpeek も可)
; ne_cseg : WORD (+28, 2byte) wpoke st,28,値 / 値 = wpeek(st,28)
; ne_cmod : WORD (+30, 2byte) wpoke st,30,値 / 値 = wpeek(st,30)
; ne_cbnrestab : WORD (+32, 2byte) wpoke st,32,値 / 値 = wpeek(st,32)
; ne_segtab : WORD (+34, 2byte) wpoke st,34,値 / 値 = wpeek(st,34)
; ne_rsrctab : WORD (+36, 2byte) wpoke st,36,値 / 値 = wpeek(st,36)
; ne_restab : WORD (+38, 2byte) wpoke st,38,値 / 値 = wpeek(st,38)
; ne_modtab : WORD (+40, 2byte) wpoke st,40,値 / 値 = wpeek(st,40)
; ne_imptab : WORD (+42, 2byte) wpoke st,42,値 / 値 = wpeek(st,42)
; ne_nrestab : INT (+44, 4byte) st.11 = 値 / 値 = st.11 (lpoke/lpeek も可)
; ne_cmovent : WORD (+48, 2byte) wpoke st,48,値 / 値 = wpeek(st,48)
; ne_align : WORD (+50, 2byte) wpoke st,50,値 / 値 = wpeek(st,50)
; ne_cres : WORD (+52, 2byte) wpoke st,52,値 / 値 = wpeek(st,52)
; ne_exetyp : BYTE (+54, 1byte) poke st,54,値 / 値 = peek(st,54)
; ne_flagsothers : BYTE (+55, 1byte) poke st,55,値 / 値 = peek(st,55)
; ne_pretthunks : WORD (+56, 2byte) wpoke st,56,値 / 値 = wpeek(st,56)
; ne_psegrefbytes : WORD (+58, 2byte) wpoke st,58,値 / 値 = wpeek(st,58)
; ne_swaparea : WORD (+60, 2byte) wpoke st,60,値 / 値 = wpeek(st,60)
; ne_expver : WORD (+62, 2byte) wpoke st,62,値 / 値 = wpeek(st,62)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global IMAGE_OS2_HEADER, pack=2
#field short ne_magic
#field byte ne_ver
#field byte ne_rev
#field short ne_enttab
#field short ne_cbenttab
#field int ne_crc
#field short ne_flags
#field short ne_autodata
#field short ne_heap
#field short ne_stack
#field int ne_csip
#field int ne_sssp
#field short ne_cseg
#field short ne_cmod
#field short ne_cbnrestab
#field short ne_segtab
#field short ne_rsrctab
#field short ne_restab
#field short ne_modtab
#field short ne_imptab
#field int ne_nrestab
#field short ne_cmovent
#field short ne_align
#field short ne_cres
#field byte ne_exetyp
#field byte ne_flagsothers
#field short ne_pretthunks
#field short ne_psegrefbytes
#field short ne_swaparea
#field short ne_expver
#endstruct
stdim st, IMAGE_OS2_HEADER ; NSTRUCT 変数を確保
st->ne_magic = 100
mes "ne_magic=" + st->ne_magic