Im trying to edit the bytes of a file. More like a hex viewer/editor. For example:
//Adding the file bytes to array (byte array)
$bytes = str_split(file_get_contents("test.file")); //It can be any file. like jpg,png, exe, jar...
And now i want just to edit 5 bytes and change them to some chracter values. For example:
//Adding the file bytes to an array (byte array)
$bytes = str_split(file_get_contents("test.file")); //It can be any file. like jpg,png, exe,jar...
$string = "hello";
$bytes[5] = $string[0];
$bytes[6] = $string[1];
$bytes[7] = $string[3];
$bytes[8] = $string[4];
file_put_contents("edited.file", $bytes);
But it just doesnt work... I need to convert first the letters of the $string to bytes and then edit the specific bytes of the byte array ($bytes), without corrupting the file.
I have tried using unpack(), pack() functions but i cant make it work... I have tried also ord() function but then saves them as interger, but i want to save the bytes of the string.