Exemplo n.º 1
0
    def test_set(self):

        s = '01 20 40 E2 02 20 61 E0 01 30 D1 E4 00 00 53 E3 02 30 C1 E7 FB FF FF 1A 1E FF 2F E1'

        odb = OdbFile(BinaryString(s, 'arm'))
        odb.execute(LoadOperation())

        modify = ModifySettingsFactory.set_architecture('i386')
        odb.execute(modify)
        binary = odb.get_binary()
        options = binary.options
        self.assertEquals("i386", options.architecture)

        modify = ModifySettingsFactory.set_base_address('1000')
        odb.execute(modify)
        binary = odb.get_binary()
        options = binary.options
        self.assertEquals("1000", options.base_address)

        modify = ModifySettingsFactory.set_endian('BIG')
        odb.execute(modify)
        binary = odb.get_binary()
        options = binary.options
        self.assertEquals("BIG", options.endian)

        modify = ModifySettingsFactory.set_values(
            {'selected_opts': ["intel-mnemonic"]})
        odb.execute(modify)
        binary = odb.get_binary()
        options = binary.options
        self.assertEquals(1, len(options.get_extra_options()))
        self.assertEquals('intel-mnemonic', options.get_extra_options()[0])
Exemplo n.º 2
0
    def test_hash(self):
        s = '55 31 D2 89 E5 8B 45 08 56 8B 75 0C 53 8D 58 FF 0F B6 0C 16 88 4C 13 01 83 C2 01 84 C9 75 F1 5B 5E 5D C3'

        odb_file = OdbFile(BinaryString(s, 'i386'))
        self.assertEqual('d41d8cd98f00b204e9800998ecf8427e',
                         odb_file.get_binary().md5())
        self.assertEqual('da39a3ee5e6b4b0d3255bfef95601890afd80709',
                         odb_file.get_binary().sha1())
Exemplo n.º 3
0
    def test_load_string_arm(self):

        s = '01 20 40 E2 02 20 61 E0 01 30 D1 E4 00 00 53 E3 02 30 C1 E7 FB FF FF 1A 1E FF 2F E1'

        odb_file = OdbFile(BinaryString(s, 'arm'))
        odb_file.execute(LoadOperation())
        odb_file.execute(PassiveScanOperation())

        self.assertEqual(1, len(odb_file.get_structure_list(Branch)))
Exemplo n.º 4
0
    def test_size(self):
        odb_file = OdbFile(
            BinaryFile(self.get_test_bin_path('ls'), 'elf64-x86-64',
                       'i386:x86-64'))
        self.assertEqual(114032, odb_file.get_binary().size)

        s = '01 20 40 E2 02 20 61 E0 01 30 D1 E4 00 00 53 E3 02 30 C1 E7 FB FF FF 1A 1E FF 2F E1'
        odb_file = OdbFile(BinaryString(s, 'arm'))
        self.assertEqual(28, odb_file.get_binary().size)
Exemplo n.º 5
0
def DeserializeBinary(d):
    if d['kind'] == 'file':
        return BinaryFile.deserialize(d)
    elif d['kind'] == 'string':
        return BinaryString.deserialize(d)
    elif d['kind'] == 'file_model':
        return BinaryFileModel.deserialize(d)
    else:
        raise Exception("Unrecognized binary kind %s" % d['kind'])
Exemplo n.º 6
0
    def test_load_and_get(self):

        s = '01 20 40 E2 02 20 61 E0 01 30 D1 E4 00 00 53 E3 02 30 C1 E7 FB FF FF 1A 1E FF 2F E1'

        odb = OdbFile(BinaryString(s, 'arm'))
        odb.execute(LoadOperation())

        binary = odb.get_binary()
        options = binary.options

        self.assertEquals("arm", options.architecture)
        self.assertEquals(0, options.base_address)
        self.assertEquals('binary', options.target)
Exemplo n.º 7
0
    def test_load_string(self):

        s = '55 31 D2 89 E5 8B 45 08 56 8B 75 0C 53 8D 58 FF 0F B6 0C 16 88 4C 13 01 83 C2 01 84 C9 75 F1 5B 5E 5D C3'

        odb_file = OdbFile(BinaryString(s, 'i386'))
        odb_file.execute(LoadOperation())

        passive_scan_operation = PassiveScanOperation()
        odb_file.execute(passive_scan_operation)

        self.assertEqual(1, len(odb_file.get_structure_list(Branch)))
        self.assertEqual(1, len(odb_file.get_structure_list(Parcel)))
        self.assertEqual(0, odb_file.get_structure_list(Parcel)[0].vma_start)
        self.assertEqual(35, odb_file.get_structure_list(Parcel)[0].vma_end)
Exemplo n.º 8
0
def load_examples(owner=None):
    EXAMPLES_DIR = os.path.join(
        os.path.dirname(oda.apps.odaweb.examples.__file__), 'examples')

    for example in Examples:
        short_name = example['short_name']
        valid_file_storage_id = True

        if OdaMaster.objects.filter(short_name=short_name).exists():
            print('Example %s already exists in the database' % short_name)
            oda_master = OdaMaster.objects.filter(
                short_name=short_name).first()
        else:
            oda_master = OdaMaster(
                short_name=short_name,
                project_name=example['project_name'],
                owner=owner,
                default_permission=OdaMasterPermissionLevel.read.value)

        print('Adding example %s to database' % short_name)

        if 'data' in example:
            example_data = ''.join(example['data'].split())
            odb_file = OdbFile(
                BinaryString(example_data, example['options']['architecture']))
        elif 'file_name' in example:
            odb_file = OdbFile(
                BinaryFile(os.path.join(EXAMPLES_DIR, example['file_name']),
                           example['options']['target'],
                           example['options']['architecture']))

        odb_file.execute(LoadOperation())
        odb_file.execute(PassiveScanOperation())

        if 'comments' in example:
            for vma, msg in example['comments']:
                odb_file.execute(CreateCommentOperation(vma, msg))
                print("Adding Comment %s To %s" % (msg, str(odb_file)))

        if 'labels' in example:
            for vma, label in example['labels']:
                odb_file.execute(CreateLabelOperation(vma, label))
                print("Saving label %s To %s" % (label, str(odb_file)))

        oda_master.odb_file = odb_file
        oda_master.save()
Exemplo n.º 9
0
Arquivo: views.py Projeto: ygemici/oda
    def partial_update(self, request, pk):
        oda_master = OdaMaster.objects.get(
            short_name=request.data['short_name'],
            revision=request.data['revision'])

        previous_odb = oda_master.odb_file

        try:
            odb_file = OdbFile(
                BinaryString(request.data['binary_string'],
                             previous_odb.get_binary().options.architecture))
            odb_file.execute(LoadOperation())
            odb_file.execute(PassiveScanOperation())
        except (TypeError, UnicodeDecodeError, UnicodeEncodeError):
            return HttpResponseNotAllowed('Invalid hex digits')

        oda_master.odb_file = odb_file
        oda_master.save()

        logger.info("updating...")

        return Response({'binary_string': request.data['binary_string']})