diff --git a/binhop.py b/binhop.py index ec0b9e7..ccd6435 100644 --- a/binhop.py +++ b/binhop.py @@ -8,9 +8,10 @@ import binwalk import os from aiohttp_compress import compress_middleware from aiohttp import web +from typing import List, Tuple, Dict, Union -async def scan_file(filename, base_dir): +async def scan_file(filename: str, base_dir: str) -> List: try: scan = binwalk.scan( filename, @@ -26,7 +27,7 @@ async def scan_file(filename, base_dir): print("Critical failure: ", e) -async def build_listing(path): +async def build_listing(path: str) -> Tuple[int, int, Dict]: result = {} num_files, num_dirs = 0, 0 for item in os.listdir(path): @@ -41,7 +42,7 @@ async def build_listing(path): return num_files, num_dirs, result -async def upload_file(request): +async def upload_file(request: web.Request) -> web.json_response: reader = await request.multipart() field = await reader.next() assert field.name == "file" @@ -119,18 +120,18 @@ async def upload_file(request): return web.json_response(response_data) -async def serve_index(request): +async def serve_index(request: web.Request) -> web.FileResponse: return web.FileResponse("index.html") -async def serve_static(request): +async def serve_static(request: web.Request) -> Union[web.FileResponse, web.HTTPNotFound]: path = request.path[1:] if not path.startswith("static/"): return web.HTTPNotFound() return web.FileResponse(path) -async def main(): +async def main() -> None: app = web.Application() app.middlewares.append(compress_middleware) diff --git a/static/binhop.js b/static/binhop.js index 3718889..46c58d0 100644 --- a/static/binhop.js +++ b/static/binhop.js @@ -209,14 +209,10 @@ async function process_upload(file) { }); if (response.ok) { - // if (1 === 1) { const data = await response.json(); - // const json = '{"meta":{"name":"miwifi_r4av2_firmware_6bdd4_2.30.500.bin","sizeb":13632488,"sha1":"6cefd9d5de3b80799d0341b19043d108624dcaca","md5":"639616a5b70983903ccdd019a7a6bdd4","sig_quant":411,"duration":"00:05.457"},"offsets":[{"start":960,"end":13630770,"d":"LZMA compressed data"},{"start":1704660,"end":13621866,"d":"Squashfs filesystem"},{"start":4534008,"end":5267984,"d":"xz compressed data"},{"start":5258380,"end":5267984,"d":"ASCII cpio archive"}]}'; - // const data = JSON.parse(json); const container = document.querySelector('.container'); - - // visualization + container.innerHTML = `