Browse Source

Import naive

世界 4 years ago
parent
commit
b9daeddcbf

+ 1 - 2
.gitignore

@@ -16,5 +16,4 @@ local.properties
 /app/libs/
 /app/src/main/assets/v2ray
 /service_account_credentials.json
-/xtls-plugin/src/main/jniLibs
-/trojan-go-plugin/src/main/jniLibs
+jniLibs/

+ 3 - 0
.gitmodules

@@ -37,3 +37,6 @@
 [submodule "core/src/main/jni/proxychains-ng"]
 	path = core/src/main/jni/proxychains
 	url = https://github.com/SagerNet/proxychains-ng
+[submodule "naive-plugin/src/main/jni/naiveproxy"]
+	path = naive-plugin/src/main/jni/naiveproxy
+	url = https://github.com/klzgrad/naiveproxy

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

@@ -13,6 +13,7 @@
       <w>grpc</w>
       <w>gson</w>
       <w>libev</w>
+      <w>libnaive</w>
       <w>libtrojan</w>
       <w>naiveproxy</w>
       <w>nativeproxy</w>

+ 1 - 0
.idea/gradle.xml

@@ -17,6 +17,7 @@
             <option value="$PROJECT_DIR$/colorpicker" />
             <option value="$PROJECT_DIR$/core" />
             <option value="$PROJECT_DIR$/flexbox" />
+            <option value="$PROJECT_DIR$/naive-plugin" />
             <option value="$PROJECT_DIR$/plugin" />
             <option value="$PROJECT_DIR$/preferencex" />
             <option value="$PROJECT_DIR$/preferencex-colorpicker" />

+ 1 - 0
.idea/vcs.xml

@@ -5,6 +5,7 @@
     <mapping directory="$PROJECT_DIR$/core/src/main/jni/badvpn" vcs="Git" />
     <mapping directory="$PROJECT_DIR$/core/src/main/jni/libancillary" vcs="Git" />
     <mapping directory="$PROJECT_DIR$/core/src/main/jni/proxychains" vcs="Git" />
+    <mapping directory="$PROJECT_DIR$/naive-plugin/src/main/jni/naiveproxy" vcs="Git" />
     <mapping directory="$PROJECT_DIR$/shadowsocks/src/main/rust/shadowsocks-rust" vcs="Git" />
     <mapping directory="$PROJECT_DIR$/shadowsocksr/src/main/jni/libancillary" vcs="Git" />
     <mapping directory="$PROJECT_DIR$/shadowsocksr/src/main/jni/libsodium" vcs="Git" />

+ 25 - 0
bin/libs/naive.sh

@@ -0,0 +1,25 @@
+#!/bin/bash
+
+source "bin/init/env.sh"
+
+ROOT="$PROJECT/naive-plugin/src/main/jniLibs"
+OUTPUT="naive"
+LIB_OUTPUT="lib$OUTPUT.so"
+
+cd naive-plugin/src/main/jni/naiveproxy/src
+
+export EXTRA_FLAGS='target_os="android" target_cpu="arm64"'
+./get-clang.sh
+./build.sh
+DIR="$ROOT/arm64-v8a"
+rm -rf $DIR
+mkdir -p $DIR
+cp out/Release/naive $DIR/$LIB_OUTPUT
+
+export EXTRA_FLAGS='target_os="android" target_cpu="x64"'
+./get-clang.sh
+./build.sh
+DIR="$ROOT/x86_64"
+rm -rf $DIR
+mkdir -p $DIR
+cp out/Release/naive $DIR/$LIB_OUTPUT

+ 98 - 0
naive-plugin/build.gradle

@@ -0,0 +1,98 @@
+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.naive"
+        minSdkVersion 21
+        targetSdkVersion 30
+        versionCode 1
+        versionName "90.0.4430.85-7"
+    }
+
+    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"), "../plugin/proguard-rules.pro"
+            signingConfig keystorePwd == null ? signingConfigs.debug : signingConfigs.release
+        }
+    }
+
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+        coreLibraryDesugaringEnabled true
+    }
+
+    kotlinOptions {
+        jvmTarget = "1.8"
+    }
+
+    packagingOptions {
+        exclude "/META-INF/*.version"
+        exclude "/META-INF/*.kotlin_module"
+        exclude "/META-INF/native-image/**"
+        exclude "/META-INF/INDEX.LIST"
+        exclude "DebugProbesKt.bin"
+        exclude "/kotlin/**"
+    }
+
+    splits {
+        abi {
+            enable true
+            universalApk false
+        }
+    }
+
+    applicationVariants.all { variant ->
+        variant.outputs.all { output ->
+            outputFileName = outputFileName.replace("plugin", "plugin-" + variant.versionName)
+        }
+    }
+
+}
+
+dependencies {
+    implementation project(":plugin")
+    coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
+}

+ 37 - 0
naive-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.naive"
+    android:installLocation="internalOnly">
+
+    <application
+        android:allowBackup="false"
+        android:extractNativeLibs="true"
+        android:label="Naive Plugin">
+        <provider
+            android:name=".BinaryProvider"
+            android:authorities="io.nekohasekai.sagernet.plugin.naive.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="/naive-plugin"
+                    android:scheme="plugin" />
+            </intent-filter>
+
+            <meta-data
+                android:name="io.nekohasekai.sagernet.plugin.id"
+                android:value="naive-plugin" />
+            <meta-data
+                android:name="io.nekohasekai.sagernet.plugin.executable_path"
+                android:value="libnaive.so" />
+        </provider>
+    </application>
+
+</manifest>

+ 44 - 0
naive-plugin/src/main/java/io/nekohasekai/sagernet/plugin/naive/BinaryProvider.kt

@@ -0,0 +1,44 @@
+/******************************************************************************
+ *                                                                            *
+ * Copyright (C) 2021 by nekohasekai <[email protected]>                    *
+ * Copyright (C) 2021 by Max Lv <[email protected]>                          *
+ * Copyright (C) 2021 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.naive
+
+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("naive-plugin", 0b111101101)
+    }
+
+    override fun getExecutable() = context!!.applicationInfo.nativeLibraryDir + "/libnaive.so"
+    override fun openFile(uri: Uri): ParcelFileDescriptor = when (uri.path) {
+        "/naive-plugin" -> ParcelFileDescriptor.open(
+            File(getExecutable()),
+            ParcelFileDescriptor.MODE_READ_ONLY
+        )
+        else -> throw FileNotFoundException()
+    }
+}

+ 1 - 0
naive-plugin/src/main/jni/naiveproxy

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

+ 1 - 0
settings.gradle

@@ -8,6 +8,7 @@ include ':shadowsocksr'
 include ':plugin'
 include ':xtls-plugin'
 include ':trojan-go-plugin'
+include ':naive-plugin'
 
 include ':preferencex'
 include ':preferencex-ringtone'

+ 3 - 3
trojan-go-plugin/src/main/AndroidManifest.xml

@@ -1,7 +1,7 @@
 <?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.trojan_go"
+    package="io.nekohasekai.sagernet.plugin.naive"
     android:installLocation="internalOnly">
 
     <application
@@ -9,8 +9,8 @@
         android:extractNativeLibs="true"
         android:label="Trojan-Go Plugin">
         <provider
-            android:name=".BinaryProvider"
-            android:authorities="io.nekohasekai.sagernet.plugin.trojan_go.BinaryProvider"
+            android:name="io.nekohasekai.sagernet.plugin.naive.BinaryProvider"
+            android:authorities="io.nekohasekai.sagernet.plugin.naive.BinaryProvider"
             android:directBootAware="true"
             android:exported="true"
             tools:ignore="ExportedContentProvider">

+ 21 - 20
trojan-go-plugin/src/main/java/io/nekohasekai/sagernet/plugin/trojan_go/BinaryProvider.kt → trojan-go-plugin/src/main/java/io/nekohasekai/sagernet/plugin/naive/BinaryProvider.kt

@@ -1,24 +1,25 @@
-/*******************************************************************************
- *                                                                             *
- *  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/>.       *
- *                                                                             *
- *******************************************************************************/
+/******************************************************************************
+ *                                                                            *
+ * Copyright (C) 2021 by nekohasekai <[email protected]>                    *
+ * Copyright (C) 2021 by Max Lv <[email protected]>                          *
+ * Copyright (C) 2021 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.trojan_go
+package io.nekohasekai.sagernet.plugin.naive
 
 import android.net.Uri
 import android.os.ParcelFileDescriptor

+ 20 - 19
xtls-plugin/src/main/java/io/nekohasekai/sagernet/plugin/xtls/BinaryProvider.kt

@@ -1,22 +1,23 @@
-/*******************************************************************************
- *                                                                             *
- *  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/>.       *
- *                                                                             *
- *******************************************************************************/
+/******************************************************************************
+ *                                                                            *
+ * Copyright (C) 2021 by nekohasekai <[email protected]>                    *
+ * Copyright (C) 2021 by Max Lv <[email protected]>                          *
+ * Copyright (C) 2021 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.xtls