Skip to content

Commit

Permalink
Added ARM support because why not (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy authored Nov 12, 2023
1 parent 12b773d commit 3104ed7
Show file tree
Hide file tree
Showing 26 changed files with 206 additions and 101 deletions.
4 changes: 4 additions & 0 deletions .github/Invoke-VisualStudio.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ Function Invoke-VisualStudio2022x64 {
Function Invoke-VisualStudio2022arm64 {
Invoke-CmdScript "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsamd64_arm64.bat"
}

Function Invoke-VisualStudio2022arm {
Invoke-CmdScript "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsamd64_arm.bat"
}
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
- {os: windows-latest, arch: x86, config: RelWithDebInfo, build: full}
- {os: windows-latest, arch: arm64, config: Debug, build: full}
- {os: windows-latest, arch: arm64, config: RelWithDebInfo, build: full}
- {os: windows-latest, arch: arm, config: Debug, build: full}
- {os: windows-latest, arch: arm, config: RelWithDebInfo, build: full}
- {os: ubuntu-latest, arch: x64, config: Debug, build: full}
- {os: ubuntu-latest, arch: x64, config: RelWithDebInfo, build: full}

Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ if(PWN_INCLUDE_DISASSEMBLER)
endif(PWN_INCLUDE_DISASSEMBLER)

if(MSVC)
if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "arm64")
enable_language(CXX ASM_MARMASM)
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x64")
if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x64")
enable_language(CXX ASM_MASM)
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "win32")
enable_language(CXX ASM_MASM)
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "arm")
enable_language(CXX ASM_MARMASM)
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "arm64")
enable_language(CXX ASM_MARMASM)
endif()
else()
enable_language(CXX ASM_NASM)
Expand Down
2 changes: 1 addition & 1 deletion Modules/Binary/Include/Win32/PE.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class PE

struct PeExceptionTableEntry : IMAGE_RUNTIME_FUNCTION_ENTRY
{
#if defined(_ARM64_)
#if defined(_ARM_) || defined(_ARM64_)
DWORD EndAddress {};
#endif
usize Size;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Binary/Source/Win32/PE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ PE::FillException()
return;
}

#if defined(_ARM64_)
#if defined(_ARM_) || defined(_ARM64_)
// TODO adjust from `Flags` field value, based on `ARM64_FNPDATA_FLAGS`
DWORD EndAddress {e.BeginAddress + e.FunctionLength};
#else
Expand Down
4 changes: 2 additions & 2 deletions Modules/Binary/Tests/pwn_binary_pe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ TEST_CASE("Native PE file parser", "[" NS "]")
{
REQUIRE(entry.BeginAddress != 0);
REQUIRE(entry.EndAddress != 0);
#ifndef _ARM64_
#if !defined(_ARM64_) && !defined(_ARM_)
REQUIRE(entry.UnwindInfoAddress != 0);
#endif // _ARM64_
#endif // !_ARM64_ && !_ARM_
}
}

Expand Down
19 changes: 16 additions & 3 deletions Modules/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ if(WIN32)

target_compile_options(${PROJECT_NAME}
PUBLIC

$<$<COMPILE_LANGUAGE:CXX>:
/Zc:__cplusplus
$<$<NOT:$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},arm64>>:$<$<CONFIG:Debug>:/fsanitize=address>>
$<IF:$<CONFIG:Debug>,/sdl /WX /Gy /Gm- /permissive-,/WX /Zi /Zf /Gm /Gm- /permissive- >
/EHsc
$<IF:$<CONFIG:Debug>,
/sdl /WX /Gy /Gm- /permissive-,
/WX /Zi /Zf /Gm /Gm- /permissive-
>
/diagnostics:caret /ZH:SHA_256

# ASAN only supported for Intel
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},x64>:$<$<CONFIG:Debug>:/fsanitize=address>>
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},win32>:$<$<CONFIG:Debug>:/fsanitize=address>>
>
PRIVATE
)
Expand All @@ -60,8 +68,13 @@ if(WIN32)
target_link_options(${PROJECT_NAME}
PUBLIC

$<$<NOT:$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},arm64>>:$<$<CONFIG:Debug>:/InferAsanLibs>>
# Link ASAN for debug
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},win32>:$<$<CONFIG:Debug>:/InferAsanLibs>>
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},x64>:$<$<CONFIG:Debug>:/InferAsanLibs>>

# Fix issues with SAFESEH linking for 32b
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},win32>:/SAFESEH:NO>
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},arm>:/SAFESEH:NO>
)

target_link_libraries(${PROJECT_NAME}
Expand Down
3 changes: 2 additions & 1 deletion Modules/Common/Include/Architecture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ struct Architecture
///
///@brief Supported architecture declarations
///
static constexpr CMap<std::string_view, Architecture, 3> Architectures {
static constexpr CMap<std::string_view, Architecture, 4> Architectures {
{{
{"x64"sv, {"X86_64"sv, ArchitectureType::x64, 8, Endianess::little}},
{"x86"sv, {"X86_32"sv, ArchitectureType::x86, 4, Endianess::little}},
{"arm64"sv, {"ARM_AARCH64"sv, ArchitectureType::arm64, 8, Endianess::little}},
{"arm"sv, {"ARM_AARCH64"sv, ArchitectureType::arm, 4, Endianess::little}},
}},
};

Expand Down
7 changes: 5 additions & 2 deletions Modules/Process/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL win32)
set(ASM_DIR ${SOURCE_DIR}/Win32/asm/x86)
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL arm64)
set(ASM_DIR ${SOURCE_DIR}/Win32/asm/arm64)
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL arm)
set(ASM_DIR ${SOURCE_DIR}/Win32/asm/arm)
else()
message(FATAL_ERROR "Unknown arch ${CMAKE_GENERATOR_PLATFORM}")
endif()
Expand All @@ -38,8 +40,9 @@ add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
add_dependencies(${PROJECT_NAME} ${DEPS})
add_library(PWN::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC ${INTERFACE_DIR} PRIVATE ${HEADER_DIR})
target_compile_definitions(${PROJECT_NAME} PUBLIC)
target_link_libraries(${PROJECT_NAME} PUBLIC ${DEPS} Userenv.lib)

# target_compile_definitions(${PROJECT_NAME} PUBLIC)
target_link_libraries(${PROJECT_NAME} PUBLIC ${DEPS} Userenv.lib Ole32.lib)

install(DIRECTORY ${INTERFACE_DIR} DESTINATION ${CMAKE_PROJECT_NAME})

Expand Down
2 changes: 1 addition & 1 deletion Modules/Process/Source/Win32/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Memory::QueryInternal(
MemoryInformationClass,
Buffer.get(),
Size,
&ReturnLength);
(PSIZE_T)&ReturnLength);
if ( NT_SUCCESS(Status) )
{
break;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Process/Source/Win32/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ AppContainer::AppContainer(
// build the startup info
//
usize size = 0;
::InitializeProcThreadAttributeList(nullptr, 1, 0, &size);
::InitializeProcThreadAttributeList(nullptr, 1, 0, (PSIZE_T)&size);
if ( size == 0u )
{
throw std::runtime_error("InitializeProcThreadAttributeList() failed");
Expand All @@ -711,7 +711,7 @@ AppContainer::AppContainer(
m_StartupInfo.StartupInfo.cb = sizeof(STARTUPINFOEX);
m_StartupInfo.lpAttributeList = (LPPROC_THREAD_ATTRIBUTE_LIST)::new u8[size];

if ( ::InitializeProcThreadAttributeList(m_StartupInfo.lpAttributeList, 1, 0, &size) == 0 )
if ( ::InitializeProcThreadAttributeList(m_StartupInfo.lpAttributeList, 1, 0, (PSIZE_T)&size) == 0 )
{
throw std::runtime_error("InitializeProcThreadAttributeList() failed");
}
Expand Down
18 changes: 12 additions & 6 deletions Modules/Process/Source/Win32/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ constexpr int WINDOWS_VERSION_22H2 = 19045;

EXTERN_C_START

#ifndef _M_ARM64
bool
GetTeb(uptr* teb);
#if defined(_ARM64_) || defined(_ARM_)

//
// TODO those are not working yet
//

usize
GetTebLength();
#else
bool
GetTeb(uptr* teb)
{
Expand All @@ -42,6 +41,13 @@ GetTebLength()
{
return 0;
}

#else
bool
GetTeb(uptr* teb);

usize
GetTebLength();
#endif // _M_ARM64
EXTERN_C_END

Expand Down
20 changes: 20 additions & 0 deletions Modules/Process/Source/Win32/asm/arm/get_teb.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GLOBAL GetPeb
GLOBAL GetPebLength

CODE


GetPeb PROC PUBLIC EXPORT
;;; TODO
BX LR
GetPeb ENDP
GetPeb_end::

GetPebLength PROC PUBLIC EXPORT
;;; TODO
BX LR
GetPebLength ENDP

ENDS

END
19 changes: 19 additions & 0 deletions Modules/Process/Source/Win32/asm/arm/trampoline.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GLOBAL GoToTrampoline
GLOBAL GoToTrampolineLength

CODE

GoToTrampoline PROC PUBLIC EXPORT
;;; TODO
bx lr
GoToTrampoline ENDP
GoToTrampoline_end::

GoToTrampolineLength PROC PUBLIC EXPORT
;;; TODO
bx lr
GoToTrampolineLength ENDP

ENDS

END
3 changes: 2 additions & 1 deletion Modules/Registry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if(NOT WIN32)
message(STATUS "The Registry module is only available for Windows")
return()
endif()

Expand All @@ -20,7 +21,7 @@ add_dependencies(${PROJECT_NAME} PWN::Common)
add_library(PWN::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC ${INTERFACE_DIR} PRIVATE ${HEADER_DIR})
target_compile_definitions(${PROJECT_NAME} PUBLIC)
target_link_libraries(${PROJECT_NAME} PUBLIC PWN::Common)
target_link_libraries(${PROJECT_NAME} PUBLIC PWN::Common AdvApi32.lib)

install(DIRECTORY ${INTERFACE_DIR} DESTINATION ${CMAKE_PROJECT_NAME})

Expand Down
13 changes: 3 additions & 10 deletions Modules/Registry/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
enable_testing()
set(TEST_EXECUTABLE_NAME tests_pwn_${PROJECT_NAME})
list(APPEND SOURCE_FILES

${TEST_DIR}/main.cpp
${TEST_DIR}/pwn_win_registry.cpp
)

add_executable(${TEST_EXECUTABLE_NAME} ${SOURCE_FILES})
add_executable(${TEST_EXECUTABLE_NAME} ${TEST_DIR}/main.cpp ${TEST_DIR}/pwn_win_registry.cpp)
add_executable(PWN::Tests::${PROJECT_NAME} ALIAS ${TEST_EXECUTABLE_NAME})
add_dependencies(${TEST_EXECUTABLE_NAME} PWN::Deps::Catch2 PWN::${PROJECT_NAME})
target_include_directories(${TEST_EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:${PROJECT_NAME},INCLUDE_DIRECTORIES>)
target_link_libraries(${TEST_EXECUTABLE_NAME} PUBLIC Catch2::Catch2WithMain PWN::${PROJECT_NAME})

if(WIN32)
target_link_options(${TEST_EXECUTABLE_NAME} PUBLIC /SUBSYSTEM:Console)
endif(WIN32)
target_link_options(${TEST_EXECUTABLE_NAME} PUBLIC /SUBSYSTEM:Console)

add_test(NAME ${TEST_EXECUTABLE_NAME} COMMAND $<TARGET_FILE:${TEST_EXECUTABLE_NAME}>)
set_tests_properties(${TEST_EXECUTABLE_NAME} PROPERTIES LABELS Common LABELS Registry)
Expand Down
2 changes: 1 addition & 1 deletion Modules/Remote/Source/Win32/ALPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Base::SendAndReceive(HANDLE hSocket, Message& MsgIn)
MsgIn.Get(),
nullptr,
reinterpret_cast<PPORT_MESSAGE>(lpRawMsgOut.get()),
&dwMsgOutLen,
(PSIZE_T)&dwMsgOutLen,
nullptr,
nullptr);
if ( !NT_SUCCESS(Status) )
Expand Down
6 changes: 5 additions & 1 deletion Modules/Security/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ add_dependencies(${PROJECT_NAME} PWN::Common PWN::System)
add_library(PWN::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC ${INTERFACE_DIR} ../System/Include PRIVATE ${HEADER_DIR})
target_compile_definitions(${PROJECT_NAME} PUBLIC)
target_link_libraries(${PROJECT_NAME} PUBLIC PWN::Common)
target_link_libraries(${PROJECT_NAME}
PUBLIC
PWN::Common
Advapi32.lib
)

install(DIRECTORY ${INTERFACE_DIR} DESTINATION ${CMAKE_PROJECT_NAME})

Expand Down
1 change: 1 addition & 0 deletions Modules/Security/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target_link_libraries(${TEST_EXECUTABLE_NAME} PUBLIC Catch2::Catch2WithMain PWN:

if(WIN32)
target_link_options(${TEST_EXECUTABLE_NAME} PUBLIC /SUBSYSTEM:Console)
target_link_libraries(${TEST_EXECUTABLE_NAME} PUBLIC AdvApi32.lib)
endif(WIN32)

add_test(NAME ${TEST_EXECUTABLE_NAME} COMMAND $<TARGET_FILE:${TEST_EXECUTABLE_NAME}>)
Expand Down
2 changes: 1 addition & 1 deletion Modules/Service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_dependencies(${PROJECT_NAME} PWN::Common)
add_library(PWN::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC ${INTERFACE_DIR} PRIVATE ${HEADER_DIR})
target_compile_definitions(${PROJECT_NAME} PUBLIC)
target_link_libraries(${PROJECT_NAME} PUBLIC PWN::Common)
target_link_libraries(${PROJECT_NAME} PUBLIC PWN::Common AdvApi32.lib)

install(DIRECTORY ${INTERFACE_DIR} DESTINATION ${CMAKE_PROJECT_NAME})

Expand Down
1 change: 1 addition & 0 deletions Modules/Shellcode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if(WIN32)
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},x64>:${SOURCE_DIR}/Win32/asm/x64/copy_system_token.asm>
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},win32>:${SOURCE_DIR}/Win32/asm/x86/copy_system_token.asm>
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},arm64>:${SOURCE_DIR}/Win32/asm/arm64/copy_system_token.asm>
$<$<STREQUAL:${CMAKE_GENERATOR_PLATFORM},arm>:${SOURCE_DIR}/Win32/asm/arm/copy_system_token.asm>
)
else()
return()
Expand Down
Loading

0 comments on commit 3104ed7

Please sign in to comment.