-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1017 from onekey-sec/report_carve_dir
Report carve dir
- Loading branch information
Showing
53 changed files
with
346 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
watch_file flake.nix flake.lock devenv.nix | ||
use nix \ | ||
--option extra-substituters "https://unblob.cachix.org" \ | ||
--option extra-trusted-public-keys "unblob.cachix.org-1:5kWA6DwOg176rSqU8TOTBXWxsDB4LoCMfGfTgL5qCAE=" | ||
# Source further custom features from .env.user if exists | ||
# Also allows users to disable/override features in this file | ||
source_env_if_exists .envrc.user | ||
|
||
if ${UNBLOB_USE_DEVENV:-true}; then | ||
watch_file flake.nix flake.lock devenv.nix | ||
use nix \ | ||
--option extra-substituters "https://unblob.cachix.org" \ | ||
--option extra-trusted-public-keys "unblob.cachix.org-1:5kWA6DwOg176rSqU8TOTBXWxsDB4LoCMfGfTgL5qCAE=" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
tests/integration/** filter=lfs diff=lfs merge=lfs -text | ||
tests/files/** filter=lfs diff=lfs merge=lfs -text |
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/__outputs__/chunks/_c_e/chunks_c/0-160.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/__outputs__/chunks/_c_e/chunks_c/160-375.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/__outputs__/chunks/_c_e/chunks_c/375-512.padding
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...fixes/__outputs__/chunks/_carve_extract/chunks_carve/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...xes/__outputs__/chunks/_carve_extract/chunks_carve/160-375.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/__outputs__/chunks/_carve_extract/chunks_carve/375-512.padding
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
.../suffixes/__outputs__/chunks/defaults/chunks_extract/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...uffixes/__outputs__/chunks/defaults/chunks_extract/160-375.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/__outputs__/chunks/defaults/chunks_extract/375-512.padding
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/__outputs__/collisions.zip/_c_e/collisions.zip_e/chunks
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
.../__outputs__/collisions.zip/_c_e/collisions.zip_e/chunks_c/0-160.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
..._outputs__/collisions.zip/_c_e/collisions.zip_e/chunks_c/160-375.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
.../files/suffixes/__outputs__/collisions.zip/_c_e/collisions.zip_e/chunks_c/375-512.padding
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...s/files/suffixes/__outputs__/collisions.zip/_c_e/collisions.zip_e/chunks_carve/0-160.gzip
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...utputs__/collisions.zip/_c_e/collisions.zip_e/chunks_carve/0-160.gzip_e/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...__/collisions.zip/_c_e/collisions.zip_e/chunks_carve/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/__outputs__/collisions.zip/_carve_extract/collisions.zip_extract/chunks
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
.../__outputs__/collisions.zip/_carve_extract/collisions.zip_extract/chunks_carve/0-160.gzip
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...p/_carve_extract/collisions.zip_extract/chunks_carve/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/files/suffixes/__outputs__/collisions.zip/defaults/collisions.zip_extract/chunks
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...ffixes/__outputs__/collisions.zip/defaults/collisions.zip_extract/chunks_carve/0-160.gzip
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...ons.zip/defaults/collisions.zip_extract/chunks_carve/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...s.zip/defaults/collisions.zip_extract/chunks_extract/0-160.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...zip/defaults/collisions.zip_extract/chunks_extract/160-375.gzip_extract/gzip.uncompressed
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...__outputs__/collisions.zip/defaults/collisions.zip_extract/chunks_extract/375-512.padding
Git LFS file not shown
Git LFS file not shown
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file removed
0
tests/integration/compression/zstd/__output__/lorem.truncated.zstd_extract/.gitkeep
Empty file.
Empty file removed
0
tests/integration/compression/zstd/__output__/truncated.dos.zstd_extract/.gitkeep
Empty file.
Empty file.
Empty file removed
0
tests/integration/executable/elf/elf64/__output__/hellomod.sha1.ko_extract/.gitkeep
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from unblob.processing import ExtractionConfig, process_file | ||
from unblob.report import OutputDirectoryExistsReport | ||
from unblob.testing import check_output_is_the_same | ||
|
||
TEST_DATA_PATH = Path(__file__).parent / "files/suffixes" | ||
|
||
|
||
def _patch(extraction_config: ExtractionConfig, carve_suffix: str, extract_suffix: str): | ||
extraction_config.keep_extracted_chunks = False | ||
extraction_config.carve_suffix = carve_suffix | ||
extraction_config.extract_suffix = extract_suffix | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"carve_suffix,extract_suffix,output_root_dir_name", | ||
[ | ||
("_extract", "_extract", "defaults"), | ||
("_c", "_e", "_c_e"), | ||
("_carve", "_extract", "_carve_extract"), | ||
], | ||
) | ||
def test_top_level_carve( | ||
carve_suffix: str, | ||
extract_suffix: str, | ||
output_root_dir_name: str, | ||
extraction_config: ExtractionConfig, | ||
): | ||
_patch(extraction_config, carve_suffix, extract_suffix) | ||
input_file = TEST_DATA_PATH / "__input__/chunks" | ||
carve_dir_name = input_file.name + extraction_config.carve_suffix | ||
extract_dir_name = input_file.name + extraction_config.extract_suffix | ||
expected_output_dir = TEST_DATA_PATH / "__outputs__/chunks" / output_root_dir_name | ||
|
||
reports = process_file(extraction_config, input_file) | ||
|
||
assert reports.errors == [] | ||
|
||
assert ( | ||
carve_dir_name == extract_dir_name | ||
or not (extraction_config.extract_root / extract_dir_name).exists() | ||
) | ||
check_output_is_the_same(expected_output_dir, extraction_config.extract_root) | ||
|
||
|
||
EXPECTED_COLLISION_PATHS: "dict[tuple[str, str], set]" = { | ||
("_extract", "_extract"): { | ||
"collisions.zip_extract/chunks_carve/0-160.gzip_extract", | ||
}, | ||
("_carve", "_extract"): { | ||
"collisions.zip_extract/chunks_carve", | ||
"collisions.zip_extract/chunks_carve/0-160.gzip_extract", | ||
}, | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"carve_suffix,extract_suffix,output_root_dir_name", | ||
[ | ||
("_extract", "_extract", "defaults"), | ||
("_c", "_e", "_c_e"), | ||
("_carve", "_extract", "_carve_extract"), | ||
], | ||
) | ||
def test_top_level_extract_and_collisions( | ||
carve_suffix: str, | ||
extract_suffix: str, | ||
output_root_dir_name: str, | ||
extraction_config: ExtractionConfig, | ||
): | ||
_patch(extraction_config, carve_suffix, extract_suffix) | ||
input_file = TEST_DATA_PATH / "__input__/collisions.zip" | ||
carve_dir_name = input_file.name + extraction_config.carve_suffix | ||
extract_dir_name = input_file.name + extraction_config.extract_suffix | ||
expected_output_dir = ( | ||
TEST_DATA_PATH / "__outputs__/collisions.zip" / output_root_dir_name | ||
) | ||
|
||
reports = process_file(extraction_config, input_file) | ||
|
||
# check collision problems - the input was prepared to have collisions | ||
# during both the carving and extracting phases | ||
problem_paths = { | ||
e.path.relative_to(extraction_config.extract_root).as_posix() | ||
for e in reports.errors | ||
if isinstance(e, OutputDirectoryExistsReport) | ||
} | ||
key = (carve_suffix, extract_suffix) | ||
assert problem_paths == EXPECTED_COLLISION_PATHS.get(key, set()) | ||
# we expect only OutputDirectoryExistsReport-s | ||
assert len(reports.errors) == len(problem_paths) | ||
|
||
assert ( | ||
carve_dir_name == extract_dir_name | ||
or not (extraction_config.extract_root / carve_dir_name).exists() | ||
) | ||
check_output_is_the_same(expected_output_dir, extraction_config.extract_root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.