Re: Semi-newbie Question .... streams ...

From: Date: Thu, 15 Nov 2007 19:12:42 +0000
Subject: Re: Semi-newbie Question .... streams ...
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-264621@lists.php.net to get a copy of this message
Per Jessen wrote:
Jim Lucas wrote:
If this is an EXE, I assume it is in binary format? If so, would not your serial number have been compiled into the software? Wouldn't a simple search/replace fail in this case?
If the string (the serial number) is unique, and all in one place, a simple search/replace will do fine. /Per Jessen, Zürich
Well, then in this case, I would get the two strings that you want to work with and then do something like this. I would try and keep the binary organized in such a way that the marker string would be at the beginning of the file. One problem you might run into doing it this way is that you might catch the marker string on your chunk block break point. In that case, it will not work. By no means is this a complete script, or should it be used without some additional sanity checks USE AT YOUR OWN RISK <?php $chunk_size = 1024; $marker = 'somestring'; $serial = 'somenewstring'; // Please to sanity checks here to make sure they are not trying to get protected files :) $filename = $_GET['filename']; // Try and open file, if you can't, display error if ( ( $fh = fopen($filename, 'r') === false ) { echo "Could not get file"; die(); } // If we are still go2go, send headers for download
        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment; filename=\"whatever.exe\"");
// Get a line of data while ( $data = fgets($fh, $chunk_size) ) { // Check data for serial marker if ( strpos($data, $marker) !== false ) { // if found, replace marker with actual number $data = str_replace($marker, $serial, $data); } // Send data to browser echo $data; } exit; ?> -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare

« previous php.general (#264621) next »