Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

swapdevids.pl 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/perl -w
  2. #
  3. # Program to reverse the device identifier IDs in the PCIR and PnP
  4. # structures in a ROM for old non-compliant BIOSes
  5. #
  6. # GPL, Ken Yap 2001
  7. #
  8. use bytes;
  9. use IO::Seekable;
  10. sub swaplocs ($$$)
  11. {
  12. my ($dataref, $loc1, $loc2) = @_;
  13. my ($t);
  14. $t = substr($$dataref, $loc1, 1);
  15. substr($$dataref, $loc1, 1) = substr($$dataref, $loc2, 1);
  16. substr($$dataref, $loc2, 1) = $t;
  17. }
  18. sub printdevids ($$)
  19. {
  20. my ($dataref, $loc) = @_;
  21. return (sprintf "%02x %02x %02x", unpack('C3', substr($$dataref, $loc, 3)));
  22. }
  23. $#ARGV >= 0 or die "Usage: $0 romimage\n";
  24. $file = $ARGV[0];
  25. open(F, "+<$file") or die "$file: $!\n";
  26. binmode(F);
  27. # Handle up to 64kB ROM images
  28. $len = read(F, $data, 64*1024);
  29. defined($len) or die "$file: $!\n";
  30. substr($data, 0, 2) eq "\x55\xAA" or die "$file: Not a boot ROM image\n";
  31. ($pci, $pnp) = unpack('v2', substr($data, 0x18, 4));
  32. ($pci < $len and $pnp < $len) or die "$file: Not a PCI PnP ROM image\n";
  33. (substr($data, $pci, 4) eq 'PCIR' and substr($data, $pnp, 4) eq '$PnP')
  34. or die "$file: No PCI and PNP structures, not a PCI PNP ROM image\n";
  35. &swaplocs(\$data, $pci+13, $pci+15);
  36. &swaplocs(\$data, $pnp+18, $pnp+20);
  37. seek(F, 0, SEEK_SET) or die "$file: Cannot seek to beginning\n";
  38. print F $data;
  39. close(F);
  40. print "PCI devids now: ", &printdevids(\$data, $pci+13), "\n";
  41. print "PnP devids now: ", &printdevids(\$data, $pnp+18), "\n";
  42. exit(0);