Skip to content

Commit

Permalink
Feat: Add the check for whether the PE matches the platform
Browse files Browse the repository at this point in the history
  • Loading branch information
czs108 committed Feb 6, 2024
1 parent e313ff6 commit ea1f418
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
27 changes: 27 additions & 0 deletions include/utility/platform_check.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @file platform_check.h
* @brief Check if the PE image matches the program platform.
* @author Chen Zhenshuo (chenzs108@outlook.com)
* @version 1.0
* @date 2020-01-14
*
* @par GitHub
* https://github.com/czs108/
*
* @note The implementation is different between x64 and x86 platforms.
*/

#pragma once

#include "../image.h"

#include <stdbool.h>

/**
* @brief Check if the PE image matches the program platform.
*
* @param image_info The PE image.
* @return `true` if the PE image matches the program platform, otherwise `false`.
*/
bool IsPeMatchPlatform(
const PE_IMAGE_INFO *const image_info);
15 changes: 14 additions & 1 deletion src/utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ target_sources(utility
PUBLIC
${HEADER_PATH}/error_handling.h
${HEADER_PATH}/file_access.h
)
${HEADER_PATH}/platform_check.h
)

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
target_sources(utility
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/platform_check_x64.c
)
else()
target_sources(utility
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/platform_check_x86.c
)
endif()
25 changes: 25 additions & 0 deletions src/utility/platform_check_x64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @file platform_check_x64.c
* @brief Check if the PE image matches the program platform.
* @author Chen Zhenshuo (chenzs108@outlook.com)
* @version 1.0
* @date 2020-01-14
*
* @par GitHub
* https://github.com/czs108/
*
* @note This implementation is for x64 platforms.
*/

#include "platform_check.h"

#include <assert.h>


bool IsPeMatchPlatform(
const PE_IMAGE_INFO *const image_info)
{
assert(image_info != NULL);

return IsPe64(image_info);
}
25 changes: 25 additions & 0 deletions src/utility/platform_check_x86.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @file platform_check_x86.c
* @brief Check if the PE image matches the program platform.
* @author Chen Zhenshuo (chenzs108@outlook.com)
* @version 1.0
* @date 2020-01-14
*
* @par GitHub
* https://github.com/czs108/
*
* @note This implementation is for x86 platforms.
*/

#include "platform_check.h"

#include <assert.h>


bool IsPeMatchPlatform(
const PE_IMAGE_INFO *const image_info)
{
assert(image_info != NULL);

return IsPe64(image_info) != true;
}

0 comments on commit ea1f418

Please sign in to comment.