• R/O
  • SSH
  • HTTPS

pefrm-units: Commit


Commit MetaInfo

Revision55 (tree)
Time2019-04-14 23:07:51
Authorquiret

Log Message

- bugfixes
- updated to Visual Studio 2019

Change Summary

Incremental Difference

--- pefrmrunbasic/src/main.cpp (revision 54)
+++ pefrmrunbasic/src/main.cpp (revision 55)
@@ -73,9 +73,9 @@
7373 std::uint32_t imageSize = calcExec.peOptHeader.sizeOfImage;
7474
7575 // We first have to allocate our executable into a special position.
76- void *imageMemory = VirtualAlloc( NULL, imageSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE ); // TODO: set proper access rights.
76+ void *imageMemory = VirtualAlloc( nullptr, imageSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE ); // TODO: set proper access rights.
7777
78- assert( imageMemory != NULL );
78+ assert( imageMemory != nullptr );
7979
8080 size_t newImageBase = (size_t)imageMemory;
8181
@@ -82,9 +82,10 @@
8282 // Map the binary into address space.
8383 // This is done in a very basic way and it is left up to the reader to improve it.
8484 {
85- calcExec.ForAllSections(
86- [&]( PEFile::PESection *theSect )
85+ for ( auto iter = calcExec.GetSectionIterator(); !iter.IsEnd(); iter.Increment() )
8786 {
87+ PEFile::PESection *theSect = iter.Resolve();
88+
8889 std::uint32_t virtualAddr = theSect->GetVirtualAddress();
8990
9091 std::uint32_t dataSize = (std::uint32_t)theSect->stream.Size();
@@ -93,16 +94,16 @@
9394
9495 theSect->stream.Seek( 0 );
9596 theSect->stream.Read( sectMem, dataSize );
96- });
97+ }
9798 }
9899
99100 // Relocate the binary into its space.
100101 {
101- for ( const std::pair <const std::uint32_t, PEFile::PEBaseReloc>& relocPair : calcExec.baseRelocs )
102+ for ( auto *relocNode : calcExec.baseRelocs )
102103 {
103- const std::uint32_t rvaOfBlock = relocPair.first;
104+ const std::uint32_t rvaOfBlock = relocNode->GetKey();
104105
105- for ( const PEFile::PEBaseReloc::item& relocItem : relocPair.second.items )
106+ for ( const PEFile::PEBaseReloc::item& relocItem : relocNode->GetValue().items )
106107 {
107108 void *relocMem = ( (char*)imageMemory + rvaOfBlock * PEFile::baserelocChunkSize + relocItem.offset );
108109
@@ -164,7 +165,7 @@
164165 const PEFile::PEImportDesc::importFunc& funcInfo = *thunkInfoIter;
165166
166167 // Patch the function ptr.
167- void *funcAddr = NULL;
168+ void *funcAddr = nullptr;
168169
169170 if ( funcInfo.isOrdinalImport )
170171 {
@@ -172,10 +173,10 @@
172173 }
173174 else
174175 {
175- funcAddr = GetProcAddress( memoryModule, funcInfo.name.c_str() );
176+ funcAddr = GetProcAddress( memoryModule, funcInfo.name.GetConstString() );
176177 }
177178
178- if ( funcAddr == NULL )
179+ if ( funcAddr == nullptr )
179180 {
180181 std::cout << "failed to resolve module import\n";
181182
@@ -197,9 +198,9 @@
197198 for ( const PEFile::PEImportDesc& importEntry : calcExec.imports )
198199 {
199200 // Load the actual module.
200- HMODULE memoryModule = LoadLibraryA( importEntry.DLLName.c_str() );
201+ HMODULE memoryModule = LoadLibraryA( importEntry.DLLName.GetConstString() );
201202
202- assert( memoryModule != NULL );
203+ assert( memoryModule != nullptr );
203204
204205 // Need to write into the thunk.
205206 IMAGE_THUNK_DATA *modThunkIter = (IMAGE_THUNK_DATA*)( (char*)imageMemory + importEntry.firstThunkRef.GetRVA() );
@@ -212,9 +213,9 @@
212213 {
213214 for ( const PEFile::PEDelayLoadDesc& delayLoad : calcExec.delayLoads )
214215 {
215- HMODULE modHandle = LoadLibraryA( delayLoad.DLLName.c_str() );
216+ HMODULE modHandle = LoadLibraryA( delayLoad.DLLName.GetConstString() );
216217
217- assert( modHandle != NULL );
218+ assert( modHandle != nullptr );
218219
219220 // Write it into memory.
220221 {
Show on old repository browser