这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
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 configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ AM_INIT_AUTOMAKE([foreign])
AC_PROG_MAKE_SET
AC_PROG_CC
AC_LANG(C)
LT_INIT

copyright="Copyright (C) 2022-2024 Termux."
if test "${TERMUX_APP_PACKAGE+set}" = set; then
Expand Down
1 change: 1 addition & 0 deletions scripts/dalvikvm.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ else
fi

unset LD_LIBRARY_PATH LD_PRELOAD
export LD_PRELOAD=@TERMUX_PREFIX@/lib/termux/libtermux-access.so
exec "$DALVIKVM" -Xusejit:true -Xnoimage-dex2oat -Djava.io.tmpdir=@TERMUX_PREFIX@/tmp "$@"
10 changes: 10 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ AM_CFLAGS = -Wall -Wextra -pedantic
bin_PROGRAMS = cmd

cmd_SOURCES = cmd.c

libdir = $(prefix)/lib/termux

lib_LTLIBRARIES = libtermux-access.la

libtermux_access_la_SOURCES = termux_access.c
libtermux_access_la_LDFLAGS = -shared -module -avoid-version -ldl

clean-local:
rm -f libtermux-access.la
37 changes: 37 additions & 0 deletions src/termux_access.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#define _GNU_SOURCE
#include <dlfcn.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>

// This library is needed to bypass W^X restriction in Dalvik code.
// https://cs.android.com/android/platform/superproject/+/dd6fde63193fda968440fc0a4cd9ccee5d282ab0:art/runtime/native/dalvik_system_DexFile.cc;l=381

static int stub_access(const char* __unused path, int __unused mode) {
return -1;
}

// Function pointer for the original access function
static int (*orig_access)(const char *path, int mode) = stub_access;

// Constructor to load the original access function
__attribute__((constructor, visibility("hidden")))
static void load_orig_access(void) {
orig_access = (int (*)(const char *, int))dlsym(RTLD_NEXT, "access");
if (orig_access == NULL) {
dprintf(2, "Error in `dlsym`: %s\n", dlerror());
orig_access = stub_access;
}
}

int access(const char *path, int mode) {
// Checking if path ends with ".apk", if ".apk" is an extension and if mode is W_OK
const char *apk = path == NULL ? NULL : strstr(path, ".apk");
if (mode == W_OK && apk != NULL && !strcmp(apk, ".apk"))
return 1;

// Call the original access function for other cases
return orig_access(path, mode);
}