appbinary-inspector 0.1.0__tar.gz
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.
- appbinary_inspector-0.1.0/.github/workflows/publish.yml +28 -0
- appbinary_inspector-0.1.0/LICENSE +9 -0
- appbinary_inspector-0.1.0/PKG-INFO +41 -0
- appbinary_inspector-0.1.0/README.md +28 -0
- appbinary_inspector-0.1.0/pyproject.toml +20 -0
- appbinary_inspector-0.1.0/src/appbinary_inspector/__init__.py +7 -0
- appbinary_inspector-0.1.0/src/appbinary_inspector/analyzer.py +38 -0
- appbinary_inspector-0.1.0/src/appbinary_inspector/cli.py +23 -0
- appbinary_inspector-0.1.0/src/appbinary_inspector/extract.py +41 -0
- appbinary_inspector-0.1.0/src/appbinary_inspector/formats.py +30 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
release:
|
|
6
|
+
types: [published]
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
id-token: write
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
publish:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
environment:
|
|
16
|
+
name: pypi
|
|
17
|
+
url: https://pypi.org/p/appbinary-inspector
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
- name: Build package
|
|
24
|
+
run: |
|
|
25
|
+
python -m pip install --upgrade pip build
|
|
26
|
+
python -m build
|
|
27
|
+
- name: Publish package
|
|
28
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -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.
|
|
@@ -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,28 @@
|
|
|
1
|
+
# appbinary-inspector
|
|
2
|
+
|
|
3
|
+
Static inspection of application binaries without executing them.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Detects PE, ELF, Mach-O, ZIP, 7z, and RAR headers
|
|
8
|
+
- Calculates SHA-256 and SHA-1 hashes
|
|
9
|
+
- Extracts readable strings and entropy
|
|
10
|
+
- Reads basic PE header metadata
|
|
11
|
+
- Extracts embedded ZIP archives and carves recognizable binary signatures
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install appbinary-inspector
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Use
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
appbin inspect program.exe
|
|
23
|
+
appbin extract program.exe --output extracted
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Safety
|
|
27
|
+
|
|
28
|
+
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,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "appbinary-inspector"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Safe static inspection and embedded-file extraction for application binaries."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [{name = "William Laurento"}]
|
|
13
|
+
classifiers = ["Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent"]
|
|
14
|
+
dependencies = []
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
appbin = "appbinary_inspector.cli:main"
|
|
18
|
+
|
|
19
|
+
[tool.hatch.build.targets.wheel]
|
|
20
|
+
packages = ["src/appbinary_inspector"]
|
|
@@ -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"
|