ReactOS  0.4.12-dev-418-g3df31a8
chklib.c
Go to the documentation of this file.
1 /*
2  * chklib.c
3  *
4  * Copyright (C) 1998, 1999 Emanuele Aliberti.
5  *
6  * --------------------------------------------------------------------
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This software is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this software; see the file COPYING. If
20  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
21  * Cambridge, MA 02139, USA.
22  *
23  * --------------------------------------------------------------------
24  * Check a PE DLL for loading and get an exported symbol's address
25  * (relocated).
26  *
27  */
28 //#define UNICODE
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <assert.h>
32 
33 #include <stdarg.h>
34 #include <windef.h>
35 #include <winbase.h>
36 
37 #include "../win32err.h"
38 
39 #ifdef DISPLAY_VERSION
40 static
41 void
42 DisplayVersion(
43  HANDLE dll,
45  )
46 {
47  DWORD Zero;
48  DWORD Size;
49  PVOID vi = NULL;
50 
53  ModuleName,
54  & Zero
55  );
56  if (Size == 0)
57  {
59  L"GetFileVersionInfoSize",
60  GetLastError()
61  );
62  return;
63  }
65  if (!vi) return;
67  if (0 == GetFileVersionInfo(
68  ModuleName,
69  (DWORD) dll,
70  Size,
71  vi
72  )
73  ) {
75  L"GetFileVersionInfo",
76  GetLastError()
77  );
78  return;
79  }
80 /*
81  VerQueryValue(
82  vi,
83  L"\\StringFileInfo\\040904E4\\FileDescription",
84  & lpBuffer,
85  & dwBytes
86  );
87 */
88  LocalFree(vi);
89 }
90 #endif /* def DISPLAY_VERSION */
91 
92 
93 static
94 void
96  const HANDLE dll,
97  LPCSTR SymbolName
98  )
99 {
100  FARPROC EntryPoint;
101 
102  printf(
103  "[%s]\n",
104  SymbolName
105  );
106  EntryPoint = GetProcAddress(
107  dll,
108  SymbolName
109  );
110  if (!EntryPoint)
111  {
113  L"GetProcAddress",
114  GetLastError()
115  );
116  return;
117  }
118  printf(
119  "0x%p %s\n",
120  EntryPoint,
121  SymbolName
122  );
123 }
124 
125 
126 /* --- MAIN --- */
127 
128 
129 int
131  int argc,
132  char * argv []
133  )
134 {
135  HINSTANCE dll;
137 
138  if (argc < 2)
139  {
140  fprintf(
141  stderr,
142  "\
143 ReactOS System Tools\n\
144 Check a Dynamic Link Library (DLL) for loading\n\
145 Copyright (c) 1998, 1999 Emanuele Aliberti\n\n\
146 usage: %s module [symbol [, ...]]\n",
147  argv[0]
148  );
150  }
151  dll = LoadLibraryA(argv[1]);
152  if (!dll)
153  {
154  UINT LastError;
155 
156  LastError = GetLastError();
157  PrintWin32Error(L"LoadLibrary",LastError);
158  fprintf(
159  stderr,
160  "%s: loading %s failed (%d).\n",
161  argv[0],
162  argv[1],
163  LastError
164  );
166  }
168  (HANDLE) dll,
169  ModuleName,
170  sizeof ModuleName
171  );
172  printf(
173  "%s loaded.\n",
174  ModuleName
175  );
176 #ifdef DISPLAY_VERSION
177  DisplayVersion(dll,ModuleName);
178 #endif
179  if (argc > 2)
180  {
181  int CurrentSymbol;
182 
183  for ( CurrentSymbol = 2;
184  (CurrentSymbol < argc);
185  ++CurrentSymbol
186  )
187  {
188  DisplayEntryPoint( dll, argv[CurrentSymbol] );
189  }
190  }
191  FreeLibrary(dll);
192  printf(
193  "%s unloaded.\n",
194  ModuleName
195  );
196  return EXIT_SUCCESS;
197 }
198 
199 /* EOF */
#define GetFileVersionInfo
Definition: winver.h:54
signed char * PCHAR
Definition: retypes.h:7
static int argc
Definition: ServiceArgs.c:12
#define GetFileVersionInfoSize
Definition: winver.h:53
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define assert(x)
Definition: debug.h:53
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
struct msdos_volume_info vi
Definition: mkdosfs.c:435
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1260
#define argv
Definition: mplay32.c:18
static HMODULE dll
Definition: str.c:188
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
VOID PrintWin32Error(IN LPWSTR Message, IN DWORD ErrorCode)
Definition: main.c:146
#define _MAX_PATH
Definition: utility.h:77
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
smooth NULL
Definition: ftsmooth.c:416
const char * LPCSTR
Definition: xmlstorage.h:183
void * PVOID
Definition: retypes.h:9
char TCHAR
Definition: xmlstorage.h:189
#define FreeLibrary(x)
Definition: compat.h:405
#define LMEM_ZEROINIT
Definition: winbase.h:356
unsigned int UINT
Definition: ndis.h:50
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXIT_FAILURE
Definition: jerror.c:33
#define GetModuleFileName
Definition: winbase.h:3645
static const WCHAR L[]
Definition: oid.c:1087
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:402
static void DisplayEntryPoint(const HANDLE dll, LPCSTR SymbolName)
Definition: chklib.c:95
FILE * stderr
#define GetProcAddress(x, y)
Definition: compat.h:410
int main(int argc, char *argv [])
Definition: chklib.c:130
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
void exit(int exitcode)
Definition: _exit.c:33
int(* FARPROC)()
Definition: compat.h:28
#define printf
Definition: config.h:203