Commit b7085a2f by devttys0

Added internal cpio extractor

parent 61f12a77
......@@ -9,7 +9,7 @@
# For example '%%squashfs-root%%' will be replaced with 'squashfs-root-0'
# if 'squashfs-root' already exists.
#
# Some extractors are internal and not listed here, such as those for zlib files and raw LZMA/deflate streams.
# Some extractors are internal and not listed here, such as those for zlib, cpio, and raw LZMA/deflate streams.
#################################################################################################################
# Assumes these utilities are installed in $PATH.
......@@ -43,7 +43,6 @@
# These were the extractors used from FMK that still need suitable replacements.
#^jffs2 filesystem:jffs2:/opt/firmware-mod-kit/src/jffs2/unjffs2 '%e'
#^ascii cpio archive:cpio:/opt/firmware-mod-kit/uncpio.sh '%e'
#^bff volume entry:bff:/opt/firmware-mod-kit/src/bff/bffxtractor.py '%e'
#^wdk file system:wdk:/opt/firmware-mod-kit/src/firmware-tools/unwdk.py '%e'
......
import os
import subprocess
import binwalk.core.plugin
class CPIOPlugin(binwalk.core.plugin.Plugin):
'''
Ensures that ASCII CPIO archive entries only get extracted once.
Also provides an internal CPIO extraction wrapper around the Unix
cpio utility since no output directory can be provided to it directly.
'''
# CPIO_OUT_DIR = "cpio-root"
CPIO_OUT_DIR = "cpio-root"
MODULES = ['Signature']
# def init(self):
# if self.module.extractor.enabled:
# self.module.extractor.add_rule(regex="^ascii cpio archive",
# extension="cpio",
# cmd=self.extractor)
def init(self):
if self.module.extractor.enabled:
self.module.extractor.add_rule(regex="^ascii cpio archive",
extension="cpio",
cmd=self.extractor)
# def extractor(self, fname):
# out_dir = os.path.join(os.path.split(fname)[0], self.CPIO_OUT_DIR)
def extractor(self, fname):
fname = os.path.abspath(fname)
out_dir = os.path.join(os.path.dirname(fname), self.CPIO_OUT_DIR)
# try:
# os.mkdir(out_dir)
# except OSError:
# return
try:
fpin = open(fname, "rb")
fperr = open(os.devnull, "rb")
os.mkdir(out_dir)
except OSError:
return
# # Lazy.
# os.system("cd '%s' && cpio -d -i --no-absolute-filenames < '%s' 2>&1 1>/dev/null" % (out_dir, fname))
try:
curdir = os.getcwd()
os.chdir(out_dir)
except OSError:
return
try:
subprocess.call(['cpio', '-d', '-i', '--no-absolute-filenames'],
stdin=fpin,
stderr=fperr,
stdout=fperr)
except OSError:
pass
os.chdir(curdir)
fpin.close()
fperr.close()
def pre_scan(self):
# Be sure to re-set this at the beginning of every scan
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment