7eabbd510648fa8620c82997c980e9675503a0ef
[reactos.git] / rosapps / sysutils / chklib.c
1 /* $Id: chklib.c,v 1.1 1999/05/16 07:27:35 ea Exp $
2 *
3 * chklib.c
4 *
5 * Copyright (C) 1998, 1999 Emanuele Aliberti.
6 *
7 * --------------------------------------------------------------------
8 *
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this software; see the file COPYING.LIB. If
21 * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
22 * Cambridge, MA 02139, USA.
23 *
24 * --------------------------------------------------------------------
25 * Check a PE DLL for loading and get an exported symbol's address
26 * (relocated).
27 *
28 */
29 //#define UNICODE
30 #include <windows.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <assert.h>
34 #include "win32err.h"
35
36 #ifdef DISPLAY_VERSION
37 static
38 void
39 DisplayVersion(
40 HANDLE dll,
41 PCHAR ModuleName
42 )
43 {
44 DWORD Zero;
45 DWORD Size;
46 PVOID vi = NULL;
47
48 assert(ModuleName);
49 Size = GetFileVersionInfoSize(
50 ModuleName,
51 & Zero
52 );
53 if (Size == 0)
54 {
55 PrintWin32Error(
56 L"GetFileVersionInfoSize",
57 GetLastError()
58 );
59 return;
60 }
61 vi = (PVOID) LocalAlloc(LMEM_ZEROINIT,Size);
62 if (!vi) return;
63 assert(dll != INVALID_HANDLE_VALUE);
64 if (0 == GetFileVersionInfo(
65 ModuleName,
66 (DWORD) dll,
67 Size,
68 vi
69 )
70 ) {
71 PrintWin32Error(
72 L"GetFileVersionInfo",
73 GetLastError()
74 );
75 return;
76 }
77 /*
78 VerQueryValue(
79 vi,
80 L"\\StringFileInfo\\040904E4\\FileDescription",
81 & lpBuffer,
82 & dwBytes
83 );
84 */
85 LocalFree(vi);
86 }
87 #endif /* def DISPLAY_VERSION */
88
89
90 static
91 void
92 DisplayEntryPoint(
93 const HANDLE dll,
94 LPCSTR SymbolName
95 )
96 {
97 FARPROC EntryPoint;
98
99 printf(
100 "[%s]\n",
101 SymbolName
102 );
103 EntryPoint = GetProcAddress(
104 dll,
105 SymbolName
106 );
107 if (!EntryPoint)
108 {
109 PrintWin32Error(
110 L"GetProcAddress",
111 GetLastError()
112 );
113 return;
114 }
115 printf(
116 "%08X %s\n",
117 EntryPoint,
118 SymbolName
119 );
120 }
121
122
123 /* --- MAIN --- */
124
125
126 int
127 main(
128 int argc,
129 char * argv []
130 )
131 {
132 HINSTANCE dll;
133 TCHAR ModuleName [_MAX_PATH];
134
135 if (argc != 2 && argc != 3)
136 {
137 fprintf(
138 stderr,
139 "\
140 ReactOS System Tools\n\
141 Check a Dynamic Link Library (DLL) for loading\n\
142 Copyright (c) 1998, 1999 Emanuele Aliberti\n\n\
143 usage: %s module [symbol]\n",
144 argv[0]
145 );
146 exit(EXIT_FAILURE);
147 }
148 dll = LoadLibraryA(argv[1]);
149 if (!dll)
150 {
151 UINT LastError;
152
153 LastError = GetLastError();
154 PrintWin32Error(L"LoadLibrary",LastError);
155 fprintf(
156 stderr,
157 "%s: loading %s failed (%d).\n",
158 argv[0],
159 argv[1],
160 LastError
161 );
162 exit(EXIT_FAILURE);
163 }
164 GetModuleFileName(
165 (HANDLE) dll,
166 ModuleName,
167 sizeof ModuleName
168 );
169 printf(
170 "%s loaded.\n",
171 ModuleName
172 );
173 #ifdef DISPLAY_VERSION
174 DisplayVersion(dll,ModuleName);
175 #endif
176 if (argc == 3) DisplayEntryPoint( dll, argv[2] );
177 FreeLibrary(dll);
178 printf(
179 "%s unloaded.\n",
180 ModuleName
181 );
182 return EXIT_SUCCESS;
183 }
184
185 /* EOF */