/* Layout of a MS-Windows executable.

   Corey Minyard
   minyard@wf-rch.cirr.com
*/

#define EXE_SIG		0x5a4d
#define IDENT_MIN_MSW	0x40
struct s_exe_header
{
	WORD	sig;
	BYTE	dummy1[22];
	WORD	ident;
	BYTE	dummy2[34];
	WORD	msw_header_off;
};
	
#define INFO_SIG	0x454e
struct s_info_block
{
	WORD	sig;
	BYTE	link_version;
	BYTE	link_revision;
	WORD	entry_table_off;
	WORD	entry_table_length;
	WORD	reserved1[2];
	WORD	exe_flags;
	WORD	auto_ds_num;
	WORD	init_heap_size;
	WORD	init_stack_size;
	WORD	init_ip;
	WORD	init_cs_segment;
	WORD	init_sp;
	WORD	init_ss_segment;
	WORD	num_seg_table_entries;
	WORD	num_mod_ref_entries;
	WORD	num_nonres_name_entries;
	WORD	seg_table_off;
	WORD	resource_table_off;
	WORD	res_name_table_off;
	WORD	mod_ref_table_off;
	WORD	imported_name_table_off;
	DWORD	nonres_name_table_off;
	WORD	num_movable_entry_points;
	WORD	log_sector_size_log2;
	WORD	num_resource_seg;
	BYTE	target_os;
	BYTE	additional_exe_info;
	WORD	fast_load_offset;
	WORD	fast_load_size;
	WORD	reserved2;
	WORD	win_version;
};

#define MOVABLE_SEG	0xff
#define CONST_ENTRY	0xfe
struct s_bundle_data
{
	BYTE	num_entries;
	BYTE	type;
};

struct s_entry_table_movable
{
	BYTE	flags;
	BYTE	int3f[2];
	BYTE	seg_num;
	WORD	seg_off;
};

struct s_entry_table_fixed
{
	BYTE	flags;
	BYTE	seg_off[2];
};

struct s_entry_table_const
{
	BYTE	data[3];
};


#define ST_DATASEG	0x0001
#define ST_MEMALLOCED	0x0002
#define ST_SEGLOADED	0x0004
#define ST_MOVABLE	0x0010
#define ST_PURE		0x0020
#define ST_PRELOAD	0x0040
#define ST_RESTRICT	0x0080
#define	ST_RELOCATE	0x0100
#define ST_DISCARDABLE	0x1000

struct s_segment_table
{
	WORD	seg_start_off;
	WORD	seg_length;
	WORD	flags;
	WORD	min_alloc_size;
};

struct s_nameinfo
{
	WORD	offset;
	WORD	length;
	WORD	flags;
	WORD	id;
	WORD	handle;
	WORD	usage;
};

struct s_typeinfo
{
	WORD	typeid;
	WORD	resourcecount;
	DWORD	reserved;
	struct s_nameinfo nameinfo[1];
};

struct s_reloc_data
{
	BYTE	addr_type;
	BYTE	reloc_type;
	WORD	offset;
	WORD	ref;
	WORD	value;
};
