Example #1
0
CV_uoff32_t
WINAPI
PHGetNearestHsym(
    LPADDR  lpaddr,
    HEXE    hexe,
    PHSYM   phsym
    )
{
    CV_uoff32_t dCur = CV_MAXOFFSET;
    LPEXE  lpexe;
    LPEXG  lpexg;

    *phsym = NULL;

    if (!VerifyHexe (hexe)) {
        return dCur;
    }

    SHWantSymbols(hexe);

    lpexe = (LPEXE) LLLock (hexe);

    if (lpexe->hexg != hexgNull) {
        lpexg = (LPEXG) LLLock (lpexe->hexg);
        *phsym = FindNearest (lpexg, lpaddr, (LPL) &dCur);
        LLUnlock(lpexe->hexg);
    }

    LLUnlock(hexe);

    return dCur;
}
Example #2
0
File: th.c Project: mingpen/OpenNT
HTYPE LOADDS PASCAL THGetTypeFromIndex ( HMOD hmod, THIDX index ) {
	HTYPE	htype = (HTYPE)NULL;

    if ( hmod && !CV_IS_PRIMITIVE (index) ) {
        HEXG hexg = SHHexgFromHmod ( hmod );
        LPEXG lpexg = LLLock ( hexg );
		
#ifdef HOST32 //{
		if (lpexg->ppdb) {
			assert (lpexg->ptpi);
			if (index < TypesQueryTiMac(lpexg->ptpi)) {
				if (!TypesQueryPbCVRecordForTi(lpexg->ptpi, index, (PB*) &htype)){
					htype = (HTYPE) NULL;
				}
			}
		}
		else {
			htype = NB09GetTypeFromIndex (lpexg, index);
		}
#else // }{
		htype = NB09GetTypeFromIndex (lpexg, index);
#endif // }
     	LLUnlock( hexg );
	 }
	return htype;
}
Example #3
0
LPCH
WINAPI
SLNameFromHmod (
    HMOD hmod,
    WORD iFile
    )
{
    LPCH    lpch  = NULL;
    LPMDS   lpmds;
    LPEXG   lpexg;

    if ((lpmds = (LPMDS) hmod) &&
        (lpexg = (LPEXG) LLLock (lpmds->hexg)))
    {
        UINT imod = lpmds->imds - 1;

        if (imod < lpexg->cMod && iFile <= lpexg->rgculFile [imod]) {
            lpch = lpexg->lpchFileNames +
                (lpexg->rgichFile [(WORD) (lpexg->rgiulFile [imod]) + iFile - 1]);
        }

        LLUnlock (lpmds->hexg);
    }

    return lpch;
}
Example #4
0
HSYM
WINAPI
FindNameInStatics(
    HSYM   hsym,
    PCXT   pcxt,
    LPSSTR lpsstr,
    SHFLAG fCase,
    PFNCMP pfnCmp,
    PCXT   pcxtOut
    )
{
    HEXG    hexg   = hexgNull;
    HMOD    hmod   = hmodNull;
    LPEXG   lpexg  = NULL;
    LPGST   lpgst  = NULL;
    SYMPTR  psym   = NULL;

    *pcxtOut = *pcxt;
    pcxtOut->hProc = NULL;
    pcxtOut->hBlk = NULL;

    if (!pcxt->hGrp) {
        return NULL;
    }

    hexg = SHHexgFromHmod (pcxt->hGrp);
    lpexg  = (LPEXG) LLLock (hexg);

    psym = FindNameHashedInStatics(lpexg, (SYMPTR) hsym, lpsstr, pfnCmp, fCase, &hmod);

    if (hmod != hmodNull) {
        pcxtOut->hMod = pcxt->hGrp = hmod;

        switch (psym->rectyp) {
            case S_LPROC32:
            case S_GPROC32:
            case S_LPROC16:
            case S_GPROC16:
            case S_LPROCMIPS:
            case S_GPROCMIPS:
                emiAddr (pcxtOut->addr) = (HEMI) SHHexeFromHmod (hmod);
                SHAddrFromHsym (&pcxtOut->addr, psym);
                SHHPROCFrompCXT(pcxtOut) = psym;
                break;

            default: {
                LPMDS lpmds = (LPMDS) hmod;

                SetAddrFromMod(lpmds, &pcxtOut->addr);
                emiAddr (pcxtOut->addr) = (HEMI) SHHexeFromHmod (hmod);
                ADDR_IS_LI (pcxtOut->addr) = TRUE;
                break;
            }
        }
    }

    LLUnlock (hexg);
    return psym;
}
Example #5
0
HSYM
WINAPI
SHFindNameInTypes(
    PCXT pcxt,
    LPSSTR lpsstr,
    SHFLAG fCase,
    PFNCMP pfnCmp,
    PCXT pcxtOut
    )
{
    HEXG    hexg   = hexgNull;
    LPEXG   lpexg  = NULL;
    UDTPTR  psym   = NULL;
    char    szBuf[256];
    unsigned iHash;
    TI ti;

    *pcxtOut = *pcxt;
    pcxtOut->hProc = NULL;
    pcxtOut->hBlk = NULL;

    if (!pcxt->hMod || ( lpsstr->searchmask & SSTR_NoHash )) {
        return NULL;
    }

    hexg = SHHexgFromHmod ( pcxt->hMod );

    lpexg  = (LPEXG)LLLock ( hexg );
    if (!lpexg->ptpi) {
        LLUnlock ( hexg );
        return NULL;
    }

    if (!STABFindUDTSym(lpexg->pstabUDTSym, lpsstr, pfnCmp, fCase, &psym, &iHash)) {
        TPI* ptpi = 0;
#ifdef HOST32
#if CC_LAZYTYPES
        if ( ((LPMDS)pcxt->hMod)->pmod ) {    /* use the mod's type server */
            ModQueryTpi( ((LPMDS)pcxt->hMod)->pmod, &ptpi );
        }
#endif
#endif
        if ( ptpi == 0 ) ptpi = lpexg->ptpi;
        lpStrToSz(lpsstr, szBuf);
        assert(ptpi);
        if (!TypesQueryTiForUDT(ptpi, szBuf, fCase, &ti) ||
            !STABAddUDTSym(lpexg->pstabUDTSym, lpsstr, iHash, &psym)) {
            LLUnlock ( hexg );
            return NULL;
        }
        assert(psym);
        psym->typind = ti;
    }

    LLUnlock ( hexg );
    return (SYMPTR) psym;
}
Example #6
0
LOCAL HST
HstFromLpmds (
    LPMDS lpmds
    )
{
    if (lpmds->hst != NULL) {
        return lpmds->hst;
    } else if (lpmds->pmod) {
        // Allocate space for this module's line number information,
        // then load it from the PDB and sort it.

        if (!ModQueryLines(lpmds->pmod, 0, (CB *)&lpmds->cbhst) ||
            !(lpmds->cbhst) ||
            !(lpmds->hst = MHAlloc(lpmds->cbhst)))
            return 0;

        if (ModQueryLines(lpmds->pmod, (PB)lpmds->hst, (CB *)&lpmds->cbhst)) {
            SortSM((LPSM)lpmds->hst);
            return lpmds->hst;
        } else {
            MHFree(lpmds->hst);
            lpmds->hst = 0;
            return 0;
        }
    } else if (lpmds->ulhst == 0) {
        return NULL;
    } else {
        assert(FALSE);          // We should never hit this code now
                                //  that we're mapped.
        LPEXG lpexg = (LPEXG) LLLock (lpmds->hexg);
        HANDLE hfile = SYOpen (lpexg->lszDebug);
        HST   hst   = MHAlloc ((UINT) lpmds->cbhst);

        if (hfile == INVALID_HANDLE_VALUE || hst == NULL) {
            LLUnlock (lpmds->hexg);
            return NULL;
        }

        if (SYSeek(hfile, lpmds->ulhst, SEEK_SET) != (LONG) lpmds->ulhst) {
            assert(FALSE);
        }

        if (SYReadFar (hfile, (LPB) hst, (UINT) lpmds->cbhst) != lpmds->cbhst) {
            assert (FALSE);
        }

        SYClose (hfile);

        lpmds->hst = hst;

        LLUnlock (lpmds->hexg);

        SortSM ((LPSM)hst);

        return hst;
    }
}
Example #7
0
HSYM
WINAPI
PHFindNameInPublics(
    HSYM    hsym,
    HEXE    hexe,
    LPSSTR  lpsstr,
    SHFLAG  fCase,
    PFNCMP  pfnCmp
    )
{
    SYMPTR psym = NULL;
    LPEXE  lpexe;
    LPEXG  lpexg;

    SHWantSymbols(hexe);

    if (hexe != hexeNull) {

        lpexe = (LPEXE) LLLock (hexe);

        if (lpexe->hexg == hexgNull) {
            psym = (SYMPTR)NULL;
        } else {
            lpexg  = (LPEXG) LLLock (lpexe->hexg);
            if (lpsstr->searchmask & SSTR_NoHash) {
                psym = FindNameLinearInPubs (lpexg, (SYMPTR)hsym, lpsstr, pfnCmp, fCase);
            } else {
                psym = FindNameHashedInPubs (lpexg, (SYMPTR)hsym, lpsstr, pfnCmp, fCase, NULL);
            }
            LLUnlock (lpexe->hexg);
        }

        LLUnlock (hexe);
    }

    return psym;
}
Example #8
0
HSYM
WINAPI
SHFindNameInGlobal(
    HSYM   hsym,
    PCXT   pcxt,
    LPSSTR lpsstr,
    SHFLAG fCase,
    PFNCMP pfnCmp,
    PCXT   pcxtOut
    )
{
    HEXG    hexg;
    LPEXG   lpexg;
    HEXE    hexe;
    LPEXE   lpexe;
    HMOD    hmod   = hmodNull;
    LPGST   lpgst  = NULL;
    SYMPTR  psym   = NULL;

    *pcxtOut = *pcxt;
    pcxtOut->hProc = NULL;
    pcxtOut->hBlk = NULL;

    if (!pcxt->hMod) {
        return NULL;
    }

    hexe    = SHHexeFromHmod(pcxt->hGrp ? pcxt->hGrp : pcxt->hMod);
    lpexe   = (LPEXE) LLLock(hexe);
    hexg    = lpexe->hexg;
    lpexg   = (LPEXG) LLLock (hexg);
    LLUnlock(hexe);

    // Make sure these symbols are loaded.
//    SHWantSymbols(hexe);

    if (lpsstr->searchmask & SSTR_NoHash) {
        psym = FindNameLinearInGlobs (lpexg, (SYMPTR) hsym, lpsstr, pfnCmp, fCase);
    } else {
        psym = FindNameHashedInGlobs (lpexg, (SYMPTR) hsym, lpsstr, pfnCmp, fCase, &hmod);

        if (hmod != hmodNull) {
            pcxtOut->hMod = pcxt->hGrp = hmod;

            switch (psym->rectyp) {

                case S_LPROC32:
                case S_GPROC32:
                case S_LPROC16:
                case S_GPROC16:
                case S_LPROCMIPS:
                case S_GPROCMIPS:
                    emiAddr (pcxtOut->addr) = (HEMI) SHHexeFromHmod (hmod);
                    SHAddrFromHsym (&pcxtOut->addr, psym);
                    SHHPROCFrompCXT(pcxtOut) = psym;
                    break;

                default: {
                    LPMDS lpmds = (LPMDS) hmod;

                    SetAddrFromMod(lpmds, &pcxtOut->addr);
                    emiAddr (pcxtOut->addr) = (HEMI) SHHexeFromHmod (hmod);
                    ADDR_IS_LI (pcxtOut->addr) = TRUE;
                    break;
                }
            }
        }
    }

    LLUnlock (hexg);
    return psym;
}
Example #9
0
BOOL
SLFFileInHexe(
    HEXE hexe,
    BOOL fExactMatch,
    LSZ lszFile
    )
{
    BOOL    fRet = FALSE;
    LPEXG   lpexg;
    LPEXE   lpexe;

    assert(hexe);
    lpexe = (LPEXE)LLLock(hexe);

    // Make sure that there's and exg for this exe
    if (lpexg = (LPEXG)LLLock(lpexe->hexg)) {

        // The code below is copied from IsfFromName (FYI   -markbro)
        if (lpexg->lpchFileNames) {
            _TCHAR  * lpch = (_TCHAR  *)lpexg->lpchFileNames;
            _TCHAR  * lpchMax = lpch + lpexg->cbFileNames;
            CHAR    szFileSrc [ _MAX_CVFNAME ];
            CHAR    szExtSrc [ _MAX_CVEXT ];
            WORD    cbName = 0;
            WORD    cchName = 0;
            LSZ     lszFileExt = NULL;

            _splitpath(lszFile, NULL, NULL, szFileSrc, szExtSrc);

            // If fExactMatch, the path must match the OMF
            if (fExactMatch) {
                cbName = _tcslen(lszFile);
                cchName = _tcslen(lszFile);
                lszFileExt = lszFile;
            } else {
                cbName = _tcslen(szExtSrc) + _tcslen(szFileSrc);
                cchName = _tcslen(szExtSrc) + _tcslen(szFileSrc);
                lszFileExt = lszFile + _tcslen(lszFile) - cbName;
            }

            // Stop when we've found something or the end of the table is found.
            while(!fRet && lpch < lpchMax) {
                CHAR szPathOMF [ _MAX_CVPATH ];
                CHAR szFile [ _MAX_CVFNAME ];
                CHAR szExt [ _MAX_CVEXT ];

                // IMPORTANT NOTE:
                //
                // Below, it is VITAL for DBCS to use the number of CHARACTERS
                // to compare as opposed to the number of bytes or the DBCS
                // strnicmp will fail!

                if (!_tcsnicmp (lszFileExt, lpch + cbNameLen(lpch) - cbName + 1, cchName)) {
                    memset(szPathOMF, 0, _MAX_CVPATH);
                    memcpy(szPathOMF, lpch + 1, cbNameLen(lpch));
                    _tsplitpath(szPathOMF, NULL, NULL, szFile, szExt);
                    if (!_tcsicmp (szFileSrc, szFile) &&
                        !_tcsicmp (szExtSrc, szExt))
                    {
                        fRet = TRUE;
                    }
                }

                // Skip to the next name in the table
                lpch += cbNameLen(lpch) + 1;
            }
        }
        LLUnlock(lpexe->hexg);
    }

    LLUnlock(hexe);

    return fRet;
}
Example #10
0
BOOL
SLFLineToAddrExtended (
    HSF     hsf,
    DWORD   line,
    WORD  * piSegStart,
    WORD  * piEntryFind,
    LPADDR  lpaddr,
    SHOFF * lpcbLn,
    DWORD * rgwNearestLines
    )
{
    DWORD   rgwRet[2];
    ADDR    addr = {0};
    SHOFF   cbln = 0;
    HMOD    hmod;
    BOOL    fRet = FALSE;
    LPSF    lpsf = NULL;
    WORD    cEntryRemain;

    if (piEntryFind) {
        cEntryRemain = *piEntryFind;
    } else {
        cEntryRemain = 0;
    }

    rgwRet[0] = 0;
    rgwRet[1] = 0x7fffffff;
    lpsf = (LPSF) hsf;

    ADDR_IS_LI (addr) = TRUE;

    // We need to get a mod.

    if (hmod = SLHmodFromHsf ((HEXE) NULL, hsf)) {
        HEXE  hexe  = SHHexeFromHmod (hmod);
        LPMDS lpmds = (LPMDS) hmod;

        // Set the fFlat and fOff32 bits base on the exe
        HEXG hexg = ((LPEXE) LLLock (hexe))->hexg;
        LLUnlock (hexe);
        if (((LPEXG) LLLock (hexg))->fIsPE) {
            // REVIEW - billjoy - should we check machine type or something?
            ADDRLIN32 (addr);
        } else {
            // REVIEW - billjoy - should we check machine type or something?
            //ADDR????
        }
        LLUnlock (hexg);

        if ((lpmds != NULL) && (lpsf != NULL)) {

            WORD i;

            for (i = *piSegStart; !fRet && i < lpsf->cSeg; i++) {
                ULONG   ulOff;
                WORD    iLn;
                LPSL    lpsl = NULL;
                LPSL    lpslNear = NULL;
                DWORD   wLine = 0;
                DWORD   wLineNear = 0;

                lpsl = GetLpslFromIndex ((LPSM) lpmds->hst, lpsf, i);

                for (iLn = 0; iLn < lpsl->cLnOff; iLn++) {
                    //
                    // look through all of the lines in the table
                    //
                    BOOL fT = LineFromIndex (lpsl, iLn, &wLine);

                    assert (fT);
                    if (wLine == line) {
                        LPOFP   lpofp;

                        fT = OffsetFromIndex (lpsl, iLn, &ulOff);
                        assert (fT);

                        SE_SetAddrOff (&addr, ulOff);
                        SetAddrSeg (&addr, lpsl->Seg);
                        emiAddr (addr) = (HEMI) hexe;

                        if (iLn + 1 < lpsl->cLnOff) {
                            //
                            // if the next line is in range
                            //
                            OffsetFromIndex(lpsl, (WORD)(iLn+1), &ulOff);
                            //
                            // if we have a next line get the range
                            // based on next line.
                            //

                            cbln = ulOff - GetAddrOff (addr);

                            if (cbln == (SHOFF) 0) {
                                if (wLine < rgwRet[1]) {
                                    rgwRet[1] = wLine;
                                }
                                continue;
                            }
                        } else {
                            // if we don't have a next line then
                            // get the range from the boundry

                            lpofp = GetSFBounds (lpsf, i);

                            // GetSFBounds offEnd is inclusive
                            // for the source range.  Need to
                            // add 1 for the count bytes!

                            cbln = lpofp->offEnd - ulOff + 1;

                            // the end information is probably the same as the
                            // beginning offset for the last line in the file.
                            // So for now I will make a wild guess at the
                            // size of average epilog code. 10 bytes.

                            if (!cbln) {
                                cbln = 10;
                            }
                        }

                        *piSegStart = i;
                        if (!cEntryRemain--) {
                            if (piEntryFind) {
                                *piEntryFind += 1;
                            }
                            fRet = TRUE;
                            break;
                        }
                    } else {
                        if (wLine < line) {
                            if (wLine > rgwRet[0]) {
                                rgwRet[0] = wLine;
                            }
                        } else {
                            if (wLine < rgwRet[1]) {
                                rgwRet[1] = wLine;
                            }
                        }
                    }
                }

                // If continuing search, reset to stop at 1st
                // entry in next table
                if (!fRet) {
                    cEntryRemain = 0;
                    if (piEntryFind) {
                        *piEntryFind = 0;
                    }
                }
            }
        }
    }

    if(lpaddr) {
        *lpaddr = addr;
    }
    if(lpcbLn) {
        *lpcbLn = cbln;
    }

    if(rgwNearestLines) {
        rgwNearestLines[0] = rgwRet[0];
        rgwNearestLines[1] = rgwRet[1];
    }

    return fRet;
}
Example #11
0
short
IsfFromName (
    BOOL fExactMatch,
    short isfStart,
    LSZ lszName,
    LPMDS lpmds
    )
{
    short isfFound = -1;
    short isf = isfStart;
    LPEXG lpexg = (LPEXG) LLLock (lpmds->hexg);

    if (lpexg->lpefi) {
        CHAR szFileSrc [ _MAX_CVFNAME ];
        CHAR szExtSrc [ _MAX_CVEXT ];
        WORD cbName = 0;
        WORD cchName = 0;
        LSZ  lszFileExt = NULL;
        int  imds = lpmds->imds - 1;

        _tsplitpath(lszName, NULL, NULL, szFileSrc, szExtSrc);

        // If fExactMatch, the path must match the OMF
        if (fExactMatch) {
            cbName = _tcslen(lszName);
            cchName = _tcslen(lszName);
            lszFileExt = lszName;
        } else {
            cbName = _tcslen(szExtSrc) + _tcslen(szFileSrc);
            cchName = _tcslen(szExtSrc) + _tcslen(szFileSrc);
            lszFileExt = lszName + _tcslen(lszName) - cbName;
        }

        for (isf = isfStart; isf < (short) lpexg->rgculFile [ imds ]; isf++) {
            CHAR szPathOMF [ _MAX_CVPATH ];
            CHAR szFile [ _MAX_CVFNAME ];
            CHAR szExt [ _MAX_CVEXT ];

            _TCHAR  * lpch = (_TCHAR  *)
                lpexg->lpchFileNames +
                (lpexg->rgichFile [ (WORD) (lpexg->rgiulFile [ imds ]) + isf ]);

            // IMPORTANT NOTE:
            //
            // Below, it is VITAL for DBCS to use the number of CHARACTERS
            // to compare as opposed to the number of bytes or the DBCS
            // strnicmp will fail!

            if (!_tcsnicmp (lszFileExt, (_TCHAR  *) lpch + cbNameLen(lpch) - cbName + 1, cchName)) {
                memset(szPathOMF, 0, _MAX_CVPATH);
                memcpy(szPathOMF, lpch + 1, cbNameLen(lpch));
                _tsplitpath(szPathOMF, NULL, NULL, szFile, szExt);
                if (!_tcsicmp (szFileSrc, szFile) &&
                     !_tcsicmp (szExtSrc, szExt))
                {
                    isfFound = isf;
                    break;
                }
            }
        }
    }

    LLUnlock (lpmds->hexg);

    return isfFound;
}