Browse Source

Import Xray

世界 4 years ago
parent
commit
9e13280342

+ 2 - 1
.gitignore

@@ -15,4 +15,5 @@ build/
 local.properties
 local.properties
 /app/libs/
 /app/libs/
 /app/src/main/assets/v2ray
 /app/src/main/assets/v2ray
-/service_account_credentials.json
+/service_account_credentials.json
+/xray-plugin/src/main/jniLibs

+ 3 - 0
.gitmodules

@@ -28,3 +28,6 @@
 [submodule "shadowsocksr/src/main/jni/re2"]
 [submodule "shadowsocksr/src/main/jni/re2"]
 	path = shadowsocksr/src/main/jni/re2
 	path = shadowsocksr/src/main/jni/re2
 	url = https://github.com/google/re2
 	url = https://github.com/google/re2
+[submodule "xray-plugin/src/main/go/Xray-core"]
+	path = xray-plugin/src/main/go/Xray-core
+	url = https://github.com/XTLS/Xray-core

+ 1 - 0
.idea/dictionaries/sekai.xml

@@ -21,6 +21,7 @@
       <w>uplink</w>
       <w>uplink</w>
       <w>vless</w>
       <w>vless</w>
       <w>vmess</w>
       <w>vmess</w>
+      <w>xray</w>
     </words>
     </words>
   </dictionary>
   </dictionary>
 </component>
 </component>

+ 1 - 0
.idea/gradle.xml

@@ -17,6 +17,7 @@
             <option value="$PROJECT_DIR$/plugin" />
             <option value="$PROJECT_DIR$/plugin" />
             <option value="$PROJECT_DIR$/shadowsocks" />
             <option value="$PROJECT_DIR$/shadowsocks" />
             <option value="$PROJECT_DIR$/shadowsocksr" />
             <option value="$PROJECT_DIR$/shadowsocksr" />
+            <option value="$PROJECT_DIR$/xray-plugin" />
           </set>
           </set>
         </option>
         </option>
         <option name="resolveModulePerSourceSet" value="false" />
         <option name="resolveModulePerSourceSet" value="false" />

+ 0 - 4
README.md

@@ -40,10 +40,6 @@ The application is designed to be used whenever possible.
 * The Chinese apps scanner will only scan system apps if "Show system apps" is checked  
 * The Chinese apps scanner will only scan system apps if "Show system apps" is checked  
 * ~~V2Ray browser forwarding is not yet available, only for developers to debug~~ Fixed
 * ~~V2Ray browser forwarding is not yet available, only for developers to debug~~ Fixed
 
 
-## XRAY
-
-SagerNet is a V2Ray client, not an Xray client. For that, please use the official X-flutter client.
-
 ## OPEN SOURCE LICENSES
 ## OPEN SOURCE LICENSES
 
 
 <ul>
 <ul>

+ 1 - 1
app/build.gradle

@@ -87,7 +87,7 @@ android {
 
 
     signingConfigs {
     signingConfigs {
         release {
         release {
-            storeFile project.file("release.keystore")
+            storeFile rootProject.file("release.keystore")
             storePassword keystorePwd
             storePassword keystorePwd
             keyAlias alias
             keyAlias alias
             keyPassword pwd
             keyPassword pwd

+ 47 - 0
bin/libs/xray.sh

@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+source "bin/init/env.sh"
+
+DEPS=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin
+
+ANDROID_ARM_CC=$DEPS/armv7a-linux-androideabi16-clang
+ANDROID_ARM_STRIP=$DEPS/arm-linux-androideabi-strip
+
+ANDROID_ARM64_CC=$DEPS/aarch64-linux-android21-clang
+ANDROID_ARM64_STRIP=$DEPS/aarch64-linux-android-strip
+
+ANDROID_X86_CC=$DEPS/i686-linux-android16-clang
+ANDROID_X86_STRIP=$DEPS/i686-linux-android-strip
+
+ANDROID_X86_64_CC=$DEPS/x86_64-linux-android21-clang
+ANDROID_X86_64_STRIP=$DEPS/x86_64-linux-android-strip
+
+export GO111MOD=on
+export CGO_ENABLED=1
+export GOOS=android
+
+OUTPUT="xrayexec"
+LIB_OUTPUT="lib$OUTPUT.so"
+AAR_OUTPUT="$OUTPUT.aar"
+ROOT="$PROJECT/xray-plugin/src/main/jniLibs"
+cd $PROJECT/xray-plugin/src/main/go/Xray-core
+
+DIR="$ROOT/armeabi-v7a"
+mkdir -p $DIR
+env CC=$ANDROID_ARM_CC GOARCH=arm GOARM=7 go build -x -o $DIR/$LIB_OUTPUT -trimpath -ldflags "-s -w -buildid=" ./main
+$ANDROID_ARM_STRIP $DIR/$LIB_OUTPUT
+
+DIR="$ROOT/arm64-v8a"
+mkdir -p $DIR
+env CC=$ANDROID_ARM64_CC GOARCH=arm64 go build -x -o $DIR/$LIB_OUTPUT -trimpath -ldflags "-s -w -buildid=" ./main
+$ANDROID_ARM64_STRIP $DIR/$LIB_OUTPUT
+
+DIR="$ROOT/x86"
+mkdir -p $DIR
+env CC=$ANDROID_X86_CC GOARCH=386 go build -x -o $DIR/$LIB_OUTPUT -trimpath -ldflags "-s -w -buildid=" ./main
+$ANDROID_X86_STRIP $DIR/$LIB_OUTPUT
+
+DIR="$ROOT/x86_64"
+mkdir -p $DIR
+env CC=$ANDROID_X86_64_CC GOARCH=amd64 go build -x -o $DIR/$LIB_OUTPUT -trimpath -ldflags "-s -w -buildid=" ./main
+$ANDROID_X86_64_STRIP $DIR/$LIB_OUTPUT

+ 1 - 5
metadata/description.txt

@@ -26,8 +26,4 @@ TIPS
 * Click on the title to scroll to the first proxy or the selected proxy  
 * Click on the title to scroll to the first proxy or the selected proxy  
 * Proxy list can be dragged by holding the progress bar  
 * Proxy list can be dragged by holding the progress bar  
 * The china apps scanner will only scan system apps if "Show system apps" is checked  
 * The china apps scanner will only scan system apps if "Show system apps" is checked  
-* V2Ray browser forwarding is not yet available, only for developers to debug
-
-XRAY
-
-SagerNet is a V2Ray client, not an XRay client. For that, please use the official X-flutter client.
+* V2Ray browser forwarding is not yet available, only for developers to debug

+ 0 - 0
app/release.keystore → release.keystore


+ 2 - 1
settings.gradle

@@ -4,4 +4,5 @@ rootProject.name = "SagerNet"
 include ':shadowsocks'
 include ':shadowsocks'
 include ':shadowsocksr'
 include ':shadowsocksr'
 
 
-include ':plugin'
+include ':plugin'
+include ':xray-plugin'

+ 80 - 0
xray-plugin/build.gradle

@@ -0,0 +1,80 @@
+plugins {
+    id "com.android.application"
+    id "kotlin-android"
+    id "kotlin-parcelize"
+}
+
+
+def keystorePwd = null
+def alias = null
+def pwd = null
+
+Properties properties
+def base64 = System.getenv("LOCAL_PROPERTIES")
+if (base64 != null && !base64.isBlank()) {
+    properties = new Properties()
+    properties.load(new ByteArrayInputStream(Base64.decoder.decode(base64)))
+} else if (project.rootProject.file("local.properties").exists()) {
+    properties = new Properties()
+    properties.load(project.rootProject.file("local.properties").newDataInputStream())
+}
+
+if (properties != null) {
+    keystorePwd = properties.getProperty("KEYSTORE_PASS")
+    alias = properties.getProperty("ALIAS_NAME")
+    pwd = properties.getProperty("ALIAS_PASS")
+}
+
+keystorePwd = keystorePwd ?: System.getenv("KEYSTORE_PASS")
+alias = alias ?: System.getenv("ALIAS_NAME")
+pwd = pwd ?: System.getenv("ALIAS_PASS")
+
+android {
+    compileSdkVersion 30
+    buildToolsVersion "30.0.3"
+
+    defaultConfig {
+        applicationId "io.nekohasekai.sagernet.plugin.xray"
+        minSdkVersion 21
+        targetSdkVersion 30
+        versionCode 1
+        versionName "io.nekohasekai.sagernet.plugin.xray"
+    }
+
+    signingConfigs {
+        release {
+            storeFile rootProject.file("release.keystore")
+            storePassword keystorePwd
+            keyAlias alias
+            keyPassword pwd
+        }
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled true
+            shrinkResources true
+            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
+            signingConfig keystorePwd == null ? signingConfigs.debug : signingConfigs.release
+        }
+    }
+
+    splits {
+        abi {
+            enable true
+            universalApk false
+        }
+    }
+
+    applicationVariants.all { variant ->
+        variant.outputs.all { output ->
+            outputFileName = outputFileName.replace("app", "xray-plugin-" + variant.versionName)
+        }
+    }
+
+}
+
+dependencies {
+    implementation fileTree(dir: "libs")
+    implementation project(":plugin")
+}

+ 37 - 0
xray-plugin/src/main/AndroidManifest.xml

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    package="io.nekohasekai.sagernet.plugin.xray"
+    android:installLocation="internalOnly">
+
+    <application
+        android:allowBackup="false"
+        android:extractNativeLibs="true"
+        android:label="Xray Plugin">
+        <provider
+            android:name=".BinaryProvider"
+            android:authorities="io.nekohasekai.sagernet.plugin.xray.BinaryProvider"
+            android:directBootAware="true"
+            android:exported="true"
+            tools:ignore="ExportedContentProvider">
+            <intent-filter>
+                <action android:name="io.nekohasekai.sagernet.plugin.ACTION_NATIVE_PLUGIN" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="io.nekohasekai.sagernet.plugin.ACTION_NATIVE_PLUGIN" />
+                <data
+                    android:host="io.nekohasekai.sagernet"
+                    android:path="/xray"
+                    android:scheme="plugin" />
+            </intent-filter>
+        </provider>
+
+        <meta-data
+            android:name="io.nekohasekai.sagernet.plugin.id"
+            android:value="xray-plugin" />
+        <meta-data
+            android:name="com.github.shadowsocks.plugin.executable_path"
+            android:value="libxrayexec.so" />
+    </application>
+
+</manifest>

+ 1 - 0
xray-plugin/src/main/go/Xray-core

@@ -0,0 +1 @@
+Subproject commit f65c21337cbd2183b88a1af1787acd2b8d940183

+ 41 - 0
xray-plugin/src/main/java/io/nekohasekai/sagernet/plugin/xray/BinaryProvider.kt

@@ -0,0 +1,41 @@
+/*******************************************************************************
+ *                                                                             *
+ *  Copyright (C) 2019 by Max Lv <[email protected]>                          *
+ *  Copyright (C) 2019 by Mygod Studio <[email protected]>  *
+ *                                                                             *
+ *  This program is free software: you can redistribute it and/or modify       *
+ *  it under the terms of the GNU General Public License as published by       *
+ *  the Free Software Foundation, either version 3 of the License, or          *
+ *  (at your option) any later version.                                        *
+ *                                                                             *
+ *  This program is distributed in the hope that it will be useful,            *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ *  GNU General Public License for more details.                               *
+ *                                                                             *
+ *  You should have received a copy of the GNU General Public License          *
+ *  along with this program. If not, see <http://www.gnu.org/licenses/>.       *
+ *                                                                             *
+ *******************************************************************************/
+
+package io.nekohasekai.sagernet.plugin.xray
+
+import android.net.Uri
+import android.os.ParcelFileDescriptor
+import io.nekohasekai.sagernet.plugin.NativePluginProvider
+import io.nekohasekai.sagernet.plugin.PathProvider
+import java.io.File
+import java.io.FileNotFoundException
+
+class BinaryProvider : NativePluginProvider() {
+    override fun populateFiles(provider: PathProvider) {
+        provider.addPath("xray", 0b111101101)
+    }
+
+    override fun getExecutable() = context!!.applicationInfo.nativeLibraryDir + "/libxrayexec.so"
+    override fun openFile(uri: Uri): ParcelFileDescriptor = when (uri.path) {
+        "/xray" -> ParcelFileDescriptor.open(File(getExecutable()),
+            ParcelFileDescriptor.MODE_READ_ONLY)
+        else -> throw FileNotFoundException()
+    }
+}