Last active
August 29, 2015 14:20
-
-
Save bertrandmartel/222851db26687323026f to your computer and use it in GitHub Desktop.
[ SHELL - JAVA ] Convert a file to hexadecimal format with xxd command and build a Java formatted static byte array with all these values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z $1 ];then | |
echo -e "\x1B[31mError binary file required\x1B[0m" | |
exit -1 | |
fi | |
if [ ! -f $1 ];then | |
echo -e "\x1B[31mInput file does not exist\x1B[0m" | |
exit -1 | |
fi | |
echo -ne "\x1B[01;93m" | |
xxd -p $1 | sed ':a;N;$!ba;s/\n/ /g' | sed 's/ //g' | sed 's/\(.\{2\}\)/\1,(byte)0x/g' | sed 's/^/public final static byte[] cert = new byte[]{0x/' | sed 's/\(,(byte)0x\)$/};/' | |
echo -ne "\x1B[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment