• R/O
  • SSH
  • HTTPS

pefrm-units: Commit


Commit MetaInfo

Revision26 (tree)
Time2017-08-03 01:09:57
Authorquiret

Log Message

- added some helpful text when import modules have been completely resolved successfully

Change Summary

Incremental Difference

--- pefrmdllembed/src/main.cpp (revision 25)
+++ pefrmdllembed/src/main.cpp (revision 26)
@@ -1179,6 +1179,8 @@
11791179
11801180 if ( removeImpDesc )
11811181 {
1182+ std::cout << "* terminated import module " << impDesc.DLLName << std::endl;
1183+
11821184 dstImpDescIter = exeImage.imports.erase( dstImpDescIter );
11831185 }
11841186 else
@@ -1197,118 +1199,117 @@
11971199 bool removeImpDesc = false;
11981200
11991201 // Process this import descriptor.
1202+ PEFile::PEDelayLoadDesc& impDesc = *dstImpDescIter;
1203+
1204+ if ( UniversalCompareStrings( impDesc.DLLName.c_str(), impDesc.DLLName.size(), moduleImageName, strlen(moduleImageName), false ) )
12001205 {
1201- PEFile::PEDelayLoadDesc& impDesc = *dstImpDescIter;
1206+ struct delayedImpDescriptorHandler
1207+ {
1208+ AssemblyEnvironment& env;
1209+ PEFile::PEDelayLoadDesc& impDesc;
1210+ std::uint32_t archPointerSize;
1211+ const decltype( PEFile::delayLoads )::iterator& dstImpDescIter;
12021212
1203- if ( UniversalCompareStrings( impDesc.DLLName.c_str(), impDesc.DLLName.size(), moduleImageName, strlen(moduleImageName), false ) )
1204- {
1205- struct delayedImpDescriptorHandler
1213+ AINLINE delayedImpDescriptorHandler( AssemblyEnvironment& env, PEFile::PEDelayLoadDesc& impDesc, std::uint32_t archPointerSize, const decltype( PEFile::delayLoads )::iterator& dstImpDescIter )
1214+ : impDesc( impDesc ), env( env ), dstImpDescIter( dstImpDescIter )
12061215 {
1207- AssemblyEnvironment& env;
1208- PEFile::PEDelayLoadDesc& impDesc;
1209- std::uint32_t archPointerSize;
1210- const decltype( PEFile::delayLoads )::iterator& dstImpDescIter;
1216+ this->archPointerSize = archPointerSize;
1217+ }
12111218
1212- AINLINE delayedImpDescriptorHandler( AssemblyEnvironment& env, PEFile::PEDelayLoadDesc& impDesc, std::uint32_t archPointerSize, const decltype( PEFile::delayLoads )::iterator& dstImpDescIter )
1213- : impDesc( impDesc ), env( env ), dstImpDescIter( dstImpDescIter )
1219+ AINLINE PEFile::PEImportDesc::functions_t& GetImportFunctions( void )
1220+ {
1221+ return impDesc.importNames;
1222+ }
1223+
1224+ AINLINE PEFile::PESectionDataReference& GetFirstThunkRef( void )
1225+ {
1226+ return impDesc.IATRef;
1227+ }
1228+
1229+ AINLINE void TrimFirstDescriptor( size_t trimTo )
1230+ {
1231+ impDesc.importNames.resize( trimTo );
1232+ }
1233+
1234+ AINLINE void RemoveFirstEntry( void )
1235+ {
1236+ impDesc.importNames.erase( impDesc.importNames.begin() );
1237+ }
1238+
1239+ AINLINE void MoveIATBy( PEFile& image, std::uint32_t moveBytes )
1240+ {
1241+ impDesc.IATRef = image.ResolveRVAToRef( impDesc.IATRef.GetRVA() + moveBytes );
1242+
1243+ // Move the other if it is available.
1244+ PEFile::PESectionDataReference& unloadIAT = impDesc.unloadInfoTableRef;
1245+
1246+ if ( unloadIAT.GetSection() != NULL )
12141247 {
1215- this->archPointerSize = archPointerSize;
1248+ unloadIAT = image.ResolveRVAToRef( unloadIAT.GetRVA() + moveBytes );
12161249 }
1250+ }
12171251
1218- AINLINE PEFile::PEImportDesc::functions_t& GetImportFunctions( void )
1252+ AINLINE void MakeSecondDescriptor( PEFile& image, size_t functake_idx, size_t functake_count, std::uint32_t thunkRefStartOffset )
1253+ {
1254+ PEFile::PEDelayLoadDesc newSecondImp;
1255+ newSecondImp.attrib = impDesc.attrib;
1256+ newSecondImp.DLLName = impDesc.DLLName;
1257+
1258+ // Allocate a new DLL handle memory position for this descriptor.
12191259 {
1220- return impDesc.importNames;
1221- }
1260+ PEFile::PESectionAllocation handleAlloc;
1261+ env.metaSect.Allocate( handleAlloc, this->archPointerSize, this->archPointerSize );
12221262
1223- AINLINE PEFile::PESectionDataReference& GetFirstThunkRef( void )
1224- {
1225- return impDesc.IATRef;
1263+ env.persistentAllocations.push_back( std::move( handleAlloc ) );
1264+
1265+ newSecondImp.DLLHandleRef = env.persistentAllocations.back();
12261266 }
12271267
1228- AINLINE void TrimFirstDescriptor( size_t trimTo )
1268+ // Create a special IAT out of the previous.
1269+ newSecondImp.IATRef = image.ResolveRVAToRef( impDesc.IATRef.GetRVA() + thunkRefStartOffset );
1270+
1271+ // Copy over the import names aswell.
1272+ newSecondImp.importNames.reserve( functake_count );
12291273 {
1230- impDesc.importNames.resize( trimTo );
1231- }
1274+ auto beginMoveIter = std::make_move_iterator( impDesc.importNames.begin() + functake_idx );
1275+ auto endMoveIter = ( beginMoveIter + functake_count );
12321276
1233- AINLINE void RemoveFirstEntry( void )
1234- {
1235- impDesc.importNames.erase( impDesc.importNames.begin() );
1277+ newSecondImp.importNames.insert( newSecondImp.importNames.begin(), beginMoveIter, endMoveIter );
12361278 }
12371279
1238- AINLINE void MoveIATBy( PEFile& image, std::uint32_t moveBytes )
1280+ // If an unload info table existed previously, also handle that case.
12391281 {
1240- impDesc.IATRef = image.ResolveRVAToRef( impDesc.IATRef.GetRVA() + moveBytes );
1241-
1242- // Move the other if it is available.
12431282 PEFile::PESectionDataReference& unloadIAT = impDesc.unloadInfoTableRef;
12441283
12451284 if ( unloadIAT.GetSection() != NULL )
12461285 {
1247- unloadIAT = image.ResolveRVAToRef( unloadIAT.GetRVA() + moveBytes );
1286+ unloadIAT = image.ResolveRVAToRef( unloadIAT.GetRVA() + thunkRefStartOffset );
12481287 }
12491288 }
12501289
1251- AINLINE void MakeSecondDescriptor( PEFile& image, size_t functake_idx, size_t functake_count, std::uint32_t thunkRefStartOffset )
1252- {
1253- PEFile::PEDelayLoadDesc newSecondImp;
1254- newSecondImp.attrib = impDesc.attrib;
1255- newSecondImp.DLLName = impDesc.DLLName;
1256-
1257- // Allocate a new DLL handle memory position for this descriptor.
1258- {
1259- PEFile::PESectionAllocation handleAlloc;
1260- env.metaSect.Allocate( handleAlloc, this->archPointerSize, this->archPointerSize );
1290+ newSecondImp.timeDateStamp = impDesc.timeDateStamp;
12611291
1262- env.persistentAllocations.push_back( std::move( handleAlloc ) );
1292+ // Put in the new descriptor after the one we manage.
1293+ image.delayLoads.insert( this->dstImpDescIter + 1, std::move( newSecondImp ) );
12631294
1264- newSecondImp.DLLHandleRef = env.persistentAllocations.back();
1265- }
1295+ // Done.
1296+ }
1297+ };
1298+ delayedImpDescriptorHandler splitOp( *this, impDesc, archPointerSize, dstImpDescIter );
12661299
1267- // Create a special IAT out of the previous.
1268- newSecondImp.IATRef = image.ResolveRVAToRef( impDesc.IATRef.GetRVA() + thunkRefStartOffset );
1269-
1270- // Copy over the import names aswell.
1271- newSecondImp.importNames.reserve( functake_count );
1272- {
1273- auto beginMoveIter = std::make_move_iterator( impDesc.importNames.begin() + functake_idx );
1274- auto endMoveIter = ( beginMoveIter + functake_count );
1275-
1276- newSecondImp.importNames.insert( newSecondImp.importNames.begin(), beginMoveIter, endMoveIter );
1277- }
1278-
1279- // If an unload info table existed previously, also handle that case.
1280- {
1281- PEFile::PESectionDataReference& unloadIAT = impDesc.unloadInfoTableRef;
1282-
1283- if ( unloadIAT.GetSection() != NULL )
1284- {
1285- newSecondImp.unloadInfoTableRef =
1286- image.ResolveRVAToRef( unloadIAT.GetRVA() + thunkRefStartOffset );
1287- }
1288- }
1289-
1290- newSecondImp.timeDateStamp = impDesc.timeDateStamp;
1291-
1292- // Put in the new descriptor after the one we manage.
1293- image.delayLoads.insert( this->dstImpDescIter + 1, std::move( newSecondImp ) );
1294-
1295- // Done.
1296- }
1297- };
1298- delayedImpDescriptorHandler splitOp( *this, impDesc, archPointerSize, dstImpDescIter );
1299-
1300- removeImpDesc =
1301- InjectImportsWithExports(
1302- exeImage,
1303- moduleImage.exportDir, splitOp, calcRedirRef,
1304- numOrdinalMatches, numNameMatches,
1305- archPointerSize, requiresRelocations
1306- );
1307- }
1300+ removeImpDesc =
1301+ InjectImportsWithExports(
1302+ exeImage,
1303+ moduleImage.exportDir, splitOp, calcRedirRef,
1304+ numOrdinalMatches, numNameMatches,
1305+ archPointerSize, requiresRelocations
1306+ );
13081307 }
13091308
13101309 if ( removeImpDesc )
13111310 {
1311+ std::cout << "* terminated delay-load import module " << impDesc.DLLName << std::endl;
1312+
13121313 dstImpDescIter = exeImage.delayLoads.erase( dstImpDescIter );
13131314 }
13141315 else
Show on old repository browser