Skip to content

Commit

Permalink
unicode fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinabraham committed Nov 25, 2016
1 parent 39fec36 commit ce196f7
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions StaticAnalyzer/views/shared_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import zipfile
import subprocess
import platform
import errno

from django.http import HttpResponseRedirect
from django.http import HttpResponse
Expand Down Expand Up @@ -68,8 +69,19 @@ def Unzip(APP_PATH, EXT_PATH):
try:
files = []
with zipfile.ZipFile(APP_PATH, "r") as z:
z.extractall(EXT_PATH)
files = z.namelist()
for fileinfo in z.infolist():
dat = z.open(fileinfo.filename, "r")
filename = unicode(fileinfo.filename, encoding="utf-8", errors="ignore")
outfile = os.path.join(EXT_PATH, filename)
if not os.path.exists(os.path.dirname(outfile)):
try:
os.makedirs(os.path.dirname(outfile))
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
print "\n[WARN] OS Error: Race Condition"
with io.open(outfile, mode='wb') as f:
f.write(dat.read())
dat.close()
return files
except:
PrintException("[ERROR] Unzipping Error")
Expand Down Expand Up @@ -210,38 +222,39 @@ def PDF(request):
else:
return HttpResponse(json.dumps({"report": "Report not Found"}),
content_type="application/json; charset=utf-8")
elif re.findall('APPX',TYP):
elif re.findall('APPX', TYP):
if TYP == 'APPX':
db_entry = StaticAnalyzerWindows.objects.filter( # pylint: disable-msg=E1101
db_entry = StaticAnalyzerWindows.objects.filter( # pylint: disable-msg=E1101
MD5=MD5
)
if db_entry.exists():
print "\n[INFO] Fetching data from DB for PDF Report Generation (APPX)"
context = {
'title' : db_entry[0].TITLE,
'name' : db_entry[0].APP_NAME,
'pub_name' : db_entry[0].PUB_NAME,
'size' : db_entry[0].SIZE,
'title': db_entry[0].TITLE,
'name': db_entry[0].APP_NAME,
'pub_name': db_entry[0].PUB_NAME,
'size': db_entry[0].SIZE,
'md5': db_entry[0].MD5,
'sha1' : db_entry[0].SHA1,
'sha256' : db_entry[0].SHA256,
'bin_name' : db_entry[0].BINNAME,
'version' : db_entry[0].VERSION,
'arch' : db_entry[0].ARCH,
'compiler_version' : db_entry[0].COMPILER_VERSION,
'visual_studio_version' : db_entry[0].VISUAL_STUDIO_VERSION,
'visual_studio_edition' : db_entry[0].VISUAL_STUDIO_EDITION,
'target_os' : db_entry[0].TARGET_OS,
'appx_dll_version' : db_entry[0].APPX_DLL_VERSION,
'proj_guid' : db_entry[0].PROJ_GUID,
'opti_tool' : db_entry[0].OPTI_TOOL,
'target_run' : db_entry[0].TARGET_RUN,
'files' : python_list(db_entry[0].FILES),
'strings' : db_entry[0].STRINGS,
'bin_an_results' : python_list(db_entry[0].BIN_AN_RESULTS),
'bin_an_warnings' : python_list(db_entry[0].BIN_AN_WARNINGS)
'sha1': db_entry[0].SHA1,
'sha256': db_entry[0].SHA256,
'bin_name': db_entry[0].BINNAME,
'version': db_entry[0].VERSION,
'arch': db_entry[0].ARCH,
'compiler_version': db_entry[0].COMPILER_VERSION,
'visual_studio_version': db_entry[0].VISUAL_STUDIO_VERSION,
'visual_studio_edition': db_entry[0].VISUAL_STUDIO_EDITION,
'target_os': db_entry[0].TARGET_OS,
'appx_dll_version': db_entry[0].APPX_DLL_VERSION,
'proj_guid': db_entry[0].PROJ_GUID,
'opti_tool': db_entry[0].OPTI_TOOL,
'target_run': db_entry[0].TARGET_RUN,
'files': python_list(db_entry[0].FILES),
'strings': db_entry[0].STRINGS,
'bin_an_results': python_list(db_entry[0].BIN_AN_RESULTS),
'bin_an_warnings': python_list(db_entry[0].BIN_AN_WARNINGS)
}
template= get_template("windows_binary_analysis_pdf.html")
template = get_template(
"windows_binary_analysis_pdf.html")
else:
return HttpResponse(json.dumps({"type": "Type is not Allowed"}),
content_type="application/json; charset=utf-8")
Expand Down

0 comments on commit ce196f7

Please sign in to comment.