Advertisement
fwreverse

mib binary to text converter

Jan 6th, 2012
1,384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. function makeStringGood($str) {
  3.     return str_replace(array("\r",' '),array('','_'),trim($str));
  4. }
  5. function isOid($str) {
  6.     if($str[0]==='1')
  7.     return true;
  8.     else
  9.     return false;
  10. }
  11. $file = file_get_contents('mibs.bin');
  12. $fileArray = explode(chr(0),$file);
  13. //print_r($fileArray);
  14. $infoArray = array();
  15. $bitArray = array();
  16. foreach($fileArray as $line0) {
  17.     $line = makeStringGood($line0);
  18.     if(strlen($line)>0) {
  19.     //echo "$line\n";
  20.     $infoArray[]=$line;
  21.     $bitArray[]=isOid($line);
  22.     }
  23. }
  24. //print_r($bitArray);
  25. $sections=array();
  26. //$sections2=array();//hashmap
  27. foreach($bitArray as $i => $oidFlag) {
  28.     if($oidFlag) {
  29.     if(isset($bitArray[$i-1])) {
  30.         if($bitArray[$i]===true) {
  31.         if($bitArray[$i-1]===true) {
  32.             $sections[]=$i;
  33.         } else {
  34.             $sections[]=$i-1;
  35.         }
  36.         }
  37.     }
  38.     }
  39. }
  40. //print_r($sections);
  41. $unknownNum=0;
  42. foreach($sections as $i => $startSection) {
  43.     if(isset($sections[$i+1]))
  44.     $endSection = $sections[$i+1];
  45.     else
  46.     $endSection = $startSection;
  47.     for($j = $startSection;$j<$endSection;$j++) {
  48.     //echo $infoArray[$j]."\n";
  49.     if($j===$startSection) {
  50.         if(isOid($infoArray[$j]))
  51.         echo 'unknown'.$unknownNum++.' '.$infoArray[$j];
  52.         else
  53.         echo $infoArray[$j];
  54.     } else {
  55.         echo ' '.$infoArray[$j];
  56.     }
  57.     }
  58.     echo "\n";
  59. }
  60.  
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement