MCPcopy Create free account
hub / github.com/beefytech/Beef / PopulateExportData

Method PopulateExportData

IDEHelper/Linker/BlContext.cpp:2179–2267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2177}
2178
2179void BlContext::PopulateExportData(BlSegment* exportSeg)
2180{
2181 std::vector<uint32> rvaMap;
2182
2183 String libName = GetFileName(mOutName);
2184 DynMemStream strTab;
2185
2186 int numNames = 0;
2187 int maxOrdinal = 0;
2188 for (auto& exportPair : mExports)
2189 {
2190 const StringImpl& name = exportPair.first;
2191 auto& blExport = exportPair.second;
2192 String symName;
2193 if (!blExport.mSrcName.empty())
2194 symName = blExport.mSrcName;
2195 else
2196 symName = name;
2197 if (!blExport.mNoName)
2198 numNames++;
2199
2200 int ordIdx = blExport.mOrdinal - 1;
2201 while (ordIdx >= rvaMap.size())
2202 rvaMap.push_back(0);
2203
2204 auto sym = ResolveSym(symName.c_str(), false);
2205 if (sym == NULL)
2206 {
2207 Fail(StrFormat("Unable to find exported symbol '%s'", symName.c_str()));
2208 }
2209 else
2210 {
2211 rvaMap[ordIdx] = (uint32)GetSymAddr(sym);
2212 }
2213 }
2214
2215 int numEntries = maxOrdinal - 1;
2216
2217 int32 funcRVA = exportSeg->mRVA + (int)sizeof(IMAGE_EXPORT_DIRECTORY);
2218 int32 namePtrTabRVA = funcRVA + (int)rvaMap.size() * 4;
2219 int32 ordTabRVA = namePtrTabRVA + numNames * 4;
2220 int32 strTabRVA = ordTabRVA + numNames * 2;
2221
2222 // Export Directory Table
2223 IMAGE_EXPORT_DIRECTORY exportDir = { 0 };
2224 exportDir.Name = strTabRVA + strTab.GetSize();
2225 strTab.Write((void*)libName.c_str(), (int)libName.length() + 1);
2226 exportDir.Base = 1;
2227 exportDir.NumberOfFunctions = (uint32)rvaMap.size();
2228 exportDir.NumberOfNames = numNames;
2229 exportDir.AddressOfFunctions = funcRVA;
2230 exportDir.AddressOfNames = namePtrTabRVA;
2231 exportDir.AddressOfNameOrdinals = ordTabRVA;
2232 mExportStream.WriteT(exportDir);
2233
2234 // Export Address Table
2235 mExportStream.Write((void*)&rvaMap[0], (int)rvaMap.size() * 4);
2236

Callers

nothing calls this directly

Calls 10

FailFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
c_strMethod · 0.45
GetSizeMethod · 0.45
WriteMethod · 0.45
lengthMethod · 0.45
WriteTMethod · 0.45
GetPtrMethod · 0.45

Tested by

no test coverage detected