代码拉取完成,页面将自动刷新
@think3r
2022-11-15 21:47:18
参考链接 :
由于 GLSL 代码是在运行时编译的, 而输入编译器的是一个 GLSL 字符串源码 那么通常就有如下两种方式来完成:
fread()
读入内存中再编译,
于是我就想能不能将上述两个方法的优点都结合起来? 后来发现, GNU 的 objcopy
工具就能很好的解决这点;
下方 makefile
中的三个选项可生成平台对应的 .o
文件;
-I
表示输入文件的格式;-O
表示输出文件的格式, 这个执行 objcopy
查看其支持的格式;-B
--binary-architecture <arch>
--rename-section .data=.rodata,alloc,load,readonly,data,contents
将 GLSL 代码配置为只读;
const
修饰来保证安全, 否则 GLSL 代码被放置到了只读段, 而使用的指针地址则直接指向了只读段, 修改只读段中的数据会造成程序崩溃. 加入 const 后, 编译器可额外检查代码中静态的修改错误;nm
用来列出目标文件的符号清单,
A
该符号的值是绝对的,在以后的链接过程中,不允许进行改变。这样的符号值,常常出现在中断向量表中,例如用符号来表示各个中断向量函数在中断向量表中的位置;D
该符号位于初始话数据段中。一般来说,分配到 data section 中。R
该符号位于只读数据区。const int test[] = {123, 123}
;则 test
就是一个只读数据区的符号。(存疑)000000000000015f D _binary_src_vertShader_txt_end
000000000000015f A _binary_src_vertShader_txt_size
0000000000000000 D _binary_src_vertShader_txt_start
000000000000015f R _binary_src_vertShader_txt_end
000000000000015f A _binary_src_vertShader_txt_size
0000000000000000 R _binary_src_vertShader_txt_start
--pad-to
和 --gap-fill
则分别表示对齐和对齐的填充
文件大小+1
, 且将最后一个字符填充 0, 来拟合字符串. 否则会出现 fragShader 和 vertShader 混合到一个字符串的情况, 切记!注意: arm 平台下的 size 可能不能使用(引起崩溃), 但可用 start - end
来替代;
makefile
局部:
OBJCOPY=objcopy
GLSL_Files = ./src/fragShader.txt ./src/vertShader.txt
GLSL_Objs := $(GLSL_Files:.txt=.o)
GLSL_Flags := -I binary -O elf64-littleaarch64 -B aarch64
GLSL_Flags += --rename-section .data=.rodata,alloc,load,readonly,data,contents
# expr \( `stat --format=%s $<` + 4 \) / 4 \* 4 是为了计算文件大小, 并向上 4 对齐;
$(GLSL_Objs) : %o : %txt
#echo size is $(shell expr `stat --format=%s $<`)
$(OBJCOPY) $(GLSL_Flags) --pad-to=$(shell expr \( `stat --format=%s $<` + 4 \) / 4 \* 4 ) --gap-fill=0x00 $< $@
$(Target) : $(Objs) $(GLSL_Objs)
$(CC) $(C_Flags) -o $(Target) $(Objs) $(GLSL_Objs) $(LIBS_WithPath)
程序中的使用:
extern const char const _binary_src_vertShader_txt_start[];
extern const char const _binary_src_vertShader_txt_end[];
extern const char const _binary_src_fragShader_txt_start[];
extern const char const _binary_src_fragShader_txt_end[];
uint32_t size = _binary_src_fragShader_txt_end -_binary_src_vertShader_txt_start;
for(uint32_t i = 0; i < size; i++)
{
printf("[%d] ", _binary_src_fragShader_txt_start[i]);
}
printf("\n");
TODO : 加上自定义的混淆和解密工具就 OK 了
clang-format -style=file yuvRender.glsl > shader.c
shader
的命令 :
grep -rs -E "vec3|vec4" -A 15 -B 30 ./classes* --text > out.txt
find . -name "*.so" | xargs grep --text -rs -E "vec3|vec4" -A 15 -B 30
其特点是在 栈空间上进行的操作, 因此会有栈溢出风险, 但兼容 C++11
& C++14
;
ADVobfuscator/Indexes.h:32:45: fatal error: recursive template instantiation exceeded maximum depth of 1024
-ftemplate-depth=35536
但脚本可编译通过, Android Studio 编译失败;
clang++: error: unable to execute command: Illegal instruction: 4
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Android (6317467 based on r365631c1) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project e0caee08e5f09b374a27a676d04978c81fcb1928) (based on LLVM 9.0.8svn)
Target: aarch64-none-linux-android29
Thread model: posix
InstalledDir: /Users/think3r/Library/Android/sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/darwin-x86_64/bin
clang++: note: diagnostic msg: PLEASE submit a bug report to https://github.com/android-ndk/ndk/issues and include the crash backtrace, preprocessed source, and associated run script.
clang++: note: diagnostic msg:
-O0
也看不到相关字符串;此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。