• R/O
  • SSH
  • HTTPS

pefrm-units: Commit


Commit MetaInfo

Revision63 (tree)
Time2019-11-11 01:39:32
Authorquiret

Log Message

- turns out that this sample cannot run in ARM32/ARM64 because no /DYNAMICBASE:NO support but I added the code anyway for completeness sake

Change Summary

Incremental Difference

--- pefrmrunfixed/src/main.cpp (revision 62)
+++ pefrmrunfixed/src/main.cpp (revision 63)
@@ -9,6 +9,14 @@
99
1010 #undef ABSOLUTE
1111
12+#ifdef _M_AMD64
13+#include <peloader.freg.x64.h>
14+#elif defined(_M_ARM64)
15+#include <peloader.freg.arm64.h>
16+#elif defined(_M_ARM)
17+#include <peloader.freg.arm32.h>
18+#endif //PLATFORM INCLUDES.
19+
1220 // We need special dummy variables.
1321 // Thank you to NTAuthority (bas) and iFarbod for helping.
1422 // (https://github.com/ctnorth/ctnorth/blob/master/Client/Launcher/DummyVariables.cpp)
@@ -158,20 +166,61 @@
158166 // Register all exception handlers.
159167 #ifdef _M_AMD64
160168 {
161- for ( const PEFile::PERuntimeFunction& rtFunc : fixedExec.exceptRFs )
169+ PEFileDetails::PEFunctionRegistryX64 *rtFuncs = dynamic_cast <PEFileDetails::PEFunctionRegistryX64*> ( fixedExec.genDataDirs.entries.FindOrDefault( IMAGE_DIRECTORY_ENTRY_EXCEPTION ) );
170+
171+ if ( rtFuncs != nullptr )
162172 {
163- RUNTIME_FUNCTION nativeRTFunc;
164- nativeRTFunc.BeginAddress = rtFunc.beginAddrRef.GetRVA();
165- nativeRTFunc.EndAddress = rtFunc.endAddrRef.GetRVA();
166- nativeRTFunc.UnwindInfoAddress = rtFunc.unwindInfoRef.GetRVA();
173+ for ( const PEFileDetails::PERuntimeFunctionX64& rtFunc : rtFuncs->entries )
174+ {
175+ RUNTIME_FUNCTION nativeRTFunc;
176+ nativeRTFunc.BeginAddress = rtFunc.beginAddrRef.GetRVA();
177+ nativeRTFunc.EndAddress = rtFunc.endAddrRef.GetRVA();
178+ nativeRTFunc.UnwindInfoAddress = rtFunc.unwindInfoRef.GetRVA();
167179
168- BOOLEAN success = RtlAddFunctionTable( &nativeRTFunc, 1, imageBase );
180+ BOOLEAN success = RtlAddFunctionTable( &nativeRTFunc, 1, imageBase );
169181
170- assert( success == 1 );
182+ assert( success == 1 );
183+ }
171184 }
172185 }
173-#endif
186+#elif defined(_M_ARM64)
187+ {
188+ PEFileDetails::PEFunctionRegistryARM64 *rtFuncs = dynamic_cast <PEFileDetails::PEFunctionRegistryARM64*> ( fixedExec.genDataDirs.entries.FindOrDefault( IMAGE_DIRECTORY_ENTRY_EXCEPTION ) );
174189
190+ if ( rtFuncs != nullptr )
191+ {
192+ for ( const PEFileDetails::PERuntimeFunctionARM64& rtFunc : rtFuncs->entries )
193+ {
194+ RUNTIME_FUNCTION nativeRTFunc;
195+ nativeRTFunc.BeginAddress = rtFunc.BeginAddress.GetRVA();
196+ nativeRTFunc.UnwindData = rtFunc.UnwindData;
197+
198+ BOOLEAN success = RtlAddFunctionTable( &nativeRTFunc, 1, imageBase );
199+
200+ assert( success == 1 );
201+ }
202+ }
203+ }
204+#elif defined(_M_ARM)
205+ {
206+ PEFileDetails::PEFunctionRegistryARM32 *rtFuncs = dynamic_cast <PEFileDetails::PEFunctionRegistryARM32*> ( fixedExec.genDataDirs.entries.FindOrDefault( IMAGE_DIRECTORY_ENTRY_EXCEPTION ) );
207+
208+ if ( rtFuncs != nullptr )
209+ {
210+ for ( const PEFileDetails::PERuntimeFunctionARM32& rtFunc : rtFuncs->entries )
211+ {
212+ RUNTIME_FUNCTION nativeRTFunc;
213+ nativeRTFunc.BeginAddress = rtFunc.BeginAddress.GetRVA();
214+ nativeRTFunc.UnwindData = rtFunc.UnwindData;
215+
216+ BOOLEAN success = RtlAddFunctionTable( &nativeRTFunc, 1, imageBase );
217+
218+ assert( success == 1 );
219+ }
220+ }
221+ }
222+#endif //PLATFORM DEPENDANT CODE.
223+
175224 // Helpers for thunking.
176225 struct Helpers
177226 {
Show on old repository browser