首页 技术 正文
技术 2022年11月14日
0 收藏 608 点赞 4,139 浏览 2898 个字

的参考文章:

http://www.cnblogs.com/fishou/p/4202061.html

1.download upx和所依赖的组件

upx3.:https://www.pysol.org:4443/hg/upx.hg/archive/tip.tar.gzLZMA4.:http://nchc.dl.sourceforge.net/project/sevenzip/LZMA%20SDK/4.43/lzma443.tar.bz2UCL1.:http://www.oberhumer.com/opensource/ucl/download/ucl-1.03.tar.gzZLIB1..3http://pkgs.fedoraproject.org/repo/pkgs/zlib/zlib-1.2.3.tar.gz/debc62758716a169df9f62e6ab2bc634/zlib-1.2.3.tar.gz

2.解压到/home/local/upx下

 root@study:/home/local/upxmake# ll 总用量  drwxr-xr-x   root root    8月  : ./ drwxr-xr-x   root root    8月  : ../ drwxr-xr-x   root root    8月  : lzma443/ drwxrwxrwx  jack users   7月    ucl-1.03/ drwxr-xr-x   root root    8月  : upx-hg-22a77e02b61f/ drwxr-xr-x          7月    zlib-1.2./

3.设置环境变量

export UPX_ZLIBDIR=/home/local/upxmake/zlib-1.2./export UPX_DIR=/home/local/upxmake/upx-hg-22a77e02b61f/export UPX_LZMA_VERSION=0x443export UPX_UCLDIR=/home/local/upxmake/ucl-1.03/export UPX_LZMADIR=/home/local/upxmake/lzma443/

注:这种方式设置的环境变量只在当前shell环境下有效 当我们在另外一个shell环境下输入:env |grep UPX是没有显示结果的

4.进入到/home/local/upxmake/upx-hg-22a77e02b61f/的根目录下make all进行编译

  如果在编译的过程中提示:找不到zlib.h 这个错误是因为zlib包没有安装,安装后问题即可解决。但有一点请注意安装命令是:

  sudo apt-get install zlib1g-dev,而非sudo apt-get install zlib

  如果提示 usr/bin/ld: cannot find -lucl 参考:http://www.jb51.net/LINUXjishu/211594.html

  usr/bin/ld: cannot find -lxxx错误的通用解决方法

执行:apt-get install libucl-dev即可

5.编译成功的话 在$(UPX_ROOT)|src下生成一个upx.out的文件

root@study:/home/local/upxmake# ./upx-hg-22a77e02b61f/src/upx.outUltimate Packer for eXecutablesCopyright (C)  - UPX 3.92        Markus Oberhumer, Laszlo Molnar & John Reiser  Mar 30th Usage: upx.out [-123456789dlthVL] [-qvfk] [-o file] file..Commands:-    compress faster                  -    compress better-d    decompress                        -l    list compressed file
.....................UPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.sf.net

使用UPX进行android so加固

在native代码中:

1.在native代码中定义全局变量用于增加生成的二进制的体积,否则会提示错误:

   编译UPX出现“NotCompressibleException”错误。

分析:UPX对被加壳的二进制文件有最小限制,太小的文件将无法被加壳。

解决方案:在native代码中定义足够大的数据变量,使得编译出来的二进制文件容易达          到UPX的要求

         C:int const dummy_to_make_this_compressible[] = {,,};         C++:extern "C" int const dummy_to_make_this_compressible[] = {,,};

2.要加壳的so需要有_init段

    编译UPX出现“UnknownExecutableFormatException”错误。

分析:被加壳的二进制文件必须存在init段,否则UPX将无法脱壳还原原始代码。

解决方案:在native代码中定义_init()方法,需要注意C和C++的区别

 //在native代码添加_init段
void _init(void)
{
}

注:_init并非区段,只是一个导出函数.NDK会生成对应的区段并融合在某个大区段中,所以你从区段表看不到它

我们以一个简单的例子libhello.so为例子hello.c代码如下

#include <jni.h>
void _init(void)
{ }/** jni规定 本地方法名 Java_调用本地方法类所在的包名_类名_方法名
* JNIEnv * env java环境,提供函数供调用
* jobject obj 调用本地方法的对象
*
* typedef const struct JNINativeInterface* JNIEnv;
* JNIEnv <=> struct JNINativeInterface*
* env : JNIEnv * <=> struct JNINativeInterface**
* (*env)->NewStringUTF();
*/
jstring Java_com_itheima_helloworld_MainActivity_helloFromC(JNIEnv *env, jobject obj){ // 把C字符串转化为java中字符串
return (*env)->NewStringUTF(env,"hello world");
}

用readelf工具查看libhello.so是否有_init段

正如前面所说的 section table没有_init段

readelf -S libhello.so

ubuntu14.04 x86编译upx 3.92 及so加固

使用readelf -d libhello.so 可以看到_INIT

ubuntu14.04 x86编译upx 3.92 及so加固

将libhello.so放在  ($UPX_ROOT)|src目录下进行加壳 执行

ubuntu14.04 x86编译upx 3.92 及so加固

ubuntu14.04 x86编译upx 3.92 及so加固

使用upx加壳的so的section table被抹除了

ubuntu14.04 x86编译upx 3.92 及so加固

我们用IDA对比下libhello.so加密的效果

未加密效果:代码是赤裸裸的啊

ubuntu14.04 x86编译upx 3.92 及so加固

upx加密后:

1.section table信息抹除了

ubuntu14.04 x86编译upx 3.92 及so加固

2.看下jni函数

 ubuntu14.04 x86编译upx 3.92 及so加固

反编译看下:

ubuntu14.04 x86编译upx 3.92 及so加固

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,817
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,900