Ejemplo n.º 1
0
 def test_fromdata(self):
     data = ByteArray('\0name.\0Variable\0able\0xx\0')
     st = UnpreparedElfStringTable(data=data)
     st = st.prepare(0, 0, 0, 32, '<')
     self.assertEqual(len(st.get_strings()), 5)
     self.assertEqual(st.get_string_idx(1), "name.")
     self.assertEqual(st.get_string_idx(2), "Variable")
     self.assertEqual(st.get_string_idx(3), "able")
     self.assertEqual(st.get_string_idx(4), "xx")
     self.assertEqual(st.get_string_ofs(0), "")
     self.assertEqual(st.get_string_ofs(1), "name.")
     self.assertEqual(st.get_string_ofs(7), "Variable")
     self.assertEqual(st.get_string_ofs(11), "able")
     self.assertEqual(st.get_string_ofs(16), "able")
     self.assertEqual(st.get_file_data(), data)
Ejemplo n.º 2
0
 def test_nulltable(self):
     st = UnpreparedElfStringTable()
     self.assertEqual(st.get_string_idx(0), "")
     self.assertEqual(st.index_of(""), 0)
     self.assertEqual(st.index_of("anything"), None)
     self.assertEqual(st.offset_of(""), 0)
     self.assertEqual(st.offset_of("anything"), None)
     self.assertEqual(st.get_file_data(), array.array('B', '\x00'))
Ejemplo n.º 3
0
    def test_copy(self):
        sect = BaseElfSection("test")
        self.assertRaises(NotImplementedError, sect.copy)

        sect = UnpreparedElfSection("test")
        new_sect = sect.copy()
        self.assertEquals(sect.name, new_sect.name)

        prep_sect = sect.prepare(0, 0, 0, 32, '<')
        new_sect = prep_sect.copy()
        self.assertEquals(prep_sect.name, new_sect.name)

        sect = UnpreparedElfSection("test", SHT_NOBITS)
        new_sect = sect.copy()
        self.assertEquals(sect.name, new_sect.name)

        prep_sect = sect.prepare(0, 0, 0, 32, '<')
        new_sect = prep_sect.copy()
        self.assertEquals(prep_sect.name, new_sect.name)

        sect = UnpreparedElfStringTable("string")
        strings = ["foo", "bar", "baz"]
        for string in strings:
            sect.add_string(string)
        new_sect = sect.copy()
        for i in range(len(strings)):
            self.assertEquals(sect.get_string_idx(i),
                              new_sect.get_string_idx(i))
Ejemplo n.º 4
0
 def test_fromdata(self):
     data = ByteArray("\0name.\0Variable\0able\0xx\0")
     st = UnpreparedElfStringTable(data=data)
     st = st.prepare(0, 0, 0, 32, "<")
     self.assertEqual(len(st.get_strings()), 5)
     self.assertEqual(st.get_string_idx(1), "name.")
     self.assertEqual(st.get_string_idx(2), "Variable")
     self.assertEqual(st.get_string_idx(3), "able")
     self.assertEqual(st.get_string_idx(4), "xx")
     self.assertEqual(st.get_string_ofs(0), "")
     self.assertEqual(st.get_string_ofs(1), "name.")
     self.assertEqual(st.get_string_ofs(7), "Variable")
     self.assertEqual(st.get_string_ofs(11), "able")
     self.assertEqual(st.get_string_ofs(16), "able")
     self.assertEqual(st.get_file_data(), data)
Ejemplo n.º 5
0
 def test_nulltable(self):
     st = UnpreparedElfStringTable()
     self.assertEqual(st.get_string_idx(0), "")
     self.assertEqual(st.index_of(""), 0)
     self.assertEqual(st.index_of("anything"), None)
     self.assertEqual(st.offset_of(""), 0)
     self.assertEqual(st.offset_of("anything"), None)
     self.assertEqual(st.get_file_data(), array.array("B", "\x00"))
Ejemplo n.º 6
0
 def test_simpletable(self):
     st = UnpreparedElfStringTable()
     self.assertEqual(st.add_string("name."), 1)
     self.assertEqual(st.add_string("Variable"), 7)
     self.assertEqual(st.add_string("able"), 16)
     self.assertEqual(st.add_string("xx"), 21)
     self.assertEqual(len(st.get_strings()), 5)
     self.assertEqual(st.get_string_idx(1), "name.")
     self.assertEqual(st.get_string_idx(2), "Variable")
     self.assertEqual(st.get_string_idx(3), "able")
     self.assertEqual(st.get_string_idx(4), "xx")
     self.assertEqual(st.get_string_ofs(0), "")
     self.assertEqual(st.get_string_ofs(1), "name.")
     self.assertEqual(st.get_string_ofs(7), "Variable")
     self.assertEqual(st.get_string_ofs(11), "able")
     self.assertEqual(st.get_string_ofs(16), "able")
     self.assertEqual(st.get_file_data(), array.array("B", "\0name.\0Variable\0able\0xx\0"))
Ejemplo n.º 7
0
 def test_getstringidx_out_of_bounds(self):
     st = UnpreparedElfStringTable()
     self.assertEqual(st.get_string_idx(1), None)
Ejemplo n.º 8
0
 def test_simpletable(self):
     st = UnpreparedElfStringTable()
     self.assertEqual(st.add_string("name."), 1)
     self.assertEqual(st.add_string("Variable"), 7)
     self.assertEqual(st.add_string("able"), 16)
     self.assertEqual(st.add_string("xx"), 21)
     self.assertEqual(len(st.get_strings()), 5)
     self.assertEqual(st.get_string_idx(1), "name.")
     self.assertEqual(st.get_string_idx(2), "Variable")
     self.assertEqual(st.get_string_idx(3), "able")
     self.assertEqual(st.get_string_idx(4), "xx")
     self.assertEqual(st.get_string_ofs(0), "")
     self.assertEqual(st.get_string_ofs(1), "name.")
     self.assertEqual(st.get_string_ofs(7), "Variable")
     self.assertEqual(st.get_string_ofs(11), "able")
     self.assertEqual(st.get_string_ofs(16), "able")
     self.assertEqual(st.get_file_data(),
                      array.array('B', '\0name.\0Variable\0able\0xx\0'))
Ejemplo n.º 9
0
 def test_getstringidx_out_of_bounds(self):
     st = UnpreparedElfStringTable()
     self.assertEqual(st.get_string_idx(1), None)