Win32 API 日本語リファレンス
ホームSystem.SystemServices › IMAGE_OS2_HEADER

IMAGE_OS2_HEADER

構造体
サイズx64: 64 バイト / x86: 64 バイトパッキング2

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
ne_magicWORD2+0+0NEヘッダーのマジック値。'NE'を示す。
ne_verCHAR1+2+2リンカのメジャーバージョン番号。
ne_revCHAR1+3+3リンカのマイナーバージョン番号。
ne_enttabWORD2+4+4エントリテーブルのオフセット。
ne_cbenttabWORD2+6+6エントリテーブルのバイトサイズ。
ne_crcINT4+8+8ファイル全体のCRC32チェックサム。
ne_flagsWORD2+12+12モジュール属性のフラグ。
ne_autodataWORD2+14+14自動データセグメント番号。
ne_heapWORD2+16+16ローカルヒープの初期サイズ。
ne_stackWORD2+18+18スタックの初期サイズ。
ne_csipINT4+20+20初期CS:IP値。
ne_ssspINT4+24+24初期SS:SP値。
ne_csegWORD2+28+28セグメントテーブルのエントリ数。
ne_cmodWORD2+30+30モジュール参照テーブルのエントリ数。
ne_cbnrestabWORD2+32+32非常駐名テーブルのバイトサイズ。
ne_segtabWORD2+34+34セグメントテーブルのオフセット。
ne_rsrctabWORD2+36+36リソーステーブルのオフセット。
ne_restabWORD2+38+38常駐名テーブルのオフセット。
ne_modtabWORD2+40+40モジュール参照テーブルのオフセット。
ne_imptabWORD2+42+42インポート名テーブルのオフセット。
ne_nrestabINT4+44+44非常駐名テーブルのファイルオフセット。
ne_cmoventWORD2+48+48移動可能エントリポイント数。
ne_alignWORD2+50+50セグメントアライメントのシフト量(2の対数)。
ne_cresWORD2+52+52リソースセグメント数。
ne_exetypBYTE1+54+54対象OSの種別(実行可能形式)。
ne_flagsothersBYTE1+55+55その他のEXE属性フラグ。
ne_pretthunksWORD2+56+56リターンスランクのオフセット。
ne_psegrefbytesWORD2+58+58セグメント参照バイトのオフセット。
ne_swapareaWORD2+60+60最小コードスワップ領域のサイズ。
ne_expverWORD2+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 Structure
import 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: uint16
align(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