Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.