Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
merge gui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
segfault-bilibili committed Feb 14, 2022
1 parent 11bb524 commit c9094be
Show file tree
Hide file tree
Showing 12 changed files with 1,235 additions and 30 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ android {

dependencies {
implementation 'com.github.shadowsocks:plugin:1.2.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}

task buildGoLibrary(type: Exec) {
Expand All @@ -41,4 +43,4 @@ tasks.whenTaskAdded { theTask ->
if (theTask.name.equals("preDebugBuild") || theTask.name.equals("preReleaseBuild")) {
theTask.dependsOn "buildGoLibrary"
}
}
}
72 changes: 44 additions & 28 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.shadowsocks.plugin.gost">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true">
<provider android:name=".BinaryProvider"
android:exported="true"
android:authorities="com.github.shadowsocks.plugin.gost.BinaryProvider">
<intent-filter>
<action android:name="com.github.shadowsocks.plugin.ACTION_NATIVE_PLUGIN"/>
</intent-filter>
<intent-filter>
<action android:name="com.github.shadowsocks.plugin.ACTION_NATIVE_PLUGIN"/>
<data android:scheme="plugin"
android:host="com.github.shadowsocks"
android:pathPrefix="/gost"/>
</intent-filter>
<meta-data android:name="com.github.shadowsocks.plugin.id"
android:value="gost"/>
<meta-data android:name="com.github.shadowsocks.plugin.default_config"
android:value="-F ss+mws://chacha20:ss123456@#SS_HOST:#SS_PORT"/>
</provider>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.shadowsocks.plugin.gost">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true">
<activity
android:name=".ConfigActivity">
<intent-filter>
<action android:name="com.github.shadowsocks.plugin.ACTION_CONFIGURE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="plugin"
android:host="com.github.shadowsocks"
android:path="/gost"/>
</intent-filter>
</activity>

<provider
android:name=".BinaryProvider"
android:authorities="com.github.shadowsocks.plugin.gost.BinaryProvider"
android:exported="true">
<intent-filter>
<action android:name="com.github.shadowsocks.plugin.ACTION_NATIVE_PLUGIN" />
</intent-filter>
<intent-filter>
<action android:name="com.github.shadowsocks.plugin.ACTION_NATIVE_PLUGIN" />

<data
android:host="com.github.shadowsocks"
android:path="/gost"
android:scheme="plugin" />
</intent-filter>

<meta-data
android:name="com.github.shadowsocks.plugin.id"
android:value="gost" />
</provider>
</application>

</manifest>
106 changes: 106 additions & 0 deletions app/src/main/java/com/github/shadowsocks/plugin/gost/Base64.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.github.shadowsocks.plugin.gost;

public class Base64 {
private char paddingChar = '=';

public void setPaddingChar(char c) throws Base64Exception {
if (
(c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') ||
c == '+' || c == '/'
) throw new Base64Exception("INVALID_PADDING_CHAR");
this.paddingChar = c;
}

public static class Base64Exception extends Exception {
String msg;
@Override
public String getMessage() {
return this.msg;
}
Base64Exception(String msg) {
this.msg = msg;
}
}

public byte[] decode(String encoded) throws Base64Exception {
char[] input = new char[encoded.length()];
encoded.getChars(0, encoded.length(), input, 0);
return this.decode(input);
}
public byte[] decode(char[] input) throws Base64Exception {
if (input.length % 4 != 0)
throw new Base64Exception("BASE64_DECODE_INVALID_LENGTH");
if (input.length == 0) return new byte[0];
int endPos = 0;
for (int i = input.length - 1; i >= input.length - 4; i--) {
char c = input[i];
if (
(c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') ||
c == '+' || c == '/'
) {
endPos = i + 1;
break;
} else if (c != this.paddingChar) {
throw new Base64Exception("BASE64_DECODE_INVALID_CHAR");
} else if (i == input.length - 4) {
throw new Base64Exception("BASE64_DECODE_INVALID_PADDING");
}
}
int resultLen = (endPos * 6 + 8 - 1) / 8;
byte[] result = new byte[resultLen];
for (int i = 0, o = 0, buf = 0; i < endPos; i++) {
char c = input[i];
if (c >= 'A' && c <= 'Z') {
c -= 'A';
} else if (c >= 'a' && c <= 'z') {
c += 26 - 'a';
} else if (c >= '0' && c <= '9') {
c += 26 + 26 - '0';
} else if (c == '+') {
c = 26 + 26 + 10;
} else if (c == '/') {
c = 26 + 26 + 10 + 1;
} else throw new Base64Exception("BASE64_DECODE_INVALID_CHAR");
buf |= (((int) c) & 0xFF) << (3 - (i % 4)) * 6;
if ((i + 1) % 4 == 0 || i == endPos - 1) {
for (int j = 0; j < 3 && o < resultLen; j++, o++) {
result[o] = (byte) ((buf >> (2 - j) * 8) & 0xFF);
}
buf = 0;
}
}
return result;
}
public String encode(byte[] bin) {
int resultLen = (bin.length * 8 + 6 - 1) / 6;
int outputLen = (resultLen + 4 - 1) / 4;
outputLen *= 4;
char[] output = new char[outputLen];
for (int i = 0, o = 0, buf = 0; i < bin.length; i++) {
buf |= (((int) bin[i]) & 0xFF) << (2 - (i % 3)) * 8;
if ((i + 1) % 3 == 0 || i == bin.length - 1) {
for (int j = 0; j < 4 && o < resultLen; j++, o++) {
int c = (buf >> (3 - j) * 6) & 0x3F;
if (c < 26) {
output[o] = (char) ('A' + c);
} else if (c < 26 + 26) {
output[o] = (char) ('a' + c - 26);
} else if (c < 26 + 26 + 10) {
output[o] = (char) ('0' + c - (26 + 26));
} else if (c == 26 + 26 + 10) {
output[o] = '+';
} else { // always (c == 26 + 26 + 10 + 1)
output[o] = '/';
}
}
buf = 0;
}
}
for (int i = resultLen; i < outputLen; i++) {
output[i] = this.paddingChar;
}
return new String(output);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.shadowsocks.plugin.gost;

import android.content.pm.Signature;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import com.github.shadowsocks.plugin.NativePluginProvider;
Expand Down
Loading

0 comments on commit c9094be

Please sign in to comment.