当前位置: 首页 > news >正文

Mac电脑交叉编译iphone设备可以运行的redsocks, openssl, libsevent

准备:intel x86_64芯片的mac电脑,系统为mac os15.3.1,iphone为6s的ios14.4(rootful越狱)

第一步:准备工具链(推荐使用 theos + clang

如果你已经安装过 Theos(或 NewTheos),直接用它内置的 clang 就能编译出 iOS Mach-O 可执行文件。

如果没有,可以这样安装:

# 安装 theos(推荐)
git clone --recursive https://github.com/theos/theos.git ~/theos

 

第二步:准备依赖库 libevent

你需要为 iOS 编译静态版本的 libevent:

git clone https://github.com/libevent/libevent.git
cd libevent
brew install autoconf automake libtool
./autogen.sh# 设置编译环境(假设你用 Xcode CLI 工具)
export SDK=$(xcrun --sdk iphoneos --show-sdk-path)
export CC="$(xcrun --sdk iphoneos -f clang)"
export CFLAGS="-isysroot $SDK -arch arm64 -miphoneos-version-min=10.0"./configure --host=arm-apple-darwin --disable-shared --enable-static
make

第三步:获取并修改 redsocks 源码

git clone https://github.com/darkk/redsocks.git
cd redsocks

       更新一下Makefile更是和mac系统

# Compiler settings
CC := gcc
CFLAGS := -g -O2 -std=c99 -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE -D_GNU_SOURCE -Wall
LDFLAGS := # Libraries
LIBS := -levent_core
ifeq ($(DBG_BUILD),1)LIBS += -levent_extra
endif# Sources and objects
SRCS := parser.c main.c redsocks.c log.c http-connect.c socks4.c socks5.c http-relay.c base.c base64.c md5.c http-auth.c utils.c redudp.c dnstc.c dnsu2t.c gen/version.c
OBJS := $(SRCS:.c=.o)
DEPS := .depend
OUT := redsocks
VERSION := 0.5
CONF := config.h# Directories
GEN_DIR := gen# Targets
.PHONY: all clean distclean test tags# Default target
all: $(OUT)# Generate version.c
gen/version.c: *.c *.h $(GEN_DIR)/.buildrm -f $@.tmpecho '/* this file is auto-generated during build */' > $@.tmpecho '#include "../version.h"' >> $@.tmpecho 'const char* redsocks_version = ' >> $@.tmpif [ -d .git ]; then \echo '"redsocks.git/'`git describe --tags`'"'; \if [ `git status --porcelain | grep -v -c '^??'` != 0 ]; then \echo '"'"-unclean-$(shell date --rfc-3339=seconds | tr ' ' 'T')-$(USER)@$(shell uname -n)"'"'; \fi \else \echo '"redsocks/$(VERSION)"'; \fi >> $@.tmpecho ';' >> $@.tmpmv -f $@.tmp $@# Create necessary directories
$(GEN_DIR)/.build:mkdir -p $(GEN_DIR)touch $@# Dependency generation
$(DEPS): $(SRCS)$(CC) -MM $(SRCS) 2>/dev/null > $(DEPS) || \( \# Handle missing dependencies properly with correct formatting \for SRC in $(SRCS); do \echo -n "$${SRC%.c}.o: " >> $(DEPS); \# Collect includes for each source file \export SRC_DEPS="`sed '/^\#[ \t]*include \?"\(.*\)".*/!d;s//\1/' $$SRC | sort`"; \while true; do \export SRC_DEPS_OLD="$$SRC_DEPS"; \# Recursively collect dependencies \export SRC_DEPS="`echo $$SRC_DEPS | sed 's/  */\n/g' | sort`"; \test "$$SRC_DEPS" = "$$SRC_DEPS_OLD" && break; \done; \echo $$SRC $$SRC_DEPS >> $(DEPS); \done; \)# Include dependencies
-include $(DEPS)# Final executable
$(OUT): $(OBJS)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)# Clean the build
clean:$(RM) $(OUT) $(OBJS) $(CONF) $(DEPS)# Clean everything, including generated files
distclean: clean$(RM) tags $(DEPS)$(RM) -r $(GEN_DIR)# Create tags for code navigation
tags: *.c *.hctags -R# Run tests
test: tests/__build-tstamp__ tests/prlimit-nofilecd tests && env $(TEST_ENV) ./run# Build tests
tests/__build-tstamp__: $(OUT) tests/[a-z]* tests/[a-z]*/*cd tests && ./buildtouch $@# Build test for prlimit
tests/prlimit-nofile: tests/prlimit-nofile.c$(CC) $(CFLAGS) -o $@ $^

第四步:交叉编译 redsocks

export SDK=$(xcrun --sdk iphoneos --show-sdk-path)
export CC="$(xcrun --sdk iphoneos -f clang)"
export CFLAGS="-isysroot $SDK -arch arm64 -miphoneos-version-min=10.0"
export LDFLAGS="-L/path/to/libevent/.libs"make

第五步:签名(越狱设备免验证也建议做)

brew install ldid
ldid -S redsocks

第六步:推送到 iPhone

scp redsocks root@<iphone-ip>:/usr/local/bin/
scp redsocks.conf root@<iphone-ip>:/etc/

第七步:启动测试

chmod +x /usr/local/bin/redsocks
/usr/local/bin/redsocks -c /etc/redsocks.conf

第八步:编译Openssl3.5.0(可选)

git clone https://github.com/x2on/OpenSSL-for-iPhone.git
cd OpenSSL-for-iPhone#您可以尝试在构建脚本中添加以下选项来禁用 Bitcode:export CFLAGS="-fno-bitcode"
export LDFLAGS="-fno-bitcode"./build-libssl.sh clean
./build-libssl.sh

相关文章:

  • Rust + WebAssembly 性能剖析指南
  • 辛格迪客户案例 | 厦门三维丝实施SAP系统
  • js ES6箭头函数的作用
  • 0415-批量删除操作
  • ERR_PNPM_DLX_NO_BIN No binaries found in tailwindcss
  • ClickHouse 数据库中的 “超时”
  • 游戏引擎学习第227天
  • Java微服务线程隔离技术对比:线程池隔离 vs 信号量隔离
  • union all 关联查询
  • OpenAI发布GPT-4.1:开发者专属模型的深度解析 [特殊字符]
  • 无服务器架构(Serverless)在Web开发与云原生中的应用研究
  • 外接键盘与笔记本命令键键位不同解决方案(MacOS)
  • 蓝桥杯 1.路径之谜
  • 利用quartus的DDS函数信号发生器设计
  • jdk 安装
  • 一、小白如何用Pygame制作一款跑酷类游戏(成品展示+添加背景图和道路移动效果)
  • 嵌入式面试题:C 语言基础重点总结
  • Flutter 图标和按钮组件
  • 基于RV1126开发板下的WIFI的AP模式配置
  • 【vue3】vue3+express实现图片/pdf等资源文件的下载
  • 北京顺义:做好潮白河大桥事故善后处置,举一反三排查风险
  • 中华人民共和国和阿塞拜疆共和国关于建立全面战略伙伴关系的联合声明
  • 日方炒作中国社会治安形势不佳,外交部:政治操弄意图明显
  • 护航民营企业出海,上海设37家维权工作站、建立近百人专家团队
  • 中方决定对在涉港问题上表现恶劣的美国国会议员、官员和非政府组织负责人实施制裁
  • 复旦大学史地学系在北碚