diff --git a/amitools/binfmt/elf/ELFDumper.py b/amitools/binfmt/elf/ELFDumper.py index 77a7e6d5..0df806d6 100644 --- a/amitools/binfmt/elf/ELFDumper.py +++ b/amitools/binfmt/elf/ELFDumper.py @@ -32,7 +32,6 @@ def dump_sections(self, show_relocs=False, show_debug=False): print("ELF Sections") print("id name size rela syms type flags") for sect in self.elf.sections: - # determine number of relocations rela = sect.get_rela() num_rela = len(rela) diff --git a/amitools/fs/ADFSBitmap.py b/amitools/fs/ADFSBitmap.py index 4e91e13e..c22b8159 100644 --- a/amitools/fs/ADFSBitmap.py +++ b/amitools/fs/ADFSBitmap.py @@ -315,7 +315,7 @@ def print_free(self, brief=False): res = self.blkdev.reserved for i in range(self.blkdev.num_blocks): if i >= res and self.get_bit(i): - bm[i] = "F" + bm[i] = ord("F") self.print_draw_bitmap(bm, brief) def print_used(self, brief=False): @@ -323,39 +323,39 @@ def print_used(self, brief=False): res = self.blkdev.reserved for i in range(self.blkdev.num_blocks): if i >= res and not self.get_bit(i): - bm[i] = "#" + bm[i] = ord("#") self.print_draw_bitmap(bm, brief) def draw_on_bitmap(self, bm): # show reserved blocks res = self.blkdev.reserved - bm[0:res] = "x" * res + bm[0:res] = b"x" * res # root block - bm[self.root_blk.blk_num] = "R" + bm[self.root_blk.blk_num] = ord("R") # bitmap blocks for bm_blk in self.bitmap_blks: - bm[bm_blk.blk_num] = "b" + bm[bm_blk.blk_num] = ord("b") # bitmap ext blocks for ext_blk in self.ext_blks: - bm[ext_blk.blk_num] = "B" + bm[ext_blk.blk_num] = ord("B") def print_draw_bitmap(self, bm, brief=False): - line = "" + line = bytearray() blk = 0 blk_cyl = self.blkdev.sectors * self.blkdev.heads found = False for i in range(self.blkdev.num_blocks): c = bm[i] - if ord(c) == 0: - c = "." + if c == 0: + c = ord(".") else: found = True - line += c + line.append(c) if i % self.blkdev.sectors == self.blkdev.sectors - 1: - line += " " + line.append(ord(" ")) if i % blk_cyl == blk_cyl - 1: if not brief or found: - print("%8d: %s" % (blk, line)) + print("%8d: %s" % (blk, line.decode("utf-8"))) blk += blk_cyl - line = "" + line = bytearray() found = False diff --git a/amitools/fs/ADFSDir.py b/amitools/fs/ADFSDir.py index c964a02a..e20b88fa 100644 --- a/amitools/fs/ADFSDir.py +++ b/amitools/fs/ADFSDir.py @@ -374,14 +374,14 @@ def get_path(self, pc, allow_file=True, allow_dir=True): def draw_on_bitmap(self, bm, show_all=False, first=True): blk_num = self.block.blk_num - bm[blk_num] = "D" + bm[blk_num] = ord("D") if show_all or first: self.ensure_entries() for e in self.entries: e.draw_on_bitmap(bm, show_all, False) if self.dcache_blks != None: for dcb in self.dcache_blks: - bm[dcb.blk_num] = "C" + bm[dcb.blk_num] = ord("C") def get_block_nums(self): self.ensure_entries() diff --git a/amitools/fs/ADFSFile.py b/amitools/fs/ADFSFile.py index 803236db..8b58bc9d 100644 --- a/amitools/fs/ADFSFile.py +++ b/amitools/fs/ADFSFile.py @@ -275,11 +275,11 @@ def write(self): left -= bs def draw_on_bitmap(self, bm, show_all=False, first=False): - bm[self.block.blk_num] = "H" + bm[self.block.blk_num] = ord("H") for b in self.ext_blk_nums: - bm[b] = "E" + bm[b] = ord("E") for b in self.data_blk_nums: - bm[b] = "d" + bm[b] = ord("d") def get_block_nums(self): result = [self.block.blk_num] diff --git a/amitools/fs/ADFSVolDir.py b/amitools/fs/ADFSVolDir.py index ce74bb5d..460e70ae 100644 --- a/amitools/fs/ADFSVolDir.py +++ b/amitools/fs/ADFSVolDir.py @@ -18,7 +18,7 @@ def __repr__(self): def draw_on_bitmap(self, bm, show_all=False, first=True): blk_num = self.block.blk_num - bm[blk_num] = "V" + bm[blk_num] = ord("V") if show_all or first: self.ensure_entries() for e in self.entries: diff --git a/amitools/fs/Imager.py b/amitools/fs/Imager.py index ff95fa95..086a2a8c 100644 --- a/amitools/fs/Imager.py +++ b/amitools/fs/Imager.py @@ -17,7 +17,6 @@ class Imager: - META_MODE_NONE = 0 META_MODE_DB = 1 META_MODE_FSUAE = 2 diff --git a/amitools/fs/blkdev/ADFBlockDevice.py b/amitools/fs/blkdev/ADFBlockDevice.py index 79c54007..661d0286 100644 --- a/amitools/fs/blkdev/ADFBlockDevice.py +++ b/amitools/fs/blkdev/ADFBlockDevice.py @@ -2,7 +2,6 @@ class ADFBlockDevice(BlockDevice): - # number of total sectors for DD/HD disks DD_SECS = 80 * 2 * 11 HD_SECS = 80 * 2 * 22 diff --git a/amitools/fs/block/Block.py b/amitools/fs/block/Block.py index 9e146297..391af05d 100644 --- a/amitools/fs/block/Block.py +++ b/amitools/fs/block/Block.py @@ -62,6 +62,9 @@ def is_file_data_block(self): def is_comment_block(self): return self.type == Block.T_COMMENT + def is_dir_cache_block(self): + return self.type == Block.T_DIR_CACHE + def read(self): if self.data == None: self._read_data() diff --git a/amitools/fs/block/BlockFactory.py b/amitools/fs/block/BlockFactory.py new file mode 100644 index 00000000..1f9c28c3 --- /dev/null +++ b/amitools/fs/block/BlockFactory.py @@ -0,0 +1,33 @@ +from .Block import Block +from .RootBlock import RootBlock +from .UserDirBlock import UserDirBlock +from .FileHeaderBlock import FileHeaderBlock +from .FileListBlock import FileListBlock +from .FileDataBlock import FileDataBlock +from .CommentBlock import CommentBlock +from .DirCacheBlock import DirCacheBlock + + +class BlockFactory: + @classmethod + def create_block(cls, blkdev, blk_num, type, sub_type): + if type == Block.T_SHORT: + if sub_type == Block.ST_ROOT: + return RootBlock(blkdev, blk_num) + elif sub_type == Block.ST_USERDIR: + return UserDirBlock(blkdev, blk_num) + elif sub_type == Block.ST_FILE: + return FileHeaderBlock(blkdev, blk_num) + elif type == Block.T_LIST: + if sub_type == Block.ST_FILE: + return FileListBlock(blkdev, blk_num) + elif type == Block.T_DATA: + return FileDataBlock(blkdev, blk_num) + elif type == Block.T_COMMENT: + return CommentBlock(blkdev, blk_num) + elif type == Block.T_DIR_CACHE: + return DirCacheBlock(blkdev, blk_num) + + @classmethod + def create_specific_block(cls, block): + return cls.create_block(block.blkdev, block.blk_num, block.type, block.sub_type) diff --git a/amitools/fs/block/UserDirBlock.py b/amitools/fs/block/UserDirBlock.py index 21d841a8..d18efbd0 100644 --- a/amitools/fs/block/UserDirBlock.py +++ b/amitools/fs/block/UserDirBlock.py @@ -6,7 +6,7 @@ class UserDirBlock(EntryBlock): - def __init__(self, blkdev, blk_num, is_longname): + def __init__(self, blkdev, blk_num, is_longname=False): EntryBlock.__init__( self, blkdev, diff --git a/amitools/rom/rompatcher.py b/amitools/rom/rompatcher.py index 466f7257..4f2b5742 100644 --- a/amitools/rom/rompatcher.py +++ b/amitools/rom/rompatcher.py @@ -137,7 +137,6 @@ def apply_patch(self, access, args): class RomPatcher: - # list of all available patch classes patches = [OneMegRomPatch(), FourMegRomPatch(), BootConRomPatch()] diff --git a/amitools/tools/rdbtool.py b/amitools/tools/rdbtool.py index c777266a..c6323565 100755 --- a/amitools/tools/rdbtool.py +++ b/amitools/tools/rdbtool.py @@ -24,6 +24,7 @@ import amitools.util.ByteSize as ByteSize import amitools.util.VerTag as VerTag + # ----- commands ----- class Command: def __init__(self, args, opts, edit=False): diff --git a/amitools/tools/xdftool.py b/amitools/tools/xdftool.py index 26c2863c..a756571e 100755 --- a/amitools/tools/xdftool.py +++ b/amitools/tools/xdftool.py @@ -14,6 +14,8 @@ from amitools.fs.Repacker import Repacker from amitools.fs.block.BootBlock import BootBlock from amitools.fs.block.RootBlock import RootBlock +from amitools.fs.block.Block import Block +from amitools.fs.block.BlockFactory import BlockFactory from amitools.util.CommandQueue import CommandQueue from amitools.util.HexDump import * import amitools.util.KeyValue as KeyValue @@ -567,7 +569,7 @@ def handle_vol(self, vol): n = len(self.opts) if n == 0: print( - "Usage: block ( boot | root | node [data] | dump )" + "Usage: block ( boot | root | node [data] | dump | decode )" ) return 1 cmd = self.opts[0] @@ -600,6 +602,24 @@ def handle_vol(self, vol): block_no = int(self.opts[1]) data = vol.blkdev.read_block(block_no) print_hex(data) + elif cmd == "decode": + if n == 1: + print("No block number given!") + return 1 + else: + block_no = int(self.opts[1]) + # read block + blk = Block(vol.blkdev, block_no) + blk.read() + if blk.valid: + dec_blk = BlockFactory.create_specific_block(blk) + if dec_blk: + dec_blk.read() + dec_blk.dump() + else: + blk.dump("Unknown") + else: + print("Error reading block!") # ----- Bitmap Tools ----- diff --git a/amitools/vamos/astructs/access.py b/amitools/vamos/astructs/access.py index 6ac56197..c67df06b 100644 --- a/amitools/vamos/astructs/access.py +++ b/amitools/vamos/astructs/access.py @@ -3,7 +3,6 @@ class AccessStruct(object): - _size_to_width = [None, 0, 1, None, 2] def __init__(self, mem, struct_def, struct_addr): diff --git a/amitools/vamos/astructs/astruct.py b/amitools/vamos/astructs/astruct.py index 10ed8a3e..257564f4 100644 --- a/amitools/vamos/astructs/astruct.py +++ b/amitools/vamos/astructs/astruct.py @@ -46,7 +46,6 @@ def get_all_struct_names(self): class FieldDef(FieldDefBase): - _base_offset = 0 _parent_def = None @@ -322,7 +321,6 @@ def _create_field_type(self, field_def): class AmigaStruct(TypeBase): - # overwrite in derived class! _format = None # top-level alias names for subfields diff --git a/amitools/vamos/astructs/astructdef.py b/amitools/vamos/astructs/astructdef.py index 6f2bac18..8ded8959 100644 --- a/amitools/vamos/astructs/astructdef.py +++ b/amitools/vamos/astructs/astructdef.py @@ -39,7 +39,6 @@ def _setup_fields(self, cls, format, type_name): # run through fields for field_type, field_name in format: - # replace self pointers if field_type is APTR_SELF: field_type = APTR(cls) diff --git a/amitools/vamos/lib/dos/MatchFirstNext.py b/amitools/vamos/lib/dos/MatchFirstNext.py index c316a265..04b4d86f 100644 --- a/amitools/vamos/lib/dos/MatchFirstNext.py +++ b/amitools/vamos/lib/dos/MatchFirstNext.py @@ -10,7 +10,6 @@ class MatchFirstNext: - DODIR = 4 DIDDIR = 8 diff --git a/amitools/vamos/lib/lexec/SemaphoreManager.py b/amitools/vamos/lib/lexec/SemaphoreManager.py index 2635bdbd..336ffc04 100644 --- a/amitools/vamos/lib/lexec/SemaphoreManager.py +++ b/amitools/vamos/lib/lexec/SemaphoreManager.py @@ -4,7 +4,6 @@ class SemaphoreManager: - NT_SIGNALSEM = 15 def __init__(self, alloc, mem): diff --git a/amitools/vamos/libcore/profile.py b/amitools/vamos/libcore/profile.py index 3aa8e253..79ccd2e6 100644 --- a/amitools/vamos/libcore/profile.py +++ b/amitools/vamos/libcore/profile.py @@ -241,7 +241,6 @@ def dump(self, name, write=print): class LibProfiler(Profiler): - name = "libs" def __init__(self, names=None, add_calls=False, add_all=False): diff --git a/amitools/vamos/libnative/initstruct.py b/amitools/vamos/libnative/initstruct.py index d145f360..13c15252 100644 --- a/amitools/vamos/libnative/initstruct.py +++ b/amitools/vamos/libnative/initstruct.py @@ -82,7 +82,6 @@ def init_struct(self, init_table_ptr, memory_ptr, size): class InitStructBuilder(object): - SIZE_LONG = 0 SIZE_WORD = 1 SIZE_BYTE = 2 diff --git a/amitools/vamos/libnative/libfuncs.py b/amitools/vamos/libnative/libfuncs.py index 9eab7608..c16796a0 100644 --- a/amitools/vamos/libnative/libfuncs.py +++ b/amitools/vamos/libnative/libfuncs.py @@ -6,7 +6,6 @@ class LibFuncs(object): - LVO_Open = 1 LVO_Close = 2 LVO_Expunge = 3 diff --git a/amitools/vamos/libstructs/util.py b/amitools/vamos/libstructs/util.py index b1836c87..2f55dc2e 100644 --- a/amitools/vamos/libstructs/util.py +++ b/amitools/vamos/libstructs/util.py @@ -5,6 +5,7 @@ ULONG, ) + # TagItem @AmigaStructDef class TagItemStruct(AmigaStruct): diff --git a/amitools/vamos/libtypes/library.py b/amitools/vamos/libtypes/library.py index 49d6119f..22e28bcd 100644 --- a/amitools/vamos/libtypes/library.py +++ b/amitools/vamos/libtypes/library.py @@ -40,7 +40,7 @@ def alloc(cls, alloc, tag=None, pos_size=0, neg_size=0, fd=None, **kwargs): tag=tag, pos_size=pos_size, neg_size=neg_size, - **kwargs + **kwargs, ) diff --git a/amitools/vamos/libtypes/resident.py b/amitools/vamos/libtypes/resident.py index 7d7c3e0c..e98e888d 100644 --- a/amitools/vamos/libtypes/resident.py +++ b/amitools/vamos/libtypes/resident.py @@ -10,7 +10,6 @@ @AmigaClassDef class Resident(ResidentStruct): - RTC_MATCHWORD = 0x4AFC @classmethod diff --git a/test/tools/romtool.py b/test/tools/romtool.py index f4e680b5..9fbd6cdb 100644 --- a/test/tools/romtool.py +++ b/test/tools/romtool.py @@ -1,5 +1,6 @@ import pytest + # tag a parameter for full testing def tag_full(value): return pytest.param(value, marks=pytest.mark.full) diff --git a/test/unit/libnative_initres.py b/test/unit/libnative_initres.py index 568c5603..d2bf63e2 100644 --- a/test/unit/libnative_initres.py +++ b/test/unit/libnative_initres.py @@ -29,6 +29,7 @@ def libnative_initres_init_test(buildlibnix): sp = init_addr - 4 # load lib seglist, addr, size, end = load_lib(alloc, buildlibnix) + # setup init func def init_func(op, pc): assert cpu.r_reg(REG_A0) == seglist.get_baddr() @@ -63,6 +64,7 @@ def libnative_initres_autoinit_test(buildlibnix): sp = init_addr - 4 # load lib seglist, addr, size, end = load_lib(alloc, buildlibnix) + # setup init func def init_func(op, pc): assert cpu.r_reg(REG_A0) == seglist.get_baddr()