diff --git a/JSAnalysis.py b/JSAnalysis.py index 79fce91..ddaf7e6 100644 --- a/JSAnalysis.py +++ b/JSAnalysis.py @@ -176,14 +176,13 @@ def isJavascript(content): @param content: A string @return: A boolean, True if it seems to contain Javascript code or False in the other case ''' - jsStrings = ['var ', ';', ')', '(', 'function ', '=', '{', '}', 'if ', 'else', 'return', 'while ', 'for ', + jsStrings = ['var ', ';', ')', '(', 'function ', '=', '{', '}', 'if(', 'if (', 'else{', 'else {','else if', 'return', 'while(', 'while (', 'for(', 'for (', ',', 'eval'] keyStrings = [';', '(', ')'] - reVarInit = 'var [\w0-9]+\s*?=' - reFunctionCall = '[\w0-9]+\s*?\(.*?\)\s*?;' stringsFound = [] limit = 15 - minDistinctStringsFound = 4 + #JS should at least contain ';', ')', '(', 'var', '=' + minDistinctStringsFound = 5 minRatio = 10 results = 0 length = len(content) @@ -279,4 +278,4 @@ def unescape(escapedBytes, unicode = True): unescapedBytes = escapedBytes except: return (-1, 'Error while unescaping the bytes') - return (0, unescapedBytes) \ No newline at end of file + return (0, unescapedBytes) diff --git a/PDFCore.py b/PDFCore.py index 3b2fe00..11a2d35 100644 --- a/PDFCore.py +++ b/PDFCore.py @@ -4448,7 +4448,6 @@ def updateStats(self, id, pdfObject, delete=False): return (0,'') - class PDFTrailer : def __init__(self, dict, lastCrossRefSection = '0', streamPresent = False): self.errors = [] @@ -6210,6 +6209,7 @@ def getStats (self): containingURIs = self.body[version].getContainingURIs() if len(containingURIs) > 0: statsVersion['URIs'] = [str(len(containingURIs)), containingURIs] + statsVersion['URIDisplay'] = set(self.getURIs(version=version)[0]) #only get unique URIs else: statsVersion['URIs'] = None containingJS = self.body[version].getContainingJS() @@ -6840,6 +6840,7 @@ def parse (self, fileName, forceMode = False, looseMode = False, manualAnalysis @param fileName The name of the file to be parsed @param forceMode Boolean to specify if ignore errors or not. Default value: False. @param looseMode Boolean to set the loose mode when parsing objects. Default value: False. + @param manualAnalysis Boolean to specify whether JS analysis is performed. Default value: False. @return A PDFFile instance ''' global isForceMode, pdfFile, isManualAnalysis @@ -6928,6 +6929,7 @@ def parse (self, fileName, forceMode = False, looseMode = False, manualAnalysis # Getting the number of updates in the file while fileContent.find('%%EOF') != -1: + self.readUntilSymbol(fileContent, '%%EOF') self.readUntilEndOfLine(fileContent) self.fileParts.append(fileContent[:self.charCounter]) @@ -6995,12 +6997,15 @@ def parse (self, fileName, forceMode = False, looseMode = False, manualAnalysis # Converting the body content in PDFObjects body = PDFBody() + # search for objects e.g. 10 0 obj rawIndirectObjects = self.getIndirectObjects(bodyContent, looseMode) if rawIndirectObjects != []: for j in range(len(rawIndirectObjects)): relativeOffset = 0 auxContent = str(bodyContent) + #raw content of object rawObject = rawIndirectObjects[j][0] + #object header e.g. 10 0 obj objectHeader = rawIndirectObjects[j][1] while True: index = auxContent.find(objectHeader) @@ -7014,6 +7019,7 @@ def parse (self, fileName, forceMode = False, looseMode = False, manualAnalysis else: auxContent = auxContent[index+len(objectHeader):] relativeOffset += len(objectHeader) + #find object in rawObject ret = self.createPDFIndirectObject(rawObject, forceMode, looseMode) if ret[0] != -1: pdfIndirectObject = ret[1] @@ -7345,6 +7351,7 @@ def createPDFStream(self, dict, stream): elements = {} rawNames = {} ret = self.readObject(dict[self.charCounter:], 'name') + if ret[0] == -1: if ret[1] != 'Empty content reading object': if isForceMode: @@ -7356,6 +7363,7 @@ def createPDFStream(self, dict, stream): name = None else: name = ret[1] + while name != None: key = name.getValue() rawNames[key] = name @@ -7384,6 +7392,7 @@ def createPDFStream(self, dict, stream): name = None else: name = ret[1] + if elements.has_key('/Type') and elements['/Type'].getValue() == '/ObjStm': try: pdfStream = PDFObjectStream(dict, stream, elements, rawNames, {}) @@ -7400,6 +7409,7 @@ def createPDFStream(self, dict, stream): if e.message != '': errorMessage += ': '+e.message return (-1, errorMessage) + self.charCounter = realCounter return (0,pdfStream) diff --git a/peepdf.py b/peepdf.py index 7c162db..1dabd7f 100755 --- a/peepdf.py +++ b/peepdf.py @@ -664,6 +664,11 @@ def getPeepJSON(statsDict, version, revision): if statsVersion['URIs'] is not None: stats += newLine + beforeStaticLabel + '\tObjects with URIs (' + \ statsVersion['URIs'][0] + '): ' + resetColor + str(statsVersion['URIs'][1]) + stats += newLine + beforeStaticLabel + '\tFound URIs : ' + resetColor + for display in statsVersion['URIDisplay']: + display=str(display) + if "http" in display.lower(): + stats += newLine + beforeStaticLabel + '\t\t' + resetColor + display if COLORIZED_OUTPUT and not options.avoidColors: beforeStaticLabel = warningColor if statsVersion['Objects with JS code'] != None: