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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux