Skip to content

Commit 8affe51

Browse files
sheynswtaamarin
authored andcommitted
update:
+ delete template for Clash + add dashboard files + add readme_en.md + modified iptables script with some improvements + improve box_service.sh, and customize.sh + fix: update kernel + optimize BFM script
1 parent fc0e3b5 commit 8affe51

File tree

25 files changed

+1786
-1191
lines changed

25 files changed

+1786
-1191
lines changed

.github/workflows/del.yml

100644100755
File mode changed.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Box for Magisk
22

3-
[README ID](index_id.md) || [README EN](index_en.md)
3+
[README ID](index_id.md) || [README EN](index_en.md) || [README CN](index_cn.md)
44

55
[![ANDROID](https://img.shields.io/badge/Android-3DDC84?style=for-the-badge&logo=android&logoColor=white)]()
6+
[![RELEASES](https://img.shields.io/github/downloads/taamarin/box_for_magisk/total.svg?style=for-the-badge)](https://github.com/taamarin/box_for_magisk/releases)
67

78
A fork of [CHIZI-0618/box4magisk](https://github.com/CHIZI-0618/box4magisk)
89

binary/arm.tar.bz2

2.2 MB
Binary file not shown.

binary/arm64.tar.bz2

2.2 MB
Binary file not shown.

box_service.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/system/bin/sh
22

33
(
4-
until [ $(getprop init.svc.bootanim) = "stopped" ] ; do
5-
sleep 3
6-
done
4+
until [ $(getprop init.svc.bootanim) = "stopped" ]; do
5+
sleep 3
6+
done
77

8-
chmod 755 /data/adb/box/scripts/start.sh
9-
/data/adb/box/scripts/start.sh
8+
if [ -f "/data/adb/box/scripts/start.sh" ]; then
9+
chmod 755 /data/adb/box/scripts/*
10+
/data/adb/box/scripts/start.sh
11+
else
12+
echo "File '/data/adb/box/scripts/start.sh' not found"
13+
fi
1014
)&

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
zip -r -o -X -ll box_for_magisk-$(cat module.prop | grep 'version=' | awk -F '=' '{print $2}').zip ./ -x '.git/*' -x 'index_id.md' -x 'CHANGELOG.md' -x 'update.json' -x 'build.sh' -x '.github/*'
3+
zip -r -o -X -ll box_for_magisk-$(cat module.prop | grep 'version=' | awk -F '=' '{print $2}').zip ./ -x '.git/*' -x 'index_id.md' -x 'index_en.md' -x 'CHANGELOG.md' -x 'update.json' -x 'build.sh' -x '.github/*'

customize.sh

Lines changed: 129 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,25 @@ else
2727
ui_print "- Device sdk: $API"
2828
fi
2929

30-
# check architecture
31-
if [ "$ARCH" != "arm" ] && [ "$ARCH" != "arm64" ] && [ "$ARCH" != "x86" ] && [ "$ARCH" != "x64" ]; then
32-
abort "! Unsupported platform: $ARCH"
33-
else
34-
ui_print "- Device platform: $ARCH"
35-
fi
30+
ui_print "- check architecture"
31+
case $ARCH in
32+
arm|arm64|x86|x64)
33+
ui_print "- Device platform: $ARCH"
34+
;;
35+
*)
36+
abort "! Unsupported platform: $ARCH"
37+
;;
38+
esac
3639

3740
ui_print "- Installing Box for Magisk"
3841

3942
if [ -d "/data/adb/box" ] ; then
4043
ui_print "- Backup box"
41-
mkdir -p /data/adb/box/${latest}
42-
mv /data/adb/box/* /data/adb/box/${latest}/
44+
mkdir -p "/data/adb/box/${latest}"
45+
mv /data/adb/box/* "/data/adb/box/${latest}/"
4346
fi
4447

48+
ui_print "- Set architecture ${ARCH}"
4549
case "${ARCH}" in
4650
arm)
4751
architecture="armv7"
@@ -55,71 +59,133 @@ case "${ARCH}" in
5559
x64)
5660
architecture="amd64"
5761
;;
62+
*)
63+
abort "Error: Unsupported architecture ${ARCH}"
64+
;;
5865
esac
5966

60-
ui_print "- Mkdir BFM folder"
61-
mkdir -p ${MODPATH}/system/bin
62-
mkdir -p ${MODPATH}/system/etc/security/cacerts
63-
mkdir -p /data/adb/box
64-
mkdir -p /data/adb/box/bin
65-
mkdir -p /data/adb/box/dashboard
66-
mkdir -p /data/adb/box/run
67-
mkdir -p /data/adb/box/scripts
68-
mkdir -p /data/adb/box/xray
69-
mkdir -p /data/adb/box/v2fly
70-
mkdir -p /data/adb/box/sing-box
71-
mkdir -p /data/adb/box/clash
72-
73-
ui_print "- Extracting BFM files"
74-
unzip -o "${ZIPFILE}" -x 'META-INF/*' -d ${MODPATH} >&2
75-
unzip -j -o "${ZIPFILE}" 'uninstall.sh' -d ${MODPATH} >&2
67+
ui_print "- Create directories"
68+
mkdir -p "${MODPATH}/system/bin"
69+
mkdir -p "${MODPATH}/system/etc/security/cacerts"
70+
mkdir -p "/data/adb/box"
71+
mkdir -p "/data/adb/box/bin"
72+
mkdir -p "/data/adb/box/run"
73+
mkdir -p "/data/adb/box/scripts"
74+
mkdir -p "/data/adb/box/xray"
75+
mkdir -p "/data/adb/box/v2fly"
76+
mkdir -p "/data/adb/box/sing-box"
77+
mkdir -p "/data/adb/box/clash"
78+
mkdir -p "/data/adb/box/dashboard"
79+
mkdir -p "/data/adb/box/clash/dashboard"
80+
mkdir -p "/data/adb/box/sing-box/dashboard"
81+
82+
ui_print "- Extract the ZIP file and skip the META-INF folder into the ${MODPATH} folder"
83+
unzip -o "${ZIPFILE}" -x 'META-INF/*' -d "${MODPATH}" >&2
84+
85+
ui_print "- Extract the files uninstall.sh and box_service.sh into the ${MODPATH} folder and /data/adb/service.d"
86+
unzip -j -o "${ZIPFILE}" 'uninstall.sh' -d "${MODPATH}" >&2
7687
unzip -j -o "${ZIPFILE}" 'box_service.sh' -d /data/adb/service.d >&2
77-
tar -xjf ${MODPATH}/binary/${ARCH}.tar.bz2 -C ${MODPATH}/system/bin >&2
78-
79-
ui_print "- Create resolv.conf"
80-
if [ ! -f "/system/etc/resolv.conf" ] ; then
81-
touch ${MODPATH}/system/etc/resolv.conf
82-
echo nameserver 8.8.8.8 > ${MODPATH}/system/etc/resolv.conf
83-
echo nameserver 9.9.9.9 >> ${MODPATH}/system/etc/resolv.conf
84-
echo nameserver 1.1.1.1 >> ${MODPATH}/system/etc/resolv.conf
85-
echo nameserver 149.112.112.112 >> ${MODPATH}/system/etc/resolv.conf
86-
fi
88+
89+
ui_print "- Extract the files from the binary archive and copy them to the /system/bin and /data/adb/box/bin"
90+
tar -xjf "${MODPATH}/binary/${ARCH}.tar.bz2" -C "${MODPATH}/system/bin" >&2
91+
tar -xjf "${MODPATH}/binary/${ARCH}.tar.bz2" "mlbox" -C /data/adb/box/bin >&2
92+
93+
ui_print "- Extract the dashboard.zip file to the folder /data/adb/box/clash/dashboard and /data/adb/box/sing-box/dashboard"
94+
unzip -o "${MODPATH}/dashboard.zip" -d /data/adb/box/dashboard/ >&2
95+
unzip -o "${MODPATH}/dashboard.zip" -d /data/adb/box/clash/dashboard/ >&2
96+
unzip -o "${MODPATH}/dashboard.zip" -d /data/adb/box/sing-box/dashboard/ >&2
97+
98+
ui_print ""
99+
ui_print "--------------------------------------------------------"
100+
ui_print "- Are you going to create a resolve.conf file?"
101+
ui_print "- Press Vol Up: to create the resolve.conf file."
102+
ui_print "- Press Vol Down: to ignore the resolve.conf file."
103+
while true ; do
104+
getevent -lc 1 2>&1 | grep KEY_VOLUME > $TMPDIR/events
105+
sleep 1
106+
if $(cat $TMPDIR/events | grep -q KEY_VOLUMEUP) ; then
107+
ui_print "- Create a resolve.conf file if it doesn't already exist and add server nameservers."
108+
if [ ! -f "/data/adb/modules/box_for_magisk/system/etc/resolv.conf" ]; then
109+
cat > "${MODPATH}/system/etc/resolv.conf" <<EOF
110+
nameserver 8.8.8.8
111+
nameserver 1.1.1.1
112+
nameserver 9.9.9.9
113+
nameserver 94.140.14.14
114+
EOF
115+
ui_print "[+] /data/adb/modules/box_for_magisk/system/etc/resolv.conf"
116+
ui_print "[+] nameserver 8.8.8.8"
117+
ui_print "[+] nameserver 1.1.1.1"
118+
ui_print "[+] nameserver 9.9.9.9"
119+
ui_print "[+] nameserver 94.140.14.14"
120+
fi
121+
break
122+
elif $(cat $TMPDIR/events | grep -q KEY_VOLUMEDOWN) ; then
123+
ui_print "- ignore creating file resolve.conf"
124+
break
125+
fi
126+
done
87127

88128
ui_print "- Move BFM files"
89-
mv ${MODPATH}/scripts/cacert.pem ${MODPATH}/system/etc/security/cacerts
90-
mv ${MODPATH}/scripts/bin/mlbox /data/adb/box/bin/
91-
mv ${MODPATH}/scripts/src/* /data/adb/box/scripts/
92-
mv ${MODPATH}/scripts/clash/* /data/adb/box/clash/
93-
mv ${MODPATH}/scripts/settings.ini /data/adb/box/
94-
mv ${MODPATH}/scripts/template.yml /data/adb/box/
95-
mv ${MODPATH}/scripts/xray /data/adb/box/
96-
mv ${MODPATH}/scripts/v2fly /data/adb/box/
97-
mv ${MODPATH}/scripts/sing-box /data/adb/box/
129+
mv "$MODPATH/scripts/cacert.pem" "$MODPATH/system/etc/security/cacerts"
130+
mv "$MODPATH/scripts/src/"* "/data/adb/box/scripts/"
131+
mv "$MODPATH/scripts/clash/"* "/data/adb/box/clash/"
132+
mv "$MODPATH/scripts/settings.ini" "/data/adb/box/"
133+
mv "$MODPATH/scripts/xray" "/data/adb/box/"
134+
mv "$MODPATH/scripts/v2fly" "/data/adb/box/"
135+
mv "$MODPATH/scripts/sing-box" "/data/adb/box/"
98136

99137
ui_print "- Delete leftover files"
100-
rm -rf ${MODPATH}/scripts
101-
rm -rf ${MODPATH}/binary
102-
rm -rf ${MODPATH}/box_service.sh
138+
rm -rf "${MODPATH}/scripts"
139+
rm -rf "${MODPATH}/binary"
140+
rm -f "${MODPATH}/box_service.sh"
141+
rm -f "${MODPATH}/dashboard.zip"
103142
sleep 1
143+
104144
ui_print "- Setting permissions"
105-
set_perm_recursive ${MODPATH} 0 0 0755 0644
106-
set_perm_recursive /data/adb/box/ 0 3005 0755 0644
107-
set_perm_recursive /data/adb/box/scripts/ 0 3005 0755 0700
108-
set_perm_recursive /data/adb/box/dashboard/ 0 3005 0755 0700
109-
set_perm /data/adb/service.d/box_service.sh 0 0 0755
110-
set_perm ${MODPATH}/service.sh 0 0 0755
111-
set_perm ${MODPATH}/uninstall.sh 0 0 0755
112-
set_perm ${MODPATH}/system/etc/security/cacerts/cacert.pem 0 0 0644
113-
set_perm /data/adb/box/bin/mlbox 0 0 0755
114-
set_perm /data/adb/box/scripts/box.service 0 0 0755
115-
set_perm /data/adb/box/scripts/box.tool 0 0 0755
116-
set_perm /data/adb/box/scripts/start.sh 0 0 0755
117-
set_perm /data/adb/box/scripts/box.iptables 0 0 0755
118-
set_perm /data/adb/box/scripts/box.inotify 0 0 0755
119-
120-
chmod ugo+x /data/adb/box/bin/*
121-
chmod ugo+x ${MODPATH}/system/bin/*
145+
set_perm_recursive "${MODPATH}" 0 0 0755 0644
146+
set_perm_recursive "/data/adb/box/" 0 3005 0755 0644
147+
set_perm_recursive "/data/adb/box/scripts/" 0 3005 0755 0700
148+
set_perm "/data/adb/service.d/box_service.sh" 0 0 0755
149+
set_perm "${MODPATH}/service.sh" 0 0 0755
150+
set_perm "${MODPATH}/uninstall.sh" 0 0 0755
151+
set_perm "${MODPATH}/system/etc/security/cacerts/cacert.pem" 0 0 0644
152+
set_perm ${MODPATH}/system/bin/curl 0 0 0755
153+
154+
set_perm /data/adb/box/scripts/box.inotify 0 0 0755
155+
set_perm /data/adb/box/scripts/box.service 0 0 0755
156+
set_perm /data/adb/box/scripts/box.iptables 0 0 0755
157+
set_perm /data/adb/box/scripts/box.tool 0 0 0755
158+
set_perm /data/adb/box/scripts/start.sh 0 0 0755
159+
set_perm /data/adb/box/bin/mlbox 0 0 0755
160+
161+
sleep 1
162+
163+
ui_print ""
164+
ui_print "--------------------------------------------------------"
165+
ui_print "- Have you downloaded KERNEL and GEOX?"
166+
ui_print "- Make sure you have a good internet connection."
167+
ui_print "- Press Vol Up: to download GEOX and KERNEL."
168+
ui_print "- Press Vol Down: to ignore downloading GEOX and KERNEL."
169+
while true ; do
170+
getevent -lc 1 2>&1 | grep KEY_VOLUME > $TMPDIR/events
171+
sleep 1
172+
if $(cat $TMPDIR/events | grep -q KEY_VOLUMEUP) ; then
173+
ui_print "- it will take a while...."
174+
if [ ! -f /data/adb/box/run/box.pid ]; then
175+
/data/adb/box/scripts/box.tool all && echo "- downloads are complete."
176+
else
177+
ui_print " - BFM service is still running, Cannot update geo and kernel, as it will cause conflicts"
178+
ui_print " - Download manually after reboot is complete"
179+
fi
180+
break
181+
elif $(cat $TMPDIR/events | grep -q KEY_VOLUMEDOWN) ; then
182+
ui_print "- ignore download GEOX and KERNEL"
183+
break
184+
fi
185+
done
186+
122187
ui_print "- Installation is complete, reboot your device"
188+
ui_print ""
123189
ui_print " --- Notes --- "
124190
ui_print "[+] report issues to @taamarin on Telegram"
125191
ui_print "[+] Join @taamarin on telegram to get more updates"

dashboard.zip

343 KB
Binary file not shown.

index_en.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
## WARNING
2+
This project is not responsible for: damaged devices, damaged SD cards, or burnt SoCs.
3+
4+
**Make sure your configuration file does not cause traffic loopback, otherwise it may cause your phone to restart endlessly.**
5+
6+
If you really don't know how to configure this module, you may need an application like ClashForAndroid, v2rayNG, Surfboard, SagerNet, AnXray, etc.
7+
8+
## Installation
9+
- Download the module zip package from RELEASE and install it via MAGISK. Then reboot.
10+
- Make sure you are connected to the internet, and execute the following command to download binaries etc:
11+
```shell
12+
su -c /data/adb/box/scripts/box.tool upyacd
13+
```
14+
```shell
15+
su -c /data/adb/box/scripts/box.tool subgeo
16+
```
17+
```shell
18+
su -c /data/adb/box/scripts/box.tool upcore
19+
```
20+
21+
- Support for the next online module update in Magisk Manager (updating the module will take effect without rebooting).
22+
23+
### Notes
24+
This module includes:
25+
- [clash](https://github.com/Dreamacro/clash)
26+
- [clash.meta](https://github.com/MetaCubeX/Clash.Meta)[sing-box](https://github.com/SagerNet/sing-box)
27+
- [v2ray-core](https://github.com/v2fly/v2ray-core)
28+
- [Xray-core](https://github.com/XTLS/Xray-core).
29+
- [sing-box]().
30+
31+
After installing the module, download the appropriate core file for your device's architecture and place it in the /data/adb/box/bin/ directory, or execute:
32+
33+
```shell
34+
su -c /data/adb/box/scripts/box.tool upcore
35+
```
36+
37+
## konfigurasi
38+
- bin_name:
39+
- clash
40+
- xray
41+
- v2ray
42+
- sing-box
43+
44+
- Each core works in the directory `/data/adb/box/bin/${bin_name}`, and the core name is determined by `bin_name` in the file `BFM`.
45+
- Each core configuration file needs to be customized by the user, and the scripts will check the validity of the configuration, and the check result will be saved in the file `/data/adb/box/run/runs.log.`
46+
- Tip: `clash` and `sing-box` come with ready-to-work default configurations with the transparent proxy script. For further configuration, see the official documentation. Address: [dokumen clash](https://github.com/Dreamacro/clash/wiki/configuration), [dokumen sing-box](https://sing-box.sagernet.org/configuration/outbound/)
47+
48+
49+
## Instructions
50+
### Conventional method (standard & recommended method)
51+
#### Start and stop management services
52+
**Layanan inti berikut secara kolektif disebut sebagai `BFM`**
53+
- The following core services are collectively referred to as `BFM`
54+
- You can enable or disable the module through the Magisk Manager application **in real time** to start or stop the `BFM` service, **without restarting the device**. Starting the service may take a few seconds, and stopping the service can take effect immediately.
55+
56+
#### Select applications (APPs) that require proxy
57+
- `BFM` defaults to proxying all applications (APPs) for all Android users.
58+
- If you want `BFM` to proxy all applications (APP), except for certain ones, please open the file `/data/adb/box/settings.ini` and change the value of `proxy_mode` to `blacklist` (default), add packages to `packages_list`, for example: `packages_list=("com.termux" "org.telegram.messenger")`
59+
- Use `whitelist` if you only want to proxy certain applications (APP).
60+
- When the value of `proxy_mode` is `core/tun`, transparent proxy will not work, only the corresponding kernel will start, which can be used to support TUN, currently only `clash` and `sing-box` are available.
61+
62+
### Advanced usage
63+
#### Changing proxy mode
64+
- `BFM` uses `TPROXY` to transparently proxy TCP + UDP (default). If it detects that the device does not support TPROXY, open `/data/adb/box/settings.ini` and change `network_mode="redirect"` to use `redirect` for TCP proxy only.
65+
- Open the file `/data/adb/box/settings.ini`, change the value of network_mode to redirect, tproxy, or mixed.
66+
- redirect: `redirec TCP only.`
67+
- tproxy: `tproxy TCP + UDP.`
68+
- mixed: `redirec TCP + tun UDP.`
69+
70+
#### Bypass transparent proxy when connecting to Wi-Fi or hotspot
71+
- `BFM` transparently proxies localhost and hotspot (including USB tethering) by default.
72+
- Open the file `/data/adb/box/settings.ini`, modify `ignore_out_list` and add `wlan+`, then transparent proxy will bypass wlan, and hotspot won't connect to the proxy.
73+
- Open the file `/data/adb/box/settings.ini`, modify `ap_list` and add `wlan+`. `BFM` will proxy the hotspot (for MediaTek devices, it may be ap+ / wlan+).
74+
- Use the ifconfig command in the terminal to find out the name of the AP.
75+
76+
#### Enter manual mode
77+
- If you want to fully control `BFM` by running commands, just create a new file `/data/adb/box/manual`. In this case, the `BFM` service will not start automatically when your device is turned on, and you also cannot set the start or stop of the service through the Magisk Manager app.
78+
79+
#### Starting and stopping the management service
80+
The `BFM` service script is /data/adb/box/scripts/box.service
81+
82+
- Start `BFM`:
83+
```shell
84+
su -c /data/adb/box/scripts/box.service start
85+
```
86+
- Stop `BFM`:
87+
```shell
88+
su -c /data/adb/box/scripts/box.service stop
89+
```
90+
91+
- The terminal will print logs and output them to a log file simultaneously.
92+
93+
#### Manage whether transparent proxy is enabled
94+
- The transparent proxy script is `/data/adb/box/scripts/box.tproxy`
95+
96+
- Enable transparent proxy:
97+
```shell
98+
su -c /data/adb/box/scripts/box.tproxy enable
99+
```
100+
101+
- Disable transparent proxy:
102+
```shell
103+
su -c /data/adb/box/scripts/box.tproxy disable
104+
```
105+
106+
## Other instructions
107+
- When modifying any of the core configuration files, please ensure that the tproxy related configurations are consistent with the definitions in the `/data/adb/box/settings.ini` file.
108+
- If the machine has a **public IP address**, add the IP to the intranet in the `/data/adb/box/settings.ini` file to prevent traffic loops.
109+
- Logs for the `BFM` service can be found in the `/data/adb/box/run` directory.
110+
111+
112+
## Uninstall
113+
- Removing the installation of this module from Magisk Manager will remove `/data/adb/service.d/box_service.sh` and keep the `BFM` data directory at /data/adb/box.
114+
- You can use the following commands to remove the `BFM` data:
115+
116+
```shell
117+
su -c rm -rf /data/adb/box
118+
```
119+
```shell
120+
su -c rm -rf /data/adb/service.d/box_service.sh
121+
```
122+
123+
## CHANGELOG
124+
[CHANGELOG](CHANGELOG.md)

index_id.md

100644100755
File mode changed.

0 commit comments

Comments
 (0)