onekey-sec / ubi_reader

Collection of Python scripts for reading information about and extracting data from UBI and UBIFS images.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The image could not be reproduced with ubireader_utils_info.

jclab-joseph opened this issue · comments

Original file's ubireader_display_info:

UBI File
---------------------
     Min I/O: 512
     LEB Size: 129024
     PEB Size: 131072
     Total Block Count: 601
     Data Block Count: 597
     Layout Block Count: 2
     Internal Volume Block Count: 0
     Unknown Block Count: 2
     First UBI PEB Number: 251

     Image: 1684107937
     ---------------------
        Image Sequence Num: 1684107937
        Volume Name:rootfs
        PEB Range: 0 - 600

        Volume: rootfs
        ---------------------
                Vol ID: 0
                Name: rootfs
                Block Count: 597

                Volume Record
                ---------------------
                        alignment: 1
                        crc: '0x50482322'
                        data_pad: 0
                        errors: ''
                        flags: 0
                        name: 'rootfs'
                        name_len: 6
                        padding: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                        rec_index: 0
                        reserved_pebs: 808
                        upd_marker: 0
                        vol_type: 'dynamic'

generated configurations (by ubireader_utils_info):

[rootfs]
mode = ubi
image = img-1684107937_0.ubifs
vol_type = dynamic
# vol_flags = 0
vol_id = 0
vol_name = rootfs
vol_alignment = 1
vol_size = 104251392
#!/bin/sh
/usr/sbin/ubinize -p 131072 -m 2048 -O 512 -s 512 -x 1 -Q 1684107937 -o img-1684107937.ubi img-1684107937.ini

After extracting the ubifs from the original UBI, I reproduced it with the above command.
But what you see with ubireader_display_info is different.

UBI File
---------------------
     Min I/O: 512
     LEB Size: 129024
     PEB Size: 131072
     Total Block Count: 586
     Data Block Count: 584
     Layout Block Count: 2
     Internal Volume Block Count: 0
     Unknown Block Count: 0
     First UBI PEB Number: 0

     Image: 1684107937
     ---------------------
        Image Sequence Num: 1684107937
        Volume Name:rootfs
        PEB Range: 2 - 585

        Volume: rootfs
        ---------------------
                Vol ID: 0
                Name: rootfs
                Block Count: 584

                Volume Record
                ---------------------
                        alignment: 1
                        crc: '0x50482322'
                        data_pad: 0
                        errors: ''
                        flags: 0
                        name: 'rootfs'
                        name_len: 6
                        padding: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                        rec_index: 0
                        reserved_pebs: 808
                        upd_marker: 0
                        vol_type: 'dynamic'

Also the EC Header is different.

originial
00000000  55 42 49 23 01 00 00 00  00 00 00 00 00 00 00 01  |UBI#............|
00000010  00 00 02 00 00 00 08 00  64 61 72 a1 00 00 00 00  |........dar.....|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 dc 5a 8b 61  |.............Z.a|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00020000  55 42 49 23 01 00 00 00  00 00 00 00 00 00 00 01  |UBI#............|
00020010  00 00 02 00 00 00 08 00  64 61 72 a1 00 00 00 00  |........dar.....|
00020020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00020030  00 00 00 00 00 00 00 00  00 00 00 00 dc 5a 8b 61  |.............Z.a|
00020040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00020200  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00040000  55 42 49 23 01 00 00 00  00 00 00 00 00 00 00 00  |UBI#............|
00040010  00 00 02 00 00 00 08 00  64 61 72 a1 00 00 00 00  |........dar.....|
00040020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00040030  00 00 00 00 00 00 00 00  00 00 00 00 7f cc a3 2d  |...............-|
00040040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00040200  55 42 49 21 01 01 00 00  00 00 00 00 00 00 00 00  |UBI!............|
00040210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00040230  00 00 00 00 00 00 00 00  00 00 00 00 73 b1 ab 57  |............s..W|
00040240  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00040600  e0 c3 46 59 bf 08 a5 15  e8 4f 7c cf aa 47 81 43  |..FY.....O|..G.C|
00040610  7f 9b 99 86 1c 49 3b 7c  d7 4f d5 06 3d 87 e3 9b  |.....I;|.O..=...|
00040620  02 02 00 00 49 00 00 14  01 00 3b e5 28 f2 20 f9  |....I.....;.(. .|
00040630  82 1e c2 93 1c b8 fa ac  b5 26 9d 15 6e ad 45 a5  |.........&..n.E.|
00040640  45 95 63 5b 1b 2c 67 d0  69 81 68 00 43 f4 e0 51  |E.c[.,g.i.h.C..Q|
00040650  4a 5d 0f 35 ca 2f 5d a0  0e 38 85 7e 2e c1 89 66  |J].5./]..8.~...f|
00040660  9b 79 ff e9 17 d0 59 e7  b1 ad c0 82 65 2a 92 ca  |.y....Y.....e*..|
00040670  56 38 72 d1 44 7f 18 e7  f3 ec 06 1f d0 14 c6 55  |V8r.D..........U|
00040680  09 57 ca 93 77 3e eb e0  b7 b0 33 5a 86 97 49 cb  |.W..w>....3Z..I.|
00040690  b4 86 9e de 7b 16 68 bc  82 bd 77 35 05 f9 f0 69  |....{.h...w5...i|
000406a0  43 f0 7a ce 5f 12 73 4e  3b 04 37 24 09 1d 42 67  |C.z._.sN;.7$..Bg|
000406b0  33 d0 94 02 19 1c 48 f5  db b9 fc 64 49 cf 28 25  |3.....H....dI.(%|
000406c0  51 66 a6 62 2d e7 97 39  d3 11 1f b1 67 99 de 5f  |Qf.b-..9....g.._|
000406d0  a1 ac 03 06 cb 15 f9 e1  10 25 9a 54 8d ef 49 6a  |.........%.T..Ij|
000406e0  37 5f f2 16 7c 60 3f d5  64 fe fc c2 6a 57 1f cf  |7_..|`?.d...jW..|
000406f0  01 39 4b bd ae 4d 43 f5  6f 0a 4e 38 28 36 09 3f  |.9K..MC.o.N8(6.?|
00040700  c0 cb ad 4a 53 c7 ca 89  9f 19 57 dc b6 00 73 4e  |...JS.....W...sN|
00040710  2f cf 5c 45 98 e1 3e 0a  34 26 88 0f f5 92 83 2e  |/.\E..>.4&......|
00040720  89 25 d6 31 4b dd 52 9d  84 e5 ff ff ff ff ff ff  |.%.1K.R.........|
00040730  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00040800  31 18 10 06 78 9e 49 99  ec c9 00 00 00 00 00 00  |1...x.I.........|
00040810  00 10 00 00 06 00 00 00  00 00 00 00 00 00 00 00  |................|
00040820  00 08 00 00 00 f8 01 00  48 02 00 00 54 03 00 00  |........H...T...|
00040830  00 00 80 00 00 00 00 00  05 00 00 00 02 00 00 00  |................|
00040840  01 00 00 00 01 00 00 00  08 00 00 00 00 01 00 00  |................|
00040850  04 00 00 00 01 00 00 00  00 00 00 00 00 00 00 00  |................|
00040860  00 00 00 00 00 00 00 00  00 ca 9a 3b 2a 1a c7 d9  |...........;*...|
00040870  3a 59 45 e4 8a e0 34 3a  46 21 b3 08 00 00 00 00  |:YE...4:F!......|
00040880  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00041800  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00060000  55 42 49 23 01 00 00 00  00 00 00 00 00 00 00 00  |UBI#............|
00060010  00 00 02 00 00 00 08 00  64 61 72 a1 00 00 00 00  |........dar.....|
00060020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00060030  00 00 00 00 00 00 00 00  00 00 00 00 7f cc a3 2d  |...............-|
00060040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00060200  55 42 49 21 01 01 00 00  00 00 00 00 00 00 00 01  |UBI!............|
00060210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00060230  00 00 00 00 00 00 00 00  00 00 00 00 d0 27 83 1b  |.............'..|
00060240  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00060600  fb c7 91 30 fe a5 4c cd  84 0c e1 50 44 1c 9e 6e  |...0..L....PD..n|
00060610  0c 6f e8 e3 7c b8 5f 67  6a a0 45 7f 5f e4 e8 10  |.o..|._gj.E._...|
00060620  b5 cd f2 2d b4 f4 b8 9c  44 5e 69 c9 8e 9a f2 e2  |...-....D^i.....|
00060630  3f e0 0a a0 26 a9 14 5a  a2 88 fc 6d 95 5b 39 8e  |?...&..Z...m.[9.|
00060640  d2 70 73 c0 8e 60 6d 4f  4f 36 52 4d d8 53 4e c5  |.ps..`mOO6RM.SN.|
00060650  be 4b e5 a3 61 ba a9 83  ee b4 de 51 7b 35 dd 20  |.K..a......Q{5. |
00060660  d8 8c 33 e0 00 13 c6 d3  8e 84 09 55 21 32 64 6b  |..3........U!2dk|
00060670  bc 5d 7d ae 4a 9f b1 63  05 f9 73 c3 b7 28 c5 2f  |.]}.J..c..s..(./|
00060680  4b 6a 33 23 4b e8 7c 33  4f 2d de c9 d5 b2 c4 51  |Kj3#K.|3O-.....Q|
00060690  9c dc 56 07 db c8 99 02  88 90 b2 8c 68 d7 79 f4  |..V.........h.y.|
000606a0  66 20 ed 01 a0 f8 e2 f6  12 a1 71 98 66 94 10 33  |f ........q.f..3|
000606b0  b0 9a bb 4d c4 67 d3 48  14 91 63 1d 67 7c f4 c2  |...M.g.H..c.g|..|
000606c0  cf 77 33 7a e4 88 57 ae  b6 6f c1 98 59 34 3e f2  |.w3z..W..o..Y4>.|
000606d0  5c c6 e9 1e 05 28 20 4b  a1 42 62 4f 9a 3c 5d cb  |\....( K.BbO.<].|
000606e0  0c 1b 68 6e de f9 6d 67  82 6a d4 e5 99 7a 54 4b  |..hn..mg.j...zTK|
000606f0  16 35 80 fa c1 b1 c4 8e  9a e1 de 91 7c 2e 1b df  |.5..........|...|
00060700  2b c8 98 6a e3 a9 3c 01  d0 c0 ec af 4a 0b f4 16  |+..j..<.....J...|
00060710  02 55 ae c2 dd b7 fc ce  f6 96 0d 2e 48 2d 6e 8c  |.U..........H-n.|
00060720  2d ca 97 d9 86 f9 ac 0a  58 5c ff ff ff ff ff ff  |-.......X\......|
00060730  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00060800  31 18 10 06 73 c8 8c 68  ed c9 00 00 00 00 00 00  |1...s..h........|
00060810  00 02 00 00 07 00 00 00  16 16 00 00 00 00 00 00  |................|
00060820  00 00 00 00 00 00 00 00  02 00 00 00 03 00 00 00  |................|
00060830  47 02 00 00 e0 21 01 00  44 00 00 00 3e 02 00 00  |G....!..D...>...|
00060840  47 02 00 00 00 28 01 00  10 e2 10 00 00 00 00 00  |G....(..........|
00060850  00 48 08 00 00 00 00 00  00 ed 06 00 00 00 00 00  |.H..............|
00060860  f0 00 48 04 00 00 00 00  c8 5e 05 00 00 00 00 00  |..H......^......|
00060870  c8 57 06 00 00 00 00 00  08 00 00 00 d0 0b 00 00  |.W..............|
00060880  08 00 00 00 00 10 00 00  08 00 00 00 dc 0b 00 00  |................|
00060890  00 00 00 00 00 00 00 00  0b 00 00 00 01 00 00 00  |................|
000608a0  09 00 00 00 48 02 00 00  00 00 00 00 00 00 00 00  |....H...........|
000608b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00060a00  31 18 10 06 ef de 0e ee  00 00 00 00 00 00 00 00  |1...............|
00060a10  1c 00 00 00 05 00 00 00  e4 05 00 00 00 00 00 00  |................|
00060a20  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00061000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
re-produced
00000000  55 42 49 23 01 00 00 00  00 00 00 00 00 00 00 00  |UBI#............|
00000010  00 00 02 00 00 00 08 00  64 61 72 a1 00 00 00 00  |........dar.....|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 7f cc a3 2d  |...............-|
00000040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000200  55 42 49 21 01 01 00 05  7f ff ef ff 00 00 00 00  |UBI!............|
00000210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000230  00 00 00 00 00 00 00 00  00 00 00 00 b8 25 64 a8  |.............%d.|
00000240  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000800  00 00 03 28 00 00 00 01  00 00 00 00 01 00 00 06  |...(............|
00000810  72 6f 6f 74 66 73 00 00  00 00 00 00 00 00 00 00  |rootfs..........|
00000820  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000008a0  00 00 00 00 00 00 00 00  50 48 23 22 00 00 00 00  |........PH#"....|
000008b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000950  00 00 00 00 f1 16 c3 6b  00 00 00 00 00 00 00 00  |.......k........|
00000960  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000a00  f1 16 c3 6b 00 00 00 00  00 00 00 00 00 00 00 00  |...k............|
00000a10  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*

Hi @jclab-joseph,

Looks like it's just the Physical Erase Blocks that are different. I'm guessing this was from a NAND dump, which would explain the difference. That dump would be of an image that has been used, so there will be some movement of data as wear leveling is done and normal use. EC is Erase Count, which is a counter for how many times a PEB has been used. On a fresh build of an image, this would be different, than an image that's been on a running system. You won't get a bit perfect image, especially starting with a NAND dump, because of nature of UBI. A new image, everything is nicely in order, a previously running image, will be out of order.

-Jason

@jrspruitt Thank you.