pdforensic-authentic-check 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.

Potentially problematic release.


This version of pdforensic-authentic-check might be problematic. Click here for more details.

pdforensic/__init__.py ADDED
@@ -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.0
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,11 @@
1
+ pdforensic/__init__.py,sha256=ZV5dgxExgr1GY2i70jnRHgL-gyjWo9-nWghfbOSPyX0,461
2
+ pdforensic/check_eof_markers.py,sha256=0hvzZAxCNzRHAKSLVFcQFO5RpiNqy-yDsNslpJpJwHA,1125
3
+ pdforensic/check_versions.py,sha256=3-MHH4hhZLei59YnIVjlNQmss5N23D0KIppAwIPCmMU,1349
4
+ pdforensic/retrieve_all_versions.py,sha256=TSqjqdMOYym0Yebd0yIIm9mDJggGTyGX_L3T2786wvw,2009
5
+ pdforensic/retrieve_metadata.py,sha256=836zuTw1mrVDU4TcKZNCNlI38FKq1-H4ANg7Bwgwtz0,1626
6
+ pdforensic_authentic_check-0.1.0.dist-info/licenses/LICENSE,sha256=y_53LQFJ-g-6uwPkCGVcT3LhYFuUTcTdGvz90fIBpBE,1068
7
+ pdforensic_authentic_check-0.1.0.dist-info/METADATA,sha256=VH14hMtw9PI0JWq_DXwT23vXdUPbZOBnDNloJHGLTpc,384
8
+ pdforensic_authentic_check-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ pdforensic_authentic_check-0.1.0.dist-info/entry_points.txt,sha256=X9i8BZxZyBDkHSeQIRStjf-o5tzpXrf1O5MhmH5zXj8,201
10
+ pdforensic_authentic_check-0.1.0.dist-info/top_level.txt,sha256=9JthI2_jEtlj_ZvJHod_UI6nISUJYfyS52wqjwfOj6I,11
11
+ pdforensic_authentic_check-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -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,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 @@
1
+ pdforensic