retrieve file sha1

Comments, questions, bug reports, etc.
Post Reply
bliblubli
Posts: 88
Joined: Thu Dec 31, 2015 10:45 am

retrieve file sha1

Post by bliblubli »

Hi Synchronicity,

Would it be possible allow user to retrieve the sha1 of a file by giving a path?
A Python API would really be awesome :)

Regards
synchronicity
Site Admin
Posts: 474
Joined: Sun Aug 02, 2015 10:31 pm

Re: retrieve file sha1

Post by synchronicity »

With wimlib-imagex you can use a command like:

Code: Select all

$ wimdir --detail test.wim 1 --path=ntoskrnl.exe --detailed

Full Path           = "/ntoskrnl.exe"
Short Name          = ""
Attributes          = 0x00000080
    FILE_ATTRIBUTE_NORMAL is set
Security Descriptor = 010004801400000024000000000000004000000001020000000000052000000020020000010500000000000515000000f20f597dc2d32339192be7b901020000020060000400000000001800ff011f000102000000000005200000002002000000001400ff011f0001010000000000051200000000001400bf01130001010000000000050b00000000001800a900120001020000000000052000000021020000
Creation Time       = Fri Dec 06 07:26:51 2013 UTC
Last Write Time     = Fri Dec 06 07:26:51 2013 UTC
Last Access Time    = Fri Dec 06 15:26:28 2013 UTC
Link Group ID       = 0x0000000000000000
Link Count          = 1
	Unnamed data stream:
Hash              = 0xbc27394e041a95f85d7466f27715889ee4fc11bf
Uncompressed size = 3911040 bytes
Compressed size   = 2006938 bytes
Offset in WIM     = 5004 bytes
Part Number       = 1
Reference Count   = 1
Flags             = WIM_RESHDR_FLAG_COMPRESSED  
The "SHA-1 of the file" is listed as the hash of the unnamed data stream. (Yes, it's pretty clunky; it was originally meant for debugging. It might be nice to add a format option, so you could specify something like --format="%n %h" and just get filenames and hashes, one per line.)

The underlying API funtion is wimlib_iterate_dir_tree(). It will give you the metadata for either one file, the files in a directory, or the files in a directory tree, depending on the flags passed.
bliblubli
Posts: 88
Joined: Thu Dec 31, 2015 10:45 am

Re: retrieve file sha1

Post by bliblubli »

thanks for the quick and detailed answer. It's exactly what I was looking for. Indeed a format option would help a lot :)
Post Reply