Added entry for DirectSoundFullDuplexCreate.
[wine] / tools / winedump / ne.c
1 /*
2  * Dumping of NE binaries
3  *
4  * Copyright 2002 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <fcntl.h>
22 #include <stdio.h>
23 #include <unistd.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wine/winbase16.h"
28 #include "winedump.h"
29
30 static void dump_ne_header( const IMAGE_OS2_HEADER *ne )
31 {
32     printf( "File header:\n" );
33     printf( "Linker version:      %d.%d\n", ne->ne_ver, ne->ne_rev );
34     printf( "Entry table:         %x len %d\n", ne->ne_enttab, ne->ne_cbenttab );
35     printf( "Checksum:            %08lx\n", ne->ne_crc );
36     printf( "Flags:               %04x\n", ne->ne_flags );
37     printf( "Auto data segment:   %x\n", ne->ne_autodata );
38     printf( "Heap size:           %d bytes\n", ne->ne_heap );
39     printf( "Stack size:          %d bytes\n", ne->ne_stack );
40     printf( "Stack pointer:       %x:%04x\n", SELECTOROF(ne->ne_sssp), OFFSETOF(ne->ne_sssp) );
41     printf( "Entry point:         %x:%04x\n", SELECTOROF(ne->ne_csip), OFFSETOF(ne->ne_csip) );
42     printf( "Number of segments:  %d\n", ne->ne_cseg );
43     printf( "Number of modrefs:   %d\n", ne->ne_cmod );
44     printf( "Segment table:       %x\n", ne->ne_segtab );
45     printf( "Resource table:      %x\n", ne->ne_rsrctab );
46     printf( "Resident name table: %x\n", ne->ne_restab );
47     printf( "Module table:        %x\n", ne->ne_modtab );
48     printf( "Import table:        %x\n", ne->ne_imptab );
49     printf( "Non-resident table:  %lx\n", ne->ne_nrestab );
50     printf( "Exe type:            %x\n", ne->ne_exetyp );
51     printf( "Other flags:         %x\n", ne->ne_flagsothers );
52     printf( "Fast load area:      %x-%x\n", ne->ne_pretthunks << ne->ne_align,
53             (ne->ne_pretthunks+ne->ne_psegrefbytes) << ne->ne_align );
54     printf( "Expected version:    %d.%d\n", HIBYTE(ne->ne_expver), LOBYTE(ne->ne_expver) );
55 }
56
57 static const char *get_resource_type( WORD id )
58 {
59     static char buffer[5];
60     switch(id)
61     {
62     case NE_RSCTYPE_CURSOR: return "CURSOR";
63     case NE_RSCTYPE_BITMAP: return "BITMAP";
64     case NE_RSCTYPE_ICON: return "ICON";
65     case NE_RSCTYPE_MENU: return "MENU";
66     case NE_RSCTYPE_DIALOG: return "DIALOG";
67     case NE_RSCTYPE_STRING: return "STRING";
68     case NE_RSCTYPE_FONTDIR: return "FONTDIR";
69     case NE_RSCTYPE_FONT: return "FONT";
70     case NE_RSCTYPE_ACCELERATOR: return "ACCELERATOR";
71     case NE_RSCTYPE_RCDATA: return "RCDATA";
72     case NE_RSCTYPE_GROUP_CURSOR: return "CURSOR_GROUP";
73     case NE_RSCTYPE_GROUP_ICON: return "ICON_GROUP";
74     default:
75         sprintf( buffer, "%04x", id );
76         return buffer;
77     }
78 }
79
80 static void dump_ne_resources( const void *base, const IMAGE_OS2_HEADER *ne )
81 {
82     NE_NAMEINFO *name;
83     const void *res_ptr = (char *)ne + ne->ne_rsrctab;
84     WORD size_shift = *(WORD *)res_ptr;
85     NE_TYPEINFO *info = (NE_TYPEINFO *)((WORD *)res_ptr + 1);
86     int count;
87
88     printf( "\nResources:\n" );
89     while (info->type_id != 0 && (char *)info < (char *)ne + ne->ne_restab)
90     {
91         name = (NE_NAMEINFO *)(info + 1);
92         for (count = info->count; count > 0; count--, name++)
93         {
94             if (name->id & 0x8000) printf( "  %d", (name->id & ~0x8000) );
95             else printf( "  %.*s", *((unsigned char *)res_ptr + name->id),
96                          (char *)res_ptr + name->id + 1 );
97             if (info->type_id & 0x8000) printf( " %s\n", get_resource_type(info->type_id) );
98             else printf( " %.*s\n", *((unsigned char *)res_ptr + info->type_id),
99                          (char *)res_ptr + info->type_id + 1 );
100             dump_data( (unsigned char *)base + (name->offset << size_shift),
101                        name->length << size_shift, "    " );
102         }
103         info = (NE_TYPEINFO *)name;
104     }
105 }
106
107 void ne_dump( const void *exe, size_t exe_size )
108 {
109     const IMAGE_DOS_HEADER *dos = exe;
110     const IMAGE_OS2_HEADER *ne = (IMAGE_OS2_HEADER *)((char *)dos + dos->e_lfanew);
111
112     dump_ne_header( ne );
113     dump_ne_resources( exe, ne );
114 }