datafactor-reverse-engineering 0.4.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.
- datafactor_reverse_engineering-0.4.0/LICENSE +21 -0
- datafactor_reverse_engineering-0.4.0/PKG-INFO +161 -0
- datafactor_reverse_engineering-0.4.0/README.md +147 -0
- datafactor_reverse_engineering-0.4.0/datafactor_reverse_engineering.egg-info/PKG-INFO +161 -0
- datafactor_reverse_engineering-0.4.0/datafactor_reverse_engineering.egg-info/SOURCES.txt +25 -0
- datafactor_reverse_engineering-0.4.0/datafactor_reverse_engineering.egg-info/dependency_links.txt +1 -0
- datafactor_reverse_engineering-0.4.0/datafactor_reverse_engineering.egg-info/entry_points.txt +2 -0
- datafactor_reverse_engineering-0.4.0/datafactor_reverse_engineering.egg-info/top_level.txt +1 -0
- datafactor_reverse_engineering-0.4.0/pyproject.toml +36 -0
- datafactor_reverse_engineering-0.4.0/setup.cfg +4 -0
- datafactor_reverse_engineering-0.4.0/src/__init__.py +1 -0
- datafactor_reverse_engineering-0.4.0/src/analyzer.py +103 -0
- datafactor_reverse_engineering-0.4.0/src/exceptions.py +3 -0
- datafactor_reverse_engineering-0.4.0/src/logging_config.py +56 -0
- datafactor_reverse_engineering-0.4.0/src/report.py +39 -0
- datafactor_reverse_engineering-0.4.0/tests/test_analyze_file.py +114 -0
- datafactor_reverse_engineering-0.4.0/tests/test_cli_exit_codes.py +62 -0
- datafactor_reverse_engineering-0.4.0/tests/test_cli_json.py +56 -0
- datafactor_reverse_engineering-0.4.0/tests/test_cli_json_errors.py +52 -0
- datafactor_reverse_engineering-0.4.0/tests/test_edge_cases.py +58 -0
- datafactor_reverse_engineering-0.4.0/tests/test_logging.py +70 -0
- datafactor_reverse_engineering-0.4.0/tests/test_logging_config.py +128 -0
- datafactor_reverse_engineering-0.4.0/tests/test_report.py +45 -0
- datafactor_reverse_engineering-0.4.0/tests/test_report_errors.py +52 -0
- datafactor_reverse_engineering-0.4.0/tests/test_report_json.py +40 -0
- datafactor_reverse_engineering-0.4.0/tests/test_unexpected_error_message.py +39 -0
- datafactor_reverse_engineering-0.4.0/tests/test_unexpected_errors.py +14 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DataFactor contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datafactor-reverse-engineering
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Python CLI and library for basic file inspection: SHA-256 hash, file size, and header bytes.
|
|
5
|
+
Author: Zainal Nuzuli
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Nuzuli/reverse-engineering-
|
|
8
|
+
Project-URL: Repository, https://github.com/Nuzuli/reverse-engineering-
|
|
9
|
+
Keywords: reverse-engineering,file-analysis,sha256,cli,forensics
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# DataFactor — Reverse Engineering 🛡️
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+

|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
A learning project focused on basic file inspection, reverse engineering methodology, and reproducible analysis documentation.
|
|
26
|
+
|
|
27
|
+
## Project Type
|
|
28
|
+
|
|
29
|
+
This is a standard library only command-line tool for file inspection, not infrastructure code.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- Calculate a file's SHA-256 hash.
|
|
34
|
+
- Report file size and filename.
|
|
35
|
+
- Display the first 16 bytes of a file as hexadecimal.
|
|
36
|
+
- Plain text or JSON output.
|
|
37
|
+
- Provide a reusable analysis report template.
|
|
38
|
+
- Automated tests, linting, type checking, and a dependency audit in GitHub Actions.
|
|
39
|
+
|
|
40
|
+
## Project Structure
|
|
41
|
+
|
|
42
|
+
- `src/analyzer.py`: file analysis and the command-line entry point
|
|
43
|
+
- `src/report.py`: text and JSON report formatting
|
|
44
|
+
- `tests/`: unit tests
|
|
45
|
+
- `docs/TEMPLATE_ANALYSIS.md`: analysis report template
|
|
46
|
+
- `.github/workflows/`: CI and the manual lockfile workflow
|
|
47
|
+
- `requirements.txt` and `requirements-lock.txt`: test tools and their pinned lockfile
|
|
48
|
+
- `CHANGELOG.md`, `CONTRIBUTING.md`, `LICENSE`
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
Install from PyPI (Python 3.10 or newer):
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
pip install reverse-engineering
|
|
56
|
+
reverse-engineering path/to/sample.bin
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or work from a fresh clone: The analyzer itself has no dependencies; the tools below are only for testing.
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
git clone https://github.com/Nuzuli/reverse-engineering-.git
|
|
63
|
+
cd reverse-engineering-
|
|
64
|
+
python -m venv .venv
|
|
65
|
+
source .venv/bin/activate
|
|
66
|
+
pip install -r requirements-lock.txt.
|
|
67
|
+
python -m pytest tests/ -v
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
On Windows, activate the environment with `.venv\Scripts\activate`.
|
|
71
|
+
|
|
72
|
+
For an exact, reproducible toolchain, install from the lockfile instead: `pip install -r requirements-lock.txt`. After changing `requirements.txt`, regenerate it by running the manual "Update lockfile" workflow in the Actions tab.
|
|
73
|
+
|
|
74
|
+
## Reproducible installs
|
|
75
|
+
|
|
76
|
+
`requirements-lock.txt` is committed to the repository and checked by CI, so every install uses the same pinned versions:
|
|
77
|
+
|
|
78
|
+
pip install -r requirements-lock.txt
|
|
79
|
+
python -m pytest tests/ -v
|
|
80
|
+
|
|
81
|
+
The runtime has no third-party dependencies; `requirements.txt` only lists the development toolchain (pytest, pytest-cov, ruff, mypy). After changing it, regenerate the lockfile by running the "Update lockfile" workflow in the Actions tab. CI fails if the two files disagree.
|
|
82
|
+
|
|
83
|
+
## Usage
|
|
84
|
+
|
|
85
|
+
Run from the repository root:
|
|
86
|
+
|
|
87
|
+
`python -m src.analyzer path/to/sample.bin`
|
|
88
|
+
|
|
89
|
+
Example output:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
=== File Analysis Report ===
|
|
93
|
+
File name : sample.bin
|
|
94
|
+
Size : 5 bytes
|
|
95
|
+
SHA-256 : 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
|
|
96
|
+
Header : 68 65 6c 6c 6f
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
An empty file is reported as `(empty file)`.
|
|
100
|
+
|
|
101
|
+
Add `--json` to print the result as JSON instead: `python -m src.analyzer path/to/sample.bin --json`
|
|
102
|
+
|
|
103
|
+
As a Python module:
|
|
104
|
+
|
|
105
|
+
`from src.analyzer import analyze_file`
|
|
106
|
+
|
|
107
|
+
`analyze_file("path/to/sample.bin")` returns a dictionary with the keys `name`, `size_bytes`, `sha256`, and `header_hex`. Use `src.report.format_report` or `src.report.format_json` to render it.
|
|
108
|
+
|
|
109
|
+
## Logging
|
|
110
|
+
|
|
111
|
+
Logging is off by default. Set `LOG_LEVEL` to print one JSON object per log record to stderr:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
LOG_LEVEL=INFO python -m src.analyzer path/to/sample.bin
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Each line has `timestamp`, `level`, `logger`, and `message`. Unknown level names fall back to `WARNING`.
|
|
118
|
+
|
|
119
|
+
## Error Handling
|
|
120
|
+
|
|
121
|
+
`analyze_file` raises `AnalysisError` when the path does not exist (including broken symlinks), is not a regular file (for example a directory), or cannot be read.
|
|
122
|
+
|
|
123
|
+
Command-line exit codes:
|
|
124
|
+
|
|
125
|
+
- `0`: analysis succeeded
|
|
126
|
+
- `2`: analysis failed, with the error message printed to stderr
|
|
127
|
+
|
|
128
|
+
## Logging
|
|
129
|
+
|
|
130
|
+
The analyzer uses the standard `logging` module under the logger name `src.analyzer`. Enable it in your own code, for example with `logging.basicConfig(level=logging.INFO)`.
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
Run the checks locally:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
ruff check src tests
|
|
138
|
+
mypy src
|
|
139
|
+
python -m pytest tests/ -v --cov=src --cov-fail-under=80
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The same checks run on every push through GitHub Actions.
|
|
143
|
+
|
|
144
|
+
## Analysis Workflow
|
|
145
|
+
|
|
146
|
+
1. Record sample information using `docs/TEMPLATE_ANALYSIS.md`.
|
|
147
|
+
2. Inspect basic file properties using the analyzer.
|
|
148
|
+
3. Perform further static or dynamic analysis only in an appropriate, isolated environment.
|
|
149
|
+
4. Document observations, evidence, limitations, and conclusions.
|
|
150
|
+
|
|
151
|
+
## Safety and Legal Notice
|
|
152
|
+
|
|
153
|
+
Analyze only files you are authorized to examine. Do not execute untrusted samples on your primary device. Use an isolated environment for dynamic analysis and follow applicable laws and policies.
|
|
154
|
+
|
|
155
|
+
## Project Status
|
|
156
|
+
|
|
157
|
+
This project currently provides basic file metadata inspection and a starting point for structured reverse engineering documentation. It does not yet perform binary disassembly or decompilation.
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
MIT License. See `LICENSE`.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# DataFactor — Reverse Engineering 🛡️
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
A learning project focused on basic file inspection, reverse engineering methodology, and reproducible analysis documentation.
|
|
12
|
+
|
|
13
|
+
## Project Type
|
|
14
|
+
|
|
15
|
+
This is a standard library only command-line tool for file inspection, not infrastructure code.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- Calculate a file's SHA-256 hash.
|
|
20
|
+
- Report file size and filename.
|
|
21
|
+
- Display the first 16 bytes of a file as hexadecimal.
|
|
22
|
+
- Plain text or JSON output.
|
|
23
|
+
- Provide a reusable analysis report template.
|
|
24
|
+
- Automated tests, linting, type checking, and a dependency audit in GitHub Actions.
|
|
25
|
+
|
|
26
|
+
## Project Structure
|
|
27
|
+
|
|
28
|
+
- `src/analyzer.py`: file analysis and the command-line entry point
|
|
29
|
+
- `src/report.py`: text and JSON report formatting
|
|
30
|
+
- `tests/`: unit tests
|
|
31
|
+
- `docs/TEMPLATE_ANALYSIS.md`: analysis report template
|
|
32
|
+
- `.github/workflows/`: CI and the manual lockfile workflow
|
|
33
|
+
- `requirements.txt` and `requirements-lock.txt`: test tools and their pinned lockfile
|
|
34
|
+
- `CHANGELOG.md`, `CONTRIBUTING.md`, `LICENSE`
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
Install from PyPI (Python 3.10 or newer):
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
pip install reverse-engineering
|
|
42
|
+
reverse-engineering path/to/sample.bin
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Or work from a fresh clone: The analyzer itself has no dependencies; the tools below are only for testing.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
git clone https://github.com/Nuzuli/reverse-engineering-.git
|
|
49
|
+
cd reverse-engineering-
|
|
50
|
+
python -m venv .venv
|
|
51
|
+
source .venv/bin/activate
|
|
52
|
+
pip install -r requirements-lock.txt.
|
|
53
|
+
python -m pytest tests/ -v
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
On Windows, activate the environment with `.venv\Scripts\activate`.
|
|
57
|
+
|
|
58
|
+
For an exact, reproducible toolchain, install from the lockfile instead: `pip install -r requirements-lock.txt`. After changing `requirements.txt`, regenerate it by running the manual "Update lockfile" workflow in the Actions tab.
|
|
59
|
+
|
|
60
|
+
## Reproducible installs
|
|
61
|
+
|
|
62
|
+
`requirements-lock.txt` is committed to the repository and checked by CI, so every install uses the same pinned versions:
|
|
63
|
+
|
|
64
|
+
pip install -r requirements-lock.txt
|
|
65
|
+
python -m pytest tests/ -v
|
|
66
|
+
|
|
67
|
+
The runtime has no third-party dependencies; `requirements.txt` only lists the development toolchain (pytest, pytest-cov, ruff, mypy). After changing it, regenerate the lockfile by running the "Update lockfile" workflow in the Actions tab. CI fails if the two files disagree.
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
Run from the repository root:
|
|
72
|
+
|
|
73
|
+
`python -m src.analyzer path/to/sample.bin`
|
|
74
|
+
|
|
75
|
+
Example output:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
=== File Analysis Report ===
|
|
79
|
+
File name : sample.bin
|
|
80
|
+
Size : 5 bytes
|
|
81
|
+
SHA-256 : 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
|
|
82
|
+
Header : 68 65 6c 6c 6f
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
An empty file is reported as `(empty file)`.
|
|
86
|
+
|
|
87
|
+
Add `--json` to print the result as JSON instead: `python -m src.analyzer path/to/sample.bin --json`
|
|
88
|
+
|
|
89
|
+
As a Python module:
|
|
90
|
+
|
|
91
|
+
`from src.analyzer import analyze_file`
|
|
92
|
+
|
|
93
|
+
`analyze_file("path/to/sample.bin")` returns a dictionary with the keys `name`, `size_bytes`, `sha256`, and `header_hex`. Use `src.report.format_report` or `src.report.format_json` to render it.
|
|
94
|
+
|
|
95
|
+
## Logging
|
|
96
|
+
|
|
97
|
+
Logging is off by default. Set `LOG_LEVEL` to print one JSON object per log record to stderr:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
LOG_LEVEL=INFO python -m src.analyzer path/to/sample.bin
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Each line has `timestamp`, `level`, `logger`, and `message`. Unknown level names fall back to `WARNING`.
|
|
104
|
+
|
|
105
|
+
## Error Handling
|
|
106
|
+
|
|
107
|
+
`analyze_file` raises `AnalysisError` when the path does not exist (including broken symlinks), is not a regular file (for example a directory), or cannot be read.
|
|
108
|
+
|
|
109
|
+
Command-line exit codes:
|
|
110
|
+
|
|
111
|
+
- `0`: analysis succeeded
|
|
112
|
+
- `2`: analysis failed, with the error message printed to stderr
|
|
113
|
+
|
|
114
|
+
## Logging
|
|
115
|
+
|
|
116
|
+
The analyzer uses the standard `logging` module under the logger name `src.analyzer`. Enable it in your own code, for example with `logging.basicConfig(level=logging.INFO)`.
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
Run the checks locally:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
ruff check src tests
|
|
124
|
+
mypy src
|
|
125
|
+
python -m pytest tests/ -v --cov=src --cov-fail-under=80
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The same checks run on every push through GitHub Actions.
|
|
129
|
+
|
|
130
|
+
## Analysis Workflow
|
|
131
|
+
|
|
132
|
+
1. Record sample information using `docs/TEMPLATE_ANALYSIS.md`.
|
|
133
|
+
2. Inspect basic file properties using the analyzer.
|
|
134
|
+
3. Perform further static or dynamic analysis only in an appropriate, isolated environment.
|
|
135
|
+
4. Document observations, evidence, limitations, and conclusions.
|
|
136
|
+
|
|
137
|
+
## Safety and Legal Notice
|
|
138
|
+
|
|
139
|
+
Analyze only files you are authorized to examine. Do not execute untrusted samples on your primary device. Use an isolated environment for dynamic analysis and follow applicable laws and policies.
|
|
140
|
+
|
|
141
|
+
## Project Status
|
|
142
|
+
|
|
143
|
+
This project currently provides basic file metadata inspection and a starting point for structured reverse engineering documentation. It does not yet perform binary disassembly or decompilation.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT License. See `LICENSE`.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datafactor-reverse-engineering
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Python CLI and library for basic file inspection: SHA-256 hash, file size, and header bytes.
|
|
5
|
+
Author: Zainal Nuzuli
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Nuzuli/reverse-engineering-
|
|
8
|
+
Project-URL: Repository, https://github.com/Nuzuli/reverse-engineering-
|
|
9
|
+
Keywords: reverse-engineering,file-analysis,sha256,cli,forensics
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# DataFactor — Reverse Engineering 🛡️
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+

|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
A learning project focused on basic file inspection, reverse engineering methodology, and reproducible analysis documentation.
|
|
26
|
+
|
|
27
|
+
## Project Type
|
|
28
|
+
|
|
29
|
+
This is a standard library only command-line tool for file inspection, not infrastructure code.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- Calculate a file's SHA-256 hash.
|
|
34
|
+
- Report file size and filename.
|
|
35
|
+
- Display the first 16 bytes of a file as hexadecimal.
|
|
36
|
+
- Plain text or JSON output.
|
|
37
|
+
- Provide a reusable analysis report template.
|
|
38
|
+
- Automated tests, linting, type checking, and a dependency audit in GitHub Actions.
|
|
39
|
+
|
|
40
|
+
## Project Structure
|
|
41
|
+
|
|
42
|
+
- `src/analyzer.py`: file analysis and the command-line entry point
|
|
43
|
+
- `src/report.py`: text and JSON report formatting
|
|
44
|
+
- `tests/`: unit tests
|
|
45
|
+
- `docs/TEMPLATE_ANALYSIS.md`: analysis report template
|
|
46
|
+
- `.github/workflows/`: CI and the manual lockfile workflow
|
|
47
|
+
- `requirements.txt` and `requirements-lock.txt`: test tools and their pinned lockfile
|
|
48
|
+
- `CHANGELOG.md`, `CONTRIBUTING.md`, `LICENSE`
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
Install from PyPI (Python 3.10 or newer):
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
pip install reverse-engineering
|
|
56
|
+
reverse-engineering path/to/sample.bin
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or work from a fresh clone: The analyzer itself has no dependencies; the tools below are only for testing.
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
git clone https://github.com/Nuzuli/reverse-engineering-.git
|
|
63
|
+
cd reverse-engineering-
|
|
64
|
+
python -m venv .venv
|
|
65
|
+
source .venv/bin/activate
|
|
66
|
+
pip install -r requirements-lock.txt.
|
|
67
|
+
python -m pytest tests/ -v
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
On Windows, activate the environment with `.venv\Scripts\activate`.
|
|
71
|
+
|
|
72
|
+
For an exact, reproducible toolchain, install from the lockfile instead: `pip install -r requirements-lock.txt`. After changing `requirements.txt`, regenerate it by running the manual "Update lockfile" workflow in the Actions tab.
|
|
73
|
+
|
|
74
|
+
## Reproducible installs
|
|
75
|
+
|
|
76
|
+
`requirements-lock.txt` is committed to the repository and checked by CI, so every install uses the same pinned versions:
|
|
77
|
+
|
|
78
|
+
pip install -r requirements-lock.txt
|
|
79
|
+
python -m pytest tests/ -v
|
|
80
|
+
|
|
81
|
+
The runtime has no third-party dependencies; `requirements.txt` only lists the development toolchain (pytest, pytest-cov, ruff, mypy). After changing it, regenerate the lockfile by running the "Update lockfile" workflow in the Actions tab. CI fails if the two files disagree.
|
|
82
|
+
|
|
83
|
+
## Usage
|
|
84
|
+
|
|
85
|
+
Run from the repository root:
|
|
86
|
+
|
|
87
|
+
`python -m src.analyzer path/to/sample.bin`
|
|
88
|
+
|
|
89
|
+
Example output:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
=== File Analysis Report ===
|
|
93
|
+
File name : sample.bin
|
|
94
|
+
Size : 5 bytes
|
|
95
|
+
SHA-256 : 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
|
|
96
|
+
Header : 68 65 6c 6c 6f
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
An empty file is reported as `(empty file)`.
|
|
100
|
+
|
|
101
|
+
Add `--json` to print the result as JSON instead: `python -m src.analyzer path/to/sample.bin --json`
|
|
102
|
+
|
|
103
|
+
As a Python module:
|
|
104
|
+
|
|
105
|
+
`from src.analyzer import analyze_file`
|
|
106
|
+
|
|
107
|
+
`analyze_file("path/to/sample.bin")` returns a dictionary with the keys `name`, `size_bytes`, `sha256`, and `header_hex`. Use `src.report.format_report` or `src.report.format_json` to render it.
|
|
108
|
+
|
|
109
|
+
## Logging
|
|
110
|
+
|
|
111
|
+
Logging is off by default. Set `LOG_LEVEL` to print one JSON object per log record to stderr:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
LOG_LEVEL=INFO python -m src.analyzer path/to/sample.bin
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Each line has `timestamp`, `level`, `logger`, and `message`. Unknown level names fall back to `WARNING`.
|
|
118
|
+
|
|
119
|
+
## Error Handling
|
|
120
|
+
|
|
121
|
+
`analyze_file` raises `AnalysisError` when the path does not exist (including broken symlinks), is not a regular file (for example a directory), or cannot be read.
|
|
122
|
+
|
|
123
|
+
Command-line exit codes:
|
|
124
|
+
|
|
125
|
+
- `0`: analysis succeeded
|
|
126
|
+
- `2`: analysis failed, with the error message printed to stderr
|
|
127
|
+
|
|
128
|
+
## Logging
|
|
129
|
+
|
|
130
|
+
The analyzer uses the standard `logging` module under the logger name `src.analyzer`. Enable it in your own code, for example with `logging.basicConfig(level=logging.INFO)`.
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
Run the checks locally:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
ruff check src tests
|
|
138
|
+
mypy src
|
|
139
|
+
python -m pytest tests/ -v --cov=src --cov-fail-under=80
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The same checks run on every push through GitHub Actions.
|
|
143
|
+
|
|
144
|
+
## Analysis Workflow
|
|
145
|
+
|
|
146
|
+
1. Record sample information using `docs/TEMPLATE_ANALYSIS.md`.
|
|
147
|
+
2. Inspect basic file properties using the analyzer.
|
|
148
|
+
3. Perform further static or dynamic analysis only in an appropriate, isolated environment.
|
|
149
|
+
4. Document observations, evidence, limitations, and conclusions.
|
|
150
|
+
|
|
151
|
+
## Safety and Legal Notice
|
|
152
|
+
|
|
153
|
+
Analyze only files you are authorized to examine. Do not execute untrusted samples on your primary device. Use an isolated environment for dynamic analysis and follow applicable laws and policies.
|
|
154
|
+
|
|
155
|
+
## Project Status
|
|
156
|
+
|
|
157
|
+
This project currently provides basic file metadata inspection and a starting point for structured reverse engineering documentation. It does not yet perform binary disassembly or decompilation.
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
MIT License. See `LICENSE`.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
datafactor_reverse_engineering.egg-info/PKG-INFO
|
|
5
|
+
datafactor_reverse_engineering.egg-info/SOURCES.txt
|
|
6
|
+
datafactor_reverse_engineering.egg-info/dependency_links.txt
|
|
7
|
+
datafactor_reverse_engineering.egg-info/entry_points.txt
|
|
8
|
+
datafactor_reverse_engineering.egg-info/top_level.txt
|
|
9
|
+
src/__init__.py
|
|
10
|
+
src/analyzer.py
|
|
11
|
+
src/exceptions.py
|
|
12
|
+
src/logging_config.py
|
|
13
|
+
src/report.py
|
|
14
|
+
tests/test_analyze_file.py
|
|
15
|
+
tests/test_cli_exit_codes.py
|
|
16
|
+
tests/test_cli_json.py
|
|
17
|
+
tests/test_cli_json_errors.py
|
|
18
|
+
tests/test_edge_cases.py
|
|
19
|
+
tests/test_logging.py
|
|
20
|
+
tests/test_logging_config.py
|
|
21
|
+
tests/test_report.py
|
|
22
|
+
tests/test_report_errors.py
|
|
23
|
+
tests/test_report_json.py
|
|
24
|
+
tests/test_unexpected_error_message.py
|
|
25
|
+
tests/test_unexpected_errors.py
|
datafactor_reverse_engineering-0.4.0/datafactor_reverse_engineering.egg-info/dependency_links.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "datafactor-reverse-engineering"
|
|
7
|
+
version = "0.4.0"
|
|
8
|
+
description = "Python CLI and library for basic file inspection: SHA-256 hash, file size, and header bytes."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Zainal Nuzuli" }]
|
|
13
|
+
keywords = ["reverse-engineering", "file-analysis", "sha256", "cli", "forensics"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://github.com/Nuzuli/reverse-engineering-"
|
|
17
|
+
Repository = "https://github.com/Nuzuli/reverse-engineering-"
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
reverse-engineering = "src.analyzer:main"
|
|
21
|
+
|
|
22
|
+
[tool.setuptools]
|
|
23
|
+
packages = ["src"]
|
|
24
|
+
|
|
25
|
+
# Tool settings for linting and type checking
|
|
26
|
+
[tool.ruff]
|
|
27
|
+
line-length = 100
|
|
28
|
+
|
|
29
|
+
[tool.ruff.lint]
|
|
30
|
+
select = ["E", "F", "W"]
|
|
31
|
+
ignore = ["W292"]
|
|
32
|
+
|
|
33
|
+
[tool.mypy]
|
|
34
|
+
python_version = "3.12"
|
|
35
|
+
warn_return_any = true
|
|
36
|
+
warn_unused_ignores = true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Reverse engineering helpers: basic file inspection."""
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Basic file inspection: SHA-256 hash, file size, and header bytes."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import logging
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any, Optional, Sequence
|
|
8
|
+
|
|
9
|
+
from src.exceptions import AnalysisError
|
|
10
|
+
from src.logging_config import configure_logging
|
|
11
|
+
from src.report import format_json, format_report
|
|
12
|
+
|
|
13
|
+
__all__ = ["AnalysisError", "analyze_file", "main"]
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
CHUNK_SIZE = 65536
|
|
18
|
+
HEADER_SIZE = 16
|
|
19
|
+
USAGE = "Usage: python -m src.analyzer <file> [--json]"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def analyze_file(file_path: str | Path) -> dict[str, Any]:
|
|
23
|
+
"""Inspect a file and return its name, size, SHA-256 hash, and header.
|
|
24
|
+
|
|
25
|
+
The header is the first 16 bytes rendered as space-separated hex; it is
|
|
26
|
+
empty for an empty file. Raises AnalysisError when the path is missing,
|
|
27
|
+
is not a regular file, or cannot be read.
|
|
28
|
+
"""
|
|
29
|
+
path = Path(file_path)
|
|
30
|
+
logger.info("analyze_start path=%s", path)
|
|
31
|
+
if "\0" in str(file_path):
|
|
32
|
+
logger.warning("analyze_rejected path=%s reason=file_not_found", path)
|
|
33
|
+
raise AnalysisError(f"File not found: {path}")
|
|
34
|
+
try:
|
|
35
|
+
exists = path.exists()
|
|
36
|
+
except (OSError, ValueError):
|
|
37
|
+
exists = False
|
|
38
|
+
if not exists:
|
|
39
|
+
logger.warning("analyze_rejected path=%s reason=file_not_found", path)
|
|
40
|
+
raise AnalysisError(f"File not found: {path}")
|
|
41
|
+
try:
|
|
42
|
+
is_regular = path.is_file()
|
|
43
|
+
except (OSError, ValueError):
|
|
44
|
+
is_regular = False
|
|
45
|
+
if not is_regular:
|
|
46
|
+
logger.warning("analyze_rejected path=%s reason=not_a_regular_file", path)
|
|
47
|
+
raise AnalysisError(f"Path is not a regular file: {path}")
|
|
48
|
+
digest = hashlib.sha256()
|
|
49
|
+
size = 0
|
|
50
|
+
header = b""
|
|
51
|
+
try:
|
|
52
|
+
with path.open("rb") as handle:
|
|
53
|
+
while True:
|
|
54
|
+
chunk = handle.read(CHUNK_SIZE)
|
|
55
|
+
if not chunk:
|
|
56
|
+
break
|
|
57
|
+
if size == 0:
|
|
58
|
+
header = chunk[:HEADER_SIZE]
|
|
59
|
+
size += len(chunk)
|
|
60
|
+
digest.update(chunk)
|
|
61
|
+
except OSError as exc:
|
|
62
|
+
logger.error("analyze_failed path=%s error=%s", path, exc)
|
|
63
|
+
raise AnalysisError(f"Could not read file: {path}") from exc
|
|
64
|
+
result = {
|
|
65
|
+
"name": path.name,
|
|
66
|
+
"size_bytes": size,
|
|
67
|
+
"sha256": digest.hexdigest(),
|
|
68
|
+
"header_hex": " ".join(f"{byte:02x}" for byte in header),
|
|
69
|
+
}
|
|
70
|
+
logger.info("analyze_done name=%s size_bytes=%s", path.name, size)
|
|
71
|
+
return result
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
75
|
+
"""Run the command-line interface.
|
|
76
|
+
|
|
77
|
+
Prints the report (or JSON with --json) and returns 0 on success.
|
|
78
|
+
Exits with code 2 and a short message on stderr for any failure.
|
|
79
|
+
"""
|
|
80
|
+
configure_logging()
|
|
81
|
+
args = list(sys.argv[1:] if argv is None else argv)
|
|
82
|
+
json_mode = "--json" in args
|
|
83
|
+
args = [arg for arg in args if arg != "--json"]
|
|
84
|
+
if len(args) != 1:
|
|
85
|
+
print(USAGE, file=sys.stderr)
|
|
86
|
+
sys.exit(2)
|
|
87
|
+
try:
|
|
88
|
+
result = analyze_file(args[0])
|
|
89
|
+
except AnalysisError as exc:
|
|
90
|
+
print(f"Error: {exc}", file=sys.stderr)
|
|
91
|
+
sys.exit(2)
|
|
92
|
+
except Exception as exc:
|
|
93
|
+
logger.error(
|
|
94
|
+
"analyze_unhandled_error type=%s error=%s", type(exc).__name__, exc
|
|
95
|
+
)
|
|
96
|
+
print(f"Error: unexpected error: {exc}", file=sys.stderr)
|
|
97
|
+
sys.exit(2)
|
|
98
|
+
print(format_json(result) if json_mode else format_report(result))
|
|
99
|
+
return 0
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
if __name__ == "__main__":
|
|
103
|
+
sys.exit(main())
|