WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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
Víctor Román Archidona
Date : Jul 09th 2007
Grade : 4 of 5 (graded 1 times)
Viewed : 6663
File : 4670.zip
Images : No Images for this code example.
Search : More code by Víctor Román Archidona
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

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;
    }
}
?>




Remote Archive (Zip, Tar, Gzip) downloader with FTP and local extration support
Categories : PHP, FTP, Filesystem, PHP Classes, Compression
DbObject - A PHP wrapper for working with various databases
Categories : Databases, PHP, PHP Classes
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
Browser Detecor Class
Categories : PHP Classes, PHP, HTML
filesplit : Split big text files in multiple small ones
Categories : PHP, Log Files, Filesystem, PHP Classes
A File Browser Class.To Read Drives,Directories and Files .Files writing is also possible
Categories : PHP, PHP Classes, Filesystem
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
Filter - A simple class that lets you use multiple functions to create custom filters.
Categories : PHP, PHP Classes, Strings
The GTV.class allows you to extract a value between any HTML tag or between any TEXT on a web page.
Categories : PHP, PHP Classes, Regexps
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
Simple and fast user authentication
Categories : PHP, PHP Classes, Authentication
Client classes for Dictionary servers UPDATED: 2000-06-06
Categories : Network, Search, Complete Programs, PHP Classes, PHP
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Bs_IniHandler is a class that can read and write ini-style files (and strings)
Categories : PHP, Filesystem, PHP Classes