Question

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?

Was it helpful?

Solution

I would try this:

$fp = fopen('test.exe', 'ab');
for ($i = 0, $i < 10000, $i++) {
fwrite($fp, 'a');
}
fclose($fp);

also, personaly i would prefer if the charactor you were writing coresponded to NOP. But, if it works, it works...

OTHER TIPS

Yes, looping the fwrite() multiple times should achieve the same effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top