By default, console handles are inheritable.
[wine.git] / tools / winedump / ne.c
blob0a0e1e12ae0c17811fc77d8ea9fa3626f95fb2b1
1 /*
2 * Dumping of NE binaries
4 * Copyright 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <fcntl.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #ifdef HAVE_UNISTD_H
28 #include <unistd.h>
29 #endif
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wine/winbase16.h"
34 #include "winedump.h"
36 static void dump_ne_header( const IMAGE_OS2_HEADER *ne )
38 printf( "File header:\n" );
39 printf( "Linker version: %d.%d\n", ne->ne_ver, ne->ne_rev );
40 printf( "Entry table: %x len %d\n", ne->ne_enttab, ne->ne_cbenttab );
41 printf( "Checksum: %08lx\n", ne->ne_crc );
42 printf( "Flags: %04x\n", ne->ne_flags );
43 printf( "Auto data segment: %x\n", ne->ne_autodata );
44 printf( "Heap size: %d bytes\n", ne->ne_heap );
45 printf( "Stack size: %d bytes\n", ne->ne_stack );
46 printf( "Stack pointer: %x:%04x\n", SELECTOROF(ne->ne_sssp), OFFSETOF(ne->ne_sssp) );
47 printf( "Entry point: %x:%04x\n", SELECTOROF(ne->ne_csip), OFFSETOF(ne->ne_csip) );
48 printf( "Number of segments: %d\n", ne->ne_cseg );
49 printf( "Number of modrefs: %d\n", ne->ne_cmod );
50 printf( "Segment table: %x\n", ne->ne_segtab );
51 printf( "Resource table: %x\n", ne->ne_rsrctab );
52 printf( "Resident name table: %x\n", ne->ne_restab );
53 printf( "Module table: %x\n", ne->ne_modtab );
54 printf( "Import table: %x\n", ne->ne_imptab );
55 printf( "Non-resident table: %lx\n", ne->ne_nrestab );
56 printf( "Exe type: %x\n", ne->ne_exetyp );
57 printf( "Other flags: %x\n", ne->ne_flagsothers );
58 printf( "Fast load area: %x-%x\n", ne->ne_pretthunks << ne->ne_align,
59 (ne->ne_pretthunks+ne->ne_psegrefbytes) << ne->ne_align );
60 printf( "Expected version: %d.%d\n", HIBYTE(ne->ne_expver), LOBYTE(ne->ne_expver) );
63 static const char *get_resource_type( WORD id )
65 static char buffer[5];
66 switch(id)
68 case NE_RSCTYPE_CURSOR: return "CURSOR";
69 case NE_RSCTYPE_BITMAP: return "BITMAP";
70 case NE_RSCTYPE_ICON: return "ICON";
71 case NE_RSCTYPE_MENU: return "MENU";
72 case NE_RSCTYPE_DIALOG: return "DIALOG";
73 case NE_RSCTYPE_STRING: return "STRING";
74 case NE_RSCTYPE_FONTDIR: return "FONTDIR";
75 case NE_RSCTYPE_FONT: return "FONT";
76 case NE_RSCTYPE_ACCELERATOR: return "ACCELERATOR";
77 case NE_RSCTYPE_RCDATA: return "RCDATA";
78 case NE_RSCTYPE_GROUP_CURSOR: return "CURSOR_GROUP";
79 case NE_RSCTYPE_GROUP_ICON: return "ICON_GROUP";
80 default:
81 sprintf( buffer, "%04x", id );
82 return buffer;
86 static void dump_ne_resources( const void *base, const IMAGE_OS2_HEADER *ne )
88 NE_NAMEINFO *name;
89 const void *res_ptr = (char *)ne + ne->ne_rsrctab;
90 WORD size_shift = *(WORD *)res_ptr;
91 NE_TYPEINFO *info = (NE_TYPEINFO *)((WORD *)res_ptr + 1);
92 int count;
94 printf( "\nResources:\n" );
95 while (info->type_id != 0 && (char *)info < (char *)ne + ne->ne_restab)
97 name = (NE_NAMEINFO *)(info + 1);
98 for (count = info->count; count > 0; count--, name++)
100 if (name->id & 0x8000) printf( " %d", (name->id & ~0x8000) );
101 else printf( " %.*s", *((unsigned char *)res_ptr + name->id),
102 (char *)res_ptr + name->id + 1 );
103 if (info->type_id & 0x8000) printf( " %s\n", get_resource_type(info->type_id) );
104 else printf( " %.*s\n", *((unsigned char *)res_ptr + info->type_id),
105 (char *)res_ptr + info->type_id + 1 );
106 dump_data( (unsigned char *)base + (name->offset << size_shift),
107 name->length << size_shift, " " );
109 info = (NE_TYPEINFO *)name;
113 void ne_dump( const void *exe, size_t exe_size )
115 const IMAGE_DOS_HEADER *dos = exe;
116 const IMAGE_OS2_HEADER *ne = (IMAGE_OS2_HEADER *)((char *)dos + dos->e_lfanew);
118 dump_ne_header( ne );
119 dump_ne_resources( exe, ne );