- Joined
- Jun 28, 2006
- Messages
- 285
- Reaction score
- 165
Credits: Myself.
Source: PHP
Status: Incomplete, it will not be finished.
Perhaps someone else will find some use from it. Enjoy.
Source: PHP
Status: Incomplete, it will not be finished.
Perhaps someone else will find some use from it. Enjoy.
PHP:
<?php
/*Nerv is created by Leo Renard.*/
$filename = "rank1.img";
//Softnyx Nerv.php, because SoftDICKS won't let us have Nerv.exe. We'll just have to create a better script than their own!
function ascii2hex($ascii) {
$hex = '';
for ($i = 0; $i < strlen($ascii); $i++) {
$byte = strtoupper(dechex(ord($ascii{$i})));
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
$hex.=$byte."";
}
return $hex;
}
function hex2ascii($hex){
$ascii='';
$hex=str_replace("", "", $hex);
for($i=0; $i<strlen($hex); $i=$i+2) {
$ascii.=chr(hexdec(substr($hex, $i, 2)));
}
return($ascii);
}
if(isset($_GET["image"])){
$data = $_GET["data"];
$hdata = dechex($_GET["h"]);
if(strlen($hdata) == 2){
$hdata = $hdata . "00";
} else if(strlen($hdata) == 3){
$hdata = $hdata . "0";
} else {
$hdata = $hdata;
}
$wdata = dechex($_GET["w"]);
//echo $data;
$n = $_GET["h"]*2;
$trudata = wordwrap($_GET["data"], $n, "0000", true);
echo $trudata;
$bitmap = hex2ascii("424D684E00000000000046000000380000000F000000E7FFFFFF0100100003000000224E0000120B0000120B0000000000000000000000F80000E00700001F00000000000000{$trudata}00000000");
$fp = fopen('bitmap.bmp', 'w');
fwrite($fp, $bitmap);
fclose($fp);
echo "<img src='bitmap.bmp'><p>";
echo ascii2hex($bitmap) . "<p>OR<p>" . $bitmap;
//header("Content-type: image/bmp");
//make an image instead
} else {
//r we a websight`?~! wut?
$file = file_get_contents($filename);
//echo strlen($file) . " Bytes";
//the above was to check how long our file was in bytes
$hex = ascii2hex($file);
//ascii2hex is an awesome function.
echo "<b>According to the .img header, there are these many images:</b> " . hexdec(substr($hex, 8, 2)) . " (or " . substr($hex, 8, 2) . ")<p>";
//That's what the header says! Is it lying? If it is, kill the script! BURN IT WITH FIRE!
echo "<b>..And if we guess right, the start of each image should start the subheader off with:</b> " . substr($hex, 16, 8) . "<p>";
//We're not guessing, this is what we know.
$substart = substr($hex, 16, 8);
//the very first sub header of the first image found. All other images should be the same subheader, which makes it easy to explode then array the rest.
echo "<b>Number of images actually found in \"{$filename}\" searching with the above subheader:</b> ".substr_count($hex, $substart) . "<p>";
//hopefully
if(hexdec(substr($hex, 8, 2)) == substr_count($hex, $substart)){
echo "<u>Hey! It's a match! That means this .img file was parsed correctly!</u><p>";
//continuing on...
} else {
echo "Script terminated before we cause any damage.";
//Because Softnyx sucks some major penis when it comes to .img files
}
//Going to create a table here so we can do arrays properly
echo "<table width=100%>";
//explode tiem nao plz
$eachimage = explode($substart, $hex);
$count = 0;
foreach($eachimage as $e){
if(strlen($e) == 16){
//forget this one, it's not an image
} else {
$count++;
//Let's get some width/height in hurr
$width = hexdec(substr($e, 2, 2) . substr($e, 0, 2));
$height = hexdec(substr($e, 10, 2) . substr($e, 8, 2));
//I think I got them right.. if not, LOLRESULTS!
echo "<tr><td>Image <b>$count</b><br>
Width <b>{$width}px</b><br>
Height <b>{$height}px</b><br>
(Raw Data below)<p>
<a href='nerv.php?image&w={$width}&h={$height}&data=". substr($e, 72) . "'>View image</a>
<hr noshade>
</td></tr>";
}
}
//and end it, too.
echo "</table>";
}
?>