• R/O
  • SSH
  • HTTPS

peframework: Commit


Commit MetaInfo

Revision27 (tree)
Time2019-02-14 23:51:12
Authorquiret

Log Message

- straightened out new resource creation + insertion
- added more helper API for PE resource addition

Change Summary

Incremental Difference

--- library/include/peloader.h (revision 26)
+++ library/include/peloader.h (revision 27)
@@ -1607,7 +1607,7 @@
16071607 // dynamically allocated.
16081608 for ( PEResourceItem *item : this->namedChildren )
16091609 {
1610- eir::static_del_struct <PEResourceItem, PEGlobalStaticAllocator> ( nullptr, item );
1610+ DestroyItem( item );
16111611 }
16121612
16131613 this->namedChildren.Clear();
@@ -1614,7 +1614,7 @@
16141614
16151615 for ( PEResourceItem *item : this->idChildren )
16161616 {
1617- eir::static_del_struct <PEResourceItem, PEGlobalStaticAllocator> ( nullptr, item );
1617+ DestroyItem( item );
16181618 }
16191619
16201620 this->idChildren.Clear();
@@ -1633,6 +1633,23 @@
16331633 return ( this->namedChildren.IsEmpty() && this->idChildren.IsEmpty() );
16341634 }
16351635
1636+ // Common helpers, take some functionality out of your hands.
1637+ PEResourceInfo* PutData( bool isIdentifierName, peString <char16_t> name, std::uint16_t identifier, PESectionDataReference dataRef );
1638+ PEResourceDir* MakeDir( bool isIdentifierName, peString <char16_t> name, std::uint16_t identifier );
1639+
1640+ static PEResourceDir* CreateDir( bool isIdentifierName, peString <char16_t> name, std::uint16_t identifier )
1641+ {
1642+ return eir::static_new_struct <PEResourceDir, PEGlobalStaticAllocator> ( nullptr, isIdentifierName, std::move( name ), std::move( identifier ) );
1643+ }
1644+ static PEResourceInfo* CreateData( bool isIdentifierName, peString <char16_t> name, std::uint16_t identifier, PESectionDataReference dataRef )
1645+ {
1646+ return eir::static_new_struct <PEResourceInfo, PEGlobalStaticAllocator> ( nullptr, isIdentifierName, std::move( name ), std::move( identifier ), std::move( dataRef ) );
1647+ }
1648+ static void DestroyItem( PEResourceItem *item )
1649+ {
1650+ eir::static_del_struct <PEResourceItem, PEGlobalStaticAllocator> ( nullptr, item );
1651+ }
1652+
16361653 template <typename callbackType>
16371654 inline void ForAllChildren( const callbackType& cb ) const
16381655 {
--- library/src/peloader.read.cpp (revision 26)
+++ library/src/peloader.read.cpp (revision 27)
@@ -1220,7 +1220,7 @@
12201220 }
12211221 catch( ... )
12221222 {
1223- eir::static_del_struct <PEResourceItem, PEGlobalStaticAllocator> ( nullptr, resItem );
1223+ PEResourceDir::DestroyItem( resItem );
12241224
12251225 throw;
12261226 }
@@ -1251,7 +1251,7 @@
12511251 }
12521252 catch( ... )
12531253 {
1254- eir::static_del_struct <PEResourceItem, PEGlobalStaticAllocator> ( nullptr, resItem );
1254+ PEResourceDir::DestroyItem( resItem );
12551255
12561256 throw;
12571257 }
--- library/src/peloader.resource.cpp (revision 26)
+++ library/src/peloader.resource.cpp (revision 27)
@@ -88,4 +88,70 @@
8888 }
8989
9090 return false;
91+}
92+
93+PEFile::PEResourceInfo* PEFile::PEResourceDir::PutData( bool isIdentifierName, peString <char16_t> name, std::uint16_t identifier, PESectionDataReference dataRef )
94+{
95+ PEResourceItem *existingItem = this->FindItem( isIdentifierName, name, identifier );
96+
97+ if ( existingItem )
98+ {
99+ if ( existingItem->itemType == eType::DATA )
100+ {
101+ PEResourceInfo *dataItem = (PEResourceInfo*)existingItem;
102+
103+ // Update the item.
104+ dataItem->sectRef = std::move( dataRef );
105+ return dataItem;
106+ }
107+ }
108+
109+ PEResourceInfo *newItem = CreateData( isIdentifierName, std::move( name ), std::move( identifier ), std::move( dataRef ) );
110+
111+ if ( newItem )
112+ {
113+ if ( existingItem )
114+ {
115+ this->RemoveItem( existingItem );
116+
117+ // We also delete the item.
118+ DestroyItem( existingItem );
119+ }
120+
121+ this->AddItem( newItem );
122+ }
123+
124+ return newItem;
125+}
126+
127+PEFile::PEResourceDir* PEFile::PEResourceDir::MakeDir( bool isIdentifierName, peString <char16_t> name, std::uint16_t identifier )
128+{
129+ PEResourceItem *existingItem = this->FindItem( isIdentifierName, name, identifier );
130+
131+ if ( existingItem )
132+ {
133+ if ( existingItem->itemType == eType::DIRECTORY )
134+ {
135+ PEResourceDir *dirItem = (PEResourceDir*)existingItem;
136+
137+ return dirItem;
138+ }
139+ }
140+
141+ PEResourceDir *newItem = CreateDir( isIdentifierName, std::move( name ), std::move( identifier ) );
142+
143+ if ( newItem )
144+ {
145+ if ( existingItem )
146+ {
147+ this->RemoveItem( existingItem );
148+
149+ // We also destroy the item.
150+ DestroyItem( existingItem );
151+ }
152+
153+ this->AddItem( newItem );
154+ }
155+
156+ return newItem;
91157 }
\ No newline at end of file
Show on old repository browser