Changeset 124


Ignore:
Timestamp:
Dec 17, 2001, 12:21:18 AM (24 years ago)
Author:
umoeller
Message:

Lots of changes for icons and refresh.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/dosh.h

    r123 r124  
    531531    typedef struct _NEHEADER
    532532    {
    533         CHAR      achNE[2];             // 00: "NE" magic
    534         BYTE      bLinkerVersion;       // 02: linker version
    535         BYTE      bLinkerRevision;      // 03: linker revision
    536         USHORT    usEntryTblOfs;        // 04: ofs from this to entrytable
    537         USHORT    usEntryTblLen;        // 06: length of entrytable
    538         ULONG     ulChecksum;           // 08: MS: reserved, OS/2: checksum
    539         USHORT    usFlags;              // 0c: flags
     533        CHAR      achNE[2];             // 00: "NE" magic                       ne_magic
     534        BYTE      bLinkerVersion;       // 02: linker version                   ne_ver
     535        BYTE      bLinkerRevision;      // 03: linker revision                  ne_rev
     536        USHORT    usEntryTblOfs;        // 04: ofs from this to entrytable      ne_enttab
     537        USHORT    usEntryTblLen;        // 06: length of entrytable             ne_cbenttab
     538        ULONG     ulChecksum;           // 08: MS: reserved, OS/2: checksum     ne_crc
     539        USHORT    usFlags;              // 0c: flags                            ne_flags
    540540                           /*
    541541                              #define NENOTP          0x8000          // Not a process == library
    542542                              #define NENOTMPSAFE     0x4000          // Process is not multi-processor safe
     543                                                                      // (Win3.1 SDK: "reserved")
    543544                              #define NEIERR          0x2000          // Errors in image
    544545                              #define NEBOUND         0x0800          // Bound Family/API
     546                                                                      // (Win3.1 SDK: "first segment contains code
     547                                                                      // that loads the application")
    545548                              #define NEAPPTYP        0x0700          // Application type mask
     549                                                                      // (Win3.1 SDK: "reserved")
    546550                              #define NENOTWINCOMPAT  0x0100          // Not compatible with P.M. Windowing
     551                                                                      // (Win3.1 SDK: "reserved")
    547552                              #define NEWINCOMPAT     0x0200          // Compatible with P.M. Windowing
     553                                                                      // (Win3.1 SDK: "reserved")
    548554                              #define NEWINAPI        0x0300          // Uses P.M. Windowing API
     555                                                                      // (Win3.1 SDK: "reserved")
    549556                              #define NEFLTP          0x0080          // Floating-point instructions
    550557                              #define NEI386          0x0040          // 386 instructions
     
    552559                              #define NEI086          0x0010          // 8086 instructions
    553560                              #define NEPROT          0x0008          // Runs in protected mode only
     561                                                                      // (Win3.1 SDK: "reserved")
    554562                              #define NEPPLI          0x0004          // Per-Process Library Initialization
     563                                                                      // (Win3.1 SDK: "reserved")
    555564                              #define NEINST          0x0002          // Instance data
    556565                              #define NESOLO          0x0001          // Solo data (single data)
    557566                           */
    558         USHORT    usAutoDataSegNo;      // 0e: auto-data seg no.
    559         USHORT    usInitlHeapSize;      // 10: initl. heap size
    560         USHORT    usInitlStackSize;     // 12: initl. stack size
    561         ULONG     ulCSIP;               // 14: CS:IP
    562         ULONG     ulSSSP;               // 18: SS:SP
    563         USHORT    usSegTblEntries;      // 1c: segment tbl entry count
    564         USHORT    usModuleTblEntries;   // 1e: module ref. table entry count
    565         USHORT    usNonResdTblLen;      // 20: non-resd. name tbl length
    566         USHORT    usSegTblOfs;          // 22: segment tbl ofs
    567         USHORT    usResTblOfs;          // 24: resource tbl ofs
    568         USHORT    usResdNameTblOfs;     // 26: resd. name tbl ofs
    569         USHORT    usModRefTblOfs;       // 28: module ref. table ofs
    570         USHORT    usImportTblOfs;       // 2a: import tbl ofs
    571         ULONG     ulNonResdTblOfs;      // 2c: non-resd. name tbl ofs
    572         USHORT    usMoveableEntries;    // 30: moveable entry pts. count
    573         USHORT    usLogicalSectShift;   // 32: logcl. sector shift
    574         USHORT    usResSegmCount;       // 34: resource segm. count
    575         BYTE      bTargetOS;            // 36: target OS (NEOS_* flags)
    576         BYTE      bFlags2;              // 37: addtl. flags
     567        USHORT    usAutoDataSegNo;      // 0e: auto-data seg no.                ne_autodata
     568                                        // (Win3.1 SDK: "0 if both NEINST and NESOLO are cleared")
     569        USHORT    usInitlHeapSize;      // 10: initl. heap size                 ne_heap
     570                                        // (Win3.1 SDK: "0 if no local allocation")
     571        USHORT    usInitlStackSize;     // 12: initl. stack size                ne_stack
     572                                        // (Win3.1 SDK: "0 if SS != DS")
     573        ULONG     ulCSIP;               // 14: CS:IP                            ne_csip
     574        ULONG     ulSSSP;               // 18: SS:SP                            ne_sssp
     575        USHORT    usSegTblEntries;      // 1c: segment tbl entry count          ne_cseg
     576        USHORT    usModuleTblEntries;   // 1e: module ref. table entry count    ne_cmod
     577        USHORT    usNonResdTblLen;      // 20: non-resd. name tbl length        ne_cbnrestab
     578        USHORT    usSegTblOfs;          // 22: segment tbl ofs                  ne_segtab
     579                                        // (from start of NEHEADER)
     580        USHORT    usResTblOfs;          // 24: resource tbl ofs                 ne_rsrctab
     581                                        // (from start of NEHEADER)
     582        USHORT    usResdNameTblOfs;     // 26: resd. name tbl ofs               ne_restab
     583                                        // (from start of NEHEADER)
     584        USHORT    usModRefTblOfs;       // 28: module ref. table ofs            ne_modtab
     585                                        // (from start of NEHEADER)
     586        USHORT    usImportTblOfs;       // 2a: import name tbl ofs              ne_imptab
     587                                        // (from start of NEHEADER)
     588        ULONG     ulNonResdTblOfs;      // 2c: non-resd. name tbl ofs           ne_nrestab
     589                                        // (from start of EXE!)
     590        USHORT    usMoveableEntries;    // 30: moveable entry points count      ne_cmovent
     591        USHORT    usLogicalSectShift;   // 32: logcl. sector shift              ne_align
     592                                        // (Win3.1 SDK: "typically 4, but default is 9")
     593        USHORT    usResSegmCount;       // 34: resource segm. count             ne_cres
     594        BYTE      bTargetOS;            // 36: target OS (NEOS_* flags)         ne_exetyp
     595        BYTE      bFlags2;              // 37: addtl. flags                     ne_flagsothers
     596                                        // Win3.1 SDK:
     597                                        //      bit 1 --> Win2.x, but runs in Win3.x protected mode
     598                                        //      bit 2 --> Win2.x that supports prop. fonts
     599                                        //      bit 3 --> exec contains fastload area
     600                                /*
     601                                #define NELONGNAMES     0x01
     602                                #define NEWINISPROT     0x02
     603                                #define NEWINGETPROPFON 0x04
     604                                #define NEWLOAPPL       0x80
     605                                */
     606        // the following are not listed in newexe.h, but are documented for Win3.x
    577607        USHORT    usFastLoadOfs;        // 38: fast-load area ofs
    578608        USHORT    usFastLoadLen;        // 3a: fast-load area length
     
    780810    } LXITER, *PLXITER;
    781811
     812    /*
     813     *@@ OS2NERESTBLENTRY:
     814     *      OS/2 NE resource table entry.
     815     *
     816     *@@added V0.9.16 (2001-12-08) [umoeller]
     817     */
     818
     819    typedef struct _OS2NERESTBLENTRY
     820    {
     821        USHORT      usType;
     822        USHORT      usID;
     823    } OS2NERESTBLENTRY, *POS2NERESTBLENTRY;
     824
     825    /*
     826     *@@ OS2NESEGMENT:
     827     *      OS/2 NE segment definition.
     828     *
     829     *@@added V0.9.16 (2001-12-08) [umoeller]
     830     */
     831
     832    typedef struct _OS2NESEGMENT       // New .EXE segment table entry
     833    {
     834        unsigned short      ns_sector;      // File sector of start of segment
     835        unsigned short      ns_cbseg;       // Number of bytes in file
     836        unsigned short      ns_flags;       // Attribute flags
     837        unsigned short      ns_minalloc;    // Minimum allocation in bytes
     838    } OS2NESEGMENT, *POS2NESEGMENT;
     839
    782840    #pragma pack()
    783841
     
    902960        OBJECTPAGETABLEENTRY    *pObjPageTbl;   // pLXHeader->ulPageCount
    903961
     962        // the following fields are set after doshLoadOS2NEMaps
     963        BOOL                    fOS2NEMapsLoaded;
     964        POS2NERESTBLENTRY       paOS2NEResTblEntry;
     965        POS2NESEGMENT           paOS2NESegments;
     966
    904967#endif
    905968    } EXECUTABLE, *PEXECUTABLE;
     
    9701033
    9711034    VOID doshFreeLXMaps(PEXECUTABLE pExec);
     1035
     1036    APIRET doshLoadOS2NEMaps(PEXECUTABLE pExec);
     1037
     1038    VOID doshFreeNEMaps(PEXECUTABLE pExec);
    9721039
    9731040    APIRET doshExecClose(PEXECUTABLE *ppExec);
  • trunk/src/helpers/dosh2.c

    r123 r124  
    392392 *      -- ERROR_NOT_ENOUGH_MEMORY: malloc() failed.
    393393 *
    394  *      -- ERROR_INVALID_EXE_SIGNATURE: unknown
    395  *          executable type... the given file probably
    396  *          isn't even an executable.
     394 *      -- ERROR_INVALID_EXE_SIGNATURE (191): header is
     395 *              neither plain DOS, nor NE, nor LX, nor PE.
     396 *              The given file probably isn't even an
     397 *              executable. This you will get if you
     398 *              pass in COM, BAT, or CMD files.
     399 *
     400 *      -- ERROR_BAD_EXE_FORMAT (193): header was
     401 *              recognized, but the header data was
     402 *              not understood.
    397403 *
    398404 *      -- ERROR_INVALID_PARAMETER: ppExec is NULL.
     
    419425 *      I am not sure whether PE supports such things
    420426 *      as well... if so, it should be supported too.
     427 *
     428 *      @@todo:
     429 *
     430 *          win95 \WINDOWS\extract.exe is NE with a non-standard format
     431 *          win16 \WINDOWS\EXPAND.EXE
     432 *          win16 \WINDOWS\MSD.EXE"
    421433 *
    422434 *@@added V0.9.0 [umoeller]
     
    428440 *@@changed V0.9.16 (2001-12-08) [umoeller]: now using OPEN_SHARE_DENYWRITE
    429441 *@@changed V0.9.16 (2001-12-08) [umoeller]: fLibrary was never set, works for LX and NE now
     442 *@@changed V0.9.16 (2001-12-08) [umoeller]: some speed optimizations, changed some return codes
    430443 */
    431444
     
    496509                    // remove the DOS header info, since we have none
    497510                    // V0.9.12 (2001-05-03) [umoeller]
    498                     free (pExec->pDosExeHeader);
    499                     pExec->pDosExeHeader = 0;
     511                    FREE(pExec->pDosExeHeader);
    500512                }
    501513                else
     
    523535                    // was found) or pDosExeHeader->ulNewHeaderOfs
    524536                    // V0.9.12 (2001-05-03) [umoeller]
    525                     CHAR    achNewHeaderType[2] = "";
    526537                    ULONG   cbRead;
    527 
    528                     cbRead = sizeof(achNewHeaderType);
    529                     if (!(arc = doshReadAt(hFile,
    530                                            ulNewHeaderOfs,
    531                                            FILE_BEGIN,
    532                                            &cbRead,
    533                                            achNewHeaderType)))
     538                    PBYTE   pbHeader;
     539
     540                    // now, we used to read in the first two chars
     541                    // to check out if we have PE or LX or NE and
     542                    // then read the header accordingly... but
     543                    // that wasn't terribly efficient. So load
     544                    // a chunk of data and then do a realloc()
     545                    // instead.
     546
     547                    // take the largest of LXHEADER and NEHEADER and PEHEADER
     548                    cbRead = sizeof(LXHEADER);
     549                    if (sizeof(NEHEADER) > cbRead)
     550                        cbRead = sizeof(NEHEADER);
     551                    if (sizeof(PEHEADER) > cbRead)
     552                        cbRead = sizeof(PEHEADER);
     553
     554                    if (!(pbHeader = malloc(cbRead)))
     555                        arc = ERROR_NOT_ENOUGH_MEMORY;
     556                    else if (!(arc = doshReadAt(hFile,
     557                                                ulNewHeaderOfs,
     558                                                FILE_BEGIN,
     559                                                &cbRead,
     560                                                pbHeader)))
    534561                    {
    535562                        PBYTE   pbCheckOS = NULL;
    536563
    537                         // reset file ptr
    538                         /* DosSetFilePtr(hFile,
    539                                       ulNewHeaderOfs,
    540                                       FILE_BEGIN,
    541                                       &ulLocal);
    542                            */
     564                        PSZ     achNewHeaderType = (PSZ)pbHeader;
    543565
    544566                        if (!memcmp(achNewHeaderType, "NE", 2))
     
    546568                            // New Executable:
    547569                            pExec->ulExeFormat = EXEFORMAT_NE;
    548                             // allocate NE header
    549                             if (pExec->pNEHeader = (PNEHEADER)malloc(sizeof(NEHEADER)))
     570
     571                            if (cbRead < sizeof(NEHEADER))
    550572                            {
    551                                 // read in NE header
    552                                 pExec->cbNEHeader = sizeof(NEHEADER);
    553                                 if (!(arc = doshReadAt(hFile,
    554                                                        ulNewHeaderOfs,
    555                                                        FILE_BEGIN,
    556                                                        &pExec->cbNEHeader,
    557                                                        (PBYTE)pExec->pNEHeader)))
    558                                 {
    559                                     if (pExec->cbNEHeader == sizeof(NEHEADER))
    560                                     {
    561                                         pbCheckOS = &pExec->pNEHeader->bTargetOS;
    562                                         // set library flag V0.9.16 (2001-12-08) [umoeller]
    563                                         if (pExec->pNEHeader->usFlags & 0x8000)
    564                                             // library:
    565                                             pExec->fLibrary = TRUE;
    566                                     }
    567                                     else
    568                                         // V0.9.16 (2001-12-08) [umoeller]
    569                                         arc = ERROR_INVALID_EXE_SIGNATURE;
    570                                 }
     573                                arc = ERROR_BAD_EXE_FORMAT;
     574                                FREE(pbHeader);
    571575                            }
    572576                            else
    573                                 arc = ERROR_NOT_ENOUGH_MEMORY;
     577                            {
     578                                pExec->pNEHeader = (PNEHEADER)realloc(pbHeader,
     579                                                                      sizeof(NEHEADER));
     580                                pExec->cbNEHeader = sizeof(NEHEADER);
     581                                pbCheckOS = &pExec->pNEHeader->bTargetOS;
     582                                // set library flag V0.9.16 (2001-12-08) [umoeller]
     583                                if (pExec->pNEHeader->usFlags & 0x8000)
     584                                    // library:
     585                                    pExec->fLibrary = TRUE;
     586                            }
    574587                        }
    575                         else if (   (memcmp(achNewHeaderType, "LX", 2) == 0)
    576                                  || (memcmp(achNewHeaderType, "LE", 2) == 0)
     588                        else if (    (!memcmp(achNewHeaderType, "LX", 2))
     589                                  || (!memcmp(achNewHeaderType, "LE", 2))
    577590                                            // this is used by SMARTDRV.EXE
    578591                                )
     
    580593                            // OS/2 Linear Executable:
    581594                            pExec->ulExeFormat = EXEFORMAT_LX;
    582                             // allocate LX header
    583                             if (pExec->pLXHeader = (PLXHEADER)malloc(sizeof(LXHEADER)))
     595
     596                            if (cbRead < sizeof(LXHEADER))
    584597                            {
     598                                arc = ERROR_BAD_EXE_FORMAT;
     599                                FREE(pbHeader);
     600                            }
     601                            else
     602                            {
     603                                pExec->pLXHeader = (PLXHEADER)realloc(pbHeader,
     604                                                                      sizeof(LXHEADER));
    585605                                // read in LX header
    586606                                pExec->cbLXHeader = sizeof(LXHEADER);
    587                                 if (!(arc = doshReadAt(hFile,
    588                                                        ulNewHeaderOfs,
    589                                                        FILE_BEGIN,
    590                                                        &pExec->cbLXHeader,
    591                                                        (PBYTE)pExec->pLXHeader)))
     607                                pbCheckOS = (PBYTE)(&pExec->pLXHeader->usTargetOS);
     608                                // set library flag V0.9.16 (2001-12-08) [umoeller]
     609                                if (pExec->pLXHeader->ulFlags & 0x8000)
     610                                    // library:
     611                                    pExec->fLibrary = TRUE;
     612                            }
     613                        }
     614                        else if (!memcmp(achNewHeaderType, "PE", 2))
     615                        {
     616                            pExec->ulExeFormat = EXEFORMAT_PE;
     617
     618                            if (cbRead < sizeof(PEHEADER))
     619                            {
     620                                arc = ERROR_BAD_EXE_FORMAT;
     621                                FREE(pbHeader);
     622                            }
     623                            else
     624                            {
     625                                // PE has a standard header of 24 bytes
     626                                // plus an extended header, so check what
     627                                // we've got
     628                                ULONG cbPE =   24
     629                                             + ((PPEHEADER)pbHeader)->usHeaderSize;
     630                                pExec->pPEHeader = (PPEHEADER)realloc(pbHeader,
     631                                                                      cbPE);
     632
     633                                pExec->cbPEHeader = cbPE;
     634                                pExec->ulOS = EXEOS_WIN32;
     635                                pExec->f32Bits = TRUE;
     636
     637                                // we have the first 24 bytes already, so
     638                                // go for the next chunk
     639                                if (cbRead = pExec->pPEHeader->usHeaderSize)
    592640                                {
    593                                     if (pExec->cbLXHeader == sizeof(LXHEADER))
     641                                    if (!(arc = doshReadAt(hFile,
     642                                                           ulNewHeaderOfs + 24,
     643                                                           FILE_BEGIN,
     644                                                           &cbRead,
     645                                                           (PBYTE)pExec->pPEHeader + 24)))
    594646                                    {
    595                                         pbCheckOS = (PBYTE)(&pExec->pLXHeader->usTargetOS);
    596                                         // set library flag V0.9.16 (2001-12-08) [umoeller]
    597                                         if (pExec->pLXHeader->ulFlags & 0x8000)
    598                                             // library:
    599                                             pExec->fLibrary = TRUE;
    600647                                    }
    601648                                    else
    602                                         // V0.9.16 (2001-12-08) [umoeller]
    603                                         arc = ERROR_INVALID_EXE_SIGNATURE;
     649                                        arc = ERROR_BAD_EXE_FORMAT;
    604650                                }
    605                             }
    606                             else
    607                                 arc = ERROR_NOT_ENOUGH_MEMORY;
    608                         }
    609                         else if (memcmp(achNewHeaderType, "PE", 2) == 0)
    610                         {
    611                             PEHEADER PEHeader = {0};
    612 
    613                             pExec->ulExeFormat = EXEFORMAT_PE;
    614                             pExec->ulOS = EXEOS_WIN32;
    615                             pExec->f32Bits = TRUE;
    616 
    617                             // V0.9.10 (2001-04-08) [lafaix]
    618                             // read in standard PE header
    619                             cbRead = 24;
    620                             if (!(arc = doshReadAt(hFile,
    621                                                    ulNewHeaderOfs,
    622                                                    FILE_BEGIN,
    623                                                    &cbRead,
    624                                                    (PBYTE)&PEHeader)))
    625                             {
    626                                 // allocate PE header
    627                                 if (pExec->pPEHeader = (PPEHEADER)malloc(24 + PEHeader.usHeaderSize))
    628                                 {
    629                                     // copy standard PE header
    630                                     memcpy(pExec->pPEHeader,
    631                                            &PEHeader,
    632                                            24);
    633 
    634                                     // read in optional PE header
    635                                     if (!(arc = DosRead(hFile,
    636                                                         &pExec->pPEHeader->usReserved3,
    637                                                         PEHeader.usHeaderSize,
    638                                                         &pExec->cbPEHeader)))
    639                                         pExec->cbPEHeader += 24;
    640                                 }
    641                                 else
    642                                     arc = ERROR_NOT_ENOUGH_MEMORY;
    643651                            }
    644652                        }
     
    648656
    649657                        if (pbCheckOS)
     658                        {
    650659                            // BYTE to check for operating system
    651660                            // (NE and LX):
     
    671680                                break;
    672681                            }
    673                     } // end if (!(arc = DosSetFilePtr(hFile,
     682                        }
     683                    }
    674684                }
    675685            } // end if (!(arc = DosSetFilePtr(hFile,
     
    18411851        {
    18421852            // 32-bit OS/2 executable:
    1843             if (cResources = pExec->pLXHeader->ulResTblCnt)
     1853            PLXHEADER pLXHeader = pExec->pLXHeader;
     1854            if (cResources = pLXHeader->ulResTblCnt)
    18441855            {
    18451856                #pragma pack(1)     // V0.9.9 (2001-04-02) [umoeller]
     
    18761887
    18771888                ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
    1878                                           pExec->pLXHeader->ulResTblOfs
     1889                                          pLXHeader->ulResTblOfs
    18791890                                            + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
    18801891                                          FILE_BEGIN,
     
    18961907                for (i = 0; i < cResources; i++)
    18971908                {
    1898                     ULONG ulOfsThis =   pExec->pLXHeader->ulObjTblOfs
     1909                    ULONG ulOfsThis =   pLXHeader->ulObjTblOfs
    18991910                                      + ulNewHeaderOfs // V0.9.12 (2001-05-03) [umoeller]
    19001911                                      + (   sizeof(ot)
     
    19251936        else if (pExec->ulExeFormat == EXEFORMAT_NE)
    19261937        {
     1938            PNEHEADER pNEHeader = pExec->pNEHeader;
     1939
    19271940            if (pExec->ulOS == EXEOS_OS2)
    19281941            {
    19291942                // 16-bit OS/2 executable:
    1930                 cResources = pExec->pNEHeader->usResSegmCount;
     1943                cResources = pNEHeader->usResSegmCount;
    19311944
    19321945                if (cResources)
     
    19561969
    19571970                    ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
    1958                                               pExec->pNEHeader->usResTblOfs
     1971                                              pNEHeader->usResTblOfs
    19591972                                                + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
    19601973                                              FILE_BEGIN,
     
    19751988                        ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
    19761989                                                  ulNewHeaderOfs // V0.9.12 (2001-05-03) [umoeller]
    1977                                                     + pExec->pNEHeader->usSegTblOfs
     1990                                                    + pNEHeader->usSegTblOfs
    19781991                                                    + (sizeof(ns)
    1979                                                     * (  pExec->pNEHeader->usSegTblEntries
    1980                                                        - pExec->pNEHeader->usResSegmCount
     1992                                                    * (  pNEHeader->usSegTblEntries
     1993                                                       - pNEHeader->usResSegmCount
    19811994                                                       + i)),
    19821995                                                    FILE_BEGIN,
     
    20012014
    20022015                ENSURE(DosSetFilePtr(pExec->hfExe,
    2003                                      pExec->pNEHeader->usResTblOfs
     2016                                     pNEHeader->usResTblOfs
    20042017                                       + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
    20052018                                     FILE_BEGIN,
     
    20552068
    20562069                    ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
    2057                                               pExec->pNEHeader->usResTblOfs
     2070                                              pNEHeader->usResTblOfs
    20582071                                                + ulNewHeaderOfs,
    20592072                                              FILE_BEGIN,
     
    22082221    APIRET arc;
    22092222
     2223    PLXHEADER pLXHeader;
     2224
    22102225    if (!pExec)
    22112226        arc = ERROR_INVALID_PARAMETER;
    2212     else if (pExec->ulExeFormat != EXEFORMAT_LX)
    2213         arc = ERROR_INVALID_EXE_SIGNATURE;
    22142227    else if (pExec->fLXMapsLoaded)
    22152228        // already loaded:
    22162229        arc = NO_ERROR;
     2230    else if (    (pExec->ulExeFormat != EXEFORMAT_LX)
     2231              || (!(pLXHeader = pExec->pLXHeader))
     2232            )
     2233        arc = ERROR_INVALID_EXE_SIGNATURE;
    22172234    else
    22182235    {
    2219         PLXHEADER pLXHeader = pExec->pLXHeader;
    22202236        ULONG ulNewHeaderOfs = 0;
    22212237        ULONG cb;
     
    22632279                                            (PBYTE)pExec->pObjPageTbl)))
    22642280                   )
    2265                   ;
     2281                {
     2282                }
    22662283            }
    22672284        }
     
    22902307    FREE(pExec->pObjPageTbl);
    22912308    pExec->fLXMapsLoaded = FALSE;
     2309}
     2310
     2311/*
     2312 *@@ doshLoadOS2NEMaps:
     2313 *
     2314 *      This works only if
     2315 *
     2316 *      --  ulExeFormat == EXEFORMAT_NE and
     2317 *
     2318 *      --  ulOS == EXEOS_OS2,
     2319 *
     2320 *      but not with Win16 NE executables.
     2321 *
     2322 *@@added V0.9.16 (2001-12-08) [umoeller]
     2323 */
     2324
     2325APIRET doshLoadOS2NEMaps(PEXECUTABLE pExec)
     2326{
     2327    APIRET arc;
     2328
     2329    PNEHEADER pNEHeader;
     2330
     2331    if (!pExec)
     2332        arc = ERROR_INVALID_PARAMETER;
     2333    else if (pExec->fOS2NEMapsLoaded)
     2334        // already loaded:
     2335        arc = NO_ERROR;
     2336    else if (    (pExec->ulExeFormat != EXEFORMAT_NE)
     2337              || (pExec->ulOS != EXEOS_OS2)
     2338              || (!(pNEHeader = pExec->pNEHeader))
     2339            )
     2340        arc = ERROR_INVALID_EXE_SIGNATURE;
     2341    else
     2342    {
     2343        ULONG ulNewHeaderOfs = 0;
     2344        ULONG cb;
     2345
     2346        if (pExec->pDosExeHeader)
     2347            // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
     2348            ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     2349
     2350        // resource table
     2351        if (    (!(arc = doshAllocArray(pNEHeader->usResSegmCount,
     2352                                        sizeof(OS2NERESTBLENTRY),
     2353                                        (PBYTE*)&pExec->paOS2NEResTblEntry,
     2354                                        &cb)))
     2355             && (!(arc = doshReadAt(pExec->hfExe,
     2356                                    pNEHeader->usResTblOfs
     2357                                      + ulNewHeaderOfs,
     2358                                    FILE_BEGIN,
     2359                                    &cb,
     2360                                    (PBYTE)pExec->paOS2NEResTblEntry)))
     2361            )
     2362        {
     2363            // resource segments
     2364            if (    (!(arc = doshAllocArray(pNEHeader->usResSegmCount,
     2365                                            sizeof(OS2NESEGMENT),
     2366                                            (PBYTE*)&pExec->paOS2NESegments,
     2367                                            &cb)))
     2368                 && (!(arc = doshReadAt(pExec->hfExe,
     2369                                        pNEHeader->usResTblOfs
     2370                                          + ulNewHeaderOfs
     2371                                          - cb, // pNEHeader->usResSegmCount * sizeof(struct new_seg)
     2372                                        FILE_BEGIN,
     2373                                        &cb,
     2374                                        (PBYTE)pExec->paOS2NESegments)))
     2375                )
     2376            {
     2377            }
     2378        }
     2379
     2380        if (!arc)
     2381            pExec->fOS2NEMapsLoaded = TRUE;
     2382        else
     2383            doshFreeNEMaps(pExec);
     2384    }
     2385
     2386    return (arc);
     2387}
     2388
     2389/*
     2390 *@@ doshFreeNEMaps:
     2391 *
     2392 *@@added V0.9.16 (2001-12-08) [umoeller]
     2393 */
     2394
     2395VOID doshFreeNEMaps(PEXECUTABLE pExec)
     2396{
     2397    FREE(pExec->paOS2NEResTblEntry);
     2398    FREE(pExec->paOS2NESegments);
     2399    pExec->fOS2NEMapsLoaded = FALSE;
    22922400}
    22932401
     
    23372445
    23382446        doshFreeLXMaps(pExec);
     2447        doshFreeNEMaps(pExec);
    23392448
    23402449        // fixed the memory leaks with the missing fields,
Note: See TracChangeset for help on using the changeset viewer.