• R/O
  • SSH
  • HTTPS

pefrm-units: Commit


Commit MetaInfo

Revision62 (tree)
Time2019-11-11 01:32:48
Authorquiret

Log Message

- expanded the sample to run on ARM32/ARM64 aswell (compiles but not tested yet)

Change Summary

Incremental Difference

--- pefrmrunbasic/src/main.cpp (revision 61)
+++ pefrmrunbasic/src/main.cpp (revision 62)
@@ -7,6 +7,14 @@
77
88 #include <winternl.h>
99
10+#ifdef _M_AMD64
11+#include <peloader.freg.x64.h>
12+#elif defined(_M_ARM64)
13+#include <peloader.freg.arm64.h>
14+#elif defined(_M_ARM)
15+#include <peloader.freg.arm32.h>
16+#endif //PLATFORM INCLUDES.
17+
1018 int main( int argc, char *argv[] )
1119 {
1220 // Load calc.exe and run it.
@@ -139,20 +147,61 @@
139147 // Register all exception handlers.
140148 #ifdef _M_AMD64
141149 {
142- for ( const PEFile::PERuntimeFunction& rtFunc : calcExec.exceptRFs )
150+ PEFileDetails::PEFunctionRegistryX64 *rtFuncs = dynamic_cast <PEFileDetails::PEFunctionRegistryX64*> ( calcExec.genDataDirs.entries.FindOrDefault( IMAGE_DIRECTORY_ENTRY_EXCEPTION ) );
151+
152+ if ( rtFuncs != nullptr )
143153 {
144- RUNTIME_FUNCTION nativeRTFunc;
145- nativeRTFunc.BeginAddress = rtFunc.beginAddrRef.GetRVA();
146- nativeRTFunc.EndAddress = rtFunc.endAddrRef.GetRVA();
147- nativeRTFunc.UnwindInfoAddress = rtFunc.unwindInfoRef.GetRVA();
154+ for ( const PEFileDetails::PERuntimeFunctionX64& rtFunc : rtFuncs->entries )
155+ {
156+ RUNTIME_FUNCTION nativeRTFunc;
157+ nativeRTFunc.BeginAddress = rtFunc.beginAddrRef.GetRVA();
158+ nativeRTFunc.EndAddress = rtFunc.endAddrRef.GetRVA();
159+ nativeRTFunc.UnwindInfoAddress = rtFunc.unwindInfoRef.GetRVA();
148160
149- BOOLEAN success = RtlAddFunctionTable( &nativeRTFunc, 1, newImageBase );
161+ BOOLEAN success = RtlAddFunctionTable( &nativeRTFunc, 1, newImageBase );
150162
151- assert( success == 1 );
163+ assert( success == 1 );
164+ }
152165 }
153166 }
154-#endif
167+#elif defined(_M_ARM64)
168+ {
169+ PEFileDetails::PEFunctionRegistryARM64 *rtFuncs = dynamic_cast <PEFileDetails::PEFunctionRegistryARM64*> ( calcExec.genDataDirs.entries.FindOrDefault( IMAGE_DIRECTORY_ENTRY_EXCEPTION ) );
155170
171+ if ( rtFuncs != nullptr )
172+ {
173+ for ( const PEFileDetails::PERuntimeFunctionARM64& rtFunc : rtFuncs->entries )
174+ {
175+ RUNTIME_FUNCTION nativeRTFunc;
176+ nativeRTFunc.BeginAddress = rtFunc.BeginAddress.GetRVA();
177+ nativeRTFunc.UnwindData = rtFunc.UnwindData;
178+
179+ BOOLEAN success = RtlAddFunctionTable( &nativeRTFunc, 1, newImageBase );
180+
181+ assert( success == 1 );
182+ }
183+ }
184+ }
185+#elif defined(_M_ARM)
186+ {
187+ PEFileDetails::PEFunctionRegistryARM32 *rtFuncs = dynamic_cast <PEFileDetails::PEFunctionRegistryARM32*> ( calcExec.genDataDirs.entries.FindOrDefault( IMAGE_DIRECTORY_ENTRY_EXCEPTION ) );
188+
189+ if ( rtFuncs != nullptr )
190+ {
191+ for ( const PEFileDetails::PERuntimeFunctionARM32& rtFunc : rtFuncs->entries )
192+ {
193+ RUNTIME_FUNCTION nativeRTFunc;
194+ nativeRTFunc.BeginAddress = rtFunc.BeginAddress.GetRVA();
195+ nativeRTFunc.UnwindData = rtFunc.UnwindData;
196+
197+ BOOLEAN success = RtlAddFunctionTable( &nativeRTFunc, 1, newImageBase );
198+
199+ assert( success == 1 );
200+ }
201+ }
202+ }
203+#endif //PLATFORM DEPENDANT CODE.
204+
156205 // Helpers for thunking.
157206 struct Helpers
158207 {
Show on old repository browser