Skip to content

Commit

Permalink
Feat: Add the processing of sections
Browse files Browse the repository at this point in the history
  • Loading branch information
czs108 committed Feb 6, 2024
1 parent b79e1f6 commit 836002b
Show file tree
Hide file tree
Showing 3 changed files with 519 additions and 0 deletions.
88 changes: 88 additions & 0 deletions include/section.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* @file section.h
* @brief Modify sections.
* @author Chen Zhenshuo (chenzs108@outlook.com)
* @version 1.0
* @date 2020-01-12
*
* @par GitHub
* https://github.com/czs108/
*/

#pragma once

#include "image.h"
#include "utility/encrypt.h"

#include <windows.h>

/**
* @brief The encryption information of a section.
*/
typedef struct _ENCRY_INFO
{
//! The relative virtual address of the section.
DWORD rva;

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

} ENCRY_INFO;


/**
* @brief Append a new section to the PE image.
*
* @public @memberof _PE_IMAGE_INFO
*
* @param image_info The PE image.
* @param name The name of the new section.
* @param size The size of the new section.
* @param[out] header The `IMAGE_SECTION_HEADER` structure of the new section.
* @return `true` if the method succeeds, otherwise `false`.
*/
bool AppendNewSection(
PE_IMAGE_INFO *const image_info,
const CHAR *const name,
const DWORD size,
IMAGE_SECTION_HEADER *const header);


/**
* @brief Get the number of sections that can be encrypted.
*
* @public @memberof _PE_IMAGE_INFO
*
* @param image_info The PE image.
* @return The number of sections that can be encrypted.
*/
WORD GetEncryptableSectionNumber(
const PE_IMAGE_INFO *const image_info);


/**
* @brief Encrypt sections.
*
* @public @memberof _PE_IMAGE_INFO
*
* @param image_info The PE image.
* @param encry_info
* The array where the encryption information will be saved,
* and its length must be larger than the value returned by `GetNumOfSectionsCanBeEncrypted()` method.
* Set this to `NULL` to get the required length.
* @return The number of sections can be encrypted.
*/
WORD EncryptSections(
const PE_IMAGE_INFO *const image_info,
ENCRY_INFO *const encry_info);


/**
* @brief Clear the section name.
*
* @public @memberof _PE_IMAGE_INFO
*
* @param image_info The PE image.
*/
void ClearSectionNames(
const PE_IMAGE_INFO *const image_info);
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ target_sources(PE-Packer

${CMAKE_CURRENT_LIST_DIR}/import_table.c
${HEADER_PATH}/import_table.h

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

target_link_libraries(PE-Packer utility)
Loading

0 comments on commit 836002b

Please sign in to comment.