Skip to content

Commit

Permalink
ACE: remove gui desktop code
Browse files Browse the repository at this point in the history
deprecated
  • Loading branch information
KuhakuPixel committed Aug 8, 2023
1 parent ba8f209 commit 028ac73
Show file tree
Hide file tree
Showing 196 changed files with 62,068 additions and 2,686 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "ACE/engine/third_party/cppzmq"]
path = ACE/engine/third_party/cppzmq
path = ACE/third_party/cppzmq
url = https://github.com/KuhakuPixel/cppzmq.git
[submodule "ACE/engine/third_party/libzmq"]
path = ACE/engine/third_party/libzmq
path = ACE/third_party/libzmq
url = https://github.com/KuhakuPixel/libzmq.git
183 changes: 183 additions & 0 deletions ACE/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# Set the minimum version of CMake that can be used To find the cmake version
# run $ cmake --version
# error when compiling tests
cmake_minimum_required(VERSION 3.12)
# =======================================
# require compiler that supports c++20
# https://stackoverflow.com/questions/42834844/how-to-get-cmake-to-pass-either-std-c14-c1y-or-c17-c1z-based-on-gcc-vers
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ======================================

macro(print_all_variables)
message(STATUS "print_all_variables------------------------------------------{")
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endmacro()

# recommended way of creating options to be passed by user
# https://stackoverflow.com/questions/12896988/passing-an-argument-to-cmake-via-command-prompt
SET(ACE_ANDROID_BINARY_ROOT_OUTPUT_DIR "" CACHE PATH "Export program to a path for a ANDROID_ABI and put it in {PATH}/{ANDROID_ABI}")
# set project name
set (PROJECT_NAME "ACE")
project(${PROJECT_NAME})
# ====================================== build options ============
option(BUILD_OPTIONS "display the specified build options" FALSE)
# =================================================================

# =================================== if android build ============
# can only export to a certain path if building for android
message("ACE_ANDROID_BINARY_ROOT_OUTPUT_DIR: ${ACE_ANDROID_BINARY_ROOT_OUTPUT_DIR}")
if (NOT "${ACE_ANDROID_BINARY_ROOT_OUTPUT_DIR}" STREQUAL "")
if (ANDROID)
# set binary output folder to Android assets folder
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${ACE_ANDROID_BINARY_ROOT_OUTPUT_DIR}/${ANDROID_ABI}")
else()
message(FATAL_ERROR "Can only Set ACE_ANDROID_BINARY_ROOT_OUTPUT_DIR if building for android")
endif()

endif()
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Write-Platform-Checks
# https://stackoverflow.com/questions/9160335/os-specific-instructions-in-cmake-how-to
if (ANDROID)
message("android platform level : ${ANDROID_PLATFORM_LEVEL}")
# ensure that process_vm_readv and process_vm_writev
# is available because it is only added in API level 23
#
# bionic status:
# https://android.googlesource.com/platform/bionic/+/master/docs/status.md
if (${ANDROID_PLATFORM_LEVEL} LESS 23)
message(WARNING "ANDROID_PLATFORM needs to be at least 23 but
${ANDROID_PLATFORM_LEVEL} is passed")

message(FATAL_ERROR "You need to set -DANDROID_PLATFORM to at
least \"android-23\"")

endif()
# for android we cannot use /proc/<pid>/mem
# to read/write because it will fail on important memory region
# (return read size of 0) for some reasons, even though
# in linux desktop it is fine
#
# instead use process_vm_readv or process_vm_writev
# from <sys/uio.h>
# which works well in android
add_compile_definitions(USE_PROC_VM_READ_WRITEV)
message("using process_vm_writev and process_vm_readv")
endif()
# =================================================================

add_library(common_flag INTERFACE)

# use target_compile_options so the compile flags can be reused
# https://stackoverflow.com/a/23995391/14073678
# https://stackoverflow.com/questions/60041896/reuse-target-compile-options-from-variable-for-multiple-targets-cmake
# -fno-rtti is used so class names won't be generated
# in binary (RTTI)
# https://stackoverflow.com/a/4948438/14073678
target_compile_options(common_flag INTERFACE -Wall -Werror)


set(lib_ACE_src
src/maps.cpp src/file_utils.cpp src/error.cpp
src/str_utils.cpp src/proc_stat.cpp src/scanner.cpp src/ACE_global.cpp src/ptrace.cpp
src/input.cpp src/cheat.cpp src/cheat_cmd_handler.cpp src/ace_type.cpp
src/common.cpp src/proc_rw.cpp src/proc_create.cpp src/endian.cpp src/aslr_edit.cpp
src/main_cmd_handler.cpp src/loaded_mem_info.cpp src/scan_utils.cpp src/thread_continuous.cpp src/freeze.cpp
src/to_frontend.cpp src/math_util.cpp src/match_store.cpp src/ACE_jni.cpp src/server.cpp
src/engine_module.cpp src/cheat_session.cpp src/engine_server.cpp src/attach_client.cpp
src/main_cmd_creator.cpp src/status_publisher.cpp
)

add_library(lib_ACE SHARED ${lib_ACE_src})
add_library(lib_ACE-static STATIC ${lib_ACE_src})

# ============= link ace's library with dependencies
#
set(lib_ACE_linked_libraries common_flag cppzmq-static linenoise-static)

message("linked libraries: ${lib_ACE_linked_libraries}")
# add extra library to link to for android (logging and etc)
if(ANDROID)
list(APPEND lib_ACE_linked_libraries android log)
endif()

# make it public, so other program can use the library that is linked to lib_ACE
# if we don't make it public, the program linked with lib_ACE have to link
# manually against cppzmq-static for example, which is not pretty :D
target_link_libraries(lib_ACE PUBLIC ${lib_ACE_linked_libraries})
target_link_libraries(lib_ACE-static PUBLIC ${lib_ACE_linked_libraries})


# ============= Populating lib_ACE's Including Directories ============
# so other project can include it easily
# https://stackoverflow.com/questions/48554758/why-create-an-include-directory-in-c-and-c-projects

target_include_directories(lib_ACE
PUBLIC
${PROJECT_SOURCE_DIR}/include
)

target_include_directories(lib_ACE-static
PUBLIC
${PROJECT_SOURCE_DIR}/include
)

# =====================================================================

# ================================================================================
# for unit testing the the file's utils copy necessary files into the build
# folder Just in case that it is built in a different directory
file(COPY test/test_files DESTINATION .)

# ================================================================================
include(./cmake_utils/CMakeLists.txt)
# CTest needs to read the location of the mem check command (valgrind ,it needs
# to read from DartConfiguration.tcl, and to make that this instruction is
# needed credits :
# https://stackoverflow.com/questions/26498089/ctest-does-not-find-valgrind

include(CTest)
# add unit tests
enable_testing()

# third party library
add_subdirectory(third_party/)
# attach_client
add_subdirectory(client/)
# test
add_subdirectory(test/)
add_test(NAME test_ace COMMAND test_ace)
# ================================================================================
# build example program
add_subdirectory(example_program/)
#
add_subdirectory(program_utils/)
add_subdirectory(mock_program/)

# ===============================================================================
# build main program
add_executable(${PROJECT_NAME} src/main.cpp)
# ===============================================================================
if (STRIP_ON_RELEASE)
strip_target_on_release(${PROJECT_NAME})
endif()
# ===============================================================================
# link against the library and add compile's options defined in common_flag
target_link_libraries(${PROJECT_NAME} PRIVATE common_flag)
target_link_libraries(${PROJECT_NAME} PRIVATE lib_ACE-static)

if(BUILD_OPTIONS)
message("build options: ")
print_all_variables()
endif()

# ============================================= install options ========================

# Binaries
install (TARGETS ${PROJECT_NAME}
DESTINATION bin)
# ======================================================================================
29 changes: 29 additions & 0 deletions ACE/client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.12)

project(ACE_client)
find_package(cppzmq)

include(../cmake_utils/CMakeLists.txt)
# ======================== binaries ===============
set(client_programs attach_client util_client status_subscriber)
foreach(program_name IN LISTS client_programs)
# get the source code of the program
set(program_name_src_file "${program_name}.cpp")
# ======================= client ==================
add_executable(
${program_name}
${program_name_src_file}
)

target_link_libraries(
${program_name}
PRIVATE lib_ACE-static
)

strip_target_on_release(${program_name})
# ============================================= install options ========================

install (TARGETS ${program_name}
DESTINATION bin)
# ======================================================================================
endforeach()
7 changes: 7 additions & 0 deletions ACE/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# client
client binaries intended for use by a GUI

File | Description
----------------------------- | -----------------------------------------------
[attach_client](./attach_client.cpp) | talk to ACE's server that is already attached to a process
[util_client](./util_client.cpp) | provides access to ACE's main functions like listing processes, checking if process is alive and etc
58 changes: 58 additions & 0 deletions ACE/client/attach_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "ACE/attach_client.hpp"
#include "../third_party/CLI11.hpp"
#include "ACE/ACE_global.hpp"
#include "ACE/input.hpp"
#include "ACE/main_cmd_creator.hpp"
#include "ACE/to_frontend.hpp"
#include <iostream>
#include <stdio.h>
#include <string>

int main(int argc, char **argv) {

// ================ parse args =================
CLI::App app{"client for to ACE's server whose has been "
"attached to a process"};
// --msg command
std::string msg_to_server = "";
CLI::Option *msg_option = app.add_option(
"--msg", msg_to_server,
"send message to engine's server and get reply via stdout\n");
//
//
int port = ACE_global::engine_server_client_default_port;
app.add_option("--port", port, "default port: " + std::to_string(port));
// ==============================================
// parse inputs
try {
(app).parse(argc, argv);
} catch (const CLI::ParseError &e) {
frontend::handle_cli_parse_error(true, e);
return (app).exit(e);
}
// ==============================================
attach_client client = attach_client(port);

// only output one time request
if (*msg_option) {
std::string reply = client.request(msg_to_server);
printf("%s", reply.c_str());
}
// just run as console app if no args passed
else {
// run prompt
auto on_input = [&](std::string input_str) -> E_loop_statement {
// dont allow empty input
if (input_str.size() == 0)
return E_loop_statement::continue_;
//
std::string reply = client.request(input_str);
printf("\n%s\n", reply.c_str());
return E_loop_statement::continue_;
};

run_input_loop(on_input, "Engine Server");
}

return 0;
}
55 changes: 55 additions & 0 deletions ACE/client/status_subscriber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

/*
* demonstrate on seeing active progress by ACE
* by using publisher-subscriber pattern
* */

#include "../third_party/CLI11.hpp"
#include "ACE/ACE_global.hpp"
#include <iostream>
#include <sstream>
#include <zmq.hpp>

int main(int argc, char *argv[]) {

// ================ parse args =================
CLI::App app{"client for to listening to ACE's server's status to track "
"things like scan progress in real time"};
int port = ACE_global::status_publisher_subscriber_default_port;
app.add_option("--port", port, "default port: " + std::to_string(port));
// ==============================================
// parse inputs
try {
(app).parse(argc, argv);
} catch (const CLI::ParseError &e) {
return (app).exit(e);
}
// ==============================================

/*
* listen all message published to [port]
* */
zmq::context_t context(1);

// Socket to talk to server
zmq::socket_t subscriber(context, zmq::socket_type::sub);
subscriber.connect("tcp://localhost:" + std::to_string(port));

// empty string "" for no filter at all
// we want to receive all message
subscriber.set(zmq::sockopt::subscribe, "");

while (true) {
zmq::message_t msg_received;

zmq::recv_result_t res =
subscriber.recv(msg_received, zmq::recv_flags::none);
if (!res.has_value()) {
printf("warning: message failed to be received\n");
}

std::string data_str = std::string(msg_received.to_string());
printf("%s\n", data_str.c_str());
}
return 0;
}
26 changes: 26 additions & 0 deletions ACE/client/util_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "../third_party/CLI11.hpp"
#include "ACE/ACE_global.hpp"
#include "ACE/attach_client.hpp"
#include "ACE/input.hpp"
#include "ACE/main_cmd_creator.hpp"
#include "ACE/to_frontend.hpp"
#include <iostream>
#include <stdio.h>
#include <string>

int main(int argc, char **argv) {
CLI::App app{"client for accessing ACE's main util like listing processes, "
"checking if a process still alive and etc "};
// add ACE's main command to client
main_mode_options _main_mode_options = main_mode_options();
main_cmd_create(&app, &_main_mode_options);
// ==============================================
// parse inputs
try {
(app).parse(argc, argv);
} catch (const CLI::ParseError &e) {
frontend::handle_cli_parse_error(true, e);
return (app).exit(e);
}
return 0;
}
Loading

0 comments on commit 028ac73

Please sign in to comment.