Esempio n. 1
0
File: views.py Progetto: ygemici/oda
def odb_file_view(request, oda_master):
    saved = request.session.get('saved', False)

    context = {
        'isLazyUser':
        request.user.is_lazy_user(),
        'examples': [{
            'project_name': x['project_name'],
            'short_name': x['short_name']
        } for x in Examples],
        'master':
        oda_master,
        'binary':
        oda_master.odb_file.get_binary(),
        'section_info':
        Ofd(oda_master.odb_file.get_binary()).get_loadable_sections(),
        'saved':
        saved,
        'architectures':
        get_supported_archs(),
        'endians': [{
            'name': x,
            'intValue': y
        } for x, y in get_supported_endians().items()]
    }

    request.session['saved'] = False

    # oda_master = OdaMaster.objects.get(short_name='mkdir', revision=0)
    # odb_file = oda_master.odb_file
    # dasm = Disassembler(odb_file)
    # dunits = dasm.analyze(0, 10000000)
    return render(request, 'ace.djhtml', context)
Esempio n. 2
0
File: views.py Progetto: ygemici/oda
 def architectures(self, request, pk):
     return Response({
         'architectures':
         get_supported_archs(),
         'endians': [{
             'name': x,
             'intValue': y
         } for x, y in get_supported_endians().items()]
     })
Esempio n. 3
0
File: views.py Progetto: ygemici/oda
def oda_master_details(request, short_name, version=0):
    saved = request.session.get('saved', False)
    oda_master = OdaMaster.objects.filter(short_name=short_name,
                                          revision=version).last()
    binary = oda_master.odb_file.get_binary()
    section_info = Ofd(
        oda_master.odb_file.get_binary()).get_loadable_sections()
    context = {
        'isLazyUser':
        request.user.is_lazy_user(),
        'examples': [{
            'project_name': x['project_name'],
            'short_name': x['short_name']
        } for x in Examples],
        'master': {
            'project_name': oda_master.project_name,
            'short_name': oda_master.short_name
        },
        'binary': {
            # 'liveMode': binary.is_live_mode()
            'target': binary.options.target,
            'arch': binary.options.architecture,
            'size': binary.size,
            'options': {
                'architecture': binary.options.architecture,
                'base_address': binary.options.base_address,
                'endian': binary.options.endian,
                'selected_opts': binary.options.selected_opts
            }
        },
        'section_info': {
            'start_addr': section_info.start_addr,
            'stop_addr': section_info.stop_addr
        },
        'saved':
        saved,
        'architectures':
        get_supported_archs(),
        'endians': [{
            'name': x,
            'intValue': y
        } for x, y in get_supported_endians().items()]
    }
    return render_to_json(context)
Esempio n. 4
0
File: views.py Progetto: ygemici/oda
def options_form(request):
    # oda_master = get_session(request)
    arch = request.GET[
        'arch']  # oda_master.odb_file.get_binary().options.architecture
    baseAddr = 0  # oda_master.odb_file.get_binary().options.base_address
    selected_opts = []

    class HexUploadForm(forms.Form):
        hex_val = forms.CharField(required=False)
        arch = forms.CharField(required=False)
        base_address = forms.CharField(required=False)
        endian = forms.CharField(required=False)

    return render(
        request, 'form-platform-options.djhtml', {
            'arch': arch,
            'supported_archs': get_supported_archs(),
            'supported_endians': get_supported_endians(),
            'options': get_platform_options(arch),
            'base_address': baseAddr,
            'selected_opts': selected_opts,
            'form': HexUploadForm(),
            'form_type': 'live'
        })
Esempio n. 5
0
File: views.py Progetto: ygemici/oda
    def get(self, request):
        short_name = request.query_params.get('short_name')
        revision = request.query_params.get('revision', 0)
        oda = OdaMaster.objects.get(short_name=short_name, revision=revision)
        odb_file = oda.odb_file
        binary = oda.odb_file.get_binary()
        sym_dict = {
            sym.vma: sym
            for sym in odb_file.get_structure_list(Symbol) if (sym.vma != 0)
        }

        branches = odb_file.get_structure_list(Branch)

        live_mode = isinstance(binary, BinaryString)

        symbols = sym_dict.values()

        parcels = sorted(odb_file.get_structure_list(Parcel),
                         key=lambda p: p.vma_start)

        sections = filter(lambda s: s.is_loadable(),
                          odb_file.get_structure_list(Section))

        dasm = Disassembler(odb_file)
        size = dasm.total_lines()

        # Include the built in types
        builtins = [field() for field in BuiltinTypes()]

        # Include c_structs too
        cstructs = odb_file.get_structure_list(CStruct)
        fieldTypes = sorted(builtins + cstructs,
                            key=lambda s: type(s).__name__)

        binary_text = 'N/A'
        if live_mode:
            binary_text = binary.binary_string_display

        return Response({
            'project_name':
            oda.project_name,
            'binary': {
                'size': int(str(binary.size)),
                'md5': str(binary.md5()),
                'sha1': str(binary.sha1()),
                'desc': binary.desc(),
                'name': binary.name,
                'malware': False,  # str(lookup_malware(binary)),
                'benign': True,  # str(lookup_benign(binary)),
                'text': binary_text,
                'options': {
                    'architecture': binary.options.architecture,
                    'base_address': binary.options.base_address,
                    'endian': binary.options.endian,
                    'selected_opts': binary.options.selected_opts
                }
            },
            'live_mode':
            live_mode,
            'functions': [
                FunctionSerializer(x).data
                for x in odb_file.get_structure_list(Function)
            ],
            'labels': [
                LabelSerializer(x).data
                for x in odb_file.get_structure_list(Label)
            ],
            'sections':
            SectionSerializer(sections, many=True).data,
            'parcels': [ParcelSerializer(x).data for x in parcels],
            'comments': [
                CommentSerializer(x).data
                for x in odb_file.get_structure_list(Comment)
            ],
            'symbols': [SymbolSerializer(x).data for x in symbols],
            'branches': [BranchSerializer(x).data for x in branches],
            'default_permission_level':
            oda.default_permission_level().name,
            'strings': [
                DataStringSerializer({
                    'string': x.value,
                    'addr': x.addr
                }).data for x in odb_file.get_structure_list(DataString)
            ],
            'structTypes': [
                CStructSerializer(x).data
                for x in odb_file.get_structure_list(CStruct)
            ],
            'structFieldTypes':
            [CStructFieldTypeSerializer(x).data for x in fieldTypes],
            'displayUnits': {
                "size": size
            },
            #TODO Move these elsewhere
            'user':
            UserSerializer(request.user).data,
            'architectures':
            get_supported_archs(),
            'endians': [{
                'name': x,
                'intValue': y
            } for x, y in get_supported_endians().items()]
        })