ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

access.c
Go to the documentation of this file.
00001 /*
00002  *  IMAGEHLP library
00003  *
00004  *  Copyright 1998  Patrik Stridvall
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <stdarg.h>
00022 #include <string.h>
00023 #include "windef.h"
00024 #include "winbase.h"
00025 #include "winnt.h"
00026 #include "winternl.h"
00027 #include "winerror.h"
00028 #include "wine/debug.h"
00029 #include "imagehlp.h"
00030 
00031 WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
00032 
00033 /***********************************************************************
00034  *           Data
00035  */
00036 
00037 static PLOADED_IMAGE IMAGEHLP_pFirstLoadedImage=NULL;
00038 static PLOADED_IMAGE IMAGEHLP_pLastLoadedImage=NULL;
00039 
00040 static LOADED_IMAGE IMAGEHLP_EmptyLoadedImage = {
00041   NULL,       /* ModuleName */
00042   0,          /* hFile */
00043   NULL,       /* MappedAddress */
00044   NULL,       /* FileHeader */
00045   NULL,       /* LastRvaSection */
00046   0,          /* NumberOfSections */
00047   NULL,       /* Sections */
00048   1,          /* Characteristics */
00049   FALSE,      /* fSystemImage */
00050   FALSE,      /* fDOSImage */
00051   FALSE,      /* fReadOnly */
00052   0,          /* Version */
00053   { &IMAGEHLP_EmptyLoadedImage.Links, &IMAGEHLP_EmptyLoadedImage.Links }, /* Links */
00054   148,        /* SizeOfImage; */
00055 };
00056 
00057 DECLSPEC_HIDDEN extern HANDLE IMAGEHLP_hHeap;
00058 
00059 /***********************************************************************
00060  *      GetImageConfigInformation (IMAGEHLP.@)
00061  */
00062 BOOL WINAPI GetImageConfigInformation(
00063   PLOADED_IMAGE LoadedImage,
00064   PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
00065 {
00066   FIXME("(%p, %p): stub\n",
00067     LoadedImage, ImageConfigInformation
00068   );
00069   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
00070   return FALSE;
00071 }
00072 
00073 /***********************************************************************
00074  *      GetImageUnusedHeaderBytes (IMAGEHLP.@)
00075  */
00076 DWORD WINAPI GetImageUnusedHeaderBytes(
00077   PLOADED_IMAGE LoadedImage,
00078   LPDWORD SizeUnusedHeaderBytes)
00079 {
00080   FIXME("(%p, %p): stub\n",
00081     LoadedImage, SizeUnusedHeaderBytes
00082   );
00083   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
00084   return 0;
00085 }
00086 
00087 /***********************************************************************
00088  *      ImageLoad (IMAGEHLP.@)
00089  */
00090 PLOADED_IMAGE WINAPI ImageLoad(PCSTR DllName, PCSTR DllPath)
00091 {
00092   PLOADED_IMAGE pLoadedImage;
00093 
00094   FIXME("(%s, %s): stub\n", DllName, DllPath);
00095       
00096   pLoadedImage = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE));
00097   if (pLoadedImage)
00098     pLoadedImage->FileHeader = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(IMAGE_NT_HEADERS));
00099   
00100   return pLoadedImage;
00101 }
00102 
00103 /***********************************************************************
00104  *      ImageUnload (IMAGEHLP.@)
00105  */
00106 BOOL WINAPI ImageUnload(PLOADED_IMAGE pLoadedImage)
00107 {
00108   LIST_ENTRY *pCurrent, *pFind;
00109 
00110   TRACE("(%p)\n", pLoadedImage);
00111   
00112   if(!IMAGEHLP_pFirstLoadedImage || !pLoadedImage)
00113     {
00114       /* No image loaded or null pointer */
00115       SetLastError(ERROR_INVALID_PARAMETER);
00116       return FALSE;
00117     }
00118 
00119   pFind=&pLoadedImage->Links;
00120   pCurrent=&IMAGEHLP_pFirstLoadedImage->Links;
00121   while((pCurrent != pFind) &&
00122     (pCurrent != NULL))
00123       pCurrent = pCurrent->Flink;
00124   if(!pCurrent)
00125     {
00126       /* Not found */
00127       SetLastError(ERROR_INVALID_PARAMETER);
00128       return FALSE;
00129     }
00130 
00131   if(pCurrent->Blink)
00132     pCurrent->Blink->Flink = pCurrent->Flink;
00133   else
00134     IMAGEHLP_pFirstLoadedImage = pCurrent->Flink?CONTAINING_RECORD(
00135       pCurrent->Flink, LOADED_IMAGE, Links):NULL;
00136 
00137   if(pCurrent->Flink)
00138     pCurrent->Flink->Blink = pCurrent->Blink;
00139   else
00140     IMAGEHLP_pLastLoadedImage = pCurrent->Blink?CONTAINING_RECORD(
00141       pCurrent->Blink, LOADED_IMAGE, Links):NULL;
00142 
00143   return FALSE;
00144 }
00145 
00146 /***********************************************************************
00147  *      MapAndLoad (IMAGEHLP.@)
00148  */
00149 BOOL WINAPI MapAndLoad(PCSTR pszImageName, PCSTR pszDllPath, PLOADED_IMAGE pLoadedImage,
00150                        BOOL bDotDll, BOOL bReadOnly)
00151 {
00152     CHAR szFileName[MAX_PATH];
00153     HANDLE hFile = INVALID_HANDLE_VALUE;
00154     HANDLE hFileMapping = NULL;
00155     PVOID mapping = NULL;
00156     PIMAGE_NT_HEADERS pNtHeader = NULL;
00157 
00158     TRACE("(%s, %s, %p, %d, %d)\n",
00159           pszImageName, pszDllPath, pLoadedImage, bDotDll, bReadOnly);
00160 
00161     if (!SearchPathA(pszDllPath, pszImageName, bDotDll ? ".DLL" : ".EXE",
00162                      sizeof(szFileName), szFileName, NULL))
00163     {
00164         SetLastError(ERROR_FILE_NOT_FOUND);
00165         goto Error;
00166     }
00167 
00168     hFile = CreateFileA(szFileName,
00169                         GENERIC_READ | (bReadOnly ? 0 : GENERIC_WRITE),
00170                         FILE_SHARE_READ,
00171                         NULL, OPEN_EXISTING, 0, NULL);
00172     if (hFile == INVALID_HANDLE_VALUE)
00173     {
00174         WARN("CreateFile: Error = %d\n", GetLastError());
00175         goto Error;
00176     }
00177 
00178     hFileMapping = CreateFileMappingA(hFile, NULL, 
00179                                       (bReadOnly ? PAGE_READONLY : PAGE_READWRITE) | SEC_COMMIT,
00180                                       0, 0, NULL);
00181     if (!hFileMapping)
00182     {
00183         WARN("CreateFileMapping: Error = %d\n", GetLastError());
00184         goto Error;
00185     }
00186 
00187     mapping = MapViewOfFile(hFileMapping, bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, 0, 0);
00188     CloseHandle(hFileMapping);
00189     if (!mapping)
00190     {
00191         WARN("MapViewOfFile: Error = %d\n", GetLastError());
00192         goto Error;
00193     }
00194 
00195     if (!(pNtHeader = RtlImageNtHeader(mapping)))
00196     {
00197         WARN("Not an NT header\n");
00198         UnmapViewOfFile(mapping);
00199         goto Error;
00200     }
00201 
00202     pLoadedImage->ModuleName       = HeapAlloc(GetProcessHeap(), 0,
00203                                                strlen(szFileName) + 1);
00204     if (pLoadedImage->ModuleName) strcpy(pLoadedImage->ModuleName, szFileName);
00205     pLoadedImage->hFile            = hFile;
00206     pLoadedImage->MappedAddress    = mapping;
00207     pLoadedImage->FileHeader       = pNtHeader;
00208     pLoadedImage->Sections         = (PIMAGE_SECTION_HEADER)
00209         ((LPBYTE) &pNtHeader->OptionalHeader +
00210          pNtHeader->FileHeader.SizeOfOptionalHeader);
00211     pLoadedImage->NumberOfSections = pNtHeader->FileHeader.NumberOfSections;
00212     pLoadedImage->SizeOfImage      = GetFileSize(hFile, NULL);
00213     pLoadedImage->Characteristics  = pNtHeader->FileHeader.Characteristics;
00214     pLoadedImage->LastRvaSection   = pLoadedImage->Sections;
00215 
00216     pLoadedImage->fSystemImage     = FALSE; /* FIXME */
00217     pLoadedImage->fDOSImage        = FALSE; /* FIXME */
00218 
00219     pLoadedImage->Links.Flink      = &pLoadedImage->Links;
00220     pLoadedImage->Links.Blink      = &pLoadedImage->Links;
00221 
00222     return TRUE;
00223 
00224 Error:
00225     if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
00226     return FALSE;
00227 }
00228 
00229 /***********************************************************************
00230  *      SetImageConfigInformation (IMAGEHLP.@)
00231  */
00232 BOOL WINAPI SetImageConfigInformation(
00233   PLOADED_IMAGE LoadedImage,
00234   PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
00235 {
00236   FIXME("(%p, %p): stub\n",
00237     LoadedImage, ImageConfigInformation
00238   );
00239   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
00240   return FALSE;
00241 }
00242 
00243 /***********************************************************************
00244  *      UnMapAndLoad (IMAGEHLP.@)
00245  */
00246 BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE pLoadedImage)
00247 {
00248     HeapFree(GetProcessHeap(), 0, pLoadedImage->ModuleName);
00249     /* FIXME: MSDN states that a new checksum is computed and stored into the file */
00250     if (pLoadedImage->MappedAddress) UnmapViewOfFile(pLoadedImage->MappedAddress);
00251     if (pLoadedImage->hFile != INVALID_HANDLE_VALUE) CloseHandle(pLoadedImage->hFile);
00252     return TRUE;
00253 }

Generated on Sun May 27 2012 04:20:49 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.