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的更多相关文章

  1. dll文件32位64位检测工具以及Windows文件夹SysWow64的坑

    自从操作系统升级到64位以后,就要不断的需要面对32位.64位的问题.相信有很多人并不是很清楚32位程序与64位程序的区别,以及Program Files (x86),Program Files的区别 ...

  2. dll文件32位64位检测工具以及Windows文件夹SysWow64的坑(很详细,还有自动动手编程探测dll)

    阅读目录 dll文件不匹配导致数据库无法启动 究竟是System32还是SysWow64 区分dll文件32位64位的程序让我倍感迷惑 再次判断究竟是System32还是SysWow64——意想不到的 ...

  3. dll文件32位64位检测工具以及Windows文件夹SysWow64的坑【转发】

    原文地址:http://www.cnblogs.com/hbccdf/archive/2014/03/09/3590916.html 自从操作系统升级到64位以后,就要不断的需要面对32位.64位的问 ...

  4. [转]oracle odp.net 32位/64位版本的问题

    本文转自:http://www.cnblogs.com/yjmyzz/archive/2011/04/19/2020793.html 如果你的机器上安装了odp.net,且确信machine.conf ...

  5. 错误: 未能完成程序集的安装(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 ...

  6. [转载]使用32位64位交叉编码混淆来打败静态和动态分析工具 - wildsator

    0×00 摘要 混淆是一种能增加二进制分析和逆向工程难度与成本的常用技术.主流的混淆技术都是着眼于使用与目标CPU相同的机器代码,在相同的处理器模式下,隐藏代码并进行控制.本文中引入了一种新的混淆方法 ...

  7. 最新Internet Download Manager (IDMan) 6.25 Build 20 32位 64位注册破解补丁

    0x00 IDMan介绍 Internet Download Manager提升你的下载速度最多达5倍,安排下载时程,或续传一半的软件.Internet Download Manager的续传功能可以 ...

  8. 笔记:C语言数据类型在32位与64位机器上的字节数

    读<深入理解计算机系统> 第二章 信息的表示与处理 32位与64位的典型值,单位字节 声明 32位机器 64位机器 char 1 1 short int int 4 4 long int ...

  9. 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 ...

随机推荐

  1. Ueditor自定义默认宽度高度

    如题. 最近需要使用到网页后台富文本编辑器.经过同学推荐,最后决定使用百度家的Ueditor. 官方地址:http://ueditor.baidu.com/website/ 贴吧地址:ueditor讨 ...

  2. WPF passwordbox 圆角制作

    将以下节点复制到app.xaml的<Application.Resources>节点下 <Style TargetType="PasswordBox">   ...

  3. Android中应用程序如何获得系统签名权限

    有些库的使用条件比较苛刻,要求同一签名的程序才可以获得访问权.此时即便是在AndroidManifest.xml中添加了相应的permission,依旧会得到没有xx访问权限的问题.比如android ...

  4. MYSQL 索引页 结构图

    create table t( a ) not ) default null,primary key(a)); mysql> select * from t; +----+------+ | a ...

  5. 【转】cocos2d-x中锚点设置及定位方式

    http://blog.csdn.net/wayne5ning/article/details/8160506 说在前面:以下是基于cocos2d-2.0-x-2.0.3作的总结 问题 在cocos2 ...

  6. 以非root权限安装nginx及运行

    本章主要讲如何在无root权限(包含无sudo权限)条件下于centos命令行中安装nginx以及在大于1024的端口(这里用8080)上运行. 1. 安装 两种方式,一是下载预编译好的rpm包安装, ...

  7. css动画结束后 js无法修改translated值 .

    由于项目的需要,俺要做一些页面的转场动画. 即将是移动端,肯定是首先css动画了. 结果确发现,css动画中,如果设置animation-fill-mode: both;在动画结束后无法个性trans ...

  8. 【原创教程】JavaScript详解之语法和对象

    JavaScript的好的想法:函数.弱类型.动态对象和一个富有表现力的对象字面量表示法. JavaScript的坏的想法:基于全局变量的编程模型.   好了,不管他是好的还是坏的,都是我的最爱,下面 ...

  9. asp.net各种获取客户端ip方法

    Request.ServerVariables("REMOTE_ADDR") 来取得客户端的IP地址,但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的IP地址,而不是真 ...

  10. 再次回首 TCP Socket服务器编程

    转载:http://www.cnblogs.com/zc22/archive/2010/06/27/1766007.html ------------------ 前言 --------------- ...