Jump to content

Help with making directory structures from gz


DarkWater

Recommended Posts

Okay.  I'm usually the one answering the questions on this forum, but I ran into a new function today and was eager to learn about it.  Well, I did, and I figured out how to self-extract a file from a PHP script.  This is my code:

 

<?php

//gzdecode function
function gzdecode ($data) {
$flags = ord(substr($data, 3, 1));
$headerlen = 10;
$extralen = 0;
$filenamelen = 0;
if ($flags & 4) {
$extralen = unpack('v' ,substr($data, 10, 2));
$extralen = $extralen[1];
$headerlen += 2 + $extralen;
}
if ($flags & 8  ) // Filename
$headerlen = strpos($data, chr(0), $headerlen) + 1;
if ($flags & 16) // Comment
$headerlen = strpos($data, chr(0), $headerlen) + 1;
if ($flags & 2) // CRC at end of file
$headerlen += 2;
$unpacked = gzinflate(substr($data, $headerlen));
if ($unpacked === FALSE)
$unpacked = $data;
return $unpacked;
}
//
//
//AFTER FUNCTION:
//////////////////////////////////
if (!isset($_GET['extract'])) {
echo '<a href="' . substr($_SERVER['PHP_SELF'], strrpos("/", $_SERVER['PHP_SELF']), strlen($_SERVER['PHP_SELF'])) . '?extract=1">Extract file.</a>';
die();
}
$fp = fopen(__FILE__, 'r');
// seek file pointer to data
fseek($fp, __COMPILER_HALT_OFFSET__);
// and output it
$buffer = fread($fp,8192);
$decoded = gzdecode(base64_decode($buffer));
//$uncompressed = gzdecode($decoded);

$filename = "pleasework.php";
$fd = fopen($filename,"w");
fwrite($fd,$decoded);
fclose($fd);

echo "File written correctly!";
__halt_compiler();H4sIAAAAAAAAA7OxL8go4EpNzshXUPLxB0Mlay57Oy4AHe25CBkAAAA=

 

That's my whole script.  Even though there's no closing PHP tag, it's perfectly valid.  The function I learned was __halt_compiler();, and the string after it is a base64, gzencoded representation of small php file.  It works perfectly and allows me to extract the file and create it.  My question is how do I create directory trees and multiple files with this "self-extracting" method?  FUDForum uses it in its install, if anyone wants to check it out. >_> 

 

Many thanks to those who help...or even have an idea about what I just said. >_>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.