首页 > 其他分享 >android antirollback verno 获取方法

android antirollback verno 获取方法

时间:2024-06-06 22:03:14浏览次数:13  
标签:uint64 index rollback param antirollback android verno data size

ReadRollbackIndex.exe 获取

调查avbVBMeta结构体

typedef struct AvbVBMetaImageHeader {
  /*   0: Four bytes equal to "AVB0" (AVB_MAGIC). */
  uint8_t magic[AVB_MAGIC_LEN];

  /*   4: The major version of libavb required for this header. */
  uint32_t required_libavb_version_major;
  /*   8: The minor version of libavb required for this header. */
  uint32_t required_libavb_version_minor;

  /*  12: The size of the signature block. */
  uint64_t authentication_data_block_size;
  /*  20: The size of the auxiliary data block. */
  uint64_t auxiliary_data_block_size;

  /*  28: The verification algorithm used, see |AvbAlgorithmType| enum. */
  uint32_t algorithm_type;

  /*  32: Offset into the "Authentication data" block of hash data. */
  uint64_t hash_offset;
  /*  40: Length of the hash data. */
  uint64_t hash_size;

  /*  48: Offset into the "Authentication data" block of signature data. */
  uint64_t signature_offset;
  /*  56: Length of the signature data. */
  uint64_t signature_size;

  /*  64: Offset into the "Auxiliary data" block of public key data. */
  uint64_t public_key_offset;
  /*  72: Length of the public key data. */
  uint64_t public_key_size;

  /*  80: Offset into the "Auxiliary data" block of public key metadata. */
  uint64_t public_key_metadata_offset;
  /*  88: Length of the public key metadata. Must be set to zero if there
   *  is no public key metadata.
   */
  uint64_t public_key_metadata_size;

  /*  96: Offset into the "Auxiliary data" block of descriptor data. */
  uint64_t descriptors_offset;
  /* 104: Length of descriptor data. */
  uint64_t descriptors_size;

  /* 112: The rollback index which can be used to prevent rollback to
   *  older versions.
   */
  uint64_t rollback_index;

  /* 120: Flags from the AvbVBMetaImageFlags enumeration. This must be
   * set to zero if the vbmeta image is not a top-level image.
   */
  uint32_t flags;

  /* 124: The location of the rollback index defined in this header.
   * Only valid for the main vbmeta. For chained partitions, the rollback
   * index location must be specified in the AvbChainPartitionDescriptor
   * and this value must be set to 0.
   */
  uint32_t rollback_index_location;

  /* 128: The release string from avbtool, e.g. "avbtool 1.0.0" or
   * "avbtool 1.0.0 xyz_board Git-234abde89". Is guaranteed to be NUL
   * terminated. Applications must not make assumptions about how this
   * string is formatted.
   */
  uint8_t release_string[AVB_RELEASE_STRING_SIZE];

  /* 176: Padding to ensure struct is size AVB_VBMETA_IMAGE_HEADER_SIZE
   * bytes. This must be set to zeroes.
   */
  uint8_t reserved[80];
} AVB_ATTR_PACKED AvbVBMetaImageHeader;

发现antirollback 值保存位置在vbmeata.img offset 是112~119

故可以做一个exe文件读取vbmeta.img文件rollback index值,代码如下:

// ReadRollbackIndex.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include "stdio.h"
#include "stdlib.h"
#include <direct.h>
#include "Windows.h"

#define MAX_PATH_LEN 1024

//0x77 <==> 119
#define ROLLBAK_INDEX_OFFSET 0x77

void TcharToChar(const TCHAR * tchar, char * _char)
{
    int iLength;
    //获取字节长度   
    iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);

    //将tchar值赋给_char    
    WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
}

int _tmain(int argc, _TCHAR* argv[])
{
    char currPath[MAX_PATH_LEN] = "\0";

    char fileName[MAX_PATH_LEN] = "\0";
    if(argc > 1)
    {
        TcharToChar(argv[1], fileName);
        printf("transfer filename: %s \n", fileName);
    }


    // get current path
    if (getcwd(currPath, sizeof(currPath)) == NULL){
        printf("getcwd() error");
    };
    //printf(" currPath = %s \n", currPath);

    char vbmetaFileName[MAX_PATH_LEN] = "\0";

    //if(strlen(fileName) > 0){
    if(argc > 1)
        sprintf(vbmetaFileName, "%s\\%s", currPath, fileName);
    }else{
        sprintf(vbmetaFileName, "%s\\vbmeta.img", currPath);
    }
    printf("vbmeta.img file path: %s \n", vbmetaFileName);
    

    // open and read file
    FILE* pVbmetaFile = fopen(vbmetaFileName, "rb");
    if (pVbmetaFile == NULL)
    {
        printf("open %s failed.", vbmetaFileName);
        return -1;
    }

    //文件指针偏移  SEEK_SET初始位置开始偏移
    if(!fseek(pVbmetaFile, ROLLBAK_INDEX_OFFSET, SEEK_SET)){
        int rollbackIndex = fgetc(pVbmetaFile);  
        printf("Rollback Index:    %d\n", rollbackIndex);
    }
    
    // release file handle
    fclose(pVbmetaFile);

    return 0;
}

此段代码经 vs2010  编译验证ok,程序运行结果:

代码中获取

antirollback 获取:

pl阶段获取 pl/lk的version。 需要在校验完LK img后可以呼叫获取:
获取pl ver api:seclib_get_pl_ver
获取LK ver api:get_img_ver

LK阶段获取modem 的img ver:
api: get_img_ver


MTK:
/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/common/avb/libavb/avb_slot_verify.c
io_ret = ops->read_rollback_index(ops, rollback_index_location, &stored_rollback_index);
这里会根据rollback_index_location来读anti-rollback值

/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/common/boot/avb20/load_vfy_boot.c
int load_vfy_boot(uint32_t bootimg_type, uint32_t addr)函数
        ret = record_avb_version(slot_data);
这里会在验证AVB结束后更新anti-rollback ver。

set_avb_otp_ver(AVB_GROUP, (uint32_t)min_ver);

#define AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_LOCATIONS 32


qcom:
LINUX/android/external/u-boot/common/avb_verify.c
 virtual AvbIOResult read_rollback_index(AvbOps* ops,
                                           size_t rollback_index_slot,
                                           uint64_t* out_rollback_index) = 0;
 
 virtual AvbIOResult write_rollback_index(AvbOps* ops,
                                           size_t rollback_index_slot,
                                           uint64_t rollback_index) = 0;
    memset(param, 0, sizeof(param));
      param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT;
      param[0].u.value.a = rollback_index_slot;
      param[1].attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT;
      param[1].u.value.a = (u32)(rollback_index >> 32);
      param[1].u.value.b = (u32)rollback_index;
  
      return invoke_func(ops->user_data, TA_AVB_CMD_WRITE_ROLLBACK_INDEX,
                 ARRAY_SIZE(param), param);

标签:uint64,index,rollback,param,antirollback,android,verno,data,size
From: https://blog.csdn.net/jimbo_lee/article/details/139413270

相关文章

  • aandroid studio 通过intent向另一个界面传输信息
    基本流程和上一篇一样地址:https://www.cnblogs.com/yansans/p/18235968 只是再最后加了一句代码intent.putExtra("name",name.getText().toString());这句代码用键值对比较好理解,是将从前端传递来的name的值命名为“name”并传递给MainActivity2 MainActivity2的后......
  • Android studio后端接收数据步骤
    最近记性越来越差,简单的实验居然磨了我三个小时只好把详细步骤放出来,防止再忘记 前端<?xmlversion="1.0"encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="htt......
  • Android视频开发入门: VideoView、MediaPlayer、 FFmpeg、exoplayer...
    现在,视频功能是越来越普遍的需求。本文将提供一个关于Android视频开发的入门指南,帮助读者快速掌握视频播放、录制和处理等基本功能。1、概述在Android平台上,视频开发主要涉及以下几个方面:视频播放与控制视频录制与处理视频编解码与格式转换视频流媒体与直播接下来,我......
  • Android网络请求:协程+Flow+Retrofit+OkHttp
    在Android开发中,网络请求是一个很常见的任务。随着Kotlin协程和Flow的流行,我们有了新的工具来优雅地处理网络请求。结合Retrofit和OkHttp,我们可以构建一个强大的、易于理解和维护的网络请求框架。一、Kotlin协程与FlowKotlin协程是Kotlin提供的一种轻量级线程管理方式。它......
  • Android课程设计课题题目推荐(安卓期末大作业,毕业设计,Androidstudio)
    博主介绍:本人专注于Android/java/数据库/微信小程序技术领域的开发,以及有好几年的计算机毕业设计方面的实战开发经验和技术积累;尤其是在安卓(Android)的app的开发和微信小程序的开发,很是熟悉和了解;本人也是多年的Android开发人员;希望我发布的此篇文件可以帮助到您;......
  • Android财付通App(完整文件,实验报告,演示视频)
    移动数据库应用开发大作业题目:基于Android平台的理财通软件开发学院:信息工程学院专业:网络工程班号:学生姓名:指导教师:基于android平台的理财通软件开发学生姓名:饶明昌班级:170461指导老师:邬志红摘要:当今我们生活在一个数字信息化的时代,随着GPRS、GSM、CDMA、......
  • 01《android studio开发实战(第三版)》阅读笔记
    第一章:初识AndroidStudio本章介绍AndroidStudio的基本概念和安装步骤,帮助读者快速搭建开发环境。了解AndroidStudio的发展历史和其在Android开发中的地位。安装和配置:详细说明了如何在Windows、Mac和Linux系统上安装AndroidStudio,并进行必要的配置。创建第一个项目:通过......
  • 【Android面试题】请你分别采用递归和非递归对二叉树进行遍历?
    请你分别采用递归和非递归对二叉树进行遍历?这道题想考察什么?1、二叉树的基本原理和遍历的方法?考察的知识点二叉树遍历的基本概念、二叉树的基本原理考生如何回答二叉树的基本概念当然可以!二叉树是一种常见的数据结构,它由一组称为节点的元素构成。每个节点可以有零个......
  • Android应用程序启动源码浅析-(三万字长文慎点&Android14)
    在Android桌面Launcher源码浅析中介绍了Android的桌面程序Launcher是如何响应用户点击事件并启动App的,这篇文章继续介绍App在Android系统层的启动流程。一、启动流程sequenceDiagramparticipantUserparticipantLauncherparticipantActivityManagerService......
  • Android Studio使用ADB远程调试(真机)(通过无线调试)
    准备工作1)设备:笔记本电脑、安卓手机2)设备连接相同网络(如:同个WIFI)3)手机开启开发者模块、USB调试、USB安装ps:本人安卓手机是红米手机,开启开发者模式可参考:https://baijiahao.baidu.com/s?id=1758792460891751075&wfr=spider&for=pc操作步骤1)打开AndroidStudio,通过File->Proje......