WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : ElfReader: An ELF (Executable and Linking Format) header information in PHP. Shows how to use the UNPACK function to read data.
Categories : PHP, Linux, PHP Classes Click here to Update Your Picture
Victor Roman
Date : Jul 09th 2007
Grade : 4 of 5 (graded 1 times)
Viewed : 1707
File : 4670.zip
Images : No Images for this code example.
Search : More code by Victor Roman
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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