Skip to content

Commit

Permalink
[FEATURE] If old loader selected, use old redir
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed May 1, 2022
1 parent 77eff1c commit 0fc38b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
17 changes: 9 additions & 8 deletions pe2shc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project ( pe2shc )

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")

option(OLD_STUB "Build with the old stub" OFF)
option(OLD_LOADER "Build with the old loader stub" OFF)

# include libpeconv headers:
include_directories ( ${PECONV_DIR}/include )
Expand All @@ -18,14 +18,15 @@ set (hdrs
resource.h
)

if( OLD_STUB)
set (rsrc
resource1.rc
)
if( OLD_LOADER )
set (rsrc
resource1.rc
)
add_definitions(-DOLD_LOADER)
else()
set (rsrc
resource2.rc
)
set (rsrc
resource2.rc
)
endif()

add_executable ( ${PROJECT_NAME} ${hdrs} ${srcs} ${rsrc} main.cpp )
Expand Down
12 changes: 7 additions & 5 deletions pe2shc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

bool overwrite_hdr(BYTE *my_exe, size_t exe_size, DWORD raw, bool is64b)
{
size_t value_pos = 8;
const size_t value_pos = 8;
size_t redir_size = 0;
BYTE* redir_code = nullptr;

Expand Down Expand Up @@ -36,14 +36,16 @@ bool overwrite_hdr(BYTE *my_exe, size_t exe_size, DWORD raw, bool is64b)
"\xFF\xD3" // call ebx
"\xc3"; // ret

redir_code = redir_code32;
redir_size = sizeof(redir_code32);

#ifndef OLD_LOADER
if (is64b) {
redir_code = redir_code64;
redir_size = sizeof(redir_code64);
}
else {
redir_code = redir_code32;
redir_size = sizeof(redir_code32);
}
#endif

if (!redir_code) return false;

size_t offset = redir_size - value_pos;
Expand Down

0 comments on commit 0fc38b6

Please sign in to comment.