Changeset 4445 for trunk/src


Ignore:
Timestamp:
Oct 6, 2000, 5:16:07 PM (25 years ago)
Author:
sandervl
Message:

changes for setting current dir of new process

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/KERNEL32.DEF

    r4440 r4445  
    1 ; $Id: KERNEL32.DEF,v 1.88 2000-10-06 11:04:00 sandervl Exp $
     1; $Id: KERNEL32.DEF,v 1.89 2000-10-06 15:15:59 sandervl Exp $
    22
    33;Created by BLAST for IBM's compiler
     
    10331033    _RegisterPe2LxDll@12                                          @1209
    10341034
    1035     _CreateWin32PeLdrExe@16                                       @1236
     1035    _CreateWin32PeLdrExe@20                                       @1236
    10361036
    10371037    _RegisterLxExe@8                                              @1237
  • trunk/src/kernel32/directory.cpp

    r4387 r4445  
    1 /* $Id: directory.cpp,v 1.30 2000-10-02 18:39:33 sandervl Exp $ */
     1/* $Id: directory.cpp,v 1.31 2000-10-06 15:16:03 sandervl Exp $ */
    22
    33/*
     
    112112                                          LPSTR, lpBuffer)
    113113{
    114   return O32_GetCurrentDirectory(nBufferLength, lpBuffer);
     114 UINT rc;
     115
     116  rc = O32_GetCurrentDirectory(nBufferLength, lpBuffer);
     117  if(rc) {
     118    dprintf(("CurrentDirectory = %s", lpBuffer));
     119  }
     120  return rc;
    115121}
    116122
  • trunk/src/kernel32/winexepeldr.cpp

    r4440 r4445  
    1 /* $Id: winexepeldr.cpp,v 1.12 2000-10-06 11:04:01 sandervl Exp $ */
     1/* $Id: winexepeldr.cpp,v 1.13 2000-10-06 15:16:03 sandervl Exp $ */
    22
    33/*
    44 * Win32 PE loader Exe class
    55 *
    6  * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
     6 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
    77 *
    88 *
     
    2323#include <misc.h>
    2424#include <win32type.h>
     25#include <win32api.h>
    2526#include <winexepeldr.h>
    2627#include <wprocess.h>
     
    4647//******************************************************************************
    4748//Called by ring 3 pe loader to create win32 executable
     49//PE.EXE command line options:
     50//   /OPT:[x1=y,x2=z,..]         
     51//   x = CURDIR    -> set current directory to y
     52//   (not other options available at this time)
    4853//******************************************************************************
    49 BOOL WIN32API CreateWin32PeLdrExe(char *szFileName, char *szCmdLine,
     54BOOL WIN32API CreateWin32PeLdrExe(char *szFileName, char *szCmdLine,
     55                                  char *peoptions,
    5056                                  ULONG reservedMem, BOOL fConsoleApp)
    5157{
     
    6773        return FALSE;
    6874  }
     75  //Handle special pe cmd line options here (/OPT:[x1=y,x2=z,..])
     76  if(peoptions) {
     77        char *option;
    6978
     79        option = strchr(peoptions, '[');
     80        if(option) {
     81                option++;
     82                option = strstr(option, "CURDIR=");
     83                if(option) {
     84                        char *curdir, *tmp;
     85                        int   curdirlength;
     86
     87                        option += 7;
     88                        tmp = option;
     89                        while(*tmp != ']' && *tmp != ',' && *tmp != 0) {
     90                                tmp++;
     91                        }
     92                        curdirlength = (int)(tmp-option);
     93                        curdir = (char *)malloc(curdirlength+1);
     94                        memcpy(curdir, option, curdirlength);
     95                        curdir[curdirlength] = 0;
     96                        SetCurrentDirectoryA((LPCSTR)curdir);
     97                        free(curdir);
     98                }
     99        }
     100  }
    70101  //exe length + space + (possibly) 2x'"' + cmd line length + 0 terminator
    71102  szFullCmdLine = (char *)malloc(strlen(szFileName) + 3 + strlen(szCmdLine) + 1);
  • trunk/src/kernel32/winexepeldr.h

    r4440 r4445  
    1 /* $Id: winexepeldr.h,v 1.3 2000-10-06 11:04:02 sandervl Exp $ */
     1/* $Id: winexepeldr.h,v 1.4 2000-10-06 15:16:04 sandervl Exp $ */
    22
    33/*
     
    1616#include <winimagepeldr.h>
    1717
    18 typedef BOOL (* WIN32API WIN32CTOR)(char *, char *, ULONG, BOOL);
     18typedef BOOL (* WIN32API WIN32CTOR)(char *, char *, char *, ULONG, BOOL);
    1919
    2020//Class for executables run by the ring 3 PE loader
  • trunk/src/kernel32/winimagepeldr.cpp

    r4440 r4445  
    1 /* $Id: winimagepeldr.cpp,v 1.56 2000-10-06 11:04:02 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.57 2000-10-06 15:16:05 sandervl Exp $ */
    22
    33/*
     
    480480        char *pszName;
    481481
    482         switch (i)
    483         {
     482        if(oh.DataDirectory[i].VirtualAddress && oh.DataDirectory[i].Size) {
     483                switch (i)
     484                {
    484485                case IMAGE_DIRECTORY_ENTRY_EXPORT:      pszName = "Export Directory (IMAGE_DIRECTORY_ENTRY_EXPORT)"; break;
    485486                case IMAGE_DIRECTORY_ENTRY_IMPORT:      pszName = "Import Directory (IMAGE_DIRECTORY_ENTRY_IMPORT)"; break;
     
    497498                default:
    498499                    pszName = "unknown";
    499         }
    500         dprintf((LOG, "directory %s", pszName));
    501         dprintf((LOG, "          Address    0x%08x", oh.DataDirectory[i].VirtualAddress));
    502         dprintf((LOG, "          Size       0x%08x", oh.DataDirectory[i].Size));
     500                }
     501                dprintf((LOG, "directory %s", pszName));
     502                dprintf((LOG, "          Address    0x%08x", oh.DataDirectory[i].VirtualAddress));
     503                dprintf((LOG, "          Size       0x%08x", oh.DataDirectory[i].Size));
     504        }
    503505   }
    504506   dprintf((LOG, "\n\n"));
  • trunk/src/kernel32/winimgres.cpp

    r4436 r4445  
    1 /* $Id: winimgres.cpp,v 1.47 2000-10-05 19:38:45 sandervl Exp $ */
     1/* $Id: winimgres.cpp,v 1.48 2000-10-06 15:16:06 sandervl Exp $ */
    22
    33/*
     
    323323}
    324324
    325 
     325/**
     326 * This function finds a resource (sub)directory within a given resource directory.
     327 * @returns   Pointer to resource directory. NULL if not found or not a directory.
     328 * @param     pResDirToSearch  Pointer to resource directory to search. (any level)
     329 * @param     lpszName         Resource ID string.
     330 * @sketch
     331 * @status    completely implemented
     332 * @author    knut st. osmundsen
     333 */
     334PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
     335                                                        LPCWSTR lpszName)
     336{
     337    PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
     338    int     i;
     339    int     idName = -1;
     340
     341    if(pResDirToSearch == NULL) {
     342        return NULL;
     343    }
     344
     345    /* lpszName */
     346    if ((ULONG)lpszName != ID_GETFIRST && HIWORD(lpszName) != 0)
     347    {
     348        if (lpszName[0] == '#')
     349        {
     350            char szBuf[10];
     351            lstrcpynWtoA(szBuf, (WCHAR*)(lpszName + 1), sizeof(szBuf));
     352            idName = atoi(szBuf);
     353        }
     354    }
     355    else
     356        idName = (int)lpszName;
     357
     358    paResDirEntries = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResDirToSearch + sizeof(*pResDirToSearch));
     359    if(idName == ID_GETFIRST) {
     360        return paResDirEntries[0].u2.s.DataIsDirectory ?
     361               (PIMAGE_RESOURCE_DIRECTORY) (paResDirEntries[0].u2.s.OffsetToDirectory + (ULONG)pResRootDir)
     362               : NULL;
     363    }
     364
     365    if (idName != -1)
     366    {   /* idName */
     367        paResDirEntries += pResDirToSearch->NumberOfNamedEntries;
     368
     369        for (i = 0; i < pResDirToSearch->NumberOfIdEntries; i++)
     370            if (paResDirEntries[i].u1.Id == (WORD)idName)
     371                return paResDirEntries[i].u2.s.DataIsDirectory ?
     372                    (PIMAGE_RESOURCE_DIRECTORY) (paResDirEntries[i].u2.s.OffsetToDirectory + (ULONG)pResRootDir /*?*/
     373                                                 /*- ulRVAResourceSection*/)
     374                    : NULL;
     375    }
     376    else
     377    {   /* string name */
     378        int cusName = lstrlenW(lpszName);
     379
     380        for (i = 0; i < pResDirToSearch->NumberOfNamedEntries; i++)
     381        {
     382            PIMAGE_RESOURCE_DIR_STRING_U pResDirStr =
     383                (PIMAGE_RESOURCE_DIR_STRING_U)(paResDirEntries[i].u1.s.NameOffset + (ULONG)pResRootDir /*?*/);
     384
     385            //SvL: Must do case insensitive string compare here
     386            if (pResDirStr->Length == cusName
     387                && lstrncmpiW(pResDirStr->NameString, lpszName, cusName) == 0)
     388            {
     389                return paResDirEntries[i].u2.s.DataIsDirectory ?
     390                    (PIMAGE_RESOURCE_DIRECTORY) (paResDirEntries[i].u2.s.OffsetToDirectory + (ULONG)pResRootDir
     391                                                 /*- ulRVAResourceSection*/)
     392                    : NULL;
     393            }
     394        }
     395    }
     396
     397    return NULL;
     398}
     399
     400/**
     401 * This function finds a resource (sub)directory within a given resource directory.
     402 * @returns   Pointer to resource directory. NULL if not found or not a directory.
     403 * @param     pResDirToSearch  Pointer to resource directory to search. (any level)
     404 * @param     lpszName         Resource ID string.
     405 * @sketch
     406 * @status    completely implemented
     407 * @author    knut st. osmundsen
     408 */
     409PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
     410                                                        LPCTSTR lpszName)
     411{
     412    PIMAGE_RESOURCE_DIRECTORY   pResDirRet;
     413    LPCWSTR                     lpszwName;
     414
     415    if(pResDirToSearch == NULL) {
     416        return NULL;
     417    }
     418
     419    /* lpszName */
     420    if ((ULONG)lpszName != ID_GETFIRST && HIWORD(lpszName) != 0)
     421    {
     422        lpszwName = AsciiToUnicodeString((char*)lpszName);
     423        if (lpszwName == NULL)
     424            return NULL;
     425    }
     426    else
     427        lpszwName = (LPWSTR)lpszName;
     428
     429    pResDirRet = getResSubDirW(pResDirToSearch, lpszwName);
     430
     431    if ((ULONG)lpszName != ID_GETFIRST && HIWORD(lpszwName) != 0)
     432        free((void*)lpszwName);
     433
     434    return pResDirRet;
     435}
     436//******************************************************************************
     437/**
     438 * This function finds a resource data entry within a given resource directory.
     439 * @returns   Pointer to resource data entry. NULL if not found
     440 * @param     pResDirToSearch  Pointer to resource directory to search. (lang level)
     441 * @param     language         Resource language id
     442 * @param     fGetDefault      TRUE -> get first available resource if not found
     443 * @sketch
     444 * @status    completely implemented
     445 * @author    Sander van Leeuwen
     446 */
     447//******************************************************************************
     448PIMAGE_RESOURCE_DATA_ENTRY
     449     Win32ImageBase::getResDataLang(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
     450                                    ULONG language, BOOL fGetDefault)
     451{
     452    PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
     453    int     i;
     454
     455    if(pResDirToSearch == NULL) {
     456        return NULL;
     457    }
     458
     459    paResDirEntries = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResDirToSearch + sizeof(*pResDirToSearch));
     460
     461    if(pResDirToSearch->NumberOfNamedEntries) {
     462        DebugInt3();
     463    }
     464    paResDirEntries += pResDirToSearch->NumberOfNamedEntries;
     465
     466    for (i = 0; i < pResDirToSearch->NumberOfIdEntries; i++) {
     467        if (paResDirEntries[i].u1.Id == language)
     468        {
     469                return (PIMAGE_RESOURCE_DATA_ENTRY) (paResDirEntries[i].u2.s.OffsetToDirectory + (ULONG)pResRootDir);
     470        }
     471    }
     472
     473    // if nothing found and fGetDefault is true, return first entry
     474    if(fGetDefault)
     475    {
     476        return (PIMAGE_RESOURCE_DATA_ENTRY) (paResDirEntries[0].u2.s.OffsetToDirectory + (ULONG)pResRootDir);
     477    }
     478    return NULL;
     479}
     480//******************************************************************************
     481//******************************************************************************
     482BOOL Win32ImageBase::enumResourceTypesA(HMODULE hmod, ENUMRESTYPEPROCA lpEnumFunc,
     483                                        LONG lParam)
     484{
     485 PIMAGE_RESOURCE_DIRECTORY       prdType;
     486 PIMAGE_RESOURCE_DIRECTORY_ENTRY prde;
     487 PIMAGE_RESOURCE_DIR_STRING_U    pstring;
     488 ULONG  i, nameOffset;
     489 BOOL   fRet;
     490
     491    if (pResRootDir == NULL)
     492    {
     493        SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
     494        return FALSE;
     495    }
     496
     497    if ((ULONG)lpEnumFunc < 0x10000 || (ULONG)lpEnumFunc >= 0xc0000000)
     498    {
     499        SetLastError(ERROR_NOACCESS);
     500        return FALSE;
     501    }
     502
     503    //reminder:
     504    //1st level -> types
     505    //2nd level -> names
     506    //3rd level -> language
     507
     508    /* set pointer to first resource type entry */
     509    prde = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResRootDir + sizeof(IMAGE_RESOURCE_DIRECTORY));
     510
     511    for (i=0; i<pResRootDir->NumberOfNamedEntries+pResRootDir->NumberOfIdEntries && fRet; i++)
     512    {
     513        /* locate directory or each resource type */
     514        prdType = (PIMAGE_RESOURCE_DIRECTORY)((int)pResRootDir + (int)prde->u2.OffsetToData);
     515
     516        if (prde->u1.s.NameIsString)
     517        {//name or id entry?
     518                //SvL: 30-10-'97, high bit is set, so clear to get real offset
     519                nameOffset = prde->u1.Name & ~0x80000000;
     520       
     521                pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResRootDir + nameOffset);
     522                char *typename = (char *)malloc(pstring->Length+1);
     523                lstrcpynWtoA(typename, pstring->NameString, pstring->Length+1);
     524                typename[pstring->Length] = 0;
     525
     526                fRet = lpEnumFunc(hmod, typename, lParam);
     527                free(typename);
     528        }
     529        else {
     530                fRet = lpEnumFunc(hmod, (LPSTR)prde->u1.Id, lParam);
     531        }
     532
     533        /* increment to next entry */
     534        prde++;
     535    }
     536    return fRet > 0 ? TRUE : FALSE;
     537}
     538//******************************************************************************
     539//******************************************************************************
     540BOOL Win32ImageBase::enumResourceTypesW(HMODULE hmod, ENUMRESTYPEPROCW lpEnumFunc,
     541                                        LONG lParam)
     542{
     543 PIMAGE_RESOURCE_DIRECTORY       prdType;
     544 PIMAGE_RESOURCE_DIRECTORY_ENTRY prde;
     545 PIMAGE_RESOURCE_DIR_STRING_U    pstring;
     546 ULONG  i, nameOffset;
     547 BOOL   fRet;
     548 LPWSTR lpszType;
     549
     550    if (pResRootDir == NULL)
     551    {
     552        SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
     553        return FALSE;
     554    }
     555
     556    if ((ULONG)lpEnumFunc < 0x10000 || (ULONG)lpEnumFunc >= 0xc0000000)
     557    {
     558        SetLastError(ERROR_NOACCESS);
     559        return FALSE;
     560    }
     561
     562    //reminder:
     563    //1st level -> types
     564    //2nd level -> names
     565    //3rd level -> language
     566
     567    /* set pointer to first resource type entry */
     568    prde = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResRootDir + sizeof(IMAGE_RESOURCE_DIRECTORY));
     569
     570    for (i=0; i<pResRootDir->NumberOfNamedEntries+pResRootDir->NumberOfIdEntries && fRet; i++)
     571    {
     572        /* locate directory or each resource type */
     573        prdType = (PIMAGE_RESOURCE_DIRECTORY)((int)pResRootDir + (int)prde->u2.OffsetToData);
     574
     575        if (prde->u1.s.NameIsString)
     576        {//name or id entry?
     577                //SvL: 30-10-'97, high bit is set, so clear to get real offset
     578                nameOffset = prde->u1.Name & ~0x80000000;
     579       
     580                pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResRootDir + nameOffset);
     581
     582                lpszType = (LPWSTR)malloc((pstring->Length+1) * sizeof(WCHAR));
     583                memcpy(lpszType, pstring->NameString, pstring->Length * sizeof(WCHAR));
     584                lpszType[pstring->Length] = 0;
     585
     586                fRet = lpEnumFunc(hmod, pstring->NameString, lParam);
     587
     588                free(lpszType);
     589        }
     590        else    fRet = lpEnumFunc(hmod, (LPWSTR)prde->u1.Id, lParam);
     591
     592        /* increment to next entry */
     593        prde++;
     594    }
     595    return fRet > 0 ? TRUE : FALSE;
     596}
    326597/**
    327598 * The EnumResourceNames function searches a module for each
     
    362633                                        LONG lParam)
    363634{
    364     BOOL                            fRet;
    365     PIMAGE_RESOURCE_DIRECTORY       pResDirOurType;
    366     PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
     635 BOOL                            fRet;
     636 PIMAGE_RESOURCE_DIRECTORY       pResDirOurType;
     637 PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
    367638
    368639    if (pResRootDir == NULL)
     
    484755                                        LONG lParam)
    485756{
    486     BOOL                            fRet;
    487     PIMAGE_RESOURCE_DIRECTORY       pResDirOurType;
    488     PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
     757 BOOL                            fRet;
     758 PIMAGE_RESOURCE_DIRECTORY       pResDirOurType;
     759 PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
    489760
    490761    if (pResRootDir == NULL)
     
    517788    {
    518789        unsigned  cResEntries;
    519         unsigned  i;
     790        unsigned  i, length;
    520791
    521792        fRet = TRUE;
     
    524795        for (i = 0; i < cResEntries && fRet; i++)
    525796        {
    526             LPWSTR lpszName;
    527 
    528             if (paResDirEntries[i].u1.s.NameIsString)
     797            LPWSTR lpszName, lpszResName;
     798
     799            if(paResDirEntries[i].u1.s.NameIsString)
     800            {
    529801                lpszName = (LPWSTR)(paResDirEntries[i].u1.s.NameOffset + (ULONG)pResRootDir + 2);
    530             else
     802                length   = (int)*(LPWSTR)(paResDirEntries[i].u1.s.NameOffset + (ULONG)pResRootDir);
     803
     804                lpszResName = (LPWSTR)malloc((length+1) * sizeof(WCHAR));
     805                memcpy(lpszResName, lpszName, length * sizeof(WCHAR));
     806                lpszResName[length] = 0;
     807
     808                fRet = lpEnumFunc(hmod, lpszType, lpszResName, lParam);
     809                free(lpszResName);
     810            }
     811            else {
    531812                lpszName = (LPWSTR)paResDirEntries[i].u1.Id;
    532 
    533             fRet = lpEnumFunc(hmod, lpszType, lpszName, lParam);
     813                fRet = lpEnumFunc(hmod, lpszType, lpszName, lParam);
     814            }
    534815        }
    535816    }
     
    541822
    542823    return fRet > 0;
    543 }
    544 
    545 
    546 
    547 /**
    548  * This function finds a resource (sub)directory within a given resource directory.
    549  * @returns   Pointer to resource directory. NULL if not found or not a directory.
    550  * @param     pResDirToSearch  Pointer to resource directory to search. (any level)
    551  * @param     lpszName         Resource ID string.
    552  * @sketch
    553  * @status    completely implemented
    554  * @author    knut st. osmundsen
    555  */
    556 PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
    557                                                         LPCWSTR lpszName)
    558 {
    559     PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
    560     int     i;
    561     int     idName = -1;
    562 
    563     if(pResDirToSearch == NULL) {
    564         return NULL;
    565     }
    566 
    567     /* lpszName */
    568     if ((ULONG)lpszName != ID_GETFIRST && HIWORD(lpszName) != 0)
    569     {
    570         if (lpszName[0] == '#')
    571         {
    572             char szBuf[10];
    573             lstrcpynWtoA(szBuf, (WCHAR*)(lpszName + 1), sizeof(szBuf));
    574             idName = atoi(szBuf);
    575         }
    576     }
    577     else
    578         idName = (int)lpszName;
    579 
    580     paResDirEntries = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResDirToSearch + sizeof(*pResDirToSearch));
    581     if(idName == ID_GETFIRST) {
    582         return paResDirEntries[0].u2.s.DataIsDirectory ?
    583                (PIMAGE_RESOURCE_DIRECTORY) (paResDirEntries[0].u2.s.OffsetToDirectory + (ULONG)pResRootDir)
    584                : NULL;
    585     }
    586 
    587     if (idName != -1)
    588     {   /* idName */
    589         paResDirEntries += pResDirToSearch->NumberOfNamedEntries;
    590 
    591         for (i = 0; i < pResDirToSearch->NumberOfIdEntries; i++)
    592             if (paResDirEntries[i].u1.Id == (WORD)idName)
    593                 return paResDirEntries[i].u2.s.DataIsDirectory ?
    594                     (PIMAGE_RESOURCE_DIRECTORY) (paResDirEntries[i].u2.s.OffsetToDirectory + (ULONG)pResRootDir /*?*/
    595                                                  /*- ulRVAResourceSection*/)
    596                     : NULL;
    597     }
    598     else
    599     {   /* string name */
    600         int cusName = lstrlenW(lpszName);
    601 
    602         for (i = 0; i < pResDirToSearch->NumberOfNamedEntries; i++)
    603         {
    604             PIMAGE_RESOURCE_DIR_STRING_U pResDirStr =
    605                 (PIMAGE_RESOURCE_DIR_STRING_U)(paResDirEntries[i].u1.s.NameOffset + (ULONG)pResRootDir /*?*/);
    606 
    607             //SvL: Must do case insensitive string compare here
    608             if (pResDirStr->Length == cusName
    609                 && lstrncmpiW(pResDirStr->NameString, lpszName, cusName) == 0)
    610             {
    611                 return paResDirEntries[i].u2.s.DataIsDirectory ?
    612                     (PIMAGE_RESOURCE_DIRECTORY) (paResDirEntries[i].u2.s.OffsetToDirectory + (ULONG)pResRootDir
    613                                                  /*- ulRVAResourceSection*/)
    614                     : NULL;
    615             }
    616         }
    617     }
    618 
    619     return NULL;
    620 }
    621 
    622 /**
    623  * This function finds a resource (sub)directory within a given resource directory.
    624  * @returns   Pointer to resource directory. NULL if not found or not a directory.
    625  * @param     pResDirToSearch  Pointer to resource directory to search. (any level)
    626  * @param     lpszName         Resource ID string.
    627  * @sketch
    628  * @status    completely implemented
    629  * @author    knut st. osmundsen
    630  */
    631 PIMAGE_RESOURCE_DIRECTORY Win32ImageBase::getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
    632                                                         LPCTSTR lpszName)
    633 {
    634     PIMAGE_RESOURCE_DIRECTORY   pResDirRet;
    635     LPCWSTR                     lpszwName;
    636 
    637     if(pResDirToSearch == NULL) {
    638         return NULL;
    639     }
    640 
    641     /* lpszName */
    642     if ((ULONG)lpszName != ID_GETFIRST && HIWORD(lpszName) != 0)
    643     {
    644         lpszwName = AsciiToUnicodeString((char*)lpszName);
    645         if (lpszwName == NULL)
    646             return NULL;
    647     }
    648     else
    649         lpszwName = (LPWSTR)lpszName;
    650 
    651     pResDirRet = getResSubDirW(pResDirToSearch, lpszwName);
    652 
    653     if ((ULONG)lpszName != ID_GETFIRST && HIWORD(lpszwName) != 0)
    654         free((void*)lpszwName);
    655 
    656     return pResDirRet;
    657 }
    658 //******************************************************************************
    659 /**
    660  * This function finds a resource data entry within a given resource directory.
    661  * @returns   Pointer to resource data entry. NULL if not found
    662  * @param     pResDirToSearch  Pointer to resource directory to search. (lang level)
    663  * @param     language         Resource language id
    664  * @param     fGetDefault      TRUE -> get first available resource if not found
    665  * @sketch
    666  * @status    completely implemented
    667  * @author    Sander van Leeuwen
    668  */
    669 //******************************************************************************
    670 PIMAGE_RESOURCE_DATA_ENTRY
    671      Win32ImageBase::getResDataLang(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
    672                                     ULONG language, BOOL fGetDefault)
    673 {
    674     PIMAGE_RESOURCE_DIRECTORY_ENTRY paResDirEntries;
    675     int     i;
    676 
    677     if(pResDirToSearch == NULL) {
    678         return NULL;
    679     }
    680 
    681     paResDirEntries = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResDirToSearch + sizeof(*pResDirToSearch));
    682 
    683     if(pResDirToSearch->NumberOfNamedEntries) {
    684         DebugInt3();
    685     }
    686     paResDirEntries += pResDirToSearch->NumberOfNamedEntries;
    687 
    688     for (i = 0; i < pResDirToSearch->NumberOfIdEntries; i++) {
    689         if (paResDirEntries[i].u1.Id == language)
    690         {
    691                 return (PIMAGE_RESOURCE_DATA_ENTRY) (paResDirEntries[i].u2.s.OffsetToDirectory + (ULONG)pResRootDir);
    692         }
    693     }
    694 
    695     // if nothing found and fGetDefault is true, return first entry
    696     if(fGetDefault)
    697     {
    698         return (PIMAGE_RESOURCE_DATA_ENTRY) (paResDirEntries[0].u2.s.OffsetToDirectory + (ULONG)pResRootDir);
    699     }
    700     return NULL;
    701 }
    702 //******************************************************************************
    703 //******************************************************************************
    704 BOOL Win32ImageBase::enumResourceTypesA(HMODULE hmod, ENUMRESTYPEPROCA lpEnumFunc,
    705                                         LONG lParam)
    706 {
    707  PIMAGE_RESOURCE_DIRECTORY       prdType;
    708  PIMAGE_RESOURCE_DIRECTORY_ENTRY prde;
    709  PIMAGE_RESOURCE_DIR_STRING_U    pstring;
    710  ULONG  i, nameOffset;
    711  BOOL   fRet;
    712 
    713     if (pResRootDir == NULL)
    714     {
    715         SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
    716         return FALSE;
    717     }
    718 
    719     if ((ULONG)lpEnumFunc < 0x10000 || (ULONG)lpEnumFunc >= 0xc0000000)
    720     {
    721         SetLastError(ERROR_NOACCESS);
    722         return FALSE;
    723     }
    724 
    725     //reminder:
    726     //1st level -> types
    727     //2nd level -> names
    728     //3rd level -> language
    729 
    730     /* set pointer to first resource type entry */
    731     prde = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResRootDir + sizeof(IMAGE_RESOURCE_DIRECTORY));
    732 
    733     for (i=0; i<pResRootDir->NumberOfNamedEntries+pResRootDir->NumberOfIdEntries && fRet; i++)
    734     {
    735         /* locate directory or each resource type */
    736         prdType = (PIMAGE_RESOURCE_DIRECTORY)((int)pResRootDir + (int)prde->u2.OffsetToData);
    737 
    738         if (prde->u1.s.NameIsString)
    739         {//name or id entry?
    740                 //SvL: 30-10-'97, high bit is set, so clear to get real offset
    741                 nameOffset = prde->u1.Name & ~0x80000000;
    742        
    743                 pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResRootDir + nameOffset);
    744                 char *typename = (char *)malloc(pstring->Length+1);
    745                 lstrcpynWtoA(typename, pstring->NameString, pstring->Length+1);
    746                 typename[pstring->Length] = 0;
    747 
    748                 fRet = lpEnumFunc(hmod, typename, lParam);
    749                 free(typename);
    750         }
    751         else {
    752                 fRet = lpEnumFunc(hmod, (LPSTR)prde->u1.Id, lParam);
    753         }
    754 
    755         /* increment to next entry */
    756         prde++;
    757     }
    758     return fRet > 0 ? TRUE : FALSE;
    759 }
    760 //******************************************************************************
    761 //******************************************************************************
    762 BOOL Win32ImageBase::enumResourceTypesW(HMODULE hmod, ENUMRESTYPEPROCW lpEnumFunc,
    763                                         LONG lParam)
    764 {
    765  PIMAGE_RESOURCE_DIRECTORY       prdType;
    766  PIMAGE_RESOURCE_DIRECTORY_ENTRY prde;
    767  PIMAGE_RESOURCE_DIR_STRING_U    pstring;
    768  ULONG  i, nameOffset;
    769  BOOL   fRet;
    770 
    771     if (pResRootDir == NULL)
    772     {
    773         SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
    774         return FALSE;
    775     }
    776 
    777     if ((ULONG)lpEnumFunc < 0x10000 || (ULONG)lpEnumFunc >= 0xc0000000)
    778     {
    779         SetLastError(ERROR_NOACCESS);
    780         return FALSE;
    781     }
    782 
    783     //reminder:
    784     //1st level -> types
    785     //2nd level -> names
    786     //3rd level -> language
    787 
    788     /* set pointer to first resource type entry */
    789     prde = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)((ULONG)pResRootDir + sizeof(IMAGE_RESOURCE_DIRECTORY));
    790 
    791     for (i=0; i<pResRootDir->NumberOfNamedEntries+pResRootDir->NumberOfIdEntries && fRet; i++)
    792     {
    793         /* locate directory or each resource type */
    794         prdType = (PIMAGE_RESOURCE_DIRECTORY)((int)pResRootDir + (int)prde->u2.OffsetToData);
    795 
    796         if (prde->u1.s.NameIsString)
    797         {//name or id entry?
    798                 //SvL: 30-10-'97, high bit is set, so clear to get real offset
    799                 nameOffset = prde->u1.Name & ~0x80000000;
    800        
    801                 pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResRootDir + nameOffset);
    802                 fRet = lpEnumFunc(hmod, pstring->NameString, lParam);
    803         }
    804         else    fRet = lpEnumFunc(hmod, (LPWSTR)prde->u1.Id, lParam);
    805 
    806         /* increment to next entry */
    807         prde++;
    808     }
    809     return fRet > 0 ? TRUE : FALSE;
    810824}
    811825//******************************************************************************
  • trunk/src/kernel32/wprocess.cpp

    r4422 r4445  
    1 /* $Id: wprocess.cpp,v 1.101 2000-10-04 19:36:26 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.102 2000-10-06 15:16:07 sandervl Exp $ */
    22
    33/*
     
    15631563            }
    15641564            cmdline = (char *)malloc(strlen(lpApplicationName)+strlen(lpCommandLine) + 16);
    1565             sprintf(cmdline, "PE.EXE %s %s", lpApplicationName, lpCommandLine);
     1565            sprintf(cmdline, "%s %s", lpApplicationName, lpCommandLine);
    15661566         }
    15671567         else {
    15681568            cmdline = (char *)malloc(strlen(lpApplicationName) + 16);
    1569             sprintf(cmdline, "PE.EXE %s", lpApplicationName);
     1569            sprintf(cmdline, "%s", lpApplicationName);
    15701570        }
    15711571    }
    15721572    else {
    15731573        cmdline = (char *)malloc(strlen(lpCommandLine) + 16);
    1574         sprintf(cmdline, "PE.EXE %s", lpCommandLine);
     1574        sprintf(cmdline, "%s", lpCommandLine);
    15751575    }
    15761576    char szAppName[255];
    15771577    char *exename = szAppName;
    1578     strncpy(szAppName, &cmdline[7], sizeof(szAppName)); //skip pe.exe
     1578    strncpy(szAppName, cmdline, sizeof(szAppName));
    15791579    szAppName[254] = 0;
    15801580    if(*exename == '"') {
     
    16001600    }   
    16011601    dprintf(("KERNEL32:  CreateProcess %s\n", cmdline));
     1602
     1603    //SvL: Allright. Before we call O32_CreateProcess, we must take care of
     1604    //     lpCurrentDirectory ourselves. (Open32 ignores it!)
     1605    if(lpCurrentDirectory) {
     1606        char *newcmdline;
     1607
     1608        newcmdline = (char *)malloc(strlen(lpCurrentDirectory) + strlen(cmdline) + 32);
     1609        sprintf(newcmdline, "PE.EXE /OPT:[CURDIR=%s] %s", lpCurrentDirectory, cmdline);
     1610        free(cmdline);
     1611        cmdline = newcmdline;
     1612    }
     1613    else {
     1614        char *newcmdline;
     1615
     1616        newcmdline = (char *)malloc(strlen(cmdline) + 16);
     1617        sprintf(newcmdline, "PE.EXE %s", cmdline);
     1618        free(cmdline);
     1619        cmdline = newcmdline;
     1620    }
    16021621    rc = O32_CreateProcess("PE.EXE", (LPCSTR)cmdline,lpProcessAttributes,
    16031622                         lpThreadAttributes, bInheritHandles, dwCreationFlags,
    16041623                         lpEnvironment, lpCurrentDirectory, lpStartupInfo,
    16051624                         lpProcessInfo);
    1606     if(rc == TRUE) {
     1625    if(rc == TRUE)
     1626    {
    16071627      if (dwCreationFlags & DEBUG_PROCESS && pThreadDB != NULL)
    16081628      {
  • trunk/src/peldr/pe.cpp

    r4441 r4445  
    1 /* $Id: pe.cpp,v 1.22 2000-10-06 11:04:42 sandervl Exp $ */
     1/* $Id: pe.cpp,v 1.23 2000-10-06 15:15:25 sandervl Exp $ */
    22
    33/*
    44 * PELDR main exe loader code
    55 *
    6  * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
     6 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
    77 *
     8 * Command line options:
     9 *   /OPT:[x1=y,x2=z,..]         
     10 *   x = CURDIR    -> set current directory to y
     11 *   (not other options available at this time)
    812 *
    913 * Project Odin Software License can be found in LICENSE.TXT
     
    6367
    6468//should be the same as in ..\kernel32\winexepeldr.h
    65 typedef BOOL (* WIN32API WIN32CTOR)(char *, char *, ULONG, BOOL);
     69typedef BOOL (* WIN32API WIN32CTOR)(char *, char *, char *, ULONG, BOOL);
    6670
    6771WIN32CTOR   CreateWin32Exe       = 0;
     
    8387 PTIB   ptib;
    8488 PPIB   ppib;
    85  char  *cmdline, *win32cmdline;
     89 char  *cmdline, *win32cmdline, *peoptions, *newcmdline;
    8690 BOOL   fQuote = FALSE;
    8791 int    nrTries = 1;
     
    9296                cmdline = ppib->pib_pchcmd;
    9397                cmdline += strlen(cmdline)+1;   //skip pe.exe
     98                peoptions = strstr(cmdline, "/OPT:[");
     99                if(peoptions) {
     100                        newcmdline = strchr(peoptions, ']');
     101                        if(newcmdline) {
     102                                cmdline = newcmdline+1;
     103                        }
     104                        else    DebugInt3();    //should not happen!
     105                }               
    94106                while(*cmdline == ' ')  cmdline++; //skip leading space
    95107                if(*cmdline == '"') {
     
    186198        goto fail;
    187199  }
    188   rc = DosQueryProcAddr(hmodKernel32, 0, "_CreateWin32PeLdrExe@16", (PFN *)&CreateWin32Exe);
    189 
    190   if(CreateWin32Exe(exeName, win32cmdline, reservedMemory, fConsoleApp) == FALSE) {
     200  rc = DosQueryProcAddr(hmodKernel32, 0, "_CreateWin32PeLdrExe@20", (PFN *)&CreateWin32Exe);
     201
     202  if(CreateWin32Exe(exeName, win32cmdline, peoptions, reservedMemory, fConsoleApp) == FALSE) {
    191203        goto fail;
    192204  }
Note: See TracChangeset for help on using the changeset viewer.