Changeset 1410 for trunk/src


Ignore:
Timestamp:
Oct 23, 1999, 2:34:48 PM (26 years ago)
Author:
sandervl
Message:

Changes for logging & getversionsize/struct

Location:
trunk/src/kernel32
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/directory.cpp

    r1370 r1410  
    1 /* $Id: directory.cpp,v 1.6 1999-10-20 08:09:04 sandervl Exp $ */
     1/* $Id: directory.cpp,v 1.7 1999-10-23 12:34:46 sandervl Exp $ */
    22
    33/*
     
    2323#include <heapstring.h>
    2424#include <options.h>
    25 
     25#include "initterm.h"
    2626
    2727ODINDEBUGCHANNEL(KERNEL32-DIRECTORY)
     
    175175{
    176176  LPSTR lpstrEnv = getenv("WIN32.DIR.SYSTEM");          /* query environment */
     177
     178  if (lpstrEnv != NULL)
     179  {
     180    lstrcpynA(lpBuffer,                   /* copy environment variable to buffer */
     181              lpstrEnv,
     182              uSize);
     183    return (lstrlenA(lpBuffer));                /* return number of copies bytes */
     184  }
     185  else
     186  {
     187    int len;
     188
     189    len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"SYSTEM","",lpBuffer,uSize);
     190    if (len > 2) {
     191        return len;
     192    }
     193    else {//SvL: Use path of kernel32.dll instead of calling Open32 api (which returns \OS2\SYSTEM)
     194        lstrcpynA(lpBuffer, kernel32Path, uSize);
     195        return lstrlenA(lpBuffer);
     196    }
     197  }
     198}
     199
     200
     201/*****************************************************************************
     202 * Name      : GetSystemDirectoryW
     203 * Purpose   :
     204 * Parameters:
     205 * Variables :
     206 * Result    :
     207 * Remark    :
     208 * Status    :
     209 *
     210 * Author    : Patrick Haller [Wed, 1999/09/28 20:44]
     211 *****************************************************************************/
     212
     213ODINFUNCTION2(UINT,GetSystemDirectoryW,LPWSTR,lpBuffer,
     214                                       UINT,  uSize)
     215{
     216  char *asciibuffer = (char *)malloc(uSize+1);
     217  UINT  rc;
     218
     219  rc = GetSystemDirectoryA(asciibuffer, uSize);
     220  if(rc) AsciiToUnicode(asciibuffer, lpBuffer);
     221  free(asciibuffer);
     222  return(rc);
     223}
     224
     225
     226/*****************************************************************************
     227 * Name      : GetWindowsDirectoryA
     228 * Purpose   :
     229 * Parameters:
     230 * Variables :
     231 * Result    :
     232 * Remark    :
     233 * Status    :
     234 *
     235 * Author    : Patrick Haller [Wed, 1999/09/28 20:44]
     236 *****************************************************************************/
     237
     238ODINFUNCTION2(UINT,GetWindowsDirectoryA,LPSTR,lpBuffer,
     239                                        UINT,uSize)
     240{
     241  LPSTR lpstrEnv = getenv("WIN32.DIR.WINDOWS");         /* query environment */
    177242
    178243  if (lpstrEnv != NULL)
     
    186251    int len;
    187252
    188     len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"SYSTEM","",lpBuffer,uSize);
    189     if (len > 2) return len;
    190     else
    191                                /* if no override by environment is available */
    192       return O32_GetSystemDirectory(lpBuffer,uSize);
    193   }
    194 }
    195 
    196 
    197 /*****************************************************************************
    198  * Name      : GetSystemDirectoryW
    199  * Purpose   :
    200  * Parameters:
    201  * Variables :
    202  * Result    :
    203  * Remark    :
    204  * Status    :
    205  *
    206  * Author    : Patrick Haller [Wed, 1999/09/28 20:44]
    207  *****************************************************************************/
    208 
    209 ODINFUNCTION2(UINT,GetSystemDirectoryW,LPWSTR,lpBuffer,
    210                                        UINT,  uSize)
    211 {
    212   char *asciibuffer = (char *)malloc(uSize+1);
    213   UINT  rc;
    214 
    215   rc = GetSystemDirectoryA(asciibuffer, uSize);
    216   if(rc) AsciiToUnicode(asciibuffer, lpBuffer);
    217   free(asciibuffer);
    218   return(rc);
    219 }
    220 
    221 
    222 /*****************************************************************************
    223  * Name      : GetWindowsDirectoryA
    224  * Purpose   :
    225  * Parameters:
    226  * Variables :
    227  * Result    :
    228  * Remark    :
    229  * Status    :
    230  *
    231  * Author    : Patrick Haller [Wed, 1999/09/28 20:44]
    232  *****************************************************************************/
    233 
    234 ODINFUNCTION2(UINT,GetWindowsDirectoryA,LPSTR,lpBuffer,
    235                                         UINT,uSize)
    236 {
    237   LPSTR lpstrEnv = getenv("WIN32.DIR.WINDOWS");         /* query environment */
    238 
    239   if (lpstrEnv != NULL)
    240   {
    241     lstrcpynA(lpBuffer,                   /* copy environment variable to buffer */
    242               lpstrEnv,
    243               uSize);
    244     return (lstrlenA(lpBuffer));                /* return number of copies bytes */
    245   } else
    246   {
    247     int len;
    248 
    249253    len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"WINDOWS","",lpBuffer,uSize);
    250254    if (len > 2) return len;
  • trunk/src/kernel32/initterm.cpp

    r1370 r1410  
    1 /* $Id: initterm.cpp,v 1.15 1999-10-20 08:09:04 sandervl Exp $ */
     1/* $Id: initterm.cpp,v 1.16 1999-10-23 12:34:46 sandervl Exp $ */
    22
    33/*
     
    3939#include <win32type.h>
    4040#include <odinlx.h>
     41#include "oslibmisc.h"
    4142
    4243/*-------------------------------------------------------------------*/
     
    6364ULONG flAllocMem = 0;
    6465int   loadNr = 0;
     66char  kernel32Path[CCHMAXPATH] = "";
    6567
    6668/****************************************************************************/
     
    8890    {
    8991        case 0 :
     92        {
    9093            loadNr = globLoadNr++;
    9194
     95            strcpy(kernel32Path, OSLibGetDllName(hModule));
     96            char *endofpath = strrchr(kernel32Path, '\\');
     97            *(endofpath+1) = 0;
    9298            dprintf(("kernel32 init\n"));
    9399            _ctordtorInit();
     
    120126            PROFILE_LoadOdinIni();
    121127            break;
     128        }
    122129        case 1 :
    123130            UnregisterLxDll(hModule);
  • trunk/src/kernel32/initterm.h

    r646 r1410  
    1 /* $Id: initterm.h,v 1.1 1999-08-23 13:55:08 sandervl Exp $ */
     1/* $Id: initterm.h,v 1.2 1999-10-23 12:34:47 sandervl Exp $ */
    22/*
    33 * KERNEL32 DLL entry point header
     
    3131/* flag to optimize DosAllocMem to use all the memory on SMP machines */
    3232extern ULONG flAllocMem;
     33extern char  kernel32Path[];
    3334
    3435#endif
  • trunk/src/kernel32/makefile

    r1280 r1410  
    1 # $Id: makefile,v 1.44 1999-10-14 09:21:42 sandervl Exp $
     1# $Id: makefile,v 1.45 1999-10-23 12:34:47 sandervl Exp $
    22
    33#
     
    3333winexepe2lx.obj winexelx.obj winexepeldr.obj WINRES.OBJ \
    3434pefile.OBJ winimgres.OBJ wintls.obj async.OBJ fileio.obj \
    35 atom.obj disk.obj directory.obj cvtbitmap.obj hmmmap.obj \
     35atom.obj disk.obj directory.obj cvtbitmap.obj hmmmap.obj winfakepeldr.obj \
    3636cvtmenu.obj cvtaccel.obj cvticon.obj cvticongrp.obj oslibexcept.obj \
    3737cvtcursor.obj cvtcursorgrp.obj stubs.obj interlock.obj toolhelp.obj
     
    9393
    9494directory.obj: directory.cpp \
    95     $(PDWIN32_INCLUDE)\unicode.h
     95    $(PDWIN32_INCLUDE)\unicode.h \
     96    initterm.h
    9697
    9798disk.obj: disk.cpp \
     
    174175    $(PDWIN32_INCLUDE)\windllpeldr.h \
    175176    $(PDWIN32_INCLUDE)\winimagebase.h \
     177    $(PDWIN32_INCLUDE)\winfakepeldr.h \
    176178    $(PDWIN32_INCLUDE)\versionos2.h \
    177179    $(PDWIN32_INCLUDE)\wprocess.h \
     
    342344                   $(PDWIN32_INCLUDE)\winimagelx.h $(PDWIN32_INCLUDE)\odinlx.h $(PDWIN32_INCLUDE)\winimagebase.h $(PDWIN32_INCLUDE)\winimagelx.h
    343345winexepeldr.obj:   winexepeldr.cpp $(PDWIN32_INCLUDE)\winexebase.h $(PDWIN32_INCLUDE)\winexepeldr.h $(PDWIN32_INCLUDE)\winimagepeldr.h $(PDWIN32_INCLUDE)\winimagebase.h
     346winfakepeldr.obj:  winfakepeldr.cpp $(PDWIN32_INCLUDE)\winimagepeldr.h $(PDWIN32_INCLUDE)\winimagebase.h $(PDWIN32_INCLUDE)\winfakepeldr.h
    344347
    345348winimgres.OBJ: winimgres.cpp $(PDWIN32_INCLUDE)\winimagebase.h $(PDWIN32_INCLUDE)\pefile.h $(PDWIN32_INCLUDE)\winimagepe2lx.h $(PDWIN32_INCLUDE)\winimagepeldr.h $(PDWIN32_INCLUDE)\winimagelx.h $(PDWIN32_INCLUDE)\winres.h
  • trunk/src/kernel32/misc.cpp

    r922 r1410  
    1 /* $Id: misc.cpp,v 1.11 1999-09-13 14:57:07 phaller Exp $ */
     1/* $Id: misc.cpp,v 1.12 1999-10-23 12:34:47 sandervl Exp $ */
    22
    33/*
     
    257257        sprintf(logname, "odin32_%d.log", loadNr);
    258258        flog = fopen(logname, "w");
     259        if(flog == NULL) {//probably running exe on readonly device
     260                sprintf(logname, "%sodin32_%d.log", kernel32Path, loadNr);
     261                flog = fopen(logname, "w");
     262        }
    259263    }
    260264    else
  • trunk/src/kernel32/winimagepeldr.cpp

    r1284 r1410  
    1 /* $Id: winimagepeldr.cpp,v 1.7 1999-10-14 09:57:35 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.8 1999-10-23 12:34:48 sandervl Exp $ */
    22
    33/*
     
    88 *
    99 * Project Odin Software License can be found in LICENSE.TXT
     10 *
     11 *
     12 * NOTE: RSRC_LOAD is a special flag to only load the resource directory
     13 *       of a PE image. Processing imports, sections etc is not done.
     14 *       Nor is it put into the linked list of dlls (if it's a dll).
     15 *       This is useful for GetVersionSize/Resource in case it wants to
     16 *       get version info of an image that is not loaded.
     17 *       So an instance of this type can't be used for anything but resource lookup!
    1018 *
    1119 */
     
    5967//******************************************************************************
    6068//******************************************************************************
    61 Win32PeLdrImage::Win32PeLdrImage(char *szFileName) :
     69Win32PeLdrImage::Win32PeLdrImage(char *szFileName, int loadtype) :
    6270    Win32ImageBase(-1),
    6371    nrsections(0), imageSize(0),
    6472    imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
    6573    nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
    66     pResSection(NULL)
    67 {
     74    pResSection(NULL), fImgMapping(0)
     75{
     76  loadType = loadtype;
     77
    6878  strcpy(this->szFileName, szFileName);
    6979
     
    8393        sprintf(logname, "pe_%d.log", loadNr);
    8494        fout.open(logname, ios::out | ios::trunc);
     95        if(fout.good() == FALSE) {
     96                sprintf(logname, "%spe_%d.log", kernel32Path, loadNr);
     97                fout.open(logname, ios::out | ios::trunc);
     98        }
    8599        dprintf(("PE LOGFILE for %s: %s", szModule, logname));
    86100        foutInit = TRUE;
     
    99113  if(ordexports)
    100114        free(ordexports);
     115
     116  //SvL: Only happens for images that aren't really loaded (RSRC_LOAD)
     117  if(fImgMapping) CloseHandle(fImgMapping);
     118  fImgMapping = 0;
    101119}
    102120//******************************************************************************
     
    104122BOOL Win32PeLdrImage::init(ULONG reservedMem)
    105123{
    106  HANDLE fImgMapping = 0;
    107124 char   szErrorMsg[64];
    108125 LPVOID win32file     = NULL;
     
    172189  nSections = NR_SECTIONS(win32file);
    173190
    174   if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) {
     191  if(loadType == REAL_LOAD)
     192  {
     193   if ((psh = (PIMAGE_SECTION_HEADER)SECTIONHDROFF (win32file)) != NULL) {
    175194    fout << endl << "*************************PE SECTIONS START**************************" << endl;
    176195    for (i=0; i<nSections; i++) {
     
    281300        goto failure;
    282301     }
    283   }
    284   fout << "*************************PE SECTIONS END **************************" << endl;
    285   imageSize += imageVirtBase - oh.ImageBase;
    286   fout << "Total size of Image " << imageSize << endl;
    287   fout << "imageVirtBase       " << imageVirtBase << endl;
    288   fout << "imageVirtEnd        " << imageVirtEnd << endl;
    289 
    290   //In case there are any gaps between sections, adjust size
    291   if(imageSize != imageVirtEnd - oh.ImageBase) {
     302   }
     303   fout << "*************************PE SECTIONS END **************************" << endl;
     304   imageSize += imageVirtBase - oh.ImageBase;
     305   fout << "Total size of Image " << imageSize << endl;
     306   fout << "imageVirtBase       " << imageVirtBase << endl;
     307   fout << "imageVirtEnd        " << imageVirtEnd << endl;
     308
     309   //In case there are any gaps between sections, adjust size
     310   if(imageSize != imageVirtEnd - oh.ImageBase) {
    292311        fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;
    293312        imageSize = imageVirtEnd - oh.ImageBase;
    294   }
    295   if(allocSections(reservedMem) == FALSE) {
     313   }
     314   if(allocSections(reservedMem) == FALSE) {
    296315        fout << "Failed to allocate image memory, rc " << errorState << endl;
    297316        goto failure;
    298   }
    299   fout << "OS/2 base address " << realBaseAddress << endl;
    300   if(storeSections((char *)win32file) == FALSE) {
     317   }
     318   fout << "OS/2 base address " << realBaseAddress << endl;
     319   if(storeSections((char *)win32file) == FALSE) {
    301320        fout << "Failed to store sections, rc " << errorState << endl;
    302321        goto failure;
    303   }
    304   if(oh.AddressOfEntryPoint) {
     322   }
     323   if(oh.AddressOfEntryPoint) {
    305324        entryPoint = realBaseAddress + oh.AddressOfEntryPoint;
    306   }
    307   else {
    308         fout << "EntryPoint == NULL" << endl;
     325   }
     326   else {
     327        fout << "EntryPoint == NULL" << endl; 
    309328        entryPoint = NULL;
    310   }
    311 
    312   if(tlsDir != NULL) {
    313    Section *sect = findSection(SECTION_TLS);
     329   }
     330
     331   if(tlsDir != NULL) {
     332    Section *sect = findSection(SECTION_TLS);
    314333
    315334        if(sect == NULL) {
     
    334353        }
    335354        setTLSCallBackAddr((PIMAGE_TLS_CALLBACK *)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfCallBacks - sect->virtaddr)));
    336   }
    337 
    338   if(realBaseAddress != oh.ImageBase) {
     355   }
     356
     357   if(realBaseAddress != oh.ImageBase) {
    339358        if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) {
    340359                fout << "Failed to set fixups" << endl;
    341360                goto failure;
    342361        }
    343   }
    344   if(fh.Characteristics & IMAGE_FILE_DLL) {
     362   }
     363   if(fh.Characteristics & IMAGE_FILE_DLL) {
    345364        if(processExports((char *)win32file) == FALSE) {
    346365                fout << "Failed to process exported apis" << endl;
    347366                goto failure;
    348367        }
    349   }
    350 
    351   //SvL: Use pointer to image header as module handle now. Some apps needs this
    352   hinstance = (HINSTANCE)realBaseAddress;
     368   }
     369
     370   //SvL: Use pointer to image header as module handle now. Some apps needs this
     371   hinstance = (HINSTANCE)realBaseAddress;
     372  }
    353373
    354374  //PH: get pResDir pointer correct first, since processImports may
     
    361381  }
    362382
    363   if(processImports((char *)win32file) == FALSE) {
     383  if (loadType == REAL_LOAD)
     384  {
     385   if(processImports((char *)win32file) == FALSE) {
    364386        fout << "Failed to process imports!" << endl;
    365         goto failure;
    366   }
    367 
    368   //set final memory protection flags (storeSections sets them to read/write)
    369   if(setMemFlags() == FALSE) {
     387        goto failure;
     388   }
     389
     390   //set final memory protection flags (storeSections sets them to read/write)
     391   if(setMemFlags() == FALSE) {
    370392        fout << "Failed to set memory protection" << endl;
    371393        goto failure;
    372   }
    373 
    374   CloseHandle(fImgMapping);
     394   }
     395   CloseHandle(fImgMapping);
     396   fImgMapping = 0;
     397  }
    375398  return(TRUE);
    376399failure:
    377400  if(fImgMapping) CloseHandle(fImgMapping);
     401  fImgMapping = 0;
    378402  errorState = ERROR_INTERNAL;
    379403  return FALSE;
  • trunk/src/kernel32/wprocess.cpp

    r1403 r1410  
    1 /* $Id: wprocess.cpp,v 1.39 1999-10-22 18:07:24 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.40 1999-10-23 12:34:48 sandervl Exp $ */
    22
    33/*
     
    2424#include <winexebase.h>
    2525#include <windllpeldr.h>
     26#include <winfakepeldr.h>
    2627
    2728#ifdef __IBMCPP__
     
    605606         if(lpszCommandLine) {
    606607                cmdline = (char *)malloc(strlen(lpszImageName)+strlen(lpszCommandLine) + 16);
    607                 sprintf(cmdline, "%s %s", lpszImageName, lpszCommandLine);
     608                sprintf(cmdline, "PE.EXE %s %s", lpszImageName, lpszCommandLine);
    608609                fAllocStr = TRUE;
    609610         }
    610          else   cmdline = (char *)lpszImageName;
     611         else {
     612                cmdline = (char *)malloc(strlen(lpszImageName) + 16);
     613                sprintf(cmdline, "PE.EXE %s", lpszImageName);
     614                fAllocStr = TRUE;
     615         }
    611616    }
    612     else cmdline = (char *)lpszCommandLine;
    613 
     617    else {
     618        cmdline = (char *)malloc(strlen(lpszCommandLine) + 16);
     619        sprintf(cmdline, "PE.EXE %s", lpszCommandLine);
     620        fAllocStr = TRUE;
     621    }
    614622    dprintf(("KERNEL32:  CreateProcess %s\n", cmdline));
    615623    rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
    616624    if(fAllocStr)
    617     free(cmdline);
     625        free(cmdline);
    618626
    619627    dprintf(("KERNEL32:  CreateProcess returned %d\n", rc));
     
    674682{
    675683 Win32ImageBase *winimage;
     684 Win32PeLdrRsrcImg *rsrcimg;
    676685
    677686  dprintf(("GetVersionStruct"));
     
    681690  else {
    682691        winimage = (Win32ImageBase *)Win32DllBase::findModule(modname);
    683         if(winimage == NULL) {
    684                 dprintf(("GetVersionStruct can't find Win32Image for %s\n", modname));
    685                 return(FALSE);
     692        if(winimage == NULL)
     693        {
     694                if(Win32ImageBase::isPEImage(modname) == FALSE)
     695                {
     696                 HINSTANCE hInstance;
     697                 
     698                        //must be an LX dll, just load it (app will probably load it anyway)
     699                        hInstance = LoadLibraryA(modname);
     700                        if(hInstance == 0)
     701                                return 0;
     702                        winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
     703                        if(winimage) {
     704                                return winimage->getVersionStruct(verstruct, bufLength);
     705                        }
     706                        return 0;
     707                }
     708                //SvL: Try to load it
     709                rsrcimg = new Win32PeLdrRsrcImg(modname);
     710                if(rsrcimg == NULL)
     711                        return 0;
     712
     713                rsrcimg->init(0);
     714                if(rsrcimg->getError() != NO_ERROR)
     715                {
     716                        dprintf(("GetVersionStruct can't load %s\n", modname));
     717                        delete rsrcimg;
     718                        return(FALSE);
     719                }
     720                BOOL rc = rsrcimg->getVersionStruct(verstruct, bufLength);
     721                delete rsrcimg;
     722                return rc;
    686723        }
    687724  }
     
    693730{
    694731 Win32ImageBase *winimage;
     732 Win32PeLdrRsrcImg *rsrcimg;
    695733
    696734  dprintf(("GetVersionSize of %s\n", modname));
     
    701739  else {
    702740        winimage = (Win32ImageBase *)Win32DllBase::findModule(modname);
    703         if(winimage == NULL) {
    704                 dprintf(("GetVersionSize can't find Win32Image for %s\n", modname));
    705                 return(FALSE);
     741        if(winimage == NULL)
     742        {
     743                if(Win32ImageBase::isPEImage(modname) == FALSE)
     744                {
     745                 HINSTANCE hInstance;
     746                 
     747                        //must be an LX dll, just load it (app will probably load it anyway)
     748                        hInstance = LoadLibraryA(modname);
     749                        if(hInstance == 0)
     750                                return 0;
     751                        winimage = (Win32ImageBase *)Win32DllBase::findModule(hInstance);
     752                        if(winimage) {
     753                                return winimage->getVersionSize();
     754                        }
     755                        return 0;
     756                }
     757
     758                //SvL: Try to load it
     759                rsrcimg = new Win32PeLdrRsrcImg(modname);
     760                if(rsrcimg == NULL)
     761                        return 0;
     762
     763                rsrcimg->init(0);
     764                if(rsrcimg->getError() != NO_ERROR)
     765                {
     766                        dprintf(("GetVersionSize can't load %s\n", modname));
     767                        delete rsrcimg;
     768                        return(FALSE);
     769                }
     770                rsrcimg->init(0);
     771                int size = rsrcimg->getVersionSize();
     772                delete rsrcimg;
     773                return size;
    706774        }
    707775  }
Note: See TracChangeset for help on using the changeset viewer.