5 Commits

Author SHA1 Message Date
CherretGit
3776b0ddfc remove termux elf cleaner 2026-03-18 23:01:18 +07:00
CherretGit
4c324e395f dont create bin dir in build-module.sh script 2026-03-18 22:44:38 +07:00
CherretGit
743bc86866 remove trash 2026-03-18 22:40:09 +07:00
CherretGit
8b8b2275c4 update build scripts 2026-03-18 17:11:39 +07:00
CherretGit
3097ea86b4 remove ${zaprettdir} and add ${lua_lib:id} 2026-03-18 16:54:54 +07:00
18 changed files with 80 additions and 86 deletions

View File

@@ -8,15 +8,11 @@ just -f rust/justfile build-android --release
echo "Make build dirs"
mkdir -p zaprett/system/bin
mkdir -p zaprett/zaprett/bin
mkdir -p zaprett/zaprett/lists/include
mkdir -p zaprett/zaprett/manifests/lists/include
mkdir -p zaprett/zaprett/files/lists/include
mkdir -p zaprett-hosts/system/bin
mkdir -p zaprett-hosts/system/etc
mkdir -p zaprett-hosts/zaprett/bin
mkdir -p zaprett-hosts/zaprett/lists/include
mkdir -p zaprett-hosts/zaprett/manifests/lists/include
mkdir -p out manifests lists
mkdir -p zaprett-hosts/zaprett/files/lists/include
mkdir -p out lists
echo "Copy files to dirs"
cp rust/target/armv7-linux-androideabi/release/zaprett zaprett/system/bin/zaprett-armv7
@@ -49,15 +45,11 @@ done
cp -a src/* zaprett/
cp -r zaprett/* zaprett-hosts/
echo "Download and copy actual lists and manifests"
wget https://raw.githubusercontent.com/CherretGit/zaprett-repo/refs/heads/main/manifests/lists/include/list-youtube.json -O manifests/list-youtube.json
wget https://raw.githubusercontent.com/CherretGit/zaprett-repo/refs/heads/main/manifests/lists/include/list-discord.json -O manifests/list-discord.json
echo "Download and copy actual lists"
wget https://raw.githubusercontent.com/CherretGit/zaprett-repo/refs/heads/main/files/lists/include/list-youtube.txt -O lists/list-youtube.txt
wget https://raw.githubusercontent.com/CherretGit/zaprett-repo/refs/heads/main/files/lists/include/list-discord.txt -O lists/list-discord.txt
cp lists/* zaprett/zaprett/lists/include/
cp manifests/* zaprett/zaprett/manifests/lists/include
cp lists/* zaprett-hosts/zaprett/lists/include/
cp manifests/* zaprett-hosts/zaprett/manifests/lists/include
cp lists/* zaprett/zaprett/files/lists/include/
cp lists/* zaprett-hosts/zaprett/files/lists/include/
cp hosts/hosts zaprett-hosts/system/etc
echo "Create module.prop"
@@ -88,4 +80,4 @@ mv zaprett.zip out/
mv zaprett-hosts.zip out/
echo "Clean temp files"
rm -rf zaprett zaprett-hosts manifests lists
rm -rf zaprett zaprett-hosts lists

View File

@@ -5,6 +5,6 @@ edition.workspace = true
repository.workspace = true
[build-dependencies]
cmake = "0.1.57"
glob = "0.3.3"
bindgen = "0.72.1"
cmake = "0.1.57"

View File

@@ -3,26 +3,13 @@ use std::path::PathBuf;
fn main() {
let dst = cmake::Config::new(env::var("CARGO_MANIFEST_DIR").unwrap()).build();
println!("cargo:rustc-link-search=native={}", dst.join("lib").display());
println!("cargo:rustc-link-lib=dylib=nfqws");
println!("cargo:rustc-link-lib=z");
println!("cargo:rustc-link-lib=netfilter_queue");
println!("cargo:rustc-link-lib=nfnetlink");
println!("cargo:rustc-link-lib=mnl");
if let Ok(libs) = env::var("NETFILTER_LIBS") {
println!("cargo:rustc-link-search=native={libs}/lib");
}
println!("cargo:rerun-if-changed=zapret/nfq");
println!("cargo:rerun-if-changed=CMakeLists.txt");
println!("cargo:rerun-if-changed=build.rs");
let mut builder = bindgen::Builder::default();
for header in glob::glob("zapret/nfq/*.h")
.unwrap()
.filter_map(Result::ok)

View File

@@ -5,27 +5,11 @@ fn main() {
let dst = cmake::Config::new(env::var("CARGO_MANIFEST_DIR").unwrap()).build();
println!("cargo:rustc-link-search=native={}", dst.join("lib").display());
println!("cargo:rustc-link-lib=dylib=nfqws2");
println!("cargo:rustc-link-lib=z");
println!("cargo:rustc-link-lib=netfilter_queue");
println!("cargo:rustc-link-lib=nfnetlink");
println!("cargo:rustc-link-lib=mnl");
println!("cargo:rustc-link-lib=static=luajit-5.1");
println!("cargo:rustc-link-lib=unwind");
if let Ok(libs) = env::var("NETFILTER_LIBS") {
println!("cargo:rustc-link-search=native={libs}/lib");
}
if let Ok(libs) = env::var("LUAJIT_LIBS") {
println!("cargo:rustc-link-search=native={libs}/lib");
}
println!("cargo:rerun-if-changed=CMakeLists.txt");
println!("cargo:rerun-if-changed=zapret2/nfq2");
println!("cargo:rerun-if-changed=build.rs");
let mut builder = bindgen::Builder::default();
for header in glob::glob("zapret2/nfq2/*.h")
.unwrap()
.filter_map(Result::ok)

View File

@@ -6,8 +6,6 @@ pub mod path {
LazyLock::new(|| Path::new("/data/adb/modules/zaprett"));
pub static ZAPRETT_DIR_PATH: LazyLock<&Path> =
LazyLock::new(|| Path::new("/storage/emulated/0/zaprett"));
pub static ZAPRETT_LIBS_PATH: LazyLock<&Path> =
LazyLock::new(|| Path::new("/storage/emulated/0/zaprett/files/strategies/nfqws2/libs"));
}
// Only for testing
@@ -20,6 +18,4 @@ pub mod path {
LazyLock::new(|| Path::new("zaprett_module"));
pub static ZAPRETT_DIR_PATH: LazyLock<&Path> =
LazyLock::new(|| Path::new("zaprett_dir"));
pub static ZAPRETT_LIBS_PATH: LazyLock<&Path> =
LazyLock::new(|| Path::new("zaprett_dir/strategies/nfqws2/libs"));
}

View File

@@ -16,7 +16,7 @@ use sysctl::{Ctl, CtlValue, Sysctl};
use sysinfo::{Pid as SysPid, System};
use tokio::fs;
use tokio::io::AsyncReadExt;
use crate::path::path::{MODULE_PATH, ZAPRETT_DIR_PATH, ZAPRETT_LIBS_PATH};
use crate::path::path::{MODULE_PATH, ZAPRETT_DIR_PATH};
use crate::strategy::prepare_manifests;
pub async fn start_service() -> anyhow::Result<()> {
@@ -71,14 +71,13 @@ pub async fn start_service() -> anyhow::Result<()> {
let manifest = get_manifest(Path::new(strategy_path))?;
Cow::Owned(fs::read_to_string(manifest.file()).await?)
};
let regex_hostlists = Regex::new(r"\$(?:hostlists|\{hostlists})")?;
let regex_hostlists = Regex::new(r"\$\{hostlists\}")?;
let regex_hostlist = Regex::new(r"\$\{hostlist:([^}]+)\}")?;
let regex_hostlist_exclude = Regex::new(r"\$\{hostlist_exclude:([^}]+)\}")?;
let regex_ipset = Regex::new(r"\$\{ipset:([^}]+)\}")?;
let regex_ipset_exclude = Regex::new(r"\$\{ipset_exclude:([^}]+)\}")?;
let regex_ipsets = Regex::new(r"\$(?:ipsets|\{ipsets})")?;
let regex_zaprettdir = Regex::new(r"\$(?:zaprettdir|\{zaprettdir})")?;
let regex_libsdir = Regex::new(r"\$(?:libsdir|\{libsdir})")?;
let regex_ipsets = Regex::new(r"\$\{ipsets\}")?;
let regex_libsdir = Regex::new(r"\$\{lua_lib:([^}]+)\}")?;
let regex_bindir = Regex::new(r"\$\{bin:([^}]+)\}")?;
let (hosts, ipsets) = config.list_type().merge(&config).await?;
let hostlists: HashMap<String, Manifest> =
@@ -105,29 +104,32 @@ pub async fn start_service() -> anyhow::Result<()> {
.into_iter()
.map(|m| (m.id().clone(), m))
.collect();
let lua_lib: HashMap<String, Manifest> =
get_all_manifests(&ZAPRETT_DIR_PATH.join("manifests/libs"))
.unwrap_or_default()
.into_iter()
.map(|m| (m.id().clone(), m))
.collect();
let bins: HashMap<String, Manifest> =
get_all_manifests(&ZAPRETT_DIR_PATH.join("manifests/bin"))
.unwrap_or_default()
.into_iter()
.map(|m| (m.id().clone(), m))
.collect();
let strat_modified = prepare_manifests(&start, &regex_hostlist, &hostlists, &tmp_dir, "txt")?;
let strat_modified = prepare_manifests(&strat_modified, &regex_hostlist_exclude, &hostlists_exclude, &tmp_dir, "txt")?;
let strat_modified = prepare_manifests(&strat_modified, &regex_ipset, &ipset, &tmp_dir, "txt")?;
let strat_modified = prepare_manifests(&strat_modified, &regex_ipset_exclude, &ipset_exclude, &tmp_dir, "txt")?;
let strat_modified = prepare_manifests(&strat_modified, &regex_bindir, &bins, &tmp_dir, "bin")?;
let strat_modified = prepare_manifests(&start, &regex_hostlist, &hostlists, &tmp_dir)?;
let strat_modified = prepare_manifests(&strat_modified, &regex_hostlist_exclude, &hostlists_exclude, &tmp_dir)?;
let strat_modified = prepare_manifests(&strat_modified, &regex_ipset, &ipset, &tmp_dir)?;
let strat_modified = prepare_manifests(&strat_modified, &regex_ipset_exclude, &ipset_exclude, &tmp_dir)?;
let strat_modified = prepare_manifests(&strat_modified, &regex_libsdir, &lua_lib, &tmp_dir)?;
let strat_modified = prepare_manifests(&strat_modified, &regex_bindir, &bins, &tmp_dir)?;
let strat_modified = regex_hostlists.replace_all(&strat_modified, &hosts);
let strat_modified = regex_ipsets.replace_all(&strat_modified, &ipsets);
let strat_modified =
regex_zaprettdir.replace_all(&strat_modified, ZAPRETT_DIR_PATH.to_str().unwrap());
let strat_modified =
regex_libsdir.replace_all(&strat_modified, ZAPRETT_LIBS_PATH.to_str().unwrap());
let strat_modified = strat_modified.into_owned();
let ctl = Ctl::new("net.netfilter.nf_conntrack_tcp_be_liberal")?;
ctl.set_value(CtlValue::String("1".into()))?;
setup_iptables_rules().expect("setup iptables rules");
setup_iptables_rules()?;
if config.service_type() == &ServiceType::Nfqws {
daemonize_nfqws(&strat_modified).await;

View File

@@ -3,7 +3,7 @@ use regex::Regex;
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
pub fn prepare_manifests(input: &str, regex: &Regex, manifests: &HashMap<String, Manifest>, tmp_dir: &Path, ext: &str) -> anyhow::Result<String> {
pub fn prepare_manifests(input: &str, regex: &Regex, manifests: &HashMap<String, Manifest>, tmp_dir: &Path) -> anyhow::Result<String> {
let required: HashSet<String> = regex.captures_iter(input).map(|c| c[1].to_string()).collect();
let mut paths: HashMap<String, PathBuf> = HashMap::new();
for id in &required {
@@ -12,7 +12,9 @@ pub fn prepare_manifests(input: &str, regex: &Regex, manifests: &HashMap<String,
.ok_or_else(|| anyhow::anyhow!("Manifest not found: {}", id))?;
let path = Path::new(manifest.file());
let mut dst = tmp_dir.join(id);
dst.set_extension(ext);
if let Some(ext) = path.extension() {
dst.set_extension(ext);
}
std::fs::copy(path, &dst)?;
paths.insert(id.clone(), dst);
}

View File

@@ -110,24 +110,6 @@ _build_luajit target_arch:
echo "LuaJIT for {{target_arch}} already built"
fi
_elf-clean target_dir:
#!/usr/bin/env bash
TERMUX_ELF_CLEANER="{{TARGET}}/termux-elf-cleaner"
if [ ! -f "$TERMUX_ELF_CLEANER" ]; then
echo "Downloading termux-elf-cleaner to {{TARGET}}..."
mkdir -p "{{TARGET}}"
wget -q -O "$TERMUX_ELF_CLEANER" "https://github.com/termux/termux-elf-cleaner/releases/download/v3.0.1/termux-elf-cleaner"
chmod +x "$TERMUX_ELF_CLEANER"
fi
BINARY="{{target_dir}}/zaprett"
if [ -f "$BINARY" ]; then
echo "Patching $BINARY with API {{ANDROID_API}}..."
"$TERMUX_ELF_CLEANER" --api {{ANDROID_API}} "$BINARY"
else
echo "Binary $BINARY not found!"
exit 1
fi
_install_rust_target target:
#!/usr/bin/env bash
if ! rustup target list --installed | grep -q "{{target}}"; then
@@ -162,6 +144,5 @@ build-android *args: prepare-android
just _build_luajit $t
just _install_rust_target $t
NETFILTER_LIBS=$NETFILTER_LIBS-$t LUAJIT_LIBS=$LUAJIT_LIBS-$t cargo ndk -t $t --platform $ANDROID_API build {{args}}
just _elf-clean "target/${t}/release"
)
done

View File

@@ -12,7 +12,7 @@ ui_print "App by: egor-white, Cherret"
ui_print "####################"
ui_print "Creating zaprett directory..."
mkdir /sdcard/zaprett; mkdir /sdcard/zaprett/lists; mkdir /sdcard/zaprett/bin; mkdir /sdcard/zaprett/strategies;
mkdir /sdcard/zaprett
ui_print "Copying lists and binaries to /sdcard/zaprett..."
cp -r $MODPATH/zaprett/. /sdcard/zaprett/

View File

@@ -0,0 +1,10 @@
{
"schema": 1,
"id": "quic_initial_www_google_com",
"name": "quic_initial_www_google_com",
"version": "1.0.0",
"author": "zaprett-devs",
"description": "Binary artifact: quic_initial_www_google_com",
"dependencies": [],
"file": "/storage/emulated/0/zaprett/files/bin/quic_initial_www_google_com.bin"
}

View File

@@ -0,0 +1,10 @@
{
"schema": 1,
"id": "tls_clienthello_4pda_to",
"name": "tls_clienthello_4pda_to",
"version": "1.0.0",
"author": "zaprett-devs",
"description": "Binary artifact: tls_clienthello_4pda_to",
"dependencies": [],
"file": "/storage/emulated/0/zaprett/files/bin/tls_clienthello_4pda_to.bin"
}

View File

@@ -0,0 +1,10 @@
{
"schema": 1,
"id": "tls_clienthello_www_google_com",
"name": "tls_clienthello_www_google_com",
"version": "1.0.0",
"author": "zaprett-devs",
"description": "Binary artifact: tls_clienthello_www_google_com",
"dependencies": [],
"file": "/storage/emulated/0/zaprett/files/bin/tls_clienthello_www_google_com.bin"
}

View File

@@ -0,0 +1,10 @@
{
"schema": 1,
"id": "list-discord",
"name": "list-discord",
"version": "1.0.0",
"author": "zaprett-devs",
"description": "Домены Discord",
"dependencies": [],
"file": "/storage/emulated/0/zaprett/files/lists/include/list-discord.txt"
}

View File

@@ -0,0 +1,10 @@
{
"schema": 1,
"id": "list-youtube",
"name": "list-youtube",
"version": "1.0.0",
"author": "zaprett-devs",
"description": "Домены YouTube",
"dependencies": [],
"file": "/storage/emulated/0/zaprett/files/lists/include/list-youtube.txt"
}