re-applied changes to app-forensics/libewf

This commit is contained in:
Volker Wegert 2022-11-20 23:09:22 +01:00
parent 99e2331873
commit df0bc033c4
No known key found for this signature in database
GPG key ID: 1BCEC13D2F171EC4
5 changed files with 847 additions and 0 deletions

View file

@ -0,0 +1,2 @@
DIST libewf-experimental-20201210.tar.gz 2585847 BLAKE2B e06d408cc4493bbc5af5e7129c02dabb78e04676179cde44c48aa4449e75e910012f28f7c1575b8b9e0b6db122eb9ac31cff573d26db169a5b579c3be43b99f4 SHA512 5537753648cbe5de4891bb0c0f3baa2a4b74c1cbe637d3e63812b0707f25f6dc2677f44dce43aa4ccde1b55177b358b5c89efad3eaa28af568ba682ee9423d83
DIST libewf-experimental-20201230.tar.gz 2582683 BLAKE2B 3dd866114516674e303527b752dadc12f3979c402ec1bb6125a94d09fe288565ad8f962b4bedc19d135f503e87141a2ba61ad18e34d087dc2b19f577ca9c4b9b SHA512 ccff3f15e3e457eb7f2c8fd6e92f44908ef0725ae60804bb079d3986483a6176d56741e0dcfe4ef1bf69fd0aa573ea6e880766660ea066beeb17c62c8a8a2d8e

View file

@ -0,0 +1,656 @@
#!/usr/bin/env python
#
# Python-bindings handle type test script
#
# Copyright (C) 2006-2022, Joachim Metz <joachim.metz@gmail.com>
#
# Refer to AUTHORS for acknowledgements.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import argparse
import os
import random
import sys
import unittest
import pyewf
class HandleTypeTests(unittest.TestCase):
"""Tests the handle type."""
def test_signal_abort(self):
"""Tests the signal_abort function."""
ewf_handle = pyewf.handle()
ewf_handle.signal_abort()
def test_open(self):
"""Tests the open function."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
# TODO: fix
# with self.assertRaises(IOError):
# ewf_handle.open(filenames)
ewf_handle.close()
with self.assertRaises(TypeError):
ewf_handle.open(None)
def test_open_file_objects(self):
"""Tests the open_file_objects function."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
if not os.path.isfile(test_source):
raise unittest.SkipTest("source not a regular file")
filenames = pyewf.glob(test_source)
file_objects = [open(filename, "rb") for filename in filenames]
ewf_handle = pyewf.handle()
ewf_handle.open_file_objects(file_objects)
# TODO: change IOError into IOError
with self.assertRaises(MemoryError):
ewf_handle.open_file_objects(file_objects)
ewf_handle.close()
with self.assertRaises(TypeError):
ewf_handle.open_file_objects(None)
for file_object in file_objects:
file_object.close()
def test_close(self):
"""Tests the close function."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
ewf_handle = pyewf.handle()
# TODO: fix
# with self.assertRaises(IOError):
# ewf_handle.close()
def test_open_close(self):
"""Tests the open and close functions."""
test_source = unittest.source
if not test_source:
return
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
# Test open and close.
ewf_handle.open(filenames)
ewf_handle.close()
# Test open and close a second time to validate clean up on close.
ewf_handle.open(filenames)
ewf_handle.close()
if os.path.isfile(test_source):
with open(test_source, "rb") as file_object:
# Test open_file_objects and close.
ewf_handle.open_file_objects([file_object])
ewf_handle.close()
# Test open_file_objects and close a second time to validate clean up on close.
ewf_handle.open_file_objects([file_object])
ewf_handle.close()
# Test open_file_objects and close and dereferencing file_object.
ewf_handle.open_file_objects([file_object])
del file_object
ewf_handle.close()
def test_read_buffer(self):
"""Tests the read_buffer function."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
media_size = ewf_handle.get_media_size()
if media_size < 4096:
# Test read without maximum size.
ewf_handle.seek_offset(0, os.SEEK_SET)
data = ewf_handle.read_buffer()
self.assertIsNotNone(data)
self.assertEqual(len(data), media_size)
# Test read with maximum size.
ewf_handle.seek_offset(0, os.SEEK_SET)
data = ewf_handle.read_buffer(size=4096)
self.assertIsNotNone(data)
self.assertEqual(len(data), min(media_size, 4096))
if media_size > 8:
ewf_handle.seek_offset(-8, os.SEEK_END)
# Read buffer on media_size boundary.
data = ewf_handle.read_buffer(size=4096)
self.assertIsNotNone(data)
self.assertEqual(len(data), 8)
# Read buffer beyond media_size boundary.
data = ewf_handle.read_buffer(size=4096)
self.assertIsNotNone(data)
self.assertEqual(len(data), 0)
# Stress test read buffer.
ewf_handle.seek_offset(0, os.SEEK_SET)
remaining_media_size = media_size
for _ in range(1024):
read_size = int(random.random() * 4096)
data = ewf_handle.read_buffer(size=read_size)
self.assertIsNotNone(data)
data_size = len(data)
if read_size > remaining_media_size:
read_size = remaining_media_size
self.assertEqual(data_size, read_size)
remaining_media_size -= data_size
if not remaining_media_size:
ewf_handle.seek_offset(0, os.SEEK_SET)
remaining_media_size = media_size
with self.assertRaises(ValueError):
ewf_handle.read_buffer(size=-1)
ewf_handle.close()
# Test the read without open.
with self.assertRaises(IOError):
ewf_handle.read_buffer(size=4096)
def test_read_buffer_file_object(self):
"""Tests the read_buffer function on a file-like object."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
if not os.path.isfile(test_source):
raise unittest.SkipTest("source not a regular file")
ewf_handle = pyewf.handle()
with open(test_source, "rb") as file_object:
ewf_handle.open_file_objects([file_object])
media_size = ewf_handle.get_media_size()
# Test normal read.
data = ewf_handle.read_buffer(size=4096)
self.assertIsNotNone(data)
self.assertEqual(len(data), min(media_size, 4096))
ewf_handle.close()
def test_read_buffer_at_offset(self):
"""Tests the read_buffer_at_offset function."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
media_size = ewf_handle.get_media_size()
# Test normal read.
data = ewf_handle.read_buffer_at_offset(4096, 0)
self.assertIsNotNone(data)
self.assertEqual(len(data), min(media_size, 4096))
if media_size > 8:
# Read buffer on media_size boundary.
data = ewf_handle.read_buffer_at_offset(4096, media_size - 8)
self.assertIsNotNone(data)
self.assertEqual(len(data), 8)
# Read buffer beyond media_size boundary.
data = ewf_handle.read_buffer_at_offset(4096, media_size + 8)
self.assertIsNotNone(data)
self.assertEqual(len(data), 0)
# Stress test read buffer.
for _ in range(1024):
random_number = random.random()
media_offset = int(random_number * media_size)
read_size = int(random_number * 4096)
data = ewf_handle.read_buffer_at_offset(read_size, media_offset)
self.assertIsNotNone(data)
remaining_media_size = media_size - media_offset
data_size = len(data)
if read_size > remaining_media_size:
read_size = remaining_media_size
self.assertEqual(data_size, read_size)
remaining_media_size -= data_size
if not remaining_media_size:
ewf_handle.seek_offset(0, os.SEEK_SET)
with self.assertRaises(ValueError):
ewf_handle.read_buffer_at_offset(-1, 0)
with self.assertRaises(ValueError):
ewf_handle.read_buffer_at_offset(4096, -1)
ewf_handle.close()
# Test the read without open.
with self.assertRaises(IOError):
ewf_handle.read_buffer_at_offset(4096, 0)
def test_seek_offset(self):
"""Tests the seek_offset function."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
media_size = ewf_handle.get_media_size()
ewf_handle.seek_offset(16, os.SEEK_SET)
offset = ewf_handle.get_offset()
self.assertEqual(offset, 16)
ewf_handle.seek_offset(16, os.SEEK_CUR)
offset = ewf_handle.get_offset()
self.assertEqual(offset, 32)
ewf_handle.seek_offset(-16, os.SEEK_CUR)
offset = ewf_handle.get_offset()
self.assertEqual(offset, 16)
if media_size > 16:
ewf_handle.seek_offset(-16, os.SEEK_END)
offset = ewf_handle.get_offset()
self.assertEqual(offset, media_size - 16)
ewf_handle.seek_offset(16, os.SEEK_END)
offset = ewf_handle.get_offset()
self.assertEqual(offset, media_size + 16)
# TODO: change IOError into ValueError
with self.assertRaises(IOError):
ewf_handle.seek_offset(-1, os.SEEK_SET)
# TODO: change IOError into ValueError
with self.assertRaises(IOError):
ewf_handle.seek_offset(-32 - media_size, os.SEEK_CUR)
# TODO: change IOError into ValueError
with self.assertRaises(IOError):
ewf_handle.seek_offset(-32 - media_size, os.SEEK_END)
# TODO: change IOError into ValueError
with self.assertRaises(IOError):
ewf_handle.seek_offset(0, -1)
ewf_handle.close()
# Test the seek without open.
with self.assertRaises(IOError):
ewf_handle.seek_offset(16, os.SEEK_SET)
def test_seek_offset_file_object(self):
"""Tests the seek_offset function on a file-like object."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
if not os.path.isfile(test_source):
raise unittest.SkipTest("source not a regular file")
ewf_handle = pyewf.handle()
with open(test_source, "rb") as file_object:
ewf_handle.open_file_objects([file_object])
offset = ewf_handle.get_offset()
self.assertEqual(offset, 0)
ewf_handle.seek_offset(16, os.SEEK_SET)
offset = ewf_handle.get_offset()
self.assertEqual(offset, 16)
ewf_handle.close()
def test_get_offset(self):
"""Tests the get_offset function."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
offset = ewf_handle.get_offset()
self.assertIsNotNone(offset)
ewf_handle.close()
def test_get_root_file_entry(self):
"""Tests the get_root_file_entry function and root_file_entry property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
# TODO: check media type and skip if not LEF
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
# root_file_entry = ewf_handle.get_root_file_entry()
# self.assertIsNotNone(root_file_entry)
# self.assertIsNotNone(ewf_handle.root_file_entry)
ewf_handle.close()
def test_get_sectors_per_chunk(self):
"""Tests the get_sectors_per_chunk function and sectors_per_chunk property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
sectors_per_chunk = ewf_handle.get_sectors_per_chunk()
self.assertIsNotNone(sectors_per_chunk)
self.assertIsNotNone(ewf_handle.sectors_per_chunk)
ewf_handle.close()
def test_get_bytes_per_sector(self):
"""Tests the get_bytes_per_sector function and bytes_per_sector property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
bytes_per_sector = ewf_handle.get_bytes_per_sector()
self.assertIsNotNone(bytes_per_sector)
self.assertIsNotNone(ewf_handle.bytes_per_sector)
ewf_handle.close()
def test_get_number_of_sectors(self):
"""Tests the get_number_of_sectors function and number_of_sectors property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
number_of_sectors = ewf_handle.get_number_of_sectors()
self.assertIsNotNone(number_of_sectors)
self.assertIsNotNone(ewf_handle.number_of_sectors)
ewf_handle.close()
def test_get_chunk_size(self):
"""Tests the get_chunk_size function and chunk_size property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
chunk_size = ewf_handle.get_chunk_size()
self.assertIsNotNone(chunk_size)
self.assertIsNotNone(ewf_handle.chunk_size)
ewf_handle.close()
def test_get_error_granularity(self):
"""Tests the get_error_granularity function and error_granularity property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
error_granularity = ewf_handle.get_error_granularity()
self.assertIsNotNone(error_granularity)
self.assertIsNotNone(ewf_handle.error_granularity)
ewf_handle.close()
def test_get_compression_method(self):
"""Tests the get_compression_method function and compression_method property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
compression_method = ewf_handle.get_compression_method()
self.assertIsNotNone(compression_method)
self.assertIsNotNone(ewf_handle.compression_method)
ewf_handle.close()
def test_get_media_size(self):
"""Tests the get_media_size function and media_size property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
media_size = ewf_handle.get_media_size()
self.assertIsNotNone(media_size)
self.assertIsNotNone(ewf_handle.media_size)
ewf_handle.close()
def test_get_media_type(self):
"""Tests the get_media_type function and media_type property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
media_type = ewf_handle.get_media_type()
self.assertIsNotNone(media_type)
self.assertIsNotNone(ewf_handle.media_type)
ewf_handle.close()
def test_get_media_flags(self):
"""Tests the get_media_flags function and media_flags property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
media_flags = ewf_handle.get_media_flags()
self.assertIsNotNone(media_flags)
self.assertIsNotNone(ewf_handle.media_flags)
ewf_handle.close()
def test_get_format(self):
"""Tests the get_format function and format property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
format = ewf_handle.get_format()
self.assertIsNotNone(format)
self.assertIsNotNone(ewf_handle.format)
ewf_handle.close()
def test_get_header_codepage(self):
"""Tests the get_header_codepage function and header_codepage property."""
test_source = unittest.source
if not test_source:
raise unittest.SkipTest("missing source")
filenames = pyewf.glob(test_source)
ewf_handle = pyewf.handle()
ewf_handle.open(filenames)
header_codepage = ewf_handle.get_header_codepage()
self.assertIsNotNone(header_codepage)
self.assertIsNotNone(ewf_handle.header_codepage)
ewf_handle.close()
if __name__ == "__main__":
argument_parser = argparse.ArgumentParser()
argument_parser.add_argument(
"source", nargs="?", action="store", metavar="PATH",
default=None, help="path of the source file.")
options, unknown_options = argument_parser.parse_known_args()
unknown_options.insert(0, sys.argv[0])
setattr(unittest, "source", options.source)
unittest.main(argv=unknown_options, verbosity=2)

View file

@ -0,0 +1,89 @@
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
PYTHON_COMPAT=( python3_{10..11} )
inherit autotools python-single-r1
DESCRIPTION="Libewf is a library to access the Expert Witness Compression Format (EWF)"
HOMEPAGE="https://github.com/libyal/libewf"
SRC_URI="https://github.com/libyal/libewf/releases/download/${PV}/${PN}-experimental-${PV}.tar.gz"
LICENSE="LGPL-3"
SLOT="0"
KEYWORDS="amd64 ~arm64 x86"
IUSE="nls unicode python +fuse +threads debug"
REQUIRED_USE="
python? ( ${PYTHON_REQUIRED_USE} )
"
DEPEND="
nls? (
virtual/libiconv
virtual/libintl
)
python? ( dev-lang/python:* )
app-forensics/libbfio[nls=,unicode=,threads=]
dev-libs/libcaes[nls=,python=]
dev-libs/libcdata[nls=]
dev-libs/libcdatetime[nls=]
dev-libs/libcerror[nls=]
dev-libs/libcfile[nls=,unicode=]
dev-libs/libclocale[nls=,unicode=]
dev-libs/libcnotify[nls=]
dev-libs/libcpath[nls=,unicode=]
dev-libs/libcsplit[nls=,unicode=]
dev-libs/libcthreads[nls=]
dev-libs/libfcache[nls=]
dev-libs/libfdata[nls=,threads=]
dev-libs/libfdatetime[nls=]
dev-libs/libfguid[nls=]
dev-libs/libfvalue[nls=]
dev-libs/libhmac[nls=,unicode=,threads=]
app-forensics/libodraw[nls=,unicode=,threads=]
dev-libs/libsmdev[nls=,unicode=,threads=,python=]
app-forensics/libsmraw[nls=,unicode=,threads=,python=,fuse=]
dev-libs/libuna[nls=,unicode=]
sys-libs/zlib
app-arch/bzip2
sys-apps/util-linux
dev-libs/openssl
"
# sys-apps/util-linux is for libuuid
RDEPEND="
${DEPEND}
python? ( ${PYTHON_DEPS} )
fuse? ( sys-fs/fuse )
"
src_prepare() {
# workaround for missing files in distribution package, see https://github.com/libyal/libewf/issues/174
# should not be required any more in releases after 20201230
cp "${FILESDIR}/2022-11-pyewf_test_handle.py" "${WORKDIR}/${P}/tests/pyewf_test_handle.py"
eautoreconf
eapply_user
}
src_configure() {
econf \
$(use_enable nls) \
$(use_with nls libiconv-prefix) \
$(use_with nls libintl-prefix) \
$(use_enable unicode wide-character-type) \
$(use_enable debug verbose-output ) \
$(use_enable debug debug-output ) \
$(use_enable threads multi-threading-support) \
$(use_enable python) \
$(use_enable python python3) \
$(use_with fuse libfuse) \
}
src_test() {
ewarn "After running test_library.sh, the process will apparently stop running."
ewarn "This is due to a long-running test named test_glob.sh that may take a minute to complete."
default_src_test
}

View file

@ -0,0 +1,89 @@
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
PYTHON_COMPAT=( python3_{10..11} )
inherit autotools python-single-r1
DESCRIPTION="Libewf is a library to access the Expert Witness Compression Format (EWF)"
HOMEPAGE="https://github.com/libyal/libewf"
SRC_URI="https://github.com/libyal/libewf/releases/download/${PV}/${PN}-experimental-${PV}.tar.gz"
LICENSE="LGPL-3"
SLOT="0"
KEYWORDS="amd64 ~arm64 x86"
IUSE="nls unicode python +fuse +threads debug"
REQUIRED_USE="
python? ( ${PYTHON_REQUIRED_USE} )
"
DEPEND="
nls? (
virtual/libiconv
virtual/libintl
)
python? ( dev-lang/python:* )
app-forensics/libbfio[nls=,unicode=,threads=]
dev-libs/libcaes[nls=,python=]
dev-libs/libcdata[nls=]
dev-libs/libcdatetime[nls=]
dev-libs/libcerror[nls=]
dev-libs/libcfile[nls=,unicode=]
dev-libs/libclocale[nls=,unicode=]
dev-libs/libcnotify[nls=]
dev-libs/libcpath[nls=,unicode=]
dev-libs/libcsplit[nls=,unicode=]
dev-libs/libcthreads[nls=]
dev-libs/libfcache[nls=]
dev-libs/libfdata[nls=,threads=]
dev-libs/libfdatetime[nls=]
dev-libs/libfguid[nls=]
dev-libs/libfvalue[nls=]
dev-libs/libhmac[nls=,unicode=,threads=]
app-forensics/libodraw[nls=,unicode=,threads=]
dev-libs/libsmdev[nls=,unicode=,threads=,python=]
app-forensics/libsmraw[nls=,unicode=,threads=,python=,fuse=]
dev-libs/libuna[nls=,unicode=]
sys-libs/zlib
app-arch/bzip2
sys-apps/util-linux
dev-libs/openssl
"
# sys-apps/util-linux is for libuuid
RDEPEND="
${DEPEND}
python? ( ${PYTHON_DEPS} )
fuse? ( sys-fs/fuse )
"
src_prepare() {
# workaround for missing files in distribution package, see https://github.com/libyal/libewf/issues/174
# should not be required any more in releases after 20201230
cp "${FILESDIR}/2022-11-pyewf_test_handle.py" "${WORKDIR}/${P}/tests/pyewf_test_handle.py"
eautoreconf
eapply_user
}
src_configure() {
econf \
$(use_enable nls) \
$(use_with nls libiconv-prefix) \
$(use_with nls libintl-prefix) \
$(use_enable unicode wide-character-type) \
$(use_enable debug verbose-output ) \
$(use_enable debug debug-output ) \
$(use_enable threads multi-threading-support) \
$(use_enable python) \
$(use_enable python python3) \
$(use_with fuse libfuse) \
}
src_test() {
ewarn "After running test_library.sh, the process will apparently stop running."
ewarn "This is due to a long-running test named test_glob.sh that may take a minute to complete."
default_src_test
}

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="person">
<email>unknown@pentoo.ch</email>
<name>Author Unknown</name>
</maintainer>
<use>
<flag name="fuse">Enable FUSE support</flag>
</use>
</pkgmetadata>