Пример #1
0
    def test_inBasicDS(self):
        ds = DataStore(":memory:")
        seg = Segment([0, 1, 2, 3, 4, 5, 6, 7], 0x0)
        ds.addSegment(seg)

        self.assertEqual(False, -1 in ds)
        self.assertEqual(True, 0 in ds)
        self.assertEqual(True, 1 in ds)
        self.assertEqual(True, 2 in ds)
        self.assertEqual(True, 3 in ds)
        self.assertEqual(True, 4 in ds)
        self.assertEqual(True, 5 in ds)
        self.assertEqual(True, 6 in ds)
        self.assertEqual(True, 7 in ds)
        self.assertEqual(False, 8 in ds)
Пример #2
0
	def test_inBasicDS(self):
		ds = DataStore(":memory:")
		seg = Segment([0,1,2,3,4,5,6,7], 0x0)
		ds.addSegment(seg)
		
		def fakeCallable():
			ds[-1]
		self.assertRaises(KeyError, fakeCallable)
		
		for i in xrange(0,8):
			ds[i]
			
		def fakeCallable():
			ds[8]
		self.assertRaises(KeyError, fakeCallable)
Пример #3
0
	def test_inBasicDS(self):
		ds = DataStore(":memory:")
		seg = Segment([0,1,2,3,4,5,6,7], 0x0)
		ds.addSegment(seg)
		
		
		self.assertEqual(False, -1 in ds)
		self.assertEqual(True, 0 in ds)
		self.assertEqual(True, 1 in ds)
		self.assertEqual(True, 2 in ds)
		self.assertEqual(True, 3 in ds)
		self.assertEqual(True, 4 in ds)
		self.assertEqual(True, 5 in ds)
		self.assertEqual(True, 6 in ds)
		self.assertEqual(True, 7 in ds)
		self.assertEqual(False, 8 in ds)
Пример #4
0
    def test_inBasicDS(self):
        ds = DataStore(":memory:")
        seg = Segment([0, 1, 2, 3, 4, 5, 6, 7], 0x0)
        ds.addSegment(seg)

        def fakeCallable():
            ds[-1]

        self.assertRaises(KeyError, fakeCallable)

        for i in xrange(0, 8):
            ds[i]

        def fakeCallable():
            ds[8]

        self.assertRaises(KeyError, fakeCallable)
Пример #5
0
import sys

from idis.datastore import DataStore

ds = DataStore(sys.argv[1])

location = ds[int(sys.argv[2], 0)]

print """
Address: %04x
length: %d
TypeClass: %s
TypeName: %s""" % (location.addr, location.length, location.typeclass,
                   location.typename)
Пример #6
0
 def test_notInDS(self):
     ds = DataStore(":memory:")
     self.assertEqual(False, 0 in ds)
     self.assertEqual(False, 1 in ds)
     self.assertEqual(False, -1 in ds)
Пример #7
0
    def testUndefine(self):
        ds = DataStore(":memory:")
        seg = Segment([0, 1, 2, 3, 4, 5, 6, 7], 0x0)
        ds.addSegment(seg)

        undefine(ds, 0)
Пример #8
0
import time

sys.path += [os.path.dirname(sys.path[0])]

import idis
import idis.tools
from idis.datastore import DataStore
import arch

testfile = '/tmp/basic_test_name'
try:
    os.unlink(testfile)
except OSError:
    pass

ds = DataStore(testfile)

my_dir = os.path.dirname(sys.argv[0])

testfile_path = my_dir + "/src/8051_flash_trunc.bin"

startTime = time.time()
print "Starting tests at time %f" % startTime

idis.tools.addBinary(ds, testfile_path, 0x0, 0x8000, 0x7E00)

ds.flush()

midTime = time.time()
print "Loading binary took %f seconds" % (midTime - startTime)
Пример #9
0
	def mainloop(self, filenames):
		if (len(filenames) < 1):
			self.shutdown()
			print "usage: idis filename"
			return
			
		ds = DataStore(filenames[0])
		try:
			# Setup a few more params [move to init?]
			curses_set_cursor(0)
			cursG.dialog.bgattr = curses.color_pair(COLOR_WHITE_ON_BLUE)
			cursG.dialog.fldattr = curses.color_pair(COLOR_BLACK_ON_WHITE)
			cursG.dialog.badfldattr = curses.color_pair(COLOR_RED_ON_WHITE)| curses.A_REVERSE

			colors_nohil = {

				IND_ADDR: (curses.color_pair(COLOR_CYAN_ON_BLUE)),
				IND_COMMENT: (curses.color_pair(COLOR_WHITE_ON_BLUE)),
				IND_LABEL: (curses.color_pair(COLOR_GREEN_ON_BLUE)) | curses.A_BOLD,
				IND_XREF: (curses.color_pair(COLOR_GREEN_ON_BLUE)),

				IND_DISASM_OPC: (curses.color_pair(COLOR_WHITE_ON_BLUE)),
				IND_DISASM_PUNC: (curses.color_pair(COLOR_CYAN_ON_BLUE)),
				IND_DISASM_CONSTANT: (curses.color_pair(COLOR_GREEN_ON_BLUE)),

				IND_SRCMARK:curses.color_pair(COLOR_RED_ON_BLUE) | curses.A_BOLD,
				IND_DSTMARK:curses.color_pair(COLOR_GREEN_ON_BLUE) | curses.A_BOLD,
			}
			colors_hil = {
				IND_HSEL: curses.color_pair(COLOR_WHITE_ON_BLUE)  | curses.A_BOLD,

				IND_ADDR: (curses.color_pair(COLOR_CYAN_ON_BLUE) | curses.A_BOLD),
				IND_COMMENT: (curses.color_pair(COLOR_WHITE_ON_BLUE) | curses.A_BOLD),
				IND_LABEL: (curses.color_pair(COLOR_GREEN_ON_BLUE) | curses.A_BOLD),
				IND_XREF: (curses.color_pair(COLOR_GREEN_ON_BLUE) | curses.A_BOLD),

				
				IND_DISASM_OPC: (curses.color_pair(COLOR_WHITE_ON_BLUE)) | curses.A_BOLD,
				IND_DISASM_PUNC: (curses.color_pair(COLOR_WHITE_ON_BLUE)) | curses.A_BOLD,
				IND_DISASM_CONSTANT: (curses.color_pair(COLOR_GREEN_ON_BLUE)) | curses.A_BOLD,

				
				IND_SRCMARK:curses.color_pair(COLOR_RED_ON_BLUE) | curses.A_BOLD,
				IND_DSTMARK:curses.color_pair(COLOR_GREEN_ON_BLUE) | curses.A_BOLD,
			}
			
			display_win = AssemblerDisplay(self.stdscr, ds, colors_nohil, colors_hil)
			locations = []

			while 1:
				ds.flush()
				display_win.redraw()

				# HACK
				try:
					while display_win.seladdr > display_win.last_displayed_addr:
						display_win.window_base += ds[display_win.window_base].length
						display_win.redraw()
				except AttributeError:
					pass

				self.stdscr.refresh()
				c=self.stdscr.getch()
				if 0<c<256:
					c_h = c
					c=chr(c)
					# Q or q exits
					if c in 'Qq': break
					if c == 'A':
						def fileExistsValidator(f):
							try:
								open(f,"r")
							except IOError:
								return False
							return True
						
						res = cursG.dialog.doInputDialog(self.stdscr, [
									cursG.dialog.InputField("fname","FileName", validator=fileExistsValidator)
									],
									fld_w = 80
									)

						if (res != None):
							idis.tools.addIHex(ds, res["fname"])

					

					if c == 'r':
						idis.tools.rebuild(ds, runtime_arch)
						
					if c == 'R':
						idis.tools.clean(ds)
					
					if c == 'g':
						
						res = cursG.dialog.doInputDialog(self.stdscr, [
									cursG.dialog.InputField("addr","Address", "0x%04x" % display_win.seladdr, validator=cursG.dialog.intValidator) ] )

						if res:	
							loc = int(res["addr"], 0)
							locations.append((display_win.seladdr, display_win.window_base))
							display_win.seladdr = loc
							display_win.window_base = loc

					if c_h == 0x7f:
						try:
							(display_win.seladdr, display_win.window_base) = locations.pop()
						except IndexError: pass

					if c == 'a':
						def fileExistsValidator(f):
							try:
								open(f,"r")
							except IOError:
								return False
							return True
						def intOrBlankValidator(f):
							return f == "" or cursG.dialog.intValidator(f)

						res = cursG.dialog.doInputDialog(self.stdscr, [
									cursG.dialog.InputField("fname","FileName", validator=fileExistsValidator),
									cursG.dialog.InputField("base","Base Address", "0x0", validator = cursG.dialog.intValidator),
									cursG.dialog.InputField("startoffs","Start offset", "0x0", validator = cursG.dialog.intValidator),
									cursG.dialog.InputField("length","Length to load", "", validator = intOrBlankValidator),
									],
									fld_w = 80
									)
						if (res != None):
							if res["length"] == "": length = -1
							else:                   length = int(res["length"],0)
							
							idis.tools.addBinary(ds, res["fname"], int(res["base"],0), int(res["startoffs"],0), length)


						ds.flush()

					if c == 'X':
						idis.tools.xrefsPass(ds)
					if c == 'L':
						idis.tools.labelsPass(ds)

					# The following commands require the line to be in the datastore
					if display_win.seladdr != None and display_win.seladdr in ds:
						if c == '\n':
							naddr = idis.tools.follow(ds,display_win.seladdr)
							if naddr != None and naddr in ds:
								locations.append((display_win.seladdr, display_win.window_base))
								display_win.seladdr = naddr
								display_win.window_base = display_win.seladdr
						if c == 'u':
							idis.tools.undefine(ds, display_win.seladdr)

						if c == 'c':
							idis.tools.codeFollow(ds, runtime_arch, display_win.seladdr)

						if c == 's':
							idis.tools.decodeAs(ds, "astring", display_win.seladdr)
							
						if c == 'v':
							d = ds[display_win.seladdr].cdict

							#fields = [ cursG.dialog.InputField(i[0], i[0], str(i[1])) for i in d.iteritems() ]
							#cursG.dialog.doInputDialog(self.stdscr, fields)
							#takeInput(stdscr, ds[display_win.seladdr].comment, 4)

						if c == ";":	
							ds[display_win.seladdr].comment = takeInput(self.stdscr, ds[display_win.seladdr].comment, 4)

						if c == "l":	
							lstr = ds[display_win.seladdr].label
							if not lstr: lstr = ""
							ds[display_win.seladdr].label = takeInput(self.stdscr, lstr, 1)
				else:
					display_win.doCommand(c)

		except:
			self.__graceful_cleanup()
Пример #10
0
    def mainloop(self, filenames):
        if (len(filenames) < 1):
            self.shutdown()
            print "usage: idis filename"
            return

        ds = DataStore(filenames[0])
        try:
            # Setup a few more params [move to init?]
            curses_set_cursor(0)
            cursG.dialog.bgattr = curses.color_pair(COLOR_WHITE_ON_BLUE)
            cursG.dialog.fldattr = curses.color_pair(COLOR_BLACK_ON_WHITE)
            cursG.dialog.badfldattr = curses.color_pair(
                COLOR_RED_ON_WHITE) | curses.A_REVERSE

            colors_nohil = {
                IND_ADDR: (curses.color_pair(COLOR_CYAN_ON_BLUE)),
                IND_COMMENT: (curses.color_pair(COLOR_WHITE_ON_BLUE)),
                IND_LABEL:
                (curses.color_pair(COLOR_GREEN_ON_BLUE)) | curses.A_BOLD,
                IND_XREF: (curses.color_pair(COLOR_GREEN_ON_BLUE)),
                IND_DISASM_OPC: (curses.color_pair(COLOR_WHITE_ON_BLUE)),
                IND_DISASM_PUNC: (curses.color_pair(COLOR_CYAN_ON_BLUE)),
                IND_DISASM_CONSTANT: (curses.color_pair(COLOR_GREEN_ON_BLUE)),
                IND_SRCMARK:
                curses.color_pair(COLOR_RED_ON_BLUE) | curses.A_BOLD,
                IND_DSTMARK:
                curses.color_pair(COLOR_GREEN_ON_BLUE) | curses.A_BOLD,
            }
            colors_hil = {
                IND_HSEL:
                curses.color_pair(COLOR_WHITE_ON_BLUE) | curses.A_BOLD,
                IND_ADDR:
                (curses.color_pair(COLOR_CYAN_ON_BLUE) | curses.A_BOLD),
                IND_COMMENT:
                (curses.color_pair(COLOR_WHITE_ON_BLUE) | curses.A_BOLD),
                IND_LABEL:
                (curses.color_pair(COLOR_GREEN_ON_BLUE) | curses.A_BOLD),
                IND_XREF:
                (curses.color_pair(COLOR_GREEN_ON_BLUE) | curses.A_BOLD),
                IND_DISASM_OPC:
                (curses.color_pair(COLOR_WHITE_ON_BLUE)) | curses.A_BOLD,
                IND_DISASM_PUNC:
                (curses.color_pair(COLOR_WHITE_ON_BLUE)) | curses.A_BOLD,
                IND_DISASM_CONSTANT:
                (curses.color_pair(COLOR_GREEN_ON_BLUE)) | curses.A_BOLD,
                IND_SRCMARK:
                curses.color_pair(COLOR_RED_ON_BLUE) | curses.A_BOLD,
                IND_DSTMARK:
                curses.color_pair(COLOR_GREEN_ON_BLUE) | curses.A_BOLD,
            }

            display_win = AssemblerDisplay(self.stdscr, ds, colors_nohil,
                                           colors_hil)
            locations = []

            while 1:
                ds.flush()
                display_win.redraw()

                # HACK
                try:
                    while display_win.seladdr > display_win.last_displayed_addr:
                        display_win.window_base += ds[
                            display_win.window_base].length
                        display_win.redraw()
                except AttributeError:
                    pass

                self.stdscr.refresh()
                c = self.stdscr.getch()
                if 0 < c < 256:
                    c_h = c
                    c = chr(c)
                    # Q or q exits
                    if c in 'Qq': break
                    if c == 'A':

                        def fileExistsValidator(f):
                            try:
                                open(f, "r")
                            except IOError:
                                return False
                            return True

                        res = cursG.dialog.doInputDialog(self.stdscr, [
                            cursG.dialog.InputField(
                                "fname",
                                "FileName",
                                validator=fileExistsValidator)
                        ],
                                                         fld_w=80)

                        if (res != None):
                            idis.tools.addIHex(ds, res["fname"])

                    if c == 'r':
                        idis.tools.rebuild(ds, runtime_arch)

                    if c == 'R':
                        idis.tools.clean(ds)

                    if c == 'g':

                        res = cursG.dialog.doInputDialog(
                            self.stdscr, [
                                cursG.dialog.InputField(
                                    "addr",
                                    "Address",
                                    "0x%04x" % display_win.seladdr,
                                    validator=cursG.dialog.intValidator)
                            ])

                        if res:
                            loc = int(res["addr"], 0)
                            locations.append(
                                (display_win.seladdr, display_win.window_base))
                            display_win.seladdr = loc
                            display_win.window_base = loc

                    if c_h == 0x7f:
                        try:
                            (display_win.seladdr,
                             display_win.window_base) = locations.pop()
                        except IndexError:
                            pass

                    if c == 'a':

                        def fileExistsValidator(f):
                            try:
                                open(f, "r")
                            except IOError:
                                return False
                            return True

                        def intOrBlankValidator(f):
                            return f == "" or cursG.dialog.intValidator(f)

                        res = cursG.dialog.doInputDialog(self.stdscr, [
                            cursG.dialog.InputField(
                                "fname",
                                "FileName",
                                validator=fileExistsValidator),
                            cursG.dialog.InputField(
                                "base",
                                "Base Address",
                                "0x0",
                                validator=cursG.dialog.intValidator),
                            cursG.dialog.InputField(
                                "startoffs",
                                "Start offset",
                                "0x0",
                                validator=cursG.dialog.intValidator),
                            cursG.dialog.InputField(
                                "length",
                                "Length to load",
                                "",
                                validator=intOrBlankValidator),
                        ],
                                                         fld_w=80)
                        if (res != None):
                            if res["length"] == "": length = -1
                            else: length = int(res["length"], 0)

                            idis.tools.addBinary(ds, res["fname"],
                                                 int(res["base"], 0),
                                                 int(res["startoffs"], 0),
                                                 length)

                        ds.flush()

                    if c == 'X':
                        idis.tools.xrefsPass(ds)
                    if c == 'L':
                        idis.tools.labelsPass(ds)

                    # The following commands require the line to be in the datastore
                    if display_win.seladdr != None and display_win.seladdr in ds:
                        if c == '\n':
                            naddr = idis.tools.follow(ds, display_win.seladdr)
                            if naddr != None and naddr in ds:
                                locations.append((display_win.seladdr,
                                                  display_win.window_base))
                                display_win.seladdr = naddr
                                display_win.window_base = display_win.seladdr
                        if c == 'u':
                            idis.tools.undefine(ds, display_win.seladdr)

                        if c == 'c':
                            idis.tools.codeFollow(ds, runtime_arch,
                                                  display_win.seladdr)

                        if c == 's':
                            idis.tools.decodeAs(ds, "astring",
                                                display_win.seladdr)

                        if c == 'v':
                            d = ds[display_win.seladdr].cdict

                            #fields = [ cursG.dialog.InputField(i[0], i[0], str(i[1])) for i in d.iteritems() ]
                            #cursG.dialog.doInputDialog(self.stdscr, fields)
                            #takeInput(stdscr, ds[display_win.seladdr].comment, 4)

                        if c == ";":
                            ds[display_win.seladdr].comment = takeInput(
                                self.stdscr, ds[display_win.seladdr].comment,
                                4)

                        if c == "l":
                            lstr = ds[display_win.seladdr].label
                            if not lstr: lstr = ""
                            ds[display_win.seladdr].label = takeInput(
                                self.stdscr, lstr, 1)
                else:
                    display_win.doCommand(c)

        except:
            self.__graceful_cleanup()
Пример #11
0
		os.path.dirname(sys.path[0]) 
			]



import idis
import idis.tools
from idis.datastore import DataStore
import arch

testfile = '/tmp/basic_test_name'
try:
	os.unlink(testfile)
except OSError: pass

ds = DataStore(testfile)

my_dir = os.path.dirname(sys.argv[0])

testfile_path = my_dir + "/src/8051_flash_trunc.bin"


startTime = time.time()
print "Starting tests at time %f" % startTime

idis.tools.addBinary(ds, testfile_path, 0x0, 0x8000, 0x7E00)

ds.flush()

midTime = time.time()
print "Loading binary took %f seconds" % (midTime - startTime)
Пример #12
0
	def testUndefine(self):
		ds = DataStore(":memory:")
		seg = Segment([0,1,2,3,4,5,6,7], 0x0)
		ds.addSegment(seg)
		
		undefine(ds, 0)