Imported Upstream version 0.2r183

parent a5cf494d
......@@ -3,7 +3,7 @@
# http://peepdf.eternal-todo.com
# By Jose Miguel Esparza <jesparza AT eternal-todo.com>
#
# Copyright (C) 2012 Jose Miguel Esparza
# Copyright (C) 2011-2013 Jose Miguel Esparza
#
# This file is part of peepdf.
#
......@@ -53,6 +53,7 @@ FILE_ADD = 2
VAR_WRITE = 3
VAR_ADD = 4
newLine = os.linesep
errorsFile = 'errors.txt'
filter2RealFilterDict = {'b64':'base64','base64':'base64','asciihex':'/ASCIIHexDecode','ahx':'/ASCIIHexDecode','ascii85':'/ASCII85Decode','a85':'/ASCII85Decode','lzw':'/LZWDecode','flatedecode':'/FlateDecode','fl':'/FlateDecode','runlength':'/RunLengthDecode','rl':'/RunLengthDecode','ccittfax':'/CCITTFaxDecode','ccf':'/CCITTFaxDecode','jbig2':'/JBIG2Decode','dct':'/DCTDecode','jpx':'/JPXDecode'}
warningColor = Fore.YELLOW
errorColor = Fore.RED
......@@ -68,6 +69,7 @@ class PDFConsole(cmd.Cmd):
'''
Class of the peepdf interactive console. To see details about commands: http://code.google.com/p/peepdf/wiki/Commands
'''
def __init__(self, pdfFile, outputColors = False, stdin = None):
cmd.Cmd.__init__(self, stdin = stdin)
if COLORIZED_OUTPUT:
......@@ -88,6 +90,7 @@ class PDFConsole(cmd.Cmd):
self.loggingFile = None
self.output = None
self.redirect = None
self.leaving = False
self.outputVarName = None
self.outputFileName = None
self.avoidOutputColors = outputColors
......@@ -101,6 +104,10 @@ class PDFConsole(cmd.Cmd):
else:
return line
def postloop(self):
print newLine + 'Leaving the Peepdf interactive console...Bye! ;)' + newLine
self.leaving = True
def do_bytes(self, argv):
if self.pdfFile == None:
message = '*** Error: You must open a file!!'
......@@ -2287,8 +2294,10 @@ class PDFConsole(cmd.Cmd):
object = self.pdfFile.getObject(id, v)
objectType = object.getType()
if objectType == 'dictionary' or objectType == 'stream':
type = object.getElementByName('/Type').getValue()
if type == '/Metadata':
subType = object.getElementByName('/Type')
if subType != []:
subType = subType.getValue()
if subType == '/Metadata':
value = object.getValue()
if value != '':
output += 'Object '+str(id)+' in version '+str(v)+':' + newLine*2+value+newLine*2
......
......@@ -5,7 +5,7 @@
# http://peepdf.eternal-todo.com
# By Jose Miguel Esparza <jesparza AT eternal-todo.com>
#
# Copyright (C) 2012 Jose Miguel Esparza
# Copyright (C) 2011-2013 Jose Miguel Esparza
#
# This file is part of peepdf.
#
......@@ -27,7 +27,7 @@
Initial script to launch the tool
'''
import sys, os, optparse, re, urllib2, datetime, hashlib
import sys, os, optparse, re, urllib2, datetime, hashlib, traceback
from datetime import datetime
from PDFCore import PDFParser,vulnsDict
......@@ -119,8 +119,8 @@ def getPeepXML(statsDict, version, revision):
comments.text = statsDict['Comments']
errors = etree.SubElement(basicInfo, 'errors', num = str(len(statsDict['Errors'])))
for error in statsDict['Errors']:
errorMessage = etree.SubElement(errors, 'error_message')
errorMessage.text = error
errorMessageXML = etree.SubElement(errors, 'error_message')
errorMessageXML.text = error
advancedInfo = etree.SubElement(root, 'advanced')
for version in range(len(statsDict['Versions'])):
statsVersion = statsDict['Versions'][version]
......@@ -223,17 +223,18 @@ def getPeepXML(statsDict, version, revision):
author = 'Jose Miguel Esparza'
email = 'jesparza AT eternal-todo.com'
email = 'peepdf AT eternal-todo.com'
url = 'http://peepdf.eternal-todo.com'
twitter = 'http://twitter.com/EternalTodo'
peepTwitter = 'http://twitter.com/peepdf'
version = '0.2'
revision = '158'
revision = '183'
stats = ''
pdf = None
fileName = None
statsDict = None
newLine = os.linesep
errorsFile = 'errors.txt'
warningColor = Fore.YELLOW
errorColor = Fore.RED
staticColor = Fore.BLUE
......@@ -241,9 +242,9 @@ staticColor = Fore.BLUE
versionHeader = 'Version: peepdf ' + version + ' r' + revision
peepdfHeader = versionHeader + newLine*2 +\
url + newLine +\
peepTwitter + newLine*2 +\
peepTwitter + newLine +\
email + newLine*2 +\
author + newLine +\
email + newLine +\
twitter + newLine
argsParser = optparse.OptionParser(usage='Usage: '+sys.argv[0]+' [options] PDF_file',description=versionHeader)
......@@ -257,9 +258,10 @@ argsParser.add_option('-v', '--version', action='store_true', dest='version', de
argsParser.add_option('-x', '--xml', action='store_true', dest='xmlOutput', default=False, help='Shows the document information in XML format.')
(options, args) = argsParser.parse_args()
if options.version:
try:
if options.version:
print peepdfHeader
elif options.update:
elif options.update:
updated = False
newVersion = ''
localVersion = 'v'+version+' r'+revision
......@@ -311,7 +313,7 @@ elif options.update:
message += ' to '+newVersion
print message
else:
else:
if len(args) == 1:
fileName = args[0]
if not os.path.exists(fileName):
......@@ -334,13 +336,33 @@ else:
console = PDFConsole(pdf,stdin=scriptFileObject)
try:
console.cmdloop()
finally:
except:
errorMessage = '*** Error: Exception not handled using the batch mode!!'
'''
if COLORIZED_OUTPUT and not options.avoidColors:
errorMessage = errorColor + errorMessage + Style.RESET_ALL
print errorMessage + newLine
traceback.print_exc(file=open(errorsFile,'a'))
'''
scriptFileObject.close()
traceback.print_exc(file=open(errorsFile,'a'))
raise Exception('PeepException','Send me an email ;)')
else:
if options.xmlOutput:
try:
from lxml import etree
xml = getPeepXML(statsDict, version, revision)
print xml
except:
errorMessage = '*** Error: Exception while generating the XML file!!'
traceback.print_exc(file=open(errorsFile,'a'))
'''
if COLORIZED_OUTPUT and not options.avoidColors:
errorMessage = errorColor + errorMessage + Style.RESET_ALL
print errorMessage + newLine
traceback.print_exc(file=open(errorsFile,'a'))
'''
raise Exception('PeepException','Send me an email ;)')
else:
if statsDict != None:
if not JS_MODULE:
......@@ -459,9 +481,33 @@ else:
for url in urls:
stats += '\t\t' + url + newLine
stats += newLine * 2
if fileName != None:
print stats
if options.isInteractive:
from PDFConsole import PDFConsole
console = PDFConsole(pdf, options.avoidColors)
console.cmdloop(stats + newLine)
elif fileName != None:
print stats
\ No newline at end of file
while not console.leaving:
try:
console.cmdloop()
except:
errorMessage = '*** Error: Exception not handled using the interactive console!! Please, report it to the author!!'
if COLORIZED_OUTPUT and not options.avoidColors:
errorMessage = errorColor + errorMessage + Style.RESET_ALL
print errorMessage + newLine
traceback.print_exc(file=open(errorsFile,'a'))
except Exception as e:
excName,excReason = e.args
if excName != 'PeepException':
errorMessage = '*** Error: Exception not handled!!'
traceback.print_exc(file=open(errorsFile,'a'))
if COLORIZED_OUTPUT and not options.avoidColors:
errorMessage = errorColor + errorMessage + Style.RESET_ALL
print errorMessage + newLine
finally:
if os.path.exists(errorsFile):
message = newLine + 'Please, don\'t forget to report the errors found:' + newLine*2
message += '\t- Sending the file "errors.txt" to the author (mailto:peepdfREMOVETHIS@eternal-todo.com)"' + newLine
message += '\t- And/Or creating an issue on the project webpage (https://code.google.com/p/peepdf/issues/list)' + newLine
if COLORIZED_OUTPUT and not options.avoidColors:
message = errorColor + message + Style.RESET_ALL
sys.exit(message)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment