diff --git a/examples/angularview/angularview.py b/examples/angularview/angularview.py index 25f42da..56476b9 100644 --- a/examples/angularview/angularview.py +++ b/examples/angularview/angularview.py @@ -2,50 +2,37 @@ import logging import pygments from voltron.plugin import * from voltron.lexers import * +from voltron.api import * from flask import * log = logging.getLogger('api') -app = Flask(__name__) - -lexers = { - 'lldb_intel': LLDBIntelLexer -} - -@app.route('/') -def root(): - return redirect("static", code=302) - - -@app.route("/api/request", methods=['POST']) -def handle_post(): - res = app.server.handle_request(request.data.decode('UTF-8')) - res.formatted = format_disasm(res) - return Response(str(res), status=200, mimetype='application/json') - - -def format_disasm(response): - """ - Format - """ - formatted = None - - try: - lexer_id = '{}_{}'.format(response.host, response.flavor) - log.debug("lexer: {}".format(lexer_id)) - lexer = lexers[lexer_id]() - except: - lexer = None - - if lexer: - formatted = pygments.highlight(response.disassembly.strip(), lexer, pygments.formatters.HtmlFormatter()) - - log.debug(formatted) - - return formatted - class AngularViewPlugin(WebPlugin): name = 'angularview' - app = app + + +class FormatDisassemblyRequest(APIRequest): + _fields = {'disassembly': True} + + def dispatch(self): + try: + res = FormatDisassemblyResponse( + disassembly=pygments.highlight(self.disassembly.strip(), LLDBIntelLexer(), pygments.formatters.HtmlFormatter())) + except Exception as e: + msg = "Exception formatting disassembly: {}".format(e) + log.exception(msg) + res = APIGenericErrorResponse(msg) + + return res + + +class FormatDisassemblyResponse(APIResponse): + _fields = {'disassembly': True} + + +class FormatDisassemblyPlugin(APIPlugin): + request = "format_disasm" + request_class = FormatDisassemblyRequest + response_class = FormatDisassemblyResponse diff --git a/examples/angularview/static/js/services.js b/examples/angularview/static/js/services.js index 190092c..145e60a 100644 --- a/examples/angularview/static/js/services.js +++ b/examples/angularview/static/js/services.js @@ -15,14 +15,19 @@ factory('voltronAPIservice', function($http) }); } - voltronAPI.disassemble = function(address, count) { + voltronAPI.disassemble_format = function(data) { + res = voltronAPI.request(createRequest('disassemble', {address: address, count: count})) return $http({ method: 'POST', - url: '../api/request', - data: createRequest('disassemble', {address: address, count: count}) + url: '/api/request', + data: createRequest('format_disasm', {disassembly: res.data.disassembly}) }); } + voltronAPI.disassemble = function(address, count) { + return voltronAPI.request(createRequest('disassemble', {address: address, count: count})) + } + voltronAPI.command = function(command) { return voltronAPI.request(createRequest('command', {command: command})) } @@ -51,13 +56,5 @@ factory('voltronAPIservice', function($http) return voltronAPI.request(createRequest('version', {})) } - voltronAPI.wait = function(timeout) { - // return voltronAPI.request(createRequest('wait', {timeout: timeout})) - return $http({ - method: 'GET', - url: '/api/wait?timeout='+timeout - }); - } - return voltronAPI; });