0

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?

4
  • My god, that's exponentional. I can't even begin to fathom how large the string would be when called with junk(100)... Commented Jun 16, 2010 at 14:32
  • That's why I am asking for a better way to do it, thanks. Commented Jun 16, 2010 at 14:34
  • Actually, according to Google, the string would be of length 3.24518554 × 10^32, no wonder you're running out of memory ;) Commented Jun 16, 2010 at 14:37
  • I knew it runs out of memory before coding it, I did it just to show what I am trying to achieve. Commented Jun 16, 2010 at 14:41

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
@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.
Of course, it raisesthe question of why you are modifying an exe file
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.