Esempio n. 1
0
def test_sections():

    # The sparse memory image we will be testing

    mem_image = SparseMemoryImage()

    # Create first bytearray with some data

    data_ints_a = [random.randint(0, 1000) for r in xrange(10)]
    data_bytes_a = bytearray()
    for data_int in data_ints_a:
        data_bytes_a.extend(struct.pack("<I", data_int))

    # Create a second section section and add it to the sparse memory image

    section_a = SparseMemoryImage.Section(".text", 0x1000, data_bytes_a)
    mem_image.add_section(section_a)

    # Create a second bytearray with some data

    data_ints_b = [random.randint(0, 1000) for r in xrange(10)]
    data_bytes_b = bytearray()
    for data_ints in data_ints_b:
        data_bytes_b.extend(struct.pack("<I", data_int))

    # Create a second section section and add it to the sparse memory
    # image. Use the alternative syntax for adding a section.

    section_b = SparseMemoryImage.Section(".data", 0x2000, data_bytes_b)
    mem_image.add_section(".data", 0x2000, data_bytes_b)

    # Retrieve and check both sections

    section_a_test = mem_image.get_section(".text")
    assert section_a_test == section_a

    section_b_test = mem_image.get_section(".data")
    assert section_b_test == section_b

    # Retrieve sections as a list

    sections_test = mem_image.get_sections()
    assert sections_test == [section_a_test, section_b_test]
def test_sections():

  # The sparse memory image we will be testing

  mem_image = SparseMemoryImage()

  # Create first bytearray with some data

  data_ints_a  = [ random.randint(0,1000) for r in xrange(10) ]
  data_bytes_a = bytearray()
  for data_int in data_ints_a:
    data_bytes_a.extend(struct.pack("<I",data_int))

  # Create a second section section and add it to the sparse memory image

  section_a = SparseMemoryImage.Section( ".text", 0x1000, data_bytes_a )
  mem_image.add_section( section_a )

  # Create a second bytearray with some data

  data_ints_b  = [ random.randint(0,1000) for r in xrange(10) ]
  data_bytes_b = bytearray()
  for data_ints in data_ints_b:
    data_bytes_b.extend(struct.pack("<I",data_int))

  # Create a second section section and add it to the sparse memory
  # image. Use the alternative syntax for adding a section.

  section_b = SparseMemoryImage.Section( ".data", 0x2000, data_bytes_b )
  mem_image.add_section( ".data", 0x2000, data_bytes_b )

  # Retrieve and check both sections

  section_a_test = mem_image.get_section( ".text" )
  assert section_a_test == section_a

  section_b_test = mem_image.get_section( ".data" )
  assert section_b_test == section_b

  # Retrieve sections as a list

  sections_test = mem_image.get_sections()
  assert sections_test == [ section_a_test, section_b_test ]