检测目标程序ELF bit是32还是64
android操作系统在5.0之后加入了对64位程序的支持,同时兼容运行32位的进程
android的进程绝大部分是zygote父进程fork出来的子进程
zygote进程fork出来的进程是32位进程
zygote64进程fork出来的进程是64位进程
但是有一些在zygote启动之前的进程,那就是init进程fork出来的,都属于64bit进程
zygote进程在fork出子进程之后,更改了进程的名字(setNiceName)
如果想根据进程名找到进程文件,通过读取elf头的方法来判断目标进程的elf bit
不是太理想
通过man proc查阅文档可以知道,解析目标进程的auxv文件可以判断elf bit
内核支持从2.6开始,android的内核版本在这之后,检测auxv文件判断elf bit是可靠的
先上makefile,Application.mk
APP_ABI := arm64-v8a
APP_PLATFORM := android-
只编译64位的版本,如果系统无法跑64位程序,证明整个系统都是32位的
Android.mk
# Copyright (C) The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS)
LOCAL_MODULE := auxv
LOCAL_SRC_FILES := auxv.c
LOCAL_ARM_MODE := arm
include $(BUILD_EXECUTABLE)
源码auxv.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> /*
* Parsing auxv: if you parse the auxv structure yourself (not relying on the dynamic loader), then there's
* a bit of a conundrum: the auxv structure follows the rule of the process it describes, so sizeof(unsigned
* long) will be 4 for 32-bit processes and 8 for 64-bit processes. We can make this work for us. In
* order for this to work on 32-bit systems, all key codes must be 0xffffffff or less. On a 64-bit system,
* the most significant 32 bits will be zero. Intel machines are little endians, so these 32 bits follow
* the least significant ones in memory. * As such, all you need to do is: * 1. Read 16 bytes from the `auxv` file.
* 2. Is this the end of the file?
* 3. Then it's a 64-bit process.
* 4. Done.
* 5. Is buf[4], buf[5], buf[6] or buf[7] non-zero?
* 6. Then it's a 32-bit process.
* 7. Done.
* 8. Go to 1.
*/ int check_auxv(int pid)
{
if(pid < )
{
printf("invalid process id\n");
return -;
} char auxv[];
snprintf(auxv, , "/proc/%d/auxv", pid);
int fd = open(auxv, O_RDONLY);
if(fd < )
{
printf("%s does not exist\nprocess %d maybe running in 32 bit elf mode", auxv, pid);
return ;
}
const int SIZE = ;
char buf[SIZE];
do {
int nread = read(fd, buf, SIZE);
if(nread < SIZE)
{
printf("process %d running in 64 bit elf mode\n", pid);
break;
} if(buf[] && buf[] && buf[])
{
printf("process %d running in 32 bit elf mode @ line %d\n", pid, __LINE__);
printf("%x, %x, %x, %x\n", buf[], buf[], buf[], buf[]);
break;
}
else if(buf[])
{
printf("process %d running in 32 bit elf mode\n", pid);
break;
}
} while(); close(fd); return ;
} int main(int argc, char* argv[])
{
if(argc <= )
{
printf("usage:auxv pid1 [pid2 pid3 ...]\n");
return ;
}
int i = ;
for(i = ; i < argc; ++i)
{
int pid = atoi(argv[i]);
check_auxv(pid);
} return ;
}
编译命令
call ndk-build NDK_PROJECT_PATH=. NDK_APPLICATION_MK=./Application.mk
目录结构
|---Application.mk
|---build.bat
|---jni
||---Android.mk
||---auxv.c
检测目标程序ELF bit是32还是64的更多相关文章
- dll文件32位64位检测工具以及Windows文件夹SysWow64的坑
自从操作系统升级到64位以后,就要不断的需要面对32位.64位的问题.相信有很多人并不是很清楚32位程序与64位程序的区别,以及Program Files (x86),Program Files的区别 ...
- dll文件32位64位检测工具以及Windows文件夹SysWow64的坑(很详细,还有自动动手编程探测dll)
阅读目录 dll文件不匹配导致数据库无法启动 究竟是System32还是SysWow64 区分dll文件32位64位的程序让我倍感迷惑 再次判断究竟是System32还是SysWow64——意想不到的 ...
- dll文件32位64位检测工具以及Windows文件夹SysWow64的坑【转发】
原文地址:http://www.cnblogs.com/hbccdf/archive/2014/03/09/3590916.html 自从操作系统升级到64位以后,就要不断的需要面对32位.64位的问 ...
- [转]oracle odp.net 32位/64位版本的问题
本文转自:http://www.cnblogs.com/yjmyzz/archive/2011/04/19/2020793.html 如果你的机器上安装了odp.net,且确信machine.conf ...
- 错误: 未能完成程序集的安装(hr = 0x8007000b),.net程序关于使用Oracle.DataAccess.dll不同版本x86和x64问题,即oracle odp.net 32位/64位版本的问题
如果你的机器上安装了odp.net,且确信machine.config也有类似以下结节:(64位+.net 4.0环境下,machine.config可能会有4份,分别对应于.net2.0/4.0的3 ...
- [转载]使用32位64位交叉编码混淆来打败静态和动态分析工具 - wildsator
0×00 摘要 混淆是一种能增加二进制分析和逆向工程难度与成本的常用技术.主流的混淆技术都是着眼于使用与目标CPU相同的机器代码,在相同的处理器模式下,隐藏代码并进行控制.本文中引入了一种新的混淆方法 ...
- 最新Internet Download Manager (IDMan) 6.25 Build 20 32位 64位注册破解补丁
0x00 IDMan介绍 Internet Download Manager提升你的下载速度最多达5倍,安排下载时程,或续传一半的软件.Internet Download Manager的续传功能可以 ...
- 笔记:C语言数据类型在32位与64位机器上的字节数
读<深入理解计算机系统> 第二章 信息的表示与处理 32位与64位的典型值,单位字节 声明 32位机器 64位机器 char 1 1 short int int 4 4 long int ...
- Win7 下用 VS2015 编译最新 openssl(1.0.2j)包含32、64位debug和release版本的dll、lib(8个版本)
Win7 64位系统下通过VS2015编译好的最新的OpenSSL(1.0.2j)所有八个版本的链接库, 包含以下八个版本: 1.32位.debug版LIB: 2.32位.release版LIB: 3 ...
随机推荐
- Microsoft SyncToy 文件同步工具
Microsoft SyncToy SyncToy 是由 微软 推出的一款免费的文件夹同步工具.虽然名字中有一个 Toy,但是大家可千万不要误以为它的功能弱爆了.实际上,我感觉这款软件还真是摆脱了微软 ...
- tar linux 打包 压缩 gzip 命令说明
参数:-c :建立一个压缩档案的参数指令(create 的意思):-x :解开一个压缩档案的参数指令!-t :查看 tarfile 里面的档案! 特别注意,在参数的下达中, c/x/t ...
- 创业公司求IOS、Android攻城狮一枚
地点:北京CBD附近(地铁1号线大望路) 魅力值:送珍贵期权 你要会: 1. IOS或者Android开发 2.可以处理类似微视/秒拍的视频录制功能 3.熟悉jso ...
- 节点类(CCNode)
节点与渲染树 回顾前面的介绍,我们已经知道了精灵.层和场景如何构成一个游戏的框架.精灵属于层,层属于场景,玩家与精灵互动,并导致游戏画面在不同场景中切换.把每个环节拼接在一起,我们得到了一个完整的关系 ...
- GUI之CCControlExtension
Introduction CCControl is inspired by the UIControl API class from the UIKit library of CocoaTouch. ...
- CXF错误:Unsupported major.minor version 51.0,java.lang.UnsupportedClassVersionErro
CXF错误:Unsupported major.minor version 51.0 java.lang.UnsupportedClassVersionError >>>>&g ...
- boost.log要点笔记
span.kw { color: #007020; font-weight: bold; } code > span.dt { color: #902000; } code > span. ...
- (转)css换行样式:word-wrap同word-break的区别
以下是引用片段: word-wrap:break-word; overflow:hidden; 而不是 以下是引用片段: word-wrap:break-word; word-break:break- ...
- 隐藏元素的宽高无法通过原生js获取的问题
1.起源:移动app项目中,页面加载时需要加载国家下拉列表,将隐藏的透明浮层和一个显示加载过程中的框 显示出来,隐藏的透明浮层设置宽高都是100%即可,而这个加载提示框需要先得出它的宽高,然后再根据页 ...
- css3 盒模型
0,前言 在css2.1 之前,我们都熟知的两种盒模型,一种是w3c标准盒模型,另外一种是怪异模式下的盒模型.在css3之前我们一直使用的是标准盒模型,但是标准盒模型的宽度总是需要小心的去使用,稍有不 ...