pdforensic-authentic-check 0.1.1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alex Mkwizu
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,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: pdforensic-authentic-check
3
+ Version: 0.1.1
4
+ Summary: A simple PDF forensic toolkit using pdfresurrect and bash utilities
5
+ Author: Alex Mkwizu
6
+ Author-email: alexgmkwizu@gmail.com
7
+ License-File: LICENSE
8
+ Provides-Extra: dev
9
+ Requires-Dist: pytest; extra == "dev"
10
+ Dynamic: author
11
+ Dynamic: author-email
12
+ Dynamic: license-file
13
+ Dynamic: provides-extra
14
+ Dynamic: summary
@@ -0,0 +1,167 @@
1
+ # 📄 pdforensic
2
+
3
+
4
+ > A lightweight Python toolkit for forensic analysis of PDF files using [pdfresurrect](https://github.com/enferex/pdfresurrect) and unix kernel shell utilities.
5
+
6
+ **pdforensic** wraps common PDF forensic techniques into an easy-to-use Python and CLI interface — allowing you to extract metadata, recover previous versions, count EOF markers, and inspect version layers of PDF files.
7
+
8
+ ## Project Directory
9
+ ```
10
+ .
11
+ ├── bin
12
+ │ ├── pdfresurrect
13
+ │ └── pdfresurrect.1
14
+ ├── LICENSE
15
+ ├── pdforensic
16
+ │ ├── __init__.py
17
+ ├── README.md
18
+ ├── setup.py
19
+ └── tests
20
+ ├── pdf-to-test
21
+ │ ├── pdf-to-test-a.pdf
22
+ │ └── pdf-to-test-b.pdf
23
+ ├── test_check_eof_markers.py
24
+ ├── test_check_versions.py
25
+ ├── test_retrieve_all-versions.py
26
+ └── test_retrieve_metadata.py
27
+ ```
28
+ ## The Package
29
+
30
+ This package has been built to work on unix kernel i.e., linux OS and MacOS.
31
+
32
+ You will require Python 3.13.x to work with this package.
33
+
34
+ This package is an ongoing experiment to understand how to check for an edited PDF and automate the process.
35
+
36
+ It is built on top of [pdfresurrect](https://github.com/enferex/pdfresurrect) which is a C tool that reads the PDF at it's lowest level extracting metadata , object streams , check for previous versions by checking for cross-referencing of streams and also able to rewrite previous versions.
37
+
38
+ The **pdfresurrect** functionalities have been wrapped to be reusable quickly with Python.
39
+
40
+ An additional functionality from my PDF research has been added that check for `%%EOF` markers its absence means the PDF is corrupted and not in a proper format. A linearized or an original or freshly saved has 1 `%%EOF` marker , more than 1 means the PDF has been tampered with.
41
+
42
+ Hence you can use above functionalities to build a PDF verification algorithim if you do now what type of PDF file you will be processing by comparing it's properties against new incoming PDF's.
43
+
44
+ ## 🐍 Using the Python Package
45
+
46
+ You can use **pdforensic** directly from Python code by importing its core functions.
47
+
48
+ ### 📦 Importable Functions
49
+
50
+ ```python
51
+ from pdforensic import (
52
+ extract_pdf_metadata,
53
+ recover_pdf_versions,
54
+ count_pdf_eof_markers,
55
+ check_no_of_versions
56
+ )
57
+ ```
58
+ 1. Extract PDF Metadata
59
+
60
+ ```python
61
+ from pdforensic import extract_pdf_metadata
62
+
63
+ metadata = extract_pdf_metadata("tests/pdf-to-test/pdf-to-test-a.pdf")
64
+ print(metadata)
65
+ ```
66
+ Returns:
67
+
68
+ ```python
69
+
70
+ {
71
+ 'Versions': '1',
72
+ 'PDF Version': '1.4',
73
+ 'Title': 'My Document',
74
+ 'Producer': 'Skia/PDF',
75
+ ...
76
+ }
77
+ ```
78
+
79
+ 2. Recover Previous Versions
80
+
81
+ ```python
82
+
83
+ from pdforensic import recover_pdf_versions
84
+
85
+ message = recover_pdf_versions("tests/pdf-to-test/pdf-to-test-b.pdf")
86
+ print(message)
87
+ ```
88
+
89
+ Example output:
90
+ ```python
91
+ Recovered 2 version(s). Found in: pdf-to-test-b-versions/
92
+ ```
93
+
94
+ 3. Count %%EOF Markers
95
+
96
+ ```python
97
+ from pdforensic import count_pdf_eof_markers
98
+
99
+ count = count_pdf_eof_markers("tests/pdf-to-test/pdf-to-test-a.pdf")
100
+ print(f"EOF markers: {count}")
101
+ ```
102
+
103
+ 4. Check Number of PDF Versions
104
+
105
+ ```python
106
+ from pdforensic import check_no_of_versions
107
+
108
+ num_versions = check_no_of_versions("tests/pdf-to-test/pdf-to-test-a.pdf")
109
+ print(f"PDF contains {num_versions} version(s).")
110
+ ```
111
+
112
+ **🧪 Pro Tip**
113
+ You can integrate these tools into a PDF auditing script or pipeline for digital forensics, penetration testing, academic research, or version tracking.
114
+
115
+ ### 📦 Using CLI
116
+
117
+ **🔧 Command-Line Interface (CLI)**
118
+
119
+ Once installed (with pip install -e .), the following CLI commands are available:
120
+
121
+ **Command Description**
122
+
123
+ ```
124
+ pdf-meta Extract metadata from a PDF file
125
+ pdf-recover Recover previous versions of a PDF
126
+ pdf-eof Count %%EOF markers in a PDF
127
+ pdf-versions Check number of versions in a PDF (via -q)
128
+ ```
129
+
130
+ Example Usage
131
+ ```bash
132
+
133
+ pdf-meta <pdf_path>
134
+
135
+ pdf-recover <pdf_path>
136
+
137
+ pdf-eof <pdf_path>
138
+
139
+ pdf-versions <pdf_path>
140
+
141
+ ```
142
+ ## 🛠️ Installation
143
+
144
+ ### Option 1: Clone and Install from GitHub (Recommended)
145
+
146
+ ```bash
147
+ git clone https://github.com/yourusername/pdforensic.git
148
+ cd pdforensic
149
+ pip install -e .
150
+ #This installs pdforensic in editable mode, meaning any changes you make to the code will take effect immediately.
151
+ ```
152
+
153
+ ### Option 2: Install with Dev Dependencies (for testing and development)
154
+ ```bash
155
+ pip install -e '.[dev]'
156
+ #This includes testing tools i.e., pytest.
157
+ ```
158
+ ### Option 3: Install directly via GitHub URL (no clone)
159
+ ```bash
160
+ pip install git+https://github.com/genie360s/pdforensic.git
161
+ ```
162
+
163
+
164
+
165
+ #### 📜 License
166
+
167
+ MIT License © 2025 Alex Mkwizu
@@ -0,0 +1,17 @@
1
+ """
2
+ pdforensic - Lightweight PDF forensics utility wrapping pdfresurrect and other shell tools.
3
+ """
4
+
5
+ from .retrieve_metadata import extract_pdf_metadata
6
+ from .retrieve_all_versions import recover_pdf_versions
7
+ from .check_versions import check_no_of_versions
8
+ from .check_eof_markers import count_pdf_eof_markers
9
+
10
+ __version__ = "0.1.0"
11
+
12
+ __all__ = [
13
+ "extract_pdf_metadata",
14
+ "recover_pdf_versions",
15
+ "check_no_of_versions",
16
+ "count_pdf_eof_markers"
17
+ ]
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import argparse
4
+ import re
5
+
6
+ def count_pdf_eof_markers(pdf_path):
7
+ """
8
+ Count the number of %%EOF markers in a PDF file.
9
+
10
+ Args:
11
+ pdf_path (str): Path to the PDF file.
12
+
13
+ Returns:
14
+ int: Number of %%EOF markers.
15
+ -1: If file not found or unreadable.
16
+ """
17
+ try:
18
+ with open(pdf_path, 'rb') as f:
19
+ content = f.read()
20
+
21
+ matches = re.findall(rb"%%EOF", content)
22
+ return len(matches)
23
+
24
+ except FileNotFoundError:
25
+ return -1
26
+ except Exception as e:
27
+ print(f"Error reading PDF: {e}")
28
+ return -1
29
+
30
+ def cli():
31
+ """
32
+ Command-line interface for counting %%EOF markers in a PDF file.
33
+ """
34
+ parser = argparse.ArgumentParser(description="Count %%EOF markers in a PDF file")
35
+ parser.add_argument("pdf_path", type=str, help="Path to the PDF file")
36
+ args = parser.parse_args()
37
+
38
+ count = count_pdf_eof_markers(args.pdf_path)
39
+ if count == -1:
40
+ print("❌ Could not open or read the PDF.")
41
+ else:
42
+ print(f"Number of %%EOF markers found: {count}")
43
+
44
+ if __name__ == "__main__":
45
+ cli()
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import subprocess
4
+ import argparse
5
+
6
+ def check_no_of_versions(pdf_path):
7
+ """
8
+ Check the number of versions of a PDF file using the pdfresurrect tool.
9
+
10
+ Args:
11
+ pdf_path (str): The path to the PDF file.
12
+
13
+ Returns:
14
+ int: The number of versions found in the PDF file.
15
+ """
16
+ try:
17
+ result = subprocess.run(
18
+ ['./bin/pdfresurrect', '-q', pdf_path],
19
+ capture_output=True,
20
+ text=True,
21
+ check=True
22
+ )
23
+ output = result.stdout.strip()
24
+ if ':' in output:
25
+ parts = output.split(':')
26
+ version_str = parts[1].strip()
27
+ if version_str.isdigit():
28
+ return int(version_str)
29
+ print(f"Unexpected output: {output}")
30
+ return 0
31
+ except subprocess.CalledProcessError as e:
32
+ print(f"Error checking PDF versions: {e}")
33
+ return 0
34
+
35
+ def cli():
36
+ """
37
+ Command-line interface for checking number of PDF versions.
38
+ """
39
+ parser = argparse.ArgumentParser(description="Check the number of PDF versions using pdfresurrect")
40
+ parser.add_argument("pdf_path", type=str, help="Path to the PDF file")
41
+ args = parser.parse_args()
42
+
43
+ versions = check_no_of_versions(args.pdf_path)
44
+ print(f"Number of versions found: {versions}")
45
+
46
+ if __name__ == "__main__":
47
+ cli()
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import subprocess
4
+ import argparse
5
+ import os
6
+
7
+ def recover_pdf_versions(pdf_path):
8
+ """
9
+ Recover previous versions of a PDF using pdfresurrect -w.
10
+ If previous versions are recovered, list them from the auto-created folder.
11
+
12
+ Args:
13
+ pdf_path (str): Path to the PDF file.
14
+
15
+ Returns:
16
+ str: Status message with recovered file listing if applicable.
17
+ """
18
+ try:
19
+ result = subprocess.run(
20
+ ['./bin/pdfresurrect', '-w', pdf_path],
21
+ capture_output=True,
22
+ text=True,
23
+ check=True
24
+ )
25
+
26
+ output = result.stdout.strip()
27
+ print(f"\n[pdforensic output]:\n{output}\n")
28
+
29
+ # Case 1: Only one version
30
+ if "There is only one version of this PDF" in output:
31
+ return "There is only one version of this PDF. No previous versions recovered."
32
+
33
+ # Case 2: Folder exists with recovered versions
34
+ base_name = os.path.splitext(os.path.basename(pdf_path))[0]
35
+ version_folder = f"{base_name}-versions"
36
+
37
+ if os.path.isdir(version_folder):
38
+ recovered_files = os.listdir(version_folder)
39
+ print(f"Recovered versions & summary text of change found in: {version_folder}/")
40
+ for f in recovered_files:
41
+ print(f"✔ {f}")
42
+ return f"Recovered {len(recovered_files)} version(s)."
43
+ else:
44
+ return "Warning: Recovery folder not found, although output indicated multiple versions."
45
+
46
+ except subprocess.CalledProcessError as e:
47
+ return f"Error recovering PDF versions: {e}"
48
+
49
+ def cli():
50
+ """
51
+ Command-line interface for recovering PDF versions.
52
+ """
53
+ parser = argparse.ArgumentParser(description="Recover previous PDF versions using pdfresurrect")
54
+ parser.add_argument("pdf_path", type=str, help="Path to the PDF file")
55
+ args = parser.parse_args()
56
+
57
+ message = recover_pdf_versions(args.pdf_path)
58
+ print(f"\nResult: {message}")
59
+
60
+ if __name__ == "__main__":
61
+ cli()
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import subprocess
4
+ import argparse
5
+
6
+ def extract_pdf_metadata(pdf_path):
7
+ """
8
+ Extract PDF forensic metadata using pdfresurrect -i.
9
+
10
+ Args:
11
+ pdf_path (str): Path to the PDF file.
12
+
13
+ Returns:
14
+ dict: Metadata extracted from the PDF.
15
+ """
16
+ metadata = {}
17
+ try:
18
+ result = subprocess.run(
19
+ ['./bin/pdfresurrect', '-i', pdf_path],
20
+ capture_output=True,
21
+ text=True,
22
+ check=True
23
+ )
24
+
25
+ lines = result.stdout.strip().splitlines()
26
+
27
+ for line in lines:
28
+ if line.strip() == "":
29
+ continue
30
+
31
+ # Handle Version X -- Y objects
32
+ if line.startswith("Version") and "--" in line and "objects" in line:
33
+ metadata["object_summary"] = line.strip()
34
+ continue
35
+
36
+ # Handle key: value
37
+ if ":" in line:
38
+ key, value = line.split(":", 1)
39
+ metadata[key.strip()] = value.strip().strip("()")
40
+
41
+ return metadata
42
+
43
+ except subprocess.CalledProcessError as e:
44
+ print(f"Error extracting metadata: {e}")
45
+ return {}
46
+
47
+ def cli():
48
+ """
49
+ Command-line interface for extracting PDF metadata.
50
+ """
51
+ parser = argparse.ArgumentParser(description="Extract PDF metadata using pdfresurrect")
52
+ parser.add_argument("pdf_path", type=str, help="Path to the PDF file")
53
+ args = parser.parse_args()
54
+
55
+ meta = extract_pdf_metadata(args.pdf_path)
56
+ print("Extracted PDF Metadata:")
57
+ for key, value in meta.items():
58
+ print(f"{key}: {value}")
59
+
60
+ if __name__ == "__main__":
61
+ cli()
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: pdforensic-authentic-check
3
+ Version: 0.1.1
4
+ Summary: A simple PDF forensic toolkit using pdfresurrect and bash utilities
5
+ Author: Alex Mkwizu
6
+ Author-email: alexgmkwizu@gmail.com
7
+ License-File: LICENSE
8
+ Provides-Extra: dev
9
+ Requires-Dist: pytest; extra == "dev"
10
+ Dynamic: author
11
+ Dynamic: author-email
12
+ Dynamic: license-file
13
+ Dynamic: provides-extra
14
+ Dynamic: summary
@@ -0,0 +1,18 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ pdforensic/__init__.py
5
+ pdforensic/check_eof_markers.py
6
+ pdforensic/check_versions.py
7
+ pdforensic/retrieve_all_versions.py
8
+ pdforensic/retrieve_metadata.py
9
+ pdforensic_authentic_check.egg-info/PKG-INFO
10
+ pdforensic_authentic_check.egg-info/SOURCES.txt
11
+ pdforensic_authentic_check.egg-info/dependency_links.txt
12
+ pdforensic_authentic_check.egg-info/entry_points.txt
13
+ pdforensic_authentic_check.egg-info/requires.txt
14
+ pdforensic_authentic_check.egg-info/top_level.txt
15
+ tests/test_check_eof_markers.py
16
+ tests/test_check_versions.py
17
+ tests/test_retrieve_all-versions.py
18
+ tests/test_retrieve_metadata.py
@@ -0,0 +1,5 @@
1
+ [console_scripts]
2
+ pdf-eof = pdforensic.check_eof_markers:cli
3
+ pdf-meta = pdforensic.retrieve_metadata:cli
4
+ pdf-recover = pdforensic.retrieve_all_versions:cli
5
+ pdf-versions = pdforensic.check_versions:cli
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,26 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name='pdforensic-authentic-check',
8
+ version='0.1.1',
9
+ description='A simple PDF forensic toolkit using pdfresurrect and bash utilities',
10
+ author='Alex Mkwizu',
11
+ author_email='alexgmkwizu@gmail.com',
12
+ packages=find_packages(),
13
+ include_package_data=True,
14
+ install_requires=[], # Add any dependencies like PyPDF2 if used
15
+ extras_require={
16
+ "dev": ["pytest"]
17
+ },
18
+ entry_points={
19
+ 'console_scripts': [
20
+ 'pdf-meta=pdforensic.retrieve_metadata:cli',
21
+ 'pdf-recover=pdforensic.retrieve_all_versions:cli',
22
+ 'pdf-eof=pdforensic.check_eof_markers:cli',
23
+ 'pdf-versions=pdforensic.check_versions:cli'
24
+ ],
25
+ },
26
+ )
@@ -0,0 +1,9 @@
1
+ from pdforensic.check_eof_markers import count_pdf_eof_markers
2
+
3
+ def test_count_eof_in_single_version_pdf():
4
+ count = count_pdf_eof_markers("tests/pdf-to-test/pdf-to-test-b.pdf")
5
+ assert count == 1
6
+
7
+ def test_count_eof_in_multi_version_pdf():
8
+ count = count_pdf_eof_markers("tests/pdf-to-test/pdf-to-test-a.pdf")
9
+ assert count > 1
@@ -0,0 +1,9 @@
1
+ from pdforensic.check_versions import check_no_of_versions
2
+
3
+ def test_check_single_version_pdf():
4
+ count = check_no_of_versions("tests/pdf-to-test/pdf-to-test-a.pdf")
5
+ assert count == 1
6
+
7
+ # def test_check_multi_version_pdf():
8
+ # count = check_no_of_versions("tests/pdf-to-test/pdf-to-test-b.pdf")
9
+ # assert count > 1
@@ -0,0 +1,13 @@
1
+ import os
2
+ from pdforensic.retrieve_all_versions import recover_pdf_versions
3
+
4
+ def test_recover_pdf_versions_single_version():
5
+ result = recover_pdf_versions("tests/pdf-to-test/pdf-to-test-b.pdf")
6
+ assert "only one version" in result.lower()
7
+
8
+ def test_recover_pdf_versions_multi_version():
9
+ result = recover_pdf_versions("tests/pdf-to-test/pdf-to-test-a.pdf")
10
+ assert "recovered" in result.lower()
11
+ folder = "pdf-to-test-a-versions"
12
+ assert os.path.exists(folder)
13
+ assert len(os.listdir(folder)) > 0
@@ -0,0 +1,7 @@
1
+ import os
2
+ from pdforensic.retrieve_metadata import extract_pdf_metadata
3
+
4
+ def test_extract_pdf_metadata_returns_dict():
5
+ metadata = extract_pdf_metadata("tests/pdf-to-test/pdf-to-test-a.pdf")
6
+ assert isinstance(metadata, dict)
7
+ assert "PDF Version" in metadata