自己编译一个只有 hy2 协议的 sing-box 脚本,只有 8.4M Linux arm64 平台 由 gemini ai 生成

#!/bin/bash
# -----------------------------------------------------------
# 脚本功能: 为 aarch64 (MT7981) 交叉编译 sing-box,仅保留 Hysteria2
# 并且注入版本信息,最终使用 UPX 压缩。
# -----------------------------------------------------------

# --- 1. 环境检查与准备 ---

# 检查是否在 sing-box 源码根目录
if [ ! -d "cmd/sing-box" ]; then
    echo "错误: 请在 sing-box 源码的根目录执行此脚本。"
    exit 1
fi

# 检查 Go 环境
if ! command -v go &> /dev/null; then
    echo "错误: Go 语言环境未安装或不在 PATH 中。"
    exit 1
fi

# 检查 UPX
if ! command -v upx &> /dev/null; then
    echo "警告: UPX 未安装或不在 PATH 中。将跳过压缩步骤,二进制文件体积可能较大。"
    USE_UPX=false
else
    USE_UPX=true
fi

# 更新源码
echo "--- 正在拉取最新的 sing-box 源码 ---"
git pull

# --- 2. 设置交叉编译环境变量 (MT7981 / aarch64) ---

echo "--- 设置 aarch64 交叉编译环境 ---"
export GOOS="linux"
export GOARCH="arm64"
export CGO_ENABLED="0"

# --- 3. 获取版本信息 ---

echo "--- 正在获取 Git 版本信息 ---"
# VERSION:只获取最接近的标签名(如 v1.12.12),用于 Version 字段
VERSION=$(git describe --tags --abbrev=0 2>/dev/null)
if [ -z "$VERSION" ]; then
    VERSION=$(git describe --tags --always --dirty)
fi

# REVISION: 获取提交哈希
REVISION=$(git rev-parse HEAD)
OUTPUT_NAME="sing-box_hy2_aarch64"

# --- 4. 定义编译参数 (Build Tags & ldflags) ---

# 仅保留 Hysteria2 (hy2) 和必要的组件
BUILD_TAGS="os_linux netgo hy2 with_quic json \
    without_clash without_v2ray_api without_v2ray_protocol without_trojan \
    without_vless without_shadowsocks without_naive without_tuic without_wireguard \
    without_tun without_gso"

# *** 最终关键修正:Version 注入路径改为 constant.Version ***
LDFLAGS="-s -w -X 'github.com/sagernet/sing-box/constant.Version=${VERSION}' -X 'github.com/sagernet/sing-box/pkg/version.Revision=${REVISION}'"

# --- 5. 执行编译 ---

echo "--- 开始编译 ($GOOS/$GOARCH) ---"
echo "版本: $VERSION"
echo "目标文件: $OUTPUT_NAME"

# 使用 -a 标志,强制重新编译所有依赖和目标文件
go build -a -trimpath -ldflags "${LDFLAGS}" \
    -tags "${BUILD_TAGS}" \
    -o ${OUTPUT_NAME} ./cmd/sing-box

if [ $? -ne 0 ]; then
    echo "错误: 编译失败!请检查 Go 版本和源码。"
    exit 1
fi

echo "--- 编译成功!文件大小: $(du -h $OUTPUT_NAME | awk '{print $1}') ---"

# --- 6. UPX 压缩 (可选) ---

if $USE_UPX; then
    echo "--- 正在使用 UPX 压缩 ---"
    upx --best ${OUTPUT_NAME}
    echo "--- 压缩完成!新文件大小: $(du -h $OUTPUT_NAME | awk '{print $1}') ---"
else
    echo "跳过 UPX 压缩。如果需要更小体积,请安装 UPX。"
fi

echo "--- 脚本执行完毕。二进制文件位于当前目录: ${OUTPUT_NAME} ---"

openwrt 中以自建节点方式跑 nikkia 的配置文件

#---------------------------------------------------#
## 这个是配置文件模版,可根据自己情况重新定义。正式配置文件要放到 "/etc/mihomo" 文件夹下。
## 
## 当前配置:
## - Hysteria2 代理(高性能抗干扰协议)
## - Vmess 代理(备用协议)
## - TUN 模式支持(全局透明代理)
## - 优化 DNS 解析(防污染、加速访问)
## - 自动分流规则(国内直连、国外代理)
## - 自动测速选择(自动选择最佳节点)
## - 面板访问控制(支持远程管理)
##
## 使用方法: 
## 1. 将此文件放置在 $HOME/.config/mihomo/config.yaml
## 2. 替换 VPS_IP 为你的服务器 IP 地址
## 3. 替换 your_password 为你的实际密码
## 4. 根据你的网络情况调整上传下载速度
#---------------------------------------------------#

# 通用代理端口:同时支持HTTP和SOCKS5协议,一般软件都可以使用这个端口
mixed-port: 7890

# 仅HTTP协议专用端口(如果你的软件只支持HTTP代理,用这个)
port: 7891

# 仅SOCKS5协议专用端口(如果你的软件只支持SOCKS5代理,用这个)
socks-port: 7892


# 指定 Clash 应绑定的网络接口。
# 此设置决定 Clash 将使用哪个网络接口进行所有网络操作。
# 在这里设置为 "eth0",这通常是 Linux 系统上的主要以太网接口。
# interface-name: 192.168.88.6

# 是否允许来自局域网的连接(开启后,其他设备可以通过你的电脑上网)
allow-lan: true

# 监听地址,"*"表示监听所有地址,这样局域网内其他设备才能连接
bind-address: "*"
mode: rule

# 日志设置:silent=不显示日志,info=显示基本信息,warning=显示警告
# error=只显示错误,debug=显示所有调试信息(日志会占用内存,一般保持静默即可)
log-level: silent

# 控制面板访问地址和端口,可以通过浏览器访问查看连接状态
external-controller: 0.0.0.0:9090


# 远程控制面板UI,无需下载就能使用(如果想用就取消注释)
#external-ui: https://yacd.haishan.me

# MetaCubeX界面,比上面那个更漂亮(目前启用的是这个)
external-ui: ui

# 访问控制面板的密码,设置后别人就不能随意访问你的控制面板了
secret: "替换为控制面板的访问密码"


# DNS设置(处理域名解析的方式,很重要!)
dns:
  enable: true
  listen: 0.0.0.0:53
  cache: true
  cache-size: 8192
  ipv6: false # 关闭IPv6,大多数情况下不需要

  # 国内DNS服务器,用于解析常规域名
  default-nameserver:
    - 223.5.5.5  # 阿里DNS
    - 119.29.29.29  # 114DNS
  enhanced-mode: fake-ip # 加速DNS解析的模式
  fake-ip-range: 198.18.0.0/16 # 虚拟IP地址池

  # 下面这些域名将使用真实IP而非虚拟IP,这样可以避免一些服务无法正常工作
  # 比如网易云音乐、游戏服务器等需要真实IP的服务
  fake-ip-filter:
    - '*.lan'
    - '*.localdomain'
    - '*.example'
    - '*.invalid'
    - '*.localhost'
    - '*.test'
    - '*.local'
    - '*.home.arpa'
    - 'time.*.com'
    - 'time.*.gov'
    - 'time.*.edu.cn'
    - 'time.*.apple.com'
    - 'time1.*.com'
    - 'time2.*.com'
    - 'time3.*.com'
    - 'time4.*.com'
    - 'time5.*.com'
    - 'time6.*.com'
    - 'time7.*.com'
    - 'ntp.*.com'
    - 'ntp1.*.com'
    - 'ntp2.*.com'
    - 'ntp3.*.com'
    - 'ntp4.*.com'
    - 'ntp5.*.com'
    - 'ntp6.*.com'
    - 'ntp7.*.com'
    - '*.time.edu.cn'
    - '*.ntp.org.cn'
    - '+.pool.ntp.org'
    - 'time1.cloud.tencent.com'
    - 'music.163.com'
    - '*.music.163.com'
    - '*.126.net'
    - 'musicapi.taihe.com'
    - 'music.taihe.com'
    - 'songsearch.kugou.com'
    - 'trackercdn.kugou.com'
    - '*.kuwo.cn'
    - 'api-jooxtt.sanook.com'
    - 'api.joox.com'
    - 'joox.com'
    - 'y.qq.com'
    - '*.y.qq.com'
    - 'streamoc.music.tc.qq.com'
    - 'mobileoc.music.tc.qq.com'
    - 'isure.stream.qqmusic.qq.com'
    - 'dl.stream.qqmusic.qq.com'
    - 'aqqmusic.tc.qq.com'
    - 'amobile.music.tc.qq.com'
    - '*.xiami.com'
    - '*.music.migu.cn'
    - 'music.migu.cn'
    - '*.msftconnecttest.com'
    - '*.msftncsi.com'
    - 'msftconnecttest.com'
    - 'msftncsi.com'
    - 'localhost.ptlogin2.qq.com'
    - 'localhost.sec.qq.com'
    - '+.srv.nintendo.net'
    - '+.stun.playstation.net'
    - 'xbox.*.microsoft.com'
    - 'xnotify.xboxlive.com'
    - '+.battlenet.com.cn'
    - '+.wotgame.cn'
    - '+.wggames.cn'
    - '+.wowsgame.cn'
    - '+.wargaming.net'
    - 'proxy.golang.org'
    - 'stun.*.*'
    - 'stun.*.*.*'
    - '+.stun.*.*'
    - '+.stun.*.*.*'
    - '+.stun.*.*.*.*'
    - 'heartbeat.belkin.com'
    - '*.linksys.com'
    - '*.linksyssmartwifi.com'
    - '*.router.asus.com'
    - 'mesu.apple.com'
    - 'swscan.apple.com'
    - 'swquery.apple.com'
    - 'swdownload.apple.com'
    - 'swcdn.apple.com'
    - 'swdist.apple.com'
    - 'lens.l.google.com'
    - 'stun.l.google.com'
    - '+.nflxvideo.net'
    - '*.square-enix.com'
    - '*.finalfantasyxiv.com'
    - '*.ffxiv.com'
    - '*.mcdn.bilivideo.cn'

  # 国内DNS服务器(加密连接,更安全)
  nameserver:
    - https://doh.pub/dns-query      # 腾讯DNS
    - https://dns.alidns.com/dns-query  # 阿里DNS

  # 国外DNS服务器,用于解析被污染的域名
  fallback:
     - https://dns.google/dns-query     # 谷歌DNS
     - https://cloudflare-dns.com/dns-query  # Cloudflare DNS

  # 哪些情况下会使用国外DNS
  fallback-filter:
    geoip: false
    ipcidr:
      # 以下是内网IP段,不会使用国外DNS
      - 0.0.0.0/8
      - 10.0.0.0/8
      - 100.64.0.0/10
      - 127.0.0.0/8
      - 169.254.0.0/16
      - 172.16.0.0/12
      - 192.0.0.0/24
      - 192.0.2.0/24
      - 192.88.99.0/24
      - 192.168.0.0/16
      - 198.18.0.0/15
      - 198.51.100.0/24
      - 203.0.113.0/24
      - 224.0.0.0/4
      - 240.0.0.0/4
      - 255.255.255.255/32
    domain:
      # 这些网站强制使用国外DNS解析,避免被污染
      - '+.google.com'
      - '+.facebook.com'
      - '+.youtube.com'
      - '+.githubusercontent.com'
      - '+.googlevideo.com'

# TUN模式设置(让系统所有流量都经过Clash,无需单独为每个软件设置代理)
tun:
  enable: true # 开启后所有流量都会通过Clash,无需在软件里单独设置代理
  stack: system # 使用系统网络栈
  dns-hijack:
    - tcp://any:53  # 接管所有DNS请求,防止DNS泄露
    - udp://any:53  # 接管所有DNS请求,防止DNS泄露

# 代理服务器设置
proxies:
  # Hysteria2代理(高性能抗干扰协议)

  - name: "替换为节点名称1"
    type: hysteria2
    server: 替换为VPS的IP
    port: 替换为hy2的端口
    password: "替换为你的Hysteria2密码"
    up: 50  # 上传速度
    down: 500  # 下载速度
    sni: cn.bing.com # 伪装成访问必应
    skip-cert-verify: true # 跳过证书验证

  - name: "替换为节点名称2"
    type: hysteria2
    server: 替换为VPS的IP
    port: 替换为hy2的端口
    password: "替换为你的Hysteria2密码"
    sni: cn.bing.com
    skip-cert-verify: true
    obfs: salamander
    obfs-password: "替换为你的obfs密码"

  - name: "替换为节点名称3"
    type: tuic
    server: 替换为VPS的IP
    port: 替换为tuic的端口
    uuid: 替换为tuic的UUID
    password: 替换为tuic的密码
    alpn:
      - h3
    skip-cert-verify: true
    congestion-controller: bbr

# 代理分组(让你可以选择走直连还是代理)
proxy-groups:
  # 手动选择代理组
  - name: Proxy
    type: select
    proxies:
      - 替换为节点名称1 # Hysteria2代理
      - 替换为节点名称2 # Hysteria2代理
      - 替换为节点名称3 # TUIC代理
      - DIRECT # 直连选项

  # 自动测速选择最快的代理
  - name: "auto"
    type: url-test
    proxies:
      - 替换为节点名称1
      - 替换为节点名称2
      - 替换为节点名称3
      - DIRECT
    url: 'https://www.gstatic.com/generate_204'
    interval: 300 # 每300秒测速一次

# 规则集(决定哪些网站走代理,哪些直连)
rule-providers:
  apple-proxy:
    type: http
    behavior: classical
    url: "https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/Rulesets/Clash/Basic/Apple-proxy.yaml"
    path: ./ruleset/Apple-proxy.yaml
    interval: 3600 # 每小时更新一次规则

  apple-direct:
    type: http
    behavior: classical
    url: "https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/Rulesets/Clash/Basic/Apple-direct.yaml"
    path: ./ruleset/Apple-direct.yaml
    interval: 3600

  cn:
    type: http
    behavior: classical
    url: "https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/Rulesets/Clash/Basic/CN.yaml"
    path: ./ruleset/CN.yaml
    interval: 3600

  ad-keyword:
    type: http
    behavior: classical
    url: "https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/Rulesets/Clash/Basic/common-ad-keyword.yaml"
    path: ./ruleset/common-ad-keyword.yaml
    interval: 3600

  foreign:
    type: http
    behavior: classical
    url: "https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/Rulesets/Clash/Basic/foreign.yaml"
    path: ./ruleset/foreign.yaml
    interval: 3600

  telegram:
    type: http
    behavior: classical
    url: "https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/Rulesets/Clash/App/social/Telegram.yaml"
    path: ./ruleset/Telegram.yaml
    interval: 3600

  lan:
    type: http
    behavior: classical
    url: "https://cdn.jsdelivr.net/gh/Hackl0us/SS-Rule-Snippet@master/Rulesets/Clash/Basic/LAN.yaml"
    path: ./ruleset/LAN.yaml
    interval: 3600

# 最终规则(按顺序匹配,匹配到就停止)
rules:
  - RULE-SET,lan,DIRECT # 局域网直连
  - RULE-SET,cn,DIRECT # 中国网站走直连
  - GEOIP,CN,DIRECT # 中国IP直连
  - RULE-SET,apple-proxy,Proxy # 苹果服务走代理
  - RULE-SET,apple-direct,DIRECT # 苹果国内服务走直连
  - RULE-SET,ad-keyword,REJECT # 广告关键词拦截
  - RULE-SET,foreign,Proxy # 国外网站走代理
  - RULE-SET,telegram,Proxy # Telegram走代理
  - MATCH,Proxy # 其他所有请求走代理

在 routeros 中用 container 运行 sing-box

先做镜像:
docker pull gzxhwq/sing-box:1.11.14
docker save -o sing-box.tar gzxhwq/sing-box

把 sing-box.tar 文件上传到 routeros 中

配置文件 config.json 如下:

{
  "log": {
    "level": "error",
    "disabled": true
  },
  "dns": {
    "strategy": "ipv4_only",
    "servers": [
      {
        "tag": "cloudflare",
        "address": "https://1.1.1.1/dns-query",
        "detour": "proxy"
      },
      {
        "tag": "local",
        "address": "223.5.5.5",
        "detour": "direct"
      },
      {
        "tag": "block",
        "address": "rcode://success"
      }
    ],
    "rules": [
      {
        "rule_set": "geosite-cn",
        "server": "local",
        "disable_cache": true
      }
    ]
  },
  "inbounds": [
    {
      "type": "tun",
      "tag": "tun-in",
      "interface_name": "tun0",
      "address": [
        "172.19.0.1/30"
      ],
      "auto_route": true,
      "strict_route": false,
      "sniff": true
    }
  ],
  "outbounds": [
    {
      "type": "hysteria2",
      "tag": "proxy",
      "server": "VPS 地址",
      "server_port": 端口,
      "password": "密码",
      "obfs": {
        "type": "salamander",
        "password": "obfs密码"
      },
      "tls": {
        "enabled": true,
        "server_name": "VPS 地址",
        "insecure": true
      }
    }
  ],
  "route": {
    "auto_detect_interface": true,
    "rule_set": [
      {
        "tag": "geosite-cn",
        "type": "local",
        "format": "binary",
        "path": "./rule-set/geosite-geolocation-cn.srs"
      },
      {
        "tag": "geoip-cn",
        "type": "local",
        "format": "binary",
        "path": "./rule-set/geoip-cn.srs"
      }
    ],
    "rules": [
      {
        "protocol": "dns",
        "outbound": "proxy"
      },
      {
        "rule_set": [
          "geosite-cn",
          "geoip-cn"
        ],
        "action": "direct"
      },
      {
        "outbound": "proxy"
      }
    ]
  }
}

王爽<<汇编语言>>第 3 版 实验 14 访问 CMOS RAM 作业

assume cs:codesg

stacksg segment stack
  dw 0,0,0,0,0,0,0,0
stacksg ends
datasg segment
  dw 8 dup (0)
datasg ends

codesg segment
  byteno: db 9,8,7,4,2,0
  symbol: db '// ::-'

  begin:
    mov ds,ax
    mov ax,datasg
    mov es,ax
    mov si,0
    mov di,offset symbol
    mov bx,offset byteno

  read:
    mov al,cs:[bx]
    out 70h,al
    in al,71h
    mov ah,al
    mov cl,4
    shr ah,cl
    and al,00001111b
    add ah,30h
    add al,30h

    mov es:[si],ah
    mov es:[si+1],al
    mov al,cs:[di]
    mov es:[si+2],al
    
    cmp byte ptr cs:[bx],0
    je print
    inc bx
    inc di
    add si,3
    jmp short read

  print:
    mov byte ptr es:[si+2],24h
    mov ax,datasg
    mov ds,ax
    mov dx,0
    mov ah,9
    int 21h

  quit:
    mov ax,4c00h
    int 21h


codesg ends

end begin