Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/cpp/Core/Canvas/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ namespace Canvas {
PRIVATE_API const char *configsPath;

PRIVATE_API std::vector<void (*)(std::string)> onKeyboardCompleteListeners;
PRIVATE_API std::mutex onKeyboardCompleteListenersMutex;
}
2 changes: 2 additions & 0 deletions app/src/main/cpp/Core/Canvas/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <vector>
#include <string>
#include <mutex>
#include <jni.h>
#include <android/asset_manager_jni.h>

Expand Down Expand Up @@ -63,4 +64,5 @@ namespace Canvas {
extern const char *configsPath;

extern std::vector<void (*)(std::string)> onKeyboardCompleteListeners;
extern std::mutex onKeyboardCompleteListenersMutex;
}
13 changes: 7 additions & 6 deletions app/src/main/cpp/Core/Cipher/CipherPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ CipherPatch::~CipherPatch() {

std::lock_guard<std::mutex> lock(cipher_patch_mtx);

CipherBase::s_InstanceVec.erase(
std::find(
CipherBase::s_InstanceVec.begin(),
CipherBase::s_InstanceVec.end(),
(CipherBase *)this
)
auto it = std::find(
CipherBase::s_InstanceVec.begin(),
CipherBase::s_InstanceVec.end(),
(CipherBase *)this
);
if (it != CipherBase::s_InstanceVec.end()) {
CipherBase::s_InstanceVec.erase(it);
}
CipherInternal::ForgetInstall(this);
artpatch_die(this->patch);
}
8 changes: 4 additions & 4 deletions app/src/main/cpp/Core/Cipher/CipherUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void CipherUtils::patternToBytes(const std::string _pattern, char* _bytesBuffer,
}
}

if (!(bytes.empty() || mask.empty() || bytes.size() != mask.size())) {
if (!(bytes.empty() || mask.empty() || bytes.size() != mask.size() || bytes.size() >= 256)) {
std::memcpy(_bytesBuffer, bytes.data(), bytes.size());
_bytesBuffer[bytes.size()] = '\0';
_maskBuffer = mask;
Expand Down Expand Up @@ -272,13 +272,13 @@ char* CipherUtils::readAsset(const char* _assetPath) {
}

void CipherUtils::addOnKeyboardCompleteListener(void (*_listener)(std::string)) {
std::lock_guard<std::mutex> lock(Canvas::onKeyboardCompleteListenersMutex);
Canvas::onKeyboardCompleteListeners.push_back(_listener);
}

DeviceInfo CipherUtils::get_DeviceInfo() {
DeviceInfo deviceInfo;
std::memcpy(&deviceInfo, &Canvas::deviceInfo, sizeof(deviceInfo));
return deviceInfo;
return {Canvas::deviceInfo.xdpi, Canvas::deviceInfo.ydpi, Canvas::deviceInfo.density,
Canvas::deviceInfo.deviceName, Canvas::deviceInfo.deviceManufacturer, Canvas::deviceInfo.deviceModel};
}

void CipherUtils::performHapticFeedback(HapticFeedbackType _type) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/Core/Iconloader/IconLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ PRIVATE_API SkyImage& IconLoader::uploadImageKtx(const char* name, const bool& i
else IconLoader::images.insert(std::make_pair(name, image));
return *image;
case KTX_UNSUPPORTED_TEXTURE_TYPE:
default:
__android_log_print(ANDROID_LOG_ERROR,"IconLoader", "Unsupported texture type");
free(assetBuf);
glDeleteTextures(1, &texid);
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/cpp/Core/fileselector/fileselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,28 @@ static jobjectArray fsel_build_mime_array(JNIEnv* env,
return arr;
}

namespace {
struct ThreadAttachment {
bool attached = false;
~ThreadAttachment() {
if (attached) Canvas::javaVM->DetachCurrentThread();
}
};
}

bool requestFileMultiNamed(const char* const* mime_types, size_t mime_type_count,
callback_function callback, bool save,
const char* suggested_name) {
if (!mime_types || mime_type_count == 0) return false;

JNIEnv* env;
ThreadAttachment attachment;
if (Canvas::javaVM->GetEnv((void**)&env, JNI_VERSION_1_6) == JNI_EDETACHED) {
if (Canvas::javaVM->AttachCurrentThread(&env, nullptr) != JNI_OK) {
__android_log_print(ANDROID_LOG_ERROR, "fileselector", "Failed to attach thread to JVM");
return false;
}
attachment.attached = true;
}
if (!class_FileSelector || !method_nselectFileMultiNamed) {
__android_log_print(ANDROID_LOG_ERROR, "fileselector", "FileSelector not initialized");
Expand All @@ -113,9 +124,6 @@ bool requestFileMultiNamed(const char* const* mime_types, size_t mime_type_count
jobjectArray mimeArr = fsel_build_mime_array(env, mime_types, mime_type_count);
if (!mimeArr) return false;

// Null stays null all the way into the Java side, where it means "leave the
// name field as it was" - the pre-EXTRA_TITLE behaviour, and what
// requestFileMulti below still asks for.
jstring nameStr = nullptr;
if (suggested_name && suggested_name[0] != '\0') {
nameStr = env->NewStringUTF(suggested_name);
Expand Down Expand Up @@ -150,11 +158,13 @@ bool requestFiles(const char* const* mime_types, size_t mime_type_count,
if (!mime_types || mime_type_count == 0) return false;

JNIEnv* env;
ThreadAttachment attachment;
if (Canvas::javaVM->GetEnv((void**)&env, JNI_VERSION_1_6) == JNI_EDETACHED) {
if (Canvas::javaVM->AttachCurrentThread(&env, nullptr) != JNI_OK) {
__android_log_print(ANDROID_LOG_ERROR, "fileselector", "Failed to attach thread to JVM");
return false;
}
attachment.attached = true;
}
if (!class_FileSelector || !method_nselectFiles) {
__android_log_print(ANDROID_LOG_ERROR, "fileselector", "FileSelector not initialized");
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/cpp/Utils/artpatch/artpatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ __attribute__((visibility ("hidden"))) unsigned char artpatch_decode_hex_digit(c
case 'D': return 13;
case 'E': return 14;
case 'F': return 15;
case 'a': return 10;
case 'b': return 11;
case 'c': return 12;
case 'd': return 13;
case 'e': return 14;
case 'f': return 15;
default: return 255;
}
}
Expand Down Expand Up @@ -88,21 +94,23 @@ __attribute__((visibility ("hidden"))) void artpatch_set_hex(patch_t patch, cons

__attribute__((visibility ("hidden"))) void artpatch_apply(patch_t patch) {
const void* pagestart = (void*)((uintptr_t)patch->patchDestination & -PAGE_SIZE);
size_t span = ((uintptr_t)patch->patchDestination + patch->patchLength - (uintptr_t)pagestart + PAGE_SIZE - 1) & -PAGE_SIZE;
int prot_flags = procutils_read_mprotection(pagestart);
if(!mprotect(pagestart, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC)) {
if(!mprotect(pagestart, span, PROT_READ | PROT_WRITE | PROT_EXEC)) {
if(!patch->patchApplied) memcpy(patch->backup, patch->patchDestination, patch->patchLength);
memcpy(patch->patchDestination, patch->patch, patch->patchLength);
mprotect(pagestart, PAGE_SIZE, prot_flags);
mprotect(pagestart, span, prot_flags);
patch->patchApplied = true;
}
}
__attribute__((visibility ("hidden"))) void artpatch_restore(patch_t patch) {
if(!patch->patchApplied) return;
const void* pagestart = (void*)((uintptr_t)patch->patchDestination & -PAGE_SIZE);
size_t span = ((uintptr_t)patch->patchDestination + patch->patchLength - (uintptr_t)pagestart + PAGE_SIZE - 1) & -PAGE_SIZE;
int prot_flags = procutils_read_mprotection(pagestart);
if(!mprotect(pagestart, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC)) {
if(!mprotect(pagestart, span, PROT_READ | PROT_WRITE | PROT_EXEC)) {
memcpy(patch->patchDestination, patch->backup, patch->patchLength);
mprotect(pagestart, PAGE_SIZE, prot_flags);
mprotect(pagestart, span, prot_flags);
patch->patchApplied = false;
}else{
__android_log_print(ANDROID_LOG_FATAL,"artPatch","Unable to change memory protection to restore backup!");
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/Utils/artpatch/procutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ __attribute__((visibility ("hidden"))) int procutils_read_mprotection(void* addr
unsigned long addr0 = strtoul(b->mem, &end0, 0x10);
char*end1 = (void*)0;
unsigned long addr1 = strtoul(end0+1, &end1, 0x10);
if ((void*)addr0 <= addr && addr <= (void*)addr1) {
if ((void*)addr0 <= addr && addr < (void*)addr1) {
res |= (end1+1)[0] == 'r' ? PROT_READ : 0;
res |= (end1+1)[1] == 'w' ? PROT_WRITE : 0;
res |= (end1+1)[2] == 'x' ? PROT_EXEC : 0;
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/cpp/Utils/imgui_androidbk/androidbk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static EGLSurface g_EglSurface = EGL_NO_SURFACE;
static EGLContext g_EglContext = EGL_NO_CONTEXT;
static EGLConfig egl_config;
static EGLint egl_format;
static bool run = true;
static std::atomic<bool> run{true};
static ANativeWindow *androidWindow;
static double g_time = 0;

Expand Down Expand Up @@ -524,15 +524,17 @@ PRIVATE_API void renderloop()
g_EglSurface = nullptr;
}

PRIVATE_API void init_sfc(JNIEnv *env, jobject surface) {
PRIVATE_API bool init_sfc(JNIEnv *env, jobject surface) {
if(androidWindow != nullptr) {
ANativeWindow_release(androidWindow);
}
androidWindow = ANativeWindow_fromSurface(env, surface);
if (androidWindow == nullptr) return false;
ANativeWindow_acquire(androidWindow);
ANativeWindow_setBuffersGeometry(androidWindow, 0, 0, egl_format);
g_EglSurface = eglCreateWindowSurface(g_EglDisplay, egl_config, androidWindow, nullptr);
eglMakeCurrent(g_EglDisplay, g_EglSurface, g_EglSurface, g_EglContext);
return true;
}

static jclass class_ImGUI;
Expand Down Expand Up @@ -729,8 +731,8 @@ Java_git_artdeell_skymodloader_ImGUI_wantsMouse(JNIEnv *env, jclass clazz) {
extern "C"
JNIEXPORT void JNICALL
Java_git_artdeell_skymodloader_ImGUI_resurface(JNIEnv *env, jclass clazz, jobject surface) {
init_sfc(env, surface);
eglMakeCurrent(g_EglDisplay, g_EglSurface, g_EglSurface, g_EglContext);
run = true;
if (!init_sfc(env, surface)) return;
eglMakeCurrent(g_EglDisplay, g_EglSurface, g_EglSurface, g_EglContext);
renderloop();
}
7 changes: 6 additions & 1 deletion app/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,12 @@ Java_git_artdeell_skymodloader_MainActivity_onKeyboardCompleteNative(
jstring message
) {
std::string msg = env->GetStringUTFChars(message, nullptr);
for (auto& listener : Canvas::onKeyboardCompleteListeners) {
std::vector<void (*)(std::string)> listeners;
{
std::lock_guard<std::mutex> lock(Canvas::onKeyboardCompleteListenersMutex);
listeners = Canvas::onKeyboardCompleteListeners;
}
for (auto& listener : listeners) {
listener(msg);
}
}
Expand Down
Loading