Skip to content

Commit

Permalink
Suport KernelSU
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamail committed Jan 19, 2023
1 parent 6daa7c9 commit c025ede
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
files: Clash_for_Magisk-v*.zip
files: Clash_for_KernelSU-v*.zip
generate_release_notes: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Clash_for_KernelSU-v3.0.zip
.DS_Store
33 changes: 0 additions & 33 deletions META-INF/com/google/android/update-binary

This file was deleted.

1 change: 0 additions & 1 deletion META-INF/com/google/android/updater-script

This file was deleted.

45 changes: 20 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Clash for Magisk
# Clash for KernelSU
<h1 align="center">
<img src="https://github.com/taamarin/ClashforMagisk/blob/master/docs/logo.png" alt="Clash" width="200">
<img src="https://github.com/Dreamail/ClashforKernelSU/blob/master/docs/logo.png" alt="Clash" width="200">
<br>Clash<br>
</h1>
<h4 align="center">Proxy Transparan for android.</h4>
Expand All @@ -9,27 +9,24 @@
<div align="center">

[![ANDROID](https://img.shields.io/badge/Android-3DDC84?style=for-the-badge&logo=android&logoColor=white)]()
[![RELEASES](https://img.shields.io/github/downloads/taamarin/ClashforMagisk/total.svg?style=for-the-badge)](https://github.com/taamarin/ClashforMagisk/releases)
[![TELEGRAM CHANNEL](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/nothing_taamarin)
[![TELEGRAM](https://img.shields.io/badge/Telegram%20-Grups%20-blue?style=for-the-badge)](https://t.me/taamarin)
[![MAGISK](https://img.shields.io/badge/Magisk%20-v20.4+-brightgreen?style=for-the-badge)](https://github.com/topjohnwu/Magisk)
[![RELEASES](https://img.shields.io/github/downloads/Dreamail/ClashforKernelSU/total.svg?style=for-the-badge)](https://github.com/Dreamail/ClashforKernelSU/releases)
[![API](https://img.shields.io/badge/API-19%2B-brightgreen.svg?style=for-the-badge)](https://android-arsenal.com/api?level=19)
<a href="https://github.com/taamarin/ClashforMagisk/releases">
<img src="https://img.shields.io/github/release/taamarin/ClashforMagisk/all.svg?style=for-the-badge">
<a href="https://github.com/Dreamail/ClashforKernelSU/releases">
<img src="https://img.shields.io/github/release/Dreamail/ClashforKernelSU/all.svg?style=for-the-badge">
</a>

</div>

A fork of [ClashForMagisk](https://github.com/kalasutra/Clash_For_Magisk)
A fork of [ClashForMagisk](https://github.com/taamarin/ClashforMagisk)

This is a Clash module for Magisk, and includes binaries for arm, arm64, x86, x64.
This is a Clash module for KernelSU, and includes binaries for arm, arm64.

## Manager Apps CFM
## Manager Apps
- [ClashForMagisk_Manager](https://t.me/taamarin/26137) EN
- [ClashForMagisk_Manager](https://t.me/MagiskChangeKing/159) CN

## Install
You can download the release [installer zip](https://github.com/taamarin/ClashforMagisk/releases) file and install it via the Magisk Manager App.
You can download the release [installer zip](https://github.com/Dreamail/ClashforKernelSU/releases) file and install it via the KernelSU manager App.

#### Config
- Clash config files `/data/clash/*`
Expand All @@ -43,26 +40,26 @@ You can download the release [installer zip](https://github.com/taamarin/Clashfo
### Normal usage ( Default and Recommended )
##### Manage service start / stop
- Clash service is auto-run after system boot up by default.
- You can use Magisk Manager App to manage it. Be patient to wait it take effect (about 3 second).
- You can use KernelSU manager App to manage it. Be patient to wait it take effect (about 3 second).

### Advanced usage
> MODDIR= "/data/clash"
##### Change proxy mode
- Clash uses `TPROXY` transparent proxy `TCP + UDP` by default, if it detects that the device does not support `TPROXY`, it will automatically use `REDIRECT` to proxy only `TCP`

- Open `${MODDIR}/scripts/clash.config` file line [17-18](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L17-#L18), modify the value of `network_mode` to `TCP` or `MIXED `to use `REDIRECT` to proxy `TCP`, and `UDP` will not be proxied when `TUN` is not enabled in the Clash kernel
- Open `${MODDIR}/scripts/clash.config` file line [17-18](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L17-#L18), modify the value of `network_mode` to `TCP` or `MIXED `to use `REDIRECT` to proxy `TCP`, and `UDP` will not be proxied when `TUN` is not enabled in the Clash kernel

##### Bypass transparent proxy when connected to Wi-Fi or open a hotspot
Clash default transparent proxy local and hotspot, line [20-23](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L20-#L23)
Clash default transparent proxy local and hotspot, line [20-23](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L20-#L23)

- Open the `${MODDIR}/scripts/clash.config` file, modify the `ignore_out_list` array and add the `wlan+` element, the transparent proxy will `bypass` the `WLAN`, and the hotspot will not be affected

- Open the `${MODDIR}/scripts/clash.config` file, modify the ap_list array and delete the `wlan+` element to opaque proxy `WLAN` and hotspot (the `MediaTek` model may be `ap+` instead of `wlan+`)

##### Select which packages to proxy
- If you expect all Apps proxy by Clash with transparent proxy EXCEPT specific Apps, write down bypass at the first line then these Apps' packages separated as above in file `/data/clash/packages.list`
- clash.config line [14-15](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L14-#L15)
- clash.config line [14-15](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L14-#L15)
- `blacklist` & `whitelits`, not working on `fake-ip`

- dns:
Expand All @@ -87,7 +84,7 @@ Clash default transparent proxy local and hotspot, line [20-23](https://github.c
##### subscription
you can use SubScription
- open `/data/clash/clash.config` line [30-35](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L30-#L35)
- open `/data/clash/clash.config` line [30-35](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L30-#L35)
- update_interval="interval contab"
- Subcript_url="your_link"
- auto_updateSubcript="true"
Expand All @@ -98,7 +95,7 @@ ${MODDIR}/scripts/clash.tool -s
```

##### Config Online
- **clash.config** line [37-38](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L37-#L38), If true,
- **clash.config** line [37-38](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L37-#L38), If true,
- use it to download the subscription configuration, when starting Clash , So no need to type `${MODDIR}/scripts/clash.tool -s` anymore

##### Change Clash kernel
Expand All @@ -108,28 +105,26 @@ You can use Clash.Premium and Clash.Meta
- Clash Premium
- `/data/clash/kernel/lib/Clash.Premium`

you can download the Kernel automatically, for the settings in the **clash.config** line [85-109](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L85-#L109)
you can download the Kernel automatically, for the settings in the **clash.config** line [85-109](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L85-#L109)
```shell
${MODDIR}/scripts/clash.tool -k
```

##### GeoSite, GeoIP, and Mmdb
- settings are in clash.config line [111-135](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L111-#L135)
- settings are in clash.config line [111-135](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L111-#L135)
- if true, will be updated every day at 00.00
- you can change the URL

## Uninstall
- Uninstall the module via Magisk Manager App.
- Uninstall the module via KernelSU manager App.
- You can clean Clash data dir by running command
```shell
rm -rf /data/clash && rm -rf /data/adb/service.d/clash_service.sh
rm -rf /data/clash
```

## Tutorial Clash For Magisk
> Tutorial [Tap Here](https://telegra.ph/%F0%9D%93%92%F0%9D%93%B5%F0%9D%93%AA%F0%9D%93%BC%F0%9D%93%B1%F0%9D%93%95%F0%9D%93%B8%F0%9D%93%BB%F0%9D%93%9C%F0%9D%93%AA%F0%9D%93%B0%F0%9D%93%B2%F0%9D%93%BC%F0%9D%93%B4-11-28)
## Credits
This is a repo fork
- [taamarin/ClashforMagisk](https://github.com/taamarin/ClashforMagisk)
- [kalasutra/Clash_for_magisk](https://github.com/kalasutra/Clash_For_Magisk)
- [CHIZI-0618/box4magisk](https://github.com/CHIZI-0618/box4magisk)
- [Asterisk4Magisk/Xray4Magisk](https://github.com/Asterisk4Magisk/Xray4Magisk)
Expand Down
Binary file modified binary/arm.tar.bz2
Binary file not shown.
Binary file modified binary/arm64.tar.bz2
Binary file not shown.
Binary file removed binary/x64.tar.bz2
Binary file not shown.
Binary file removed binary/x86.tar.bz2
Binary file not shown.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

zip -r -o -X -ll Clash_for_Magisk-$(cat module.prop | grep 'version=' | awk -F '=' '{print $2}').zip ./ -x '.git/*' -x 'build.sh' -x 'docs/*' -x 'CHANGELOG.md' -x 'README.md' -x 'update.json' -x '.github/*'
zip -r -o -X -ll Clash_for_KernelSU-$(cat module.prop | grep 'version=' | awk -F '=' '{print $2}').zip ./ -x '.git/*' -x 'build.sh' -x 'docs/*' -x 'CHANGELOG.md' -x 'README.md' -x 'update.json' -x '.github/*'
22 changes: 7 additions & 15 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@ architecture=""
uid="0"
gid="3005"
clash_data_dir="/data/clash"
modules_dir="/data/adb/modules"
modules_dir="/data/adb/ksu/modules"
bin_path="/system/bin/"
dns_path="/system/etc"
clash_adb_dir="/data/adb"
clash_service_dir="/data/adb/service.d"
busybox_data_dir="/data/adb/magisk/busybox"
ca_path="${dns_path}/security/cacerts"
clash_data_dir_kernel="${clash_data_dir}/kernel"
clash_data_dir_tools="${clash_data_dir}/tools"
clash_data_sc="${clash_data_dir}/scripts"
mod_config="${clash_data_sc}/clash.config"
yacd_dir="${clash_data_dir}/dashboard"
latest=$(date +%Y%m%d%H%M)

if [ $BOOTMODE ! = true ] ; then
ui_print "- Installing through TWRP Not supported"
ui_print "- Intsall this module via Magisk Manager"
ui_print "- Intsall this module via KernelSU manager"
abort "- ! Aborting installation !"
fi

ui_print "- Installing Clash for Magisk"
ui_print "- Installing Clash for KernelSU"

if [ -d "${clash_data_dir}" ] ; then
ui_print "- Backup Clash"
Expand All @@ -41,6 +39,7 @@ fi
ui_print "- Create folder Clash."
mkdir -p ${clash_data_dir}
mkdir -p ${clash_data_dir_kernel}
mkdir -p ${clash_data_dir_tools}
mkdir -p ${MODPATH}${ca_path}
mkdir -p ${clash_data_dir}/dashboard
mkdir -p ${MODPATH}/system/bin
Expand Down Expand Up @@ -77,11 +76,6 @@ ui_print "- Move Cert&Geo"
mv ${clash_data_dir}/scripts/cacert.pem ${MODPATH}${ca_path}
mv ${MODPATH}/geo/* ${clash_data_dir}/

if [ ! -d /data/adb/service.d ] ; then
ui_print "- Make folder service"
mkdir -p /data/adb/service.d
fi

ui_print "- Create resolv.conf"
if [ ! -f "${dns_path}/resolv.conf" ] ; then
touch ${MODPATH}${dns_path}/resolv.conf
Expand All @@ -98,7 +92,6 @@ fi

unzip -j -o "${ZIPFILE}" 'service.sh' -d ${MODPATH} >&2
unzip -j -o "${ZIPFILE}" 'uninstall.sh' -d ${MODPATH} >&2
unzip -j -o "${ZIPFILE}" 'clash_service.sh' -d ${clash_service_dir} >&2

ui_print "- Extract binary-$ARCH "
tar -xjf ${MODPATH}/binary/${ARCH}.tar.bz2 -C ${clash_data_dir_kernel}/&& echo "- extar kernel Succes" || echo "- extar kernel gagal"
Expand All @@ -109,6 +102,7 @@ mv ${clash_data_dir}/scripts/clash.config ${clash_data_dir}/
mv ${clash_data_dir}/scripts/mosdns ${clash_data_dir}/
mv ${clash_data_dir}/mosdns/mosdns ${clash_data_dir_kernel}/
mv ${clash_data_dir}/mosdns/dnstt-client ${clash_data_dir_kernel}/
mv ${clash_data_dir_kernel}/busybox ${clash_data_dir_tools}/

if [ ! -f "${bin_path}/ss" ] ; then
mv ${clash_data_dir_kernel}/ss ${MODPATH}${bin_path}/
Expand All @@ -120,15 +114,13 @@ rm -rf ${MODPATH}/dashboard.zip
rm -rf ${MODPATH}/scripts
rm -rf ${MODPATH}/geo
rm -rf ${MODPATH}/binary
rm -rf ${MODPATH}/clash_service.sh
rm -rf ${clash_data_dir}/scripts/config.yaml
rm -rf ${clash_data_dir_kernel}/curl

sleep 1

ui_print "- Set Permissons"
set_perm_recursive ${MODPATH} 0 0 0755 0644
set_perm_recursive ${clash_service_dir} 0 0 0755 0755
set_perm_recursive ${clash_data_dir} ${uid} ${gid} 0755 0644
set_perm_recursive ${clash_data_dir}/scripts ${uid} ${gid} 0755 0755
set_perm_recursive ${clash_data_dir}/kernel ${uid} ${gid} 0755 0755
Expand All @@ -152,6 +144,6 @@ set_perm ${clash_data_dir}/scripts/usage.sh 0 0 0755
set_perm ${clash_data_dir}/clash.config ${uid} ${gid} 0755
set_perm ${clash_data_dir}/kernel/mosdns 0 0 0755
set_perm ${clash_data_dir}/kernel/dnstt-client 0 0 0755
set_perm ${clash_service_dir}/clash_service.sh 0 0 0755
set_perm ${clash_data_dir}/tools/busybox 0 0 0755
sleep 1
ui_print "- Installation is complete, reboot your device"
8 changes: 4 additions & 4 deletions module.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id=ClashForMagisk
name=Clash for Magisk
id=ClashForKernelSU
name=Clash for KernelSU
version=v2.5.1
versionCode=20221201
author=t🌸amarin
author=t🌸amarin,Dreamail
description= Use iptables to support Clash's transparent proxy. Hey, damn half-crippled Android!!!
updateJson=https://github.com/taamarin/ClashforMagisk/raw/master/update.json
#updateJson=https://github.com/taamarin/ClashforMagisk/raw/master/update.json
2 changes: 1 addition & 1 deletion scripts/clash.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/system/bin/sh

# busybox path
busybox_path="/data/adb/magisk/busybox"
busybox_path="/data/clash/tools/busybox"
ipv6=$(grep "ipv6" /data/clash/template | ${busybox_path} awk -F ': ' '{print $2}' | head -1)

run_usage="false"
Expand Down
2 changes: 1 addition & 1 deletion scripts/clash.service
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ start_clash() {
replace_kernel
echo $(date) > $CFM_logs_file
echo "$(${Clash_bin_path} -v)" >> $CFM_logs_file
echo "Clash for Magisk v2.5.1" > /dev/null
echo "Clash for KernelSU v2.5.1" > /dev/null
echo "CPU: % | RES: kb" >> $CFM_logs_file
echo "━━━━━━━━━━━━━━━━━━━━━━━━━" >> $CFM_logs_file
if [ "${ipv6}" = "false" ] ; then
Expand Down
8 changes: 2 additions & 6 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#!/system/bin/sh

moddir="/data/adb/modules/ClashForMagisk"
if [ -n "$(magisk -v | grep lite)" ]
then
moddir=/data/adb/lite_modules/ClashForMagisk
fi
moddir="/data/adb/ksu/modules/ClashForKernelSU"

scripts_dir="/data/clash/scripts"
busybox_path="/data/adb/magisk/busybox"
busybox_path="/data/clash/tools/busybox"
Clash_run_path="/data/clash/run"
Clash_pid_file="${Clash_run_path}/clash.pid"

Expand Down
4 changes: 3 additions & 1 deletion scripts/usage.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/system/bin/sh

busybox_path="/data/clash/tools/busybox"

getmemory(){
clash_pid=$(cat /data/clash/run/clash.pid)
clash_alive=$(grep VmRSS /proc/${clash_pid}/status | /data/adb/magisk/busybox awk -F':' '{print $2}' | /data/adb/magisk/busybox awk '{print $1}')
clash_alive=$(grep VmRSS /proc/${clash_pid}/status | ${busybox_path} awk -F':' '{print $2}' | ${busybox_path} awk '{print $1}')
if [ ${clash_alive} -ge 1024 ]
then
clash_res="$(expr ${clash_alive} / 1024)Mb"
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Clash_data_dir="/data/clash"

rm_data() {
rm -rf ${Clash_data_dir}
rm -rf /data/adb/service.d/clash_service.sh
}

rm_data
Expand Down

0 comments on commit c025ede

Please sign in to comment.