#!/system/bin/sh

SETTING_START_PARAMSET="working_folder/params"

setenforce 0
/system/bin/am start -a android.intent.action.MAIN -e toasttext "Подготовка к перезагрузке сервиса..." -n bellavita.toast/.MainActivity

sleep 3
/system/bin/am start -a android.intent.action.MAIN -e toasttext "Очистка таблицы iptables mangle" -n bellavita.toast/.MainActivity
iptables -t mangle -F

/system/bin/am start -a android.intent.action.MAIN -e toasttext "Останавливаю уже запущенные сервисы" -n bellavita.toast/.MainActivity
# Ищем процесс dpi-tunnel.sh и убиваем его
PID=$(ps -ef | grep 'ZDT-D' | awk '{print $2}')
if [ -n "$PID" ]; then
echo "Процесс ZDT-D найден, убиваем его (PID: $PID)..."
kill -9 $PID
echo "Процесс убит."
else
echo "Процесс ZDT-D не найден."
fi
# Ищем процесс nfqws и убиваем его
PID=$(ps -ef | grep 'nfqws' | awk '{print $2}')
if [ -n "$PID" ]; then
echo "Процесс nfqws найден, убиваем его (PID: $PID)..."
kill -9 $PID
echo "Процесс убит."
else
echo "Процесс nfqws не найден."
fi
# Ищем процесс dpitunnel-cli и убиваем его
PID=$(ps -ef | grep 'dpitunnel-cli' | awk '{print $2}')
if [ -n "$PID" ]; then
echo "Процесс dpitunnel-cli найден, убиваем его (PID: $PID)..."
kill -9 $PID
echo "Процесс убит."
else
echo "Процесс dpitunnel-cli не найден."
fi

sleep 3
/system/bin/am start -a android.intent.action.MAIN -e toasttext "Запускаю zapret" -n bellavita.toast/.MainActivity

nfqws --uid=0:0 --qnum=200 --filter-tcp=80 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/netrogat.txt --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/netrogat.txt --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-youtubeQ.txt --dpi-desync=fake --dpi-desync-repeats=2 --dpi-desync-cutoff=n2 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_pl_by_ori.bin --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-youtubeGV.txt --dpi-desync=split --dpi-desync-split-pos=1 --dpi-desync-fooling=badseq --dpi-desync-repeats=10 --dpi-desync-autottl --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-youtube.txt --dpi-desync=fake,split2 --dpi-desync-split-seqovl=2 --dpi-desync-split-pos=2 --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_www_google_com.bin --dpi-desync-autottl --new --filter-tcp=80 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-blacklist.txt --dpi-desync=fake,split2 --dpi-desync-fooling=badseq --dpi-desync-autottl --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-blacklist.txt --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/myhostlist.txt --dpi-desync=fake,split2 --dpi-desync-split-seqovl=1 --dpi-desync-split-pos=2 --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_www_google_com.bin --dpi-desync-skip-nosni=1 --dpi-desync-autottl --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-discord.txt --dpi-desync=fake --dpi-desync-udplen-increment=10 --dpi-desync-repeats=7 --dpi-desync-udplen-pattern=0xDEADBEEF --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_pl_by_ori.bin --dpi-desync-cutoff=n2 --new --filter-udp=50000-50200 --dpi-desync=fake --dpi-desync-any-protocol --dpi-desync-cutoff=d2 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_pl_by_ori.bin --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-discord.txt --dpi-desync=fake,disorder2 --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_www_google_com.bin --dpi-desync-split-pos=1 --dpi-desync-fooling=md5sig --dpi-desync-repeats=10 --dpi-desync-autottl --new --filter-tcp=443 --hostlist-auto=/data/adb/modules/ZDT-D/autohostlist.txt --hostlist-exclude=/data/adb/modules/ZDT-D/working_folder/bin/netrogat.txt --dpi-desync=split --dpi-desync-split-pos=1 --dpi-desync-fooling=badseq --dpi-desync-repeats=10 --dpi-desync-autottl --new --filter-tcp=80 --dpi-desync=fake,split2 --dpi-desync-autottl=2 --dpi-desync-fooling=md5sig --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/ips.txt --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/ips.txt --dpi-desync=fake,split2 --dpi-desync-repeats=11 --dpi-desync-fooling=md5sig --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_www_google_com.bin --new --filter-tcp=80,443 --dpi-desync=fake,disorder2 --dpi-desync-repeats=6 --dpi-desync-autottl=2 --dpi-desync-fooling=md5sig --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/ips.txt --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/ips.txt --dpi-desync=fake --dpi-desync-repeats=11 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_initial_www_google_com.bin --new --filter-udp=443 --dpi-desync=fake --dpi-desync-repeats=11 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/ips.txt --new --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_sberbank_ru.bin --new --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_initial_facebook_com.bin --new --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_vk_com.bin --new --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_rutracker_org_kyber.bin --new --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_initial_rutracker_org_kyber_1.bin --new --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_initial_rr2---sn-gvnuxaxjvh-o8ge_googlevideo_com.bin --new --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/dht_find_node.bin --new --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/dtls_clienthello_w3_org.bin --new --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_iana_org.bin --new --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/zero_1024.bin --new --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/wireguard_response.bin --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/Instagram.list.txt --dpi-desync=fake --dpi-desync-repeats=2 --dpi-desync-cutoff=n2 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_1.bin --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/Instagram.list.txt --dpi-desync=fake --dpi-desync-repeats=2 --dpi-desync-cutoff=n2 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_2.bin --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/Instagram.list.txt --dpi-desync=fake --dpi-desync-repeats=2 --dpi-desync-cutoff=n2 --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_1.bin --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/Instagram.list.txt --dpi-desync=fake --dpi-desync-repeats=2 --dpi-desync-cutoff=n2 --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_2.bin --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/Instagram.list.txt --dpi-desync=fake --dpi-desync-repeats=2 --dpi-desync-cutoff=n2 --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_3.bin --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/discord.txt --dpi-desync=fake --dpi-desync-repeats=6 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_initial_www_google_com.bin --new --filter-udp=443 --ipset=/data/adb/modules/ZDT-D/working_folder/bin/ipset-discord.txt --dpi-desync=fake --dpi-desync-any-protocol --dpi-desync-cutoff=d3 --dpi-desync-repeats=6 --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/discord.txt --dpi-desync=fake,split --dpi-desync-autottl=2 --dpi-desync-repeats=6 --dpi-desync-fooling=badseq --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_www_google_com.bin --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/general.txt --dpi-desync=fake --dpi-desync-repeats=6 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_initial_www_google_com.bin --new --filter-tcp=80 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/general.txt --dpi-desync=fake,split2 --dpi-desync-autottl=2 --dpi-desync-fooling=md5sig --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/general.txt --dpi-desync=fake,split --dpi-desync-autottl=2 --dpi-desync-repeats=6 --dpi-desync-fooling=badseq --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_www_google_com.bin --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/general.txt --dpi-desync=fake --dpi-desync-repeats=6 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_initial_www_google_com.bin --new --filter-udp=50000-50100 --ipset=/data/adb/modules/ZDT-D/working_folder/bin/ipset-discord.txt --dpi-desync=fake --dpi-desync-any-protocol --dpi-desync-cutoff=d3 --dpi-desync-repeats=6 --new --filter-tcp=80 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/general.txt --dpi-desync=fake,split2 --dpi-desync-autottl=2 --dpi-desync-fooling=md5sig --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/general.txt --dpi-desync=split2 --dpi-desync-split-seqovl=652 --dpi-desync-split-pos=2 --dpi-desync-split-seqovl-pattern=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_www_google_com.bin --new --filter-l3=ipv4 --filter-tcp=443 --dpi-desync=syndata --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/general.txt --dpi-desync=fake --dpi-desync-repeats=6 --dpi-desync-fooling=md5sig --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_www_google_com.bin --new --dpi-desync=fake,disorder2 --dpi-desync-split-pos=1 --dpi-desync-ttl=6 --dpi-desync-fooling=md5sig,badseq --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/quic_initial_www_google_com.bin --wssize 1:6 --new --filter-tcp=80 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/netrogat.txt --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/netrogat.txt --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-youtubeQ.txt --dpi-desync=fake --dpi-desync-repeats=2 --dpi-desync-cutoff=n2 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_pl_by_ori.bin --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-youtubeGV.txt --dpi-desync=split --dpi-desync-split-pos=1 --dpi-desync-fooling=badseq --dpi-desync-repeats=10 --dpi-desync-autottl --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-discord.txt --dpi-desync=fake --dpi-desync-udplen-increment=10 --dpi-desync-repeats=7 --dpi-desync-udplen-pattern=0xDEADBEEF --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_pl_by_ori.bin --dpi-desync-cutoff=n2 --new --filter-tcp=80 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-blacklist.txt --dpi-desync=fake,split2 --dpi-desync-fooling=badseq --dpi-desync-autottl --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/russia-blacklist.txt --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/myhostlist.txt --dpi-desync=fake,split2 --dpi-desync-split-seqovl=1 --dpi-desync-split-pos=2 --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_www_google_com.bin --dpi-desync-skip-nosni=1 --dpi-desync-autottl --new --filter-udp=50000-50200 --dpi-desync=fake --dpi-desync-any-protocol --dpi-desync-cutoff=d2 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_pl_by_ori.bin --new --filter-tcp=443 --hostlist-auto=/data/adb/modules/ZDT-D/autohostlist.txt --hostlist-exclude=/data/adb/modules/ZDT-D/working_folder/bin/netrogat.txt --dpi-desync=split --dpi-desync-split-pos=1 --dpi-desync-fooling=badseq --dpi-desync-repeats=10 --dpi-desync-autottl --new --filter-tcp=80,443 --dpi-desync=fake,disorder2 --dpi-desync-repeats=6 --dpi-desync-autottl=2 --dpi-desync-fooling=md5sig --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/ips.txt --new --filter-udp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/ips.txt --dpi-desync=fake --dpi-desync-repeats=11 --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/quic_initial_www_google_com.bin --new --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_sberbank_ru.bin --new --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_vk_com.bin --new --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/dtls_clienthello_w3_org.bin --new --dpi-desync-fake-quic=/data/adb/modules/ZDT-D/working_folder/bin/wireguard_response.bin --new --filter-l3=ipv4 --filter-tcp=443 --dpi-desync=syndata --wssize 1:6 --filter-l3=ipv4 --filter-tcp=443 --filter-udp=443,50000-50050 --dpi-desync=fake --dpi-desync-cutoff=d2 --dpi-desync-any-protocol --new --filter-tcp=443 --hostlist=/data/adb/modules/ZDT-D/working_folder/bin/google.txt --dpi-desync=fake,split --dpi-desync-fooling=badseq --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_drive_google_com.bin --dpi-desync-repeats=10 --new --filter-tcp=443 --hostlist-auto=/data/adb/modules/ZDT-D/working_folder/bin/blocked.txt --dpi-desync=fake,split --dpi-desync-fooling=badseq --dpi-desync-fake-tls=/data/adb/modules/ZDT-D/working_folder/bin/tls_clienthello_drive_google_com.bin --new --filter-udp=443 --dpi-desync=fake > /dev/null 2>&1 &

/system/bin/am start -a android.intent.action.MAIN -e toasttext "Устанавливаю правила iptables mangle для всей системы" -n bellavita.toast/.MainActivity

# Установка правил в цепочке PREROUTING
iptables -t mangle -A PREROUTING -p udp --sport 6969 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass
iptables -t mangle -A PREROUTING -p udp --sport 443 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass
iptables -t mangle -A PREROUTING -p tcp --sport 8000 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass
iptables -t mangle -A PREROUTING -p tcp --sport 443 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass
iptables -t mangle -A PREROUTING -p tcp --sport 80 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass

# Установка правил в цепочке POSTROUTING
iptables -t mangle -A POSTROUTING -p udp --dport 6969 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass
iptables -t mangle -A POSTROUTING -p udp --dport 443 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass
iptables -t mangle -A POSTROUTING -p tcp --dport 8000 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass
iptables -t mangle -A POSTROUTING -p tcp --dport 443 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass
iptables -t mangle -A POSTROUTING -p tcp --dport 80 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 200 --queue-bypass

# Переключаем ползунки
sed -i 's/^full_system=0$/full_system=1/' "$SETTING_START_PARAMSET"
sed -i 's/^dpi_tunnel_0=1$/dpi_tunnel_0=0/' "$SETTING_START_PARAMSET"
sed -i 's/^dpi_tunnel_1=1$/dpi_tunnel_1=0/' "$SETTING_START_PARAMSET"
sed -i 's/^alternativel=1$/alternativel=0/' "$SETTING_START_PARAMSET"
sed -i 's/^vpn_service=1$/vpn_service=0/' "$SETTING_START_PARAMSET"

setenforce 1