-
Notifications
You must be signed in to change notification settings - Fork 89
feat(handler): add partclone handler #1155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job :)
4333278
to
48d9d40
Compare
partclone is not available on OSX in nixpkg - https://github.com/onekey-sec/unblob/actions/runs/14124724723/job/39571274718?pr=1155 Would need to provide a patch for https://github.com/NixOS/nixpkgs/blob/e6057380b59bdf9a3693ca3ef45d67e6a95a0d66/pkgs/by-name/pa/partclone/package.nix. Will look into it. It will take some time since I need to spin up some VMs. |
I looked into partclone, it can't be built on OSX. It depends on libraries that are only available on Linux (e.g. We need the ability to tag handlers as unsupported on OSX so their test is not run when testing on that platform. Ideas welcome. |
I found a python build in lib that can return information about the system: Could we not match on that and set the test on |
We still need a way to mark the test as skipped if platform is not supported by the handler in test_all_handlers. Will look into it. |
fba0229
to
8a57c5b
Compare
d901a03
to
b9d7977
Compare
There are CI failures (I remember commenting this, so my bad originally, the current code is both more verbose and not supported by earlier python versions): Literal[2] | Literal[4] should be Literal[2, 4] and also its test is failing the type check, and it will even after this fix, so take a look: /home/runner/work/unblob/unblob/tests/test_file_utils.py:364:62 - error: Argument of type "int" cannot be assigned to parameter "endian_len" of type "Literal[2, 4]" in function "get_endian"
Type "int" is not assignable to type "Literal[2, 4]"
"int" is not assignable to type "Literal[2]"
"int" is not assignable to type "Literal[4]" (reportArgumentType)
/home/runner/work/unblob/unblob/tests/test_file_utils.py:390:48 - error: Argument of type "int" cannot be assigned to parameter "endian_len" of type "Literal[2, 4]" in function "get_endian"
Type "int" is not assignable to type "Literal[2, 4]" |
get_endian was limited to 32 bit integer magic values and partclone required checking a 16 bit integer magic value. We therefore created get_endian_short and expose it from file_utils.
Partclone is a utility used for backing up and restoring partitions. Many cloning tools (such as Clonezilla) rely on it to create block-level images that include filesystem metadata. Right now only partclone version 2 is supported. end offset is computed from data available in partclone's super block. Extraction is performed by `partclone.restore`, which is part of `partclone` package on Debian based systems and Nix.
partclone is not available on Darwin (OSX), so we need to skip that test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work and revisions! :)
Partclone is a program similar to the well-known backup utility "Partition Image" a.k.a partimage. Partclone provides utilities to save and restore used blocks on a partition and is designed for higher compatibility of the file system by using existing libraries, e.g. e2fslibs is used to read and write the ext2 partition.
Partclone now supports ext2, ext3, ext4, hfs+, reiserfs, reiser4, btrfs, vmfs3, vmfs5, xfs, jfs, ufs, ntfs, fat(12/16/32), exfat, f2fs, nilfs.
Partclone has two version. This handler supports the second one and automatically checks the endian value.
Create partclone image:
partclone.[file_system] -F -c -s [source_file] -o [output.img] -L /dev/stdout[default=/var/log/partclone.log]
Restore partclone image:
partclone.restore -W -r -s [source_fiile.img] -o [restored.img] -L /dev/stdout[default=/var/log/partclone.log]
Notes
-L
should be used since it will lead in the most cases to errors.img
The header has the following structure :
Unblob parses the header to determine the start and end offset by adding:
Block size
*Blocks per checksum
. Each N-Bytes a 4 byte checksum will occur (min: 1)Finally the
CRC32
value in the header does not the final XOR with0xFFFFFFFF
. This can lead to deviation if checked manually.[Sources]
https://github.com/Thomas-Tsai/partclone
https://partclone.org/
https://wiki.osdev.org/Ext2
https://piazza.com/class_profile/get_resource/il71xfllx3l16f/inz4wsb2m0w2oz
https://www.science.smith.edu/~nhowe/262/oldlabs/ext2.html
https://www.science.smith.edu/~nhowe/262/oldlabs/kernel/ext2_fs.h