检测目标程序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-21
只编译64位的版本,如果系统无法跑64位程序,证明整个系统都是32位的
Android.mk
# Copyright (C) 2009 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 < 0){printf("invalid process id\n");return -1;}char auxv[256];snprintf(auxv, 256, "/proc/%d/auxv", pid);int fd = open(auxv, O_RDONLY);if(fd < 0){printf("%s does not exist\nprocess %d maybe running in 32 bit elf mode", auxv, pid);return 0;}const int SIZE = 16;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[4] && buf[5] && buf[6]){printf("process %d running in 32 bit elf mode @ line %d\n", pid, __LINE__);printf("%x, %x, %x, %x\n", buf[4], buf[5], buf[6], buf[7]);break;}else if(buf[7]){printf("process %d running in 32 bit elf mode\n", pid);break;}} while(1);close(fd);return 0; }int main(int argc, char* argv[]) {if(argc <= 1){printf("usage:auxv pid1 [pid2 pid3 ...]\n");return 0;}int i = 0;for(i = 1; i < argc; ++i){int pid = atoi(argv[i]);check_auxv(pid);}return 0; }
编译命令
call ndk-build NDK_PROJECT_PATH=. NDK_APPLICATION_MK=./Application.mk
目录结构
|---Application.mk |---build.bat |---jni ||---Android.mk ||---auxv.c
转载于:https://www.cnblogs.com/jojodru/p/5564059.html
检测目标程序ELF bit是32还是64相关推荐
- dll文件32位64位检测工具以及Windows文件夹SysWow64的坑
自从操作系统升级到64位以后,就要不断的需要面对32位.64位的问题.相信有很多人并不是很清楚32位程序与64位程序的区别,以及Program Files (x86),Program Files的区别 ...
- Centos版本 32或64位查看命令
1.uname -a 查看OS详细信息 2. file /bin/ls 显示系统程序信息,就能看出多少位 3.获得机器字长 getconf LONG_BIT 4.查看OS版本 cat /proc/v ...
- 32位与64位下各类型长度对比
64 位的优点:64 位的应用程序可以直接访问 4EB 的内存和文件大小最大达到4 EB(2 的 63 次幂):可以访问大型数据库.本文介绍的是64位下C语言开发程序注意事项. 1. 32 位和 64 ...
- linux内核学习之三:linux中的32位与64位
linux内核学习之三:linux中的"32位"与"64位" 在通用PC领域,不论是windows还是linux界,我们都会经常听到"32位" ...
- Android编译32或64位程序
★★★ 个人博客导读首页-点击此处 ★★★ 1.查看一个程序是32位还是64位: $ readelf -h tee-supplicant ELF Header: Magic: 7f 45 4c 46 ...
- 渲染终极者 finalRender R3.5 SE for 3ds max/design 2009/2010/2011 32位/64位 汉
中文名: 终级渲染器 渲染终极者 finalRender R3.5 SE for 3ds max/design 2009/2010/2011 32位/64位 顶渲简体中文版 资源格式: 压缩包 版本: ...
- android sdk64位资源,android SDK 有32位或64位的分别吗
android环境下搞开发工作,原来用的是32位的(操作系统32位.Eclipse.JDK 都是32位). 现在换了win7 64位系统, Eclipse.JDK 有32位或64位的, 问一下,and ...
- 查看linux版本32还是64位,查看linux系统版本是32位的还是64位的
一. [root@linuxzgf ~]#getconf LONG_BIT [root@linuxzgf ~]#getconf WORD_BIT (32位的系统中int类型和long类型一般都是4字节 ...
- 深度技术ghost win8 32位/64位装机旗舰版V2014
深度技术ghost win8 32位装机旗舰版V2014下载地址:http://pan.baidu.com/s/1kTLqJLt 深度技术ghost win8 64位装机旗舰版V2014下载地址:ht ...
- linux系统32和64的区别,32位和64位的Linux系统区别
区别之一:当初设计的定位不同 64位操作系统的设计定位是:满足机械设计和分析.三维动画.视频编辑和创作,以及科学计算和高性能计算应用程序等领域,这些应用领域的共同特点就是需要有大量的系统内存和浮点性能 ...
最新文章
- 实战 | 多种方法实现以图搜图
- 关于分库分表,这有一套大而全的轻量级架构设计思路
- QIIME 2教程. 19使用q2-vsearch聚类ASVs为OTUs(2020.11)
- 2014 网选 5024 Wang Xifeng's Little Plot
- Superior Scheduler:带你了解FusionInsight MRS的超级调度器
- (50)IO的延迟约束(输入延迟约束)
- 冯仕堃:预训练模型哪家强?百度知识增强大模型探索实践!
- Linux acpi off学习的必要
- 解决办法:Error:java: Compilation failed: internal java compiler error
- java多线程写数据到数据库6_java多线程向数据库写入数据
- keil5怎么放大字体_keil5如何设置字体大小-keil设置字体大小的方法
- C++实现 利用前序序列和中序序列构建二叉树
- 国密SM2非对称算法与实现
- 如何用burpsuite和手机模拟器给apk抓包
- 记录贴:学习Andorid开发
- Ambarella : 一家伟大的视频压缩处理芯片厂商
- linux7.1装宝塔,CentOS 7.6 宝塔 + SSRPanel 安装
- python 请在微信客户端打开_完美解决 请在微信客户端打开链接
- python 拼音识别_python识别一段由字母组成的字符串是否是拼音
- 小米计算机无法清除,小米蓝牙怎么删除不常用设备
热门文章
- springboot开启缓存_springBoot与缓存使用
- gpu云服务器运行游戏_99元起!华为云鲲鹏云手机正式发布:流畅运行大型游戏...
- 熔断机制什么意思_什么是“熔断机制”,为什么交易所需要它?看完你就明白了!...
- 【cf-edu-round72: C 】The Number Of Good Substrings(思维)
- oracle 自治事务异常不回滚,ORA-06519: 检测到活动的自治事务处理,已经回退
- 孝感高考成绩2021分数查询,孝感教育局官网2021年大悟中考分数查询成绩查分
- java shell文件_Java 文件读写示例1
- 价值连城 ImageNet图像分类大神 Andrej Karpathy的采访 给AI 深度学习从业者的建议
- 手动安装ipa,通过XCode手动安装包iOS App, ipa Devices and Simulators
- 算法:回溯十八 Factor Combinations 因子组合(3种解法)