Jump to content

Help with fwrite + pack


aquadeluxe

Recommended Posts

I'm having trouble with this code.

 

<?php
$path_to_file = "file_e.bin";

$fp = fopen($path_to_file, "w+b");
fseek($fp, 0x103, SEEK_SET);
fwrite($fp, pack('H*', '6E'));
fclose($fp);

?>

 

What is happening is the file is normally a very long file, but it then just gets truncated to 0x103, and all the hex before 0x103 gets turned into 00. Does anyone have a solution?

Link to comment
https://forums.phpfreaks.com/topic/99157-help-with-fwrite-pack/
Share on other sites

You have stated what happens but not what you expect..

from looking at the code i assume you didn't expect the zeros

change

fwrite($fp, pack('H*', '6E'));

should be

fwrite($fp, pack('H*', 6E));

 

also

$fp = fopen($path_to_file, "w+b");

should be

$fp = fopen($path_to_file, "r+");

 

Link to comment
https://forums.phpfreaks.com/topic/99157-help-with-fwrite-pack/#findComment-508271
Share on other sites

I want to just change the 0x103 offset and keep all of the other bytes in tack.

 

When I change from w+b to r+ without changing the pack statement, it then returns the whole file, but 0x103 is still in it's original form. When I change omit the single quotes on 6E, it just gives a T_STRING error.

Link to comment
https://forums.phpfreaks.com/topic/99157-help-with-fwrite-pack/#findComment-508326
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.