• R/O
  • SSH
  • HTTPS

pefrm-units: Commit


Commit MetaInfo

Revision57 (tree)
Time2019-06-07 03:48:34
Authorquiret

Log Message

- fixed memory allocation issues related to resources
- added ability to ignore resources for embedding

Change Summary

Incremental Difference

--- pefrmdllembed/src/main.cpp (revision 56)
+++ pefrmdllembed/src/main.cpp (revision 57)
@@ -150,7 +150,7 @@
150150 }
151151 catch( ... )
152152 {
153- delete resItem;
153+ PEFile::PEResourceDir::DestroyItem( resItem );
154154
155155 throw;
156156 }
@@ -192,7 +192,7 @@
192192
193193 into.RemoveItem( resItem );
194194
195- delete resItem;
195+ PEFile::PEResourceDir::DestroyItem( resItem );
196196
197197 resItem = CloneResourceItem( sectResolver, embedItem );
198198
@@ -202,7 +202,7 @@
202202 }
203203 catch( ... )
204204 {
205- delete resItem;
205+ PEFile::PEResourceDir::DestroyItem( resItem );
206206
207207 throw;
208208 }
@@ -249,7 +249,7 @@
249249 dataItem.codePage = srcDataItem->codePage;
250250 dataItem.reserved = srcDataItem->reserved;
251251
252- itemOut = new PEFile::PEResourceInfo( std::move( dataItem ) );
252+ itemOut = PEFile::PEResourceDir::CreateData( std::move( dataItem ) );
253253 }
254254 else if ( srcItemType == PEFile::PEResourceItem::eType::DIRECTORY )
255255 {
@@ -275,13 +275,13 @@
275275 }
276276 catch( ... )
277277 {
278- delete newItem;
278+ PEFile::PEResourceDir::DestroyItem( newItem );
279279
280280 throw;
281281 }
282282 });
283283
284- itemOut = new PEFile::PEResourceDir( std::move( dirItem ) );
284+ itemOut = PEFile::PEResourceDir::CreateDir( std::move( dirItem ) );
285285 }
286286 else
287287 {
@@ -566,7 +566,7 @@
566566 return;
567567 }
568568
569- inline int EmbedModuleIntoExecutable( PEFile& moduleImage, bool requiresRelocations, const char *moduleImageName, bool injectMatchingImports, bool doTakeoverExports, std::uint32_t archPointerSize )
569+ inline int EmbedModuleIntoExecutable( PEFile& moduleImage, bool requiresRelocations, const char *moduleImageName, bool injectMatchingImports, bool doTakeoverExports, bool doIgnoreResources, std::uint32_t archPointerSize )
570570 {
571571 PEFile& exeImage = this->embedImage;
572572
@@ -1001,16 +1001,23 @@
10011001 // Copy over the resources aswell.
10021002 if ( moduleImage.resourceRoot.IsEmpty() == false )
10031003 {
1004- std::cout << "embedding module resources" << std::endl;
1004+ if ( !doIgnoreResources )
1005+ {
1006+ std::cout << "embedding module resources" << std::endl;
10051007
1006- // We merge things.
1007- bool hasChanged =
1008- resourceHelpers::EmbedResourceDirectoryInto( peString <wchar_t> (), resolveSectionLink, exeImage.resourceRoot, moduleImage.resourceRoot );
1008+ // We merge things.
1009+ bool hasChanged =
1010+ resourceHelpers::EmbedResourceDirectoryInto( peString <wchar_t> (), resolveSectionLink, exeImage.resourceRoot, moduleImage.resourceRoot );
10091011
1010- if ( hasChanged )
1012+ if ( hasChanged )
1013+ {
1014+ // Need to write new resource data directory.
1015+ exeImage.resAllocEntry = PEFile::PESectionAllocation();
1016+ }
1017+ }
1018+ else
10111019 {
1012- // Need to write new resource data directory.
1013- exeImage.resAllocEntry = PEFile::PESectionAllocation();
1020+ std::cout << "ignoring resources" << std::endl;
10141021 }
10151022 }
10161023
@@ -1661,6 +1668,7 @@
16611668 bool doInjectMatchingImports = false;
16621669 bool doTakeoverExports = true;
16631670 bool doPrintHelp = false;
1671+ bool doIgnoreResources = false;
16641672
16651673 if ( argc >= 1 )
16661674 {
@@ -1690,6 +1698,10 @@
16901698 {
16911699 doPrintHelp = true;
16921700 }
1701+ else if ( opt == "nores" || opt == "ignres" )
1702+ {
1703+ doIgnoreResources = true;
1704+ }
16931705 else
16941706 {
16951707 std::cout << "unknown cmdline option: " << opt << std::endl;
@@ -1713,6 +1725,7 @@
17131725 std::cout << "-efix: restores original executable entry point in PE header after DLL load" << std::endl;
17141726 std::cout << "-injimp: hooks executable imports with input DLL exports" << std::endl;
17151727 std::cout << "-noexp: does not take over DLL exports into executable" << std::endl;
1728+ std::cout << "-nores: leaves out resources from the DLL" << std::endl;
17161729 std::cout << "-help: prints this help text" << std::endl;
17171730
17181731 return 0;
@@ -2057,7 +2070,7 @@
20572070 const char *moduleFileName = FetchFileName( inputModImageName );
20582071
20592072 // Perform the embedding.
2060- int statusEmbed = asmEnv.EmbedModuleIntoExecutable( moduleImage, requiresRelocations, moduleFileName, doInjectMatchingImports, doTakeoverExports, archPointerSize );
2073+ int statusEmbed = asmEnv.EmbedModuleIntoExecutable( moduleImage, requiresRelocations, moduleFileName, doInjectMatchingImports, doTakeoverExports, doIgnoreResources, archPointerSize );
20612074
20622075 if ( statusEmbed != 0 )
20632076 {
Show on old repository browser