Skip to content

Commit

Permalink
Merge pull request #118 from digitalsleuth/py2_py3
Browse files Browse the repository at this point in the history
Update python2 tools to python3, remove deprecated python2 packages
  • Loading branch information
ekristen authored Nov 14, 2024
2 parents c9d4f20 + 1326a1c commit 3b91b05
Show file tree
Hide file tree
Showing 89 changed files with 3,702 additions and 2,069 deletions.
465 changes: 263 additions & 202 deletions sift/files/page-brute/page_brute-BETA.py

Large diffs are not rendered by default.

659 changes: 608 additions & 51 deletions sift/files/pdf-tools/mPDF.py

Large diffs are not rendered by default.

26 changes: 21 additions & 5 deletions sift/files/pdf-tools/make-pdf-embedded.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/python
#!/usr/bin/env python3

__description__ = 'tool to create a PDF document with an embedded file'
__author__ = 'Didier Stevens'
__version__ = '0.5.0'
__date__ = '2011/07/01'
__version__ = '0.5.1'
__date__ = '2017/04/23'

"""
Source code put in public domain by Didier Stevens, no Copyright
Expand All @@ -19,13 +19,28 @@
2008/11/09: V0.3, added autostart and button
2009/06/15: V0.4.0: added stego
2011/07/01: V0.5.0: added support for Python 3
2017/04/23: V0.5.1: added option -n
Todo:
"""

import mPDF
import optparse

# CIC: Call If Callable
def CIC(expression):
if callable(expression):
return expression()
else:
return expression

# IFF: IF Function
def IFF(expression, valueTrue, valueFalse):
if expression:
return CIC(valueTrue)
else:
return CIC(valueFalse)

def ReadBinaryFile(name):
"""Read a binary file and return the content, return None if error occured
"""
Expand Down Expand Up @@ -93,6 +108,7 @@ def Main():
oParser.add_option('-b', '--button', action='store_true', default=False, help='add a "button" to launch the embedded file')
oParser.add_option('-s', '--stego', action='store_true', default=False, help='"hide" the embedded file by replacing /EmbeddedFiles with /Embeddedfiles')
oParser.add_option('-m', '--message', default='', help='text to display in the PDF document')
oParser.add_option('-n', '--name', default='', help='filename to use in the PDF objects (by default same as file-to-embed name)')
(options, args) = oParser.parse_args()

if len(args) != 2:
Expand All @@ -111,7 +127,7 @@ def Main():
if embeddedFileContent == None:
print('Error opening/reading file %s' % embeddedFileName)
else:
CreatePDFWithEmbeddedFile(pdfFileName, embeddedFileName, embeddedFileContent, options.filters, options.nobinary, options.autoopen, options.button, options.stego, options.message)
CreatePDFWithEmbeddedFile(pdfFileName, IFF(options.name == '', embeddedFileName, options.name), embeddedFileContent, options.filters, options.nobinary, options.autoopen, options.button, options.stego, options.message)

if __name__ == '__main__':
Main()
20 changes: 10 additions & 10 deletions sift/files/pdf-tools/make-pdf-helloworld.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#20080518
#20080519

Expand All @@ -8,11 +8,11 @@
import sys

if len(sys.argv) != 2:
print "Usage: make-pdf-helloworld pdf-file"
print " "
print " Source code put in the public domain by Didier Stevens, no Copyright"
print " Use at your own risk"
print " https://DidierStevens.com"
print("Usage: make-pdf-helloworld pdf-file")
print(" ")
print(" Source code put in the public domain by Didier Stevens, no Copyright")
print(" Use at your own risk")
print(" https://DidierStevens.com")

else:
pdffile = sys.argv[1]
Expand All @@ -24,10 +24,10 @@
oPDF.template1()

#oPDF.stream(5, 0, "BT /F1 24 Tf 100 700 Td (Hello World) Tj ET")
oPDF.stream(5, 0, """BT /F1 12 Tf 100 700 Td 15 TL
(Hello World) Tj
(Second Line) '
(Third Line) '
oPDF.stream(5, 0, """BT /F1 12 Tf 100 700 Td 15 TL
(Hello World) Tj
(Second Line) '
(Third Line) '
ET
100 712 100 -100 re S""")

Expand Down
27 changes: 12 additions & 15 deletions sift/files/pdf-tools/make-pdf-javascript.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3

# V0.1 2008/05/23
# make-pdf-javascript, use it to create a PDF document with embedded JavaScript that will execute automatically when the document is opened
Expand All @@ -8,7 +8,7 @@
# Use at your own risk
#
# History:
#
#
# 2008/05/29: continue
# 2008/11/09: cleanup for release

Expand All @@ -26,24 +26,21 @@ def Main():

if len(args) != 1:
parser.print_help()
print ''
print ' make-pdf-javascript, use it to create a PDF document with embedded JavaScript that will execute automatically when the document is opened'
print ' Source code put in the public domain by Didier Stevens, no Copyright'
print ' Use at your own risk'
print ' https://DidierStevens.com'
print('')
print(' make-pdf-javascript, use it to create a PDF document with embedded JavaScript that will execute automatically when the document is opened')
print(' Source code put in the public domain by Didier Stevens, no Copyright')
print(' Use at your own risk')
print(' https://DidierStevens.com')

else:
oPDF = mPDF.cPDF(args[0])

oPDF.header()

oPDF.indirectobject(1, 0, '<<\n /Type /Catalog\n /Outlines 2 0 R\n /Pages 3 0 R\n /OpenAction 7 0 R\n>>')
oPDF.indirectobject(2, 0, '<<\n /Type /Outlines\n /Count 0\n>>')
oPDF.indirectobject(3, 0, '<<\n /Type /Pages\n /Kids [4 0 R]\n /Count 1\n>>')
oPDF.indirectobject(4, 0, '<<\n /Type /Page\n /Parent 3 0 R\n /MediaBox [0 0 612 792]\n /Contents 5 0 R\n /Resources <<\n /ProcSet [/PDF /Text]\n /Font << /F1 6 0 R >>\n >>\n>>')
oPDF.stream(5, 0, 'BT /F1 12 Tf 100 700 Td 15 TL (JavaScript example) Tj ET')
oPDF.indirectobject(6, 0, '<<\n /Type /Font\n /Subtype /Type1\n /Name /F1\n /BaseFont /Helvetica\n /Encoding /MacRomanEncoding\n>>')

if options.javascript == None and options.javascriptfile == None:
javascript = """app.alert({cMsg: 'Hello from PDF JavaScript', cTitle: 'Testing PDF JavaScript', nIcon: 3});"""
elif options.javascript != None:
Expand All @@ -52,19 +49,19 @@ def Main():
try:
fileJavasScript = open(options.javascriptfile, 'rb')
except:
print "error opening file %s" % options.javascriptfile
print("error opening file %s" % options.javascriptfile)
return

try:
javascript = fileJavasScript.read()
except:
print "error reading file %s" % options.javascriptfile
print("error reading file %s" % options.javascriptfile)
return
finally:
fileJavasScript.close()

oPDF.indirectobject(7, 0, '<<\n /Type /Action\n /S /JavaScript\n /JS (%s)\n>>' % javascript)

oPDF.xrefAndTrailer('1 0 R')

if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 3b91b05

Please sign in to comment.