Skip to content

Commit

Permalink
Feat: Add the processing of extra data
Browse files Browse the repository at this point in the history
  • Loading branch information
czs108 committed Feb 6, 2024
1 parent 87a0846 commit dde8e33
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
45 changes: 45 additions & 0 deletions include/extra_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @file extra_data.h
* @brief Process the extra data behind the PE image.
* @author Chen Zhenshuo (chenzs108@outlook.com)
* @version 1.0
* @date 2020-01-12
*
* @par GitHub
* https://github.com/czs108/
*/

#pragma once

#include <windows.h>

#include <stdbool.h>

/**
* @brief The view of the extra data.
*
* @see `LoadPeImage()`
*/
typedef struct _EXTRA_DATA_VIEW
{
//! The base address of the data.
const BYTE* base;

//! The size of the data.
DWORD size;

} EXTRA_DATA_VIEW;


/**
* @brief Write the extra data to the file.
*
* @public @memberof _EXTRA_DATA_VIEW
*
* @param data The extra data.
* @param file The file.
* @return `true` if the method succeeds, otherwise `false`.
*/
bool WriteExtraDataToFile(
const EXTRA_DATA_VIEW *const data,
const HANDLE file);
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ target_include_directories(PE-Packer PRIVATE ${HEADER_PATH})
target_sources(PE-Packer
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/main.c

${CMAKE_CURRENT_LIST_DIR}/extra_data.c
${HEADER_PATH}/extra_data.h
)

target_link_libraries(PE-Packer utility)
34 changes: 34 additions & 0 deletions src/extra_data.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @file extra_data.c
* @brief Process the extra data behind the PE image.
* @author Chen Zhenshuo (chenzs108@outlook.com)
* @version 1.0
* @date 2020-01-12
*
* @par GitHub
* https://github.com/czs108/
*/

#include "extra_data.h"
#include "utility/file_access.h"

#include <assert.h>

bool WriteExtraDataToFile(
const EXTRA_DATA_VIEW *const data,
const HANDLE file)
{
assert(data != NULL);
assert(file != INVALID_HANDLE_VALUE);

if (data->size > 0)
{
assert(data->base != NULL);

return WriteAllToFile(file, data->base, data->size);
}
else
{
return true;
}
}

0 comments on commit dde8e33

Please sign in to comment.