From 95c32685beacff363d1ef69ffae806906b3d1015 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Wed, 16 Feb 2022 20:19:21 +0300 Subject: [PATCH] Driver: Add proxycb/*_arm64.asm --- src/driver/loader/fortmm.c | 9 +- src/driver/proxycb/fortpcb_dst.c | 4 +- src/driver/proxycb/fortpcb_dst_arm64.asm | 269 +++++++++++++++++++++++ src/driver/proxycb/fortpcb_src.c | 2 +- src/driver/proxycb/fortpcb_src_arm64.asm | 269 +++++++++++++++++++++++ src/driver/scripts/install.bat | 3 +- 6 files changed, 547 insertions(+), 9 deletions(-) create mode 100644 src/driver/proxycb/fortpcb_dst_arm64.asm create mode 100644 src/driver/proxycb/fortpcb_src_arm64.asm diff --git a/src/driver/loader/fortmm.c b/src/driver/loader/fortmm.c index af628e2e..d37625dd 100644 --- a/src/driver/loader/fortmm.c +++ b/src/driver/loader/fortmm.c @@ -6,9 +6,6 @@ # define PAGE_SIZE 0x1000 #endif -#define ARCHITECTURE_TYPE_X86 0x00000000 -#define ARCHITECTURE_TYPE_X64 0x00000001 - /* MIN/MAX of address aligned */ #define MIN_ALIGNED(address, alignment) (LPVOID)((uintptr_t) (address) & ~((alignment) -1)) #define MAX_ALIGNED(value, alignment) (((value) + (alignment) -1) & ~((alignment) -1)) @@ -97,7 +94,7 @@ static void PatchAddressRelocations( *patchAddrHL += locationDelta; } break; -#ifdef _WIN64 +#if defined(_WIN64) case IMAGE_REL_BASED_DIR64: { PUCHAR *patchAddr64 = (PUCHAR *) (dest + offset); *patchAddr64 += locationDelta; @@ -304,7 +301,9 @@ static BOOL IsPEHeaderValid(PVOID lpData, DWORD dwSize) || dwSize < pNtHeaders->OptionalHeader.SizeOfHeaders /* Check for the correct architecture */ || pNtHeaders->FileHeader.Machine != -#ifdef _WIN64 +#if defined(_M_ARM64) + IMAGE_FILE_MACHINE_ARM64 +#elif defined(_WIN64) IMAGE_FILE_MACHINE_AMD64 #else IMAGE_FILE_MACHINE_I386 diff --git a/src/driver/proxycb/fortpcb_dst.c b/src/driver/proxycb/fortpcb_dst.c index 8f2c43d4..70b485a0 100644 --- a/src/driver/proxycb/fortpcb_dst.c +++ b/src/driver/proxycb/fortpcb_dst.c @@ -4,7 +4,7 @@ ProxyCallbackProc g_proxyCallbacksArray[PROXY_CALLBACKS_COUNT]; -#ifdef _WIN64 +#if defined(_WIN64) && !defined(_M_ARM64) # define ProxyCallbackExtern(i) extern void proxyCallback##i(void) @@ -144,7 +144,7 @@ static ProxyCallbackProc g_proxyDstCallbacks[PROXY_CALLBACKS_COUNT] = { FORT_API void fort_proxycb_dst_setup(PFORT_PROXYCB_INFO cbInfo) { -#ifdef _WIN64 +#if defined(_WIN64) && !defined(_M_ARM64) cbInfo->dst = g_proxyDstCallbacks; cbInfo->callbacks = g_proxyCallbacksArray; #else diff --git a/src/driver/proxycb/fortpcb_dst_arm64.asm b/src/driver/proxycb/fortpcb_dst_arm64.asm new file mode 100644 index 00000000..57cb4331 --- /dev/null +++ b/src/driver/proxycb/fortpcb_dst_arm64.asm @@ -0,0 +1,269 @@ + AREA fortpcb_dst, CODE + + IMPORT g_proxyCallbacksArray + + MACRO + ProxyCallbackProc $index + adrl x9, g_proxyCallbacksArray + mov x10, #$index + ldr x9, [x9, x10, lsl#3] + br x9 + MEND + + EXPORT proxyCallback0 +proxyCallback0 + ProxyCallbackProc 0 + + EXPORT proxyCallback1 +proxyCallback1 + ProxyCallbackProc 1 + + EXPORT proxyCallback2 +proxyCallback2 + ProxyCallbackProc 2 + + EXPORT proxyCallback3 +proxyCallback3 + ProxyCallbackProc 3 + + EXPORT proxyCallback4 +proxyCallback4 + ProxyCallbackProc 4 + + EXPORT proxyCallback5 +proxyCallback5 + ProxyCallbackProc 5 + + EXPORT proxyCallback6 +proxyCallback6 + ProxyCallbackProc 6 + + EXPORT proxyCallback7 +proxyCallback7 + ProxyCallbackProc 7 + + EXPORT proxyCallback8 +proxyCallback8 + ProxyCallbackProc 8 + + EXPORT proxyCallback9 +proxyCallback9 + ProxyCallbackProc 9 + + EXPORT proxyCallback10 +proxyCallback10 + ProxyCallbackProc 10 + + EXPORT proxyCallback11 +proxyCallback11 + ProxyCallbackProc 11 + + EXPORT proxyCallback12 +proxyCallback12 + ProxyCallbackProc 12 + + EXPORT proxyCallback13 +proxyCallback13 + ProxyCallbackProc 13 + + EXPORT proxyCallback14 +proxyCallback14 + ProxyCallbackProc 14 + + EXPORT proxyCallback15 +proxyCallback15 + ProxyCallbackProc 15 + + EXPORT proxyCallback16 +proxyCallback16 + ProxyCallbackProc 16 + + EXPORT proxyCallback17 +proxyCallback17 + ProxyCallbackProc 17 + + EXPORT proxyCallback18 +proxyCallback18 + ProxyCallbackProc 18 + + EXPORT proxyCallback19 +proxyCallback19 + ProxyCallbackProc 19 + + EXPORT proxyCallback20 +proxyCallback20 + ProxyCallbackProc 20 + + EXPORT proxyCallback21 +proxyCallback21 + ProxyCallbackProc 21 + + EXPORT proxyCallback22 +proxyCallback22 + ProxyCallbackProc 22 + + EXPORT proxyCallback23 +proxyCallback23 + ProxyCallbackProc 23 + + EXPORT proxyCallback24 +proxyCallback24 + ProxyCallbackProc 24 + + EXPORT proxyCallback25 +proxyCallback25 + ProxyCallbackProc 25 + + EXPORT proxyCallback26 +proxyCallback26 + ProxyCallbackProc 26 + + EXPORT proxyCallback27 +proxyCallback27 + ProxyCallbackProc 27 + + EXPORT proxyCallback28 +proxyCallback28 + ProxyCallbackProc 28 + + EXPORT proxyCallback29 +proxyCallback29 + ProxyCallbackProc 29 + + EXPORT proxyCallback30 +proxyCallback30 + ProxyCallbackProc 30 + + EXPORT proxyCallback31 +proxyCallback31 + ProxyCallbackProc 31 + + EXPORT proxyCallback32 +proxyCallback32 + ProxyCallbackProc 32 + + EXPORT proxyCallback33 +proxyCallback33 + ProxyCallbackProc 33 + + EXPORT proxyCallback34 +proxyCallback34 + ProxyCallbackProc 34 + + EXPORT proxyCallback35 +proxyCallback35 + ProxyCallbackProc 35 + + EXPORT proxyCallback36 +proxyCallback36 + ProxyCallbackProc 36 + + EXPORT proxyCallback37 +proxyCallback37 + ProxyCallbackProc 37 + + EXPORT proxyCallback38 +proxyCallback38 + ProxyCallbackProc 38 + + EXPORT proxyCallback39 +proxyCallback39 + ProxyCallbackProc 39 + + EXPORT proxyCallback40 +proxyCallback40 + ProxyCallbackProc 40 + + EXPORT proxyCallback41 +proxyCallback41 + ProxyCallbackProc 41 + + EXPORT proxyCallback42 +proxyCallback42 + ProxyCallbackProc 42 + + EXPORT proxyCallback43 +proxyCallback43 + ProxyCallbackProc 43 + + EXPORT proxyCallback44 +proxyCallback44 + ProxyCallbackProc 44 + + EXPORT proxyCallback45 +proxyCallback45 + ProxyCallbackProc 45 + + EXPORT proxyCallback46 +proxyCallback46 + ProxyCallbackProc 46 + + EXPORT proxyCallback47 +proxyCallback47 + ProxyCallbackProc 47 + + EXPORT proxyCallback48 +proxyCallback48 + ProxyCallbackProc 48 + + EXPORT proxyCallback49 +proxyCallback49 + ProxyCallbackProc 49 + + EXPORT proxyCallback50 +proxyCallback50 + ProxyCallbackProc 50 + + EXPORT proxyCallback51 +proxyCallback51 + ProxyCallbackProc 51 + + EXPORT proxyCallback52 +proxyCallback52 + ProxyCallbackProc 52 + + EXPORT proxyCallback53 +proxyCallback53 + ProxyCallbackProc 53 + + EXPORT proxyCallback54 +proxyCallback54 + ProxyCallbackProc 54 + + EXPORT proxyCallback55 +proxyCallback55 + ProxyCallbackProc 55 + + EXPORT proxyCallback56 +proxyCallback56 + ProxyCallbackProc 56 + + EXPORT proxyCallback57 +proxyCallback57 + ProxyCallbackProc 57 + + EXPORT proxyCallback58 +proxyCallback58 + ProxyCallbackProc 58 + + EXPORT proxyCallback59 +proxyCallback59 + ProxyCallbackProc 59 + + EXPORT proxyCallback60 +proxyCallback60 + ProxyCallbackProc 60 + + EXPORT proxyCallback61 +proxyCallback61 + ProxyCallbackProc 61 + + EXPORT proxyCallback62 +proxyCallback62 + ProxyCallbackProc 62 + + EXPORT proxyCallback63 +proxyCallback63 + ProxyCallbackProc 63 + + END diff --git a/src/driver/proxycb/fortpcb_src.c b/src/driver/proxycb/fortpcb_src.c index 149439bf..c037afe0 100644 --- a/src/driver/proxycb/fortpcb_src.c +++ b/src/driver/proxycb/fortpcb_src.c @@ -146,7 +146,7 @@ FORT_API void fort_proxycb_src_prepare(PFORT_PROXYCB_INFO cbInfo) FORT_API void fort_proxycb_src_setup(PFORT_PROXYCB_INFO cbInfo) { -#ifdef _WIN64 +#if defined(_WIN64) && !defined(_M_ARM64) memcpy(g_proxyDstCallbacksArray, cbInfo->dst, sizeof(g_proxyDstCallbacksArray)); #else UNUSED(cbInfo); diff --git a/src/driver/proxycb/fortpcb_src_arm64.asm b/src/driver/proxycb/fortpcb_src_arm64.asm new file mode 100644 index 00000000..183666cf --- /dev/null +++ b/src/driver/proxycb/fortpcb_src_arm64.asm @@ -0,0 +1,269 @@ + AREA fortpcb_src, CODE + + IMPORT g_proxyDstCallbacksArray + + MACRO + ProxyCallbackProc $index + adrl x9, g_proxyDstCallbacksArray + mov x10, #$index + ldr x9, [x9, x10, lsl#3] + br x9 + MEND + + EXPORT proxyDstCallback0 +proxyDstCallback0 + ProxyCallbackProc 0 + + EXPORT proxyDstCallback1 +proxyDstCallback1 + ProxyCallbackProc 1 + + EXPORT proxyDstCallback2 +proxyDstCallback2 + ProxyCallbackProc 2 + + EXPORT proxyDstCallback3 +proxyDstCallback3 + ProxyCallbackProc 3 + + EXPORT proxyDstCallback4 +proxyDstCallback4 + ProxyCallbackProc 4 + + EXPORT proxyDstCallback5 +proxyDstCallback5 + ProxyCallbackProc 5 + + EXPORT proxyDstCallback6 +proxyDstCallback6 + ProxyCallbackProc 6 + + EXPORT proxyDstCallback7 +proxyDstCallback7 + ProxyCallbackProc 7 + + EXPORT proxyDstCallback8 +proxyDstCallback8 + ProxyCallbackProc 8 + + EXPORT proxyDstCallback9 +proxyDstCallback9 + ProxyCallbackProc 9 + + EXPORT proxyDstCallback10 +proxyDstCallback10 + ProxyCallbackProc 10 + + EXPORT proxyDstCallback11 +proxyDstCallback11 + ProxyCallbackProc 11 + + EXPORT proxyDstCallback12 +proxyDstCallback12 + ProxyCallbackProc 12 + + EXPORT proxyDstCallback13 +proxyDstCallback13 + ProxyCallbackProc 13 + + EXPORT proxyDstCallback14 +proxyDstCallback14 + ProxyCallbackProc 14 + + EXPORT proxyDstCallback15 +proxyDstCallback15 + ProxyCallbackProc 15 + + EXPORT proxyDstCallback16 +proxyDstCallback16 + ProxyCallbackProc 16 + + EXPORT proxyDstCallback17 +proxyDstCallback17 + ProxyCallbackProc 17 + + EXPORT proxyDstCallback18 +proxyDstCallback18 + ProxyCallbackProc 18 + + EXPORT proxyDstCallback19 +proxyDstCallback19 + ProxyCallbackProc 19 + + EXPORT proxyDstCallback20 +proxyDstCallback20 + ProxyCallbackProc 20 + + EXPORT proxyDstCallback21 +proxyDstCallback21 + ProxyCallbackProc 21 + + EXPORT proxyDstCallback22 +proxyDstCallback22 + ProxyCallbackProc 22 + + EXPORT proxyDstCallback23 +proxyDstCallback23 + ProxyCallbackProc 23 + + EXPORT proxyDstCallback24 +proxyDstCallback24 + ProxyCallbackProc 24 + + EXPORT proxyDstCallback25 +proxyDstCallback25 + ProxyCallbackProc 25 + + EXPORT proxyDstCallback26 +proxyDstCallback26 + ProxyCallbackProc 26 + + EXPORT proxyDstCallback27 +proxyDstCallback27 + ProxyCallbackProc 27 + + EXPORT proxyDstCallback28 +proxyDstCallback28 + ProxyCallbackProc 28 + + EXPORT proxyDstCallback29 +proxyDstCallback29 + ProxyCallbackProc 29 + + EXPORT proxyDstCallback30 +proxyDstCallback30 + ProxyCallbackProc 30 + + EXPORT proxyDstCallback31 +proxyDstCallback31 + ProxyCallbackProc 31 + + EXPORT proxyDstCallback32 +proxyDstCallback32 + ProxyCallbackProc 32 + + EXPORT proxyDstCallback33 +proxyDstCallback33 + ProxyCallbackProc 33 + + EXPORT proxyDstCallback34 +proxyDstCallback34 + ProxyCallbackProc 34 + + EXPORT proxyDstCallback35 +proxyDstCallback35 + ProxyCallbackProc 35 + + EXPORT proxyDstCallback36 +proxyDstCallback36 + ProxyCallbackProc 36 + + EXPORT proxyDstCallback37 +proxyDstCallback37 + ProxyCallbackProc 37 + + EXPORT proxyDstCallback38 +proxyDstCallback38 + ProxyCallbackProc 38 + + EXPORT proxyDstCallback39 +proxyDstCallback39 + ProxyCallbackProc 39 + + EXPORT proxyDstCallback40 +proxyDstCallback40 + ProxyCallbackProc 40 + + EXPORT proxyDstCallback41 +proxyDstCallback41 + ProxyCallbackProc 41 + + EXPORT proxyDstCallback42 +proxyDstCallback42 + ProxyCallbackProc 42 + + EXPORT proxyDstCallback43 +proxyDstCallback43 + ProxyCallbackProc 43 + + EXPORT proxyDstCallback44 +proxyDstCallback44 + ProxyCallbackProc 44 + + EXPORT proxyDstCallback45 +proxyDstCallback45 + ProxyCallbackProc 45 + + EXPORT proxyDstCallback46 +proxyDstCallback46 + ProxyCallbackProc 46 + + EXPORT proxyDstCallback47 +proxyDstCallback47 + ProxyCallbackProc 47 + + EXPORT proxyDstCallback48 +proxyDstCallback48 + ProxyCallbackProc 48 + + EXPORT proxyDstCallback49 +proxyDstCallback49 + ProxyCallbackProc 49 + + EXPORT proxyDstCallback50 +proxyDstCallback50 + ProxyCallbackProc 50 + + EXPORT proxyDstCallback51 +proxyDstCallback51 + ProxyCallbackProc 51 + + EXPORT proxyDstCallback52 +proxyDstCallback52 + ProxyCallbackProc 52 + + EXPORT proxyDstCallback53 +proxyDstCallback53 + ProxyCallbackProc 53 + + EXPORT proxyDstCallback54 +proxyDstCallback54 + ProxyCallbackProc 54 + + EXPORT proxyDstCallback55 +proxyDstCallback55 + ProxyCallbackProc 55 + + EXPORT proxyDstCallback56 +proxyDstCallback56 + ProxyCallbackProc 56 + + EXPORT proxyDstCallback57 +proxyDstCallback57 + ProxyCallbackProc 57 + + EXPORT proxyDstCallback58 +proxyDstCallback58 + ProxyCallbackProc 58 + + EXPORT proxyDstCallback59 +proxyDstCallback59 + ProxyCallbackProc 59 + + EXPORT proxyDstCallback60 +proxyDstCallback60 + ProxyCallbackProc 60 + + EXPORT proxyDstCallback61 +proxyDstCallback61 + ProxyCallbackProc 61 + + EXPORT proxyDstCallback62 +proxyDstCallback62 + ProxyCallbackProc 62 + + EXPORT proxyDstCallback63 +proxyDstCallback63 + ProxyCallbackProc 63 + + END diff --git a/src/driver/scripts/install.bat b/src/driver/scripts/install.bat index cb4b786c..8562fefb 100644 --- a/src/driver/scripts/install.bat +++ b/src/driver/scripts/install.bat @@ -1,7 +1,8 @@ @rem Install driver @set ARCH=x86 -@if defined PROGRAMFILES(X86) @set ARCH=x86_64 +@if "%PROCESSOR_ARCHITECTURE%" == "AMD64" @set ARCH=x86_64 +@if "%PROCESSOR_ARCHITECTURE%" == "ARM64" @set ARCH=ARM64 @set BASENAME=fortfw @set FILENAME=%BASENAME%.sys