เทคนิคการ Extract ไฟล์ .rpm

โปรแกรมบน CentOS ที่ควรติดตั้งใช้งานร่วมกับ VoIP Server

เทคนิคการ Extract ไฟล์ .rpm

โพสต์โดย nuiz » 12 มิ.ย. 2011 16:08

ผมมีเทคนิคการแตกหรือระเบิดไฟล์ .rpm ออกมา หรือที่เราเรียกว่า RPM Extracting จุดประสงค์ของผมก็คือต้องการไฟล์บางไฟล์ที่อยู่ในไฟล์ .rpm ซึ่งไฟล์นี้จะถูกลบไปถ้าผมติดตั้งด้วยคำสั่ง rpm -ivh หรือ rpm -Uvh ตามปกติ

มาดูวิธีการระเบิดไฟล์ .rpm กันครับ

1. สร้างไฟล์ rpm2cpio

ไฟล์นี้ผมก๊อบมาจากในเน็ตอ่ะครับและผมก็ใช้ชื่อไฟล์เดิม ไม่ได้เปลี่ยน

โค้ด: เลือกทั้งหมด
#!/usr/bin/perl

# Copyright (C) 1997,1998,1999, Roger Espel Llima
# Copyright (C) 2000, Sergey Babkin
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and any associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# SOFTWARE'S COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE

# (whew, that's done!)

# why does the world need another rpm2cpio?  because the existing one
# won't build unless you have half a ton of things that aren't really
# required for it, since it uses the same library used to extract RPM's.
# in particular, it won't build on the HPsUX box i'm on.


# add a path if desired
$gzip = "gzip";

sub printhelp {
  print "rpm2cpio, perl version by orabidoo <odar\@pobox.com>\n";
  print "use: rpm2cpio [file.rpm]\n";
  print "dumps the contents to stdout as a GNU cpio archive\n";
  exit 0;
}

if ($#ARGV == -1) {
  printhelp if -t STDIN;
  $f = "STDIN";
} elsif ($#ARGV == 0) {
  open(F, "< $ARGV[0]") or die "Can't read file $ARGV[0]\n";
  $f = 'F';
} else {
  printhelp;
}

printhelp if -t STDOUT;

# gobble the file up
undef $/;
$|=1;
#$rpm = <$f>;
#close ($f);

read $f, $rpm, 96 ;

($magic, $major, $minor) = unpack("NCC", $rpm);

die "Not an RPM\n" if $magic != 0xedabeedb;
die "Not a version 3 or 4 RPM\n" if $major != 3 && $major != 4;

$filter="";

read $f, $rpm, 16 or die "No header\n" ;
while(1) {
        ($magic, $crap, $sections, $bytes) = unpack("N4", $rpm);
        $smagic = unpack("n", $rpm);
        $format="unknown";
        if ($smagic eq 0x1f8b) {
                $filter="gzip -cd";
                last;
        }
        if (substr($rpm, 0, 3) eq "BZh") {
                $filter="bzip2 -cd";
                last;
        }
        #printf(STDERR "0x%x 0x%x 0x%x 0x%x\n", $magic, $sections, $bytes, $smagic);
        die "Error: header not recognized\n" if $magic != 0x8eade801;
        seek $f, 16*$sections+$bytes, 1 or die "FIle is too small\n"; # skip the headers
        do {
                read $f, $rpm, 1 or die "No header\n" ;
                $c = unpack("C", $rpm);
        } while($c==0);
        read $f, $rpm, 15, 1 or die "No header\n" ;
}

#read $f, $rpm, 20 or die "No gzip header\n"; # the gzip header
#$smagic = unpack("n", $rpm);
#printf(STDERR "0x%x\n", $smagic);
die "Error: bogus RPM\n" if $filter eq "";

open(ZCAT, "| $filter") || die "can't pipe to $filter\n";
#print STDERR "CPIO archive found!\n";

while($rpm ne '') {
        print ZCAT $rpm;
        read $f, $rpm, 10240 ; # read in blocks
}

close ZCAT;


2. ทำให้ไฟล์ rpm2cpio รันได้
โค้ด: เลือกทั้งหมด
chmod 755 rpm2cpio


3. สร้างไดเร็คตอรี่เปล่าๆขึ้นมา
เอาไว้รองรับไฟล์ที่จะถูกแตกออกมา
โค้ด: เลือกทั้งหมด
mkdir /tmp/test


4. ก๊อบไฟล์ rpm2cpio.pl และไฟล์ .rpm ที่ต้องการจะ Extract ไปไว้
ผมต้องการแตกไฟล์ php-5.2.10.i386.rpm
โค้ด: เลือกทั้งหมด
cp rpm2cpio php-5.2.10.i386.rpm /tmp/test


5. รันคำสั่งเพื่อแตกไฟล์
โค้ด: เลือกทั้งหมด
cd /tmp/test
rpm2cpio php-5.2.10.i386.rpm | cpio -idmv


6. ผลลัพท์
ภายในไดเร็คตอรี่ /tmp/test จะมีไฟล์และไดเร็คตอรี่ซึ่งจะเกิดขึ้นมา (เมื่อเราติดตั้งด้วยคำสั่ง rpm -ivh) แล้วผมก็ไปก๊อบเอาไฟล์ที่ต้องการได้เลย

สะดวกจริงๆครับ
** หากมีปัญหากับอุปกรณ์ที่ซื้อมาเองหรือบริการที่ทำขึ้นมาเอง ให้โพสต์ถามในเว็บบอร์ดนี้นะครับ **
** งานเร่งด่วนติดต่อว่าจ้างที่เบอร์ 08-5161-9439 อีเมล์ iamaladin@gmail.com ไลน์ NuizVoip ครับ **
nuiz
Diamond Member
 
โพสต์: 6993
ลงทะเบียนเมื่อ: 24 มี.ค. 2010 09:33

ย้อนกลับไปยัง CentOS - The Community Enterprise Operating System

ผู้ใช้งานขณะนี้

่กำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และ บุคคลทั่วไป 1 ท่าน