Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions _build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import os
import shlex
import subprocess
import sys

from setuptools import Extension
from setuptools import errors
Expand Down Expand Up @@ -146,7 +145,7 @@ def build_extension(self, extension):
"""Builds the extension."""
sources = extension.sources
if sources is None or not isinstance(sources, (list, tuple)):
raise SetupError(
raise errors.SetupError(
f"in 'ext_modules' option (extension '{extension.name:s}'), 'sources' "
f"must be present and must be a list of source filenames"
)
Expand Down
8 changes: 0 additions & 8 deletions class_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@
"""

import io
import os
import pdb
import re
import sys

Expand Down Expand Up @@ -2397,7 +2395,6 @@ def __init__(
self.class_name, self.name, return_type
)
)
# pdb.set_trace()
self.return_type = PVoid("func_return")

def get_string(self):
Expand Down Expand Up @@ -2929,14 +2926,11 @@ def write_definition(self, out):
"class_name": self.class_name,
"definition_class_name": self.definition_class_name,
}

out.write(
("{{\n" " {class_name:s} result_constructor = NULL;\n").format(
**values_dict
)
)

# pdb.set_trace()
self.write_local_vars(out)

# Assign the initialise_proxies handler
Expand Down Expand Up @@ -4659,12 +4653,10 @@ def write(self, out):
try:
self.module.write(out)
except:
# pdb.post_mortem()
raise

def write_headers(self):
pass
# pdb.set_trace()


if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions tests/cycle_collection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
"""Cyclic-GC regression test for the generated pytsk3 wrappers.

The wrappers participate in cycles via the C-side keepalive fields
Expand Down
88 changes: 52 additions & 36 deletions tests/fs_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,7 @@

import pytsk3

import test_lib


def walk_filesystem(directory, prefix=b"", max_depth=8, _depth=0):
"""Recursive directory walk yielding (path, entry) pairs.

Mirrors samples/fls.py and dfvfs's TSKFileSystem traversal: skip
'.', '..', and the synthetic '$OrphanFiles' node; recurse via
File.as_directory(); cap depth to avoid runaway loops on
pathological inputs (e.g. cyclic symlinks).
"""
if _depth > max_depth:
return
for entry in directory:
if not entry.info or not entry.info.name:
continue
name = entry.info.name.name
if name in (b".", b"..", b"$OrphanFiles"):
continue
yield prefix + b"/" + name, entry
meta = entry.info.meta
if meta is not None and meta.type == pytsk3.TSK_FS_META_TYPE_DIR:
try:
sub = entry.as_directory()
except (IOError, OSError):
continue
yield from walk_filesystem(sub, prefix + b"/" + name, max_depth, _depth + 1)

from tests import test_lib

# fls -l ./test_data/image.raw
# d/d 11: lost+found 2012-05-25 17:55:50 (CEST)
Expand Down Expand Up @@ -76,7 +49,7 @@ def _testOpenMeta(self, fs_info):

self.assertNotEqual(file_object, None)

with self.assertRaises(IOError):
with self.assertRaises(OSError):
file_object = fs_info.open_meta(19)


Expand Down Expand Up @@ -149,16 +122,53 @@ def setUp(self):

def testInitialize(self):
"""Test the initialize functionality."""
with self.assertRaises(IOError):
with self.assertRaises(OSError):
pytsk3.FS_Info(self._img_info, offset=0)


class TSKFsInfoFileObjectTest(TSKFsInfoTestCase):
"""Tests the FS_Info object using an Img_Info file-like object."""

def _WalkFileSystem(self, directory, prefix=b"", max_depth=8, depth=0):
"""Recursive directory walk yielding (path, entry) pairs.

Mirrors samples/fls.py and dfvfs's TSKFileSystem traversal: skip
'.', '..', and the synthetic '$OrphanFiles' node; recurse via
File.as_directory(); cap depth to avoid runaway loops on
pathological inputs (e.g. cyclic symlinks).
"""
if depth <= max_depth:
for entry in directory:
if not entry.info or not entry.info.name:
continue

name = entry.info.name.name
if name in (b".", b"..", b"$OrphanFiles"):
continue

path = prefix + b"/" + name
yield path, entry

meta = entry.info.meta
if meta is not None and meta.type == pytsk3.TSK_FS_META_TYPE_DIR:
try:
sub_directory = entry.as_directory()
except OSError:
continue

path = prefix + b"/" + name
yield from self._WalkFileSystem(
sub_directory,
prefix=path,
max_depth=max_depth,
depth=depth + 1,
)

def setUp(self):
"""Sets up the needed objects used throughout the test."""
test_file = os.path.join("test_data", "image.raw")

# pylint: disable=consider-using-with
self._file_object = open(test_file, "rb")

stat_info = os.stat(test_file)
Expand All @@ -178,21 +188,23 @@ def testOpenMeta(self):
self._testOpenMeta(fs_info)

def testRecursiveWalkMatchesAcrossOpenPaths(self):
"""Walk every file via FileObject-backed image; bytes via inode == bytes via path.
"""Walk every file via a file-like object backed image.

Mirrors the dominant dfvfs pipeline (TSKFileSystemImage subclass
feeding TSKFileSystem). End-to-end exercise of the proxied read
callback, parent keepalive, and the open-by-inode vs open-by-path
paths in one walk.
Tests proxied read callback, parent keepalive, and the open-by-inode versus
open-by-path paths in a single walk.
"""
fs_info = pytsk3.FS_Info(self._img_info, offset=0)
paths = dict(walk_filesystem(fs_info.open_dir("/")))
directory = fs_info.open_dir("/")

paths = dict(self._WalkFileSystem(directory))
self.assertIn(b"/passwords.txt", paths)
self.assertIn(b"/a_directory/a_file", paths)

for path, entry in paths.items():
meta = entry.info.meta
if meta is None or meta.type != pytsk3.TSK_FS_META_TYPE_REG:
continue

by_inode = fs_info.open_meta(meta.addr).read_random(0, meta.size)
by_path = fs_info.open(path.decode("utf-8")).read_random(0, meta.size)
self.assertEqual(by_inode, by_path, msg=path)
Expand All @@ -204,6 +216,8 @@ class TSKFsInfoFileObjectWithDetectTest(TSKFsInfoTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
test_file = os.path.join("test_data", "image.raw")

# pylint: disable=consider-using-with
self._file_object = open(test_file, "rb")

stat_info = os.stat(test_file)
Expand All @@ -229,6 +243,8 @@ class TSKFsInfoFileObjectWithLargeSize(TSKFsInfoTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
test_file = os.path.join("test_data", "image.raw")

# pylint: disable=consider-using-with
self._file_object = open(test_file, "rb")

self._file_size = 1024 * 1024 * 1024 * 1024
Expand Down
11 changes: 9 additions & 2 deletions tests/img_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytsk3

import test_lib
from tests import test_lib


class TSKImgInfoTestCase(unittest.TestCase):
Expand All @@ -28,7 +28,8 @@ def _testGetSize(self, img_info):
"""
self.assertNotEqual(img_info, None)

self.assertEqual(img_info.get_size(), self._file_size)
file_size = getattr(self, "_file_size")
self.assertEqual(img_info.get_size(), file_size)

def _testRead(self, img_info):
"""Test the read functionality.
Expand Down Expand Up @@ -96,6 +97,8 @@ class TSKImgInfoFileObjectTest(TSKImgInfoTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
test_file = os.path.join("test_data", "image.raw")

# pylint: disable=consider-using-with
self._file_object = open(test_file, "rb")

stat_info = os.stat(test_file)
Expand Down Expand Up @@ -127,6 +130,8 @@ class TSKImgInfoFileObjectWithDetectTest(TSKImgInfoTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
test_file = os.path.join("test_data", "image.raw")

# pylint: disable=consider-using-with
self._file_object = open(test_file, "rb")

stat_info = os.stat(test_file)
Expand Down Expand Up @@ -164,6 +169,8 @@ class TSKImgInfoFileObjectLargeSizeTest(TSKImgInfoTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
test_file = os.path.join("test_data", "image.raw")

# pylint: disable=consider-using-with
self._file_object = open(test_file, "rb")
self._file_size = 1024 * 1024 * 1024 * 1024

Expand Down
7 changes: 2 additions & 5 deletions tests/security.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python
#!/usr/bin/env python3
"""Security regression tests for pytsk3."""

import io
import os
import unittest

Expand Down Expand Up @@ -95,7 +94,6 @@ def testOversizedRead(self):
self.assertGreater(
img_info.max_overflow, 0, "subclass never overflowed"
)

names = sorted(
entry.info.name.name
for entry in directory
Expand Down Expand Up @@ -167,10 +165,9 @@ def testEveryStructWrapperRaisesOnUnboundAccess(self):
"""Test the property getter "self->base == NULL" guard."""
classes = [
candidate
for candidate in self._CANDIDATE_ATTRIBUTES.keys()
for candidate in self._CANDIDATE_ATTRIBUTES
if hasattr(pytsk3, candidate)
]

self.assertGreater(len(classes), 0, "no struct wrapper classes found")

guard_hits = 0
Expand Down
7 changes: 5 additions & 2 deletions tests/thread_safety.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
"""Thread-safety and free-threaded Python regression tests for pytsk3.

These exercise patterns that can crash or scramble state when:
Expand Down Expand Up @@ -555,6 +554,8 @@ class GilStaysOffTest(unittest.TestCase):
stays off the entire time.
"""

# pylint: disable=protected-access

@unittest.skipUnless(_is_free_threaded(), "requires a free-threaded Python build")
def testGilStaysOffAcrossOperations(self):
self.assertFalse(sys._is_gil_enabled())
Expand Down Expand Up @@ -860,6 +861,8 @@ class CycleCollectionTest(unittest.TestCase):
any user payload) leaks for the process lifetime.
"""

# pylint: disable=protected-access

def testCycleIsCollected(self):
sentinel_alive = [True]

Expand Down
Loading
Loading