def getVarContent(jsCode, varContent): clearBytes = '' replicas = ['\n', '\r', '\t', ' '] for v in replicas: varContent = varContent.replace(v, '') parts = varContent.split('+') for part in parts: if re.match('["\'].*?["\']', part, re.DOTALL): clearBytes += part[1:-1] else: part = escapeString(part) varContent = re.findall(part + '\s*?=\s*?(.*?)[,;]', jsCode, re.DOTALL) if varContent: clearBytes += getVarContent(jsCode, varContent[0]) return clearBytes
def getVarContent(jsCode, varContent): ''' Given the Javascript code and the content of a variable this method tries to obtain the real value of the variable, cleaning expressions like "a = eval; a(js_code);" @param jsCode: The Javascript code (string) @param varContent: The content of the variable (string) @return: A string with real value of the variable ''' clearBytes = '' varContent = varContent.replace('\n', '') varContent = varContent.replace('\r', '') varContent = varContent.replace('\t', '') varContent = varContent.replace(' ', '') parts = varContent.split('+') for part in parts: if re.match('["\'].*?["\']', part, re.DOTALL): clearBytes += part[1:-1] else: part = escapeString(part) varContent = re.findall(part + '\s*?=\s*?(.*?)[,;]', jsCode, re.DOTALL) if varContent != []: clearBytes += getVarContent(jsCode, varContent[0]) return clearBytes
def getVarContent(jsCode, varContent): """ Given the Javascript code and the content of a variable this method tries to obtain the real value of the variable, cleaning expressions like "a = eval; a(js_code);" @param jsCode: The Javascript code (string) @param varContent: The content of the variable (string) @return: A string with real value of the variable """ clearBytes = "" varContent = varContent.replace("\n", "") varContent = varContent.replace("\r", "") varContent = varContent.replace("\t", "") varContent = varContent.replace(" ", "") parts = varContent.split("+") for part in parts: if re.match("[\"'].*?[\"']", part, re.DOTALL): clearBytes += part[1:-1] else: part = escapeString(part) varContent = re.findall(part + "\s*?=\s*?(.*?)[,;]", jsCode, re.DOTALL) if varContent != []: clearBytes += getVarContent(jsCode, varContent[0]) return clearBytes
def getVarContent(jsCode, varContent): """ Given the Javascript code and the content of a variable this method tries to obtain the real value of the variable, cleaning expressions like "a = eval; a(js_code);" @param jsCode: The Javascript code (string) @param varContent: The content of the variable (string) @return: A string with real value of the variable """ clearBytes = "" varContent = varContent.replace("\n", "") varContent = varContent.replace("\r", "") varContent = varContent.replace("\t", "") varContent = varContent.replace(" ", "") parts = varContent.split("+") for part in parts: if re.match("[\"'].*?[\"']", part, re.DOTALL): clearBytes += part[1:-1] else: part = escapeString(part) varContent = re.findall(part + "\s*?=\s*?(.*?)[,;]", jsCode, re.DOTALL) if varContent: clearBytes += getVarContent(jsCode, varContent[0]) return clearBytes