|
|
|
The file offset is stored using a class for their manageability, it stores the current offset and reads the specified bytes without making the user fight against that.
More about ELF : http://en.wikipedia.org/wiki/Executable_and_Linkable_Format
Example Usage
| <?php
/* Some files...: */
$binaries = array("/bin/bash", "/sbin/ifconfig");
/* Dumps the ELF file information: */
foreach ($binaries as $binary) {
if (!is_file($binary))
continue;
echo "Dumping information about: $binary\n";
print_r(readHeader($binary));
echo "\n";
}
function readHeader($file)
{
/* Our file management class: */
require_once "filereader.class.php";
$fr = new FileReader($file, "rb");
/* Gets the first 16 bytes (E_IDENT): */
$bytes = $fr->readBytes(16);
$magic = unpack("C16", $bytes);
/* Cheks if the file is a valid ELF file: */
if ($magic[1] != 0x7f
|| $magic[2] != ord('E')
|| $magic[3] != ord('L')
|| $magic[4] != ord('F')) {
die("Specified file is not an ELF binary");
}
/* And now reads the rest of information (~52 bytes): */
$elf_information = array(
"ei_class" => $magic[5],
"ei_data" => $magic[6],
"ei_version" => $magic[7],
"ei_osabi" => $magic[8],
"ei_abiversion" => $magic[9],
"ei_pad" => $magic[10],
"ei_nident" => $magic[16],
"e_type" => getElementZero(unpack("S*", $fr->readBytes(2))),
"e_machine" => getElementZero(unpack("S*", $fr->readBytes(2))),
"e_version" => getElementZero(unpack("I*", $fr->readBytes(4))),
"e_entry" => getElementZero(unpack("I*", $fr->readBytes(4))),
"e_phoff" => getElementZero(unpack("I*", $fr->readBytes(4))),
"e_shoff" => getElementZero(unpack("I*", $fr->readBytes(4))),
"e_flags" => getElementZero(unpack("I*", $fr->readBytes(4))),
"e_ehsize" => getElementZero(unpack("S*", $fr->readBytes(2))),
"e_phentsize" => getElementZero(unpack("S*", $fr->readBytes(2))),
"e_phnum" => getElementZero(unpack("S*", $fr->readBytes(2))),
"e_shetsize" => getElementZero(unpack("S*", $fr->readBytes(2))),
"e_shnum" => getElementZero(unpack("S*", $fr->readBytes(2))),
"e_shtrndx" => getElementZero(unpack("S*", $fr->ReadBytes(2)))
);
return $elf_information;
}
function getElementZero($where)
{
return $where[1];
}
?> | |
filereader.class.php
| <?php
class FileReader
{
private $_fh = null;
private $_offset = 0;
public function __construct($file, $mode)
{
if (is_readable($file))
$this->_fh = fopen($file, $mode);
}
public function __destruct()
{
if ($this->_fh)
fclose($this->_fh);
}
public function getOffset()
{
return $this->_offset;
}
public function readBytes($bytes)
{
if (!$this->_fh)
return null;
$read = fread($this->_fh, $bytes);
$this->_offset += $bytes;
fseek($this->_fh, $this->_offset);
return $read;
}
}
?> | |
|
|
| very simple ftp class Categories : PHP, PHP Classes, FTP | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | A Timing Class Categories : PHP, PHP Classes, Date Time | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | Create HTML forms dynamicly using Javascript & PHP Categories : PHP, PHP Classes, Java Script | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | | | RSS parser.
Parses RSS into an array. Quick and nasty but does the job.
No checking is done for correct Tags, only correct XML.
PHP4 needed to display result (uses print_r). Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS) | | | Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags. Categories : PHP, PHP Classes, Algorithms, Security | | | an example of the cyberlib payment class Categories : PHP, PHP Classes, Ecommerce, Credit Cards | | | Power Form Validation Categories : PHP, PHP Classes, Data Validation | | | MySQL Handler Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip Categories : Email, Network, PHP, PHP Classes | | | Browser Detecor Class Categories : PHP Classes, PHP, HTML | | | PostGreSQL and MySQL 2 in 1 db Manager Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL | |
|
|
|