Commit 9075d711 authored by Sophie Brun's avatar Sophie Brun

New upstream version 0.4.1

parent 6f3b2db1
Metadata-Version: 1.0
Name: peepdf
Version: 0.3.6
Version: 0.4.1
Summary: UNKNOWN
Home-page: http://eternal-todo.com
Author: Jose Miguel Esparza
Author-email: UNKNOWN
License: GNU GPLv3
Description-Content-Type: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Metadata-Version: 1.0
Name: peepdf
Version: 0.3.6
Version: 0.4.1
Summary: UNKNOWN
Home-page: http://eternal-todo.com
Author: Jose Miguel Esparza
Author-email: UNKNOWN
License: GNU GPLv3
Description-Content-Type: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
......@@ -5,12 +5,10 @@ peepdf/PDFConsole.py
peepdf/PDFCore.py
peepdf/PDFCrypto.py
peepdf/PDFFilters.py
peepdf/PDFOutput.py
peepdf/PDFUtils.py
peepdf/__init__.py
peepdf/aes.py
peepdf/ccitt.py
peepdf/constants.py
peepdf/jjdecode.py
peepdf/lzw.py
peepdf/main.py
......
jsbeautifier==1.6.2
colorama==0.3.7
future>=0.16.0
Pillow==3.2.0
pythonaes==1.0
......@@ -58,8 +58,8 @@ preDefinedCode = 'var app = this;'
# Regex that matches any character that's <32 && >127 and not a whitespace.
bad_chars_re = "|".join(re.escape(chr(ch)) for ch in (
[ch for ch in xrange(32) if chr(ch) not in "\n\r\t\f"] +
[ch for ch in xrange(128, 256)]
[ch for ch in range(32) if chr(ch) not in "\n\r\t\f"] +
[ch for ch in range(128, 256)]
))
def analyseJS(code, context=None, manualAnalysis=False):
......@@ -199,8 +199,8 @@ def isJavascript(content):
if re.findall(reJSscript, content, re.DOTALL | re.IGNORECASE):
return True
_, count = re.subn(bad_chars_re, "", content, len(content) / 10)
if count == len(content) / 10:
_, count = re.subn(bad_chars_re, "", content, len(content) // 10)
if int(count) == len(content) // 10:
return False
for string in jsStrings:
......@@ -244,7 +244,7 @@ def searchObfuscatedFunctions(jsCode, function):
return obfuscatedFunctionsInfo
def unescape(escapedBytes, unicode=True):
def unescape(escapedBytes, str=True):
'''
This method unescapes the given string
......@@ -253,13 +253,13 @@ def unescape(escapedBytes, unicode=True):
'''
# TODO: modify to accept a list of escaped strings?
unescapedBytes = ''
if unicode:
if str:
unicodePadding = '\x00'
else:
unicodePadding = ''
try:
if escapedBytes.lower().find('%u') != -1 or escapedBytes.lower().find('\u') != -1 or escapedBytes.find('%') != -1:
if escapedBytes.lower().find('\u') != -1:
if escapedBytes.lower().find('%u') != -1 or escapedBytes.lower().find('\\u') != -1 or escapedBytes.find('%') != -1:
if escapedBytes.lower().find('\\u') != -1:
splitBytes = escapedBytes.split('\\')
else:
splitBytes = escapedBytes.split('%')
......
......@@ -33,6 +33,9 @@ import hashlib
import traceback
import jsbeautifier
# Return a string on Py2 & Py3.
from builtins import input
from peepdf.PDFUtils import (
getBytesFromFile, countArrayElements, clearScreen, hexToString,
escapeRegExpString, vtcheck, countNonPrintableChars
......@@ -45,7 +48,7 @@ from peepdf.PDFCore import (
)
from base64 import b64encode, b64decode
from PDFFilters import decodeStream, encodeStream
from peepdf.PDFFilters import decodeStream, encodeStream
from peepdf.jjdecode import JJDecoder
try:
......@@ -152,7 +155,7 @@ class PDFConsole(cmd.Cmd):
def postloop(self):
if self.use_rawinput:
print newLine + 'Leaving the Peepdf interactive console...Bye! ;)' + newLine
print((newLine + 'Leaving the Peepdf interactive console...Bye! ;)' + newLine))
self.leaving = True
def do_bytes(self, argv):
......@@ -185,8 +188,8 @@ class PDFConsole(cmd.Cmd):
self.help_bytes()
def help_bytes(self):
print newLine + 'Usage: bytes $offset $num_bytes [$file]'
print newLine + 'Shows or stores in the specified file $num_bytes of the file beginning from $offset' + newLine
print((newLine + 'Usage: bytes $offset $num_bytes [$file]'))
print((newLine + 'Shows or stores in the specified file $num_bytes of the file beginning from $offset' + newLine))
def do_changelog(self, argv):
if self.pdfFile is None:
......@@ -266,8 +269,8 @@ class PDFConsole(cmd.Cmd):
self.log_output('changelog ' + argv, output)
def help_changelog(self):
print newLine + 'Usage: changelog [$version]'
print newLine + 'Shows the changelog of the document or version of the document' + newLine
print((newLine + 'Usage: changelog [$version]'))
print((newLine + 'Shows the changelog of the document or version of the document' + newLine))
def do_create(self, argv):
message = ''
......@@ -307,7 +310,7 @@ class PDFConsole(cmd.Cmd):
content = open(jsFile, 'rb').read()
else:
if self.use_rawinput:
content = raw_input(
content = input(
newLine + 'Please, specify the Javascript code you want to include in the file (if the code includes EOL characters use a js_file instead):' + newLine * 2)
else:
message = '*** Error: You must specify a Javascript file in batch mode!!'
......@@ -346,7 +349,7 @@ class PDFConsole(cmd.Cmd):
return False
warning = 'Warning: stream objects cannot be compressed. If the Catalog object is compressed could lead to corrupted files for Adobe Reader!!'
if self.use_rawinput:
res = raw_input(
res = input(
warning + newLine + 'Which objects do you want to compress? (Valid respones: all | 1-5 | 1,2,5,7,8) ')
else:
res = 'all'
......@@ -354,7 +357,7 @@ class PDFConsole(cmd.Cmd):
objects = []
elif res.count('-') == 1:
limits = res.split('-')
objects = range(int(limits[0]), int(limits[1]) + 1)
objects = list(range(int(limits[0]), int(limits[1]) + 1))
elif res.find(',') != -1:
objects = [int(id) for id in res.split(',')]
elif res.isdigit():
......@@ -384,10 +387,10 @@ class PDFConsole(cmd.Cmd):
self.log_output('create ' + argv, message)
def help_create(self):
print newLine + 'Usage: create pdf simple|(open_action_js [$js_file])'
print newLine + 'Creates a new simple PDF file or one with Javascript code to be executed when opening the file. It\'s possible to specify the file where the Javascript code is stored or do it manually.' + newLine * 2
print 'Usage: create object_stream [$version]' + newLine
print 'Creates an object stream choosing the objects to be compressed.' + newLine
print((newLine + 'Usage: create pdf simple|(open_action_js [$js_file])'))
print((newLine + 'Creates a new simple PDF file or one with Javascript code to be executed when opening the file. It\'s possible to specify the file where the Javascript code is stored or do it manually.' + newLine * 2))
print(('Usage: create object_stream [$version]' + newLine))
print(('Creates an object stream choosing the objects to be compressed.' + newLine))
def do_decode(self, argv):
decodedContent = ''
......@@ -429,7 +432,7 @@ class PDFConsole(cmd.Cmd):
size = int(args[1])
for i in range(iniFilterArgs, len(args)):
filter = args[i].lower()
if filter not in filter2RealFilterDict.keys():
if filter not in list(filter2RealFilterDict.keys()):
self.help_decode()
return False
if filter in notImplementedFilters:
......@@ -487,21 +490,21 @@ class PDFConsole(cmd.Cmd):
self.log_output('decode ' + argv, decodedContent, [decodedContent], bytesOutput=True)
def help_decode(self):
print newLine + 'Usage: decode variable $var_name $filter1 [$filter2 ...]'
print 'Usage: decode file $file_name $filter1 [$filter2 ...]'
print 'Usage: decode raw $offset $num_bytes $filter1 [$filter2 ...]'
print 'Usage: decode string $encoded_string $filter1 [$filter2 ...]' + newLine
print 'Decodes the content of the specified variable, file or raw bytes using the following filters or algorithms:'
print '\tbase64,b64: Base64'
print '\tasciihex,ahx: /ASCIIHexDecode'
print '\tascii85,a85: /ASCII85Decode'
print '\tlzw: /LZWDecode'
print '\tflatedecode,fl: /FlateDecode'
print '\trunlength,rl: /RunLengthDecode'
print '\tccittfax,ccf: /CCITTFaxDecode'
print '\tjbig2: /JBIG2Decode (Not implemented)'
print '\tdct: /DCTDecode (Not implemented)'
print '\tjpx: /JPXDecode (Not implemented)' + newLine
print((newLine + 'Usage: decode variable $var_name $filter1 [$filter2 ...]'))
print ('Usage: decode file $file_name $filter1 [$filter2 ...]')
print ('Usage: decode raw $offset $num_bytes $filter1 [$filter2 ...]')
print(('Usage: decode string $encoded_string $filter1 [$filter2 ...]' + newLine))
print ('Decodes the content of the specified variable, file or raw bytes using the following filters or algorithms:')
print ('\tbase64,b64: Base64')
print ('\tasciihex,ahx: /ASCIIHexDecode')
print ('\tascii85,a85: /ASCII85Decode')
print ('\tlzw: /LZWDecode')
print ('\tflatedecode,fl: /FlateDecode')
print ('\trunlength,rl: /RunLengthDecode')
print ('\tccittfax,ccf: /CCITTFaxDecode')
print ('\tjbig2: /JBIG2Decode (Not implemented)')
print ('\tdct: /DCTDecode (Not implemented)')
print(('\tjpx: /JPXDecode (Not implemented)' + newLine))
def do_decrypt(self, argv):
if self.pdfFile is None:
......@@ -527,8 +530,8 @@ class PDFConsole(cmd.Cmd):
self.log_output('decrypt ' + argv, message)
def help_decrypt(self):
print newLine + 'Usage: decrypt $password'
print newLine + 'Decrypts the file with the specified password' + newLine
print((newLine + 'Usage: decrypt $password'))
print((newLine + 'Decrypts the file with the specified password' + newLine))
def do_embed(self, argv):
fileType = 'application#2Fpdf'
......@@ -789,10 +792,10 @@ class PDFConsole(cmd.Cmd):
self.log_output('open ' + argv, message)
def help_embed(self):
print newLine + 'Usage: embed [-x] $filename [$file_type]'
print newLine + 'Embeds the specified file in the actual PDF file. The default type is "application/pdf".' + newLine
print 'Options:'
print '\t-x: The file is executed when the actual PDF file is opened' + newLine
print((newLine + 'Usage: embed [-x] $filename [$file_type]'))
print((newLine + 'Embeds the specified file in the actual PDF file. The default type is "application/pdf".' + newLine))
print ('Options:')
print(('\t-x: The file is executed when the actual PDF file is opened' + newLine))
def do_encode(self, argv):
encodedContent = ''
......@@ -834,7 +837,7 @@ class PDFConsole(cmd.Cmd):
size = int(args[1])
for i in range(iniFilterArgs, len(args)):
filter = args[i].lower()
if filter not in filter2RealFilterDict.keys():
if filter not in list(filter2RealFilterDict.keys()):
self.help_encode()
return False
if filter in notImplementedFilters:
......@@ -887,21 +890,21 @@ class PDFConsole(cmd.Cmd):
self.log_output('encode ' + argv, encodedContent, [encodedContent], bytesOutput=True)
def help_encode(self):
print newLine + 'Usage: encode variable $var_name $filter1 [$filter2 ...]'
print 'Usage: encode file $file_name $filter1 [$filter2 ...]'
print 'Usage: encode raw $offset $num_bytes $filter1 [$filter2 ...]'
print 'Usage: encode string $my_string $filter1 [$filter2 ...]' + newLine
print 'Encodes the content of the specified variable, file or raw bytes using the following filters or algorithms:'
print '\tbase64,b64: Base64'
print '\tasciihex,ahx: /ASCIIHexDecode'
print '\tascii85,a85: /ASCII85Decode (Not implemented)'
print '\tlzw: /LZWDecode'
print '\tflatedecode,fl: /FlateDecode'
print '\trunlength,rl: /RunLengthDecode (Not implemented)'
print '\tccittfax,ccf: /CCITTFaxDecode (Not implemented)'
print '\tjbig2: /JBIG2Decode (Not implemented)'
print '\tdct: /DCTDecode (Not implemented)'
print '\tjpx: /JPXDecode (Not implemented)' + newLine
print((newLine + 'Usage: encode variable $var_name $filter1 [$filter2 ...]'))
print ('Usage: encode file $file_name $filter1 [$filter2 ...]')
print ('Usage: encode raw $offset $num_bytes $filter1 [$filter2 ...]')
print(('Usage: encode string $my_string $filter1 [$filter2 ...]' + newLine))
print ('Encodes the content of the specified variable, file or raw bytes using the following filters or algorithms:')
print ('\tbase64,b64: Base64')
print ('\tasciihex,ahx: /ASCIIHexDecode')
print ('\tascii85,a85: /ASCII85Decode (Not implemented)')
print ('\tlzw: /LZWDecode')
print ('\tflatedecode,fl: /FlateDecode')
print ('\trunlength,rl: /RunLengthDecode (Not implemented)')
print ('\tccittfax,ccf: /CCITTFaxDecode (Not implemented)')
print ('\tjbig2: /JBIG2Decode (Not implemented)')
print ('\tdct: /DCTDecode (Not implemented)')
print(('\tjpx: /JPXDecode (Not implemented)' + newLine))
def do_encode_strings(self, argv):
if self.pdfFile is None:
......@@ -981,8 +984,8 @@ class PDFConsole(cmd.Cmd):
self.log_output('encode_strings ' + argv, message)
def help_encode_strings(self):
print newLine + 'Usage: encode_strings [$object_id|trailer [$version]]'
print newLine + 'Encodes the strings and names included in the file, object or trailer' + newLine
print((newLine + 'Usage: encode_strings [$object_id|trailer [$version]]'))
print((newLine + 'Encodes the strings and names included in the file, object or trailer' + newLine))
def do_encrypt(self, argv):
if self.pdfFile is None:
......@@ -1010,8 +1013,8 @@ class PDFConsole(cmd.Cmd):
self.log_output('encrypt ' + argv, message)
def help_encrypt(self):
print newLine + 'Usage: encrypt [$password]'
print newLine + 'Encrypts the file with the default or specified password' + newLine
print((newLine + 'Usage: encrypt [$password]'))
print((newLine + 'Encrypts the file with the default or specified password' + newLine))
def do_errors(self, argv):
if self.pdfFile is None:
......@@ -1096,15 +1099,15 @@ class PDFConsole(cmd.Cmd):
self.log_output('errors ' + argv, errors)
def help_errors(self):
print newLine + 'Usage: errors [$object_id|xref|trailer [$version]]'
print newLine + 'Shows the errors of the file or object (object_id, xref, trailer)' + newLine
print((newLine + 'Usage: errors [$object_id|xref|trailer [$version]]'))
print((newLine + 'Shows the errors of the file or object (object_id, xref, trailer)' + newLine))
def do_exit(self, argv):
return True
def help_exit(self):
print newLine + 'Usage: exit'
print newLine + 'Exits from the console' + newLine
print((newLine + 'Usage: exit'))
print((newLine + 'Exits from the console' + newLine))
def do_extract(self, argv):
validTypes = ['uri', 'js']
......@@ -1158,8 +1161,8 @@ class PDFConsole(cmd.Cmd):
self.log_output('extract ' + argv, output)
def help_extract(self):
print newLine + 'Usage: extract uri|js [$version]'
print newLine + 'Extracts all the given type elements of the specified version after being decoded and decrypted (if necessary)' + newLine
print((newLine + 'Usage: extract uri|js [$version]'))
print((newLine + 'Extracts all the given type elements of the specified version after being decoded and decrypted (if necessary)' + newLine))
def do_filters(self, argv):
if self.pdfFile is None:
......@@ -1188,7 +1191,7 @@ class PDFConsole(cmd.Cmd):
iniFilterArgs = 2
else:
version = None
validFilters = filter2RealFilterDict.keys() + ['none']
validFilters = list(filter2RealFilterDict.keys()) + ['none']
validFilters.remove('b64')
validFilters.remove('base64')
for i in range(iniFilterArgs, len(args)):
......@@ -1278,18 +1281,18 @@ class PDFConsole(cmd.Cmd):
self.log_output('filters ' + argv, message + value, [value], bytesOutput=True)
def help_filters(self):
print newLine + 'Usage: filters $object_id [$version] [$filter1 [$filter2 ...]]'
print newLine + 'Shows the filters found in the stream object or set the filters in the object (first filter is used first). The valid values for filters are the following:'
print '\tnone: No filters'
print '\tasciihex,ahx: /ASCIIHexDecode'
print '\tascii85,a85: /ASCII85Decode (Not implemented)'
print '\tlzw: /LZWDecode'
print '\tflatedecode,fl: /FlateDecode'
print '\trunlength,rl: /RunLengthDecode (Not implemented)'
print '\tccittfax,ccf: /CCITTFaxDecode (Not implemented)'
print '\tjbig2: /JBIG2Decode (Not implemented)'
print '\tdct: /DCTDecode (Not implemented)'
print '\tjpx: /JPXDecode (Not implemented)' + newLine
print((newLine + 'Usage: filters $object_id [$version] [$filter1 [$filter2 ...]]'))
print((newLine + 'Shows the filters found in the stream object or set the filters in the object (first filter is used first). The valid values for filters are the following:'))
print ('\tnone: No filters')
print ('\tasciihex,ahx: /ASCIIHexDecode')
print ('\tascii85,a85: /ASCII85Decode (Not implemented)')
print ('\tlzw: /LZWDecode')
print ('\tflatedecode,fl: /FlateDecode')
print ('\trunlength,rl: /RunLengthDecode (Not implemented)')
print ('\tccittfax,ccf: /CCITTFaxDecode (Not implemented)')
print ('\tjbig2: /JBIG2Decode (Not implemented)')
print ('\tdct: /DCTDecode (Not implemented)')
print(('\tjpx: /JPXDecode (Not implemented)' + newLine))
def do_hash(self, argv):
content = ''
......@@ -1397,16 +1400,16 @@ class PDFConsole(cmd.Cmd):
self.log_output('hash ' + argv, output)
def help_hash(self):
print newLine + 'Usage: hash object|rawobject|stream|rawstream $object_id [$version]'
print 'Usage: hash raw $offset $num_bytes'
print 'Usage: hash file $file_name'
print 'Usage: hash variable $var_name'
print 'Usage: hash string $my_string'
print newLine + 'Generates the hash (MD5/SHA1/SHA256) of the specified source: raw bytes of the file, objects and streams, and the content of files or variables' + newLine
print((newLine + 'Usage: hash object|rawobject|stream|rawstream $object_id [$version]'))
print ('Usage: hash raw $offset $num_bytes')
print ('Usage: hash file $file_name')
print ('Usage: hash variable $var_name')
print ('Usage: hash string $my_string')
print((newLine + 'Generates the hash (MD5/SHA1/SHA256) of the specified source: raw bytes of the file, objects and streams, and the content of files or variables' + newLine))
def help_help(self):
print newLine + 'Usage: help [$command]'
print newLine + 'Shows the available commands or the usage of the specified command' + newLine
print((newLine + 'Usage: help [$command]'))
print((newLine + 'Shows the available commands or the usage of the specified command' + newLine))
def do_info(self, argv):
if self.pdfFile is None:
......@@ -1737,8 +1740,8 @@ class PDFConsole(cmd.Cmd):
self.log_output('info ' + argv, stats)
def help_info(self):
print newLine + 'Usage: info [$object_id|xref|trailer [$version]]'
print newLine + 'Shows information of the file or object ($object_id, xref, trailer)' + newLine
print((newLine + 'Usage: info [$object_id|xref|trailer [$version]]'))
print((newLine + 'Shows information of the file or object ($object_id, xref, trailer)' + newLine))
def do_js_analyse(self, argv):
content = ''
......@@ -1773,13 +1776,13 @@ class PDFConsole(cmd.Cmd):
content = self.variables[src][0]
if not isJavascript(content):
if self.use_rawinput:
res = raw_input('The variable may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The variable may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The variable does not contain Javascript code!!'
self.log_output('js_analyse ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
elif type == 'file':
if not os.path.exists(src):
message = '*** Error: The file does not exist!!'
......@@ -1789,13 +1792,13 @@ class PDFConsole(cmd.Cmd):
content = open(src, 'rb').read()
if not isJavascript(content):
if self.use_rawinput:
res = raw_input('The file may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The file may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The file does not contain Javascript code!!'
self.log_output('js_analyse ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
elif type == 'object':
if self.pdfFile is None:
message = '*** Error: You must open a file!!'
......@@ -1817,13 +1820,13 @@ class PDFConsole(cmd.Cmd):
content = object.getJSCode()[0]
else:
if self.use_rawinput:
res = raw_input('The object may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The object may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The object does not contain Javascript code!!'
self.log_output('js_analyse ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
objectType = object.getType()
if objectType == 'stream':
content = object.getStream()
......@@ -1877,11 +1880,11 @@ class PDFConsole(cmd.Cmd):
self.log_output('js_analyse ' + argv, jsanalyseOutput, unescapedBytes)
def help_js_analyse(self):
print newLine + 'Usage: js_analyse variable $var_name'
print 'Usage: js_analyse file $file_name'
print 'Usage: js_analyse object $object_id [$version]'
print 'Usage: js_analyse string $javascript_code'
print newLine + 'Analyses the Javascript code stored in the specified string, variable, file or object' + newLine
print((newLine + 'Usage: js_analyse variable $var_name'))
print ('Usage: js_analyse file $file_name')
print ('Usage: js_analyse object $object_id [$version]')
print ('Usage: js_analyse string $javascript_code')
print((newLine + 'Analyses the Javascript code stored in the specified string, variable, file or object' + newLine))
def do_js_beautify(self, argv):
content = ''
......@@ -1912,13 +1915,13 @@ class PDFConsole(cmd.Cmd):
content = self.variables[src][0]
if not isJavascript(content):
if self.use_rawinput:
res = raw_input('The variable may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The variable may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The variable does not contain Javascript code!!'
self.log_output('js_beautify ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
elif type == 'file':
if not os.path.exists(src):
message = '*** Error: The file does not exist!!'
......@@ -1928,13 +1931,13 @@ class PDFConsole(cmd.Cmd):
content = open(src, 'rb').read()
if not isJavascript(content):
if self.use_rawinput:
res = raw_input('The file may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The file may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The file does not contain Javascript code!!'
self.log_output('js_beautify ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
elif type == 'string':
content = src
else:
......@@ -1958,13 +1961,13 @@ class PDFConsole(cmd.Cmd):
content = object.getJSCode()[0]
else:
if self.use_rawinput:
res = raw_input('The object may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The object may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The object does not contain Javascript code!!'
self.log_output('js_beautify ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
objectType = object.getType()
if objectType == 'stream':
content = object.getStream()
......@@ -1991,11 +1994,11 @@ class PDFConsole(cmd.Cmd):
self.log_output('js_beautify ' + argv, beautyContent)
def help_js_beautify(self):
print newLine + 'Usage: js_beautify variable $var_name'
print 'Usage: js_beautify file $file_name'
print 'Usage: js_beautify object $object_id [$version]'
print 'Usage: js_beautify string $javascript_code [$version]'
print newLine + 'Beautifies the Javascript code stored in the specified variable, file or object' + newLine
print((newLine + 'Usage: js_beautify variable $var_name'))
print ('Usage: js_beautify file $file_name')
print ('Usage: js_beautify object $object_id [$version]')
print ('Usage: js_beautify string $javascript_code [$version]')
print((newLine + 'Beautifies the Javascript code stored in the specified variable, file or object' + newLine))
def do_js_code(self, argv):
if self.pdfFile is None:
......@@ -2035,7 +2038,7 @@ class PDFConsole(cmd.Cmd):
jsCode = object.getJSCode()
if len(jsCode) > 1:
if self.use_rawinput:
res = raw_input(
res = input(
newLine + 'There are more than one Javascript code, do you want to see all (1) or just the last one (2)? ')
else:
res = '1'
......@@ -2058,8 +2061,8 @@ class PDFConsole(cmd.Cmd):
self.log_output('js_code ' + argv, message)
def help_js_code(self):
print newLine + 'Usage: js_code $object_id [$version]'
print newLine + 'Shows the Javascript code found in the object' + newLine
print((newLine + 'Usage: js_code $object_id [$version]'))
print((newLine + 'Shows the Javascript code found in the object' + newLine))
def do_js_eval(self, argv):
error = ''
......@@ -2095,13 +2098,13 @@ class PDFConsole(cmd.Cmd):
content = self.variables[src][0]
if not isJavascript(content):
if self.use_rawinput:
res = raw_input('The variable may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The variable may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The variable does not contain Javascript code!!'
self.log_output('js_eval ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
elif type == 'file':
if not os.path.exists(src):
message = '*** Error: The file does not exist!!'
......@@ -2111,13 +2114,13 @@ class PDFConsole(cmd.Cmd):
content = open(src, 'rb').read()
if not isJavascript(content):
if self.use_rawinput:
res = raw_input('The file may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The file may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The file does not contain Javascript code!!'
self.log_output('js_eval ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
elif type == 'object':
if self.pdfFile is None:
message = '*** Error: You must open a file!!'
......@@ -2139,13 +2142,13 @@ class PDFConsole(cmd.Cmd):
content = object.getJSCode()[0]
else:
if self.use_rawinput:
res = raw_input('The object may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The object may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The object does not contain Javascript code!!'
self.log_output('js_eval ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
objectType = object.getType()
if objectType == 'stream':
content = object.getStream()
......@@ -2195,11 +2198,11 @@ class PDFConsole(cmd.Cmd):
self.log_output('js_eval ' + argv, '*** Error: ' + error)
def help_js_eval(self):
print newLine + 'Usage: js_eval variable $var_name'
print 'Usage: js_eval file $file_name'
print 'Usage: js_eval object $object_id [$version]'
print 'Usage: js_eval string $javascript_code'
print newLine + 'Evaluates the Javascript code stored in the specified variable, file, object or raw code in a global context' + newLine
print((newLine + 'Usage: js_eval variable $var_name'))
print ('Usage: js_eval file $file_name')
print ('Usage: js_eval object $object_id [$version]')
print ('Usage: js_eval string $javascript_code')
print((newLine + 'Evaluates the Javascript code stored in the specified variable, file, object or raw code in a global context' + newLine))
def do_js_jjdecode(self, argv):
content = ''
......@@ -2230,13 +2233,13 @@ class PDFConsole(cmd.Cmd):
content = self.variables[src][0]
if not isJavascript(content):
if self.use_rawinput:
res = raw_input('The variable may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The variable may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The variable does not contain Javascript code!!'
self.log_output('js_jjdecode ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
elif type == 'file':
if not os.path.exists(src):
message = '*** Error: The file does not exist!!'
......@@ -2246,13 +2249,13 @@ class PDFConsole(cmd.Cmd):
content = open(src, 'rb').read()
if not isJavascript(content):
if self.use_rawinput:
res = raw_input('The file may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The file may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The file does not contain Javascript code!!'
self.log_output('js_jjdecode ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
elif type == 'string':
content = src
else:
......@@ -2276,13 +2279,13 @@ class PDFConsole(cmd.Cmd):
content = object.getJSCode()[0]
else:
if self.use_rawinput:
res = raw_input('The object may not contain Javascript code, do you want to continue? (y/n) ')
res = input('The object may not contain Javascript code, do you want to continue? (y/n) ')
if res.lower() == 'n':
message = '*** Error: The object does not contain Javascript code!!'
self.log_output('js_jjdecode ' + argv, message)
return False
else:
print 'Warning: the object may not contain Javascript code...' + newLine
print(('Warning: the object may not contain Javascript code...' + newLine))
objectType = object.getType()
if objectType == 'stream':
content = object.getStream()
......@@ -2328,11 +2331,11 @@ class PDFConsole(cmd.Cmd):
self.log_output('js_jjdecode ' + argv, decodedContent)
def help_js_jjdecode(self):
print newLine + 'Usage: js_jjdecode variable $var_name'
print 'Usage: js_jjdecode file $file_name'
print 'Usage: js_jjdecode object $object_id [$version]'
print 'Usage: js_jjdecode string $encoded_js_code [$version]'
print newLine + 'Decodes the Javascript code stored in the specified variable, file or object using the jjencode/decode algorithm by Yosuke Hasegawa (http://utf-8.jp/public/jjencode.html)' + newLine
print((newLine + 'Usage: js_jjdecode variable $var_name'))
print ('Usage: js_jjdecode file $file_name')
print ('Usage: js_jjdecode object $object_id [$version]')
print ('Usage: js_jjdecode string $encoded_js_code [$version]')
print((newLine + 'Decodes the Javascript code stored in the specified variable, file or object using the jjencode/decode algorithm by Yosuke Hasegawa (http://utf-8.jp/public/jjencode.html)' + newLine))
def do_js_join(self, argv):