|
【技术讨论】
哪位大佬知道update.img的头部信息如何修改
发表于 2021-3-3 14:19:10
浏览:7991
|
回复:0
打印
只看该作者
[复制链接]
楼主
- //解析固件,获得固件头部信息
- int analyticImage(const char *filepath, PRKIMAGE_HDR phdr) {
- long long ulFwSize;
- STRUCT_RKIMAGE_HEAD rkimage_head;
- unsigned char m_md5[32];
- int fd = open(filepath, O_RDONLY);
- if (fd < 0) {
- LOGE("Can't open %s\n", filepath);
- return -2;
- }
- //1. image 头部信息读取
- if (read(fd, &rkimage_head, sizeof(STRUCT_RKIMAGE_HEAD)) != sizeof(STRUCT_RKIMAGE_HEAD)) {
- LOGE("Can't read %s\n(%s)\n", filepath, strerror(errno));
- close(fd);
- return -2;
- }
- [color=Red] if ((rkimage_head.reserved[14]=='H')&&(rkimage_head.reserved[15]=='I'))[/color] {
- ulFwSize = *((DWORD *)(&rkimage_head.reserved[16]));
- ulFwSize <<= 32;
- ulFwSize += rkimage_head.dwFWOffset;
- ulFwSize += rkimage_head.dwFWSize;
- } else {
- ulFwSize = rkimage_head.dwFWOffset + rkimage_head.dwFWSize;
- }
- rkimage_head.dwFWSize = ulFwSize - rkimage_head.dwFWOffset;
- display_head(&rkimage_head);
- //2. 固件md5 校验
- long long fileSize;
- int nMd5DataSize;
- fileSize = lseek64(fd, 0L, SEEK_END);
- nMd5DataSize = fileSize - ulFwSize;
- if (nMd5DataSize >= 160) {
- LOGE("md5 : not support sign image.\n");
- //sign image
- //m_bSignFlag = true;
- //m_signMd5Size = nMd5DataSize-32;
- //fseeko64(m_pFile,ulFwSize,SEEK_SET);
- //fread(m_md5,1,32,m_pFile);
- //fread(m_signMd5,1,nMd5DataSize-32,m_pFile);
- } else {
- lseek64(fd, -32, SEEK_END);
- if ( read(fd, m_md5, 32) != 32) {
- LOGE("lseek failed.\n");
- return -2;
- }
- }
- //3. image 地址信息读取
- if (lseek64(fd, rkimage_head.dwFWOffset, SEEK_SET) == -1) {
- LOGE("lseek failed.\n");
- return -2;
- }
- if (read(fd, phdr, sizeof(RKIMAGE_HDR)) != sizeof(RKIMAGE_HDR)) {
- LOGE("Can't read %s\n(%s)\n", filepath, strerror(errno));
- close(fd);
- return -2;
- }
- if (phdr->tag != RKIMAGE_TAG) {
- LOGE("tag: %x\n", phdr->tag);
- LOGE("Invalid image\n");
- return -3;
- }
- if (rkimage_head.dwFWOffset) {
- adjustFileOffset(phdr, rkimage_head.dwFWOffset, rkimage_head.dwBootOffset, rkimage_head.dwBootSize);
- }
- display_hdr(phdr);
- close(fd);
- #if 1
- if (!compareMd5sum((char*)filepath, m_md5, 0, fileSize-32)) {
- LOGE("Md5Check update.img fwSize:%ld", fileSize-32);
- return -1;
- }
- #endif
- LOGI("analyticImage ok.\n");
- return 0;
- }
复制代码 |
|