Skip to content

Commit

Permalink
Feat: Add the shell entry
Browse files Browse the repository at this point in the history
  • Loading branch information
czs108 committed Feb 6, 2024
1 parent 3d8dc11 commit aed5cb4
Show file tree
Hide file tree
Showing 5 changed files with 53,001 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ target_include_directories(shell PUBLIC ${HEADER_PATH})

target_sources(shell
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/entry_export.h
PUBLIC
)

if(CMAKE_SIZEOF_VOID_P EQUAL 8)

message(FATAL_ERROR "[!] Must configuring on/for x86 platform")
else()
target_sources(shell
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/entry_x86.asm
${CMAKE_CURRENT_LIST_DIR}/include_x86/windows.inc
${CMAKE_CURRENT_LIST_DIR}/include_x86/winextra.inc
)

set_source_files_properties(entry_x86.asm PROPERTIES COMPILE_FLAGS "/c /coff")
set_source_files_properties(entry_x86.asm PROPERTIES LINKER_FLAGS "/SAFESEH:NO")
endif()
91 changes: 91 additions & 0 deletions src/shell/entry_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* @file entry_export.h
* @brief The fields and structures exported by the entry shell.
* @author Chen Zhenshuo (chenzs108@outlook.com)
* @version 1.0
* @date 2020-01-15
*
* @par GitHub
* https://github.com/czs108/
*
* @warning
* All exported data fields are just lables in the `.asm` shell file,
* they need to be relocated by `&` operator.
*/

#pragma once

#include "../section.h"

#include <windows.h>


//! The maximum number of encrypted sections supported by the program.
#define MAX_ENCRY_SECTION_COUNT 0x40


/**
* @brief The encryption information of a segment of the shell.
*/
typedef struct _SEG_ENCRY_INFO
{
//! The offset, relative to the shell.
DWORD seg_offset;

//! The size.
DWORD seg_size;

} SEG_ENCRY_INFO;


/**
* @brief The original PE information.
*/
typedef struct _ORIGIN_PE_INFO
{
//! The offset, relative to the shell.
DWORD entry_point;

//! The offset of the original import table, relative to the load segment.
DWORD imp_table_offset;

//! The relative virtual address of the relocation table.
DWORD reloc_table_rva;

//! The relative virtual address of the thread-local storage table.
DWORD tls_table_rva;

//! The image base.
VOID *image_base;

//! The encryption information of sections, up to 0x40 sections and a blank structure.
ENCRY_INFO section_encry_info[MAX_ENCRY_SECTION_COUNT + 1];

} ORIGIN_PE_INFO;


//! The beginning of the shell template.
extern DWORD shell_begin;


//! The beginning and the end of the import table template of the shell itself.
extern DWORD imp_table_begin;
extern DWORD imp_table_end;


//! The beginning and the end of the boot segment template.
extern DWORD boot_seg_begin;
extern DWORD boot_seg_end;


//! The beginning and the end of the load segment template.
extern DWORD load_seg_begin;
extern DWORD load_seg_end;


//! The encryption information of the load segment.
extern SEG_ENCRY_INFO load_seg_encry_info;


//! The original PE information.
extern ORIGIN_PE_INFO origin_pe_info;
Loading

0 comments on commit aed5cb4

Please sign in to comment.