Advertisement
Guest User

Untitled

a guest
Feb 20th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.16 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # Copyright (C) 1997,1998,1999, Roger Espel Llima
  4.  
  5. #
  6.  
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8.  
  9. # of this software and any associated documentation files (the "Software"), to
  10.  
  11. # deal in the Software without restriction, including without limitation the
  12.  
  13. # rights to use, copy, modify, merge, publish, distribute, sublicense,
  14.  
  15. # and/or sell copies of the Software, and to permit persons to whom the
  16.  
  17. # Software is furnished to do so, subject to the following conditions:
  18.  
  19. #
  20.  
  21. # The above copyright notice and this permission notice shall be included in
  22.  
  23. # all copies or substantial portions of the Software.
  24.  
  25. #
  26.  
  27. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28.  
  29. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  30.  
  31. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  32.  
  33. # SOFTWARE'S COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  34.  
  35. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  36.  
  37. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  38.  
  39. # THE SOFTWARE
  40.  
  41. # (whew, that's done!)
  42.  
  43. # why does the world need another rpm2cpio? because the existing one
  44.  
  45. # won't build unless you have half a ton of things that aren't really
  46.  
  47. # required for it, since it uses the same library used to extract RPM's.
  48.  
  49. # in particular, it won't build on the HPsUX box i'm on.
  50.  
  51. # sw 2002-Mar-6 Don't slurp the whole file
  52.  
  53. # add a path if desired
  54.  
  55. $gzip = "gzip";
  56.  
  57. sub printhelp {
  58.  
  59. print <
  60. rpm2cpio, perl version by orabidoo +sw
  61.  
  62. dumps the contents to stdout as a cpio archive
  63.  
  64. use: rpm2cpio [file.rpm] > file.cpio
  65.  
  66. Here's how to use cpio:
  67.  
  68. list of contents: cpio -t -i < /file/name
  69.  
  70. extract files: cpio -d -i < /file/name
  71.  
  72. HERE
  73.  
  74. exit 0;
  75.  
  76. }
  77.  
  78. if ($#ARGV == -1) {
  79.  
  80. printhelp if -t STDIN;
  81.  
  82. $f = "STDIN";
  83.  
  84. } elsif ($#ARGV == 0) {
  85.  
  86. open(F, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
  87.  
  88. $f = 'F';
  89.  
  90. } else {
  91.  
  92. printhelp;
  93.  
  94. }
  95.  
  96. printhelp if -t STDOUT;
  97.  
  98. # gobble the file up
  99.  
  100. ##undef $/;
  101.  
  102. ##$|=1;
  103.  
  104. ##$rpm = <$f>;
  105.  
  106. ##close ($f);
  107.  
  108. read $f,$rpm,96;
  109.  
  110. ($magic, $major, $minor, $crap) = unpack("NCC C90", $rpm);
  111.  
  112. die "Not an RPM\n" if $magic != 0xedabeedb;
  113.  
  114. die "Not a version 3 or 4 RPM\n" if $major != 3 && $major != 4;
  115.  
  116. ##$rpm = substr($rpm, 96);
  117.  
  118. while (!eof($f)) {
  119.  
  120. $pos = tell($f);
  121.  
  122. read $f,$rpm,16;
  123.  
  124. $smagic = unpack("n", $rpm);
  125.  
  126. last if $smagic eq 0x1f8b;
  127.  
  128. # Turns out that every header except the start of the gzip one is
  129.  
  130. # padded to an 8 bytes boundary.
  131.  
  132. if ($pos & 0x7) {
  133.  
  134. $pos += 7;
  135.  
  136. $pos &= ~0x7;# Round to 8 byte boundary
  137.  
  138. seek $f, $pos, 0;
  139.  
  140. read $f,$rpm,16;
  141.  
  142. }
  143.  
  144. ($magic, $crap, $sections, $bytes) = unpack("N4", $rpm);
  145.  
  146. die "Error: header not recognized\n" if $magic != 0x8eade801;
  147.  
  148. $pos += 16;# for header
  149.  
  150. $pos += 16 * $sections;
  151.  
  152. $pos += $bytes;
  153.  
  154. seek $f, $pos, 0;
  155.  
  156. }
  157.  
  158. if (eof($f)) {
  159.  
  160. die "bogus RPM\n";
  161.  
  162. }
  163.  
  164. open(ZCAT, "|gzip -cd") || die "can't pipe to gzip\n";
  165.  
  166. print STDERR "CPIO archive found!\n";
  167.  
  168. print ZCAT $rpm;
  169.  
  170. while (read($f, ($_=''), 16384) > 0) {
  171.  
  172. print ZCAT;
  173.  
  174. }
  175.  
  176. close ZCAT;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement