upx工具编译使用指导

网络上有现成的upx工具,在github上面:https://github.com/upx/upx/releases 根据自己的操作系统和cpu选择相应的工具。下载下来就可以使用。

下面是说我在编译时遇到的一些问题:

下载的包是upx-3.94.tar.gz

tar -zxvf upx-3.94.tar.gz 解压到当前文件夹
进入解压目录执行命令:

make all

出现问题1:

ubuntu@ubuntu-ThinkPad-X220:~/upx/process/upx-3.94$ make all make -C
src all make[1]: Entering directory
/home/ubuntu/upx/process/upx-3.94/src' ../src/stub/src/c/Makevars.lzma:12: *** ERROR: missing directory src/lzma-sdk/; visit https://github.com/upx/upx-lzma-sdk . Stop. make[1]: Leaving directory/home/ubuntu/upx/process/upx-3.94/src’
make: *** [all] Error 2

显示没有src的lzma-sdk目录,错误中有提示信息要求访问网站并下载。
下载之后的upx-lzma-sdk-master.zip,并解压出现目录upx-lzma-sdk-master。将目录改名成lzma-sdk,并放到upz-3.94/src目录下,再执行命令make all。

出现问题2:

In file included from c_file.cpp:29:0: conf.h:140:6: error: #error
“please upgrade your UCL installation”
error “please upgrade your UCL installation”
^

#error是c++预处理指令,当编译器处理到该指令时将停止编译并输出错误信息。

查看上下文:

if !defined(UCL_VERSION) || (UCL_VERSION < 0x010300L) error “please
upgrade your UCL installation” endif

发现是没有设置UCL_VERSION。需要下载ucl安装包,到链接http://www.oberhumer.com/opensource/ucl/download/ucl-1.03.tar.gz,下载ucl解压,并编译
./configure
make
然后命令行中输入
export UPX_UCLDIR=/home/ubuntu/upx/process/ucl-1.03
再次执行命令make all
出现问题3:

ERROR: binary file detected ./src/c_file.o: ELF>�@@ GCC: (Ubuntu
4.8.4-2ubuntu1~14.04.3) 4.8.4.symtab.strtab.shstrtab.text.data.bss.comment.note.GNU-stack@!@@,0@,5llE��

��c_file.cppmake[1]: *** [upx.out] Error 1 make[1]: *** Deleting file upx.out' make[1]: Leaving directory/home/ubuntu/upx/process/upx-3.94/src’ make: ***
[all] Error 2

出现这种问题,就修改home/ubuntu/upx/process/upx-3.94/src/stub/scripts/check_whitespace.sh,将下面的语句全部注释掉

#print("$ARGV\n");
if (m,[\x00\x01\x02\xfe\xff],) { print “ERROR: binary file detected $ARGV: $"; exit(1); }
if (m,[\r\x1a],) { print "ERROR: DOS EOL detected $ARGV: KaTeX parse error: Expected 'EOF', got '}' at position 14: _"; exit(1); }̲ if (m,([ \…,) {
# allow exactly two trailing spaces for GitHub flavoured Markdown in .md files
if ($1 ne " " || KaTeX parse error: Can't use function '\.' in math mode at position 11: ARGV !~ m,\̲.̲md,) {
print "ERROR: trailing whitespace detected $ARGV: KaTeX parse error: Expected 'EOF', got '}' at position 22: …it(1); }̲ } if (…ARGV =~ m,(^|/)(gnu|m)?make(file|vars),i) { }
elsif (KaTeX parse error: Can't use function '\.' in math mode at position 18: …GV =~ m,/tmp/.*\̲.̲(disasm|dump),) { }
elsif (KaTeX parse error: Undefined control sequence: \w at position 37: …rc/arch/.*/lzma\̲w̲+\.S,) { }
else { print "ERROR: hard TAB detected $ARGV: $
”; exit(1); }
}

然后再执行编译make all。
就出现了可执行文件

ubuntu@ubuntu-ThinkPad-X220:~/upx/process/upx-3.94/src$ ls -l upx.out
-rwxrwxr-x 1 ubuntu ubuntu 2082496 10月 21 10:17 upx.out

用./upx.out -h 查看用法,其中最简单用法:
./upx.out -o liboutput.so libinput.so

参考事项:

1.交叉编译:

如果是交叉编译,需要修改upx下面src/Makefile文件将

toolchain

CXX ?= g++
中的CXX改成你要用的编译工具链

2.无so源码的upx加壳:

so加壳涉及到很多修改so库源码的地方,见参考链接。如果手头上没有so库源码。那么针对jni生成的so文件,可以修改upx中的p_lx_elf.cpp文件,将

if (/jni_onload_sym ||/ elf_find_dynamic(Elf32_Dyn::DT_INIT)) {
改成
if (jni_onload_sym || elf_find_dynamic(Elf32_Dyn::DT_INIT)) {

修改后的也是可以对jni的so库文件加壳。但具体使用中有没有问题,可不敢保证。
对于非jni的so库文件,如果没有源码,基本上加不了壳的。
————————————————
版权声明:本文为CSDN博主「sunyoop」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sunyoop/article/details/78301268

发布了11 篇原创文章 · 获赞 0 · 访问量 343

猜你喜欢

转载自blog.csdn.net/qq_37316433/article/details/104460884