MJx0 / KittyMemory

This library aims for runtime code patching for both Android and iOS
MIT License
334 stars 113 forks source link

Android build error #27

Closed AntogamerYT closed 3 months ago

AntogamerYT commented 8 months ago
ld: error: undefined symbol: KittyScanner::findDataFirst(unsigned long, unsigned long, void const*, unsigned long)
>>> referenced by DroidRedirect.cpp:51 (src\DroidRedirect.cpp:51)
>>>               ./obj/local/arm64-v8a/objs/droidredirect/DroidRedirect.o:(FindBuildingFunction(char const*, int))

ld: error: undefined symbol: KittyScanner::findIdaPatternFirst(unsigned long, unsigned long, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)
>>> referenced by DroidRedirect.cpp:58 (src\DroidRedirect.cpp:58)
>>>               ./obj/local/arm64-v8a/objs/droidredirect/DroidRedirect.o:(FindBuildingFunction(char const*, int))

ld: error: undefined symbol: KittyMemory::getElfBaseMap(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)
>>> referenced by KittyScanner.hpp:175 (src/../KittyMemory\KittyScanner.hpp:175)
>>>               ./obj/local/arm64-v8a/objs/droidredirect/DroidRedirect.o:(KittyScanner::ElfScanner::createWithPath(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&))

ld: error: undefined symbol: KittyMemory::getAllMaps()
>>> referenced by KittyScanner.hpp:163 (src/../KittyMemory\KittyScanner.hpp:163)
>>>               ./obj/local/arm64-v8a/objs/droidredirect/DroidRedirect.o:(KittyScanner::ElfScanner::createWithPath(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&))

ld: error: undefined symbol: KittyScanner::ElfScanner::ElfScanner(unsigned long, std::__ndk1::vector<KittyMemory::ProcMap, std::__ndk1::allocator<KittyMemory::ProcMap> > const&)
>>> referenced by KittyScanner.hpp:163 (src/../KittyMemory\KittyScanner.hpp:163)
>>>               ./obj/local/arm64-v8a/objs/droidredirect/DroidRedirect.o:(KittyScanner::ElfScanner::createWithPath(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

i just added the library to Android.mk and included it like in the example project but i get these errors on compilation, this is my android.mk:

LOCAL_PATH := $(call my-dir)

KITTYMEMORY_PATH = ../KittyMemory
KITTYMEMORY_SRC = $(wildcard $(KITTYMEMORY_PATH)/*.cpp)

include $(CLEAR_VARS)
LOCAL_MODULE    := Keystone
LOCAL_SRC_FILES := $(KITTYMEMORY_PATH)/Deps/Keystone/libs-android/$(TARGET_ARCH_ABI)/libkeystone.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := libcpp
LOCAL_SRC_FILES := libc++_shared.so

include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := droidredirect

LOCAL_SRC_FILES := DroidRedirect.cpp And64InlineHook.cpp $(KITTYMEMORY_SRC)

LOCAL_STATIC_LIBRARIES := Keystone

LOCAL_CFLAGS    := -fvisibility=hidden -fno-stack-protector -Wall -Wno-address-of-temporary 
LOCAL_CPPFLAGS := -std=c++20 -fexceptions
LOCAL_SHARED_LIBRARIES := libcpp

LOCAL_LDLIBS    += -llog 

include $(BUILD_SHARED_LIBRARY)
MJx0 commented 7 months ago

seems like LOCAL_SRC_FILES did not pick the source files properly. check the path

AntogamerYT commented 7 months ago

seems like LOCAL_SRC_FILES did not pick the source files properly. check the path

i modified KITTYMEMORY_PATH = ../KittyMemory to KITTYMEMORY_PATH = ./src/KittyMemory and it worked, i can confirm this by logging KITTYMEMORY_SRC: KITTYMEMORY_SRC: ./src/KittyMemory/KittyArm64.cpp ./src/KittyMemory/KittyMemory.cpp ./src/KittyMemory/KittyScanner.cpp ./src/KittyMemory/KittyUtils.cpp ./src/KittyMemory/MemoryBackup.cpp ./src/KittyMemory/MemoryPatch.cpp

That seemed to work, until: make: *** No rule to make target 'src/./src/KittyMemory/KittyArm64.cpp', needed by 'obj/local/arm64-v8a/objs/droidredirect/./src/KittyMemory/KittyArm64.o'. Stop.

This is how my project is structured (ignore the errors [it's just vscode intellisense doing the funny] and the mess lol): image

MJx0 commented 6 months ago

its better to use $(LOCAL_PATH), try to log that to see the folder you are currently compiling from. your android mk file is at same folder with kittymemory so it should be

KITTYMEMORY_PATH = $(LOCAL_PATH)/KittyMemory

now since LOCAL_SRC_FILES is relative to $(LOCAL_PATH) you can use subst to get relative path like this

KITTYMEMORY_SRC =  $(subst $(LOCAL_PATH)/,,$(wildcard $(KITTYMEMORY_PATH)/*.cpp))