Skip to content

Commit 4669bd9

Browse files
v1.0.0-rc1:
- Change min SDK to 21 - Refactor code - Fix crushes - Add proxy mode - Add listening ip setting - Update main screen - Update settings screen - Move logs saving to main screen
1 parent 54cc788 commit 4669bd9

35 files changed

+1660
-765
lines changed

.idea/render.experimental.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@ android {
1111

1212
defaultConfig {
1313
applicationId = "io.github.dovecoteescapee.byedpi"
14-
minSdk = 24
14+
minSdk = 21
1515
targetSdk = 34
16-
versionCode = 2
17-
versionName = "0.1.1-alpha"
16+
versionCode = 3
17+
versionName = "1.0.0-rc1"
1818

1919
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2020
}
2121

22+
buildFeatures {
23+
buildConfig = true
24+
}
25+
2226
buildTypes {
2327
release {
28+
buildConfigField("String", "VERSION_NAME", "\"${defaultConfig.versionName}\"")
29+
2430
isMinifyEnabled = false
2531
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
2632
}
33+
debug {
34+
buildConfigField("String", "VERSION_NAME", "\"${defaultConfig.versionName}-debug\"")
35+
}
2736
}
2837
compileOptions {
2938
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -72,7 +81,7 @@ abstract class BuildTun2Socks : DefaultTask() {
7281
}
7382
project.exec {
7483
workingDir = tun2socksDir
75-
commandLine("gomobile", "bind", "-o", tun2socksOutput, "./engine")
84+
commandLine("gomobile", "bind", "-o", tun2socksOutput, "-trimpath", "./engine")
7685
}
7786
}
7887
}

app/src/main/AndroidManifest.xml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
xmlns:tools="http://schemas.android.com/tools">
44

55
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
67
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
78
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
8-
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
99

1010
<application
1111
android:allowBackup="true"
@@ -16,10 +16,11 @@
1616
android:roundIcon="@mipmap/ic_launcher_round"
1717
android:supportsRtl="true"
1818
android:theme="@style/Theme.ByeDPI"
19-
tools:targetApi="31">
19+
tools:targetApi="34">
2020
<activity
21-
android:name=".MainActivity"
22-
android:exported="true">
21+
android:name=".activities.MainActivity"
22+
android:exported="true"
23+
android:launchMode="singleInstance">
2324
<intent-filter>
2425
<action android:name="android.intent.action.MAIN" />
2526

@@ -28,16 +29,31 @@
2829
</activity>
2930

3031
<activity
31-
android:name=".SettingsActivity"
32+
android:name=".activities.SettingsActivity"
3233
android:label="@string/title_settings"
33-
android:exported="false"/>
34+
android:exported="true"/>
3435

35-
<service android:name=".ByeDpiVpnService"
36+
<service android:name=".services.ByeDpiVpnService"
3637
android:permission="android.permission.BIND_VPN_SERVICE"
37-
android:exported="true">
38+
android:foregroundServiceType="specialUse"
39+
android:exported="false">
3840
<intent-filter>
3941
<action android:name="android.net.VpnService"/>
4042
</intent-filter>
43+
<meta-data
44+
android:name="android.net.VpnService.SUPPORTS_ALWAYS_ON"
45+
android:value="false" />
46+
<property
47+
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
48+
android:value="vpn" />
49+
</service>
50+
51+
<service android:name=".services.ByeDpiProxyService"
52+
android:foregroundServiceType="specialUse"
53+
android:exported="false">
54+
<property
55+
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
56+
android:value="proxy" />
4157
</service>
4258
</application>
4359

app/src/main/cpp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
3030
byedpi/desync.c
3131
byedpi/packets.c
3232
byedpi/proxy.c
33+
byedpi/main.c
3334
native-lib.c
3435
)
3536

3637
include_directories("byedpi")
3738

3839
set(CMAKE_C_FLAGS "-std=c99 -O2 -D_XOPEN_SOURCE=500")
3940

41+
add_compile_definitions(ANDROID_APP)
42+
4043
# Specifies libraries CMake should link to your target library. You
4144
# can link libraries from various origins, such as libraries defined in this
4245
# build script, prebuilt third-party libraries, or Android system libraries.

app/src/main/cpp/native-lib.c

Lines changed: 52 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,40 @@
22
#include <proxy.h>
33
#include <params.h>
44
#include <packets.h>
5-
#include <jni.h>
6-
#include <android/log.h>
75
#include <unistd.h>
8-
#include <pthread.h>
96
#include <string.h>
7+
#include <netdb.h>
8+
#include <sys/eventfd.h>
109

11-
extern int NOT_EXIT;
12-
13-
struct packet fake_tls = {
14-
sizeof(tls_data), tls_data
15-
},
16-
fake_http = {
17-
sizeof(http_data), http_data
18-
};
19-
20-
struct params params = {
21-
.ttl = 8,
22-
.split = 3,
23-
.sfdelay = 3000,
24-
.attack = DESYNC_NONE,
25-
.split_host = 0,
26-
.def_ttl = 0,
27-
.custom_ttl = 0,
28-
.mod_http = 0,
29-
.tlsrec = 0,
30-
.tlsrec_pos = 0,
31-
.tlsrec_sni = 0,
32-
.de_known = 0,
10+
#include <jni.h>
11+
#include <android/log.h>
3312

34-
.ipv6 = 1,
35-
.resolve = 1,
36-
.max_open = 512,
37-
.bfsize = 16384,
38-
.baddr = {
39-
.sin6_family = AF_INET
40-
},
41-
.debug = 2
13+
const enum demode DESYNC_METHODS[] = {
14+
DESYNC_NONE,
15+
DESYNC_SPLIT,
16+
DESYNC_DISORDER,
17+
DESYNC_FAKE
4218
};
4319

44-
int get_default_ttl()
45-
{
46-
int orig_ttl = -1, fd;
47-
socklen_t tsize = sizeof(orig_ttl);
20+
extern struct packet fake_tls, fake_http;
21+
extern int get_default_ttl();
22+
extern int get_addr(const char *str, struct sockaddr_ina *addr);
4823

49-
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
50-
uniperror("socket");
24+
JNIEXPORT jint JNICALL
25+
Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniEventFd(JNIEnv *env, jobject thiz) {
26+
int fd = eventfd(0, EFD_NONBLOCK);
27+
if (fd < 0) {
5128
return -1;
5229
}
53-
if (getsockopt(fd, IPPROTO_IP, IP_TTL,
54-
(char *)&orig_ttl, &tsize) < 0) {
55-
uniperror("getsockopt IP_TTL");
56-
}
57-
close(fd);
58-
return orig_ttl;
59-
}
60-
61-
void *run(void *srv) {
62-
LOG(LOG_S, "Start proxy thread");
63-
listener(*((struct sockaddr_ina *) srv));
64-
free(srv);
65-
LOG(LOG_S, "Stop proxy thread");
66-
return NULL;
30+
return fd;
6731
}
6832

69-
JNIEXPORT jlong JNICALL
70-
Java_io_github_dovecoteescapee_byedpi_ByeDpiVpnService_jniStartProxy(
33+
JNIEXPORT jint JNICALL
34+
Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniStartProxy(
7135
JNIEnv *env,
7236
jobject thiz,
37+
jint event_fd,
38+
jstring ip,
7339
jint port,
7440
jint max_connections,
7541
jint buffer_size,
@@ -82,24 +48,35 @@ Java_io_github_dovecoteescapee_byedpi_ByeDpiVpnService_jniStartProxy(
8248
jint fake_ttl,
8349
jboolean host_mixed_case,
8450
jboolean domain_mixed_case,
85-
jboolean host_remove_space,
51+
jboolean host_remove_spaces,
8652
jboolean tls_record_split,
8753
jint tls_record_split_position,
8854
jboolean tls_record_split_at_sni) {
89-
enum demode desync_methods[] = {DESYNC_NONE, DESYNC_SPLIT, DESYNC_DISORDER, DESYNC_FAKE};
55+
56+
struct sockaddr_ina s = {
57+
.in.sin_family = AF_INET,
58+
.in.sin_addr.s_addr = inet_addr("0.0.0.0"),
59+
};
60+
61+
const char *address = (*env)->GetStringUTFChars(env, ip, 0);
62+
if (get_addr(address, &s) < 0) {
63+
return -1;
64+
}
65+
s.in.sin_port = htons(port);
9066

9167
params.max_open = max_connections;
9268
params.bfsize = buffer_size;
9369
params.def_ttl = default_ttl;
9470
params.resolve = !no_domain;
9571
params.de_known = desync_known;
96-
params.attack = desync_methods[desync_method];
72+
params.attack = DESYNC_METHODS[desync_method];
9773
params.split = split_position;
9874
params.split_host = split_at_host;
9975
params.ttl = fake_ttl;
100-
params.mod_http |= host_mixed_case ? MH_HMIX : 0;
101-
params.mod_http |= domain_mixed_case ? MH_DMIX : 0;
102-
params.mod_http |= host_remove_space ? MH_SPACE : 0;
76+
params.mod_http =
77+
MH_HMIX * host_mixed_case |
78+
MH_DMIX * domain_mixed_case |
79+
MH_SPACE * host_remove_spaces;
10380
params.tlsrec = tls_record_split;
10481
params.tlsrec_pos = tls_record_split_position;
10582
params.tlsrec_sni = tls_record_split_at_sni;
@@ -110,23 +87,22 @@ Java_io_github_dovecoteescapee_byedpi_ByeDpiVpnService_jniStartProxy(
11087
}
11188
}
11289

113-
struct sockaddr_ina *srv = malloc(sizeof(struct sockaddr_ina));
114-
srv->in.sin_family = AF_INET;
115-
srv->in.sin_addr.s_addr = inet_addr("0.0.0.0");
116-
srv->in.sin_port = htons(port);
117-
118-
NOT_EXIT = 1;
90+
int res = listener(event_fd, s);
11991

120-
pthread_t proxy_thread;
121-
if (pthread_create(&proxy_thread, NULL, run, srv) != 0) {
122-
LOG(LOG_S, "Failed to start proxy thread");
123-
return -1;
92+
if (close(event_fd) < 0) {
93+
uniperror("close");
12494
}
12595

126-
return proxy_thread;
96+
return res < 0 ? get_e() : 0;
12797
}
12898

129-
JNIEXPORT void JNICALL
130-
Java_io_github_dovecoteescapee_byedpi_ByeDpiVpnService_jniStopProxy(JNIEnv *env, jobject thiz, jlong proxy_thread) {
131-
NOT_EXIT = 0;
132-
}
99+
JNIEXPORT jint JNICALL
100+
Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniStopProxy(JNIEnv *env, jobject thiz,
101+
jint event_fd) {
102+
if (eventfd_write(event_fd, 1) < 0) {
103+
uniperror("eventfd_write");
104+
LOG(LOG_S, "event_fd: %d", event_fd);
105+
}
106+
107+
return 0;
108+
}

0 commit comments

Comments
 (0)