appbinary-inspector 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ """Static binary inspection without executing the analyzed file."""
2
+
3
+ from .analyzer import inspect_file
4
+ from .extract import extract_embedded
5
+
6
+ __all__ = ["inspect_file", "extract_embedded"]
7
+ __version__ = "0.1.0"
@@ -0,0 +1,38 @@
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ import math
5
+ import re
6
+ import struct
7
+ from pathlib import Path
8
+
9
+ from .formats import detect_format
10
+
11
+ PRINTABLE = re.compile(rb"[\x20-\x7e]{4,}")
12
+
13
+ def _entropy(data: bytes) -> float:
14
+ if not data:
15
+ return 0.0
16
+ counts = [0] * 256
17
+ for value in data:
18
+ counts[value] += 1
19
+ return -sum((n / len(data)) * math.log2(n / len(data)) for n in counts if n)
20
+
21
+ def _pe_metadata(data: bytes) -> dict:
22
+ if not data.startswith(b"MZ") or len(data) < 0x40:
23
+ return {}
24
+ offset = struct.unpack_from("<I", data, 0x3C)[0]
25
+ if offset + 24 > len(data) or data[offset:offset + 4] != b"PE\0\0":
26
+ return {"valid": False}
27
+ machine, sections, timestamp, _, _, opt_size, characteristics = struct.unpack_from("<HHIIIHH", data, offset + 4)
28
+ machine_names = {0x14C: "x86", 0x8664: "x86-64", 0xAA64: "ARM64"}
29
+ return {"valid": True, "architecture": machine_names.get(machine, hex(machine)), "section_count": sections, "timestamp_utc": timestamp, "optional_header_size": opt_size, "characteristics": hex(characteristics)}
30
+
31
+ def inspect_file(path: str | Path, string_limit: int = 200) -> dict:
32
+ """Return static metadata. The target file is never executed."""
33
+ target = Path(path)
34
+ data = target.read_bytes()
35
+ report = {"path": str(target), "size_bytes": len(data), "format": detect_format(target), "sha256": hashlib.sha256(data).hexdigest(), "sha1": hashlib.sha1(data).hexdigest(), "entropy": round(_entropy(data), 4), "strings": [s.decode("utf-8", "replace") for s in PRINTABLE.findall(data)[:string_limit]]}
36
+ if data.startswith(b"MZ"):
37
+ report["pe"] = _pe_metadata(data)
38
+ return report
@@ -0,0 +1,23 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+
6
+ from .analyzer import inspect_file
7
+ from .extract import extract_embedded
8
+
9
+ def main() -> None:
10
+ parser = argparse.ArgumentParser(description="Static application-binary inspector. Never executes targets.")
11
+ commands = parser.add_subparsers(dest="command", required=True)
12
+ inspect_cmd = commands.add_parser("inspect", help="inspect a binary")
13
+ inspect_cmd.add_argument("file")
14
+ inspect_cmd.add_argument("--strings", type=int, default=200)
15
+ extract_cmd = commands.add_parser("extract", help="extract recognizable embedded files")
16
+ extract_cmd.add_argument("file")
17
+ extract_cmd.add_argument("--output", required=True)
18
+ args = parser.parse_args()
19
+ result = inspect_file(args.file, args.strings) if args.command == "inspect" else extract_embedded(args.file, args.output)
20
+ print(json.dumps(result, indent=2))
21
+
22
+ if __name__ == "__main__":
23
+ main()
@@ -0,0 +1,41 @@
1
+ from __future__ import annotations
2
+
3
+ import io
4
+ import zipfile
5
+ from pathlib import Path
6
+
7
+ from .formats import EMBEDDED_SIGNATURES
8
+
9
+ def extract_embedded(path: str | Path, output_dir: str | Path, min_offset: int = 1) -> list[dict]:
10
+ """Carve recognizable embedded files without executing or decrypting content."""
11
+ source = Path(path)
12
+ destination = Path(output_dir)
13
+ destination.mkdir(parents=True, exist_ok=True)
14
+ data = source.read_bytes()
15
+ found: list[dict] = []
16
+ seen: set[tuple[int, str]] = set()
17
+ for signature, (kind, extension) in EMBEDDED_SIGNATURES.items():
18
+ start = 0
19
+ while True:
20
+ index = data.find(signature, start)
21
+ if index < 0:
22
+ break
23
+ start = index + 1
24
+ if index < min_offset or (index, kind) in seen:
25
+ continue
26
+ seen.add((index, kind))
27
+ stem = f"{source.stem}_offset_{index:08x}"
28
+ if kind == "zip":
29
+ try:
30
+ with zipfile.ZipFile(io.BytesIO(data[index:])) as archive:
31
+ member_dir = destination / stem
32
+ member_dir.mkdir(exist_ok=True)
33
+ archive.extractall(member_dir)
34
+ found.append({"offset": index, "type": kind, "path": str(member_dir), "members": archive.namelist()})
35
+ except (zipfile.BadZipFile, OSError):
36
+ pass
37
+ else:
38
+ carved = destination / f"{stem}{extension}"
39
+ carved.write_bytes(data[index:])
40
+ found.append({"offset": index, "type": kind, "path": str(carved), "note": "carved from signature through EOF"})
41
+ return found
@@ -0,0 +1,30 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ MAGIC = {
6
+ b"MZ": "PE executable (Windows)",
7
+ b"\x7fELF": "ELF executable (Linux/Unix)",
8
+ b"\xcf\xfa\xed\xfe": "Mach-O executable (macOS, 64-bit)",
9
+ b"\xfe\xed\xfa\xcf": "Mach-O executable (macOS, 64-bit, swapped)",
10
+ b"PK\x03\x04": "ZIP archive",
11
+ b"7z\xbc\xaf'\x1c": "7z archive",
12
+ b"Rar!\x1a\x07": "RAR archive",
13
+ }
14
+
15
+ EMBEDDED_SIGNATURES = {
16
+ b"PK\x03\x04": ("zip", ".zip"),
17
+ b"\x1f\x8b\x08": ("gzip", ".gz"),
18
+ b"7z\xbc\xaf'\x1c": ("7z", ".7z"),
19
+ b"MZ": ("pe", ".exe"),
20
+ b"\x7fELF": ("elf", ".elf"),
21
+ b"%PDF-": ("pdf", ".pdf"),
22
+ b"\x89PNG\r\n\x1a\n": ("png", ".png"),
23
+ }
24
+
25
+ def detect_format(path: Path) -> str:
26
+ header = path.read_bytes()[:16]
27
+ for signature, name in MAGIC.items():
28
+ if header.startswith(signature):
29
+ return name
30
+ return "Unknown binary/data"
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.5
2
+ Name: appbinary-inspector
3
+ Version: 0.1.0
4
+ Summary: Safe static inspection and embedded-file extraction for application binaries.
5
+ Author: William Laurento
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+
14
+ # appbinary-inspector
15
+
16
+ Static inspection of application binaries without executing them.
17
+
18
+ ## Features
19
+
20
+ - Detects PE, ELF, Mach-O, ZIP, 7z, and RAR headers
21
+ - Calculates SHA-256 and SHA-1 hashes
22
+ - Extracts readable strings and entropy
23
+ - Reads basic PE header metadata
24
+ - Extracts embedded ZIP archives and carves recognizable binary signatures
25
+
26
+ ## Install
27
+
28
+ ```bash
29
+ pip install appbinary-inspector
30
+ ```
31
+
32
+ ## Use
33
+
34
+ ```bash
35
+ appbin inspect program.exe
36
+ appbin extract program.exe --output extracted
37
+ ```
38
+
39
+ ## Safety
40
+
41
+ Targets are read as bytes only and never executed. The package does not defeat encryption, DRM, licensing controls, passwords, or code protections. It can analyze plaintext and extract recognizable embedded content from files you are authorized to inspect.
@@ -0,0 +1,10 @@
1
+ appbinary_inspector/__init__.py,sha256=tBb2ggN4aP6sJ7hzFYdKxwojYnaLGvapyw4-lWmMTOA,211
2
+ appbinary_inspector/analyzer.py,sha256=LfQ3aLMD9RtXRa7RR0mRrHTR91luMo_QyyUYfPHEF9E,1681
3
+ appbinary_inspector/cli.py,sha256=EGWLTQ2HiY5zS_U3GiszOlvZ-F8qD2ZbSKaW3Q-I6Zg,937
4
+ appbinary_inspector/extract.py,sha256=FofXanoXafsSyWLfBe0avVWN_mHGOLBYrCIeSR9bJww,1702
5
+ appbinary_inspector/formats.py,sha256=E6eGQKfVksZj8tfsqekzoHHNOU1wLQtxEwVz33gufeo,888
6
+ appbinary_inspector-0.1.0.dist-info/METADATA,sha256=g0iVy2JkqDCjbZqHRCOTKlYGiLawgtrKn1UCqx1qP5k,1181
7
+ appbinary_inspector-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
8
+ appbinary_inspector-0.1.0.dist-info/entry_points.txt,sha256=Gi7rR36onA2o47WIFar5XaLOCTuJ037ROkivUrhe_9o,56
9
+ appbinary_inspector-0.1.0.dist-info/licenses/LICENSE,sha256=SWA3EM54riVlLercJr5RthChAiJCBjJgJ8juIo4g5Sw,1072
10
+ appbinary_inspector-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ appbin = appbinary_inspector.cli:main
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 William Laurento
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.