xxd

How to convert hexadecimal hash into binary at terminal?

▼魔方 西西 提交于 2021-01-29 19:25:15
问题 Main question: How to use xxd -r ? Secondary details. This command outputs a hexadecimal hash: openssl dgst -sha256 myFile | awk '{print $2}' > myHashHex I suppose that myHashHex is a "hexdump", isn't it? I thought that xxd -r < myHashHex will convert... Well, it does not work . NOTES To test/compare. I think that this is the same (no headers) in binary: openssl dgst -sha256 -binary myFile > myHashBin So, I expected that xxd -r < myHashHex > newHashBin generates newHashBin = myHashBin . PS:

Why is DH prime and its hex different in openssl?

匆匆过客 提交于 2020-02-08 10:01:30
问题 From the below, why is prime not same as xxd hex? I am trying to generate my own parameters but not sure what is the math for those values... [root@localhost]# openssl dh -in dhp.pem -text DH Parameters: (1024 bit) prime: 00:94:b4:12:21:6d:42:b9:e3:1a:15:de:0a:ee:b6: 4b:41:fa:8f:de:44:1e:ea:a2:a2:9c:b2:28:47:19: 88:f8:65:0a:e6:09:58:c3:69:69:b4:d5:d4:d2:b5: 21:4d:1f:9b:a9:78:58:37:94:0f:6e:51:00:62:e5: d2:44:53:36:72:99:1f:22:fc:a3:93:ab:3a:e8:3f: 7b:1b:49:36:82:1c:c3:35:4b:ef:43:f9:d4:1d:6c:

Create Binary files in UNIX

时光毁灭记忆、已成空白 提交于 2019-12-31 22:22:07
问题 This question was out there for a while and I thought I should offer some bonus points if I can get it to work. What did I do… Recently at work, I wrote a parser that would convert a binary file in a readable format. Binary file isn't an Ascii file with 10101010 characters. It has been encoded in binary. So if I do a cat on the file, I get the following - [jaypal~/Temp/GTP]$ cat T20111017153052.NEW ==?sGTP?ղ?N????W????&Xx1?T?&Xx1?; ?d@#e? ?0H????????|?X?@@(?ղ??VtPOC01 cceE??k@9??W傇??R?K?i2??d

How to print float value from binary file in shell?

风流意气都作罢 提交于 2019-12-21 17:18:40
问题 I've binary file consisting double float (8 bytes) or just float (4 bytes) value which was generated in the following way: $ python -c $'from struct import pack\nwith open("file.bin", "wb") as f: f.write(pack("<d", 0.123))' $ xxd file.bin 00000000: b072 6891 ed7c bf3f .rh..|.? which I could print it back from Python via: $ python -c $'from struct import unpack\nwith open("file.bin", "rb") as f: print(unpack("<d", f.read(8)))' (0.123,) The same for 4-byte float, just change <d into <f

How to search & replace arbitrary literal strings in sed and awk (and perl)

放肆的年华 提交于 2019-12-20 03:48:06
问题 Say we have some arbitrary literals in a file that we need to replace with some other literal. Normally, we'd just reach for sed (1) or awk (1) and code something like: sed "s/$target/$replacement/g" file.txt But what if the $target and/or $replacement could contain characters that are sensitive to sed (1) such as regular expressions. You could escape them but suppose you don't know what they are - they are arbitrary, ok? You'd need to code up something to escape all possible sensitive

How to insert an offset to hexdump with xxd?

岁酱吖の 提交于 2019-12-12 03:15:59
问题 Is there an easy way to add an offset to the hex dump generated by xxd ? i.e instead of 0000: <data> 0004: <data> 0008: <data> I should get Offset+0000: <data> Offset+0004: <data> Offset+0008: <data> 回答1: This is what I am doing now..It works perfectly but its kind of lame approach for just adding an offset :) xxd file.bin | xxd -r -s 0x2e00000 | xxd -s 0x2e00000 > file.hex 回答2: xxd now appears to come with offset support, using -o [offset] for example: xxd -o 0x07d20000 file.bin My version

How best can I programmatically apply `__attribute__ ((unused))` to these auto-generated objects?

允我心安 提交于 2019-12-10 19:34:21
问题 In my makefile I have the following target, which "compiles" text/HTML resources into unsigned char arrays using xxd -i. I wrap the result in an anonymous namespace and header guards for multiple-inclusion safety both inside and between translation units. templates.h: @echo "#ifndef TEMPLATES_H" > templates.h @echo "#define TEMPLATES_H" >> templates.h @echo "// Auto-generated file! Do not modify!" >> templates.h @echo "// NB: arrays are not null-terminated" >> templates.h @echo "// (anonymous

diff - find specific change between two values in hex dump

半腔热情 提交于 2019-12-07 10:28:33
问题 I am analyzing hex data from binary data dumps from a basic command-line program of mine. I'm basically dumping the exact contents of a struct (a large array of structs, actually) to a text file. I then create a second binary dump, and compare the two files in vim using xxd to create binary-to-text representations of the original data. Both files are the exact same size in bytes, and I'm trying to compare the two in a meaningful way. Even a small change in the data before I dump the file

How to print float value from binary file in shell?

点点圈 提交于 2019-12-04 08:28:17
I've binary file consisting double float (8 bytes) or just float (4 bytes) value which was generated in the following way: $ python -c $'from struct import pack\nwith open("file.bin", "wb") as f: f.write(pack("<d", 0.123))' $ xxd file.bin 00000000: b072 6891 ed7c bf3f .rh..|.? which I could print it back from Python via: $ python -c $'from struct import unpack\nwith open("file.bin", "rb") as f: print(unpack("<d", f.read(8)))' (0.123,) The same for 4-byte float, just change <d into <f (mentioned as float.bin later on). How do I print that value from the shell script using cleaner way (without

How to search & replace arbitrary literal strings in sed and awk (and perl)

女生的网名这么多〃 提交于 2019-12-02 02:06:26
Say we have some arbitrary literals in a file that we need to replace with some other literal. Normally, we'd just reach for sed (1) or awk (1) and code something like: sed "s/$target/$replacement/g" file.txt But what if the $target and/or $replacement could contain characters that are sensitive to sed (1) such as regular expressions. You could escape them but suppose you don't know what they are - they are arbitrary, ok? You'd need to code up something to escape all possible sensitive characters - including the '/' separator. eg t=$( echo "$target" | sed 's/\./\\./g; s/\*/\\*/g; s/\[/\\[/g; .