Hex editting
Moderator: General Moderators
-
aquadeluxe
- Forum Newbie
- Posts: 6
- Joined: Mon Mar 31, 2008 7:18 pm
Hex editting
Is there anyway in PHP to change hex values like in C?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
-
aquadeluxe
- Forum Newbie
- Posts: 6
- Joined: Mon Mar 31, 2008 7:18 pm
Re: Hex editting
Sorry I didn't explain myself well enough. I wanted to know how I can edit hex values from a file. An example would be change the offset 0x103 from 74 to 6E.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Hex editting
Untested:aquadeluxe wrote:Sorry I didn't explain myself well enough. I wanted to know how I can edit hex values from a file. An example would be change the offset 0x103 from 74 to 6E.
Code: Select all
$fp = fopen($path_to_file, "w+b"); //Open file for reading and writing in binary mode
fseek($fp, 0x103, SEEK_SET); //Seek to 0x103
fwrite($fp, pack('H*', '6E')); //Write 0x6E packed into a binary byte
fclose($fp); //Close the filehttp://php.net/fopen
http://php.net/fread
http://php.net/fwrite
http://php.net/fseek
http://php.net/fclose
http://php.net/pack
http://php.net/unpack
-
aquadeluxe
- Forum Newbie
- Posts: 6
- Joined: Mon Mar 31, 2008 7:18 pm
Re: Hex editting
It worked, kinda. It change 0x103 to 6E, but everything before it was 00 and the file ended at 0x103 instead of keep on going.