Ignore:
Timestamp:
Apr 16, 2001, 9:29:52 PM (24 years ago)
Author:
umoeller
Message:

Various fixes for V0.9.10.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/dosh2.c

    r57 r59  
    810810 *@@changed V0.9.1 (2000-02-13) [umoeller]: fixed 32-bits flag
    811811 *@@changed V0.9.7 (2000-12-20) [lafaix]: fixed ulNewHeaderOfs
     812 *@@changed V0.9.10 (2001-04-08) [lafaix]: added PE support
    812813 *@@changed V0.9.10 (2001-04-08) [umoeller]: now setting ppExec only if NO_ERROR is returned
    813814 */
     
    945946                            else if (memcmp(achNewHeaderType, "PE", 2) == 0)
    946947                            {
     948                                PEHEADER PEHeader = {0};
     949
    947950                                pExec->ulExeFormat = EXEFORMAT_PE;
    948951                                pExec->ulOS = EXEOS_WIN32;
    949952                                pExec->f32Bits = TRUE;
    950953
    951                                 // can't parse this yet
     954                                // V0.9.10 (2001-04-08) [lafaix]
     955                                // read in standard PE header
     956                                if (!(arc = DosRead(hFile,
     957                                                    &PEHeader,
     958                                                    24,
     959                                                    &ulBytesRead)))
     960                                {
     961                                    // allocate PE header
     962                                    pExec->pPEHeader = (PPEHEADER)malloc(24 + PEHeader.usHeaderSize);
     963                                    if (!(pExec->pPEHeader))
     964                                        arc = ERROR_NOT_ENOUGH_MEMORY;
     965                                    else
     966                                    {
     967                                        // copy standard PE header
     968                                        memcpy(pExec->pPEHeader,
     969                                               &PEHeader,
     970                                               24);
     971
     972                                        // read in optional PE header
     973                                        if (!(arc = DosRead(hFile,
     974                                                            &(pExec->pPEHeader->usReserved3),
     975                                                            PEHeader.usHeaderSize,
     976                                                            &(pExec->cbPEHeader))))
     977                                            pExec->cbPEHeader += 24;
     978                                    }
     979                                }
    952980                            }
    953981                            else
     
    12431271 *@@changed V0.9.9 (2001-04-03) [umoeller]: added tons of error checking, changed prototype to return APIRET
    12441272 *@@changed V0.9.9 (2001-04-05) [lafaix]: rewritten error checking code
     1273 *@@changed V0.9.10 (2001-04-10) [lafaix]: added Win16 and Win386 support
     1274 *@@changed V0.9.10 (2001-04-13) [lafaix]: removed 127 characters limit
    12451275 */
    12461276
     
    12501280{
    12511281    if (    (pExec)
    1252          && (pExec->ulOS == EXEOS_OS2)
     1282         && (    (pExec->ulOS == EXEOS_OS2)
     1283              || (pExec->ulOS == EXEOS_WIN16)
     1284              || (pExec->ulOS == EXEOS_WIN386)
     1285            )
    12531286       )
    12541287    {
     
    12861319                    // reading the length of the module name
    12871320                    ENSURE_SAFE(DosRead(pExec->hfExe, &bLen, 1, &ulDummy));
    1288 
    1289                     // At most 127 bytes
    1290                     bLen &= 0x7F;
    12911321
    12921322                    // reading the module name
     
    13041334        else if (pExec->ulExeFormat == EXEFORMAT_NE)
    13051335        {
    1306             // 16-bit OS/2 executable:
     1336            // 16-bit executable:
    13071337            cModules = pExec->pNEHeader->usModuleTblEntries;
    13081338
     
    13451375
    13461376                    ENSURE_SAFE(DosRead(pExec->hfExe, &bLen, 1, &ulDummy));
    1347 
    1348                     bLen &= 0x7F;
    13491377
    13501378                    ENSURE_SAFE(DosRead(pExec->hfExe,
     
    16621690        ENSURE(DosRead(pExec->hfExe, &bType, 1, &ulDummy));
    16631691
    1664         for (i = 0; i < bCnt; i++)
     1692        if (bType)
    16651693        {
    1666             ENSURE(DosRead(pExec->hfExe,
    1667                            &bFlag,
    1668                            1,
    1669                            &ulDummy));
    1670 
    1671             if (bFlag & 0x01)
     1694            for (i = 0; i < bCnt; i++)
    16721695            {
    1673                 if (paFunctions)
     1696                ENSURE(DosRead(pExec->hfExe,
     1697                               &bFlag,
     1698                               1,
     1699                               &ulDummy));
     1700
     1701                if (bFlag & 0x01)
    16741702                {
    1675                     paFunctions[usCurrent].ulOrdinal = usOrdinal;
    1676                     paFunctions[usCurrent].ulType = 1; // 16-bit entry
    1677                     paFunctions[usCurrent].achFunctionName[0] = 0;
     1703                    if (paFunctions)
     1704                    {
     1705                        paFunctions[usCurrent].ulOrdinal = usOrdinal;
     1706                        paFunctions[usCurrent].ulType = 1; // 16-bit entry
     1707                        paFunctions[usCurrent].achFunctionName[0] = 0;
     1708                    }
     1709                    usCurrent++;
    16781710                }
    1679                 usCurrent++;
    1680             }
    1681 
    1682             usOrdinal++;
    1683 
    1684             if (bType == 0xFF)
    1685             {
    1686                 // moveable segment
    1687                 ENSURE(DosSetFilePtr(pExec->hfExe,
    1688                                      5,
    1689                                      FILE_CURRENT,
    1690                                      &ulDummy));
    1691             }
    1692             else
    1693             {
    1694                 // fixed segment
    1695                 ENSURE(DosSetFilePtr(pExec->hfExe,
    1696                                      2,
    1697                                      FILE_CURRENT,
    1698                                      &ulDummy));
    1699             }
    1700 
    1701         } // end for
     1711
     1712                usOrdinal++;
     1713
     1714                if (bType == 0xFF)
     1715                {
     1716                    // moveable segment
     1717                    ENSURE(DosSetFilePtr(pExec->hfExe,
     1718                                         5,
     1719                                         FILE_CURRENT,
     1720                                         &ulDummy));
     1721                }
     1722                else
     1723                {
     1724                    // fixed segment or constant (0xFE)
     1725                    ENSURE(DosSetFilePtr(pExec->hfExe,
     1726                                         2,
     1727                                         FILE_CURRENT,
     1728                                         &ulDummy));
     1729                }
     1730
     1731            } // end for
     1732        }
     1733        else
     1734            usOrdinal += bCnt;
    17021735    } // end while (TRUE)
    17031736
     
    18151848 *@@changed V0.9.9 (2001-04-03) [umoeller]: added tons of error checking, changed prototype to return APIRET
    18161849 *@@changed V0.9.9 (2001-04-05) [lafaix]: rewritten error checking code
     1850 *@@changed V0.9.10 (2001-04-10) [lafaix]: added Win16 and Win386 support
    18171851 */
    18181852
     
    18221856{
    18231857    if (    (pExec)
    1824          && (pExec->ulOS == EXEOS_OS2)
     1858         && (    (pExec->ulOS == EXEOS_OS2)
     1859              || (pExec->ulOS == EXEOS_WIN16)
     1860              || (pExec->ulOS == EXEOS_WIN386)
     1861            )
    18251862       )
    18261863    {
     
    18801917        else if (pExec->ulExeFormat == EXEFORMAT_NE)
    18811918        {
    1882             // It's a 16bit OS/2 executable
     1919            // it's a "new" segmented 16bit executable
    18831920
    18841921            // here too the number of exported entry points
     
    19802017 *@@added V0.9.7 (2000-12-18) [lafaix]
    19812018 *@@changed V0.9.9 (2001-04-03) [umoeller]: added tons of error checking, changed prototype to return APIRET
     2019 *@@changed V0.9.10 (2001-04-10) [lafaix]: added Win16 and Win386 support
    19822020 */
    19832021
     
    19872025{
    19882026    if (    (pExec)
    1989          && (pExec->ulOS == EXEOS_OS2)
     2027         && (    (pExec->ulOS == EXEOS_OS2)
     2028              || (pExec->ulOS == EXEOS_WIN16)
     2029              || (pExec->ulOS == EXEOS_WIN386)
     2030            )
    19902031       )
    19912032    {
     
    20822123        else if (pExec->ulExeFormat == EXEFORMAT_NE)
    20832124        {
    2084             // 16-bit OS/2 executable:
    2085             cResources = pExec->pNEHeader->usResSegmCount;
    2086 
    2087             if (cResources)
     2125            if (pExec->ulOS == EXEOS_OS2)
    20882126            {
    2089                 #pragma pack(1)     // V0.9.9 (2001-04-02) [umoeller]
    2090                 struct {unsigned short type; unsigned short name;} rti;
    2091                 struct new_seg                          /* New .EXE segment table entry */
     2127                // 16-bit OS/2 executable:
     2128                cResources = pExec->pNEHeader->usResSegmCount;
     2129
     2130                if (cResources)
    20922131                {
    2093                     unsigned short      ns_sector;      /* File sector of start of segment */
    2094                     unsigned short      ns_cbseg;       /* Number of bytes in file */
    2095                     unsigned short      ns_flags;       /* Attribute flags */
    2096                     unsigned short      ns_minalloc;    /* Minimum allocation in bytes */
    2097                 } ns;
    2098                 #pragma pack()
    2099 
    2100                 ULONG cb = sizeof(FSYSRESOURCE) * cResources;
    2101                 ULONG ulDummy;
    2102                 int i;
    2103 
    2104                 paResources = (PFSYSRESOURCE)malloc(cb);
    2105                 if (!paResources)
    2106                     ENSURE_FAIL(ERROR_NOT_ENOUGH_MEMORY);
    2107 
    2108                 memset(paResources, 0, cb);     // V0.9.9 (2001-04-03) [umoeller]
    2109 
    2110                 // we first read the resources IDs and types
    2111 
    2112                 ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
    2113                                           pExec->pNEHeader->usResTblOfs
    2114                                             + pExec->pDosExeHeader->ulNewHeaderOfs,
    2115                                           FILE_BEGIN,
    2116                                           &ulDummy));
    2117 
    2118                 for (i = 0; i < cResources; i++)
     2132                    #pragma pack(1)     // V0.9.9 (2001-04-02) [umoeller]
     2133                    struct {unsigned short type; unsigned short name;} rti;
     2134                    struct new_seg                          /* New .EXE segment table entry */
     2135                    {
     2136                        unsigned short      ns_sector;      /* File sector of start of segment */
     2137                        unsigned short      ns_cbseg;       /* Number of bytes in file */
     2138                        unsigned short      ns_flags;       /* Attribute flags */
     2139                        unsigned short      ns_minalloc;    /* Minimum allocation in bytes */
     2140                    } ns;
     2141                    #pragma pack()
     2142
     2143                    ULONG cb = sizeof(FSYSRESOURCE) * cResources;
     2144                    ULONG ulDummy;
     2145                    int i;
     2146
     2147                    paResources = (PFSYSRESOURCE)malloc(cb);
     2148                    if (!paResources)
     2149                        ENSURE_FAIL(ERROR_NOT_ENOUGH_MEMORY);
     2150
     2151                    memset(paResources, 0, cb);     // V0.9.9 (2001-04-03) [umoeller]
     2152
     2153                    // we first read the resources IDs and types
     2154
     2155                    ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2156                                              pExec->pNEHeader->usResTblOfs
     2157                                                + pExec->pDosExeHeader->ulNewHeaderOfs,
     2158                                              FILE_BEGIN,
     2159                                              &ulDummy));
     2160
     2161                    for (i = 0; i < cResources; i++)
     2162                    {
     2163                        ENSURE_SAFE(DosRead(pExec->hfExe, &rti, sizeof(rti), &ulDummy));
     2164
     2165                        paResources[i].ulID = rti.name;
     2166                        paResources[i].ulType = rti.type;
     2167                    }
     2168
     2169                    // we then read their sizes and flags
     2170
     2171                    for (i = 0; i < cResources; i++)
     2172                    {
     2173                        ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2174                                                  pExec->pDosExeHeader->ulNewHeaderOfs
     2175                                                    + pExec->pNEHeader->usSegTblOfs
     2176                                                    + (sizeof(ns)
     2177                                                    * (  pExec->pNEHeader->usSegTblEntries
     2178                                                       - pExec->pNEHeader->usResSegmCount
     2179                                                       + i)),
     2180                                                    FILE_BEGIN,
     2181                                                    &ulDummy));
     2182
     2183                        ENSURE_SAFE(DosRead(pExec->hfExe, &ns, sizeof(ns), &ulDummy));
     2184
     2185                        paResources[i].ulSize = ns.ns_cbseg;
     2186
     2187                        paResources[i].ulFlag  = (ns.ns_flags & OBJPRELOAD) ? RNPRELOAD : 0;
     2188                        paResources[i].ulFlag |= (ns.ns_flags & OBJSHARED) ? RNPURE : 0;
     2189                        paResources[i].ulFlag |= (ns.ns_flags & OBJDISCARD) ? RNMOVE : 0;
     2190                        paResources[i].ulFlag |= (ns.ns_flags & OBJDISCARD) ? 4096 : 0;
     2191                    }
     2192                } // end if (cResources)
     2193            }
     2194            else
     2195            {
     2196                // 16-bit Windows executable
     2197                USHORT usAlignShift;
     2198                ULONG  ulDummy;
     2199
     2200                ENSURE(DosSetFilePtr(pExec->hfExe,
     2201                                     pExec->pNEHeader->usResTblOfs
     2202                                       + pExec->pDosExeHeader->ulNewHeaderOfs,
     2203                                     FILE_BEGIN,
     2204                                     &ulDummy));
     2205
     2206                ENSURE(DosRead(pExec->hfExe,
     2207                               &usAlignShift,
     2208                               sizeof(usAlignShift),
     2209                               &ulDummy));
     2210
     2211                while (TRUE)
    21192212                {
    2120                     ENSURE_SAFE(DosRead(pExec->hfExe, &rti, sizeof(rti), &ulDummy));
    2121 
    2122                     paResources[i].ulID = rti.name;
    2123                     paResources[i].ulType = rti.type;
     2213                    USHORT usTypeID;
     2214                    USHORT usCount;
     2215
     2216                    ENSURE(DosRead(pExec->hfExe,
     2217                                   &usTypeID,
     2218                                   sizeof(usTypeID),
     2219                                   &ulDummy));
     2220
     2221                    if (usTypeID == 0)
     2222                        break;
     2223
     2224                    ENSURE(DosRead(pExec->hfExe,
     2225                                   &usCount,
     2226                                   sizeof(usCount),
     2227                                   &ulDummy));
     2228
     2229                    ENSURE(DosSetFilePtr(pExec->hfExe,
     2230                                         sizeof(ULONG),
     2231                                         FILE_CURRENT,
     2232                                         &ulDummy));
     2233
     2234                    cResources += usCount;
     2235
     2236                    // first pass, skip NAMEINFO table
     2237                    ENSURE(DosSetFilePtr(pExec->hfExe,
     2238                                         usCount*6*sizeof(USHORT),
     2239                                         FILE_CURRENT,
     2240                                         &ulDummy));
    21242241                }
    21252242
    2126                 // we then read their sizes and flags
    2127 
    2128                 for (i = 0; i < cResources; i++)
     2243                if (cResources)
    21292244                {
     2245                    USHORT usCurrent = 0;
     2246                    ULONG cb = sizeof(FSYSRESOURCE) * cResources;
     2247
     2248                    paResources = (PFSYSRESOURCE)malloc(cb);
     2249                    if (!paResources)
     2250                        ENSURE_FAIL(ERROR_NOT_ENOUGH_MEMORY);
     2251
     2252                    memset(paResources, 0, cb);
     2253
    21302254                    ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
    2131                                               pExec->pDosExeHeader->ulNewHeaderOfs
    2132                                                 + pExec->pNEHeader->usSegTblOfs
    2133                                                 + (sizeof(ns)
    2134                                                 * (  pExec->pNEHeader->usSegTblEntries
    2135                                                    - pExec->pNEHeader->usResSegmCount
    2136                                                    + i)),
    2137                                                 FILE_BEGIN,
     2255                                              pExec->pNEHeader->usResTblOfs
     2256                                                + pExec->pDosExeHeader->ulNewHeaderOfs,
     2257                                              FILE_BEGIN,
     2258                                              &ulDummy));
     2259
     2260                    ENSURE_SAFE(DosRead(pExec->hfExe,
     2261                                        &usAlignShift,
     2262                                        sizeof(usAlignShift),
     2263                                        &ulDummy));
     2264
     2265                    while (TRUE)
     2266                    {
     2267                        USHORT usTypeID;
     2268                        USHORT usCount;
     2269                        int i;
     2270
     2271                        ENSURE_SAFE(DosRead(pExec->hfExe,
     2272                                            &usTypeID,
     2273                                            sizeof(usTypeID),
     2274                                            &ulDummy));
     2275
     2276                        if (usTypeID == 0)
     2277                            break;
     2278
     2279                        ENSURE_SAFE(DosRead(pExec->hfExe,
     2280                                            &usCount,
     2281                                            sizeof(usCount),
     2282                                            &ulDummy));
     2283
     2284                        ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2285                                                  sizeof(ULONG),
     2286                                                  FILE_CURRENT,
     2287                                                  &ulDummy));
     2288
     2289                        // second pass, read NAMEINFO table
     2290                        for (i = 0; i < usCount; i++)
     2291                        {
     2292                            USHORT usLength,
     2293                                   usFlags,
     2294                                   usID;
     2295
     2296                            ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2297                                                      sizeof(USHORT),
     2298                                                      FILE_CURRENT,
     2299                                                      &ulDummy));
     2300
     2301                            ENSURE_SAFE(DosRead(pExec->hfExe,
     2302                                                &usLength,
     2303                                                sizeof(USHORT),
    21382304                                                &ulDummy));
    2139 
    2140                     ENSURE_SAFE(DosRead(pExec->hfExe, &ns, sizeof(ns), &ulDummy));
    2141 
    2142                     paResources[i].ulSize = ns.ns_cbseg;
    2143 
    2144                     paResources[i].ulFlag  = (ns.ns_flags & OBJPRELOAD) ? RNPRELOAD : 0;
    2145                     paResources[i].ulFlag |= (ns.ns_flags & OBJSHARED) ? RNPURE : 0;
    2146                     paResources[i].ulFlag |= (ns.ns_flags & OBJDISCARD) ? RNMOVE : 0;
    2147                     paResources[i].ulFlag |= (ns.ns_flags & OBJDISCARD) ? 4096 : 0;
     2305                            ENSURE_SAFE(DosRead(pExec->hfExe,
     2306                                                &usFlags,
     2307                                                sizeof(USHORT),
     2308                                                &ulDummy));
     2309                            ENSURE_SAFE(DosRead(pExec->hfExe,
     2310                                                &usID,
     2311                                                sizeof(USHORT),
     2312                                                &ulDummy));
     2313
     2314                            ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2315                                                      2*sizeof(USHORT),
     2316                                                      FILE_CURRENT,
     2317                                                      &ulDummy));
     2318
     2319                            // !!! strings ids and types not handled yet
     2320                            // !!! 15th bit is used to denotes strings
     2321                            // !!! offsets [lafaix]
     2322                            paResources[usCurrent].ulType = usTypeID ^ 0x8000;
     2323                            paResources[usCurrent].ulID = usID ^ 0x8000;
     2324                            paResources[usCurrent].ulSize = usLength << usAlignShift;
     2325                            paResources[usCurrent].ulFlag = usFlags & 0x70;
     2326
     2327                            usCurrent++;
     2328                        }
     2329                    }
    21482330                }
    2149             } // end if (cResources)
     2331            }
    21502332        } // end else if (pExec->ulExeFormat == EXEFORMAT_NE)
    21512333        else
Note: See TracChangeset for help on using the changeset viewer.