speedreeder

perl mbr1

May 18th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.38 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. #Lab 5: Master Boot Record
  4. #by Alex Reeder
  5. #
  6. #
  7.  
  8. use File::Basename;
  9. use Term::Menu;
  10. use Term::Prompt;
  11.  
  12. my $fileFull;
  13. my $fileName;
  14.  
  15.  
  16. #pull MBR.bin file from argument
  17. if (-e $ARGV[0]) {
  18.     $fileFull = $ARGV[0];
  19.     $fileName = basename($fileFull);
  20.     if ($fileName eq "MBR.bin") {
  21.         print "MBR.bin read succesfully.\n"
  22.     }
  23.     else {
  24.         die "Improper file.\n";
  25.     }
  26. }
  27. else {
  28.     die "File not found.\n";
  29. }
  30.  
  31. #open the MBR.bin file
  32. open(MBR, $fileFull);
  33. binmode MBR;
  34. my @MBR = <MBR>;
  35.  
  36.  
  37. my ($data, $n, $offset);
  38. while (($n = read MBR, $data, 4, $offset) != 0) {
  39. #  print "$n bytes read\n";
  40.   $offset += $n;
  41. }
  42. close(MBR);
  43. foreach $n (@MBR){
  44.     print $n;
  45.     print "\n";
  46. }
  47. #&mainMenu;
  48.  
  49. sub mainMenu {
  50.     my $prompt = new Term::Menu (
  51.             tries   => 1000,
  52.             aftertext => "Please enter the number corresponding to the answer you want to choose: ",
  53.         );
  54.         my $answer = $prompt->menu(
  55.             1   => ["Disk signature", '1'],
  56.             2   => ["Partition Table Entry", '2'],
  57.             3   => ["MBR signature", '3'],
  58.             4   => ["Exit", '4'],
  59.         );
  60.     if ($answer == 1) {
  61.         &diskSig;
  62.     }
  63.     elsif ($answer == 2){
  64.         &partTable;
  65.     }
  66.     elsif ($answer == 3){
  67.         &MBRSig;
  68.     }
  69.     elsif ($answer == 4){
  70.         print ("\nExiting...\n");
  71.         exit;
  72.     }  
  73. }
  74.  
  75. sub diskSig {
  76.     print "in DS!\n";
  77.     &mainMenu;
  78. }
  79.  
  80. sub partTable {
  81.     print "in part!\n";
  82.     &mainMenu;
  83. }
  84.  
  85. sub MBRSig {
  86.     print "in MBR!\n";
  87.     &mainMenu;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment