Add bytes to binary file using only PHP?
Posted
by hurmans
on Stack Overflow
See other posts from Stack Overflow
or by hurmans
Published on 2010-06-16T14:20:56Z
Indexed on
2010/06/16
14:22 UTC
Read the original article
Hit count: 305
I am trying to add random bytes to binary (.exe) files to increase it size using php. So far I got this:
function junk($bs)
{
// string length: 256 chars
$tmp = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
for($i=0;$i<=$bs;$i++)
{
$tmp = $tmp . $tmp;
}
return $tmp;
}
$fp = fopen('test.exe', 'ab');
fwrite($fp, junk(1));
fclose($fp);
This works fine and the resulting exe is functional but if I want to do junk(100) to add more size to the file I get the php error "Fatal error: Allowed memory size..."
In which other way could I achieve this without getting an error? Would it be ok to loop the fwrite xxx times?
© Stack Overflow or respective owner