Android文件格式

article/2025/11/8 23:51:00

在Android的priv-app目录下发现有oat类型的文件夹
什么是oat

It’s Of Ahead Time, a silly reordering of Ahead Of Time. We went with that because then we say that process of converting .dex files to .oat files would be called quakerizing and that would be really funny.

参考如下文章:

  • 10 - Android formats

When dealing with application development, the main part of the code is usually written in Java. Developers can also write native code (C/C++) through the Java Native Interface (JNI) interface.
In the APK building process, the Java code is eventually transformed in the Dalvik bytecode which is interpreted by the Android Java virtual machine. The Android JVM is different from the implementation by Oracle and, among the differences, it is based on registers whereas the one from Oracle is based on a stack.
在 APK 构建过程中,Java 代码最终转化为 Dalvik 字节码,由 Android Java 虚拟机解释。 Android JVM 与 Oracle 的实现不同,其中不同之处在于它基于寄存器,而 Oracle 的实现基于堆栈。

To produce the Dalvik bytecode, Java sources are first compiled with javac into the Java bytecode and then Android transforms this bytecode into the Dalvik one by using the dx compiler (or the new one: D8). This bytecode is finally wrapped in a DEX file(s) such as classes.dex. The DEX format is specific to Android and the documentation is available here.
为了生成 Dalvik 字节码,首先使用 javac 将 Java 源代码编译成 Java 字节码,然后 Android 通过使用 dx 编译器(或新的编译器:D8)将此字节码转换为 Dalvik 字节码。 这个字节码最终被包装在一个 DEX 文件中,例如 classes.dex

During the installation of the APK, the system applies optimizations on this DEX file in order to speed-up the execution. Indeed interpreting bytecode is not as efficient as executing native code and the Dalvik virtual machine is based on registers that are 32-bits width size whereas most of the recent CPU are 64-bits width.
在安装APK的过程中,系统会对该DEX文件进行优化,以加快执行速度。 实际上,解释字节码不如执行本机代码高效,而且 Dalvik 虚拟机基于 32 位宽度的寄存器,而最近的大多数 CPU 都是 64 位宽度。

To address this issue and prior to Android 4.4 (KitKat), the runtime used JIT compilation to transform Dalvik bytecode into assembly. The JIT ocurred during the execution and it was done each time the application was executed. Since Android 4.4 they moved to a new runtime which, among other features, performs the optimizations during the installation. Consequently the installation takes more time but transformations to native code are done once.
为了解决这个问题,在 Android 4.4 (KitKat) 之前,运行时使用 JIT 编译将 Dalvik 字节码转换为程序集。 JIT 在执行期间发生,并且每次执行应用程序时都会完成。 从 Android 4.4 开始,他们迁移到了新的运行时,除其他功能外,该运行时在安装期间执行优化。 因此,安装需要更多时间,但本地代码的转换只需完成一次。

To optimize the Dalvik bytecode, the original DEX file (e.g. classes.dex) is transformed into another file that will contain the native code. This new file usually has the .odex, .oat extension and is wrapped by the ELF format. Using ELF format makes sense for mainly two reasons:
为了优化 Dalvik 字节码,原始 DEX 文件(例如 classes.dex)被转换为另一个包含本机代码的文件。 这个新文件通常具有 .odex、.oat 扩展名,并以 ELF 格式包装。 使用 ELF 格式的意义主要有两个原因:

  • It’s the default format used by Linux and Android to package assembly code.
  • It enables to use the same loader: /system/bin/linker{64}

OAT files are in fact ELF and this is why, we choose to add this new format in LIEF. This ELF format is actually used as a wrapper over another format which is specific to Android: the OAT format.

DEX are transformed into .odex files that are primarily ELF files wrapping a custom OAT format.
DEX 被转换为 .odex 文件,这些文件主要是封装了自定义 OAT 格式的 ELF 文件。
在这里插入图片描述

The process of converting Java sources into the OAT can be simplified with the following diagram:
在这里插入图片描述

参考:

  • Android Runtime (ART) 和 Dalvik
  • Android Runtime

Android Runtime(缩写为ART),是一种在Android操作系统上的运行环境,由Google公司研发,并在2013年作为Android 4.4系统中的一项测试功能正式对外发布,在Android 5.0及后续Android版本中作为正式的运行时库取代了以往的Dalvik虚拟机。ART能够把应用程序的字节码转换为机器码,是Android所使用的一种新的虚拟机。它与Dalvik的主要不同在于:Dalvik采用的是JIT技术,而ART采用Ahead-of-time(英语:Ahead-of-time compilation)(AOT)技术。ART同时也改善了性能、垃圾回收(Garbage Collection)、应用程序出错以及性能分析。
JIT最早在Android 2.2系统中引进到Dalvik虚拟机中,在应用程序启动时,JIT通过进行连续的性能分析来优化程序代码的执行,在程序运行的过程中,Dalvik虚拟机在不断的进行将字节码编译成机器码的工作。与Dalvik虚拟机不同的是,ART引入了AOT这种预编译技术,在应用程序安装的过程中,ART就已经将所有的字节码重新编译成了机器码。应用程序运行过程中无需进行实时的编译工作,只需要进行直接调用。因此,ART极大的提高了应用程序的运行效率,同时也减少了手机的电量消耗,提高了移动设备的续航能力,在垃圾回收等机制上也有了较大的提升。为了保证向下兼容,ART使用了相同的Dalvik字节码文件(dex),即在应用程序目录下保留了dex文件供旧程序调用,然而.odex文件则替换成了可执行与可链接格式(ELF)可执行文件。一旦一个程序被ART的dex2oat命令编译,那么这个程序将会只通过ELF可执行文件来运行。因此,相对于Dalvik虚拟机模式,ART模式下Android应用程序的安装需要消耗更多的时间,同时也会占用更大的内部储存空间,用于储存编译后的代码,但节省了很多Dalvik虚拟机用于实时编译的时间。

预先 (AOT) 编译
ART 引入了预先编译机制,可提高应用的性能。ART 还具有比 Dalvik 更严格的安装时验证。
在安装时,ART 使用设备自带的 dex2oat 工具来编译应用。此实用工具接受 DEX 文件作为输入,并为目标设备生成经过编译的应用可执行文件。该工具应能够顺利编译所有有效的 DEX 文件。但是,一些后处理工具会生成无效文件,Dalvik 可以接受这些文件,但 ART 无法编译这些文件。如需了解详情,请参阅处理垃圾回收问题。


http://chatgpt.dhexx.cn/article/iOKKXjUp.shtml

相关文章

Android项目打包生成apk文件

Android开发打包生成APK文件 打包apk文件分为两种 无需密钥的apk有密钥的apk(常规) 他们的区别只是就是安全问题。 1.没有密钥的apk 点击之后会自动生成没有密钥的APK。 在编辑器的右下角会出现该弹窗,点击location会帮你找到该文件 2.有密钥的APK 1.找到bui…

Java利用mpxj解析mpp格式文件

转载请注明来源:http://blog.csdn.net/loongshawn/article/details/51038051 《Java利用mpxj解析mpp格式文件》《SpringBoot添加Email发送功能》《SpringBoot配置log4j输出日志》《SpringBoot定时任务说明》《SpringBoot接口服务处理Whitelabel Error Page》《构建…

java解析mpp文件(包含层级关系)

我用的是递归循环的&#xff0c;不限制有多少子级关系都可以拿到 首先引入解析mpp所需依赖 <dependency><groupId>net.sf.mpxj</groupId><artifactId>mpxj</artifactId><version>7.1.0</version></dependency>解析所用实体类…

Date转换年月日

timebasic.js //时间戳转年月日 export function format(shijianchuo) {//shijianchuo是整数&#xff0c;否则要parseInt转换var time new Date(shijianchuo);var y time.getFullYear();var m time.getMonth() 1;m m < 10 ? "0" m : m;var d time.getDate…

C# 接口中DateTime类型字段返回年月日格式,去掉时分秒的数据

背景 在我们平时写接口的时候&#xff0c;避免不了这样一个问题&#xff0c;数据库中存的字段类型为datetime,代码中对应的实体类也是DateTime类型的字段&#xff0c;于是在读取数据库内容之后返回的数据也是DateTime类型的值&#xff0c;比如2022-10-24 18:34:56.110&#xf…

vue3-用dayjs将时间戳转为年月日格式

已知&#xff0c;格式化时间&#xff1a;dayjs(cellValue).format(YYYY-MM-DD) 用法&#xff1a; import dayjs from dayjs;dayjs(时间戳).format(YYYY-MM-DD HH:mm:ss); 如&#xff0c;在get请求中使用&#xff1a; service.get(/trace/sourceSearchInput.value).then(res …

Java但中获取时间将时间转换成字符串格式(年月日格式)

一:直接上马拿走&#xff1a; package cn.wyj.one;import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date;/*** 测试时间对象和字符串之间的相互转化* DateFormat抽象类和SimpleDateFormat实现类的使用* author 86155**/public class Demo2…

Excel修改日期格式:日月年-年月日

最近处理数据&#xff0c;遇到需要处理一下日期格式&#xff0c;记一下。。。 1、原格式 2、新建Excel表&#xff0c;复制到表中&#xff0c;选择列&#xff0c;数据-分列&#xff0c;下一步…,选择列格式为“DMY”,点击完成 3、效果(若不成功&#xff0c;可以试一试其他的)

各种加密证书

证书相关知识 PFX文件属于数字证书。pfx数字证书既包含有公钥又包含私钥&#xff0c;cer | crt数字证书只包含公钥。参考 JKS&#xff08;Java Key Store&#xff09;就是利用Java Keytool 工具生成的Keystore文件&#xff0c;JKS文件由公钥和密钥构成&#xff0c;其中的公钥…

公钥,私钥,数字签名,证书

今天&#xff0c;我读到一篇好文章。 它用图片通俗易懂地解释了&#xff0c;"数字签名"&#xff08;digital signature&#xff09;和"数字证书"&#xff08;digital certificate&#xff09;到底是什么。 我对这些问题的理解&#xff0c;一直是模模糊糊…

国密SSL证书保障网站安全

国内很多网站为了网站安全都会部署SSL证书&#xff0c;目前市面上申请到的SSL服务器证书基本都是采用RSA国际算法&#xff0c;市场上80%的SSL服务器证书都是由国外CA尤其是美国为主的CA签发的证书。 网络安全就是国家安全&#xff0c;网络安全的对手也已经不仅仅是黑客&#xf…

构建用于签名/加密双证书测试体系的可执行命令

注意事项 生成证书请求的填写 范例Subject: C CN, ST Beijing, L Beijing, O MSI, OU msi, CN ca, emailAddress cagmssl.com 前面的步骤存在错误&#xff0c;后面改用脚本进行证书生成&#xff0c;阅读时请跳过前面错误的内容 错误的内容 -> 开始 CA 生成私钥 o…

来此加密证书申请,验证,自动部署

之前用certbot, 后来一直不报错, 证书不管用, 就想着干脆直接使用来此加密, 不要中间商了, 就有了直接到来此加密注册之旅 注册地址: 来此加密https://letsencrypt.osfipin.com/user-0408/order/list附上这两年的"战绩" 申请这么多证书主要原因是, 测试域名太多, 一…

加密和数字证书

目录 一 KPI概述二 KPI应用1 内容安全加密2 加密文件3 使用非对称加密对称加密密钥4 非对称加密的缺点5 数字签名6 数字证书7 时钟服务8 私钥使用者认证9 总结附&#xff1a;U盾的工作原理介绍 三 详解公钥、私钥、数字证书的概念1 加密和认证2 公钥和私钥3 证书4 总结5 签名证…

加密解密和CA证书杂记

最近两三个月&#xff0c;断断续续的一直在处理CA证书相关的事情。CA证书本质上也是一种加解密&#xff0c;因此就自然而然的涉及到一些加密和解密的技术&#xff0c;这就让我在了解CA的同时&#xff0c;也对加密和解密有了更进一步的认识和理解。 以下便是一个比较杂&#xff…

证书和加解密

刚进公司&#xff0c;在实习期需要了解很多关于加解密算法和证书相关的东西&#xff0c;我以写博客的方式把我近1个多月了解的东西整理出来传授给大家&#xff0c;大家觉得可以的话请不要吝啬你们的赞。 目录 什么是PKI 证书申请流程 加密与解密 签名认证 数字信封 数字…

HTTPS(对称加密+非对称加密+证书)

目录 1. 加密和解密 HTTPS工作过程 2. 对称加密 3. 对称加密 4. 既然都有非对称加密了,那为啥还要有对称加密 5. 中间人攻击 6. 引入证书 HTTPS 也是一个应用层协议. 是在 HTTP 协议的基础上引入了一个加密层. HTTP 协议内容都是按照文本的方式明文传输的. 这就导致在…

非对称加密与数字证书

文章目录 1 非对称加密2 数字签名3 数字证书4 数字签名和数字证书的区别5 CA 认证中心如何保证权威性6 HTTPS 协议7 HTTPS 与 SSL8 为什么不一直使用HTTPS 1 非对称加密 非对称加密&#xff0c;是指不能从加密密钥推算出解密密钥。加密密钥不需要保密&#xff0c;可以公开&…

安全和加密CA证书

一、介绍 1、为什么要加密 ※ 不加密流量的易受攻击性 ● 密码/数据嗅探 ● 数据操作 ● 验证操作 ● 相当于邮寄明信片 ※ 不安全的传统协议 --明文 ● telnet、FTP、POP3等等&#xff1b;不安全密码 ● http.smtp、…

安全-加密与证书

对称加密 在对称加密中&#xff0c;加密和解密使用的是同一个密钥&#xff0c;即&#xff1a;使用相同的密钥对密文进行加密和解密 比如&#xff1a;A和B&#xff0c;A和B保存同一个密钥&#xff0c;A使用这个密钥对明文进行加密&#xff0c;发送给B&#xff0c;B再使用这个密…