Skip to content

Commit

Permalink
[NOBIN] Added DLL test
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Nov 21, 2022
1 parent 1f4c9d9 commit 03e071d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
#add the application that will be used for tests:
add_subdirectory ( test_case1 )
add_subdirectory ( dcp_test )

add_subdirectory ( test_case2_dll )
enable_testing()

#WARNING: in order for tests to work, all the binaries must be installed by: cmake --build . --target install
Expand All @@ -29,3 +29,14 @@ set_tests_properties(ConvTestCase1 PROPERTIES PASS_REGULAR_EXPRESSION "Saved as:
add_test(RunTestCase1 "${CMAKE_INSTALL_PREFIX}//runshc.exe" "${CMAKE_INSTALL_PREFIX}//test_case1.shc.exe")
set_tests_properties(RunTestCase1 PROPERTIES DEPENDS test_case1)
set_tests_properties(RunTestCase1 PROPERTIES PASS_REGULAR_EXPRESSION "Test passed!")

# 4) convert DLL
add_test(ConvTestCase2 "${CMAKE_INSTALL_PREFIX}//pe2shc.exe" "${CMAKE_INSTALL_PREFIX}//test_case2.dll" "${CMAKE_INSTALL_PREFIX}//test_case2.shc.dll")
set_tests_properties(ConvTestCase2 PROPERTIES PASS_REGULAR_EXPRESSION "Saved as:")
set_tests_properties(RunPe2Shc PROPERTIES DEPENDS pe2shc)

# 5) does converted DLL loads & unloads properly
add_test(RunTestCase2 "${CMAKE_INSTALL_PREFIX}//runshc.exe" "${CMAKE_INSTALL_PREFIX}//test_case2.shc.dll")
set_tests_properties(RunTestCase2 PROPERTIES DEPENDS test_case2_dll)
set_tests_properties(RunTestCase2 PROPERTIES DEPENDS runshc)
set_tests_properties(RunTestCase2 PROPERTIES PASS_REGULAR_EXPRESSION "DLL loaded*DLL unloaded*>>> FINISHED.")
17 changes: 17 additions & 0 deletions tests/test_case2_dll/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required ( VERSION 3.0 )
project (test_case2)

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

set (srcs
main.cpp
)

set (hdrs
)

add_library ( ${PROJECT_NAME} SHARED ${hdrs} ${srcs} main.def)

#install
INSTALL( TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT ${PROJECT_NAME} )
58 changes: 58 additions & 0 deletions tests/test_case2_dll/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <Windows.h>
#include <iostream>

#define TEST_NAME "Test Case 2"
inline DWORD rotl32a(DWORD x, DWORD n)
{
return (x << n) | (x >> (32 - n));
}

inline char to_lower(char c)
{
if (c >= 'A' && c <= 'Z') {
c = c - 'A' + 'a';
}
return c;
}

DWORD calc_checksum(BYTE *str, size_t buf_size, bool enable_tolower)
{
if (str == NULL) return 0;

DWORD checksum = 0;
for (size_t i = 0; i < buf_size; i++) {
checksum = rotl32a(checksum, 7);
char c = str[i];
if (enable_tolower) {
c = to_lower(c);
}
checksum ^= c;
}
return checksum;
}

int test_checksum1()
{
char test1[] = "this is a test!";
DWORD checks = calc_checksum((BYTE*)test1, strlen(test1), true);
std::cout << "Checks 1: " << std::hex << checks << std::endl;
return checks;
}

BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
std::cout << __FUNCTION__ << std::endl;
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
std::cout << TEST_NAME << " DLL loaded\n";
test_checksum1();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
std::cout << TEST_NAME << " DLL unloaded\n";
break;
}
return TRUE;
}
1 change: 1 addition & 0 deletions tests/test_case2_dll/main.def
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LIBRARY test_case2

0 comments on commit 03e071d

Please sign in to comment.