Skip to content

Commit 464fc96

Browse files
Merge pull request #34 from digitalsleuth/fix_embed
Fix embed
2 parents c8f3537 + 0043c3e commit 464fc96

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

peepdf/PDFConsole.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,13 +752,13 @@ def do_embed(self, argv):
752752
self.log_output("embed " + argv, message)
753753
return False
754754

755-
hexFileNameObject = PDFHexString(fileName.encode("hex"))
755+
hexFileNameObject = PDFHexString(fileName.encode().hex())
756756
md5Hash = hashlib.md5(fileContent).hexdigest()
757757
fileSize = len(fileContent)
758758
paramsDic = PDFDictionary(
759759
elements={
760760
"/Size": PDFNum(str(fileSize)),
761-
"/Checksum": PDFHexString(md5Hash),
761+
"/Checksum": PDFHexString(md5Hash, IS_HASH=True),
762762
}
763763
)
764764
embeddedFileElements = {

peepdf/PDFCore.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ class PDFHexString(PDFObject):
747747
Hexadecimal string object of a PDF document
748748
"""
749749

750-
def __init__(self, hexData, IS_ID=False):
750+
def __init__(self, hexData, IS_ID=False, IS_HASH=False):
751751
self.asciiValue = ""
752752
self.objType = "hexstring"
753753
self.errors = []
@@ -766,6 +766,7 @@ def __init__(self, hexData, IS_ID=False):
766766
self.referencesInElements = {}
767767
self.references = []
768768
self.IS_ID = IS_ID
769+
self.IS_HASH = IS_HASH
769770
ret = self.update()
770771
if ret[0] == -1:
771772
if isForceMode:
@@ -803,6 +804,8 @@ def update(self, decrypt: bool = False, newHexValue: bool = True):
803804
self.encryptedValue = self.value
804805
if self.IS_ID:
805806
self.value = f"<{self.rawValue}>"
807+
if self.IS_HASH:
808+
self.value = self.rawValue
806809
except:
807810
errorMessage = "[!] Error in hexadecimal conversion"
808811
self.addError(errorMessage)
@@ -7033,7 +7036,7 @@ def removeError(self, errorMessage="", errorType=None):
70337036
self.errors.remove(error)
70347037

70357038
def save(
7036-
self, filename, pdfPath, version=None, malformedOptions=None, headerFile=None
7039+
self, filename, version=None, malformedOptions=None, headerFile=None
70377040
):
70387041
if malformedOptions is None:
70397042
malformedOptions = []
@@ -7179,7 +7182,7 @@ def save(
71797182
self.body[v].setObjects(indirectObjects)
71807183
offset = len(outputFileContent)
71817184
if os.sep not in filename:
7182-
outputPath = f"{pdfPath}{os.sep}{filename}"
7185+
outputPath = os.path.realpath(filename)
71837186
else:
71847187
outputPath = filename
71857188
if isinstance(outputFileContent, str):

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies = [
1616
"Pillow",
1717
"pythonaes",
1818
"lxml",
19-
"prettytable>=3.9.0",
19+
"prettytable>=3.12.0",
2020
"STPyV8",
2121
]
2222
requires-python = ">=3.9"
@@ -29,7 +29,7 @@ maintainers = [
2929
]
3030
description = "A Python 3 tool to explore, analyse, and disassemble PDF files"
3131
readme = "README.md"
32-
license = {file = "COPYING"}
32+
license-files = ["COPYING"]
3333
keywords = ["pdf", "peepdf", "forensics"]
3434
classifiers = [
3535
"Development Status :: 5 - Production/Stable",

0 commit comments

Comments
 (0)