Beispiel #1
0
    def __exec_data(self, args):
        if self.gctx.dis is None:
            error("load a file before")
            return
        nb_lines = self.gctx.nb_lines
        if len(args) <= 1:
            self.gctx.entry = None
            error("no address in parameter")
            return

        if len(args) == 3:
            try:
                nb_lines = int(args[2])
            except:
                pass

        ctx = self.gctx.get_addr_context(args[1])
        if ctx:
            if args[0] == "da":
                self.gctx.dis.dump_data_ascii(ctx, nb_lines)
            elif args[0] == "db":
                self.gctx.dis.dump_data(ctx, nb_lines, 1)
            elif args[0] == "dw":
                self.gctx.dis.dump_data(ctx, nb_lines, 2)
            elif args[0] == "dd":
                self.gctx.dis.dump_data(ctx, nb_lines, 4)
            elif args[0] == "dq":
                self.gctx.dis.dump_data(ctx, nb_lines, 8)
Beispiel #2
0
 def inner(user, *args, **kwargs):
     user_permissions = current_app.mdb.user_permissions.find_one({"id": user.id})
     if user_permissions is None:
         return error(403, "User has no permissions")
     elif not all(user_permissions.get(p) for p in required_permissions):
         return error(403, f"Missing one or more permissions: {required_permissions!r}")
     return func(user, *args, **kwargs)
Beispiel #3
0
 def __exec_data(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     lines = self.ctx.lines
     if len(args) <= 1:
         self.ctx.entry = None
         error("no address in parameter")
         return
     self.ctx.entry = args[1]
     if len(args) == 3:
         lines = int(args[2])
     self.ctx.print_data = True
     if init_entry_addr(self.ctx):
         if args[0] == "da":
             self.ctx.dis.dump_data_ascii(self.ctx, lines)
         elif args[0] == "db":
             self.ctx.dis.dump_data(self.ctx, lines, 1)
         elif args[0] == "dw":
             self.ctx.dis.dump_data(self.ctx, lines, 2)
         elif args[0] == "dd":
             self.ctx.dis.dump_data(self.ctx, lines, 4)
         elif args[0] == "dq":
             self.ctx.dis.dump_data(self.ctx, lines, 8)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
         self.ctx.print_data = False
Beispiel #4
0
def disasm(ctx):
    ctx.gph = ctx.dis.get_graph(ctx.entry_addr)
    if ctx.gph == None:
        error("capstone can't disassemble here")
        return
    ctx.gph.graph_init(ctx)
    
    if ctx.graph:
        ctx.gph.html_graph()

    try:
        ast = generate_ast(ctx)
    except ExcIfelse as e:
        error("can't have a ifelse here     %x" % e.addr)
        if ctx.interactive:
            return
        die()

    if ctx.vim:
        base = os.path.basename(ctx.filename) + "_" + ctx.entry
        # re-assign if no colors
        ctx.libarch.process_ast.assign_colors(ctx, ast)
        ctx.color = False
        generate_vim_syntax(ctx, base + ".vim")
        sys.stdout = open(base + ".rev", "w+")

    o = ctx.libarch.output.Output(ctx)
    o.print_ast(ctx.entry_addr, ast)

    if ctx.vim:
        print("Run :  vim {0}.rev -S {0}.vim".format(base), file=sys.stderr)
Beispiel #5
0
    def __exec_save(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return

        fd = open(self.ctx.db_path, "w+")
        db = {
            "symbols": self.ctx.dis.binary.symbols,
            "history": self.rl.history,
            "inline_comments": self.ctx.dis.inline_comments,
            "previous_comments": self.ctx.dis.previous_comments,
            "jmptables": [],
            "mips_gp": self.ctx.dis.mips_gp,
        }
        for j in self.ctx.dis.jmptables.values():
            o = {
                "inst_addr": j.inst_addr,
                "table_addr": j.table_addr,
                "table": j.table,
                "name": j.name,
            }
            db["jmptables"].append(o)
        fd.write(json.dumps(db))
        fd.close()
        print("database saved to", self.ctx.db_path)
        self.ctx.db_modified = False
Beispiel #6
0
    def __exec_save(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return

        fd = open(self.ctx.db_path, "w+")
        db = {
            "symbols": self.ctx.dis.binary.symbols,
            "history": self.rl.history,
            "inline_comments": self.ctx.dis.inline_comments,
            "previous_comments": self.ctx.dis.previous_comments,
            "jmptables": [],
            "mips_gp": self.ctx.dis.mips_gp,
        }
        for j in self.ctx.dis.jmptables.values():
            o = {
                "inst_addr": j.inst_addr,
                "table_addr": j.table_addr,
                "table": j.table,
                "name": j.name,
            }
            db["jmptables"].append(o)
        fd.write(json.dumps(db))
        fd.close()
        print("database saved to", self.ctx.db_path)
        self.ctx.db_modified = False
Beispiel #7
0
 def decorated_function(*args, **kwargs):
     encoded_jwt = request.headers.get('authorization')
     if encoded_jwt is None:
         return error(403, "missing credentials")
     if validate_jwt(encoded_jwt):
         return f(*args, **kwargs)
     return error(403, "not cool enough for this club")
Beispiel #8
0
 def __exec_load(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.filename = args[1]
     load_file(self.ctx)
Beispiel #9
0
def get_explore_collections():
    """
    Returns a paginated list of collection IDs (50/page), based on given filters.

    :q str order: The method to explore by: popular-1w, popular-1m, popular-6m, popular-all, newest, edittime, relevance
    :q str tags: A comma-separated list of tags that returned collections must have all of.
    :q str q: A search query.
    :q int page: The page of results to return.
    """
    order = request.args.get('order', 'popular-1w')
    tags = request.args.get('tags')
    if tags:
        tags = tags.split(',')
    else:
        tags = []
    q = request.args.get('q')
    page = request.args.get('page', 1)
    if page:
        try:
            page = int(page)
        except ValueError:
            return error(400, 'page must be int')

    try:
        coll_ids = explore_collections(order, tags, q, page)
    except ValueError as e:
        return error(400, str(e))

    return success(coll_ids, 200)
Beispiel #10
0
 def __exec_save(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     self.ctx.db.save(self.rl.history)
     print("database saved to", self.ctx.db.path)
     self.ctx.db.modified = False
Beispiel #11
0
 def __exec_save(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     self.ctx.db.save(self.rl.history)
     print("database saved to", self.ctx.db.path)
     self.ctx.db.modified = False
Beispiel #12
0
    def decompile(self):
        self.is_dump = False
        self.gph, pe_nb_new_syms = self.gctx.dis.get_graph(self.entry)

        if self.gph is None:
            error("capstone can't disassemble here")
            return None
        self.gph.simplify()

        if self.gctx.db.loaded and pe_nb_new_syms:
            self.gctx.db.modified = True
        
        try:
            self.gph.loop_detection(self.entry)
            ast, correctly_ended = generate_ast(self)
            if not correctly_ended:
                debug__("Second try...")
                self.gph.loop_detection(self.entry, True)
                ast, _ = generate_ast(self)

            self.ast = ast
        except ExcIfelse as e:
            error("can't have a ifelse here     %x" % e.addr)
            if self.gctx.interactive_mode:
                return None
            die()

        o = self.gctx.libarch.output.Output(self)
        o._ast(self.entry, ast)
        self.output = o
        return o
Beispiel #13
0
    def __exec_data(self, args):
        if self.gctx.dis is None:
            error("load a file before")
            return
        nb_lines = self.gctx.nb_lines
        if len(args) <= 1:
            self.gctx.entry = None
            error("no address in parameter")
            return

        if len(args) == 3:
            try:
                nb_lines = int(args[2])
            except:
                pass

        ctx = self.gctx.get_addr_context(args[1])
        if ctx:
            if args[0] == "da":
                self.gctx.dis.dump_data_ascii(ctx, nb_lines)
            elif args[0] == "db":
                self.gctx.dis.dump_data(ctx, nb_lines, 1)
            elif args[0] == "dw":
                self.gctx.dis.dump_data(ctx, nb_lines, 2)
            elif args[0] == "dd":
                self.gctx.dis.dump_data(ctx, nb_lines, 4)
            elif args[0] == "dq":
                self.gctx.dis.dump_data(ctx, nb_lines, 8)
Beispiel #14
0
def handle_auth(data):
    """
    POST /discord/auth
    Content-Type: application/json

    {"code": str}

    Returns:
    {"success": bool, "data": {"jwt": str}, "error": str}
    """
    try:
        access_token_resp = exchange_code(data['code'])
        _, user = handle_token_response(access_token_resp)
    except HTTPError as e:
        if 400 <= e.response.status_code < 500:
            return error(e.response.status_code, str(e))
        return error(500, str(e))

    token = jwt.encode(
        {
            'iss': 'avrae.io',
            'aud': 'avrae.io',
            'iat': datetime.datetime.now(),
            'id': str(user.id),
            'username': user.username,
            'discriminator': user.discriminator,
            'avatar': user.avatar
        },
        config.JWT_SECRET,
        algorithm='HS256')

    return success({'jwt': token.decode()})  # token is str
Beispiel #15
0
 def __exec_data(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     lines = self.ctx.lines
     if len(args) <= 1:
         self.ctx.entry = None
         error("no address in parameter")
         return
     self.ctx.entry = args[1]
     if len(args) == 3:
         lines = int(args[2])
     self.ctx.print_data = True
     if init_entry_addr(self.ctx):
         if args[0] == "da":
             self.ctx.dis.dump_data_ascii(self.ctx, lines)
         elif args[0] == "db":
             self.ctx.dis.dump_data(self.ctx, lines, 1)
         elif args[0] == "dw":
             self.ctx.dis.dump_data(self.ctx, lines, 2)
         elif args[0] == "dd":
             self.ctx.dis.dump_data(self.ctx, lines, 4)
         elif args[0] == "dq":
             self.ctx.dis.dump_data(self.ctx, lines, 8)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
         self.ctx.print_data = False
Beispiel #16
0
 def __exec_load(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.filename = args[1]
     load_file(self.ctx)
Beispiel #17
0
def disasm(ctx):
    ctx.gph = ctx.dis.get_graph(ctx.entry_addr)
    if ctx.gph == None:
        error("capstone can't disassemble here")
        return
    ctx.gph.graph_init(ctx)

    if ctx.graph:
        ctx.gph.html_graph(ctx.dis.jmptables)

    try:
        ast = generate_ast(ctx)
    except ExcIfelse as e:
        error("can't have a ifelse here     %x" % e.addr)
        if ctx.interactive:
            return
        die()

    if ctx.vim:
        base = os.path.basename(ctx.filename) + "_" + ctx.entry
        # re-assign if no colors
        ctx.libarch.process_ast.assign_colors(ctx, ast)
        ctx.color = False
        generate_vim_syntax(ctx, base + ".vim")
        sys.stdout = open(base + ".rev", "w+")

    o = ctx.libarch.output.Output(ctx)
    o.print_ast(ctx.entry_addr, ast)

    if ctx.vim:
        print("Run :  vim {0}.rev -S {0}.vim".format(base), file=sys.stderr)
Beispiel #18
0
 def __exec_lrawmips64(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "mips64"
     self.ctx.filename = args[1]
     load_file(self.ctx)
Beispiel #19
0
 def __exec_lrawmips64(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "mips64"
     self.ctx.filename = args[1]
     load_file(self.ctx)
Beispiel #20
0
 def __exec_lrawmips(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "mips"
     self.ctx.filename = args[1]
     load_file(self.ctx)
     self.analyzer.set(self.ctx.dis, self.ctx.db)
Beispiel #21
0
 def __exec_lrawx64(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "x64"
     self.ctx.raw_big_endian = False
     self.ctx.filename = args[1]
     load_file(self.ctx)
Beispiel #22
0
 def __exec_load(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.filename = args[1]
     load_file(self.ctx)
     if self.ctx.db is not None:
         self.rl.history = self.ctx.db["history"]
Beispiel #23
0
 def __exec_lrawmips64(self, args):
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.gctx.raw_type = "mips64"
     if self.gctx.load_file(args[1]):
         self.analyzer.set(self.gctx.dis, self.gctx.db)
Beispiel #24
0
 def __exec_load(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.filename = args[1]
     load_file(self.ctx)
     if self.ctx.db is not None:
         self.rl.history = self.ctx.db["history"]
Beispiel #25
0
 def __exec_lrawmips64(self, args):
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.gctx.raw_type = "mips64"
     if self.gctx.load_file(args[1]):
         self.analyzer.set(self.gctx.dis, self.gctx.db)
Beispiel #26
0
 def __exec_lrawx64(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "x64"
     self.ctx.raw_big_endian = False
     self.ctx.filename = args[1]
     load_file(self.ctx)
Beispiel #27
0
 def __exec_lrawmips(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "mips"
     self.ctx.filename = args[1]
     load_file(self.ctx)
     self.analyzer.set(self.ctx.dis, self.ctx.db)
Beispiel #28
0
 def __exec_lrawx86(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "x86"
     self.ctx.raw_big_endian = False
     self.ctx.filename = args[1]
     load_file(self.ctx)
     self.analyzer.set(self.ctx.dis, self.ctx.db)
Beispiel #29
0
def create_snippet(user, body, coll_id):
    coll = get_collection_with_editor_check(coll_id, user)

    if ' ' in body['name']:
        return error(400, "snippet names cannot contain spaces")
    if len(body['name']) < 2:
        return error(400, "snippet names must be at least 2 characters")

    snippet = coll.create_snippet(body['name'], body['docs'])
    return success(snippet.to_dict(js=True), 201)
Beispiel #30
0
    def __exec_sections(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return

        self.rl.print("NAME".ljust(20))
        self.rl.print(" [START - END]\n")

        for (name, start, end) in self.ctx.dis.binary.iter_sections():
            self.ctx.dis.print_section_meta(name, start, end)
Beispiel #31
0
 def __exec_xrefs(self, args):
     if self.gctx.dis is None:
         error("load a file before")
         return
     ad = None if len(args) == 1 else args[1]
     ctx = self.gctx.get_addr_context(ad)
     if ctx:
         if ctx.entry not in self.gctx.dis.xrefs:
             return
         ctx.dump_xrefs().print()
Beispiel #32
0
 def __exec_lrawx86(self, args):
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.gctx.raw_type = "x86"
     self.gctx.raw_big_endian = False
     if self.gctx.load_file(args[1]):
         self.analyzer.set(self.gctx.dis, self.gctx.db)
Beispiel #33
0
 def __exec_v(self, args):
     if self.gctx.dis is None:
         error("load a file before")
         return
     ad = None if len(args) == 1 else args[1]
     ctx = self.gctx.get_addr_context(ad)
     if ctx:
         o = ctx.dump_asm(NB_LINES_TO_DISASM)
         if o is not None:
             Visual(self.gctx, ctx, self.analyzer)
Beispiel #34
0
 def __exec_lrawx86(self, args):
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.gctx.raw_type = "x86"
     self.gctx.raw_big_endian = False
     if self.gctx.load_file(args[1]):
         self.analyzer.set(self.gctx.dis, self.gctx.db)
Beispiel #35
0
 def __exec_xrefs(self, args):
     if self.gctx.dis is None:
         error("load a file before")
         return
     ad = None if len(args) == 1 else args[1]
     ctx = self.gctx.get_addr_context(ad)
     if ctx:
         if ctx.entry not in self.gctx.dis.xrefs:
             return
         ctx.dump_xrefs().print()
Beispiel #36
0
def edit_snippet(user, body, snippet_id):
    snippet = get_collectable_with_editor_check(WorkshopSnippet, snippet_id, user)

    if ' ' in body['name']:
        return error(400, "snippet names cannot contain spaces")
    if len(body['name']) < 2:
        return error(400, "snippet names must be at least 2 characters")

    snippet.update_info(body['name'], body['docs'])
    return success(snippet.to_dict(js=True), 200)
Beispiel #37
0
    def __exec_sections(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return

        self.rl.print("NAME".ljust(20))
        self.rl.print(" [ START - END - VIRTUAL_SIZE - RAW_SIZE ]\n")

        for s in self.ctx.dis.binary.iter_sections():
            s.print_header()
Beispiel #38
0
 def __exec_lrawx86(self, args):
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "x86"
     self.ctx.raw_big_endian = False
     self.ctx.filename = args[1]
     load_file(self.ctx)
     self.analyzer.set(self.ctx.dis, self.ctx.db)
Beispiel #39
0
    def __exec_sections(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return

        self.rl.print("NAME".ljust(20))
        self.rl.print(" [ START - END - VIRTUAL_SIZE - RAW_SIZE ]\n")

        for s in self.ctx.dis.binary.iter_sections():
            s.print_header()
Beispiel #40
0
 def __exec_v(self, args):
     if self.gctx.dis is None:
         error("load a file before")
         return
     ad = None if len(args) == 1 else args[1]
     ctx = self.gctx.get_addr_context(ad)
     if ctx:
         o = ctx.dump_asm(NB_LINES_TO_DISASM)
         if o is not None:
             Visual(self.gctx, ctx, self.analyzer)
Beispiel #41
0
    def __exec_sections(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return

        self.rl.print("NAME".ljust(20))
        self.rl.print(" [START - END]\n")

        for (name, start, end) in self.ctx.dis.binary.iter_sections():
            self.ctx.dis.print_section_meta(name, start, end)
Beispiel #42
0
 def __exec_lrawarm(self, args):
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "arm"
     self.ctx.filename = args[1]
     if load_file(self.ctx):
         self.analyzer.set(self.ctx.dis, self.ctx.db)
Beispiel #43
0
 def __exec_load(self, args):
     # TODO: kill the thread analyzer before loading a new file
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.gctx.raw_type = None
     if self.gctx.load_file(args[1]):
         self.rl.history = self.gctx.db.history
         self.push_analyze_symbols()
Beispiel #44
0
    def __exec_mips_set_gp(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return

        try:
            self.ctx.dis.mips_gp = int(args[1], 16)
        except:
            error("bad address")

        self.ctx.db.modified = True
Beispiel #45
0
    def __exec_mips_set_gp(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return

        try:
            self.ctx.dis.mips_gp = int(args[1], 16)
        except:
            error("bad address")

        self.ctx.db.modified = True
Beispiel #46
0
 def __exec_load(self, args):
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.filename = args[1]
     if load_file(self.ctx):
         self.rl.history = self.ctx.db.history
         self.push_analyze_symbols()
Beispiel #47
0
 def __exec_load(self, args):
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.filename = args[1]
     if load_file(self.ctx):
         self.rl.history = self.ctx.db.history
         self.push_analyze_symbols()
Beispiel #48
0
 def __exec_lrawarm(self, args):
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "arm"
     self.ctx.filename = args[1]
     load_file(self.ctx)
     self.analyzer.set(self.ctx.dis, self.ctx.db)
Beispiel #49
0
 def __exec_load(self, args):
     # TODO: kill the thread analyzer before loading a new file
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.gctx.raw_type = None
     if self.gctx.load_file(args[1]):
         self.rl.history = self.gctx.db.history
         self.push_analyze_symbols()
Beispiel #50
0
def set_state(user, body, coll_id):
    coll = WorkshopCollection.from_id(coll_id)
    if not coll.is_owner(int(user.id)):
        return error(403, "you do not have permission to change the state of this collection")

    try:
        coll.set_state(body['state'])
    except ValueError as e:  # invalid publication state
        return error(400, str(e))

    return success(coll.to_dict(js=True), 200)
Beispiel #51
0
 def __exec_lrawx64(self, args):
     if self.check_db_modified():
         return
     if len(args) != 2:
         error("filename required")
         return
     self.ctx.reset_all()
     self.ctx.raw_type = "x64"
     self.ctx.raw_big_endian = False
     self.ctx.filename = args[1]
     if load_file(self.ctx):
         self.analyzer.set(self.ctx.dis, self.ctx.db)
Beispiel #52
0
def edit_alias(user, body, alias_id):
    alias = get_collectable_with_editor_check(WorkshopAlias, alias_id, user)

    if not body['name']:
        return error(400, "Alias must have a name")
    if ' ' in body['name']:
        return error(400, "Alias names cannot contain spaces")
    if not alias.has_parent and body['name'] in current_app.rdb.jget("default_commands", []):
        return error(409, f"{body['name']} is already a built-in command")

    alias.update_info(body['name'], body['docs'])
    return success(alias.to_dict(js=True), 200)
Beispiel #53
0
 def __exec_calls(self, args):
     if len(args) != 2:
         error("section required")
         return
     if self.ctx.dis is None:
         error("load a file before")
         return
     self.ctx.calls_in_section = args[1]
     if init_entry_addr(self.ctx):
         self.ctx.dis.print_calls(self.ctx)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
     self.ctx.calls_in_section = None
Beispiel #54
0
 def __exec_x(self, args):
     if self.gctx.dis is None:
         error("load a file before")
         return
     ad = None if len(args) == 1 else args[1]
     ctx = self.gctx.get_addr_context(ad)
     if ctx:
         try:
             o = ctx.decompile()
             if o is not None:
                 o.print()
         except:
             traceback.print_exc()
Beispiel #55
0
 def __exec_x(self, args):
     if self.ctx.dis is None:
         error("load a file before")
         return
     if len(args) == 1:
         self.ctx.entry = None
     else:
         self.ctx.entry = args[1]
     self.ctx.reset_vars()
     if init_entry_addr(self.ctx):
         disasm(self.ctx)
         self.ctx.entry = None
         self.ctx.entry_addr = 0
Beispiel #56
0
    def exec_command(self, line):
        args = shlex.split(line)
        if args[0] not in self.COMMANDS:
            error("unknown command")
            return
        c = self.COMMANDS[args[0]]

        if len(args)-1 > c.max_args:
            error("%s takes max %d args" % (args[0], c.max_args))
            return

        if c.callback_exec is not None:
            c.callback_exec(args)
Beispiel #57
0
    def __exec_sections(self, args):
        if self.ctx.dis is None:
            error("load a file before")
            return

        self.rl.print("NAME".ljust(20))
        self.rl.print("START".ljust(16))
        self.rl.print("END\n")

        for (name, start, end) in self.ctx.dis.binary.iter_sections():
            self.rl.print(name.ljust(20))
            self.rl.print(hex(start).ljust(16))
            self.rl.print(hex(end).ljust(16))
            self.rl.print("\n")
Beispiel #58
0
def init_entry_addr(ctx):
    if ctx.entry == "EP":
        entry_addr = ctx.dis.binary.get_entry_point()

    else:
        try:
            entry_addr = ctx.dis.get_addr_from_string(ctx.entry, ctx.raw_type != None)

            # An exception is raised if the symbol was not found
            if ctx.entry is None:
                ctx.entry = "main"
        except ExcSymNotFound as e:
            error("symbol %s not found" % e.symname)
            if ctx.interactive_mode:
                return False
            error("You can see all symbols with -s (if resolution is done).")
            error("Note: --dump need the option -x.")
            die()

    s = ctx.dis.binary.get_section(entry_addr)
    if s is None:
        error("the address 0x%x was not found" % entry_addr)
        if ctx.interactive_mode:
            return False
        die()

    ctx.entry_addr = entry_addr

    return True
Beispiel #59
0
def init_addr(ctx):
    if ctx.entry == "EP":
        addr = ctx.dis.binary.get_entry_point()
    else:
        try:
            addr = ctx.dis.get_addr_from_string(ctx.entry, ctx.raw_type != None)
        except ExcSymNotFound as e:
            error("symbol %s not found" % e.symname)
            if ctx.interactive:
                return False
            error("Try with --sym to see all symbols.")
            die()

    try:
        ctx.dis.check_addr(addr)
    except ExcNotExec as e:
        error("the address 0x%x is not in an executable section" % e.addr)
        if ctx.interactive:
            return False
        die()
    except ExcNotAddr as e:
        error("the address 0x%x cannot be found" % e.addr)
        if ctx.interactive:
            return False
        die()

    ctx.addr = addr

    return True