Calculating Necessary Values

There are two critical pieces of information that need to be calculated by the delay helper routine. To that end, there are a couple of inline functions in the header file, Delayimp.h, for calculating this information. The first one is for calculating the index of the current import into the three different tables (IAT, BIAT, and UIAT) and the second for counting the number of imports in a valid IAT:

// utility function for calculating the index of the current import
// for all the tables (INT, BIAT, UIAT, and IAT).
__inline unsigned
IndexFromPImgThunkData(PCImgThunkData pitdCur, PCImgThunkData pitdBase) {
    return pitdCur - pitdBase;
    }

// utility function for calculating the count of imports given the base
// of the IAT. NB: this only works on a valid IAT!
__inline unsigned
CountOfImports(PCImgThunkData pitdBase) {
    unsigned        cRet = 0;
    PCImgThunkData  pitd = pitdBase;
    while (pitd->u1.Function) {
        pitd++;
        cRet++;
        }
    return cRet;
    }