Skip to content

Commit

Permalink
Merge pull request #74 from dovecoteescapee/dev
Browse files Browse the repository at this point in the history
Add command line style settings and refactor settings
  • Loading branch information
dovecoteescapee authored Aug 11, 2024
2 parents 8085b5f + 08a562e commit 18fcf92
Show file tree
Hide file tree
Showing 25 changed files with 1,091 additions and 284 deletions.
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
tools:targetApi="34">
<activity
android:name=".activities.MainActivity"
android:exported="true"
android:launchMode="singleInstance">
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/cpp/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ int get_addr(const char *str, struct sockaddr_ina *addr);
void *add(void **root, int *n, size_t ss);

void clear_params(void);

char *ftob(const char *str, ssize_t *sl);

struct mphdr *parse_hosts(char *buffer, size_t size);

int parse_offset(struct part *part, const char *str);
60 changes: 55 additions & 5 deletions app/src/main/cpp/native-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,43 @@ const enum demode DESYNC_METHODS[] = {
DESYNC_OOB,
};

JNIEXPORT jint JNI_OnLoad(JavaVM *vm, __attribute__((unused)) void *reserved) {
oob_data.data = NULL;
JNIEXPORT jint JNI_OnLoad(
__attribute__((unused)) JavaVM *vm,
__attribute__((unused)) void *reserved) {
default_params = params;
return JNI_VERSION_1_6;
}

JNIEXPORT jint JNICALL
Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocketWithCommandLine(
JNIEnv *env,
__attribute__((unused)) jobject thiz,
jobjectArray args) {
int argc = (*env)->GetArrayLength(env, args);
char *argv[argc];
for (int i = 0; i < argc; i++) {
jstring arg = (jstring) (*env)->GetObjectArrayElement(env, args, i);
const char *arg_str = (*env)->GetStringUTFChars(env, arg, 0);
argv[i] = strdup(arg_str);
(*env)->ReleaseStringUTFChars(env, arg, arg_str);
}

int res = parse_args(argc, argv);
if (res < 0) {
uniperror("parse_args");
return -1;
}

int fd = listen_socket((struct sockaddr_ina *)&params.laddr);
if (fd < 0) {
uniperror("listen_socket");
return -1;
}
LOG(LOG_S, "listen_socket, fd: %d", fd);

return fd;
}

JNIEXPORT jint JNICALL
Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket(
JNIEnv *env,
Expand All @@ -36,6 +67,9 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket(
jint default_ttl,
jboolean custom_ttl,
jboolean no_domain,
jboolean desync_http,
jboolean desync_https,
jboolean desync_udp,
jint desync_method,
jint split_position,
jboolean split_at_host,
Expand Down Expand Up @@ -90,6 +124,10 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket(
}

dp->ttl = fake_ttl;
dp->proto =
IS_HTTP * desync_http |
IS_HTTPS * desync_https |
IS_UDP * desync_udp;
dp->mod_http =
MH_HMIX * host_mixed_case |
MH_DMIX * domain_mixed_case |
Expand All @@ -108,7 +146,9 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket(

enum demode mode = DESYNC_METHODS[desync_method];

part->flag = split_at_host ? OFFSET_SNI : 0;
int offset_flag = dp->proto || desync_https ? OFFSET_SNI : OFFSET_HOST;

part->flag = split_at_host ? offset_flag : 0;
part->pos = split_position;
part->m = mode;

Expand All @@ -125,7 +165,7 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket(
return -1;
}

tlsrec_part->flag = tls_record_split_at_sni ? OFFSET_SNI : 0;
tlsrec_part->flag = tls_record_split_at_sni ? offset_flag : 0;
tlsrec_part->pos = tls_record_split_position;
}

Expand Down Expand Up @@ -154,6 +194,16 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniCreateSocket(
(*env)->ReleaseStringUTFChars(env, custom_oob_data, oob);
}

if (dp->proto) {
dp = add((void *)&params.dp,
&params.dp_count, sizeof(struct desync_params));
if (!dp) {
uniperror("add");
clear_params();
return -1;
}
}

params.mempool = mem_pool(0);
if (!params.mempool) {
uniperror("mem_pool");
Expand Down Expand Up @@ -200,4 +250,4 @@ Java_io_github_dovecoteescapee_byedpi_core_ByeDpiProxy_jniStopProxy(
return get_e();
}
return 0;
}
}
Loading

0 comments on commit 18fcf92

Please sign in to comment.