Giter Site home page Giter Site logo

ubi_reader's Introduction

UBI Reader

UBI Reader is a Python module and collection of scripts capable of extracting the contents of UBI and UBIFS images, along with analyzing these images to determine the parameter settings to recreate them using the mtd-utils tools.

Known Issues

These are some known issues, that prevent an exact data dump from occuring.

  • This does not replay the journal, so uncommited data will not be retrieved. Data can be in the journal with both clean and unclean shutdowns.

  • Depending on how the NAND was dumped, the data bits may not be error corrected.

  • Socket files will be ignored, you can change ubireader/settings.py to have it create dummy files in their place.

Testing Branch

The testing branch includes a tools/ directory, that has scripts to help when trying to extract data from broken images. These also serve as examples of how to use parts of ubi_reader in custom scripts.

An override system is also included, for manually setting certain parameters that may be reported wrong by the UBI/FS data.

This branch will probably remain seperate, as it is meant to be customized to aid in extracting data from problematic images. You can install it with 'python setup.py develop' to make it easier to modify ubi_reader as needed.

Installation:

Latest Version

$ git clone https://github.com/jrspruitt/ubi_reader
$ cd ubi_reader
$ poetry install

Or

$ pip install --user ubi_reader

Usage:

For basic usage, the scripts need no options and if applicable will save output to ./ubifs-root/. More advanced usage can set start and end offset, specify an output directory, or for debugging can print out what it is doing to the terminal.

Run program with -h or --help for explanation of options.

Extracting File Contents:

ubireader_extract_files [options] path/to/file

The script accepts a file with UBI or UBIFS data in it, so should work with a NAND dump. It will search for the first occurance of UBI or UBIFS data and attempt to extract the contents. If file includes special files, you will need to run as root or sudo for it to create these files. With out it, it'll skip them and show a warning that these files were not created.

List/Copy Files:

ubireader_list_files [options] path/to/file

The script accepts a file with UBI or UBIFS data in it, so should work with a NAND dump. It will search for the first occurance of UBI or UBIFS data and treat it as a UBIFS. To list files supply the path to list (-P, --path), e.g. "-P /" to list the filesystems root directory. To copy a file from the filesystem to a local directory supply the source path (-C, --copy) and the destination path (-D, --copy-dest), e.g. -C /etc/passwd -D . (extract /etc/passwd from the UBIFS image and copy it to local directory).

Extracting Images:

ubireader_extract_images [options] path/to/file

This script will extract the whole UBI or UBIFS image from a NAND dump, or the UBIFS image from a UBI image. You can specify what type of image to extract by setting the (-u, --image-type) option to "UBI" or "UBIFS". Default is "UBIFS".

MTD-Utils Parameters:

ubireader_utils_info [options] path/to/file

The script will analyze a UBI image and create a Linux shell script and UBI config file that can be used for building new UBI images to the same specifications. For just a printed list of the options and values, use the (-r, --show-only) option.

Display Information:

ubireader_display_info [options] path/to/file

Depending on the image type found, this script displays some UBI information along with the header info from the layout block, including volume table records. If it is a UBIFS image, the Super Node, and both Master Nodes are displayed. Using the (-u, --ubifs-info) option, it will get the UBIFS info from inside a UBI file instead.

Display Block Information:

ubireader_display_blocks [options] "{'block.attr':?, ...}" path/to/file

Search for and display block information. This can be used for debugging failed image and file extractions. The blocks are searched for using a double quoted Python Dict of search paramaters, example. "{'peb_num':[0, 1] + range(100, 102), 'ec_hdr.ec': 1, 'is_valid': True}" This will find PEBs 0, 1, 100, 101, 102, with an erase count of 1 that is a valid block. Can use any of the parameters in ubireader.ubi.block.description.

Options:

Some general option flags are

  • -l, --log: This prints to screen actions being taken while running.
  • -v, --verbose: This basically prints everything about anything happening.
  • -p, --peb-size int: Specify PEB size of the UBI image, instead of having it guess.
  • -e, --leb-size int: Specify LEB size of UBIFS image, instead of having it guess.
  • -s, --start-offset int: Tell script to look for UBI/UBIFS data at given address.
  • -n, --end-offset int: Tell script to ignore data after given address in data.
  • -g, --guess-offset: Specify offset to start guessing where UBI data is in file. Useful for NAND dumps with false positives before image.
  • -w, --warn-only-block-read-errors: Attempts to continue extracting files even with bad block reads. Some data will be missing or corrupted!
  • -i, --ignore-block-header-errors: Forces unused and error containing blocks to be included and also displayed with log/verbose.
  • -f, --u-boot-fix: Assume blocks with image_seq 0 are because of older U-boot implementations and include them. *This may cause issues with multiple UBI image files.
  • -o, --output-dir path: Specify where files should be written to, instead of ubi_reader/output

ubi_reader's People

Contributors

at0myks avatar crmullineravsec avatar dougg3 avatar ianhan avatar jameshilliard avatar jrspruitt avatar keelung-yang avatar lthiery avatar qkaiser avatar retryfail avatar sviehb avatar vlaci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ubi_reader's Issues

Error trying to extract ubi files.

Hello everyone, I am trying to extract the contents of 2 ubi files, and I am getting an error with the software presented here.

Any idea how to fix it and extract the content from these?

It should be noted that these files have the OOB removed. But it still doesn't work.

I leave the link to the files here in case someone can shed some light.

Thanks to all :)

https://fromsmash.com/ubi-files

Is it possible to wrap several commands into subcommands?

We now have ubireader_display_{block,info} and ubireader_extract_{files,images}, and ubireader_{list_files,utils_info}

where list_files does a bit more, it is responsible for displaying files and also unpacking them.

I personally suggest to integrate ubireader display_{block,info} and list into ubireader show block/files/info, extract_{files,images} and utils_info into subcommand form.

VID_HDR appears to be offset from where it belongs

Hey,

I'm unsure whether this is a problem with ubi_reader or with the chip I got it from, but I'm struggling to either mount or extract data from a memory dump I did.

If I just straight up try to dump it, I see this error repeated for literally every block:

guess_start_offset Found UBI magic number at 0
guess_filetype Looking for file type at 0
guess_filetype File looks like a UBI image.
UBI_File Open Path: /home/ron/image.ubi
UBI_File File Size: 237355008
UBI_File Start Offset: 0
UBI_File End Offset: 237355008
UBI_File Block Size: 135168
UBI_File read loc: 0, size: 135168
vid_hdr CRC Failed: expected 0xecfe642a got 0xffffffff
extract_blocks Block: PEB# 0: LEB# 4294967295
extract_blocks file addr: 0
extract_blocks PEB: 0 has possible issue EC_HDR [], VID_HDR [crc]
        Block: PEB# 0: LEB# 4294967295
        ---------------------
                File Offset: 0
                PEB #: 0
                LEB #: 4294967295
                Block Size: 135168
                Internal Volume: True
                Is Volume Table: False
                Is Valid: True

                Erase Count Header
                ---------------------
                        data_offset: 4096
                        ec: 4264
                        errors: ''
                        hdr_crc: '0xe263b667'
                        image_seq: 2333686688
                        magic: 'UBI#'
                        padding: '\x00\x00\x00'
                        padding2: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
                        version: 1
                        vid_hdr_offset: 2048

                VID Header
                ---------------------
                        compat: -1
                        copy_flag: 255
                        data_crc: 3932094975
                        data_pad: 4294967295
                        data_size: 4294967295
                        errors: 'crc'
                        hdr_crc: '0xffffffff'
                        lnum: 4294967295
                        magic: '\xff\xff\xff\xff'
                        padding: '\xff\xff\xff\xff'
                        padding2: '\xff\xff\xff\xff'
                        padding3: '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'
                        sqnum: 18446744073709551615L
                        used_ebs: 4294967295
                        version: 255
                        vol_id: 4294967295
                        vol_type: -1

I dug into the code to try and understand what headers are supposed to look like. The first block appears to be empty and have no data, but the second block does. It appears, however, that the VID header is 0x40 bytes past where ubi_reader is looking.

Here's the EB header of the second block (the block size is 0x21000):

          ---magic---     ver -  -  -     --------- EC --------------
00021000: 55 42 49 23     01 00 00 00     00 00 00 00     00 00 10 0d  UBI#............
          vid_hdr_off     data_offset     -image_seq-     --padding--
00021010: 00 00 08 00     00 00 10 00     8b 19 3b a0     00 00 00 00  ..........;.....
          --------------------------padding--------------------------
00021020: 00 00 00 00     00 00 00 00     00 00 00 00     00 00 00 00  ................
          -----------------padding-------------------     ----crc----
00021030: 00 00 00 00     00 00 00 00     00 00 00 00     c4 b3 6f 75  ..............ou

00021040: 00 00 00 00     00 00 00 00     00 00 00 00     00 00 00 00  ................
...empty...
000217f0: 00 00 00 00     00 00 00 00     00 00 00 00     00 00 00 00  ................

If I'm reading that right, the vid_hdr_offset as 0x800, and the data_offset at 0x1000. Looks good so far!

If I fast forward to 0x800 bytes into the that block, where I'd expect to see the VID header (and where ubi_reader is reading it), I see:

00021800: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
00021810: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
00021820: 12 2e e1 ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
00021830: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................

It appears that the checksum is set, but nothing else at all, including the 'magic'. However, if I go an additional 0x40 bytes to 0x840 from the start of the block, I see what appears to be a UBI VID header (starts with 'UBI!'):

                             type  compat
          ---magic---     ver   copy      --vol_id---     ---lnum----
00021840: 55 42 49 21     01 01 00 00     00 00 00 00     00 00 01 18  UBI!............

          ----pad----     -data_size-     -used_ebs--     data_padding
00021850: 00 00 00 00     00 00 00 00     00 00 00 00     00 00 00 00  ................

          data_crc        padding         ----------seq_num----------
00021860: 00 00 00 00     00 00 00 00     00 00 00 00     00 7e 0c ad  .............~..

          ------------------padding------------------     ----crc----
00021870: 00 00 00 00     00 00 00 00     00 00 00 00     bc b0 9f 45  ...............E

00021880: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
...empty...
00021ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

It doesn't look 100% perfect, but it does start with the "UBI!" magic and apparently has a CRC32 at the end.

If I go to 0x1000 offset from the start, it looks like it could be a data block, but I haven't gotten far enough to know what that's supposed to look like yet. I'm still working through the headers.

I haven't dug super deep into the RFC or docs just yet, just the list of headers. But I thought maybe, since you've done a lot more work with this format than myself, you might see what's going on.

Thanks for any help!

Suggest Creating Nested Directories only if needed

I have a recommended patch which I believe is safe and just modifies logic slightly to only create nested folders if they are needed:

diff --git a/scripts/ubireader_extract_files b/scripts/ubireader_extract_files
index 1b2a5ae..1fc6d5a 100755
--- a/scripts/ubireader_extract_files
+++ b/scripts/ubireader_extract_files
@@ -149,9 +149,12 @@ if __name__=='__main__':
         # Loop through found images in file.
         for image in ubi_obj.images:
 
-            # Create path for specific image
-            # In case multiple images in data
-            img_outpath = os.path.join(outpath, '%s' % image.image_seq)
+            # Create path for the specific image
+            # In case of multiple images in data, add a level to the output structure to indicate this:
+            if len(ubi_obj.images) > 1:
+                img_outpath = os.path.join(outpath, repr(image.image_seq))
+            else:
+                img_outpath = outpath
 
             # Loop through volumes in each image.
             for volume in image.volumes:
@@ -159,8 +162,11 @@ if __name__=='__main__':
                 # Get blocks associated with this volume.
                 vol_blocks = image.volumes[volume].get_blocks(ubi_obj.blocks)
 
-                # Create volume data output path.
-                vol_outpath = os.path.join(img_outpath, volume)
+                # Create volume data output path, adding a level only if we have multiple volumes:
+                if len(image.volumes) > 1:
+                    vol_outpath = os.path.join(img_outpath, volume)
+                else:
+                    vol_outpath = img_outpath
                 
                 # Create volume output path directory.
                 create_output_dir(vol_outpath)

Would you be interested in implementing that or me submitting a PR for it?

ubireader_extract_files problem

I used mkfs.ubifs to make a xxx.ubifs. And then i used ubireader_extract_file -k xxxx.ubifs. However there is three files content different from the old ones.

can't unpack ubi pakage

When I try to unpack the ubi file, it return this error, I can't understand
han@OwnerLaptop:~/xiaomi/bin/_miwifi_rc01_firmware_1.0.59.bin.extracted$ ubireader_extract_images 324.ubi
Traceback (most recent call last):
File "/usr/local/bin/ubireader_extract_images", line 4, in
import('pkg_resources').run_script('ubi-reader==0.8.5', 'ubireader_extract_images')
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 667, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 1452, in run_script
raise ResolutionError(
pkg_resources.ResolutionError: Script 'scripts/ubireader_extract_images' not found in metadata at '/usr/local/lib/python3.8/dist-packages/ubi_reader-0.8.5.dist-info'

ubireader_display_info displays information about the ubi file but I can't extract them

Hello Jason,

I have a problem here and wanted to ask you if you might know what I can do to fix this.
I dumped the content of a NAND flash. Binwalk extracted an ubi file from the dump and when I used ubireader_display_info I got the following output:

`UBI File

Min I/O: 2048
LEB Size: 126976
PEB Size: 131072
Total Block Count: 847
Data Block Count: 377
Layout Block Count: 2
Internal Volume Block Count: 468
Unknown Block Count: 0
First UBI PEB Number: 10

Image: 1681423409
---------------------
	Image Sequence Num: 1681423409
	Volume Name:spare
	Volume Name:data1
	Volume Name:root1
	Volume Name:root0
	Volume Name:data0
	PEB Range: 0 - 855

	Volume: spare
	---------------------
		Vol ID: 4
		Name: spare
		Block Count: 142

		Volume Record
		---------------------
			alignment: 1
			crc: '0x743003a9'
			data_pad: 0
			errors: ''
			flags: 0
			name: u'spare'
			name_len: 5
			padding: u'\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: 4
			reserved_pebs: 386
			upd_marker: 0
			vol_type: 'dynamic'


	Volume: data1
	---------------------
		Vol ID: 3
		Name: data1
		Block Count: 8

		Volume Record
		---------------------
			alignment: 1
			crc: '0xefc3e0d'
			data_pad: 0
			errors: ''
			flags: 0
			name: u'data1'
			name_len: 5
			padding: u'\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: 3
			reserved_pebs: 34
			upd_marker: 0
			vol_type: 'dynamic'


	Volume: root1
	---------------------
		Vol ID: 1
		Name: root1
		Block Count: 110

		Volume Record
		---------------------
			alignment: 1
			crc: '0x4a7089bd'
			data_pad: 0
			errors: ''
			flags: 0
			name: u'root1'
			name_len: 5
			padding: u'\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: 1
			reserved_pebs: 232
			upd_marker: 0
			vol_type: 'dynamic'


	Volume: root0
	---------------------
		Vol ID: 0
		Name: root0
		Block Count: 108

		Volume Record
		---------------------
			alignment: 1
			crc: '0x38a2ed27'
			data_pad: 0
			errors: ''
			flags: 0
			name: u'root0'
			name_len: 5
			padding: u'\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: 232
			upd_marker: 0
			vol_type: 'dynamic'


	Volume: data0
	---------------------
		Vol ID: 2
		Name: data0
		Block Count: 9

		Volume Record
		---------------------
			alignment: 1
			crc: '0x7c2e5a97'
			data_pad: 0
			errors: ''
			flags: 0
			name: u'data0'
			name_len: 5
			padding: u'\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: 2
			reserved_pebs: 34
			upd_marker: 0
			vol_type: 'dynamic'`

This looked promising to me. The problem is when I try to extract the files with ubireader_extract_files I receive an error message:

Extracting files to: ubifs-root/1681423409/spare extract_files Error: No inodes found Extracting files to: ubifs-root/1681423409/data1 read Error: LEB: 10 is corrupted or has no data. extract_files Error: 1 UBIFS Fatal: Super block error: Wrong node type.

Is it possible that the dump itself is incomplete and if that is the case can I do something to extract files anyways without having to dump it again?

Python3 is required

Under python2, the following error occurs:

Extracting files to: ubifs-root
extract_files Error: 'module' object has no attribute 'commonpath'

repack extracted file

How to repack the extracted file?

I changed a photo in a file. I want to repackage it. Is this possible with your scripts?

Work steps:
file.ubiimg ........... -> extracted ........ -> apply changes ....... -> newFile.ubiimg

Thank you for the guidance

Unable to extract file

When Tried to extract ubi file on Ubuntu 14 it shows this error.
extract_files Error: 'module' object has no attribute 'commonpath'
but the same ubi file or later version is working.
and more the file size is increased some how after repacking on later version, if I use same compression on one file and the other

The image could not be reproduced with ubireader_utils_info.

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  |................|
*

CRC Failed

I am not sure if this is an error in my extraction process of a problem with the software. I extracted a nand dump with:

dd if=/dev/mtd1 of=mtd1.img bs=4096

*NOTE: /dev/mtd1 is attached to ubi which is mounted on /

Then I used the utility to extract the files from the image as:

ubireader_extract_files -l mtd1.img

It started recognizing the ubi fs but the CRC it is reading seem to be wrong:

guess_start_offset Found UBI magic number at 0
guess_filetype Looking for file type at 0
guess_filetype File looks like a UBI image.
UBI_File Open Path: mtd1.img
UBI_File File Size: 15597568
UBI_File Start Offset: 0
UBI_File End Offset: 15597568
UBI_File Block Size: 131072
vid_hdr CRC Failed: expected 0xb730eb2 got 0xffffffff
extract_blocks Block: PEB# 0: LEB# -1
extract_blocks PEB: 0 has possible issue EC_HDR [], VID_HDR [crc]
vid_hdr CRC Failed: expected 0xb730eb2 got 0xffffffff
extract_blocks Block: PEB# 1: LEB# -1
extract_blocks PEB: 1 has possible issue EC_HDR [], VID_HDR [crc]
vid_hdr CRC Failed: expected 0xb730eb2 got 0xffffffff
extract_blocks Block: PEB# 2: LEB# -1
extract_blocks PEB: 2 has possible issue EC_HDR [], VID_HDR [crc]
vid_hdr CRC Failed: expected 0xb730eb2 got 0xffffffff
extract_blocks Block: PEB# 3: LEB# -1
extract_blocks PEB: 3 has possible issue EC_HDR [], VID_HDR [crc]
vid_hdr CRC Failed: expected 0xb730eb2 got 0xffffffff
extract_blocks Block: PEB# 4: LEB# -1
extract_blocks PEB: 4 has possible issue EC_HDR [], VID_HDR [crc]
vid_hdr CRC Failed: expected 0xb730eb2 got 0xffffffff
extract_blocks Block: PEB# 5: LEB# -1

The output is much larger, but perhaps this is enough to understand the problem.

Any thoughts?

AttributeError: 'NoneType' object has no attribute 'data_size'

Hi,

Thank you for your work!

Trying to analyse an ubi image extracted with binwalk from a NAND flash dump, I get the following error:

$ ubireader_display_info ./_dump.bin.extracted/7BC000.ubi
Traceback (most recent call last):
File "/home/itsme/.local/bin/ubireader_display_info", line 132, in
ubi_obj = ubi(ufile_obj)
File "/home/itsme/.local/lib/python3.10/site-packages/ubireader/ubi/init.py", line 146, in init
super(ubi, self).init(ubi_file)
File "/home/itsme/.local/lib/python3.10/site-packages/ubireader/ubi/init.py", line 46, in init
self._blocks = extract_blocks(self)
File "/home/itsme/.local/lib/python3.10/site-packages/ubireader/ubi/block/init.py", line 131, in extract_blocks
blk.data_crc = (~crc32(buf[blk.ec_hdr.data_offset:blk.ec_hdr.data_offset+blk.vid_hdr.data_size]) & UBI_CRC32_INIT)
AttributeError: 'NoneType' object has no attribute 'data_size'

What goes wrong here ?

Pierre

Change First UBI PEB Number to 42.0

My original image:

ubireader_display_info  /hassio/share/ubifs-root/15-0-systm2.bin
UBI File
---------------------
        Min I/O: 2048
        LEB Size: 126976
        PEB Size: 131072
        Total Block Count: 258
        Data Block Count: 242
        Layout Block Count: 2
        Internal Volume Block Count: 0
        Unknown Block Count: 0
        First UBI PEB Number: 42.0

        Image: 251495409
        ---------------------
                Image Sequence Num: 251495409
                Volume Name:rootfs
                Volume Name:usrfs
                PEB Range: 0 - 257

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

                        Volume Record
                        ---------------------
                                alignment: 1
                                crc: '0x30fb56ba'
                                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: 496
                                upd_marker: 0
                                vol_type: 'dynamic'


                Volume: usrfs
                ---------------------
                        Vol ID: 1
                        Name: usrfs
                        Block Count: 14

                        Volume Record
                        ---------------------
                                alignment: 1
                                crc: '0x4f66b6e1'
                                data_pad: 0
                                errors: ''
                                flags: 'autoresize'
                                name: 'usrfs'
                                name_len: 5
                                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: 1
                                reserved_pebs: 14
                                upd_marker: 0
                                vol_type: 'dynamic'

My repacked image:

ubireader_display_info sys2.ubi
UBI File
---------------------
        Min I/O: 2048
        LEB Size: 126976
        PEB Size: 131072
        Total Block Count: 258
        Data Block Count: 242
        Layout Block Count: 2
        Internal Volume Block Count: 0
        Unknown Block Count: 0
        First UBI PEB Number: 0

        Image: 251495409
        ---------------------
                Image Sequence Num: 251495409
                Volume Name:rootfs
                Volume Name:usrfs
                PEB Range: 0 - 257

How can I get First UBI PEB Number: 42.0?

extract_files needs better error handling

Or a switch to keep processing dents if one is corrupt
changing the error handling to be as:
error(extract_files, 'MostlyFatal', '%s' % e)
allowed me to extract a second volume from a ubi image

compression parameter

Hello,
it would be nice to also add parameter "-x" to mkfs.ubifs when generating script using ubireader_utils_info. It corretly shows the "zlib" compression, but "-x zlib" is missing at the mkfs.ubifs line

Thanks.

Block ends after file

Dear Developer, i seem to be getting this error and i just cant fix it, can you please help.. when extracting an image i get this error:
Extracting files to: ubifs-root
read Error: Block ends at 1209249656 which is greater than file size 42029056
index Fatal: LEB: 10, UBIFS offset: 1290104, error: Bad Read Offset Request

TypeError: 'int' object is not iterable

Hi,

I'm trying to extract the data out of an NAND dump I've made from a FTTH ONT.
It seems it has UBI in it but I can't get to extract it.
It may be something special about this UBI because I also don't get it running on any other way like putting the dump into mtd/nandsim and use ubiattach (getting "unsupported on-flash UBI format" then).

That's what I get with ubireader:

$ ubireader_display_info CleanDump.bin
Traceback (most recent call last):
  File "/usr/local/bin/ubireader_display_info", line 4, in <module>
    __import__('pkg_resources').run_script('ubi-reader==0.7.1', 'ubireader_display_info')
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 666, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1469, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/ubi_reader-0.7.1-py2.7.egg/EGG-INFO/scripts/ubireader_display_info", line 132, in <module>

  File "build/bdist.linux-x86_64/egg/ubireader/ubi/__init__.py", line 166, in __init__
  File "build/bdist.linux-x86_64/egg/ubireader/ubi/image.py", line 31, in __init__
TypeError: 'int' object is not iterable

That's of binwalk finds out of this dump:

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
168116        0x290B4         AES Inverse S-Box
168372        0x291B4         AES S-Box
169716        0x296F4         SHA256 hash constants, little endian
169972        0x297F4         CRC32 polynomial table, little endian
303284        0x4A0B4         AES Inverse S-Box
303540        0x4A1B4         AES S-Box
304884        0x4A6F4         SHA256 hash constants, little endian
305140        0x4A7F4         CRC32 polynomial table, little endian
434356        0x6A0B4         AES Inverse S-Box
434612        0x6A1B4         AES S-Box
435956        0x6A6F4         SHA256 hash constants, little endian
436212        0x6A7F4         CRC32 polynomial table, little endian
567476        0x8A8B4         AES Inverse S-Box
567732        0x8A9B4         AES S-Box
569076        0x8AEF4         SHA256 hash constants, little endian
569332        0x8AFF4         CRC32 polynomial table, little endian
698548        0xAA8B4         AES Inverse S-Box
698804        0xAA9B4         AES S-Box
700148        0xAAEF4         SHA256 hash constants, little endian
700404        0xAAFF4         CRC32 polynomial table, little endian
831668        0xCB0B4         AES Inverse S-Box
831924        0xCB1B4         AES S-Box
833268        0xCB6F4         SHA256 hash constants, little endian
833524        0xCB7F4         CRC32 polynomial table, little endian
1703866       0x19FFBA        Sercomm firmware signature, version control: 0, download control: 1, hardware ID: "DHP", hardware version: 0x4100, firmware version: 0x1, starting code segment: 0x0, code size: 0x7300
2097152       0x200000        UBI erase count header, version: 1, EC: 0x0, VID header offset: 0x800, data offset: 0x1000
5898170       0x59FFBA        Sercomm firmware signature, version control: 0, download control: 1, hardware ID: "DHP", hardware version: 0x4100, firmware version: 0x0, starting code segment: 0x0, code size: 0x7300
10092474      0x99FFBA        Sercomm firmware signature, version control: 0, download control: 1, hardware ID: "DHP", hardware version: 0x4100, firmware version: 0x0, starting code segment: 0x0, code size: 0x7300
12845056      0xC40000        JFFS2 filesystem, little endian
101318656     0x60A0000       JFFS2 filesystem, little endian

When I extract that JFFS2 filesystems they're kinda broken too. It mounts and I can see some files but they can't be all of them and I'm getting CRCs errors in dmesg then.
I've thought the dump is maybe broken but my dump programmer is verifying it fine and I always get the same checksum everytime I make a dump from the original NAND.

Any idea?

This is the full 128MByte dump (with OOB/spare data removed):
https://cloud.mimimiii.net/index.php/s/zNf3cQYqdNsz9tt

Best regards
Sven / shavenne

Wrong vol_flags into ini file for ubinize

Hi,

each time you create scripts for image using ubireader_utils_info, the *.ini file contains the value vol_flags = 0 that seems to not be supported by ubinize.

Is it normal behaviour? Only way to make UBI image back is to remove that flags or use vol_flags = autoresize, that is not supported by the original image

Thanks in advance

Version bump request

Hey @jrspruitt,

any thoughts on when to expect a nother version bump? Last version is 3 years old and there's been quite some activity. Maybe a small bump is fair?

get_newest() PEB selection is broken

You cannot simply compare sqnum of volume id headers.
To find the correct PEB you need to honor copy_flag and data_crc too.
Otherwise an image takem while UBI did wear leveling or atomic LEB update (which UBIFS does commonly) will result
into broken LEB->PEB mappings and corrupted volumes.

UBIFS journal not replayed

On UBIFS replaying the journal is mandatory. If you don't do so the index tree can point to wrong (outdated or dead) leaf nodes.
You can do it like u-boot and replay into memory (e.g. just into TNC).
Please note that even a clean unmount of UBIFS does not lead to an empty journal.
That's why replaying is mandatory.

Feature req: preserve file dates

The tool works great for the purpose it was created - allows extracting and re-creating damaged UbiFS.

One thing that is not preserved are file dates. While preserving permissions works great, dates of Access/Modify/Change are all set to the extraction date.

please cut a new release

The latest release was back in 2017. It would be good if you could cut a new release at some stable point of time. Thanks

How to handle ubi dump with only one volume table ?

Hi,

Is there a way to extract an image with only one volume table block ? I lazy patched your code:

https://github.com/jrspruitt/ubi_reader/blob/5579cb8acf63c62e7c7be8ab342ddf555cd3b001/ubireader/ubi/__init__.py#L152 to 1, and patched everywhere where you use layout_list[2]. So the tool is creating the virtual image now, but fail at this:

group_pairs Layout blocks found at PEBs: [[438]]
description Create Volume: bootdata, ID: 0, Block Cnt: 1
description Create Volume: unitdata, ID: 1, Block Cnt: 1
description Create Volume: caldata, ID: 12, Block Cnt: 1
description Create Volume: caldata_backup, ID: 13, Block Cnt: 1
description Created Image: 1315753792, Volume Cnt: 4
leb_virtual_file read loc: 140251136, size: 24
UBIFS UBIFS Common Header file addr: 140251136
	UBIFS Common Header
	---------------------
		crc: 0x2000
		errors: 
		group_type: 101
		len: 1886220099
		magic: 684539205
		node_type: 114
		padding: 'ss'
		sqnum: 3

So there is somewhere that the Common header is not at the correct offset, I'm trying to understand your code on how to discover Super block to try to understand where is the error.

error when extracting a ubi file in blk.data_crc() function from ubireader

There appears to be a bug in the ubireader which checks for crc information in the header and fails to catch if it doesn't recognise it properly.

To Reproduce
Steps to reproduce the behavior:

  1. Launch unblob with command unblob file.ubi
  2. See error

Detail
Error from unblob

code=0x1 pid=22412 severity=<Severity.WARNING: 'WARNING'> stderr=Traceback (most recent call last):
  File "/home/arunmag_001/.local/bin/ubireader_extract_images", line 143, in <module>
    ubi_obj = ubi(ufile_obj)
  File "/home/arunmag_001/.local/lib/python3.10/site-packages/ubireader/ubi/__init__.py", line 146, in __init__
    super(ubi, self).__init__(ubi_file)
  File "/home/arunmag_001/.local/lib/python3.10/site-packages/ubireader/ubi/__init__.py", line 46, in __init__
    self._blocks = extract_blocks(self)
  File "/home/arunmag_001/.local/lib/python3.10/site-packages/ubireader/ubi/block/__init__.py", line 131, in extract_blocks
    blk.data_crc = (~crc32(buf[blk.ec_hdr.data_offset:blk.ec_hdr.data_offset+blk.vid_hdr.data_size]) & UBI_CRC32_INIT)
AttributeError: 'NoneType' object has no attribute 'data_size'

Same error from ubireader as well.

 ubireader_display_info 20000.ubi
Traceback (most recent call last):
  File "/home/arunmag_001/.local/bin/ubireader_display_info", line 132, in <module>
    ubi_obj = ubi(ufile_obj)
  File "/home/arunmag_001/.local/lib/python3.10/site-packages/ubireader/ubi/__init__.py", line 146, in __init__
    super(ubi, self).__init__(ubi_file)
  File "/home/arunmag_001/.local/lib/python3.10/site-packages/ubireader/ubi/__init__.py", line 46, in __init__
    self._blocks = extract_blocks(self)
  File "/home/arunmag_001/.local/lib/python3.10/site-packages/ubireader/ubi/block/__init__.py", line 131, in extract_blocks
    blk.data_crc = (~crc32(buf[blk.ec_hdr.data_offset:blk.ec_hdr.data_offset+blk.vid_hdr.data_size]) & UBI_CRC32_INIT)
AttributeError: 'NoneType' object has no attribute 'data_size'

Expected behavior
The script crash and fails to extract.

Environment information :
Linux arunmag 5.15.90.1-microsoft-standard-WSL2 onekey-sec/unblob#1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
"Ubuntu 22.04.1 LTS"
"unblob==23.4.17"

83886080-84803584.zip

TypeError: 'NoneType' object cannot be interpreted

Hi! I'm currently trying to use your software under archlinux, getting this error message, regardless of the input file.

using Python 2.7.11 (default, Dec 6 2015, 15:43:46).

[tobias@tobias-arch docsis2_w239th1]$ ubireader_utils_info -r chip1.bin 
Traceback (most recent call last):
  File "/usr/bin/ubireader_utils_info", line 4, in <module>
    __import__('pkg_resources').run_script('ubi-reader==0.4', 'ubireader_utils_info')
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 745, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1677, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/lib/python2.7/site-packages/ubi_reader-0.4-py2.7.egg/EGG-INFO/scripts/ubireader_utils_info", line 265, in <module>

  File "build/bdist.linux-x86_64/egg/ubireader/utils.py", line 62, in guess_filetype
TypeError: 'NoneType' object cannot be interpreted as an index

Any ideas?

Best regards,
Tobias

The UBIFS Version is now 5

There has been some changes, notably in the Super Block and Master Node structs, which includes some new entries, that enable an HMAC check in the scan function.

There may be other changes that need to be found, understood and implemented.

-Jason

Fatal: PEB: 285: Bad Read Offset Request

I'm trying to decompress this file... it doesn't give me any crc error just this

guess_start_offset Found UBI magic number at 0
guess_filetype Looking for file type at 0
guess_filetype File looks like a UBI image.
UBI_File Open Path: 2C0000.ubi
UBI_File File Size: 37355540
UBI_File Start Offset: 0
UBI_File End Offset: 37355540
UBI_File Block Size: 131072
extract_blocks Block: PEB# 0: LEB# 0
extract_blocks Block: PEB# 1: LEB# 1
extract_blocks Block: PEB# 2: LEB# 0
extract_blocks Block: PEB# 3: LEB# 1
extract_blocks Block: PEB# 4: LEB# 2
extract_blocks Block: PEB# 5: LEB# 3
extract_blocks Block: PEB# 6: LEB# 4
extract_blocks Block: PEB# 7: LEB# 5
extract_blocks Block: PEB# 8: LEB# 6
extract_blocks Block: PEB# 9: LEB# 7
extract_blocks Block: PEB# 10: LEB# 8
extract_blocks Block: PEB# 11: LEB# 9
extract_blocks Block: PEB# 12: LEB# 10
extract_blocks Block: PEB# 13: LEB# 11
extract_blocks Block: PEB# 14: LEB# 12
extract_blocks Block: PEB# 15: LEB# 13
extract_blocks Block: PEB# 16: LEB# 14
extract_blocks Block: PEB# 17: LEB# 15
extract_blocks Block: PEB# 18: LEB# 16
extract_blocks Block: PEB# 19: LEB# 17
extract_blocks Block: PEB# 20: LEB# 18
extract_blocks Block: PEB# 21: LEB# 19
extract_blocks Block: PEB# 22: LEB# 20
extract_blocks Block: PEB# 23: LEB# 21
extract_blocks Block: PEB# 24: LEB# 22
extract_blocks Block: PEB# 25: LEB# 23
extract_blocks Block: PEB# 26: LEB# 24
extract_blocks Block: PEB# 27: LEB# 25
extract_blocks Block: PEB# 28: LEB# 26
extract_blocks Block: PEB# 29: LEB# 27
extract_blocks Block: PEB# 30: LEB# 28
extract_blocks Block: PEB# 31: LEB# 29
extract_blocks Block: PEB# 32: LEB# 30
extract_blocks Block: PEB# 33: LEB# 31
extract_blocks Block: PEB# 34: LEB# 32
extract_blocks Block: PEB# 35: LEB# 33
extract_blocks Block: PEB# 36: LEB# 34
extract_blocks Block: PEB# 37: LEB# 35
extract_blocks Block: PEB# 38: LEB# 36
extract_blocks Block: PEB# 39: LEB# 37
extract_blocks Block: PEB# 40: LEB# 38
extract_blocks Block: PEB# 41: LEB# 39
extract_blocks Block: PEB# 42: LEB# 40
extract_blocks Block: PEB# 43: LEB# 41
extract_blocks Block: PEB# 44: LEB# 42
extract_blocks Block: PEB# 45: LEB# 43
extract_blocks Block: PEB# 46: LEB# 44
extract_blocks Block: PEB# 47: LEB# 45
extract_blocks Block: PEB# 48: LEB# 46
extract_blocks Block: PEB# 49: LEB# 47
extract_blocks Block: PEB# 50: LEB# 48
extract_blocks Block: PEB# 51: LEB# 49
extract_blocks Block: PEB# 52: LEB# 50
extract_blocks Block: PEB# 53: LEB# 51
extract_blocks Block: PEB# 54: LEB# 52
extract_blocks Block: PEB# 55: LEB# 53
extract_blocks Block: PEB# 56: LEB# 54
extract_blocks Block: PEB# 57: LEB# 55
extract_blocks Block: PEB# 58: LEB# 56
extract_blocks Block: PEB# 59: LEB# 57
extract_blocks Block: PEB# 60: LEB# 58
extract_blocks Block: PEB# 61: LEB# 59
extract_blocks Block: PEB# 62: LEB# 60
extract_blocks Block: PEB# 63: LEB# 61
extract_blocks Block: PEB# 64: LEB# 62
extract_blocks Block: PEB# 65: LEB# 63
extract_blocks Block: PEB# 66: LEB# 64
extract_blocks Block: PEB# 67: LEB# 65
extract_blocks Block: PEB# 68: LEB# 66
extract_blocks Block: PEB# 69: LEB# 67
extract_blocks Block: PEB# 70: LEB# 68
extract_blocks Block: PEB# 71: LEB# 69
extract_blocks Block: PEB# 72: LEB# 70
extract_blocks Block: PEB# 73: LEB# 71
extract_blocks Block: PEB# 74: LEB# 72
extract_blocks Block: PEB# 75: LEB# 73
extract_blocks Block: PEB# 76: LEB# 74
extract_blocks Block: PEB# 77: LEB# 75
extract_blocks Block: PEB# 78: LEB# 76
extract_blocks Block: PEB# 79: LEB# 77
extract_blocks Block: PEB# 80: LEB# 78
extract_blocks Block: PEB# 81: LEB# 79
extract_blocks Block: PEB# 82: LEB# 80
extract_blocks Block: PEB# 83: LEB# 81
extract_blocks Block: PEB# 84: LEB# 82
extract_blocks Block: PEB# 85: LEB# 83
extract_blocks Block: PEB# 86: LEB# 84
extract_blocks Block: PEB# 87: LEB# 85
extract_blocks Block: PEB# 88: LEB# 86
extract_blocks Block: PEB# 89: LEB# 87
extract_blocks Block: PEB# 90: LEB# 88
extract_blocks Block: PEB# 91: LEB# 89
extract_blocks Block: PEB# 92: LEB# 90
extract_blocks Block: PEB# 93: LEB# 91
extract_blocks Block: PEB# 94: LEB# 92
extract_blocks Block: PEB# 95: LEB# 93
extract_blocks Block: PEB# 96: LEB# 94
extract_blocks Block: PEB# 97: LEB# 95
extract_blocks Block: PEB# 98: LEB# 96
extract_blocks Block: PEB# 99: LEB# 97
extract_blocks Block: PEB# 100: LEB# 98
extract_blocks Block: PEB# 101: LEB# 99
extract_blocks Block: PEB# 102: LEB# 100
extract_blocks Block: PEB# 103: LEB# 101
extract_blocks Block: PEB# 104: LEB# 102
extract_blocks Block: PEB# 105: LEB# 103
extract_blocks Block: PEB# 106: LEB# 104
extract_blocks Block: PEB# 107: LEB# 105
extract_blocks Block: PEB# 108: LEB# 106
extract_blocks Block: PEB# 109: LEB# 107
extract_blocks Block: PEB# 110: LEB# 108
extract_blocks Block: PEB# 111: LEB# 109
extract_blocks Block: PEB# 112: LEB# 110
extract_blocks Block: PEB# 113: LEB# 111
extract_blocks Block: PEB# 114: LEB# 112
extract_blocks Block: PEB# 115: LEB# 113
extract_blocks Block: PEB# 116: LEB# 114
extract_blocks Block: PEB# 117: LEB# 115
extract_blocks Block: PEB# 118: LEB# 116
extract_blocks Block: PEB# 119: LEB# 117
extract_blocks Block: PEB# 120: LEB# 118
extract_blocks Block: PEB# 121: LEB# 119
extract_blocks Block: PEB# 122: LEB# 120
extract_blocks Block: PEB# 123: LEB# 121
extract_blocks Block: PEB# 124: LEB# 122
extract_blocks Block: PEB# 125: LEB# 123
extract_blocks Block: PEB# 126: LEB# 124
extract_blocks Block: PEB# 127: LEB# 125
extract_blocks Block: PEB# 128: LEB# 126
extract_blocks Block: PEB# 129: LEB# 127
extract_blocks Block: PEB# 130: LEB# 128
extract_blocks Block: PEB# 131: LEB# 129
extract_blocks Block: PEB# 132: LEB# 130
extract_blocks Block: PEB# 133: LEB# 131
extract_blocks Block: PEB# 134: LEB# 132
extract_blocks Block: PEB# 135: LEB# 133
extract_blocks Block: PEB# 136: LEB# 134
extract_blocks Block: PEB# 137: LEB# 135
extract_blocks Block: PEB# 138: LEB# 136
extract_blocks Block: PEB# 139: LEB# 137
extract_blocks Block: PEB# 140: LEB# 138
extract_blocks Block: PEB# 141: LEB# 139
extract_blocks Block: PEB# 142: LEB# 140
extract_blocks Block: PEB# 143: LEB# 141
extract_blocks Block: PEB# 144: LEB# 142
extract_blocks Block: PEB# 145: LEB# 143
extract_blocks Block: PEB# 146: LEB# 144
extract_blocks Block: PEB# 147: LEB# 145
extract_blocks Block: PEB# 148: LEB# 146
extract_blocks Block: PEB# 149: LEB# 147
extract_blocks Block: PEB# 150: LEB# 148
extract_blocks Block: PEB# 151: LEB# 149
extract_blocks Block: PEB# 152: LEB# 150
extract_blocks Block: PEB# 153: LEB# 151
extract_blocks Block: PEB# 154: LEB# 152
extract_blocks Block: PEB# 155: LEB# 153
extract_blocks Block: PEB# 156: LEB# 154
extract_blocks Block: PEB# 157: LEB# 155
extract_blocks Block: PEB# 158: LEB# 156
extract_blocks Block: PEB# 159: LEB# 157
extract_blocks Block: PEB# 160: LEB# 158
extract_blocks Block: PEB# 161: LEB# 159
extract_blocks Block: PEB# 162: LEB# 160
extract_blocks Block: PEB# 163: LEB# 161
extract_blocks Block: PEB# 164: LEB# 162
extract_blocks Block: PEB# 165: LEB# 163
extract_blocks Block: PEB# 166: LEB# 164
extract_blocks Block: PEB# 167: LEB# 165
extract_blocks Block: PEB# 168: LEB# 166
extract_blocks Block: PEB# 169: LEB# 167
extract_blocks Block: PEB# 170: LEB# 168
extract_blocks Block: PEB# 171: LEB# 169
extract_blocks Block: PEB# 172: LEB# 170
extract_blocks Block: PEB# 173: LEB# 171
extract_blocks Block: PEB# 174: LEB# 172
extract_blocks Block: PEB# 175: LEB# 173
extract_blocks Block: PEB# 176: LEB# 174
extract_blocks Block: PEB# 177: LEB# 175
extract_blocks Block: PEB# 178: LEB# 176
extract_blocks Block: PEB# 179: LEB# 177
extract_blocks Block: PEB# 180: LEB# 178
extract_blocks Block: PEB# 181: LEB# 179
extract_blocks Block: PEB# 182: LEB# 180
extract_blocks Block: PEB# 183: LEB# 181
extract_blocks Block: PEB# 184: LEB# 182
extract_blocks Block: PEB# 185: LEB# 183
extract_blocks Block: PEB# 186: LEB# 184
extract_blocks Block: PEB# 187: LEB# 185
extract_blocks Block: PEB# 188: LEB# 186
extract_blocks Block: PEB# 189: LEB# 187
extract_blocks Block: PEB# 190: LEB# 188
extract_blocks Block: PEB# 191: LEB# 189
extract_blocks Block: PEB# 192: LEB# 190
extract_blocks Block: PEB# 193: LEB# 191
extract_blocks Block: PEB# 194: LEB# 192
extract_blocks Block: PEB# 195: LEB# 193
extract_blocks Block: PEB# 196: LEB# 194
extract_blocks Block: PEB# 197: LEB# 195
extract_blocks Block: PEB# 198: LEB# 196
extract_blocks Block: PEB# 199: LEB# 197
extract_blocks Block: PEB# 200: LEB# 198
extract_blocks Block: PEB# 201: LEB# 199
extract_blocks Block: PEB# 202: LEB# 200
extract_blocks Block: PEB# 203: LEB# 201
extract_blocks Block: PEB# 204: LEB# 202
extract_blocks Block: PEB# 205: LEB# 203
extract_blocks Block: PEB# 206: LEB# 204
extract_blocks Block: PEB# 207: LEB# 205
extract_blocks Block: PEB# 208: LEB# 206
extract_blocks Block: PEB# 209: LEB# 207
extract_blocks Block: PEB# 210: LEB# 208
extract_blocks Block: PEB# 211: LEB# 209
extract_blocks Block: PEB# 212: LEB# 210
extract_blocks Block: PEB# 213: LEB# 211
extract_blocks Block: PEB# 214: LEB# 212
extract_blocks Block: PEB# 215: LEB# 213
extract_blocks Block: PEB# 216: LEB# 214
extract_blocks Block: PEB# 217: LEB# 215
extract_blocks Block: PEB# 218: LEB# 216
extract_blocks Block: PEB# 219: LEB# 217
extract_blocks Block: PEB# 220: LEB# 218
extract_blocks Block: PEB# 221: LEB# 219
extract_blocks Block: PEB# 222: LEB# 220
extract_blocks Block: PEB# 223: LEB# 221
extract_blocks Block: PEB# 224: LEB# 222
extract_blocks Block: PEB# 225: LEB# 223
extract_blocks Block: PEB# 226: LEB# 224
extract_blocks Block: PEB# 227: LEB# 225
extract_blocks Block: PEB# 228: LEB# 226
extract_blocks Block: PEB# 229: LEB# 227
extract_blocks Block: PEB# 230: LEB# 228
extract_blocks Block: PEB# 231: LEB# 229
extract_blocks Block: PEB# 232: LEB# 230
extract_blocks Block: PEB# 233: LEB# 231
extract_blocks Block: PEB# 234: LEB# 232
extract_blocks Block: PEB# 235: LEB# 233
extract_blocks Block: PEB# 236: LEB# 234
extract_blocks Block: PEB# 237: LEB# 235
extract_blocks Block: PEB# 238: LEB# 236
extract_blocks Block: PEB# 239: LEB# 237
extract_blocks Block: PEB# 240: LEB# 238
extract_blocks Block: PEB# 241: LEB# 239
extract_blocks Block: PEB# 242: LEB# 240
extract_blocks Block: PEB# 243: LEB# 241
extract_blocks Block: PEB# 244: LEB# 242
extract_blocks Block: PEB# 245: LEB# 243
extract_blocks Block: PEB# 246: LEB# 244
extract_blocks Block: PEB# 247: LEB# 245
extract_blocks Block: PEB# 248: LEB# 246
extract_blocks Block: PEB# 249: LEB# 247
extract_blocks Block: PEB# 250: LEB# 248
extract_blocks Block: PEB# 251: LEB# 249
extract_blocks Block: PEB# 252: LEB# 250
extract_blocks Block: PEB# 253: LEB# 251
extract_blocks Block: PEB# 254: LEB# 252
extract_blocks Block: PEB# 255: LEB# 253
extract_blocks Block: PEB# 256: LEB# 254
extract_blocks Block: PEB# 257: LEB# 255
extract_blocks Block: PEB# 258: LEB# 256
extract_blocks Block: PEB# 259: LEB# 257
extract_blocks Block: PEB# 260: LEB# 258
extract_blocks Block: PEB# 261: LEB# 259
extract_blocks Block: PEB# 262: LEB# 260
extract_blocks Block: PEB# 263: LEB# 261
extract_blocks Block: PEB# 264: LEB# 262
extract_blocks Block: PEB# 265: LEB# 263
extract_blocks Block: PEB# 266: LEB# 264
extract_blocks Block: PEB# 267: LEB# 265
extract_blocks Block: PEB# 268: LEB# 266
extract_blocks Block: PEB# 269: LEB# 267
extract_blocks Block: PEB# 270: LEB# 268
extract_blocks Block: PEB# 271: LEB# 269
extract_blocks Block: PEB# 272: LEB# 270
extract_blocks Block: PEB# 273: LEB# 271
extract_blocks Block: PEB# 274: LEB# 272
extract_blocks Block: PEB# 275: LEB# 273
extract_blocks Block: PEB# 276: LEB# 274
extract_blocks Block: PEB# 277: LEB# 275
extract_blocks Block: PEB# 278: LEB# 276
extract_blocks Block: PEB# 279: LEB# 277
extract_blocks Block: PEB# 280: LEB# 278
extract_blocks Block: PEB# 281: LEB# 279
extract_blocks Block: PEB# 282: LEB# 280
extract_blocks Block: PEB# 283: LEB# 281
extract_blocks Block: PEB# 284: LEB# 282
read Error: Block ends at 37486592 which is greater than file size 37355540
extract_blocks Fatal: PEB: 285: Bad Read Offset Request

here the file

https://repository.ilpuntotecnicoeadsl.com/index.php?dir=Ansuel/&file=2C0000.ubi

Master node selection seems broken

Maybe I'm misreading the code, please correct me if I oversee something.

In ubifs/__init__.py you read only the first master node from UBIFS_MST_LNUM and UBIFS_MST_LNUM + 1.
But both LEBs usually contain a series of master nodes and you need to find the most recent one.
Otherwise you will start from oudated/wrong roots (for index, lpt, journal, ...).

ubi reader and scripts are broken when intstalled in a python3 environment

When installing ubi_reader in a python3 environment (E.g. Ubuntu 16.04 or newer), the scripts are broken.

ubi_reader is usually installed with

sudo pip install ubi_reader

This installs ubi_reader with a python3 shebang, resulting in the interpreter complaining about the python2 syntax:

$ ubireader_extract_images --help
  File "/usr/local/bin/ubireader_extract_images", line 38
    except Exception, e:
                    ^
SyntaxError: invalid syntax

Special files are not extracted properly, even with fakeroot

Works fine as root (sudo). With fakeroot, the flags are missed and it creates empty files only instead of char/block special files (devices).

diff -r --no-dereference ubifs-root/1365211099/rootfs/ realFS/
File ubifs-root/1365211099/rootfs/dev/console is a regular empty file while file realFS/dev/console is a character special file

Testing the mounted source file system - SHOULD SEE
ls -al realFS/dev/console
crw-r--r-- 1 root root 5, 1 Apr 18 23:30 realFS/dev/console
file realFS/dev/console
realFS/dev/console: character special (5/1)

Instead, we have a problem
sudo ls -al ubifs-root/1365211099/rootfs/dev/console
-rw-r--r-- 1 ts ts 0 Oct 11 20:29 ubifs-root/1365211099/rootfs/dev/console
sudo file ubifs-root/1365211099/rootfs/dev/console
ubifs-root/1365211099/rootfs/dev/console: empty

Refactor sort.by_image_seq

I would like to suggest a refactor to sort.by_image_seq to more directly make it represent a filtering function, which is what it implements based on the current code.

I am happy to submit a PR to do this, and we could just change the internals of the function and not the signature at all. I have tested that on my images at least, the results match -- and the intent is the same as well. This should be a super minor change but just wanted to contribute it as I get used to the internals of ubi_reader.

ubireader_extract_files goes ok, but ubireader_utils_info exits with error "File does not look like UBI data"

Hello.

I have successfully extracted data from ubifs image with ubireader_extract_files.
But when I try to pack it back, I run ubireader_utils_info so it will prepare the packing script.
But it exits with an error:

root@localhost:~/test# ubireader_utils_info -v -r ubimgfile
guess_start_offset Found UBIFS magic number at 0
guess_filetype Looking for file type at 0
guess_filetype File looks like a UBIFS image.
usage: ubireader_utils_info [options] filepath
ubireader_utils_info: error: File does not look like UBI data.

ubireader_display_info reports this ubimgfile is a UBIFS Image, and shows Super and Master block.

struct error

I'm trying to see info on a ubi/ubifs dump but I get this error:

Traceback (most recent call last):
  File "/usr/local/bin/ubireader_display_info", line 5, in <module>
    pkg_resources.run_script('ubi-reader==0.4', 'ubireader_display_info')
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 528, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1401, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/ubi_reader-0.4-py2.7.egg/EGG-INFO/scripts/ubireader_display_info", line 112, in <module>

  File "build/bdist.linux-x86_64/egg/ubireader/ubi/__init__.py", line 52, in __init__
  File "build/bdist.linux-x86_64/egg/ubireader/ubi/block/__init__.py", line 124, in extract_blocks
  File "build/bdist.linux-x86_64/egg/ubireader/ubi/block/__init__.py", line 65, in __init__
  File "build/bdist.linux-x86_64/egg/ubireader/ubi/headers/__init__.py", line 49, in __init__
struct.error: unpack requires a string argument of length 64

What is the cause? Any step that I could try?

Support for PyPi sdist

We are using ubi_reader as a dependency link in our PyPI repository.

pip install imgunbundler --extra-index-url http://myrepo:8081/simple --trusted-host myrepo --process-dependency-links -v

We are starting to hit some issues with upper versions of pip not properly processing the dependency links. We even read that it could be eventually they stop supporting dependency links due to security issues. We were wondering if we could help get a sdist up to the official pypi repository so the community of users could take advantage of the Python Package Index.

TypeError: 'int' object is not iterable

Hello Jason,

I'm trying to extract a UBI filesystem copied directly from a NAND flash. Unfortunately I'm struggling with the following error.

~/ubi$ ubireader_extract_files -l ubi.img
[...]
extract_blocks Block: PEB# 2117: LEB# -1
extract_blocks Block: PEB# 2118: LEB# -1
group_pairs [[690]]
group_pairs [[690, 691]]
group_pairs [[690, 691, 2102]]
group_pairs [[690, 691, 2102, 2103]] 
Traceback (most recent call last):
  File "/usr/local/bin/ubireader_extract_files", line 4, in <module>
    __import__('pkg_resources').run_script('ubi-reader==0.4', 'ubireader_extract_files')
  File "/home/derasd/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 735, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/home/derasd/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1659, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/ubi_reader-0.4-py2.7.egg/EGG-INFO/scripts/ubireader_extract_files", line 132, in <module>

  File "build/bdist.linux-x86_64/egg/ubireader/ubi/__init__.py", line 78, in __init__
  File "build/bdist.linux-x86_64/egg/ubireader/ubi/image/__init__.py", line 31, in __init__
TypeError: 'int' object is not iterable

The full verbose output was too big for pastebin, so here is the -l output:
http://pastebin.com/nsuanYBm

And here I uploaded the whole flashdump:
http://www.megafileupload.com/b66i/ubiFlashFile

Do you have any idea what is going wrong?

Best regards,
Phil

extract_files not preserving set-user-ID or set-group-ID permission bits

In _set_file_perms function in ubireader/ubifs/output.py, chown may be clearing set-user-ID or set-group-ID permission bits

def _set_file_perms(path, inode):
    os.chmod(path, inode['ino'].mode)
    os.chown(path, inode['ino'].uid, inode['ino'].gid)

For example, a file's original permission -rwsr-xr-x may become -rwxr-xr-x after extraction.

In order to preserve set-user-ID or set-group-ID permission bits, chmod should be called after chown.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.