检测目标程序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 ...
随机推荐
- 备战“软考”之软件project
说到"软件project"就有一种非常纠结的感觉!为什么呢?由于刚进入软考复习阶段,大家都把它放到了"比較"次要的地位,由于已经学过两遍,再加上它没有非常难理解 ...
- Show Global Status 整理
原文来源:MySQL 5.5 Reference Manual 部分翻译取自:<MySQL_5.1中文参考手册> 转载请注明原文链接http://www.cnblogs.com/lenag ...
- angularjs ng-repeat checkbox
<div class="col-md-3" ng-repeat="user in title.UserList"> <p class=&quo ...
- nginx同时监听本机ipv4/ipv6端口
修改nginx.conf配置文件 server { listen ; listen [::]:; } 0.0.0.0 表示本机所有ipv4地址,需要监听特定地址替换即可 [::] 表示本机所有ip ...
- Visual Studio的性能测试工具
vs果然是宇宙最强大的IDE,这句话我经常挂在嘴边,反正觉得它挺强大 整个听技术经理说性能测试,然后我就觉得宇宙最强大的IDE应该 也有测试工具吧,那么我就百度了一下,又看看vs的选项,果然真有一个性 ...
- 浅析Activity不可见与透明
http://blog.csdn.net/lincyang/article/details/6868582 看见标题也许你会有疑问,不可见和透明不是一个意思吗? 从字面上看,这还真是差不多.但在Act ...
- Java写一个简单学生管理系统
其实作为一名Java的程序猿,无论你是初学也好,大神也罢,学生管理系统一直都是一个非常好的例子,初学者主要是用数组.List等等来写出一个简易的学生管理系统,二.牛逼一点的大神则用数据库+swing来 ...
- android - android Couldn't load runtimecore_java from loader
在写Arcgis Android 或百度Android的时候,有时会报诸如,java.lang.UnsatisfiedLinkError:android Couldn't load runtimeco ...
- [Twisted] deferred
Twisted提供一个优雅的实现(Deferred)来管理回调函数. Deferred Object 的结构 Deferred Object包含两个回调函数列表.一个用来保存成功的回调函数,另一个用来 ...
- ios动力特效,最重要的一点 属性保持(写了动力特效但是没效果的原因就在这里)
@property (nonatomic, strong) UIDynamicItemBehavior *square1PropertiesBehavior; @property (nonatomic ...