writefile(): const-ify buffer arg
Add missing includes
Add hex2bin and bin2hex