Skip to content

Commit fd2fd01

Browse files
vlaciqkaiser
authored andcommitted
refact(deps): introduce unblob-native package for entropy calculation
1 parent 1d8c944 commit fd2fd01

File tree

10 files changed

+14
-72
lines changed

10 files changed

+14
-72
lines changed

flake.nix

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
55
inputs.filter.url = "github:numtide/nix-filter";
6+
inputs.unblob-native = {
7+
url = "github:onekey-sec/unblob-native";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
};
610
inputs.pyperscan = {
711
url = "git+https://github.com/vlaci/pyperscan/?ref=main&submodules=1";
812
inputs.nixpkgs.follows = "nixpkgs";
@@ -12,7 +16,7 @@
1216
inputs.nixpkgs.follows = "nixpkgs";
1317
};
1418

15-
outputs = { self, nixpkgs, filter, pyperscan, sasquatch }:
19+
outputs = { self, nixpkgs, filter, unblob-native, pyperscan, sasquatch }:
1620
let
1721
# System types to support.
1822
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
@@ -33,7 +37,7 @@
3337
filter.overlays.default
3438
sasquatch.overlays.default
3539
(import ./overlay.nix {
36-
inherit pyperscan;
40+
inherit pyperscan unblob-native;
3741
})
3842
];
3943
packages = forAllSystems (system: rec {

nix/python/default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
{ system, python3, pyperscan }:
1+
{ system, python3, pyperscan, unblob-native }:
22

33
let
44
self = python3.override {
55
inherit self;
66
packageOverrides = final: prev: {
77
pyperscan = pyperscan.packages.${system}.default.vectorscan;
8+
unblob-native = unblob-native.packages.${system}.default;
89
treelib = final.callPackage ../treelib { };
910
};
1011
};

nix/unblob/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
, rarfile
2424
, structlog
2525
, ubi_reader
26+
, unblob-native
2627
, treelib
2728
# Runtime dependencies (extractors)
2829
, pkgs
@@ -90,6 +91,7 @@ let
9091
python-magic
9192
structlog
9293
ubi_reader
94+
unblob-native
9395
rarfile
9496
treelib
9597
];

overlay.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ inputs: final: prev:
22

33
{
44
unblob = final.unblobPython.pkgs.callPackage ./nix/unblob { };
5-
unblobPython = prev.callPackage ./nix/python { inherit (inputs) pyperscan; };
5+
unblobPython = prev.callPackage ./nix/python { inherit (inputs) unblob-native pyperscan; };
66
craneLib = inputs.crane.lib.${final.system};
77
}

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ lief = "^0.12.3"
2828
jefferson = "^0.4.2"
2929
cryptography = ">=37.0.1,<40.0"
3030
treelib = "^1.6.1"
31+
unblob-native = "^0.1.0"
3132

3233
[tool.poetry.group.dev]
3334
optional = true

tests/test_bindings.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

unblob/_py/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

unblob/_py/math.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

unblob/math.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

unblob/processing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import magic
99
import plotext as plt
1010
from structlog import get_logger
11+
from unblob_native import math_tools as mt
1112

1213
from unblob.handlers import BUILTIN_HANDLERS, Handlers
1314

@@ -16,7 +17,6 @@
1617
from .finder import search_chunks
1718
from .iter_utils import pairwise
1819
from .logging import noformat
19-
from .math import shannon_entropy
2020
from .models import (
2121
Chunk,
2222
ExtractError,
@@ -524,7 +524,7 @@ def calculate_entropy(path: Path) -> EntropyReport:
524524
entropy_sum = 0.0
525525
with File.from_path(path) as file:
526526
for chunk in iterate_file(file, 0, file_size, buffer_size=block_size):
527-
entropy = shannon_entropy(chunk)
527+
entropy = mt.shannon_entropy(chunk)
528528
entropy_percentage = round(entropy / 8 * 100, 2)
529529
percentages.append(entropy_percentage)
530530
entropy_sum += entropy * len(chunk)

0 commit comments

Comments
 (0)