2017-05-07 20:28:15 +00:00
|
|
|
from __future__ import print_function
|
2017-05-07 21:13:48 +00:00
|
|
|
from __future__ import division
|
|
|
|
from builtins import range
|
|
|
|
from builtins import object
|
2016-05-04 06:21:01 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2017-05-07 21:13:48 +00:00
|
|
|
from mock import *
|
2016-05-06 06:11:06 +00:00
|
|
|
from atrcopy import SegmentData, KBootImage, add_xexboot_header, add_atr_header
|
2016-05-04 06:21:01 +00:00
|
|
|
|
|
|
|
|
2018-06-25 00:20:32 +00:00
|
|
|
class TestKbootHeader:
|
2016-05-04 06:21:01 +00:00
|
|
|
def setup(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def check_size(self, data):
|
2016-05-06 00:44:20 +00:00
|
|
|
xex_size = len(data)
|
|
|
|
bytes = add_xexboot_header(data)
|
2016-05-06 06:11:06 +00:00
|
|
|
# rawdata = SegmentData(bytes)
|
|
|
|
# size = len(rawdata)
|
|
|
|
# atr = KBootImage(rawdata)
|
|
|
|
# newatr = atr.as_new_format("ATR")
|
|
|
|
image_size = len(bytes)
|
|
|
|
bytes = add_atr_header(bytes)
|
2016-05-06 00:44:20 +00:00
|
|
|
rawdata = SegmentData(bytes)
|
2016-05-06 06:11:06 +00:00
|
|
|
newatr = KBootImage(rawdata)
|
|
|
|
image = newatr.bytes
|
2017-05-07 20:28:15 +00:00
|
|
|
print(image[0:16])
|
2017-05-08 18:03:04 +00:00
|
|
|
paragraphs = image_size // 16
|
2017-05-07 20:28:15 +00:00
|
|
|
print(newatr.header, paragraphs)
|
2016-05-06 00:44:20 +00:00
|
|
|
assert int(image[2:4].view(dtype='<u2')) == paragraphs
|
|
|
|
assert int(image[16 + 9:16 + 9 + 2].view('<u2')) == xex_size
|
2016-05-04 06:21:01 +00:00
|
|
|
return image
|
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
for size in range(2000, 40000, 1000):
|
|
|
|
data = np.arange(size, dtype=np.uint8)
|
|
|
|
self.check_size(data)
|
|
|
|
|
|
|
|
def test_real(self):
|
2016-06-06 18:53:55 +00:00
|
|
|
data = np.fromfile("../test_data/air_defense_v18.xex", dtype=np.uint8)
|
2016-05-04 06:21:01 +00:00
|
|
|
image = self.check_size(data)
|
2016-06-06 18:53:55 +00:00
|
|
|
with open("../test_data/air_defense_v18.atr", "wb") as fh:
|
2016-05-04 06:21:01 +00:00
|
|
|
txt = image.tostring()
|
|
|
|
fh.write(txt)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
t = TestKbootHeader()
|
|
|
|
t.setup()
|
|
|
|
t.test_simple()
|
|
|
|
t.test_real()
|