qnx efs文件系统binary修复

来源:互联网 发布:centos 离线安装mysql 编辑:程序博客网 时间:2024/04/20 09:39

从spi flash从dump了qnx的固件。进一步提取出efs文件系统

但是使用qnx dumpefs命令导出文件系统时发现结构体异常。

谷歌到了类似问题患者

http://www.openqnx.com/phpbbforum/viewtopic.php?t=3620


H[01] L[FFFF] P[00]
.status=EE8E (WRITE|NO_NEXT|NO_SUPER|NO_SPLIT|BAD|LAST|DIR|BASIC)
.reserve=B2
.text_offset_hi=6C
.text_offset_lo=0018
(text_offset=01B00060)
.text_size=0003
dirent
.status=0200 (STAT)
.struct_size=0000
.first
..logi_unit=0002 ..index=0000
.moves=BA
.namelen=00
.reserve=0073
name="pt?"
stat
.status=FE70 (COMP)
.struct_size=0006
.uid=0000000C
.gid=0006FE0C
.mtime=00402CE6 Wed Feb 18 17:16:38 1970
.ctime=00000003 Thu Jan 1 01:00:03 1970
.mode=FFFFFFFC ?rwsrwsr-T


经过winhex分析,是由于块底的描述信息有误。

具体原因就是 text_offset_hi text_offset_lo的字段的值,系数不一致导致的

dumpefs的系数是4,而文件binary的系数是64,差了16倍导致的。

由于没找到怎么使用dumpefs修正这个系数

因此写了一段程序修复这个错误

块底部的描述信息,由winhex+dumpefs信息分析而来。


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>


void fixhdr(char *sector)
{
    unsigned char *hdr;


    for(hdr = (unsigned char *)sector + 0x10000 - 0x20; hdr > sector ; hdr -= 0x20)
    {
        unsigned char hi;
        unsigned short lo;
        int off, fixoff;


        if(hdr[0] == 0xFF && hdr[1] == 0xFF)
            break;


        hi = hdr[0x13];
        lo = *(unsigned short *)&hdr[0x14];
        off = ((int)hi << 16) | lo;


        fixoff = off * 16;
        lo = fixoff & 0xFFFF;
        hi = fixoff >> 16;
        hdr[0x13] = hi;
        *(unsigned short *)&hdr[0x14] = lo;
        printf("fix %06x -> %06x\n", off, fixoff);
    }
}


int main(int argc, char *argv[])
{
    FILE *fin, *fout;
    char *buf;


    if(argc != 3)
    {
        printf("efsfix [src] [dst]\r\n");
        exit(0);
    }


    fin = fopen(argv[1], "rb");
    if(!fin)
    {
        printf("fopen %s failed\n", argv[1]);
        exit(0);
    }
    fout = fopen(argv[2], "wb");
    if(!fin)
    {
        printf("fopen %s failed\n", argv[1]);
        exit(0);
    }


    buf = malloc(0x10000);
    if(!buf)
    {
        printf("malloc failed\n");
        exit(0);
    }


    while(1)
    {
        int ret;


        printf("read sector...\n");
        ret = fread(buf, 1, 0x10000, fin);
        if(ret != 0x10000)
        {
            printf("fread %d exit\n", ret);
            break;
        }


        fixhdr(buf);


        printf("write sector...\n");
        fwrite(buf, 1, 0x10000, fout);
    }




    free(buf);
    fclose(fin);
    fclose(fout);
}


修复后仍然无法正常dumpefs

这种现象形成的原因可能是 64byte alignment ECC。