From c98276d33fd44e1b7f90ff1401c430cb33465174 Mon Sep 17 00:00:00 2001 From: liuyx <327803744@qq.com> Date: Sun, 2 Apr 2017 10:30:27 +0800 Subject: [PATCH] add config.h & remove intermidle file --- CMakeCache.txt | 54 ------ CMakeFiles/cmake.check_cache | 1 - CMakeLists.txt | 7 +- HookerFactory.cpp | 10 +- HookerFactory.h | 5 +- Makefile | 330 ++++++++++++++++++++++++++++++++++- config.h | 16 ++ installer.sh | 2 - 8 files changed, 348 insertions(+), 77 deletions(-) delete mode 100644 CMakeCache.txt delete mode 100644 CMakeFiles/cmake.check_cache create mode 100644 config.h delete mode 100755 installer.sh diff --git a/CMakeCache.txt b/CMakeCache.txt deleted file mode 100644 index bd84bb6..0000000 --- a/CMakeCache.txt +++ /dev/null @@ -1,54 +0,0 @@ -# This is the CMakeCache file. -# For build in directory: /cygdrive/f/c-c++/inline-hook -# It was generated by CMake: /usr/bin/cmake.exe -# You can edit this file to change values found and used by cmake. -# If you do not want to change any of the values, simply exit the editor. -# If you do want to change a value, simply edit, save, and exit the editor. -# The syntax for the file is as follows: -# KEY:TYPE=VALUE -# KEY is the name of a variable in the cache. -# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. -# VALUE is the current value for the KEY. - -######################## -# EXTERNAL cache entries -######################## - -//If true, cmake will use relative paths in makefiles and projects. -CMAKE_USE_RELATIVE_PATHS:BOOL=OFF - - -######################## -# INTERNAL cache entries -######################## - -//This is the directory where this CMakeCache.txt was created -CMAKE_CACHEFILE_DIR:INTERNAL=/cygdrive/f/c-c++/inline-hook -//Major version of cmake used to create the current loaded cache -CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 -//Minor version of cmake used to create the current loaded cache -CMAKE_CACHE_MINOR_VERSION:INTERNAL=3 -//Patch version of cmake used to create the current loaded cache -CMAKE_CACHE_PATCH_VERSION:INTERNAL=2 -//Path to CMake executable. -CMAKE_COMMAND:INTERNAL=/usr/bin/cmake.exe -//Path to cpack program executable. -CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack.exe -//Path to ctest program executable. -CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest.exe -//Path to cache edit program executable. -CMAKE_EDIT_COMMAND:INTERNAL=/usr/bin/ccmake.exe -//Name of generator platform. -CMAKE_GENERATOR_PLATFORM:INTERNAL= -//Name of generator toolset. -CMAKE_GENERATOR_TOOLSET:INTERNAL= -//Source directory with the top level CMakeLists.txt file for this -// project -CMAKE_HOME_DIRECTORY:INTERNAL=/cygdrive/f/c-c++/inline-hook -//number of local generators -CMAKE_NUMBER_OF_LOCAL_GENERATORS:INTERNAL=1 -//Path to CMake installation. -CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.3.2 -//ADVANCED property for variable: CMAKE_USE_RELATIVE_PATHS -CMAKE_USE_RELATIVE_PATHS-ADVANCED:INTERNAL=1 - diff --git a/CMakeFiles/cmake.check_cache b/CMakeFiles/cmake.check_cache deleted file mode 100644 index 3dccd73..0000000 --- a/CMakeFiles/cmake.check_cache +++ /dev/null @@ -1 +0,0 @@ -# This file is generated by cmake for dependency checking of the CMakeCache.txt file diff --git a/CMakeLists.txt b/CMakeLists.txt index b4c3862..22d9910 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ -cmake_minimum_required(VERSION 3.6) -project(c__11) +cmake_minimum_required(VERSION 2.8) +project(hooker-test) set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_FLAGS "-std=c++11") set(SOURCE_FILES main.cpp Hooker.cpp Hooker.h HookerFactory.cpp HookerFactory.h HookerX64.cpp HookerX64.h HookerX86.cpp HookerX86.h HookerArm.cpp HookerArm.h HookerThumb.cpp HookerThumb.h) -add_executable(c__11 ${SOURCE_FILES}) +add_executable(hooker-test ${SOURCE_FILES}) diff --git a/HookerFactory.cpp b/HookerFactory.cpp index ae6ae3e..73bc96a 100644 --- a/HookerFactory.cpp +++ b/HookerFactory.cpp @@ -2,9 +2,11 @@ // Created by lamoliu on 2017/4/1. // +#include #include +#include #include "HookerFactory.h" -#include "HookerX64.h" +#include "config.h" std::unique_ptr hooker::HookerFactory::getInstance() { static std::unique_ptr sInstance; @@ -20,11 +22,11 @@ std::unique_ptr hooker::HookerFactory::getHooker() { #ifdef __x86_64__ return std::unique_ptr(std::move(new hooker::HookerX64)); #elif defined(__i386__) - return std::unique_ptr(std::move(new HookerX86)); + return std::unique_ptr(std::move(new hooker::HookerX86)); #elif defined(__arm__) - return std::unique_ptr(std::move(new HookerArm)); + return std::unique_ptr(std::move(new hooker::HookerArm)); #elif defined(__thumb__) - return std::unique_ptr(std::move(new HookerThumb)); + return std::unique_ptr(std::move(new hooker::HookerThumb)); #else throw std::string("unsupported hook architecture"); #endif diff --git a/HookerFactory.h b/HookerFactory.h index 9834f05..ce07535 100644 --- a/HookerFactory.h +++ b/HookerFactory.h @@ -13,10 +13,7 @@ namespace hooker { class HookerFactory { public: static std::unique_ptr getInstance(); - Hooker* getHooker(); - HookerFactory(const HookerFactory&) = delete; - HookerFactory&operator=(const HookerFactory&) = delete; - ~HookerFactory() = default; + std::unique_ptr getHooker(); private: explicit HookerFactory(){} }; diff --git a/Makefile b/Makefile index 0bdf802..96f8984 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,325 @@ -all: - make libinline-intel.so - make test -test: - g++ -std=c++11 -o $@ main.cpp -L. -linline-intel +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 2.8 -libinline-intel.so: - g++ -std=c++11 -o $@ inline-intel.cpp -fPIC -shared +# Default target executed when no arguments are given to make. +default_target: all +.PHONY : default_target +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + +# A target that is always out of date. +cmake_force: +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/liuyx/work/learn/inline-hook/inline-hook + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/liuyx/work/learn/inline-hook/inline-hook + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..." + /usr/bin/cmake -i . +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache +.PHONY : rebuild_cache/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/liuyx/work/learn/inline-hook/inline-hook/CMakeFiles /home/liuyx/work/learn/inline-hook/inline-hook/CMakeFiles/progress.marks + $(MAKE) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /home/liuyx/work/learn/inline-hook/inline-hook/CMakeFiles 0 +.PHONY : all + +# The main clean target clean: - rm -rf test - rm -rf libinline-intel.so + $(MAKE) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named hooker-test + +# Build rule for target. +hooker-test: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 hooker-test +.PHONY : hooker-test + +# fast build rule for target. +hooker-test/fast: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/build +.PHONY : hooker-test/fast + +Hooker.o: Hooker.cpp.o +.PHONY : Hooker.o + +# target to build an object file +Hooker.cpp.o: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/Hooker.cpp.o +.PHONY : Hooker.cpp.o + +Hooker.i: Hooker.cpp.i +.PHONY : Hooker.i + +# target to preprocess a source file +Hooker.cpp.i: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/Hooker.cpp.i +.PHONY : Hooker.cpp.i + +Hooker.s: Hooker.cpp.s +.PHONY : Hooker.s + +# target to generate assembly for a file +Hooker.cpp.s: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/Hooker.cpp.s +.PHONY : Hooker.cpp.s + +HookerArm.o: HookerArm.cpp.o +.PHONY : HookerArm.o + +# target to build an object file +HookerArm.cpp.o: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerArm.cpp.o +.PHONY : HookerArm.cpp.o + +HookerArm.i: HookerArm.cpp.i +.PHONY : HookerArm.i + +# target to preprocess a source file +HookerArm.cpp.i: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerArm.cpp.i +.PHONY : HookerArm.cpp.i + +HookerArm.s: HookerArm.cpp.s +.PHONY : HookerArm.s + +# target to generate assembly for a file +HookerArm.cpp.s: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerArm.cpp.s +.PHONY : HookerArm.cpp.s + +HookerFactory.o: HookerFactory.cpp.o +.PHONY : HookerFactory.o + +# target to build an object file +HookerFactory.cpp.o: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerFactory.cpp.o +.PHONY : HookerFactory.cpp.o + +HookerFactory.i: HookerFactory.cpp.i +.PHONY : HookerFactory.i + +# target to preprocess a source file +HookerFactory.cpp.i: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerFactory.cpp.i +.PHONY : HookerFactory.cpp.i + +HookerFactory.s: HookerFactory.cpp.s +.PHONY : HookerFactory.s + +# target to generate assembly for a file +HookerFactory.cpp.s: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerFactory.cpp.s +.PHONY : HookerFactory.cpp.s + +HookerThumb.o: HookerThumb.cpp.o +.PHONY : HookerThumb.o + +# target to build an object file +HookerThumb.cpp.o: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerThumb.cpp.o +.PHONY : HookerThumb.cpp.o + +HookerThumb.i: HookerThumb.cpp.i +.PHONY : HookerThumb.i + +# target to preprocess a source file +HookerThumb.cpp.i: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerThumb.cpp.i +.PHONY : HookerThumb.cpp.i + +HookerThumb.s: HookerThumb.cpp.s +.PHONY : HookerThumb.s + +# target to generate assembly for a file +HookerThumb.cpp.s: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerThumb.cpp.s +.PHONY : HookerThumb.cpp.s + +HookerX64.o: HookerX64.cpp.o +.PHONY : HookerX64.o + +# target to build an object file +HookerX64.cpp.o: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerX64.cpp.o +.PHONY : HookerX64.cpp.o + +HookerX64.i: HookerX64.cpp.i +.PHONY : HookerX64.i + +# target to preprocess a source file +HookerX64.cpp.i: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerX64.cpp.i +.PHONY : HookerX64.cpp.i + +HookerX64.s: HookerX64.cpp.s +.PHONY : HookerX64.s + +# target to generate assembly for a file +HookerX64.cpp.s: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerX64.cpp.s +.PHONY : HookerX64.cpp.s + +HookerX86.o: HookerX86.cpp.o +.PHONY : HookerX86.o + +# target to build an object file +HookerX86.cpp.o: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerX86.cpp.o +.PHONY : HookerX86.cpp.o + +HookerX86.i: HookerX86.cpp.i +.PHONY : HookerX86.i + +# target to preprocess a source file +HookerX86.cpp.i: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerX86.cpp.i +.PHONY : HookerX86.cpp.i + +HookerX86.s: HookerX86.cpp.s +.PHONY : HookerX86.s + +# target to generate assembly for a file +HookerX86.cpp.s: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/HookerX86.cpp.s +.PHONY : HookerX86.cpp.s + +main.o: main.cpp.o +.PHONY : main.o + +# target to build an object file +main.cpp.o: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/main.cpp.o +.PHONY : main.cpp.o + +main.i: main.cpp.i +.PHONY : main.i + +# target to preprocess a source file +main.cpp.i: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/main.cpp.i +.PHONY : main.cpp.i + +main.s: main.cpp.s +.PHONY : main.s + +# target to generate assembly for a file +main.cpp.s: + $(MAKE) -f CMakeFiles/hooker-test.dir/build.make CMakeFiles/hooker-test.dir/main.cpp.s +.PHONY : main.cpp.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... edit_cache" + @echo "... hooker-test" + @echo "... rebuild_cache" + @echo "... Hooker.o" + @echo "... Hooker.i" + @echo "... Hooker.s" + @echo "... HookerArm.o" + @echo "... HookerArm.i" + @echo "... HookerArm.s" + @echo "... HookerFactory.o" + @echo "... HookerFactory.i" + @echo "... HookerFactory.s" + @echo "... HookerThumb.o" + @echo "... HookerThumb.i" + @echo "... HookerThumb.s" + @echo "... HookerX64.o" + @echo "... HookerX64.i" + @echo "... HookerX64.s" + @echo "... HookerX86.o" + @echo "... HookerX86.i" + @echo "... HookerX86.s" + @echo "... main.o" + @echo "... main.i" + @echo "... main.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system diff --git a/config.h b/config.h new file mode 100644 index 0000000..722b5c6 --- /dev/null +++ b/config.h @@ -0,0 +1,16 @@ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +#ifdef __x86_64__ +#include "Hooker64.h" +#elif defined(__i386__) +#include "HookerX86.h" +#elif defined(__arm__) +#include "HookerArm.h" +#elif defined(__thumb__) +#include "HookerThumb.h" +#else +#error "error architecture" +#endif + +#endif diff --git a/installer.sh b/installer.sh deleted file mode 100755 index 52a5e9a..0000000 --- a/installer.sh +++ /dev/null @@ -1,2 +0,0 @@ -export LD_LIBRATH_PATH=. -make