From d39fda9f85180babb14f851300544970f749fa9a Mon Sep 17 00:00:00 2001 From: Diogo Andrei Benvenutti Date: Sun, 7 Jan 2018 01:18:51 +0100 Subject: [PATCH 1/8] Add initial CMake script --- CMakeLists.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1ed1dd8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(memscan VERSION 0.1.0 LANGUAGES CXX) + +## build settings: + +set(CMAKE_CXX_STANDARD 11) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the build type" FORCE) +endif() + +set(CMAKE_CXX_FLAGS_RELEASE -O2) + +## files: + +set(source_files + Memscan.cpp + main.cpp + utils.cpp) + +set(header_files + Memscan.h + utils.h) + +## executable: + +add_executable(${PROJECT_NAME} + ${source_files} + ${header_files}) From 2e5b66ccf9a870bd4a09295c16e3914c3bcf1533 Mon Sep 17 00:00:00 2001 From: Diogo Andrei Benvenutti Date: Sun, 7 Jan 2018 01:25:55 +0100 Subject: [PATCH 2/8] Add gitignore file --- .gitignore | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a2eb44 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Build folder +**/build + +# Temporary user files +**/CMakeLists.txt.user From eb465795a323cf8b760adf9fab092ff5f6a25d4c Mon Sep 17 00:00:00 2001 From: Diogo Andrei Benvenutti Date: Sun, 7 Jan 2018 01:28:25 +0100 Subject: [PATCH 3/8] Windows condition check --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ed1dd8..97eca6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,12 @@ cmake_minimum_required(VERSION 3.2 FATAL_ERROR) project(memscan VERSION 0.1.0 LANGUAGES CXX) +## build conditions: + +if(NOT MSVC) + message(FATAL_ERROR "Error: memscan only supports Windows right now!") +endif() + ## build settings: set(CMAKE_CXX_STANDARD 11) From 443b2804fa1987babc5fd4972e5070cbdfe4f3ce Mon Sep 17 00:00:00 2001 From: Diogo Andrei Benvenutti Date: Sun, 7 Jan 2018 01:01:42 +0100 Subject: [PATCH 4/8] Call Unicode (x64) Windows API functions --- Memscan.cpp | 2 +- utils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Memscan.cpp b/Memscan.cpp index d024015..069e5fd 100644 --- a/Memscan.cpp +++ b/Memscan.cpp @@ -56,7 +56,7 @@ Memscan::Memscan(string pin, PROCESS_MODE process_mode) { wchar_t* temp_process_name = new wchar_t[temp_size]; // loop gets process name from process handle while (true) { - if (0 == GetProcessImageFileName(process_handle, temp_process_name, temp_size)) { + if (0 == GetProcessImageFileNameW(process_handle, temp_process_name, temp_size)) { cerr << "Error: GetProcessImageFileName() failed in " << basename(__FILE__) << ":" << __LINE__ << ". Last error: " << GetLastError() << "." << endl; exit(1); } else if (wcslen(temp_process_name) == (temp_size-1)) { diff --git a/utils.cpp b/utils.cpp index 2e8abda..663ccc8 100644 --- a/utils.cpp +++ b/utils.cpp @@ -200,7 +200,7 @@ HMODULE get_base_address(HANDLE process_handle, wstring path) { wchar_t* module_path = new wchar_t[path.length()+1]; // find module of specified path for (int i = 0; i < (needed/sizeof(HMODULE)); i++) { - GetModuleFileNameEx(process_handle, hmarr[i], module_path, (DWORD) path.length()); + GetModuleFileNameExW(process_handle, hmarr[i], module_path, (DWORD) path.length()); if (to_upper(basename(path)) == to_upper(basename(module_path))) { rtn = hmarr[i]; break; From e2830e82fbf87de3263726542214ea68035e8de2 Mon Sep 17 00:00:00 2001 From: Diogo Andrei Benvenutti Date: Sun, 7 Jan 2018 01:07:18 +0100 Subject: [PATCH 5/8] Check arch is x64 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97eca6a..efafecf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,8 @@ project(memscan VERSION 0.1.0 LANGUAGES CXX) ## build conditions: -if(NOT MSVC) - message(FATAL_ERROR "Error: memscan only supports Windows right now!") +if(NOT MSVC OR NOT ${CMAKE_SIZEOF_VOID_P} STREQUAL 4) + message(FATAL_ERROR "Error: memscan only supports Windows x64 right now!") endif() ## build settings: From 111673ea2d4c8e0113fafecced862e73fc4a8b21 Mon Sep 17 00:00:00 2001 From: Diogo Andrei Benvenutti Date: Sun, 7 Jan 2018 01:10:43 +0100 Subject: [PATCH 6/8] Add appveyor build script --- appveyor.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..080943f --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,18 @@ +os: Visual Studio 2015 + +platform: + - x64 + +configuration: + - Debug + - Release + +init: + - cmd: cmake --version + - cmd: msbuild /version + +build_script: + - cmd: md build + - cmd: cd build + - cmd: cmake -G "Visual Studio 14 2015 Win64" .. + - cmd: cmake --build . --config %configuration% From 8835e9862a4b22f87dfa98359f8a19001bfe40d5 Mon Sep 17 00:00:00 2001 From: Diogo Andrei Benvenutti Date: Sun, 7 Jan 2018 01:15:23 +0100 Subject: [PATCH 7/8] Remove x64 system check Failing on non-x64 systems actually disabled the option of cross compiling. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efafecf..97eca6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,8 @@ project(memscan VERSION 0.1.0 LANGUAGES CXX) ## build conditions: -if(NOT MSVC OR NOT ${CMAKE_SIZEOF_VOID_P} STREQUAL 4) - message(FATAL_ERROR "Error: memscan only supports Windows x64 right now!") +if(NOT MSVC) + message(FATAL_ERROR "Error: memscan only supports Windows right now!") endif() ## build settings: From fd521b2e8f947da7dc8a7b7e6c711fe2e193dfc1 Mon Sep 17 00:00:00 2001 From: Diogo Andrei Benvenutti Date: Sun, 7 Jan 2018 01:28:39 +0100 Subject: [PATCH 8/8] Update README with build info --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 4659c65..fa5f264 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,17 @@ You can also specify the combination of memory units you want to scan for (e.g., Would scan the process for dwords and quadwords. +### Building + +Being [Cmake](https://cmake.org/)-based, configure the project (preferably *out-of-source*) and run the build. Here is an example: + +```shh +memscan$ mkdir build +memscan$ cd build +memscan/build$ cmake .. +memscan/build$ cmake --build . +``` + ### License memscan is distributed under the GNU General Public License v3.0 (GPLv3).