| 2034 | } |
| 2035 | |
| 2036 | void BlContext::PopulateIData(BlSegment* iDataSect) |
| 2037 | { |
| 2038 | int importLookupTableSize = ((int)mImportLookups.size() + (int)mImportFiles.size()) * 8; |
| 2039 | |
| 2040 | int hintNameTableSize = 0; |
| 2041 | PopulateIData_LookupTable(iDataSect, hintNameTableSize); |
| 2042 | |
| 2043 | int idataIdx = 0; |
| 2044 | int thunkIdx = 0; |
| 2045 | for (auto& importFilePair : mImportFiles) |
| 2046 | { |
| 2047 | auto& importFile = importFilePair.second; |
| 2048 | for (auto lookup : importFile.mLookups) |
| 2049 | { |
| 2050 | lookup->mThunkIdx = thunkIdx++; |
| 2051 | lookup->mIDataIdx = idataIdx++; |
| 2052 | } |
| 2053 | idataIdx++; // For NULL entry |
| 2054 | } |
| 2055 | |
| 2056 | int importDirectoryTableSize = ((int)mImportFiles.size() + 1) * 20; |
| 2057 | int importDirOfs = importLookupTableSize; |
| 2058 | int importLookupOfs = importDirOfs + importDirectoryTableSize; |
| 2059 | int hintNameTableOfs = importLookupTableSize + importDirectoryTableSize + importLookupTableSize; |
| 2060 | int strTableOfs = hintNameTableOfs + hintNameTableSize; |
| 2061 | |
| 2062 | // Import directory |
| 2063 | int curLookupIdx = 0; |
| 2064 | for (auto& importFilePair : mImportFiles) |
| 2065 | { |
| 2066 | auto& importFileName = importFilePair.first; |
| 2067 | auto& importFile = importFilePair.second; |
| 2068 | mImportStream.Write((int32)(iDataSect->mRVA + importLookupOfs + curLookupIdx*8)); // Import lookup table RVA |
| 2069 | mImportStream.Write((int32)0); // Timestamp |
| 2070 | mImportStream.Write((int32)0); // Forwarder chain |
| 2071 | mImportStream.Write((int32)(iDataSect->mRVA + strTableOfs)); // Name RVA |
| 2072 | mImportStream.Write((int32)(iDataSect->mRVA + curLookupIdx * 8)); // Import address table RVA |
| 2073 | curLookupIdx += (int)importFile.mLookups.size() + 1; |
| 2074 | strTableOfs += (int)importFileName.length() + 1; |
| 2075 | } |
| 2076 | |
| 2077 | // Empty import directory entry terminates |
| 2078 | mImportStream.WriteZeros(20); |
| 2079 | |
| 2080 | hintNameTableSize = 0; |
| 2081 | PopulateIData_LookupTable(iDataSect, hintNameTableSize); |
| 2082 | |
| 2083 | // Hint/Name Table |
| 2084 | for (auto& importFilePair : mImportFiles) |
| 2085 | { |
| 2086 | auto& importFile = importFilePair.second; |
| 2087 | for (auto lookup : importFile.mLookups) |
| 2088 | { |
| 2089 | if (!lookup->mName.empty()) |
| 2090 | { |
| 2091 | mImportStream.Write((int16)lookup->mHint); |
| 2092 | mImportStream.Write((void*)lookup->mName.c_str(), (int)lookup->mName.length() + 1); |
| 2093 | if ((mImportStream.GetPos() % 2) == 1) |