views:

35

answers:

2

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?

+2  A: 

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

Eric Petroelje
+1  A: 

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

thomasfedb
What is NOP ???
hurmans
No Operation. Since you are appending an executable, thomasfedb is suggesting that you may wish to append an instruction that does nothing at all, to be on the safe side. You'd need to check your microprocessor's documentation to find such an instruction.
webbiedave
@hurmans NOP is "No Operation", a valid assembly language instruction that has no direct effect on the running of a program. If included in an .exe file, it won't corrupt the code in that file.
Mark Baker
Of course, it raisesthe question of why you are modifying an exe file
Mark Baker
Indeed. –––––––
webbiedave
+1 for NOP. (15char)
Aistina