new libsystem
This commit is contained in:
+4
-4
@@ -61,7 +61,7 @@ include $(BUILD_EXECUTABLE)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= libexec
|
||||
LOCAL_MODULE:= exec
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
termExec.cpp
|
||||
@@ -72,12 +72,12 @@ include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE:= node
|
||||
LOCAL_MODULE:= system
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
node.c
|
||||
system.cpp
|
||||
|
||||
LOCAL_LDLIBS := -ldl
|
||||
LOCAL_LDLIBS := -ldl -llog
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
#include <jni.h>
|
||||
|
||||
void Java_com_github_shadowsocks_Node_exec(JNIEnv *env, jobject thiz, jstring cmd) {
|
||||
const char *str = (*env)->GetStringUTFChars(env, cmd, 0);
|
||||
setenv("LD_LIBRARY_PATH", "/vendor/lib:/system/lib", 1);
|
||||
setegid(getgid());
|
||||
seteuid(getuid());
|
||||
system(str);
|
||||
(*env)->ReleaseStringUTFChars(env, cmd, str);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#define LOG_TAG "Shadowsocks"
|
||||
|
||||
#include "jni.h"
|
||||
#include <android/log.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define LOGI(...) do { __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__); } while(0)
|
||||
#define LOGW(...) do { __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__); } while(0)
|
||||
#define LOGE(...) do { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__); } while(0)
|
||||
|
||||
void Java_com_github_shadowsocks_Node_exec(JNIEnv *env, jobject thiz, jstring cmd) {
|
||||
const char *str = env->GetStringUTFChars(cmd, 0);
|
||||
setenv("LD_LIBRARY_PATH", "/vendor/lib:/system/lib", 1);
|
||||
setegid(getgid());
|
||||
seteuid(getuid());
|
||||
system(str);
|
||||
env->ReleaseStringUTFChars(cmd, str);
|
||||
}
|
||||
|
||||
static const char *classPathName = "com/github/shadowsocks/System";
|
||||
|
||||
static JNINativeMethod method_table[] = {
|
||||
{ "exec", "(Ljava/lang/String;)V",
|
||||
(void*) Java_com_github_shadowsocks_Node_exec }
|
||||
};
|
||||
|
||||
/*
|
||||
* Register several native methods for one class.
|
||||
*/
|
||||
static int registerNativeMethods(JNIEnv* env, const char* className,
|
||||
JNINativeMethod* gMethods, int numMethods)
|
||||
{
|
||||
jclass clazz;
|
||||
|
||||
clazz = env->FindClass(className);
|
||||
if (clazz == NULL) {
|
||||
LOGE("Native registration unable to find class '%s'", className);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
|
||||
LOGE("RegisterNatives failed for '%s'", className);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register native methods for all classes we know about.
|
||||
*
|
||||
* returns JNI_TRUE on success.
|
||||
*/
|
||||
static int registerNatives(JNIEnv* env)
|
||||
{
|
||||
if (!registerNativeMethods(env, classPathName, method_table,
|
||||
sizeof(method_table) / sizeof(method_table[0]))) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called by the VM when the shared library is first loaded.
|
||||
*/
|
||||
|
||||
typedef union {
|
||||
JNIEnv* env;
|
||||
void* venv;
|
||||
} UnionJNIEnvToVoid;
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
UnionJNIEnvToVoid uenv;
|
||||
uenv.venv = NULL;
|
||||
jint result = -1;
|
||||
JNIEnv* env = NULL;
|
||||
|
||||
LOGI("JNI_OnLoad");
|
||||
|
||||
if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) {
|
||||
LOGE("ERROR: GetEnv failed");
|
||||
goto bail;
|
||||
}
|
||||
env = uenv.env;
|
||||
|
||||
if (registerNatives(env) != JNI_TRUE) {
|
||||
LOGE("ERROR: registerNatives failed");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
result = JNI_VERSION_1_4;
|
||||
|
||||
bail:
|
||||
return result;
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "Exec"
|
||||
#define LOG_TAG "Shadowsocks"
|
||||
|
||||
#include "jni.h"
|
||||
#include <android/log.h>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -28,7 +28,7 @@ import java.io.FileDescriptor;
|
||||
|
||||
public class Exec {
|
||||
static {
|
||||
System.loadLibrary("exec");
|
||||
java.lang.System.loadLibrary("exec");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -210,7 +210,7 @@ public class ShadowsocksService extends Service {
|
||||
final String cmd = String.format(BASE +
|
||||
"shadowsocks -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\"",
|
||||
appHost, remotePort, localPort, sitekey, encMethod);
|
||||
Node.exec(cmd);
|
||||
System.exec(cmd);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public class ShadowsocksService extends Service {
|
||||
final String cmd = String.format(BASE +
|
||||
"polipo proxyPort=%d socksParentProxy=127.0.0.1:%d daemonise=true pidFile=\"%s\" logLevel=1 logFile=\"%s\"",
|
||||
localPort + 1, localPort, BASE + "polipo.pid", BASE + "polipo.log");
|
||||
Node.exec(cmd);
|
||||
System.exec(cmd);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
|
||||
package com.github.shadowsocks;
|
||||
|
||||
public class Node {
|
||||
public class System {
|
||||
static {
|
||||
System.loadLibrary("node");
|
||||
java.lang.System.loadLibrary("system");
|
||||
}
|
||||
|
||||
public static native void exec(String cmd);
|
||||
Reference in New Issue
Block a user