Skip to content

Commit

Permalink
Suport KernelSU
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamail committed Jan 16, 2023
1 parent 4e37a5a commit 5fbc3a9
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 100 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 [14-15](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L14-#L15), 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 [14-15](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L14-#L15), 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 [17-21](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L17-#L21)
Clash default transparent proxy local and hotspot, line [17-21](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L17-#L21)

- 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 [11-12](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L11-#L12)
- clash.config line [11-12](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L11-#L12)
- `blacklist` & `whitelits`, not working on `fake-ip`

- dns:
Expand All @@ -87,7 +84,7 @@ Clash default transparent proxy local and hotspot, line [17-21](https://github.c
##### subscription
you can use SubScription
- open `/data/clash/clash.config` line [29-34](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L29-#L34)
- open `/data/clash/clash.config` line [29-34](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L29-#L34)
- 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 [36-37](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L36-#L37), If true,
- **clash.config** line [36-37](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L36-#L37), 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 [79-103](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L79-#L103)
you can download the Kernel automatically, for the settings in the **clash.config** line [79-103](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L79-#L103)
```shell
${MODDIR}/scripts/clash.tool -k
```

##### GeoSite, GeoIP, and Mmdb
- settings are in clash.config line [105-116](https://github.com/taamarin/ClashforMagisk/blob/master/scripts/clash.config#L105-#L116)
- settings are in clash.config line [105-116](https://github.com/Dreamail/ClashforKernelSU/blob/master/scripts/clash.config#L105-#L116)
- 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/*'
27 changes: 8 additions & 19 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,27 @@ 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; then
ui_print "- Installing from Magisk app"
ui_print "- Installing from KernelSU manager"
else
ui_print "*********************************************************"
ui_print "! Install from recovery is NOT supported"
ui_print "! Some recovery has broken implementations, install with such recovery will finally cause CFM modules not working"
ui_print "! Please install from Magisk app"
ui_print "! Please install from KernelSU manager"
abort "*********************************************************"
fi

# check Magisk
ui_print "- Magisk version: $MAGISK_VER ($MAGISK_VER_CODE)"

# check android
if [ "$API" -lt 19 ]; then
ui_print "! Unsupported sdk: $API"
Expand All @@ -47,7 +42,7 @@ else
ui_print "- Device platform: $ARCH"
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 @@ -63,6 +58,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 @@ -99,11 +95,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 @@ -120,7 +111,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 @@ -129,6 +119,7 @@ mv ${clash_data_dir_kernel}/getpcaps ${MODPATH}${bin_path}/
mv ${clash_data_dir_kernel}/getcap ${MODPATH}${bin_path}/
mv ${clash_data_dir}/scripts/clash.config ${clash_data_dir}/
mv ${clash_data_dir}/scripts/dnstt/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 @@ -140,7 +131,6 @@ 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}/scripts/dnstt
rm -rf ${clash_data_dir_kernel}/curl
Expand All @@ -149,7 +139,6 @@ 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 @@ -172,6 +161,6 @@ set_perm ${clash_data_dir}/scripts/start.sh 0 0 0755
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/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=v3.0
versionCode=20230113
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
Expand Up @@ -2,7 +2,7 @@

# busybox path
now=$(date +"%I.%M %p")
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 @@ -152,7 +152,7 @@ start_clash() {
replace_kernel
echo $(date) > ${CFM_logs_file}
echo "$(${Clash_bin_path} -v)" >> ${CFM_logs_file}
echo "Clash for Magisk v3.0" > /dev/null
echo "Clash for KernelSU v3.0" > /dev/null
echo "CPU: % | RES: kb" >> ${CFM_logs_file}
echo "━━━━━━━━━━━━━━━━━━━━━━━━━" >> ${CFM_logs_file}
if [ "${ipv6}" = "false" ] ; then
Expand Down
12 changes: 6 additions & 6 deletions scripts/clash.tool
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ update_file() {
if [ -f ${file} ] ; then
mv -f ${file} ${file_bak}
fi
echo "/data/adb/magisk/busybox wget --no-check-certificate ${update_url} -o ${file}"
/data/adb/magisk/busybox wget --no-check-certificate ${update_url} -O ${file} 2>&1
echo "${busybox_path} wget --no-check-certificate ${update_url} -o ${file}"
${busybox_path} wget --no-check-certificate ${update_url} -O ${file} 2>&1
sleep 0.5
if [ -f "${file}" ] ; then
echo ""
Expand Down Expand Up @@ -110,15 +110,15 @@ port_detection() {
update_kernel() {
if [ "${use_premium}" == "false" ] ; then
if [ "${meta_alpha}" == "false" ] ; then
tag_meta=$(/data/adb/magisk/busybox wget --no-check-certificate -qO- ${url_meta} | grep -oE "v[0-9]+\.[0-9]+\.[0-9]+" | head -1)
tag_meta=$(${busybox_path} wget --no-check-certificate -qO- ${url_meta} | grep -oE "v[0-9]+\.[0-9]+\.[0-9]+" | head -1)
filename="${file_kernel}-${platform}-${arch}-${tag_meta}"
update_file "${Clash_data_dir}/${file_kernel}.gz" "${url_meta}/download/${tag_meta}/${filename}.gz"
if [ "$?" = "0" ]
then
flag=false
fi
else
tag_meta=$(/data/adb/magisk/busybox wget --no-check-certificate -qO- ${url_meta}/expanded_assets/${tag} | grep -oE "${tag_name}" | head -1)
tag_meta=$(${busybox_path} wget --no-check-certificate -qO- ${url_meta}/expanded_assets/${tag} | grep -oE "${tag_name}" | head -1)
filename="${file_kernel}-${platform}-${arch}-${tag_meta}"
update_file "${Clash_data_dir}/${file_kernel}.gz" "${url_meta}/download/${tag}/${filename}.gz"
if [ "$?" = "0" ]
Expand All @@ -127,7 +127,7 @@ update_kernel() {
fi
fi
else
filename=$(/data/adb/magisk/busybox wget --no-check-certificate -qO- "${url_premium}/expanded_assets/premium" | grep -oE "clash-${platform}-${arch}-[0-9]+.[0-9]+.[0-9]+" | head -1)
filename=$(${busybox_path} wget --no-check-certificate -qO- "${url_premium}/expanded_assets/premium" | grep -oE "clash-${platform}-${arch}-[0-9]+.[0-9]+.[0-9]+" | head -1)
update_file "${Clash_data_dir}/${file_kernel}.gz" "${url_premium}/download/premium/${filename}.gz"
if [ "$?" = "0" ] ; then
flag=false
Expand Down Expand Up @@ -198,7 +198,7 @@ update_dashboard () {
file_dasboard="${Clash_data_dir}/dashboard.zip"
rm -rf ${Clash_data_dir}/dashboard/dist

/data/adb/magisk/busybox wget --no-check-certificate ${url_dashboard} -o ${file_dasboard} 2>&1
${busybox_path} wget --no-check-certificate ${url_dashboard} -o ${file_dasboard} 2>&1
unzip -o "${file_dasboard}" "yacd-gh-pages/*" -d ${Clash_data_dir}/dashboard >&2
mv -f ${Clash_data_dir}/dashboard/yacd-gh-pages ${Clash_data_dir}/dashboard/dist
rm -rf ${file_dasboard}
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(){
local 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"
else
Expand Down
File renamed without changes.
Loading

0 comments on commit 5fbc3a9

Please sign in to comment.