LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2007, 04:28 PM   #1
icetomyst
LQ Newbie
 
Registered: Jun 2006
Distribution: FC5
Posts: 14

Rep: Reputation: 0
php bin2hex -> hex2bin


OK what im trying to do is unpack some bin2hex data from an xml document and print it into a phpnuke block and i need to be able to apply html formatting to it.
The document being: http://www.pbbans.com/sigs/142.xml

The printing part works fine, but I can't seem to get a hex2bin function to unpack the data properly.

I've tried quite a few things, this being the latest:

Code:
function hex2bin($hexdata){
for( $i = 0; $i < strlen( $hexdata ); $i += 2 )
eval( '$bindata .= "\x' . substr( $hexdata, $i, 2 ) . '";' );
return $bindata;
}

ob_start(); 
include("http://www.pbbans.com/sigs/142.xml");
$output = ob_get_contents();
ob_end_clean(); 
$content = hex2bin($output);
BUT it ends up returning this:

Code:
\x \x <\xGR\xOU\xP_\xNA\xME\x>4g&r6öÇWF–ö<\x/G\xRO\xUP\x_N M>\x \x6g2<\x/G\xRO\xUP\x_T G\x> \x <\xGR\xOU\xP_\xWW\xW>http://www.et-main.com/\x\x \x7wwræWBÖÖ–âæ6öÒ<\x/G\xRO\xUP\x_W\xWW\x_S\xHO\xRT\x> \x <\xHE*\x_A M\xIN\x>4Ö¶fVÆ <\x/Hê _*\xMI\xN>\x \xMakaveli\x \x <\xTO\xTA\xL_\xSE\xRVR\xS>4\x\x \x3<\x/S\xTRê\xMI\xNG\x_SR\xVE\xRS\x> \x <\xTO\xTA\xL_º\xNS\x>3C<\x/T\xOT L\x_B N\xS>\x \x3dd0133d685dfdd6fa3d4053a0ac4205\x \x <\xLA\xST\x_B N\xNE _\xGU\xID\x_E\xIG\xHT\x>63C#<\x/L S\xT_º\xNNí\x_G\xUI _I\xGH\xT>\x \x72.232.53.174:27960\x \x <\xLA\xST\x_B N\xNE _\xNIK\x>4w#e <\x/L S\xT_º\xNNí\x_N\xIC\xK>\x \xMay 06, 2007\x \x\x
Which does have SOME of the information unpacked, but obviously isn't right.

Anyone know where I'm going wrong with this?
 
Old 05-06-2007, 06:38 PM   #2
MajinCline
LQ Newbie
 
Registered: Mar 2007
Distribution: Ubuntu Feisty
Posts: 5

Rep: Reputation: 0
The problem is that you are using your hex2bin function on the entire xml file when you only want the data parsed. This is making it hiccup when it sees an invalid hex octet. Everything seems to work just fine with the exception of parsing the file which you will have to do as I don't know how this data is going to be used exactly. If you need help reading in from an xml so that you can use hex2bin on each value, try looking up the xml functions in php particularly xml_parse_create. The comments on that page are especially helpful.


A couple things you should look at when fixing the script up is that the hex2bin function could be simplified to:
PHP Code:
function hex2bin($hexdata){
    return 
pack("H*"$hexdata);

... also, instead of reading the file into the output buffer, use file_get_contents or fread, like this:
$output =
PHP Code:
file_get_contents("http://www.pbbans.com/sigs/142.xml"); 
Including a file like that is just asking for security problems and to eval() parts of it is even worse if if any part of the file isn't trusted.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Are PHP session variables held in memory when you leave a PHP site? Locura Programming 11 11-16-2008 08:37 PM
Adding users with PHP (pass php variables to Expect script) Jayla Programming 1 10-20-2006 10:44 AM
Php account verify email links back to php.org zenerdiode Linux - Server 3 10-03-2006 05:21 PM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
Updating php 4.3.1 from tar and keeping current php configuration with mandrake 9.1 mrjeep Linux - General 0 04-02-2003 07:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration