Skip to content

Commit

Permalink
Remove useless files
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Dec 10, 2021
1 parent fe7353d commit ef5a205
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 27 deletions.
2 changes: 0 additions & 2 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ add_library(demo-module SHARED
target_compile_definitions(demo-module PUBLIC -DDEMOMODULE_EXPORTS)
set_target_properties(demo-module PROPERTIES
FOLDER demo
LINK_FLAGS_DEBUG "/DEF:${CMAKE_CURRENT_SOURCE_DIR}/demo-module/demo-moduled.def"
LINK_FLAGS_RELEASE "/DEF:${CMAKE_CURRENT_SOURCE_DIR}/demo-module/demo-module.def"
ARCHIVE_OUTPUT_DIRECTORY "${MMLOADER_DEMO_OUT}/lib"
LIBRARY_OUTPUT_DIRECTORY "${MMLOADER_DEMO_OUT}/bin"
RUNTIME_OUTPUT_DIRECTORY "${MMLOADER_DEMO_OUT}/bin"
Expand Down
12 changes: 7 additions & 5 deletions demo/demo-mmloader/demo-mmloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ main() {

// Here we just read the module data from disk file
// In your real project you can download the module data from remote without writing to disk file
#ifdef _DEBUG
TCHAR szDllPath[] = _T("demo-moduled.dll");
#else
TCHAR szDllPath[] = _T("demo-module.dll");
#endif
AutoReleaseModuleBuffer moduleBuffer(szDllPath);

// Load the module from the buffer
Expand All @@ -102,7 +98,7 @@ main() {
_tprintf(_T("Module was loaded successfully. Module Base: 0x%p!\r\n"), (LPVOID)hMemModule);

// Get address of function demoFunction
LPVOID lpAddr = (LPVOID)MemModuleHelper(MHM_FARPROC_GETPROC, hMemModule, "demoFunction", 0);
LPVOID lpAddr = (LPVOID)MemModuleHelper(MHM_FARPROC_GETPROC, hMemModule, "demoFunction", (VOID *)TRUE);
if (lpAddr) {
_tprintf(_T("Get address of demoFunction successfully. Address: 0x%p!\r\n"), lpAddr);

Expand All @@ -113,6 +109,12 @@ main() {
Type_TargetFunction pfnFunction = (Type_TargetFunction)lpAddr;

unsigned char buf[MAX_PATH] = {0};

//Load the module with LoadLibrary for debug
HMODULE m = ::LoadLibraryA(szDllPath);
Type_TargetFunction f = (Type_TargetFunction)::GetProcAddress(m, "demoFunction");
f(buf, MAX_PATH);

if (pfnFunction(buf, MAX_PATH)) {
char *p = "{f56fee02-16d1-44a3-b191-4d7535f92ca5}";
iRet = ::memcmp(buf, p, strlen(p));
Expand Down
53 changes: 45 additions & 8 deletions demo/demo-module/demo-module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,52 @@
//

#include "stdafx.h"

#include <string>

#include "demo-module.h"

static std::string msg = "Hello World";

std::string
get_str() {
return "hello string";
}

// This is an example of an exported function.
DEMOMODULE_API BOOL _stdcall demoFunction(unsigned char* buffer, unsigned int size)
{
if (!buffer)
return FALSE;

char* p = "{f56fee02-16d1-44a3-b191-4d7535f92ca5}";
memcpy_s(buffer, size, p, strlen(p));
return TRUE;
DEMOMODULE_API BOOL
demoFunction(unsigned char *buffer, unsigned int size) {
if (!buffer)
return FALSE;

OutputDebugStringA("global static string:");
printf("global static string:");

OutputDebugStringA(msg.c_str());
printf(msg.c_str());

OutputDebugStringA("\n");
printf("\n");

OutputDebugStringA("local static the_string:");
printf("local static the_string:");

static std::string the_string = get_str(); // crash on windows xp
if (!the_string.empty()) {
printf(the_string.c_str());
OutputDebugStringA(the_string.c_str());
} else {
// bad behavior on windows 7 and later. string is always emtpy
OutputDebugStringA("empty");
printf("empty");
}
OutputDebugStringA("\n");
printf("\n");

if (!buffer)
return FALSE;

std::string s = "{f56fee02-16d1-44a3-b191-4d7535f92ca5}";
memcpy_s(buffer, size, s.data(), s.length());
return TRUE;
}
4 changes: 0 additions & 4 deletions demo/demo-module/demo-module.def

This file was deleted.

16 changes: 13 additions & 3 deletions demo/demo-module/demo-module.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The following ifdef block is the standard way of creating macros which make exporting
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the DEMOMODULE_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// that uses this DLL. This way any other project whose source files include this file see
// DEMOMODULE_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef DEMOMODULE_EXPORTS
Expand All @@ -10,5 +10,15 @@
#define DEMOMODULE_API __declspec(dllimport)
#endif

#if defined(__cplusplus)
extern "C" {
#endif

DEMOMODULE_API BOOL
demoFunction(unsigned char *buffer, unsigned int size);


#if defined(__cplusplus)
}
#endif
// This class is exported from the demo-module.dll
DEMOMODULE_API BOOL _stdcall demoFunction(unsigned char* buffer, unsigned int size);
4 changes: 0 additions & 4 deletions demo/demo-module/demo-moduled.def

This file was deleted.

2 changes: 1 addition & 1 deletion gen-vc-proj.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake ^
-S . ^
-B .build ^
-G "Visual Studio 16 2019" ^
-G "Visual Studio 17 2022" ^
-A Win32 ^
-DCMAKE_SYSTEM_VERSION=10.0.18362.0 ^
-DCMAKE_INSTALL_PREFIX=./pacakge ^
Expand Down

0 comments on commit ef5a205

Please sign in to comment.