Skip to content

Commit

Permalink
Proxy Usable
Browse files Browse the repository at this point in the history
  • Loading branch information
GreaterFire committed Nov 23, 2018
1 parent a5a78c7 commit 0f7105a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
18 changes: 15 additions & 3 deletions app/src/main/cpp/jni-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@
using namespace std;
using namespace Net2Tr;

void startTrojan(const string &filename)
static void startTrojan(const string &config)
{
Config c;
c.load(filename);
c.load(config);
Service(c).run();
}

void startN2S(int tun_fd, const string &ip_addr, const string &netmask, const string &ip6_addr, uint16_t mtu, const string &socks5_addr, uint16_t socks5_port)
static void startN2S(int tun_fd, const string &ip_addr, const string &netmask, const string &ip6_addr, uint16_t mtu, const string &socks5_addr, uint16_t socks5_port)
{
N2T n2t(ip_addr, netmask, ip6_addr, mtu);
N2S(tun_fd, n2t, socks5_addr, socks5_port).start();
}

extern "C" {
JNIEXPORT void JNICALL Java_io_github_trojan_1gfw_igniter_JNIHelper_trojan(JNIEnv *env, jclass, jstring config) {
const char *s = env->GetStringUTFChars(config, 0);
startTrojan(s);
}

JNIEXPORT void JNICALL Java_io_github_trojan_1gfw_igniter_JNIHelper_n2s(JNIEnv *env, jclass, jint tun_fd, jstring ip_addr, jstring netmask, jstring ip6_addr, jint mtu, jstring socks5_addr, jint socks5_port) {
const char *s1 = env->GetStringUTFChars(ip_addr, 0);
const char *s2 = env->GetStringUTFChars(netmask, 0);
const char *s3 = env->GetStringUTFChars(ip6_addr, 0);
const char *s4 = env->GetStringUTFChars(socks5_addr, 0);
startN2S(tun_fd, s1, s2, s3, uint16_t(mtu), s4, uint16_t(socks5_port));
}
}

jint JNI_OnLoad(JavaVM* vm, void* reserved)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/io/github/trojan_gfw/igniter/JNIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public class JNIHelper {
static {
System.loadLibrary("jni-helper");
}
public static native void trojan(String config);
public static native void n2s(int tun_fd, String ip_addr, String netmask, String ip6_addr, int mtu, String socks5_addr, int socks5_port);
}
21 changes: 14 additions & 7 deletions app/src/main/java/io/github/trojan_gfw/igniter/TrojanService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import android.content.Intent;
import android.net.VpnService;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

public class TrojanService extends VpnService {
@Override
Expand All @@ -27,8 +22,20 @@ public int onStartCommand(Intent intent, int flags, int startId) {
b.addDnsServer("1.1.1.1");
b.addDnsServer("8.8.8.8");
ParcelFileDescriptor pfd = b.establish();
int fd = pfd.detachFd();
String trojanConfigPath = getCacheDir() + "/config.json";
final int fd = pfd.detachFd();
final String trojanConfigPath = getCacheDir() + "/config.json";
new Thread(new Runnable() {
@Override
public void run() {
JNIHelper.trojan(trojanConfigPath);
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
JNIHelper.n2s(fd, "10.114.51.5", "255.255.255.254", "", 1500, "127.0.0.1", 1080);
}
}).start();
return START_STICKY;
}
}

0 comments on commit 0f7105a

Please sign in to comment.