mirror of
https://github.com/LIV2/amitools.git
synced 2025-12-05 22:22:45 +00:00
started Python3 conversion
This commit is contained in:
parent
4b93cbd9ad
commit
afac12b413
@ -1,7 +1,10 @@
|
|||||||
sudo: false
|
sudo: false
|
||||||
language: python
|
language: python
|
||||||
python:
|
python:
|
||||||
- "2.7"
|
- "3.4"
|
||||||
|
- "3.5"
|
||||||
|
- "3.6"
|
||||||
|
- "3.7"
|
||||||
env:
|
env:
|
||||||
- PIP=pip
|
- PIP=pip
|
||||||
|
|
||||||
|
|||||||
18
README.md
18
README.md
@ -19,7 +19,7 @@ will be very helpful.
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- Python ```2.7.x```
|
- Python >= ```3.4```
|
||||||
- pip
|
- pip
|
||||||
|
|
||||||
### Optional Packages
|
### Optional Packages
|
||||||
@ -41,17 +41,9 @@ On macOS you have multiple ways of installing ```pip```:
|
|||||||
sudo easy_install pip
|
sudo easy_install pip
|
||||||
```
|
```
|
||||||
|
|
||||||
#### MacPorts Package Manager
|
|
||||||
|
|
||||||
On macOS using [MacPorts][2] package manager (Tool is called ```pip-2.7``` here):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo port install py27-pip
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Homebrew Package Manager
|
#### Homebrew Package Manager
|
||||||
|
|
||||||
With the [Homebrew][3] package manager (```pip``` is included in the ```python``` package):
|
With the [Homebrew][3] package manager (```pip``` is included in the ```python3``` package):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew install python
|
brew install python
|
||||||
@ -76,13 +68,13 @@ python get-pip.py
|
|||||||
|
|
||||||
#### Windows with Visual Studio
|
#### Windows with Visual Studio
|
||||||
|
|
||||||
- Install the latest native Windows Python 2.7.x from [python.org][6]
|
- Install the latest native Windows Python >= 3.4 from [python.org][6]
|
||||||
- There is a special Edition for Visual Studio available that allows
|
- There is a special Edition for Visual Studio available that allows
|
||||||
to compile Python 2.7 modules: Install [VCPython2.7][5]
|
to compile Python 3.x modules: Install [VCpython3][5]
|
||||||
- Open the Command Shell of the Compiler and run
|
- Open the Command Shell of the Compiler and run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd C:\Python27\Scripts
|
cd C:\Python3x\Scripts
|
||||||
pip install amitools
|
pip install amitools
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from elf.BinFmtELF import BinFmtELF
|
|
||||||
from hunk.BinFmtHunk import BinFmtHunk
|
from .elf.BinFmtELF import BinFmtELF
|
||||||
|
from .hunk.BinFmtHunk import BinFmtHunk
|
||||||
|
|
||||||
class BinFmt:
|
class BinFmt:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@ -180,7 +180,7 @@ class Segment:
|
|||||||
self.relocs[to_seg] = relocs
|
self.relocs[to_seg] = relocs
|
||||||
|
|
||||||
def get_reloc_to_segs(self):
|
def get_reloc_to_segs(self):
|
||||||
keys = self.relocs.keys()
|
keys = list(self.relocs.keys())
|
||||||
return sorted(keys, key=lambda x: x.id)
|
return sorted(keys, key=lambda x: x.id)
|
||||||
|
|
||||||
def get_reloc(self, to_seg):
|
def get_reloc(self, to_seg):
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from amitools.util.DisAsm import DisAsm
|
from amitools.util.DisAsm import DisAsm
|
||||||
from BinImage import *
|
from .BinImage import *
|
||||||
|
|
||||||
class Disassemble:
|
class Disassemble:
|
||||||
"""allows to disassemble code segments of a BinImage"""
|
"""allows to disassemble code segments of a BinImage"""
|
||||||
@ -45,7 +45,7 @@ class Disassemble:
|
|||||||
result.append(line)
|
result.append(line)
|
||||||
|
|
||||||
# create final line
|
# create final line
|
||||||
line = "%08x\t%-20s\t%-30s " % (addr," ".join(map(lambda x: "%04x" %x, word)),code)
|
line = "%08x\t%-20s\t%-30s " % (addr," ".join(["%04x" %x for x in word]),code)
|
||||||
|
|
||||||
# create line info
|
# create line info
|
||||||
size = len(word) * 2
|
size = len(word) * 2
|
||||||
@ -63,7 +63,7 @@ class Disassemble:
|
|||||||
# mini test
|
# mini test
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
from BinFmt import BinFmt
|
from .BinFmt import BinFmt
|
||||||
bf = BinFmt()
|
bf = BinFmt()
|
||||||
for a in sys.argv[1:]:
|
for a in sys.argv[1:]:
|
||||||
bi = bf.load_image(a)
|
bi = bf.load_image(a)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import print_function
|
|
||||||
from BinImage import *
|
from .BinImage import *
|
||||||
import amitools.util.HexDump as HexDump
|
import amitools.util.HexDump as HexDump
|
||||||
|
|
||||||
class Dumper:
|
class Dumper:
|
||||||
@ -49,7 +49,7 @@ class Dumper:
|
|||||||
# mini test
|
# mini test
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
from BinFmt import BinFmt
|
from .BinFmt import BinFmt
|
||||||
bf = BinFmt()
|
bf = BinFmt()
|
||||||
for a in sys.argv[1:]:
|
for a in sys.argv[1:]:
|
||||||
bi = bf.load_image(a)
|
bi = bf.load_image(a)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from __future__ import print_function
|
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
class Relocate:
|
class Relocate:
|
||||||
@ -104,7 +104,7 @@ class Relocate:
|
|||||||
# mini test
|
# mini test
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
from BinFmt import BinFmt
|
from .BinFmt import BinFmt
|
||||||
bf = BinFmt()
|
bf = BinFmt()
|
||||||
for a in sys.argv[1:]:
|
for a in sys.argv[1:]:
|
||||||
bi = bf.load_image(a)
|
bi = bf.load_image(a)
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from amitools.binfmt.BinImage import *
|
from amitools.binfmt.BinImage import *
|
||||||
from ELFFile import *
|
from .ELFFile import *
|
||||||
from ELF import *
|
from .ELF import *
|
||||||
from ELFReader import ELFReader
|
from .ELFReader import ELFReader
|
||||||
from DwarfDebugLine import DwarfDebugLine
|
from .DwarfDebugLine import DwarfDebugLine
|
||||||
|
|
||||||
|
|
||||||
class BinFmtELF:
|
class BinFmtELF:
|
||||||
@ -66,14 +66,14 @@ class BinFmtELF:
|
|||||||
seg_type = None
|
seg_type = None
|
||||||
name = sect.name_str
|
name = sect.name_str
|
||||||
flags = 0
|
flags = 0
|
||||||
if name == '.text':
|
if name == b'.text':
|
||||||
seg_type = SEGMENT_TYPE_CODE
|
seg_type = SEGMENT_TYPE_CODE
|
||||||
elif name == '.data':
|
elif name == b'.data':
|
||||||
seg_type = SEGMENT_TYPE_DATA
|
seg_type = SEGMENT_TYPE_DATA
|
||||||
elif name == '.rodata':
|
elif name == b'.rodata':
|
||||||
seg_type = SEGMENT_TYPE_DATA
|
seg_type = SEGMENT_TYPE_DATA
|
||||||
flags = SEGMENT_FLAG_READ_ONLY
|
flags = SEGMENT_FLAG_READ_ONLY
|
||||||
elif name == '.bss':
|
elif name == b'.bss':
|
||||||
seg_type = SEGMENT_TYPE_BSS
|
seg_type = SEGMENT_TYPE_BSS
|
||||||
# we got a segment
|
# we got a segment
|
||||||
if seg_type is not None:
|
if seg_type is not None:
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import print_function
|
|
||||||
import StringIO
|
import io
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
class LineState:
|
class LineState:
|
||||||
@ -52,7 +52,7 @@ class DwarfDebugLine:
|
|||||||
# get (optional) relocations
|
# get (optional) relocations
|
||||||
rela = elf_file.get_section_by_name(".rela.debug_line")
|
rela = elf_file.get_section_by_name(".rela.debug_line")
|
||||||
# start parsing
|
# start parsing
|
||||||
self.input = StringIO.StringIO(debug_line.data)
|
self.input = io.StringIO(debug_line.data)
|
||||||
# decode header
|
# decode header
|
||||||
if not self.decode_header():
|
if not self.decode_header():
|
||||||
return False
|
return False
|
||||||
@ -308,7 +308,7 @@ class DwarfDebugLine:
|
|||||||
# mini test
|
# mini test
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
from ELFReader import ELFReader
|
from .ELFReader import ELFReader
|
||||||
reader = ELFReader()
|
reader = ELFReader()
|
||||||
for a in sys.argv[1:]:
|
for a in sys.argv[1:]:
|
||||||
f = open(a, "rb")
|
f = open(a, "rb")
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from ELF import *
|
from .ELF import *
|
||||||
|
|
||||||
class ELFDumper:
|
class ELFDumper:
|
||||||
|
|
||||||
@ -13,14 +13,14 @@ class ELFDumper:
|
|||||||
sym_txt = "%s (%d) + %d" % (rel_symbol.name_str, rel_symbol.idx, rel.addend)
|
sym_txt = "%s (%d) + %d" % (rel_symbol.name_str, rel_symbol.idx, rel.addend)
|
||||||
else:
|
else:
|
||||||
sym_txt = ""
|
sym_txt = ""
|
||||||
print "%s%08x %-10s %-20s %s" % (prefix, rel.offset, rel.type_str, sect_txt, sym_txt)
|
print("%s%08x %-10s %-20s %s" % (prefix, rel.offset, rel.type_str, sect_txt, sym_txt))
|
||||||
|
|
||||||
def _dump_symbol(self, sym):
|
def _dump_symbol(self, sym):
|
||||||
print "\t\t\t%08x %6d %-8s %-8s %-16s" % (sym.value, sym.size, sym.type_str, sym.bind_str, sym.name_str)
|
print("\t\t\t%08x %6d %-8s %-8s %-16s" % (sym.value, sym.size, sym.type_str, sym.bind_str, sym.name_str))
|
||||||
|
|
||||||
def dump_sections(self, show_relocs=False, show_debug=False):
|
def dump_sections(self, show_relocs=False, show_debug=False):
|
||||||
print "ELF Sections"
|
print("ELF Sections")
|
||||||
print "id name size rela syms type flags"
|
print("id name size rela syms type flags")
|
||||||
for sect in self.elf.sections:
|
for sect in self.elf.sections:
|
||||||
|
|
||||||
# determine number of relocations
|
# determine number of relocations
|
||||||
@ -31,69 +31,69 @@ class ELFDumper:
|
|||||||
symbols = sect.get_symbols()
|
symbols = sect.get_symbols()
|
||||||
num_syms = len(symbols)
|
num_syms = len(symbols)
|
||||||
|
|
||||||
print "%2d %-16s %08x %4d %4d %-10s %s" % \
|
print("%2d %-16s %08x %4d %4d %-10s %s" % \
|
||||||
(sect.idx, sect.name_str, sect.header.size, num_rela, num_syms,
|
(sect.idx, sect.name_str, sect.header.size, num_rela, num_syms,
|
||||||
sect.header.type_str, ",".join(sect.header.flags_dec))
|
sect.header.type_str, ",".join(sect.header.flags_dec)))
|
||||||
|
|
||||||
# show relas
|
# show relas
|
||||||
if show_relocs and num_rela > 0:
|
if show_relocs and num_rela > 0:
|
||||||
print "\t\tRelocations:"
|
print("\t\tRelocations:")
|
||||||
for rel in rela:
|
for rel in rela:
|
||||||
self._dump_rela_entry(rel)
|
self._dump_rela_entry(rel)
|
||||||
|
|
||||||
# per segment relocations
|
# per segment relocations
|
||||||
for tgt_sect in sect.get_rela_sections():
|
for tgt_sect in sect.get_rela_sections():
|
||||||
print "\t\tTo Section #%d:" % tgt_sect.idx
|
print("\t\tTo Section #%d:" % tgt_sect.idx)
|
||||||
for rel in sect.get_rela_by_section(tgt_sect):
|
for rel in sect.get_rela_by_section(tgt_sect):
|
||||||
self._dump_rela_entry(rel)
|
self._dump_rela_entry(rel)
|
||||||
|
|
||||||
# show symbols
|
# show symbols
|
||||||
if show_debug and num_syms > 0:
|
if show_debug and num_syms > 0:
|
||||||
print "\t\tSymbols:"
|
print("\t\tSymbols:")
|
||||||
for sym in symbols:
|
for sym in symbols:
|
||||||
self._dump_symbol(sym)
|
self._dump_symbol(sym)
|
||||||
|
|
||||||
def dump_symbols(self):
|
def dump_symbols(self):
|
||||||
print "ELF Symbol Table"
|
print("ELF Symbol Table")
|
||||||
symtabs = self.elf.symtabs
|
symtabs = self.elf.symtabs
|
||||||
if len(symtabs) == 0:
|
if len(symtabs) == 0:
|
||||||
print "no symbols"
|
print("no symbols")
|
||||||
return
|
return
|
||||||
|
|
||||||
print "idx value size type bind visible ndx name"
|
print("idx value size type bind visible ndx name")
|
||||||
for symtab in symtabs:
|
for symtab in symtabs:
|
||||||
for sym in symtab.get_table_symbols():
|
for sym in symtab.get_table_symbols():
|
||||||
txt = sym.shndx_str
|
txt = sym.shndx_str
|
||||||
if txt is None:
|
if txt is None:
|
||||||
txt =sym.section.name_str
|
txt =sym.section.name_str
|
||||||
print "%4d %08x %6d %-8s %-8s %-8s %-16s %s" % \
|
print("%4d %08x %6d %-8s %-8s %-8s %-16s %s" % \
|
||||||
(sym.idx, sym.value, sym.size, sym.type_str,
|
(sym.idx, sym.value, sym.size, sym.type_str,
|
||||||
sym.bind_str, sym.visibility_str,
|
sym.bind_str, sym.visibility_str,
|
||||||
txt, sym.name_str)
|
txt, sym.name_str))
|
||||||
|
|
||||||
def dump_relas(self):
|
def dump_relas(self):
|
||||||
print "ELF Relocations"
|
print("ELF Relocations")
|
||||||
rela_sects = self.elf.relas
|
rela_sects = self.elf.relas
|
||||||
if len(rela_sects) == 0:
|
if len(rela_sects) == 0:
|
||||||
print "no relocations"
|
print("no relocations")
|
||||||
return
|
return
|
||||||
|
|
||||||
for rela_sect in rela_sects:
|
for rela_sect in rela_sects:
|
||||||
print rela_sect.name_str, "linked to", rela_sect.reloc_section.name_str
|
print(rela_sect.name_str, "linked to", rela_sect.reloc_section.name_str)
|
||||||
print " offset type segment + addend symbol + addend"
|
print(" offset type segment + addend symbol + addend")
|
||||||
num = 0
|
num = 0
|
||||||
for rela in rela_sect.get_relocations():
|
for rela in rela_sect.get_relocations():
|
||||||
self._dump_rela_entry(rela, prefix="%4d " % num)
|
self._dump_rela_entry(rela, prefix="%4d " % num)
|
||||||
num += 1
|
num += 1
|
||||||
|
|
||||||
def dump_relas_by_sect(self):
|
def dump_relas_by_sect(self):
|
||||||
print "ELF Relocations (by sections)"
|
print("ELF Relocations (by sections)")
|
||||||
for sect in self.elf.sections:
|
for sect in self.elf.sections:
|
||||||
to_sects = sect.get_rela_sections()
|
to_sects = sect.get_rela_sections()
|
||||||
if len(to_sects) > 0:
|
if len(to_sects) > 0:
|
||||||
print " section", sect.idx
|
print(" section", sect.idx)
|
||||||
for to_sect in to_sects:
|
for to_sect in to_sects:
|
||||||
print " -> section", to_sect.idx
|
print(" -> section", to_sect.idx)
|
||||||
num = 0
|
num = 0
|
||||||
for rela in sect.get_rela_by_section(to_sect):
|
for rela in sect.get_rela_by_section(to_sect):
|
||||||
self._dump_rela_entry(rela, prefix=" %4d " % num)
|
self._dump_rela_entry(rela, prefix=" %4d " % num)
|
||||||
@ -101,7 +101,7 @@ class ELFDumper:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from ELFReader import ELFReader
|
from .ELFReader import ELFReader
|
||||||
import sys
|
import sys
|
||||||
reader = ELFReader()
|
reader = ELFReader()
|
||||||
for a in sys.argv[1:]:
|
for a in sys.argv[1:]:
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import struct
|
import struct
|
||||||
from ELF import *
|
from .ELF import *
|
||||||
|
|
||||||
|
|
||||||
class ELFParseError(Exception):
|
class ELFParseError(Exception):
|
||||||
@ -23,7 +23,7 @@ class ELFPart:
|
|||||||
decoded = struct.unpack(">"+fmt, data)
|
decoded = struct.unpack(">"+fmt, data)
|
||||||
if len(decoded) != nlen:
|
if len(decoded) != nlen:
|
||||||
raise ELFParseError("data decode error")
|
raise ELFParseError("data decode error")
|
||||||
for i in xrange(nlen):
|
for i in range(nlen):
|
||||||
setattr(self, self._names[i], decoded[i])
|
setattr(self, self._names[i], decoded[i])
|
||||||
|
|
||||||
def _decode_flags(self, value, names):
|
def _decode_flags(self, value, names):
|
||||||
@ -34,7 +34,7 @@ class ELFPart:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def _decode_value(self, value, names):
|
def _decode_value(self, value, names):
|
||||||
if names.has_key(value):
|
if value in names:
|
||||||
return names[value]
|
return names[value]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@ -49,13 +49,13 @@ class ELFIdentifier(ELFPart):
|
|||||||
def parse(self, ident_data):
|
def parse(self, ident_data):
|
||||||
# magic
|
# magic
|
||||||
magic = ident_data[0:4]
|
magic = ident_data[0:4]
|
||||||
if magic != "\177ELF":
|
if magic != b"\177ELF":
|
||||||
raise ELFParseError("No ELF Magic found!")
|
raise ELFParseError("No ELF Magic found!")
|
||||||
self.class_ = ord(ident_data[4])
|
self.class_ = ident_data[4]
|
||||||
self.data = ord(ident_data[5])
|
self.data = ident_data[5]
|
||||||
self.version = ord(ident_data[6])
|
self.version = ident_data[6]
|
||||||
self.osabi = ord(ident_data[7])
|
self.osabi = ident_data[7]
|
||||||
self.abiversion = ord(ident_data[8])
|
self.abiversion = ident_data[8]
|
||||||
|
|
||||||
|
|
||||||
class ELFHeader(ELFPart):
|
class ELFHeader(ELFPart):
|
||||||
@ -104,13 +104,13 @@ class ELFSection:
|
|||||||
|
|
||||||
def get_rela_by_section(self, sect):
|
def get_rela_by_section(self, sect):
|
||||||
"""return a list of relocations from the given section"""
|
"""return a list of relocations from the given section"""
|
||||||
if self.reloc_by_sect.has_key(sect):
|
if sect in self.reloc_by_sect:
|
||||||
return self.reloc_by_sect[sect]
|
return self.reloc_by_sect[sect]
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_rela_sections(self):
|
def get_rela_sections(self):
|
||||||
return sorted(self.reloc_by_sect.keys(), key=lambda x : x.idx)
|
return sorted(list(self.reloc_by_sect.keys()), key=lambda x : x.idx)
|
||||||
|
|
||||||
def get_symbols(self):
|
def get_symbols(self):
|
||||||
return self.symbols
|
return self.symbols
|
||||||
@ -132,7 +132,7 @@ class ELFSectionStringTable(ELFSectionWithData):
|
|||||||
o = 0
|
o = 0
|
||||||
strtab = []
|
strtab = []
|
||||||
while o < l:
|
while o < l:
|
||||||
n = self.data.find('\0',o)
|
n = self.data.find(b'\0',o)
|
||||||
if n == -1:
|
if n == -1:
|
||||||
raise ELFParseError("Invalid strtab!")
|
raise ELFParseError("Invalid strtab!")
|
||||||
if n > 0:
|
if n > 0:
|
||||||
@ -188,12 +188,12 @@ class ELFSectionSymbolTable(ELFSectionWithData):
|
|||||||
|
|
||||||
def decode(self):
|
def decode(self):
|
||||||
entsize = self.header.entsize
|
entsize = self.header.entsize
|
||||||
num = self.header.size / entsize
|
num = self.header.size // entsize
|
||||||
symtab = []
|
symtab = []
|
||||||
self.symtab = symtab
|
self.symtab = symtab
|
||||||
off = 0
|
off = 0
|
||||||
idx = 0
|
idx = 0
|
||||||
for n in xrange(num):
|
for n in range(num):
|
||||||
entry = ELFSymbol(idx)
|
entry = ELFSymbol(idx)
|
||||||
entry_data = self.data[off:off+entsize]
|
entry_data = self.data[off:off+entsize]
|
||||||
entry.parse(entry_data)
|
entry.parse(entry_data)
|
||||||
@ -237,11 +237,11 @@ class ELFSectionRelocationsWithAddend(ELFSectionWithData):
|
|||||||
|
|
||||||
def decode(self):
|
def decode(self):
|
||||||
entsize = self.header.entsize
|
entsize = self.header.entsize
|
||||||
num = self.header.size / entsize
|
num = self.header.size // entsize
|
||||||
rela = []
|
rela = []
|
||||||
self.rela = rela
|
self.rela = rela
|
||||||
off = 0
|
off = 0
|
||||||
for n in xrange(num):
|
for n in range(num):
|
||||||
entry = ELFRelocationWithAddend()
|
entry = ELFRelocationWithAddend()
|
||||||
entry_data = self.data[off:off+entsize]
|
entry_data = self.data[off:off+entsize]
|
||||||
entry.parse(entry_data)
|
entry.parse(entry_data)
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import struct
|
import struct
|
||||||
import os
|
import os
|
||||||
from ELF import *
|
from .ELF import *
|
||||||
from ELFFile import *
|
from .ELFFile import *
|
||||||
|
|
||||||
|
|
||||||
class ELFReader:
|
class ELFReader:
|
||||||
@ -13,7 +13,7 @@ class ELFReader:
|
|||||||
shentsize = ef.header.shentsize
|
shentsize = ef.header.shentsize
|
||||||
f.seek(shoff, os.SEEK_SET)
|
f.seek(shoff, os.SEEK_SET)
|
||||||
shnum = ef.header.shnum
|
shnum = ef.header.shnum
|
||||||
for i in xrange(shnum):
|
for i in range(shnum):
|
||||||
sh = ELFSectionHeader()
|
sh = ELFSectionHeader()
|
||||||
sh_data = f.read(shentsize)
|
sh_data = f.read(shentsize)
|
||||||
sh.parse(sh_data)
|
sh.parse(sh_data)
|
||||||
@ -141,7 +141,7 @@ class ELFReader:
|
|||||||
|
|
||||||
# add entry to section list
|
# add entry to section list
|
||||||
tgt_sect = entry.section
|
tgt_sect = entry.section
|
||||||
if by_sect.has_key(tgt_sect):
|
if tgt_sect in by_sect:
|
||||||
by_sect_list = by_sect[tgt_sect]
|
by_sect_list = by_sect[tgt_sect]
|
||||||
else:
|
else:
|
||||||
by_sect_list = []
|
by_sect_list = []
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
from ELFDumper import ELFDumper
|
from .ELFDumper import ELFDumper
|
||||||
from ELFReader import ELFReader
|
from .ELFReader import ELFReader
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from amitools.binfmt.BinImage import *
|
from amitools.binfmt.BinImage import *
|
||||||
from HunkBlockFile import HunkBlockFile, HunkParseError
|
from .HunkBlockFile import HunkBlockFile, HunkParseError
|
||||||
from HunkLoadSegFile import HunkLoadSegFile, HunkSegment
|
from .HunkLoadSegFile import HunkLoadSegFile, HunkSegment
|
||||||
from HunkDebug import *
|
from .HunkDebug import *
|
||||||
import Hunk
|
from . import Hunk
|
||||||
|
|
||||||
class BinFmtHunk:
|
class BinFmtHunk:
|
||||||
"""Handle Amiga's native Hunk file format"""
|
"""Handle Amiga's native Hunk file format"""
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
"""The hunk block types defined as data classes"""
|
"""The hunk block types defined as data classes"""
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
from Hunk import *
|
from .Hunk import *
|
||||||
|
|
||||||
|
|
||||||
class HunkParseError(Exception):
|
class HunkParseError(Exception):
|
||||||
@ -49,7 +49,7 @@ class HunkBlock:
|
|||||||
data = f.read(size)
|
data = f.read(size)
|
||||||
if len(data) < size:
|
if len(data) < size:
|
||||||
return -1,None
|
return -1,None
|
||||||
endpos = data.find('\0')
|
endpos = data.find(b'\0')
|
||||||
if endpos == -1:
|
if endpos == -1:
|
||||||
return size,data
|
return size,data
|
||||||
elif endpos == 0:
|
elif endpos == 0:
|
||||||
@ -118,7 +118,7 @@ class HunkHeaderBlock(HunkBlock):
|
|||||||
|
|
||||||
# determine number of hunks in size table
|
# determine number of hunks in size table
|
||||||
num_hunks = self.last_hunk - self.first_hunk + 1
|
num_hunks = self.last_hunk - self.first_hunk + 1
|
||||||
for a in xrange(num_hunks):
|
for a in range(num_hunks):
|
||||||
hunk_size = self._read_long(f)
|
hunk_size = self._read_long(f)
|
||||||
if hunk_size < 0:
|
if hunk_size < 0:
|
||||||
raise HunkParseError("HUNK_HEADER contains invalid hunk_size")
|
raise HunkParseError("HUNK_HEADER contains invalid hunk_size")
|
||||||
@ -178,7 +178,7 @@ class HunkRelocLongBlock(HunkBlock):
|
|||||||
break
|
break
|
||||||
hunk_num = self._read_long(f)
|
hunk_num = self._read_long(f)
|
||||||
offsets = []
|
offsets = []
|
||||||
for i in xrange(num):
|
for i in range(num):
|
||||||
off = self._read_long(f)
|
off = self._read_long(f)
|
||||||
offsets.append(off)
|
offsets.append(off)
|
||||||
self.relocs.append((hunk_num, offsets))
|
self.relocs.append((hunk_num, offsets))
|
||||||
@ -214,7 +214,7 @@ class HunkRelocWordBlock(HunkBlock):
|
|||||||
hunk_num = self._read_word(f)
|
hunk_num = self._read_word(f)
|
||||||
num_words += num_offs + 1
|
num_words += num_offs + 1
|
||||||
offsets = []
|
offsets = []
|
||||||
for i in xrange(num_offs):
|
for i in range(num_offs):
|
||||||
off = self._read_word(f)
|
off = self._read_word(f)
|
||||||
offsets.append(off)
|
offsets.append(off)
|
||||||
self.relocs.append((hunk_num, offsets))
|
self.relocs.append((hunk_num, offsets))
|
||||||
@ -228,7 +228,7 @@ class HunkRelocWordBlock(HunkBlock):
|
|||||||
num_offs = len(offsets)
|
num_offs = len(offsets)
|
||||||
self._write_word(f, num_offs)
|
self._write_word(f, num_offs)
|
||||||
self._write_word(f, hunk_num)
|
self._write_word(f, hunk_num)
|
||||||
for i in xrange(num_offs):
|
for i in range(num_offs):
|
||||||
self._write_word(f, offsets[i])
|
self._write_word(f, offsets[i])
|
||||||
num_words += 2 + num_offs
|
num_words += 2 + num_offs
|
||||||
# end
|
# end
|
||||||
@ -382,7 +382,7 @@ class HunkExtBlock(HunkBlock):
|
|||||||
elif ext_type >= 0x80:
|
elif ext_type >= 0x80:
|
||||||
num_refs = self._read_long(f)
|
num_refs = self._read_long(f)
|
||||||
offsets = []
|
offsets = []
|
||||||
for i in xrange(num_refs):
|
for i in range(num_refs):
|
||||||
off = self._read_long(f)
|
off = self._read_long(f)
|
||||||
offsets.append(off)
|
offsets.append(off)
|
||||||
# is a definition
|
# is a definition
|
||||||
@ -523,7 +523,7 @@ class HunkIndexBlock(HunkBlock):
|
|||||||
num_words -= 3
|
num_words -= 3
|
||||||
unit_entry = HunkIndexUnitEntry(name_off, first_hunk_long_off)
|
unit_entry = HunkIndexUnitEntry(name_off, first_hunk_long_off)
|
||||||
self.units.append(unit_entry)
|
self.units.append(unit_entry)
|
||||||
for i in xrange(num_hunks):
|
for i in range(num_hunks):
|
||||||
# hunk description
|
# hunk description
|
||||||
name_off = self._read_word(f)
|
name_off = self._read_word(f)
|
||||||
hunk_longs = self._read_word(f)
|
hunk_longs = self._read_word(f)
|
||||||
@ -532,12 +532,12 @@ class HunkIndexBlock(HunkBlock):
|
|||||||
unit_entry.index_hunks.append(hunk_entry)
|
unit_entry.index_hunks.append(hunk_entry)
|
||||||
# refs
|
# refs
|
||||||
num_refs = self._read_word(f)
|
num_refs = self._read_word(f)
|
||||||
for j in xrange(num_refs):
|
for j in range(num_refs):
|
||||||
name_off = self._read_word(f)
|
name_off = self._read_word(f)
|
||||||
hunk_entry.sym_refs.append(HunkIndexSymbolRef(name_off))
|
hunk_entry.sym_refs.append(HunkIndexSymbolRef(name_off))
|
||||||
# defs
|
# defs
|
||||||
num_defs = self._read_word(f)
|
num_defs = self._read_word(f)
|
||||||
for j in xrange(num_defs):
|
for j in range(num_defs):
|
||||||
name_off = self._read_word(f)
|
name_off = self._read_word(f)
|
||||||
value = self._read_word(f)
|
value = self._read_word(f)
|
||||||
stype = self._read_word(f)
|
stype = self._read_word(f)
|
||||||
@ -735,20 +735,20 @@ class HunkBlockFile:
|
|||||||
# mini test
|
# mini test
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
import StringIO
|
import io
|
||||||
for a in sys.argv[1:]:
|
for a in sys.argv[1:]:
|
||||||
# read data
|
# read data
|
||||||
f = open(a, "rb")
|
f = open(a, "rb")
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
# parse from string stream
|
# parse from string stream
|
||||||
fobj = StringIO.StringIO(data)
|
fobj = io.StringIO(data)
|
||||||
hbf = HunkBlockFile()
|
hbf = HunkBlockFile()
|
||||||
hbf.read(fobj, True)
|
hbf.read(fobj, True)
|
||||||
fobj.close()
|
fobj.close()
|
||||||
print(hbf.blocks)
|
print(hbf.blocks)
|
||||||
# write to new string stream
|
# write to new string stream
|
||||||
nobj = StringIO.StringIO()
|
nobj = io.StringIO()
|
||||||
hbf.write(nobj, True)
|
hbf.write(nobj, True)
|
||||||
new_data = nobj.getvalue()
|
new_data = nobj.getvalue()
|
||||||
nobj.close()
|
nobj.close()
|
||||||
@ -760,7 +760,7 @@ if __name__ == '__main__':
|
|||||||
if len(data) != len(new_data):
|
if len(data) != len(new_data):
|
||||||
print("MISMATCH", len(data), len(new_data))
|
print("MISMATCH", len(data), len(new_data))
|
||||||
else:
|
else:
|
||||||
for i in xrange(len(data)):
|
for i in range(len(data)):
|
||||||
if data[i] != new_data[i]:
|
if data[i] != new_data[i]:
|
||||||
print("MISMATCH @%x" % i)
|
print("MISMATCH @%x" % i)
|
||||||
print("OK")
|
print("OK")
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
from __future__ import print_function
|
|
||||||
import struct
|
import struct
|
||||||
import StringIO
|
import io
|
||||||
|
|
||||||
|
|
||||||
class HunkDebugLineEntry:
|
class HunkDebugLineEntry:
|
||||||
@ -56,7 +56,7 @@ class HunkDebugAny:
|
|||||||
class HunkDebug:
|
class HunkDebug:
|
||||||
def encode(self, debug_info):
|
def encode(self, debug_info):
|
||||||
"""encode a debug info and return a debug_data chunk"""
|
"""encode a debug info and return a debug_data chunk"""
|
||||||
out = StringIO.StringIO()
|
out = io.StringIO()
|
||||||
# +0: base offset
|
# +0: base offset
|
||||||
self._write_long(out, debug_info.base_offset)
|
self._write_long(out, debug_info.base_offset)
|
||||||
# +4: type tag
|
# +4: type tag
|
||||||
@ -140,7 +140,7 @@ class HunkDebug:
|
|||||||
# ----- mini test -----
|
# ----- mini test -----
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
from HunkBlockFile import HunkBlockFile, HunkDebugBlock
|
from .HunkBlockFile import HunkBlockFile, HunkDebugBlock
|
||||||
hd = HunkDebug()
|
hd = HunkDebug()
|
||||||
for a in sys.argv[1:]:
|
for a in sys.argv[1:]:
|
||||||
hbf = HunkBlockFile()
|
hbf = HunkBlockFile()
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from amitools.util.DisAsm import DisAsm
|
from amitools.util.DisAsm import DisAsm
|
||||||
import Hunk
|
from . import Hunk
|
||||||
|
|
||||||
class HunkDisassembler:
|
class HunkDisassembler:
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ class HunkDisassembler:
|
|||||||
def find_reloc(self, hunk, addr, word):
|
def find_reloc(self, hunk, addr, word):
|
||||||
end_addr = addr + len(word) * 2
|
end_addr = addr + len(word) * 2
|
||||||
for h in hunk[1:]:
|
for h in hunk[1:]:
|
||||||
valid = self.map_reloc_to_num_words.has_key(h['type'])
|
valid = h['type'] in self.map_reloc_to_num_words
|
||||||
if valid:
|
if valid:
|
||||||
num_words = self.map_reloc_to_num_words[h['type']]
|
num_words = self.map_reloc_to_num_words[h['type']]
|
||||||
reloc = h['reloc']
|
reloc = h['reloc']
|
||||||
@ -86,7 +86,7 @@ class HunkDisassembler:
|
|||||||
|
|
||||||
# calc offset
|
# calc offset
|
||||||
addr = 0
|
addr = 0
|
||||||
for i in xrange(num_words):
|
for i in range(num_words):
|
||||||
addr = addr * 0x10000 + word[word_offset+i]
|
addr = addr * 0x10000 + word[word_offset+i]
|
||||||
|
|
||||||
reloc_type_name = h['type_name'].replace("HUNK_","").lower()
|
reloc_type_name = h['type_name'].replace("HUNK_","").lower()
|
||||||
@ -111,7 +111,7 @@ class HunkDisassembler:
|
|||||||
if h['type'] == Hunk.HUNK_EXT:
|
if h['type'] == Hunk.HUNK_EXT:
|
||||||
for ext in h['ext_ref']:
|
for ext in h['ext_ref']:
|
||||||
refs = ext['refs']
|
refs = ext['refs']
|
||||||
valid = self.map_ext_ref_to_num_words.has_key(ext['type'])
|
valid = ext['type'] in self.map_ext_ref_to_num_words
|
||||||
if valid:
|
if valid:
|
||||||
num_words = self.map_ext_ref_to_num_words[ext['type']]
|
num_words = self.map_ext_ref_to_num_words[ext['type']]
|
||||||
for ref in refs:
|
for ref in refs:
|
||||||
@ -133,9 +133,9 @@ class HunkDisassembler:
|
|||||||
# search the index of a lib for a definition
|
# search the index of a lib for a definition
|
||||||
def find_index_def(self, hunk, addr):
|
def find_index_def(self, hunk, addr):
|
||||||
main = hunk[0]
|
main = hunk[0]
|
||||||
if main.has_key('index_hunk'):
|
if 'index_hunk' in main:
|
||||||
info = main['index_hunk']
|
info = main['index_hunk']
|
||||||
if info.has_key('defs'):
|
if 'defs' in info:
|
||||||
for d in info['defs']:
|
for d in info['defs']:
|
||||||
if d['value'] == addr:
|
if d['value'] == addr:
|
||||||
return d['name']
|
return d['name']
|
||||||
@ -203,7 +203,7 @@ class HunkDisassembler:
|
|||||||
|
|
||||||
# create final line
|
# create final line
|
||||||
if symbol != None:
|
if symbol != None:
|
||||||
print "\t\t\t\t%s:" % symbol
|
print("\t\t\t\t%s:" % symbol)
|
||||||
print "%08x\t%-20s\t%-30s %s" % (addr," ".join(map(lambda x: "%04x" %x, word)),code,comment)
|
print("%08x\t%-20s\t%-30s %s" % (addr," ".join(["%04x" %x for x in word]),code,comment))
|
||||||
|
|
||||||
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
from __future__ import print_function
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from HunkBlockFile import *
|
|
||||||
from HunkDebug import HunkDebug
|
|
||||||
|
from .HunkBlockFile import *
|
||||||
|
from .HunkDebug import HunkDebug
|
||||||
|
|
||||||
|
|
||||||
class HunkSegment:
|
class HunkSegment:
|
||||||
@ -227,7 +227,7 @@ class HunkLoadSegFile:
|
|||||||
self.segments.append(seg)
|
self.segments.append(seg)
|
||||||
# set size in segments
|
# set size in segments
|
||||||
n = len(second)
|
n = len(second)
|
||||||
for i in xrange(n):
|
for i in range(n):
|
||||||
self.segments[i].size_longs = hdr_blk.hunk_table[i]
|
self.segments[i].size_longs = hdr_blk.hunk_table[i]
|
||||||
self.segments[i].size = self.segments[i].size_longs * 4
|
self.segments[i].size = self.segments[i].size_longs * 4
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ if __name__ == '__main__':
|
|||||||
if len(data) != len(new_data):
|
if len(data) != len(new_data):
|
||||||
print("MISMATCH", len(data), len(new_data))
|
print("MISMATCH", len(data), len(new_data))
|
||||||
else:
|
else:
|
||||||
for i in xrange(len(data)):
|
for i in range(len(data)):
|
||||||
if data[i] != new_data[i]:
|
if data[i] != new_data[i]:
|
||||||
print("MISMATCH @%x" % i)
|
print("MISMATCH @%x" % i)
|
||||||
print("OK")
|
print("OK")
|
||||||
|
|||||||
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import StringIO
|
import io
|
||||||
from types import *
|
from types import *
|
||||||
from Hunk import *
|
from .Hunk import *
|
||||||
|
|
||||||
class HunkReader:
|
class HunkReader:
|
||||||
"""Load Amiga executable Hunk structures"""
|
"""Load Amiga executable Hunk structures"""
|
||||||
@ -30,12 +30,12 @@ class HunkReader:
|
|||||||
result.append(v)
|
result.append(v)
|
||||||
return "[" + ",".join(result) + "]"
|
return "[" + ",".join(result) + "]"
|
||||||
elif type(obj) == DictType:
|
elif type(obj) == DictType:
|
||||||
if obj.has_key('type_name'):
|
if 'type_name' in obj:
|
||||||
type_name = obj['type_name']
|
type_name = obj['type_name']
|
||||||
return type_name.replace('HUNK_','')
|
return type_name.replace('HUNK_','')
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
for k in obj.keys():
|
for k in list(obj.keys()):
|
||||||
v = self.get_struct_summary(obj[k])
|
v = self.get_struct_summary(obj[k])
|
||||||
if v != None:
|
if v != None:
|
||||||
result.append(k + ":" + v)
|
result.append(k + ":" + v)
|
||||||
@ -129,7 +129,7 @@ class HunkReader:
|
|||||||
# determine number of hunks in size table
|
# determine number of hunks in size table
|
||||||
num_hunks = last_hunk - first_hunk + 1
|
num_hunks = last_hunk - first_hunk + 1
|
||||||
hunk_table = []
|
hunk_table = []
|
||||||
for a in xrange(num_hunks):
|
for a in range(num_hunks):
|
||||||
hunk_info = {}
|
hunk_info = {}
|
||||||
hunk_size = self.read_long(f)
|
hunk_size = self.read_long(f)
|
||||||
if hunk_size < 0:
|
if hunk_size < 0:
|
||||||
@ -194,7 +194,7 @@ class HunkReader:
|
|||||||
return RESULT_INVALID_HUNK_FILE
|
return RESULT_INVALID_HUNK_FILE
|
||||||
|
|
||||||
offsets = []
|
offsets = []
|
||||||
for a in xrange(num_relocs & 0xffff):
|
for a in range(num_relocs & 0xffff):
|
||||||
offset = self.read_long(f)
|
offset = self.read_long(f)
|
||||||
if offset < 0:
|
if offset < 0:
|
||||||
self.error_string = "%s has invalid relocation #%d offset %d (num_relocs=%d hunk_num=%d, offset=%d)" \
|
self.error_string = "%s has invalid relocation #%d offset %d (num_relocs=%d hunk_num=%d, offset=%d)" \
|
||||||
@ -228,7 +228,7 @@ class HunkReader:
|
|||||||
offsets = []
|
offsets = []
|
||||||
count = num_relocs & 0xffff
|
count = num_relocs & 0xffff
|
||||||
total_words += count + 2
|
total_words += count + 2
|
||||||
for a in xrange(count):
|
for a in range(count):
|
||||||
offset = self.read_word(f)
|
offset = self.read_word(f)
|
||||||
if offset < 0:
|
if offset < 0:
|
||||||
self.error_string = "%s has invalid relocation #%d offset %d (num_relocs=%d hunk_num=%d, offset=%d)" \
|
self.error_string = "%s has invalid relocation #%d offset %d (num_relocs=%d hunk_num=%d, offset=%d)" \
|
||||||
@ -380,7 +380,7 @@ class HunkReader:
|
|||||||
# for all hunks in unit
|
# for all hunks in unit
|
||||||
ihunks = []
|
ihunks = []
|
||||||
unit['hunk_infos'] = ihunks
|
unit['hunk_infos'] = ihunks
|
||||||
for a in xrange(num_hunks):
|
for a in range(num_hunks):
|
||||||
ihunk = {}
|
ihunk = {}
|
||||||
ihunks.append(ihunk)
|
ihunks.append(ihunk)
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ class HunkReader:
|
|||||||
if num_refs > 0:
|
if num_refs > 0:
|
||||||
refs = []
|
refs = []
|
||||||
ihunk['refs'] = refs
|
ihunk['refs'] = refs
|
||||||
for b in xrange(num_refs):
|
for b in range(num_refs):
|
||||||
ref = {}
|
ref = {}
|
||||||
name_offset = self.read_word(f)
|
name_offset = self.read_word(f)
|
||||||
total_size -= 2
|
total_size -= 2
|
||||||
@ -421,7 +421,7 @@ class HunkReader:
|
|||||||
if num_defs > 0:
|
if num_defs > 0:
|
||||||
defs = []
|
defs = []
|
||||||
ihunk['defs'] = defs
|
ihunk['defs'] = defs
|
||||||
for b in xrange(num_defs):
|
for b in range(num_defs):
|
||||||
name_offset = self.read_word(f)
|
name_offset = self.read_word(f)
|
||||||
def_value = self.read_word(f)
|
def_value = self.read_word(f)
|
||||||
def_type_flags = self.read_word(f)
|
def_type_flags = self.read_word(f)
|
||||||
@ -470,7 +470,7 @@ class HunkReader:
|
|||||||
ext = { 'type' : ext_type, 'name' : ext_name }
|
ext = { 'type' : ext_type, 'name' : ext_name }
|
||||||
|
|
||||||
# check and setup type name
|
# check and setup type name
|
||||||
if not ext_names.has_key(ext_type):
|
if ext_type not in ext_names:
|
||||||
self.error_string = "%s has unspported ext entry %d" % (hunk['type_name'],ext_type)
|
self.error_string = "%s has unspported ext entry %d" % (hunk['type_name'],ext_type)
|
||||||
return RESULT_INVALID_HUNK_FILE
|
return RESULT_INVALID_HUNK_FILE
|
||||||
ext['type_name'] = ext_names[ext_type]
|
ext['type_name'] = ext_names[ext_type]
|
||||||
@ -489,7 +489,7 @@ class HunkReader:
|
|||||||
if num_refs == 0:
|
if num_refs == 0:
|
||||||
num_refs = 1
|
num_refs = 1
|
||||||
refs = []
|
refs = []
|
||||||
for a in xrange(num_refs):
|
for a in range(num_refs):
|
||||||
ref = self.read_long(f)
|
ref = self.read_long(f)
|
||||||
refs.append(ref)
|
refs.append(ref)
|
||||||
ext['refs'] = refs
|
ext['refs'] = refs
|
||||||
@ -528,7 +528,7 @@ class HunkReader:
|
|||||||
|
|
||||||
"""Read a hunk from memory"""
|
"""Read a hunk from memory"""
|
||||||
def read_mem(self, name, data):
|
def read_mem(self, name, data):
|
||||||
fobj = StringIO.StringIO(data)
|
fobj = io.StringIO(data)
|
||||||
return self.read_file_obj(name, fobj)
|
return self.read_file_obj(name, fobj)
|
||||||
|
|
||||||
def read_file_obj(self, hfile, f):
|
def read_file_obj(self, hfile, f):
|
||||||
@ -565,7 +565,7 @@ class HunkReader:
|
|||||||
hunk_flags = hunk_raw_type & HUNK_FLAGS_MASK
|
hunk_flags = hunk_raw_type & HUNK_FLAGS_MASK
|
||||||
|
|
||||||
# check range of hunk type
|
# check range of hunk type
|
||||||
if not hunk_names.has_key(hunk_type):
|
if hunk_type not in hunk_names:
|
||||||
# no hunk file?
|
# no hunk file?
|
||||||
if is_first_hunk:
|
if is_first_hunk:
|
||||||
self.error_string = "No hunk file: '%s' type was %d" % (hfile, hunk_type)
|
self.error_string = "No hunk file: '%s' type was %d" % (hfile, hunk_type)
|
||||||
@ -913,7 +913,7 @@ class HunkReader:
|
|||||||
if lib_off == hunk_offset:
|
if lib_off == hunk_offset:
|
||||||
# found segment
|
# found segment
|
||||||
num_segs = len(unit['hunk_infos'])
|
num_segs = len(unit['hunk_infos'])
|
||||||
for i in xrange(num_segs):
|
for i in range(num_segs):
|
||||||
info = unit['hunk_infos'][i]
|
info = unit['hunk_infos'][i]
|
||||||
seg = segment_list[hunk_no+i]
|
seg = segment_list[hunk_no+i]
|
||||||
unit_segments.append(seg)
|
unit_segments.append(seg)
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import ctypes
|
import ctypes
|
||||||
import struct
|
import struct
|
||||||
import Hunk
|
from . import Hunk
|
||||||
|
|
||||||
class HunkRelocate:
|
class HunkRelocate:
|
||||||
|
|
||||||
@ -52,11 +52,11 @@ class HunkRelocate:
|
|||||||
data = ctypes.create_string_buffer(alloc_size)
|
data = ctypes.create_string_buffer(alloc_size)
|
||||||
|
|
||||||
# fill in segment data
|
# fill in segment data
|
||||||
if main_hunk.has_key('data'):
|
if 'data' in main_hunk:
|
||||||
data.value = main_hunk['data']
|
data.value = main_hunk['data']
|
||||||
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print "#%02d @ %06x" % (hunk_no, addr[hunk_no])
|
print("#%02d @ %06x" % (hunk_no, addr[hunk_no]))
|
||||||
|
|
||||||
# find relocation hunks
|
# find relocation hunks
|
||||||
for hunk in segment[1:]:
|
for hunk in segment[1:]:
|
||||||
@ -79,7 +79,7 @@ class HunkRelocate:
|
|||||||
addr = hunk_addr + delta
|
addr = hunk_addr + delta
|
||||||
self.write_long(data, offset, addr)
|
self.write_long(data, offset, addr)
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print "#%02d + %06x: %06x (delta) + %06x (hunk_addr) -> %06x" % (hunk_no, offset, delta, hunk_addr, addr)
|
print("#%02d + %06x: %06x (delta) + %06x (hunk_addr) -> %06x" % (hunk_no, offset, delta, hunk_addr, addr))
|
||||||
|
|
||||||
def read_long(self, data, offset):
|
def read_long(self, data, offset):
|
||||||
bytes = data[offset:offset+4]
|
bytes = data[offset:offset+4]
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import Hunk
|
from . import Hunk
|
||||||
import HunkDisassembler
|
from . import HunkDisassembler
|
||||||
from amitools.util.HexDump import *
|
from amitools.util.HexDump import *
|
||||||
|
|
||||||
class HunkShow:
|
class HunkShow:
|
||||||
@ -38,7 +38,7 @@ class HunkShow:
|
|||||||
|
|
||||||
def show_lib_segments(self):
|
def show_lib_segments(self):
|
||||||
for lib in self.libs:
|
for lib in self.libs:
|
||||||
print "Library #%d" % lib['lib_no']
|
print("Library #%d" % lib['lib_no'])
|
||||||
for unit in lib['units']:
|
for unit in lib['units']:
|
||||||
self.print_unit(unit['unit_no'], unit['name'])
|
self.print_unit(unit['unit_no'], unit['name'])
|
||||||
for segment in unit['segments']:
|
for segment in unit['segments']:
|
||||||
@ -59,9 +59,9 @@ class HunkShow:
|
|||||||
|
|
||||||
# overlay
|
# overlay
|
||||||
if self.overlay != None:
|
if self.overlay != None:
|
||||||
print "Overlay"
|
print("Overlay")
|
||||||
num_ov = len(self.overlay_headers)
|
num_ov = len(self.overlay_headers)
|
||||||
for o in xrange(num_ov):
|
for o in range(num_ov):
|
||||||
if not self.brief:
|
if not self.brief:
|
||||||
self.print_header(self.overlay_headers[o])
|
self.print_header(self.overlay_headers[o])
|
||||||
for segment in self.overlay_segments[o]:
|
for segment in self.overlay_segments[o]:
|
||||||
@ -72,18 +72,18 @@ class HunkShow:
|
|||||||
|
|
||||||
# unit hunks are named
|
# unit hunks are named
|
||||||
name = ""
|
name = ""
|
||||||
if hunk[0].has_key('name'):
|
if 'name' in hunk[0]:
|
||||||
name = "'%s'" % main['name']
|
name = "'%s'" % main['name']
|
||||||
|
|
||||||
type_name = main['type_name'].replace("HUNK_","")
|
type_name = main['type_name'].replace("HUNK_","")
|
||||||
size = main['size']
|
size = main['size']
|
||||||
hunk_no = main['hunk_no']
|
hunk_no = main['hunk_no']
|
||||||
if main.has_key('data_file_offset'):
|
if 'data_file_offset' in main:
|
||||||
data_file_offset = main['data_file_offset']
|
data_file_offset = main['data_file_offset']
|
||||||
else:
|
else:
|
||||||
data_file_offset = None
|
data_file_offset = None
|
||||||
hunk_file_offset = main['hunk_file_offset']
|
hunk_file_offset = main['hunk_file_offset']
|
||||||
if main.has_key('alloc_size'):
|
if 'alloc_size' in main:
|
||||||
alloc_size = main['alloc_size']
|
alloc_size = main['alloc_size']
|
||||||
else:
|
else:
|
||||||
alloc_size = None
|
alloc_size = None
|
||||||
@ -96,24 +96,24 @@ class HunkShow:
|
|||||||
self.show_extra_hunk(extra)
|
self.show_extra_hunk(extra)
|
||||||
|
|
||||||
# index hunk info is embedded if its in a lib
|
# index hunk info is embedded if its in a lib
|
||||||
if main.has_key('index_hunk'):
|
if 'index_hunk' in main:
|
||||||
self.show_index_info(main['index_hunk'])
|
self.show_index_info(main['index_hunk'])
|
||||||
|
|
||||||
if main['type'] == Hunk.HUNK_CODE and self.disassemble and len(main['data'])>0:
|
if main['type'] == Hunk.HUNK_CODE and self.disassemble and len(main['data'])>0:
|
||||||
disas = HunkDisassembler.HunkDisassembler(use_objdump = self.use_objdump, cpu = self.cpu)
|
disas = HunkDisassembler.HunkDisassembler(use_objdump = self.use_objdump, cpu = self.cpu)
|
||||||
print
|
print()
|
||||||
disas.show_disassembly(hunk, seg_list, self.disassemble_start)
|
disas.show_disassembly(hunk, seg_list, self.disassemble_start)
|
||||||
print
|
print()
|
||||||
|
|
||||||
def show_index_info(self, info):
|
def show_index_info(self, info):
|
||||||
# references from index
|
# references from index
|
||||||
if info.has_key('refs'):
|
if 'refs' in info:
|
||||||
self.print_extra("refs","#%d" % len(info['refs']))
|
self.print_extra("refs","#%d" % len(info['refs']))
|
||||||
if not self.brief:
|
if not self.brief:
|
||||||
for ref in info['refs']:
|
for ref in info['refs']:
|
||||||
self.print_symbol(-1,ref['name'],"(%d bits)" % ref['bits'])
|
self.print_symbol(-1,ref['name'],"(%d bits)" % ref['bits'])
|
||||||
# defines from index
|
# defines from index
|
||||||
if info.has_key('defs'):
|
if 'defs' in info:
|
||||||
self.print_extra("defs","#%d" % len(info['defs']))
|
self.print_extra("defs","#%d" % len(info['defs']))
|
||||||
if not self.brief:
|
if not self.brief:
|
||||||
for d in info['defs']:
|
for d in info['defs']:
|
||||||
@ -192,13 +192,13 @@ class HunkShow:
|
|||||||
# ----- printing -----
|
# ----- printing -----
|
||||||
|
|
||||||
def print_header(self, hdr):
|
def print_header(self, hdr):
|
||||||
print "\t header (segments: first=%d, last=%d, table size=%d)" % (hdr['first_hunk'], hdr['last_hunk'], hdr['table_size'])
|
print("\t header (segments: first=%d, last=%d, table size=%d)" % (hdr['first_hunk'], hdr['last_hunk'], hdr['table_size']))
|
||||||
|
|
||||||
def print_extra(self, type_name, info):
|
def print_extra(self, type_name, info):
|
||||||
print "\t\t%8s %s" % (type_name, info)
|
print("\t\t%8s %s" % (type_name, info))
|
||||||
|
|
||||||
def print_extra_sub(self, text):
|
def print_extra_sub(self, text):
|
||||||
print "\t\t\t%s" % text
|
print("\t\t\t%s" % text)
|
||||||
|
|
||||||
def print_segment_header(self, hunk_no, type_name, size, name, data_file_offset, hunk_file_offset, alloc_size):
|
def print_segment_header(self, hunk_no, type_name, size, name, data_file_offset, hunk_file_offset, alloc_size):
|
||||||
extra = ""
|
extra = ""
|
||||||
@ -207,17 +207,17 @@ class HunkShow:
|
|||||||
extra += "file header @%08x" % hunk_file_offset
|
extra += "file header @%08x" % hunk_file_offset
|
||||||
if data_file_offset != None:
|
if data_file_offset != None:
|
||||||
extra += " data @%08x" % data_file_offset
|
extra += " data @%08x" % data_file_offset
|
||||||
print "\t#%03d %-5s size %08x %s %s" % (hunk_no, type_name, size, extra, name)
|
print("\t#%03d %-5s size %08x %s %s" % (hunk_no, type_name, size, extra, name))
|
||||||
|
|
||||||
def print_symbol(self,addr,name,extra):
|
def print_symbol(self,addr,name,extra):
|
||||||
if addr == -1:
|
if addr == -1:
|
||||||
a = "xxxxxxxx"
|
a = "xxxxxxxx"
|
||||||
else:
|
else:
|
||||||
a = "%08x" % addr
|
a = "%08x" % addr
|
||||||
print "\t\t\t%s %-32s %s" % (a,name,extra)
|
print("\t\t\t%s %-32s %s" % (a,name,extra))
|
||||||
|
|
||||||
def print_unit(self, no, name):
|
def print_unit(self, no, name):
|
||||||
print " #%03d UNIT %s" % (no, name)
|
print(" #%03d UNIT %s" % (no, name))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -86,7 +86,7 @@ def read_fd(fname):
|
|||||||
elif cmd == "end":
|
elif cmd == "end":
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print "Invalid command:",cmda
|
print("Invalid command:",cmda)
|
||||||
return None
|
return None
|
||||||
# a function
|
# a function
|
||||||
else:
|
else:
|
||||||
@ -107,8 +107,8 @@ def read_fd(fname):
|
|||||||
if len(arg) != len(reg):
|
if len(arg) != len(reg):
|
||||||
# hack for double reg args found in mathieeedoub* libs
|
# hack for double reg args found in mathieeedoub* libs
|
||||||
if len(arg) * 2 == len(reg):
|
if len(arg) * 2 == len(reg):
|
||||||
arg_hi = map(lambda x: x + "_hi", arg)
|
arg_hi = [x + "_hi" for x in arg]
|
||||||
arg_lo = map(lambda x: x + "_lo", arg)
|
arg_lo = [x + "_lo" for x in arg]
|
||||||
arg = [x for pair in zip(arg_hi, arg_lo) for x in pair]
|
arg = [x for pair in zip(arg_hi, arg_lo) for x in pair]
|
||||||
else:
|
else:
|
||||||
raise IOError("Reg and Arg name mismatch in FD File")
|
raise IOError("Reg and Arg name mismatch in FD File")
|
||||||
@ -147,8 +147,8 @@ def write_fd(fname, fd, add_private):
|
|||||||
if args == None:
|
if args == None:
|
||||||
line += "()()"
|
line += "()()"
|
||||||
else:
|
else:
|
||||||
line += "(" + ",".join(map(lambda x : x[0], args)) + ")"
|
line += "(" + ",".join([x[0] for x in args]) + ")"
|
||||||
line += "(" + "/".join(map(lambda x : x[1], args)) + ")"
|
line += "(" + "/".join([x[1] for x in args]) + ")"
|
||||||
fo.write("%s\n" % line)
|
fo.write("%s\n" % line)
|
||||||
fo.write("##end\n")
|
fo.write("##end\n")
|
||||||
fo.close()
|
fo.close()
|
||||||
|
|||||||
@ -3,7 +3,7 @@ class FuncDef:
|
|||||||
def __init__(self, name, bias, private=False, is_std=False):
|
def __init__(self, name, bias, private=False, is_std=False):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.bias = bias
|
self.bias = bias
|
||||||
self.index = (bias - 6) / 6
|
self.index = (bias - 6) // 6
|
||||||
self.private = private
|
self.private = private
|
||||||
self.std = is_std
|
self.std = is_std
|
||||||
self.args = []
|
self.args = []
|
||||||
@ -24,13 +24,13 @@ class FuncDef:
|
|||||||
def add_arg(self, name, reg):
|
def add_arg(self, name, reg):
|
||||||
self.args.append((name, reg))
|
self.args.append((name, reg))
|
||||||
def dump(self):
|
def dump(self):
|
||||||
print(self.name,self.bias,self.private,self.args)
|
print((self.name,self.bias,self.private,self.args))
|
||||||
def get_arg_str(self, with_reg=True):
|
def get_arg_str(self, with_reg=True):
|
||||||
if len(self.args) == 0:
|
if len(self.args) == 0:
|
||||||
return "()"
|
return "()"
|
||||||
elif with_reg:
|
elif with_reg:
|
||||||
return "( " + ", ".join(map(lambda x : "%s/%s" % (x[0],x[1]), self.args)) + " )"
|
return "( " + ", ".join(["%s/%s" % (x[0],x[1]) for x in self.args]) + " )"
|
||||||
else:
|
else:
|
||||||
return "( " + ", ".join(map(lambda x : "%s" % x[0], self.args)) + " )"
|
return "( " + ", ".join(["%s" % x[0] for x in self.args]) + " )"
|
||||||
def get_str(self, with_reg=True):
|
def get_str(self, with_reg=True):
|
||||||
return self.name + self.get_arg_str(with_reg)
|
return self.name + self.get_arg_str(with_reg)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from FuncDef import FuncDef
|
from .FuncDef import FuncDef
|
||||||
|
|
||||||
class FuncTable:
|
class FuncTable:
|
||||||
"""Store a function table"""
|
"""Store a function table"""
|
||||||
@ -30,10 +30,10 @@ class FuncTable:
|
|||||||
return self.max_bias + 6
|
return self.max_bias + 6
|
||||||
|
|
||||||
def get_num_indices(self):
|
def get_num_indices(self):
|
||||||
return self.max_bias / 6
|
return self.max_bias // 6
|
||||||
|
|
||||||
def get_all_func_names():
|
def get_all_func_names():
|
||||||
return self.name_map.keys()
|
return list(self.name_map.keys())
|
||||||
|
|
||||||
def has_func(self, name):
|
def has_func(self, name):
|
||||||
return name in self.name_map
|
return name in self.name_map
|
||||||
@ -68,7 +68,7 @@ class FuncTable:
|
|||||||
if bias > self.max_bias:
|
if bias > self.max_bias:
|
||||||
self.max_bias = bias
|
self.max_bias = bias
|
||||||
# update index table
|
# update index table
|
||||||
tab_len = bias / 6
|
tab_len = bias // 6
|
||||||
while len(self.index_tab) < tab_len:
|
while len(self.index_tab) < tab_len:
|
||||||
self.index_tab.append(None)
|
self.index_tab.append(None)
|
||||||
index = tab_len - 1
|
index = tab_len - 1
|
||||||
@ -86,7 +86,7 @@ class FuncTable:
|
|||||||
func_def.add_arg(arg[i],reg[i])
|
func_def.add_arg(arg[i],reg[i])
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
print("FuncTable:",self.base_name)
|
print(("FuncTable:",self.base_name))
|
||||||
for f in self.funcs:
|
for f in self.funcs:
|
||||||
f.dump()
|
f.dump()
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
import ctypes
|
import ctypes
|
||||||
@ -39,7 +39,7 @@ class ADFSBitmap:
|
|||||||
def create(self):
|
def create(self):
|
||||||
# create data and preset with 0xff
|
# create data and preset with 0xff
|
||||||
self.bitmap_data = ctypes.create_string_buffer(self.bitmap_all_blk_bytes)
|
self.bitmap_data = ctypes.create_string_buffer(self.bitmap_all_blk_bytes)
|
||||||
for i in xrange(self.bitmap_all_blk_bytes):
|
for i in range(self.bitmap_all_blk_bytes):
|
||||||
self.bitmap_data[i] = chr(0xff)
|
self.bitmap_data[i] = chr(0xff)
|
||||||
|
|
||||||
# clear bit for root block
|
# clear bit for root block
|
||||||
@ -48,7 +48,7 @@ class ADFSBitmap:
|
|||||||
blk_pos += 1
|
blk_pos += 1
|
||||||
|
|
||||||
# create ext blocks
|
# create ext blocks
|
||||||
for i in xrange(self.num_ext):
|
for i in range(self.num_ext):
|
||||||
bm_ext = BitmapExtBlock(self.blkdev, blk_pos)
|
bm_ext = BitmapExtBlock(self.blkdev, blk_pos)
|
||||||
bm_ext.create()
|
bm_ext.create()
|
||||||
self.clr_bit(blk_pos)
|
self.clr_bit(blk_pos)
|
||||||
@ -56,7 +56,7 @@ class ADFSBitmap:
|
|||||||
self.ext_blks.append(bm_ext)
|
self.ext_blks.append(bm_ext)
|
||||||
|
|
||||||
# create bitmap blocks
|
# create bitmap blocks
|
||||||
for i in xrange(self.bitmap_num_blks):
|
for i in range(self.bitmap_num_blks):
|
||||||
bm = BitmapBlock(self.blkdev, blk_pos)
|
bm = BitmapBlock(self.blkdev, blk_pos)
|
||||||
bm.create()
|
bm.create()
|
||||||
self.clr_bit(blk_pos)
|
self.clr_bit(blk_pos)
|
||||||
@ -66,7 +66,7 @@ class ADFSBitmap:
|
|||||||
# set pointers to ext blocks
|
# set pointers to ext blocks
|
||||||
if self.num_ext > 0:
|
if self.num_ext > 0:
|
||||||
self.root_blk.bitmap_ext_blk = self.ext_blks[0].blk_num
|
self.root_blk.bitmap_ext_blk = self.ext_blks[0].blk_num
|
||||||
for i in xrange(self.num_ext-1):
|
for i in range(self.num_ext-1):
|
||||||
bm_ext = self.ext_blks[i]
|
bm_ext = self.ext_blks[i]
|
||||||
bm_ext_next = self.ext_blks[i+1]
|
bm_ext_next = self.ext_blks[i+1]
|
||||||
bm_ext.bitmap_ext_blk = bm_ext_next.blk_num
|
bm_ext.bitmap_ext_blk = bm_ext_next.blk_num
|
||||||
@ -74,7 +74,7 @@ class ADFSBitmap:
|
|||||||
# set pointers to bitmap blocks
|
# set pointers to bitmap blocks
|
||||||
cur_ext_index = 0
|
cur_ext_index = 0
|
||||||
cur_ext_pos = 0
|
cur_ext_pos = 0
|
||||||
for i in xrange(self.bitmap_num_blks):
|
for i in range(self.bitmap_num_blks):
|
||||||
blk_num = self.bitmap_blks[i].blk_num
|
blk_num = self.bitmap_blks[i].blk_num
|
||||||
if i < self.num_blks_in_root:
|
if i < self.num_blks_in_root:
|
||||||
# pointers in root block
|
# pointers in root block
|
||||||
@ -189,7 +189,7 @@ class ADFSBitmap:
|
|||||||
if num == 1:
|
if num == 1:
|
||||||
return [first_blk]
|
return [first_blk]
|
||||||
result = [first_blk]
|
result = [first_blk]
|
||||||
for i in xrange(num-1):
|
for i in range(num-1):
|
||||||
blk_num = self.find_free()
|
blk_num = self.find_free()
|
||||||
if blk_num == None:
|
if blk_num == None:
|
||||||
return None
|
return None
|
||||||
@ -200,14 +200,14 @@ class ADFSBitmap:
|
|||||||
|
|
||||||
def get_num_free(self):
|
def get_num_free(self):
|
||||||
num = 0
|
num = 0
|
||||||
for i in xrange(self.bitmap_bits):
|
for i in range(self.bitmap_bits):
|
||||||
if self.get_bit(i):
|
if self.get_bit(i):
|
||||||
num+=1
|
num+=1
|
||||||
return num
|
return num
|
||||||
|
|
||||||
def get_num_used(self):
|
def get_num_used(self):
|
||||||
num = 0
|
num = 0
|
||||||
for i in xrange(self.bitmap_bits):
|
for i in range(self.bitmap_bits):
|
||||||
if not self.get_bit(i):
|
if not self.get_bit(i):
|
||||||
num+=1
|
num+=1
|
||||||
return num
|
return num
|
||||||
@ -270,14 +270,14 @@ class ADFSBitmap:
|
|||||||
|
|
||||||
def create_draw_bitmap(self):
|
def create_draw_bitmap(self):
|
||||||
bm = ctypes.create_string_buffer(self.blkdev.num_blocks)
|
bm = ctypes.create_string_buffer(self.blkdev.num_blocks)
|
||||||
for i in xrange(self.blkdev.num_blocks):
|
for i in range(self.blkdev.num_blocks):
|
||||||
bm[i] = chr(0)
|
bm[i] = chr(0)
|
||||||
return bm
|
return bm
|
||||||
|
|
||||||
def print_free(self, brief=False):
|
def print_free(self, brief=False):
|
||||||
bm = self.create_draw_bitmap()
|
bm = self.create_draw_bitmap()
|
||||||
res = self.blkdev.reserved
|
res = self.blkdev.reserved
|
||||||
for i in xrange(self.blkdev.num_blocks):
|
for i in range(self.blkdev.num_blocks):
|
||||||
if i >= res and self.get_bit(i):
|
if i >= res and self.get_bit(i):
|
||||||
bm[i] = 'F'
|
bm[i] = 'F'
|
||||||
self.print_draw_bitmap(bm, brief)
|
self.print_draw_bitmap(bm, brief)
|
||||||
@ -285,7 +285,7 @@ class ADFSBitmap:
|
|||||||
def print_used(self, brief=False):
|
def print_used(self, brief=False):
|
||||||
bm = self.create_draw_bitmap()
|
bm = self.create_draw_bitmap()
|
||||||
res = self.blkdev.reserved
|
res = self.blkdev.reserved
|
||||||
for i in xrange(self.blkdev.num_blocks):
|
for i in range(self.blkdev.num_blocks):
|
||||||
if i >= res and not self.get_bit(i):
|
if i >= res and not self.get_bit(i):
|
||||||
bm[i] = '#'
|
bm[i] = '#'
|
||||||
self.print_draw_bitmap(bm, brief)
|
self.print_draw_bitmap(bm, brief)
|
||||||
@ -308,7 +308,7 @@ class ADFSBitmap:
|
|||||||
blk = 0
|
blk = 0
|
||||||
blk_cyl = self.blkdev.sectors * self.blkdev.heads
|
blk_cyl = self.blkdev.sectors * self.blkdev.heads
|
||||||
found = False
|
found = False
|
||||||
for i in xrange(self.blkdev.num_blocks):
|
for i in range(self.blkdev.num_blocks):
|
||||||
c = bm[i]
|
c = bm[i]
|
||||||
if ord(c) == 0:
|
if ord(c) == 0:
|
||||||
c = '.'
|
c = '.'
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
from .block.Block import Block
|
from .block.Block import Block
|
||||||
@ -57,7 +57,7 @@ class ADFSDir(ADFSNode):
|
|||||||
|
|
||||||
def _init_name_hash(self):
|
def _init_name_hash(self):
|
||||||
self.name_hash = []
|
self.name_hash = []
|
||||||
for i in xrange(self.block.hash_size):
|
for i in range(self.block.hash_size):
|
||||||
self.name_hash.append([])
|
self.name_hash.append([])
|
||||||
|
|
||||||
def read(self, recursive=False):
|
def read(self, recursive=False):
|
||||||
@ -66,7 +66,7 @@ class ADFSDir(ADFSNode):
|
|||||||
|
|
||||||
# create initial list with blk_num/hash_index for dir scan
|
# create initial list with blk_num/hash_index for dir scan
|
||||||
blocks = []
|
blocks = []
|
||||||
for i in xrange(self.block.hash_size):
|
for i in range(self.block.hash_size):
|
||||||
blk_num = self.block.hash_table[i]
|
blk_num = self.block.hash_table[i]
|
||||||
if blk_num != 0:
|
if blk_num != 0:
|
||||||
blocks.append((blk_num,i))
|
blocks.append((blk_num,i))
|
||||||
@ -231,7 +231,7 @@ class ADFSDir(ADFSNode):
|
|||||||
names = self.name_hash[hash_key]
|
names = self.name_hash[hash_key]
|
||||||
# find my node
|
# find my node
|
||||||
pos = None
|
pos = None
|
||||||
for i in xrange(len(names)):
|
for i in range(len(names)):
|
||||||
if names[i] == node:
|
if names[i] == node:
|
||||||
pos = i
|
pos = i
|
||||||
break
|
break
|
||||||
@ -431,7 +431,7 @@ class ADFSDir(ADFSNode):
|
|||||||
dcb = None
|
dcb = None
|
||||||
record = None
|
record = None
|
||||||
n = len(self.dcache_blks)
|
n = len(self.dcache_blks)
|
||||||
for i in xrange(n):
|
for i in range(n):
|
||||||
dcb = self.dcache_blks[i]
|
dcb = self.dcache_blks[i]
|
||||||
record = dcb.get_record_by_name(name)
|
record = dcb.get_record_by_name(name)
|
||||||
if record != None:
|
if record != None:
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .block.EntryBlock import EntryBlock
|
from .block.EntryBlock import EntryBlock
|
||||||
from .block.FileHeaderBlock import FileHeaderBlock
|
from .block.FileHeaderBlock import FileHeaderBlock
|
||||||
@ -163,12 +163,12 @@ class ADFSFile(ADFSNode):
|
|||||||
fhb_num = free_blks[0]
|
fhb_num = free_blks[0]
|
||||||
# ... for ext
|
# ... for ext
|
||||||
self.ext_blk_nums = []
|
self.ext_blk_nums = []
|
||||||
for i in xrange(self.num_ext_blks):
|
for i in range(self.num_ext_blks):
|
||||||
self.ext_blk_nums.append(free_blks[1+i])
|
self.ext_blk_nums.append(free_blks[1+i])
|
||||||
# ... for data
|
# ... for data
|
||||||
off = 1 + self.num_ext_blks
|
off = 1 + self.num_ext_blks
|
||||||
self.data_blk_nums = []
|
self.data_blk_nums = []
|
||||||
for i in xrange(self.num_data_blks):
|
for i in range(self.num_data_blks):
|
||||||
self.data_blk_nums.append(free_blks[off])
|
self.data_blk_nums.append(free_blks[off])
|
||||||
off += 1
|
off += 1
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ class ADFSFile(ADFSNode):
|
|||||||
|
|
||||||
# create file list (=ext) blocks
|
# create file list (=ext) blocks
|
||||||
ext_off = ppb
|
ext_off = ppb
|
||||||
for i in xrange(self.num_ext_blks):
|
for i in range(self.num_ext_blks):
|
||||||
flb = FileListBlock(self.blkdev, self.ext_blk_nums[i])
|
flb = FileListBlock(self.blkdev, self.ext_blk_nums[i])
|
||||||
if i == self.num_ext_blks - 1:
|
if i == self.num_ext_blks - 1:
|
||||||
ext_blk = 0
|
ext_blk = 0
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .block.CommentBlock import CommentBlock
|
from .block.CommentBlock import CommentBlock
|
||||||
from .block.EntryBlock import EntryBlock
|
from .block.EntryBlock import EntryBlock
|
||||||
@ -142,12 +142,12 @@ class ADFSNode:
|
|||||||
self.change_meta_info(MetaInfo(mod_ts=t))
|
self.change_meta_info(MetaInfo(mod_ts=t))
|
||||||
|
|
||||||
def get_list_str(self, indent=0, all=False, detail=False):
|
def get_list_str(self, indent=0, all=False, detail=False):
|
||||||
istr = u' ' * indent
|
istr = ' ' * indent
|
||||||
if detail:
|
if detail:
|
||||||
extra = self.get_detail_str()
|
extra = self.get_detail_str()
|
||||||
else:
|
else:
|
||||||
extra = self.meta_info.get_str_line()
|
extra = self.meta_info.get_str_line()
|
||||||
return u'%-40s %8s %s' % (istr + self.name.get_unicode_name(), self.get_size_str(), extra)
|
return '%-40s %8s %s' % (istr + self.name.get_unicode_name(), self.get_size_str(), extra)
|
||||||
|
|
||||||
def list(self, indent=0, all=False, detail=False, encoding="UTF-8"):
|
def list(self, indent=0, all=False, detail=False, encoding="UTF-8"):
|
||||||
print(self.get_list_str(indent=indent, all=all, detail=detail).encode(encoding))
|
print(self.get_list_str(indent=indent, all=all, detail=detail).encode(encoding))
|
||||||
@ -183,7 +183,7 @@ class ADFSNode:
|
|||||||
|
|
||||||
def get_node_path_name(self, with_vol=False):
|
def get_node_path_name(self, with_vol=False):
|
||||||
r = self.get_node_path()
|
r = self.get_node_path()
|
||||||
return FSString(u"/".join(r))
|
return FSString("/".join(r))
|
||||||
|
|
||||||
def get_detail_str(self):
|
def get_detail_str(self):
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .ADFSDir import ADFSDir
|
from .ADFSDir import ADFSDir
|
||||||
from .MetaInfo import MetaInfo
|
from .MetaInfo import MetaInfo
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .block.BootBlock import BootBlock
|
from .block.BootBlock import BootBlock
|
||||||
from .block.RootBlock import RootBlock
|
from .block.RootBlock import RootBlock
|
||||||
|
|||||||
@ -58,19 +58,19 @@ class FSError(Exception):
|
|||||||
return self.__unicode__().encode("UTF-8")
|
return self.__unicode__().encode("UTF-8")
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
if error_names.has_key(self.code):
|
if self.code in error_names:
|
||||||
code_str = unicode(error_names[self.code])
|
code_str = str(error_names[self.code])
|
||||||
else:
|
else:
|
||||||
code_str = u"?"
|
code_str = "?"
|
||||||
srcs = []
|
srcs = []
|
||||||
if self.node != None:
|
if self.node != None:
|
||||||
srcs.append(u"node=" + unicode(self.node))
|
srcs.append("node=" + str(self.node))
|
||||||
if self.block != None:
|
if self.block != None:
|
||||||
srcs.append(u"block=" + unicode(self.block))
|
srcs.append("block=" + str(self.block))
|
||||||
if self.file_name != None:
|
if self.file_name != None:
|
||||||
srcs.append(u"file_name=" + self.file_name.get_unicode())
|
srcs.append("file_name=" + self.file_name.get_unicode())
|
||||||
if self.extra != None:
|
if self.extra != None:
|
||||||
srcs.append(unicode(self.extra))
|
srcs.append(str(self.extra))
|
||||||
return u"%s(%d):%s" % (code_str, self.code, ",".join(srcs))
|
return "%s(%d):%s" % (code_str, self.code, ",".join(srcs))
|
||||||
|
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ class FSString:
|
|||||||
"""
|
"""
|
||||||
if sys.version_info[0] == 3 and type(txt) == str:
|
if sys.version_info[0] == 3 and type(txt) == str:
|
||||||
self.txt = txt
|
self.txt = txt
|
||||||
elif type(txt) == unicode:
|
elif type(txt) == str:
|
||||||
self.txt = txt
|
self.txt = txt
|
||||||
elif type(txt) == str:
|
elif type(txt) == str:
|
||||||
self.txt = txt.decode(encoding)
|
self.txt = txt.decode(encoding)
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .FSString import FSString
|
from .FSString import FSString
|
||||||
|
|
||||||
class FileName:
|
class FileName:
|
||||||
root_path_aliases = (u'', u'/', u':')
|
root_path_aliases = ('', '/', ':')
|
||||||
|
|
||||||
def __init__(self, name, is_intl=False, is_longname=False):
|
def __init__(self, name, is_intl=False, is_longname=False):
|
||||||
# check that name is a FSString
|
# check that name is a FSString
|
||||||
@ -36,7 +36,7 @@ class FileName:
|
|||||||
def get_dir_and_base_name(self):
|
def get_dir_and_base_name(self):
|
||||||
"""Return portion after last slash '/' or the full name in unicode"""
|
"""Return portion after last slash '/' or the full name in unicode"""
|
||||||
s = self.name.get_unicode()
|
s = self.name.get_unicode()
|
||||||
pos = s.rfind(u'/')
|
pos = s.rfind('/')
|
||||||
if pos != -1:
|
if pos != -1:
|
||||||
dir_name = s[:pos]
|
dir_name = s[:pos]
|
||||||
file_name = s[pos+1:]
|
file_name = s[pos+1:]
|
||||||
@ -51,7 +51,7 @@ class FileName:
|
|||||||
result = self.name.get_ami_str().upper()
|
result = self.name.get_ami_str().upper()
|
||||||
if self.is_intl:
|
if self.is_intl:
|
||||||
r = ""
|
r = ""
|
||||||
for i in xrange(len(result)):
|
for i in range(len(result)):
|
||||||
o = ord(result[i])
|
o = ord(result[i])
|
||||||
if o >= 224 and o <= 254 and o != 247:
|
if o >= 224 and o <= 254 and o != 247:
|
||||||
r += chr(o - (ord('a')-ord('A')))
|
r += chr(o - (ord('a')-ord('A')))
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
@ -31,7 +31,7 @@ class Imager:
|
|||||||
|
|
||||||
def to_path_str(self, u):
|
def to_path_str(self, u):
|
||||||
"""convert a unicode string to OS path name encoding"""
|
"""convert a unicode string to OS path name encoding"""
|
||||||
if type(u) != unicode:
|
if type(u) != str:
|
||||||
raise ValueError("to_path_str: must pass a unicode string")
|
raise ValueError("to_path_str: must pass a unicode string")
|
||||||
return u.encode(self.path_encoding)
|
return u.encode(self.path_encoding)
|
||||||
|
|
||||||
@ -205,8 +205,8 @@ class Imager:
|
|||||||
# retrieve meta info for path from DB
|
# retrieve meta info for path from DB
|
||||||
if self.meta_db != None:
|
if self.meta_db != None:
|
||||||
ami_path = parent_node.get_node_path_name().get_unicode()
|
ami_path = parent_node.get_node_path_name().get_unicode()
|
||||||
if ami_path != u"":
|
if ami_path != "":
|
||||||
ami_path += u"/" + ami_name
|
ami_path += "/" + ami_name
|
||||||
else:
|
else:
|
||||||
ami_path = ami_name
|
ami_path = ami_name
|
||||||
meta_info = self.meta_db.get_meta_info(ami_path)
|
meta_info = self.meta_db.get_meta_info(ami_path)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .MetaInfo import MetaInfo
|
from .MetaInfo import MetaInfo
|
||||||
from .RootMetaInfo import RootMetaInfo
|
from .RootMetaInfo import RootMetaInfo
|
||||||
@ -23,7 +23,7 @@ class MetaDB:
|
|||||||
return self.vol_meta
|
return self.vol_meta
|
||||||
|
|
||||||
def set_volume_name(self, name):
|
def set_volume_name(self, name):
|
||||||
if type(name) != unicode:
|
if type(name) != str:
|
||||||
raise ValueError("set_volume_name must be unicode")
|
raise ValueError("set_volume_name must be unicode")
|
||||||
self.vol_name = name
|
self.vol_name = name
|
||||||
|
|
||||||
@ -37,12 +37,12 @@ class MetaDB:
|
|||||||
return self.dos_type
|
return self.dos_type
|
||||||
|
|
||||||
def set_meta_info(self, path, meta_info):
|
def set_meta_info(self, path, meta_info):
|
||||||
if type(path) != unicode:
|
if type(path) != str:
|
||||||
raise ValueError("set_meta_info: path must be unicode")
|
raise ValueError("set_meta_info: path must be unicode")
|
||||||
self.metas[path] = meta_info
|
self.metas[path] = meta_info
|
||||||
|
|
||||||
def get_meta_info(self, path):
|
def get_meta_info(self, path):
|
||||||
if self.metas.has_key(path):
|
if path in self.metas:
|
||||||
return self.metas[path]
|
return self.metas[path]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .ProtectFlags import *
|
from .ProtectFlags import *
|
||||||
from .TimeStamp import *
|
from .TimeStamp import *
|
||||||
@ -21,10 +21,10 @@ class MetaInfo:
|
|||||||
res.append(self.get_mod_time_str())
|
res.append(self.get_mod_time_str())
|
||||||
comment = self.get_comment()
|
comment = self.get_comment()
|
||||||
if comment == None:
|
if comment == None:
|
||||||
res.append(u'')
|
res.append('')
|
||||||
else:
|
else:
|
||||||
res.append(self.get_comment().get_unicode())
|
res.append(self.get_comment().get_unicode())
|
||||||
return u' '.join(res)
|
return ' '.join(res)
|
||||||
|
|
||||||
def get_mod_time_str(self):
|
def get_mod_time_str(self):
|
||||||
if self.mod_ts != None:
|
if self.mod_ts != None:
|
||||||
@ -109,4 +109,4 @@ class MetaInfo:
|
|||||||
if self.comment != None:
|
if self.comment != None:
|
||||||
return self.comment.get_unicode()
|
return self.comment.get_unicode()
|
||||||
else:
|
else:
|
||||||
return u""
|
return ""
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .FSError import *
|
from .FSError import *
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class ProtectFlags:
|
|||||||
txt = ""
|
txt = ""
|
||||||
pos = self.flag_num - 1
|
pos = self.flag_num - 1
|
||||||
m = 1 << pos
|
m = 1 << pos
|
||||||
for i in xrange(self.flag_num):
|
for i in range(self.flag_num):
|
||||||
bit = self.mask & m == m
|
bit = self.mask & m == m
|
||||||
show = '-'
|
show = '-'
|
||||||
flg = self.flag_txt[i]
|
flg = self.flag_txt[i]
|
||||||
@ -43,7 +43,7 @@ class ProtectFlags:
|
|||||||
def bin_str(self):
|
def bin_str(self):
|
||||||
res = ""
|
res = ""
|
||||||
m = 1 << (self.flag_num - 1)
|
m = 1 << (self.flag_num - 1)
|
||||||
for i in xrange(self.flag_num):
|
for i in range(self.flag_num):
|
||||||
if m & self.mask == m:
|
if m & self.mask == m:
|
||||||
res += "1"
|
res += "1"
|
||||||
else:
|
else:
|
||||||
@ -67,7 +67,7 @@ class ProtectFlags:
|
|||||||
else:
|
else:
|
||||||
mask = None
|
mask = None
|
||||||
is_low = None
|
is_low = None
|
||||||
for i in xrange(self.flag_num):
|
for i in range(self.flag_num):
|
||||||
flg = self.flag_txt[i]
|
flg = self.flag_txt[i]
|
||||||
flg_low = flg.lower()
|
flg_low = flg.lower()
|
||||||
if flg_low == a:
|
if flg_low == a:
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .ADFSVolume import ADFSVolume
|
from .ADFSVolume import ADFSVolume
|
||||||
from amitools.fs.blkdev.BlkDevFactory import BlkDevFactory
|
from amitools.fs.blkdev.BlkDevFactory import BlkDevFactory
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from .TimeStamp import *
|
from .TimeStamp import *
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .BlockDevice import BlockDevice
|
from .BlockDevice import BlockDevice
|
||||||
import ctypes
|
import ctypes
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
@ -149,7 +149,7 @@ class BlkDevFactory:
|
|||||||
raise IOError("can't open rdisk of image file")
|
raise IOError("can't open rdisk of image file")
|
||||||
# determine partition
|
# determine partition
|
||||||
p = "0"
|
p = "0"
|
||||||
if options != None and options.has_key('part'):
|
if options != None and 'part' in options:
|
||||||
p = str(options['part'])
|
p = str(options['part'])
|
||||||
part = rdisk.find_partition_by_string(p)
|
part = rdisk.find_partition_by_string(p)
|
||||||
if part == None:
|
if part == None:
|
||||||
@ -192,7 +192,7 @@ class BlkDevFactory:
|
|||||||
# --- mini test ---
|
# --- mini test ---
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
import StringIO
|
import io
|
||||||
bdf = BlkDevFactory()
|
bdf = BlkDevFactory()
|
||||||
for a in sys.argv[1:]:
|
for a in sys.argv[1:]:
|
||||||
# open by file
|
# open by file
|
||||||
@ -202,7 +202,7 @@ if __name__ == '__main__':
|
|||||||
# open via fobj
|
# open via fobj
|
||||||
fobj = file(a,"rb")
|
fobj = file(a,"rb")
|
||||||
data = fobj.read()
|
data = fobj.read()
|
||||||
nobj = StringIO.StringIO(data)
|
nobj = io.StringIO(data)
|
||||||
blkdev = bdf.open("bluna"+a, fobj=nobj)
|
blkdev = bdf.open("bluna"+a, fobj=nobj)
|
||||||
print(a, blkdev.__class__.__name__)
|
print(a, blkdev.__class__.__name__)
|
||||||
blkdev.close()
|
blkdev.close()
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
# a block device defines a set of blocks used by a file system
|
# a block device defines a set of blocks used by a file system
|
||||||
from .DiskGeometry import DiskGeometry
|
from .DiskGeometry import DiskGeometry
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class DiskGeometry:
|
|||||||
algo = None
|
algo = None
|
||||||
if options != None:
|
if options != None:
|
||||||
(c, h, s) = self._parse_chs(options)
|
(c, h, s) = self._parse_chs(options)
|
||||||
if options.has_key('algo'):
|
if 'algo' in options:
|
||||||
algo = int(options['algo'])
|
algo = int(options['algo'])
|
||||||
# chs if fully specified then take this one
|
# chs if fully specified then take this one
|
||||||
if c != None and h != None and s != None:
|
if c != None and h != None and s != None:
|
||||||
@ -73,7 +73,7 @@ class DiskGeometry:
|
|||||||
return self.get_num_bytes()
|
return self.get_num_bytes()
|
||||||
else:
|
else:
|
||||||
# we require a size
|
# we require a size
|
||||||
if not options.has_key('size'):
|
if 'size' not in options:
|
||||||
return None
|
return None
|
||||||
# parse size
|
# parse size
|
||||||
size = options['size']
|
size = options['size']
|
||||||
@ -83,7 +83,7 @@ class DiskGeometry:
|
|||||||
return None
|
return None
|
||||||
# select guess algo
|
# select guess algo
|
||||||
algo = None
|
algo = None
|
||||||
if options.has_key('algo'):
|
if 'algo' in options:
|
||||||
algo = int(options['algo'])
|
algo = int(options['algo'])
|
||||||
# guess size
|
# guess size
|
||||||
return self._guess_for_size(size, approx=True, algo=algo, secs=s, heads=h)
|
return self._guess_for_size(size, approx=True, algo=algo, secs=s, heads=h)
|
||||||
@ -93,16 +93,16 @@ class DiskGeometry:
|
|||||||
h = None
|
h = None
|
||||||
s = None
|
s = None
|
||||||
# chs=<n>,<n>,<n>
|
# chs=<n>,<n>,<n>
|
||||||
if options.has_key('chs'):
|
if 'chs' in options:
|
||||||
comp = options['chs'].split(',')
|
comp = options['chs'].split(',')
|
||||||
if len(comp) == 3:
|
if len(comp) == 3:
|
||||||
return map(lambda x: int(x), comp)
|
return [int(x) for x in comp]
|
||||||
else:
|
else:
|
||||||
if options.has_key('s'):
|
if 's' in options:
|
||||||
s = int(options['s'])
|
s = int(options['s'])
|
||||||
if options.has_key('h'):
|
if 'h' in options:
|
||||||
h = int(options['h'])
|
h = int(options['h'])
|
||||||
if options.has_key('c'):
|
if 'c' in options:
|
||||||
c = int(options['c'])
|
c = int(options['c'])
|
||||||
return (c,h,s)
|
return (c,h,s)
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .BlockDevice import BlockDevice
|
from .BlockDevice import BlockDevice
|
||||||
from .DiskGeometry import DiskGeometry
|
from .DiskGeometry import DiskGeometry
|
||||||
|
|||||||
@ -84,12 +84,12 @@ class ImageFile:
|
|||||||
raise IOError("Can't create image file in read only mode")
|
raise IOError("Can't create image file in read only mode")
|
||||||
block = '\0' * self.block_bytes
|
block = '\0' * self.block_bytes
|
||||||
if self.fobj is not None:
|
if self.fobj is not None:
|
||||||
for i in xrange(num_blocks):
|
for i in range(num_blocks):
|
||||||
self.fobj.write(block)
|
self.fobj.write(block)
|
||||||
self.fobj.seek(0,0)
|
self.fobj.seek(0,0)
|
||||||
else:
|
else:
|
||||||
fh = file(self.file_name, "wb")
|
fh = file(self.file_name, "wb")
|
||||||
for i in xrange(num_blocks):
|
for i in range(num_blocks):
|
||||||
fh.write(block)
|
fh.write(block)
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .BlockDevice import BlockDevice
|
from .BlockDevice import BlockDevice
|
||||||
import os.path
|
import os.path
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .BlockDevice import BlockDevice
|
from .BlockDevice import BlockDevice
|
||||||
import os.path
|
import os.path
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .Block import Block
|
from .Block import Block
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .Block import Block
|
from .Block import Block
|
||||||
from amitools.util.HexDump import *
|
from amitools.util.HexDump import *
|
||||||
@ -19,7 +19,7 @@ class BitmapExtBlock(Block):
|
|||||||
def _read(self):
|
def _read(self):
|
||||||
# read bitmap blk ptrs
|
# read bitmap blk ptrs
|
||||||
self.bitmap_ptrs = []
|
self.bitmap_ptrs = []
|
||||||
for i in xrange(self.blkdev.block_longs-1):
|
for i in range(self.blkdev.block_longs-1):
|
||||||
bm_blk = self._get_long(i)
|
bm_blk = self._get_long(i)
|
||||||
self.bitmap_ptrs.append(bm_blk)
|
self.bitmap_ptrs.append(bm_blk)
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ class BitmapExtBlock(Block):
|
|||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
self.bitmap_ptrs = []
|
self.bitmap_ptrs = []
|
||||||
for i in xrange(self.blkdev.block_longs-1):
|
for i in range(self.blkdev.block_longs-1):
|
||||||
self.bitmap_ptrs.append(0)
|
self.bitmap_ptrs.append(0)
|
||||||
self.bitmap_ext_blk = 0
|
self.bitmap_ext_blk = 0
|
||||||
self.valid = True
|
self.valid = True
|
||||||
@ -38,7 +38,7 @@ class BitmapExtBlock(Block):
|
|||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
self._create_data()
|
self._create_data()
|
||||||
for i in xrange(self.blkdev.block_longs-1):
|
for i in range(self.blkdev.block_longs-1):
|
||||||
self._put_long(i, self.bitmap_ptrs[i])
|
self._put_long(i, self.bitmap_ptrs[i])
|
||||||
self._put_long(-1, self.bitmap_ext_blk)
|
self._put_long(-1, self.bitmap_ext_blk)
|
||||||
self._write_data()
|
self._write_data()
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
import ctypes
|
import ctypes
|
||||||
@ -149,7 +149,7 @@ class Block:
|
|||||||
|
|
||||||
def _calc_chksum(self):
|
def _calc_chksum(self):
|
||||||
chksum = 0
|
chksum = 0
|
||||||
for i in xrange(self.block_longs):
|
for i in range(self.block_longs):
|
||||||
if i != self.chk_loc:
|
if i != self.chk_loc:
|
||||||
chksum += self._get_long(i)
|
chksum += self._get_long(i)
|
||||||
return (-chksum) & 0xffffffff
|
return (-chksum) & 0xffffffff
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
@ -36,7 +36,7 @@ class BootBlock(Block):
|
|||||||
self.got_root_blk = self.calc_root_blk
|
self.got_root_blk = self.calc_root_blk
|
||||||
# create extra blks
|
# create extra blks
|
||||||
self.extra_blks = []
|
self.extra_blks = []
|
||||||
for i in xrange(self.num_extra):
|
for i in range(self.num_extra):
|
||||||
b = Block(self.blkdev, self.blk_num + 1 + i)
|
b = Block(self.blkdev, self.blk_num + 1 + i)
|
||||||
b._create_data()
|
b._create_data()
|
||||||
self.extra_blks.append(b)
|
self.extra_blks.append(b)
|
||||||
@ -60,7 +60,7 @@ class BootBlock(Block):
|
|||||||
n = self.blkdev.block_longs
|
n = self.blkdev.block_longs
|
||||||
chksum = 0
|
chksum = 0
|
||||||
for blk in all_blks:
|
for blk in all_blks:
|
||||||
for i in xrange(n):
|
for i in range(n):
|
||||||
if i != 1: # skip chksum
|
if i != 1: # skip chksum
|
||||||
chksum += blk._get_long(i)
|
chksum += blk._get_long(i)
|
||||||
if chksum > 0xffffffff:
|
if chksum > 0xffffffff:
|
||||||
@ -72,7 +72,7 @@ class BootBlock(Block):
|
|||||||
self._read_data()
|
self._read_data()
|
||||||
# read extra boot blocks
|
# read extra boot blocks
|
||||||
self.extra_blks = []
|
self.extra_blks = []
|
||||||
for i in xrange(self.num_extra):
|
for i in range(self.num_extra):
|
||||||
b = Block(self.blkdev, self.blk_num + 1 + i)
|
b = Block(self.blkdev, self.blk_num + 1 + i)
|
||||||
b._read_data()
|
b._read_data()
|
||||||
self.extra_blks.append(b)
|
self.extra_blks.append(b)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from .Block import Block
|
from .Block import Block
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import struct
|
import struct
|
||||||
@ -100,7 +100,7 @@ class DirCacheBlock(Block):
|
|||||||
|
|
||||||
# get records
|
# get records
|
||||||
off = 24
|
off = 24
|
||||||
for i in xrange(self.num_records):
|
for i in range(self.num_records):
|
||||||
r = DirCacheRecord()
|
r = DirCacheRecord()
|
||||||
off = r.get(self.data, off)
|
off = r.get(self.data, off)
|
||||||
if off == -1:
|
if off == -1:
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .Block import Block
|
from .Block import Block
|
||||||
from .CommentBlock import CommentBlock
|
from .CommentBlock import CommentBlock
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .Block import Block
|
from .Block import Block
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from .Block import Block
|
from .Block import Block
|
||||||
@ -36,7 +36,7 @@ class FileHeaderBlock(EntryBlock):
|
|||||||
if bc > mbc:
|
if bc > mbc:
|
||||||
bc = mbc
|
bc = mbc
|
||||||
self.data_blocks = []
|
self.data_blocks = []
|
||||||
for i in xrange(bc):
|
for i in range(bc):
|
||||||
self.data_blocks.append(self._get_long(-51-i))
|
self.data_blocks.append(self._get_long(-51-i))
|
||||||
|
|
||||||
self.protect = self._get_long(-48)
|
self.protect = self._get_long(-48)
|
||||||
@ -57,7 +57,7 @@ class FileHeaderBlock(EntryBlock):
|
|||||||
self._put_long(4, self.first_data)
|
self._put_long(4, self.first_data)
|
||||||
|
|
||||||
# data blocks
|
# data blocks
|
||||||
for i in xrange(len(self.data_blocks)):
|
for i in range(len(self.data_blocks)):
|
||||||
self._put_long(-51-i, self.data_blocks[i])
|
self._put_long(-51-i, self.data_blocks[i])
|
||||||
|
|
||||||
self._put_long(-48, self.protect)
|
self._put_long(-48, self.protect)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .Block import Block
|
from .Block import Block
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ class FileListBlock(Block):
|
|||||||
if bc > mbc:
|
if bc > mbc:
|
||||||
bc = mbc
|
bc = mbc
|
||||||
self.data_blocks = []
|
self.data_blocks = []
|
||||||
for i in xrange(bc):
|
for i in range(bc):
|
||||||
self.data_blocks.append(self._get_long(-51-i))
|
self.data_blocks.append(self._get_long(-51-i))
|
||||||
|
|
||||||
self.parent = self._get_long(-3)
|
self.parent = self._get_long(-3)
|
||||||
@ -55,7 +55,7 @@ class FileListBlock(Block):
|
|||||||
self._put_long(2, self.block_count)
|
self._put_long(2, self.block_count)
|
||||||
|
|
||||||
# data blocks
|
# data blocks
|
||||||
for i in xrange(len(self.data_blocks)):
|
for i in range(len(self.data_blocks)):
|
||||||
self._put_long(-51-i, self.data_blocks[i])
|
self._put_long(-51-i, self.data_blocks[i])
|
||||||
|
|
||||||
self._put_long(-3, self.parent)
|
self._put_long(-3, self.parent)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@ -20,7 +20,7 @@ class RootBlock(Block):
|
|||||||
# init fresh hash table
|
# init fresh hash table
|
||||||
self.hash_size = self.blkdev.block_longs - 56
|
self.hash_size = self.blkdev.block_longs - 56
|
||||||
self.hash_table = []
|
self.hash_table = []
|
||||||
for i in xrange(self.hash_size):
|
for i in range(self.hash_size):
|
||||||
self.hash_table.append(0)
|
self.hash_table.append(0)
|
||||||
|
|
||||||
# timestamps
|
# timestamps
|
||||||
@ -34,7 +34,7 @@ class RootBlock(Block):
|
|||||||
# bitmap: blank
|
# bitmap: blank
|
||||||
self.bitmap_flag = 0xffffffff
|
self.bitmap_flag = 0xffffffff
|
||||||
self.bitmap_ptrs = []
|
self.bitmap_ptrs = []
|
||||||
for i in xrange(25):
|
for i in range(25):
|
||||||
self.bitmap_ptrs.append(0)
|
self.bitmap_ptrs.append(0)
|
||||||
self.bitmap_ext_blk = 0
|
self.bitmap_ext_blk = 0
|
||||||
|
|
||||||
@ -49,12 +49,12 @@ class RootBlock(Block):
|
|||||||
|
|
||||||
# hash table
|
# hash table
|
||||||
self._put_long(3, self.hash_size)
|
self._put_long(3, self.hash_size)
|
||||||
for i in xrange(self.hash_size):
|
for i in range(self.hash_size):
|
||||||
self._put_long(6+i, self.hash_table[i])
|
self._put_long(6+i, self.hash_table[i])
|
||||||
|
|
||||||
# bitmap
|
# bitmap
|
||||||
self._put_long(-50, self.bitmap_flag)
|
self._put_long(-50, self.bitmap_flag)
|
||||||
for i in xrange(25):
|
for i in range(25):
|
||||||
self._put_long(-49+i, self.bitmap_ptrs[i])
|
self._put_long(-49+i, self.bitmap_ptrs[i])
|
||||||
self._put_long(-24, self.bitmap_ext_blk)
|
self._put_long(-24, self.bitmap_ext_blk)
|
||||||
|
|
||||||
@ -95,13 +95,13 @@ class RootBlock(Block):
|
|||||||
if hs > mhs:
|
if hs > mhs:
|
||||||
hs = mhs
|
hs = mhs
|
||||||
self.hash_table = []
|
self.hash_table = []
|
||||||
for i in xrange(hs):
|
for i in range(hs):
|
||||||
self.hash_table.append(self._get_long(6+i))
|
self.hash_table.append(self._get_long(6+i))
|
||||||
|
|
||||||
# bitmap
|
# bitmap
|
||||||
self.bitmap_flag = self._get_long(-50)
|
self.bitmap_flag = self._get_long(-50)
|
||||||
self.bitmap_ptrs = []
|
self.bitmap_ptrs = []
|
||||||
for i in xrange(25):
|
for i in range(25):
|
||||||
bm_blk = self._get_long(-49+i)
|
bm_blk = self._get_long(-49+i)
|
||||||
self.bitmap_ptrs.append(bm_blk)
|
self.bitmap_ptrs.append(bm_blk)
|
||||||
self.bitmap_ext_blk = self._get_long(-24)
|
self.bitmap_ext_blk = self._get_long(-24)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from .Block import Block
|
from .Block import Block
|
||||||
@ -34,7 +34,7 @@ class UserDirBlock(EntryBlock):
|
|||||||
# hash table of entries
|
# hash table of entries
|
||||||
self.hash_table = []
|
self.hash_table = []
|
||||||
self.hash_size = self.blkdev.block_longs - 56
|
self.hash_size = self.blkdev.block_longs - 56
|
||||||
for i in xrange(self.hash_size):
|
for i in range(self.hash_size):
|
||||||
self.hash_table.append(self._get_long(6+i))
|
self.hash_table.append(self._get_long(6+i))
|
||||||
|
|
||||||
self.valid = (self.own_key == self.blk_num)
|
self.valid = (self.own_key == self.blk_num)
|
||||||
@ -57,7 +57,7 @@ class UserDirBlock(EntryBlock):
|
|||||||
# empty hash table
|
# empty hash table
|
||||||
self.hash_table = []
|
self.hash_table = []
|
||||||
self.hash_size = self.blkdev.block_longs - 56
|
self.hash_size = self.blkdev.block_longs - 56
|
||||||
for i in xrange(self.hash_size):
|
for i in range(self.hash_size):
|
||||||
self.hash_table.append(0)
|
self.hash_table.append(0)
|
||||||
self.valid = True
|
self.valid = True
|
||||||
return True
|
return True
|
||||||
@ -71,7 +71,7 @@ class UserDirBlock(EntryBlock):
|
|||||||
self._put_long(-3, self.parent)
|
self._put_long(-3, self.parent)
|
||||||
self._put_long(-2, self.extension)
|
self._put_long(-2, self.extension)
|
||||||
# hash table
|
# hash table
|
||||||
for i in xrange(self.hash_size):
|
for i in range(self.hash_size):
|
||||||
self._put_long(6+i, self.hash_table[i])
|
self._put_long(6+i, self.hash_table[i])
|
||||||
Block.write(self)
|
Block.write(self)
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from ..Block import Block
|
from ..Block import Block
|
||||||
|
|
||||||
@ -56,6 +56,6 @@ class BadBlockBlock(Block):
|
|||||||
print(" next: %s" % self._dump_ptr(self.next))
|
print(" next: %s" % self._dump_ptr(self.next))
|
||||||
n = len(self.block_pairs) / 2
|
n = len(self.block_pairs) / 2
|
||||||
o = 0
|
o = 0
|
||||||
for i in xrange(n):
|
for i in range(n):
|
||||||
print(" bad=%d good=%d" % (self.block_pairs[o], self.block_pairs[o+1]))
|
print(" bad=%d good=%d" % (self.block_pairs[o], self.block_pairs[o+1]))
|
||||||
o += 2
|
o += 2
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from amitools.fs.block.Block import *
|
from amitools.fs.block.Block import *
|
||||||
import amitools.fs.DosType as DosType
|
import amitools.fs.DosType as DosType
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from ..Block import Block
|
from ..Block import Block
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from amitools.fs.block.Block import *
|
from amitools.fs.block.Block import *
|
||||||
import amitools.fs.DosType as DosType
|
import amitools.fs.DosType as DosType
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from ..Block import Block
|
from ..Block import Block
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from amitools.fs.block.rdb.FSHeaderBlock import *
|
from amitools.fs.block.rdb.FSHeaderBlock import *
|
||||||
from amitools.fs.block.rdb.LoadSegBlock import *
|
from amitools.fs.block.rdb.LoadSegBlock import *
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from amitools.fs.block.rdb.RDBlock import *
|
from amitools.fs.block.rdb.RDBlock import *
|
||||||
from amitools.fs.block.rdb.PartitionBlock import *
|
from amitools.fs.block.rdb.PartitionBlock import *
|
||||||
@ -128,7 +128,7 @@ class RDisk:
|
|||||||
|
|
||||||
def get_block_map(self):
|
def get_block_map(self):
|
||||||
res = []
|
res = []
|
||||||
for i in xrange(self.max_blks):
|
for i in range(self.max_blks):
|
||||||
blk = None
|
blk = None
|
||||||
# check partitions
|
# check partitions
|
||||||
if i == 0:
|
if i == 0:
|
||||||
@ -331,7 +331,7 @@ class RDisk:
|
|||||||
|
|
||||||
def get_free_blocks(self):
|
def get_free_blocks(self):
|
||||||
res = []
|
res = []
|
||||||
for i in xrange(self.max_blks):
|
for i in range(self.max_blks):
|
||||||
if i not in self.used_blks:
|
if i not in self.used_blks:
|
||||||
res.append(i)
|
res.append(i)
|
||||||
return res
|
return res
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from amitools.fs.validate.Log import Log
|
from amitools.fs.validate.Log import Log
|
||||||
import struct
|
import struct
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .BlockScan import BlockScan
|
from .BlockScan import BlockScan
|
||||||
from amitools.fs.FSString import FSString
|
from amitools.fs.FSString import FSString
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from .BlockScan import BlockScan
|
from .BlockScan import BlockScan
|
||||||
from amitools.fs.FSString import FSString
|
from amitools.fs.FSString import FSString
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
class LogEntry:
|
class LogEntry:
|
||||||
"""A class for a log entry"""
|
"""A class for a log entry"""
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
from amitools.fs.block.BootBlock import BootBlock
|
from amitools.fs.block.BootBlock import BootBlock
|
||||||
from amitools.fs.block.RootBlock import RootBlock
|
from amitools.fs.block.RootBlock import RootBlock
|
||||||
|
|||||||
@ -82,6 +82,6 @@ if __name__ == '__main__':
|
|||||||
bin_img = bf.load_image(f)
|
bin_img = bf.load_image(f)
|
||||||
print(bin_img)
|
print(bin_img)
|
||||||
bkm = BlizKickModule(bin_img)
|
bkm = BlizKickModule(bin_img)
|
||||||
print(bkm.bk_type)
|
print((bkm.bk_type))
|
||||||
bkm.fix_module()
|
bkm.fix_module()
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from RomAccess import RomAccess
|
from .RomAccess import RomAccess
|
||||||
|
|
||||||
class KickRomAccess(RomAccess):
|
class KickRomAccess(RomAccess):
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ class KickRomAccess(RomAccess):
|
|||||||
# expect 0x0019 ... 0x001f
|
# expect 0x0019 ... 0x001f
|
||||||
off = self.size - 14
|
off = self.size - 14
|
||||||
num = 0x19
|
num = 0x19
|
||||||
for i in xrange(7):
|
for i in range(7):
|
||||||
val = self.read_word(off)
|
val = self.read_word(off)
|
||||||
if val != num:
|
if val != num:
|
||||||
return False
|
return False
|
||||||
@ -84,7 +84,7 @@ class KickRomAccess(RomAccess):
|
|||||||
num_longs = self.size / 4
|
num_longs = self.size / 4
|
||||||
off = 0
|
off = 0
|
||||||
max_u32 = 0xffffffff
|
max_u32 = 0xffffffff
|
||||||
for i in xrange(num_longs):
|
for i in range(num_longs):
|
||||||
val = struct.unpack_from(">I", self.rom_data, off)[0]
|
val = struct.unpack_from(">I", self.rom_data, off)[0]
|
||||||
if off != skip_off:
|
if off != skip_off:
|
||||||
chk_sum += val
|
chk_sum += val
|
||||||
@ -144,7 +144,7 @@ class KickRomAccess(RomAccess):
|
|||||||
def write_footer(self):
|
def write_footer(self):
|
||||||
off = self.size - 0x10
|
off = self.size - 0x10
|
||||||
num = 0x18
|
num = 0x18
|
||||||
for i in xrange(8):
|
for i in range(8):
|
||||||
self.write_word(off, num)
|
self.write_word(off, num)
|
||||||
num += 1
|
num += 1
|
||||||
off += 2
|
off += 2
|
||||||
@ -205,7 +205,7 @@ class Loader(object):
|
|||||||
def _decode(cls, img, rom_key):
|
def _decode(cls, img, rom_key):
|
||||||
data = bytearray(img)
|
data = bytearray(img)
|
||||||
n = len(rom_key)
|
n = len(rom_key)
|
||||||
for i in xrange(len(data)):
|
for i in range(len(data)):
|
||||||
off = i % n
|
off = i % n
|
||||||
data[i] = data[i] ^ ord(rom_key[off])
|
data[i] = data[i] ^ ord(rom_key[off])
|
||||||
return bytes(data)
|
return bytes(data)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
@ -48,13 +48,13 @@ class RemusRomModuleExtra(object):
|
|||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
if len(self.relocs) > 0:
|
if len(self.relocs) > 0:
|
||||||
print(" relocs: ", ",".join(map(lambda x: "%08x" % x, self.relocs)))
|
print(" relocs: ", ",".join(["%08x" % x for x in self.relocs]))
|
||||||
if len(self.patches) > 0:
|
if len(self.patches) > 0:
|
||||||
print(" patches:", ",".join(map(lambda x: "%08x:%08x" % x, self.patches)))
|
print(" patches:", ",".join(["%08x:%08x" % x for x in self.patches]))
|
||||||
if len(self.brelocs) > 0:
|
if len(self.brelocs) > 0:
|
||||||
print(" brelocs:", ",".join(map(lambda x: "%08x" % x, self.brelocs)))
|
print(" brelocs:", ",".join(["%08x" % x for x in self.brelocs]))
|
||||||
if len(self.fixes) > 0:
|
if len(self.fixes) > 0:
|
||||||
print(" fixes: ", ",".join(map(lambda x: "%08x:%08x" % x, self.fixes)))
|
print(" fixes: ", ",".join(["%08x:%08x" % x for x in self.fixes]))
|
||||||
if self.chk_sum:
|
if self.chk_sum:
|
||||||
print(" chk_sum: %08x" % self.chk_sum)
|
print(" chk_sum: %08x" % self.chk_sum)
|
||||||
|
|
||||||
@ -225,39 +225,39 @@ class RemusSplitFile(RemusFile):
|
|||||||
# short patch
|
# short patch
|
||||||
if flags & FLAG_SHORT_PATCHES:
|
if flags & FLAG_SHORT_PATCHES:
|
||||||
num = self._read_word()
|
num = self._read_word()
|
||||||
for i in xrange(num):
|
for i in range(num):
|
||||||
offset = self._read_word()
|
offset = self._read_word()
|
||||||
val = self._read_long()
|
val = self._read_long()
|
||||||
patches.append((offset,val))
|
patches.append((offset,val))
|
||||||
# long patch
|
# long patch
|
||||||
if flags & FLAG_LONG_PATCHES:
|
if flags & FLAG_LONG_PATCHES:
|
||||||
num_patches = self._read_word()
|
num_patches = self._read_word()
|
||||||
for i in xrange(num_patches):
|
for i in range(num_patches):
|
||||||
offset = self._read_long()
|
offset = self._read_long()
|
||||||
val = self._read_long()
|
val = self._read_long()
|
||||||
patches.append((offset,val))
|
patches.append((offset,val))
|
||||||
# short relocs
|
# short relocs
|
||||||
if flags & FLAG_SHORT_RELOCS:
|
if flags & FLAG_SHORT_RELOCS:
|
||||||
num_short_relocs = self._read_word()
|
num_short_relocs = self._read_word()
|
||||||
for i in xrange(num_short_relocs):
|
for i in range(num_short_relocs):
|
||||||
off = self._read_word()
|
off = self._read_word()
|
||||||
relocs.append(off)
|
relocs.append(off)
|
||||||
# long relocs
|
# long relocs
|
||||||
if flags & FLAG_LONG_RELOCS:
|
if flags & FLAG_LONG_RELOCS:
|
||||||
num_long_relocs = self._read_word()
|
num_long_relocs = self._read_word()
|
||||||
for i in xrange(num_long_relocs):
|
for i in range(num_long_relocs):
|
||||||
off = self._read_long()
|
off = self._read_long()
|
||||||
relocs.append(off)
|
relocs.append(off)
|
||||||
# old dos.library BCPL relocs
|
# old dos.library BCPL relocs
|
||||||
if flags & FLAG_SHORT_BCPL_RELOCS:
|
if flags & FLAG_SHORT_BCPL_RELOCS:
|
||||||
num = self._read_word()
|
num = self._read_word()
|
||||||
for i in xrange(num):
|
for i in range(num):
|
||||||
off = self._read_word()
|
off = self._read_word()
|
||||||
brelocs.append(off)
|
brelocs.append(off)
|
||||||
# fixes
|
# fixes
|
||||||
if flags & FLAG_FIXES:
|
if flags & FLAG_FIXES:
|
||||||
num = self._read_word()
|
num = self._read_word()
|
||||||
for i in xrange(num):
|
for i in range(num):
|
||||||
off = self._read_long()
|
off = self._read_long()
|
||||||
val = self._read_long()
|
val = self._read_long()
|
||||||
fixes.append((off,val))
|
fixes.append((off,val))
|
||||||
@ -372,7 +372,7 @@ class RemusFileSet(object):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
import KickRom
|
from . import KickRom
|
||||||
|
|
||||||
if len(sys.argv) > 0:
|
if len(sys.argv) > 0:
|
||||||
for f in sys.argv[1:]:
|
for f in sys.argv[1:]:
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from RomAccess import RomAccess
|
from .RomAccess import RomAccess
|
||||||
|
|
||||||
|
|
||||||
RTC_MATCHWORD = 0x4AFC
|
RTC_MATCHWORD = 0x4AFC
|
||||||
@ -145,10 +145,10 @@ class ResidentScan:
|
|||||||
base_map[base_addr] += 1
|
base_map[base_addr] += 1
|
||||||
# one match
|
# one match
|
||||||
if len(base_map) == 1:
|
if len(base_map) == 1:
|
||||||
addr = base_map.keys()[0]
|
addr = list(base_map.keys())[0]
|
||||||
return addr
|
return addr
|
||||||
else:
|
else:
|
||||||
return sorted(base_map.keys(), key=lambda x:base_map[x])
|
return sorted(list(base_map.keys()), key=lambda x:base_map[x])
|
||||||
|
|
||||||
def get_all_resident_pos(self):
|
def get_all_resident_pos(self):
|
||||||
offs = self.get_all_matchwords()
|
offs = self.get_all_matchwords()
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import struct
|
|||||||
|
|
||||||
from amitools.binfmt.BinImage import *
|
from amitools.binfmt.BinImage import *
|
||||||
from amitools.binfmt.Relocate import *
|
from amitools.binfmt.Relocate import *
|
||||||
from KickRom import KickRomAccess
|
from .KickRom import KickRomAccess
|
||||||
|
|
||||||
|
|
||||||
class RomEntryRaw:
|
class RomEntryRaw:
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from RomAccess import RomAccess
|
from .RomAccess import RomAccess
|
||||||
|
|
||||||
|
|
||||||
class RomPatch:
|
class RomPatch:
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
import KickRom
|
from . import KickRom
|
||||||
import RemusFile
|
from . import RemusFile
|
||||||
import amitools.util.DataDir as DataDir
|
import amitools.util.DataDir as DataDir
|
||||||
from amitools.binfmt.BinImage import *
|
from amitools.binfmt.BinImage import *
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
"""Scan an ADF image an visit all files"""
|
"""Scan an ADF image an visit all files"""
|
||||||
|
|
||||||
import StringIO
|
import io
|
||||||
|
|
||||||
from amitools.fs.blkdev.BlkDevFactory import BlkDevFactory
|
from amitools.fs.blkdev.BlkDevFactory import BlkDevFactory
|
||||||
from amitools.fs.ADFSVolume import ADFSVolume
|
from amitools.fs.ADFSVolume import ADFSVolume
|
||||||
@ -50,7 +50,7 @@ class ADFSScanner:
|
|||||||
node.flush()
|
node.flush()
|
||||||
size = len(data)
|
size = len(data)
|
||||||
path = node.get_node_path_name().get_unicode()
|
path = node.get_node_path_name().get_unicode()
|
||||||
fobj = StringIO.StringIO(data)
|
fobj = io.StringIO(data)
|
||||||
sf = scan_file.create_sub_path(path, fobj, size, True, False)
|
sf = scan_file.create_sub_path(path, fobj, size, True, False)
|
||||||
ok = scanner.scan_obj(sf)
|
ok = scanner.scan_obj(sf)
|
||||||
sf.close()
|
sf.close()
|
||||||
@ -59,17 +59,17 @@ class ADFSScanner:
|
|||||||
# mini test
|
# mini test
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
from FileScanner import FileScanner
|
from .FileScanner import FileScanner
|
||||||
|
|
||||||
ifs = ['*.txt']
|
ifs = ['*.txt']
|
||||||
def handler(scan_file):
|
def handler(scan_file):
|
||||||
print(scan_file)
|
print(scan_file)
|
||||||
return True
|
return True
|
||||||
def skip_handler(scan_file):
|
def skip_handler(scan_file):
|
||||||
print("SKIP:", scan_file)
|
print(("SKIP:", scan_file))
|
||||||
return True
|
return True
|
||||||
def error_handler(scan_file, error):
|
def error_handler(scan_file, error):
|
||||||
print("FAILED:", scan_file, error)
|
print(("FAILED:", scan_file, error))
|
||||||
raise error
|
raise error
|
||||||
scanners = [ADFSScanner()]
|
scanners = [ADFSScanner()]
|
||||||
fs = FileScanner(handler, ignore_filters=ifs, error_handler=error_handler,
|
fs = FileScanner(handler, ignore_filters=ifs, error_handler=error_handler,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
import StringIO
|
import io
|
||||||
|
|
||||||
# optional lhafile
|
# optional lhafile
|
||||||
try:
|
try:
|
||||||
@ -61,7 +61,7 @@ class ZipScanner(ArchiveScanner):
|
|||||||
fobj = sf.get_fobj()
|
fobj = sf.get_fobj()
|
||||||
return zipfile.ZipFile(fobj, "r")
|
return zipfile.ZipFile(fobj, "r")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
scanner.warn(sf, "error reading archive: %s" % e)
|
scanner.warning(sf, "error reading archive: %s" % e)
|
||||||
|
|
||||||
def _create_entry_scan_file(self, arc, info, scan_file):
|
def _create_entry_scan_file(self, arc, info, scan_file):
|
||||||
name = info.filename
|
name = info.filename
|
||||||
@ -82,13 +82,13 @@ class LhaScanner(ArchiveScanner):
|
|||||||
fobj = sf.get_fobj()
|
fobj = sf.get_fobj()
|
||||||
return lhafile.LhaFile(fobj, "r")
|
return lhafile.LhaFile(fobj, "r")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
scanner.warn(sf, "error reading archive: %s" % e)
|
scanner.warning(sf, "error reading archive: %s" % e)
|
||||||
else:
|
else:
|
||||||
scanner.warn(sf, "can't handle archive. missing 'lhafile' module.")
|
scanner.warning(sf, "can't handle archive. missing 'lhafile' module.")
|
||||||
|
|
||||||
def _create_entry_scan_file(self, arc, info, scan_file):
|
def _create_entry_scan_file(self, arc, info, scan_file):
|
||||||
data = arc.read(info.filename)
|
data = arc.read(info.filename)
|
||||||
fobj = StringIO.StringIO(data)
|
fobj = io.StringIO(data)
|
||||||
size = info.file_size
|
size = info.file_size
|
||||||
name = info.filename
|
name = info.filename
|
||||||
return scan_file.create_sub_path(name, fobj, size, True, False)
|
return scan_file.create_sub_path(name, fobj, size, True, False)
|
||||||
@ -97,7 +97,7 @@ class LhaScanner(ArchiveScanner):
|
|||||||
# mini test
|
# mini test
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
from FileScanner import FileScanner
|
from .FileScanner import FileScanner
|
||||||
|
|
||||||
ifs = ['*.txt']
|
ifs = ['*.txt']
|
||||||
def handler(scan_file):
|
def handler(scan_file):
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
# scan a set of file
|
# scan a set of file
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from ScanFile import ScanFile
|
from .ScanFile import ScanFile
|
||||||
|
|
||||||
class FileScanner:
|
class FileScanner:
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import StringIO
|
import io
|
||||||
|
|
||||||
class ScanFile:
|
class ScanFile:
|
||||||
"""a file that is currently scanned"""
|
"""a file that is currently scanned"""
|
||||||
@ -69,7 +69,7 @@ class ScanFile:
|
|||||||
# create a string buffer
|
# create a string buffer
|
||||||
else:
|
else:
|
||||||
data = src_fobj.read()
|
data = src_fobj.read()
|
||||||
fobj = StringIO.StringIO(data)
|
fobj = io.StringIO(data)
|
||||||
# close old scan file
|
# close old scan file
|
||||||
src_fobj.close()
|
src_fobj.close()
|
||||||
# create promoted file
|
# create promoted file
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# fdtool <file.fd> ...
|
# fdtool <file.fd> ...
|
||||||
#
|
#
|
||||||
@ -12,13 +12,13 @@ import amitools.fd.FDFormat as FDFormat
|
|||||||
|
|
||||||
def dump(fname, fd, add_private):
|
def dump(fname, fd, add_private):
|
||||||
print(fname)
|
print(fname)
|
||||||
print(" base: %s" % fd.get_base_name())
|
print((" base: %s" % fd.get_base_name()))
|
||||||
funcs = fd.get_funcs()
|
funcs = fd.get_funcs()
|
||||||
num = 1
|
num = 1
|
||||||
for f in funcs:
|
for f in funcs:
|
||||||
if add_private or not f.is_private():
|
if add_private or not f.is_private():
|
||||||
bias = f.get_bias()
|
bias = f.get_bias()
|
||||||
print(" #%04d %5d 0x%04x %30s %s" % (num,bias,bias,f.get_name(),f.get_arg_str()))
|
print((" #%04d %5d 0x%04x %30s %s" % (num,bias,bias,f.get_name(),f.get_arg_str())))
|
||||||
num += 1
|
num += 1
|
||||||
|
|
||||||
# ----- generate -----
|
# ----- generate -----
|
||||||
@ -32,7 +32,7 @@ def generate_python_code(fd, add_private):
|
|||||||
args = tuple(args)
|
args = tuple(args)
|
||||||
else:
|
else:
|
||||||
args = None
|
args = None
|
||||||
print " (%d, '%s', %s)," % (f.get_bias(),f.get_name(),args)
|
print(" (%d, '%s', %s)," % (f.get_bias(),f.get_name(),args))
|
||||||
|
|
||||||
def generate_sasc_code(fname, fd, add_private, prefix=""):
|
def generate_sasc_code(fname, fd, add_private, prefix=""):
|
||||||
funcs = fd.get_funcs()
|
funcs = fd.get_funcs()
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
import os.path
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# hunktool
|
# hunktool
|
||||||
#
|
#
|
||||||
@ -34,15 +34,15 @@ class HunkCommand:
|
|||||||
self.failed_files = []
|
self.failed_files = []
|
||||||
|
|
||||||
def handle_file(self, path, hunk_file, error_code, delta):
|
def handle_file(self, path, hunk_file, error_code, delta):
|
||||||
if not self.counts.has_key(error_code):
|
if error_code not in self.counts:
|
||||||
self.counts[error_code] = 0
|
self.counts[error_code] = 0
|
||||||
self.counts[error_code] += 1
|
self.counts[error_code] += 1
|
||||||
|
|
||||||
print "%s (%.4fs)" % (path, delta),
|
print("%s (%.4fs)" % (path, delta), end=' ')
|
||||||
|
|
||||||
# abort if hunk parser failed!
|
# abort if hunk parser failed!
|
||||||
if error_code != Hunk.RESULT_OK:
|
if error_code != Hunk.RESULT_OK:
|
||||||
print Hunk.result_names[error_code], hunk_file.error_string
|
print(Hunk.result_names[error_code], hunk_file.error_string)
|
||||||
if self.args.dump:
|
if self.args.dump:
|
||||||
print_pretty(hunk_file.hunks)
|
print_pretty(hunk_file.hunks)
|
||||||
self.failed_files.append( (path, "READ: " + hunk_file.error_string) )
|
self.failed_files.append( (path, "READ: " + hunk_file.error_string) )
|
||||||
@ -50,43 +50,43 @@ class HunkCommand:
|
|||||||
|
|
||||||
# if verbose then print block structure
|
# if verbose then print block structure
|
||||||
if self.args.verbose:
|
if self.args.verbose:
|
||||||
print
|
print()
|
||||||
print " hunks: ",hunk_file.get_hunk_summary()
|
print(" hunks: ",hunk_file.get_hunk_summary())
|
||||||
if self.args.dump:
|
if self.args.dump:
|
||||||
print_pretty(hunk_file.hunks)
|
print_pretty(hunk_file.hunks)
|
||||||
print " type: ",
|
print(" type: ", end=' ')
|
||||||
|
|
||||||
# build segments from hunks
|
# build segments from hunks
|
||||||
ok = hunk_file.build_segments()
|
ok = hunk_file.build_segments()
|
||||||
if not ok:
|
if not ok:
|
||||||
print "BUILD SEGMENTS FAILED: %s" % (hunk_file.error_string)
|
print("BUILD SEGMENTS FAILED: %s" % (hunk_file.error_string))
|
||||||
self.failed_files.append( (path, "BUILD: " + hunk_file.error_string) )
|
self.failed_files.append( (path, "BUILD: " + hunk_file.error_string) )
|
||||||
return not self.args.stop
|
return not self.args.stop
|
||||||
|
|
||||||
# print recognized file type name
|
# print recognized file type name
|
||||||
print Hunk.type_names[hunk_file.type],
|
print(Hunk.type_names[hunk_file.type], end=' ')
|
||||||
|
|
||||||
# if verbose then print hunk structure
|
# if verbose then print hunk structure
|
||||||
if self.args.verbose:
|
if self.args.verbose:
|
||||||
print
|
print()
|
||||||
print " segments: ",hunk_file.get_segment_summary()
|
print(" segments: ",hunk_file.get_segment_summary())
|
||||||
print " overlays: ",hunk_file.get_overlay_segment_summary()
|
print(" overlays: ",hunk_file.get_overlay_segment_summary())
|
||||||
print " libs: ",hunk_file.get_libs_summary()
|
print(" libs: ",hunk_file.get_libs_summary())
|
||||||
print " units: ",hunk_file.get_units_summary()
|
print(" units: ",hunk_file.get_units_summary())
|
||||||
if self.args.dump:
|
if self.args.dump:
|
||||||
print_pretty(hunk_file.hunks)
|
print_pretty(hunk_file.hunks)
|
||||||
else:
|
else:
|
||||||
print
|
print()
|
||||||
|
|
||||||
# do special processing on hunk file for command
|
# do special processing on hunk file for command
|
||||||
ok = self.handle_hunk_file(path, hunk_file)
|
ok = self.handle_hunk_file(path, hunk_file)
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
def result(self):
|
def result(self):
|
||||||
for code in self.counts.keys():
|
for code in list(self.counts.keys()):
|
||||||
print Hunk.result_names[code],":",self.counts[code]
|
print(Hunk.result_names[code],":",self.counts[code])
|
||||||
for failed in self.failed_files:
|
for failed in self.failed_files:
|
||||||
print failed[0],failed[1]
|
print(failed[0],failed[1])
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def process_file(self, scan_file):
|
def process_file(self, scan_file):
|
||||||
@ -105,10 +105,10 @@ class HunkCommand:
|
|||||||
def run(self):
|
def run(self):
|
||||||
# setup error handler
|
# setup error handler
|
||||||
def error_handler(sf, e):
|
def error_handler(sf, e):
|
||||||
print "FAILED", sf.get_path(), e
|
print("FAILED", sf.get_path(), e)
|
||||||
return not self.args.stop
|
return not self.args.stop
|
||||||
def warning_handler(sf, msg):
|
def warning_handler(sf, msg):
|
||||||
print "WARNING", sf.get_path(), msg
|
print("WARNING", sf.get_path(), msg)
|
||||||
# setup scanners
|
# setup scanners
|
||||||
scanners = [ADFSScanner(), ZipScanner(), LhaScanner()]
|
scanners = [ADFSScanner(), ZipScanner(), LhaScanner()]
|
||||||
scanner = FileScanner(self.process_file,
|
scanner = FileScanner(self.process_file,
|
||||||
@ -118,7 +118,7 @@ class HunkCommand:
|
|||||||
for path in self.args.files:
|
for path in self.args.files:
|
||||||
ok = scanner.scan(path)
|
ok = scanner.scan(path)
|
||||||
if not ok:
|
if not ok:
|
||||||
print "ABORTED"
|
print("ABORTED")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ class Relocate(HunkCommand):
|
|||||||
|
|
||||||
def handle_hunk_file(self, path, hunk_file):
|
def handle_hunk_file(self, path, hunk_file):
|
||||||
if hunk_file.type != Hunk.TYPE_LOADSEG:
|
if hunk_file.type != Hunk.TYPE_LOADSEG:
|
||||||
print "ERROR: can only relocate LoadSeg()able files:",path;
|
print("ERROR: can only relocate LoadSeg()able files:",path);
|
||||||
return False
|
return False
|
||||||
|
|
||||||
rel = HunkRelocate.HunkRelocate(hunk_file,verbose=self.args.verbose)
|
rel = HunkRelocate.HunkRelocate(hunk_file,verbose=self.args.verbose)
|
||||||
@ -164,14 +164,14 @@ class Relocate(HunkCommand):
|
|||||||
# relocate and return data of segments
|
# relocate and return data of segments
|
||||||
datas = rel.relocate(addrs)
|
datas = rel.relocate(addrs)
|
||||||
if datas == None:
|
if datas == None:
|
||||||
print "ERROR: relocation failed:",path
|
print("ERROR: relocation failed:",path)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
print "Relocate to base address",base_addr
|
print("Relocate to base address",base_addr)
|
||||||
print "Bases: "," ".join(map(lambda x:"%06x"%(x),addrs))
|
print("Bases: "," ".join(["%06x"%(x) for x in addrs]))
|
||||||
print "Sizes: "," ".join(map(lambda x:"%06x"%(x),sizes))
|
print("Sizes: "," ".join(["%06x"%(x) for x in sizes]))
|
||||||
print "Data: "," ".join(map(lambda x:"%06x"%(len(x)),datas))
|
print("Data: "," ".join(["%06x"%(len(x)) for x in datas]))
|
||||||
print "Total: ","%06x"%(rel.get_total_size())
|
print("Total: ","%06x"%(rel.get_total_size()))
|
||||||
if args.hexdump:
|
if args.hexdump:
|
||||||
for d in datas:
|
for d in datas:
|
||||||
print_hex(d)
|
print_hex(d)
|
||||||
@ -188,7 +188,7 @@ class ElfInfo:
|
|||||||
reader = amitools.binfmt.elf.ELFReader()
|
reader = amitools.binfmt.elf.ELFReader()
|
||||||
elf = reader.load(open(f, "rb"))
|
elf = reader.load(open(f, "rb"))
|
||||||
if elf is None:
|
if elf is None:
|
||||||
print "ERROR loading ELF:",elf.error_string
|
print("ERROR loading ELF:",elf.error_string)
|
||||||
return 1
|
return 1
|
||||||
dumper = amitools.binfmt.elf.ELFDumper(elf)
|
dumper = amitools.binfmt.elf.ELFDumper(elf)
|
||||||
dumper.dump_sections(show_relocs=args.show_relocs, show_debug=args.show_debug)
|
dumper.dump_sections(show_relocs=args.show_relocs, show_debug=args.show_debug)
|
||||||
@ -207,7 +207,7 @@ def main():
|
|||||||
}
|
}
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('command', help="command: "+",".join(cmd_map.keys()))
|
parser.add_argument('command', help="command: "+",".join(list(cmd_map.keys())))
|
||||||
parser.add_argument('files', nargs='+')
|
parser.add_argument('files', nargs='+')
|
||||||
parser.add_argument('-d', '--dump', action='store_true', default=False, help="dump the hunk structure")
|
parser.add_argument('-d', '--dump', action='store_true', default=False, help="dump the hunk structure")
|
||||||
parser.add_argument('-v', '--verbose', action='store_true', default=False, help="be more verbos")
|
parser.add_argument('-v', '--verbose', action='store_true', default=False, help="be more verbos")
|
||||||
@ -224,11 +224,11 @@ def main():
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
cmd = args.command
|
cmd = args.command
|
||||||
if not cmd_map.has_key(cmd):
|
if cmd not in cmd_map:
|
||||||
print "INVALID COMMAND:",cmd
|
print("INVALID COMMAND:",cmd)
|
||||||
print "valid commands are:"
|
print("valid commands are:")
|
||||||
for a in cmd_map:
|
for a in cmd_map:
|
||||||
print " ",a
|
print(" ",a)
|
||||||
return 1
|
return 1
|
||||||
cmd_cls = cmd_map[cmd]
|
cmd_cls = cmd_map[cmd]
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
# rdbtool
|
# rdbtool
|
||||||
# swiss army knife for rdb disk images or devices
|
# swiss army knife for rdb disk images or devices
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
@ -256,7 +256,7 @@ class InitCommand(OpenCommand):
|
|||||||
def init_rdisk(self, blkdev):
|
def init_rdisk(self, blkdev):
|
||||||
opts = KeyValue.parse_key_value_strings(self.opts)
|
opts = KeyValue.parse_key_value_strings(self.opts)
|
||||||
# number of cylinders for RDB
|
# number of cylinders for RDB
|
||||||
if opts.has_key('rdb_cyls'):
|
if 'rdb_cyls' in opts:
|
||||||
rdb_cyls = int(opts['rdb_cyls'])
|
rdb_cyls = int(opts['rdb_cyls'])
|
||||||
else:
|
else:
|
||||||
rdb_cyls = 1
|
rdb_cyls = 1
|
||||||
@ -319,9 +319,9 @@ class PartEditCommand(Command):
|
|||||||
self.rdisk = rdisk
|
self.rdisk = rdisk
|
||||||
|
|
||||||
def get_dos_type(self, empty=False):
|
def get_dos_type(self, empty=False):
|
||||||
if self.popts.has_key('fs'):
|
if 'fs' in self.popts:
|
||||||
fs_str = self.popts['fs']
|
fs_str = self.popts['fs']
|
||||||
elif self.popts.has_key('dostype'):
|
elif 'dostype' in self.popts:
|
||||||
fs_str = self.popts['dostype']
|
fs_str = self.popts['dostype']
|
||||||
elif not empty:
|
elif not empty:
|
||||||
fs_str = self.args.dostype
|
fs_str = self.args.dostype
|
||||||
@ -330,7 +330,7 @@ class PartEditCommand(Command):
|
|||||||
return parse_dos_type_str(str(fs_str))
|
return parse_dos_type_str(str(fs_str))
|
||||||
|
|
||||||
def get_drv_name(self, empty=False):
|
def get_drv_name(self, empty=False):
|
||||||
if self.popts.has_key('name'):
|
if 'name' in self.popts:
|
||||||
drv_name = self.popts['name']
|
drv_name = self.popts['name']
|
||||||
elif empty:
|
elif empty:
|
||||||
drv_name = None
|
drv_name = None
|
||||||
@ -339,7 +339,7 @@ class PartEditCommand(Command):
|
|||||||
return drv_name
|
return drv_name
|
||||||
|
|
||||||
def get_bootable(self, empty=False):
|
def get_bootable(self, empty=False):
|
||||||
if self.popts.has_key('bootable'):
|
if 'bootable' in self.popts:
|
||||||
return bool(self.popts['bootable'])
|
return bool(self.popts['bootable'])
|
||||||
elif not empty:
|
elif not empty:
|
||||||
return False
|
return False
|
||||||
@ -347,7 +347,7 @@ class PartEditCommand(Command):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_boot_pri(self, empty=False):
|
def get_boot_pri(self, empty=False):
|
||||||
if self.popts.has_key('pri'):
|
if 'pri' in self.popts:
|
||||||
return self.popts['pri']
|
return self.popts['pri']
|
||||||
elif not empty:
|
elif not empty:
|
||||||
return 0
|
return 0
|
||||||
@ -355,7 +355,7 @@ class PartEditCommand(Command):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_automount(self, empty=False):
|
def get_automount(self, empty=False):
|
||||||
if self.popts.has_key('automount'):
|
if 'automount' in self.popts:
|
||||||
return bool(self.popts['automount'])
|
return bool(self.popts['automount'])
|
||||||
elif not empty:
|
elif not empty:
|
||||||
return True
|
return True
|
||||||
@ -363,7 +363,7 @@ class PartEditCommand(Command):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_fs_block_size(self, empty=False):
|
def get_fs_block_size(self, empty=False):
|
||||||
if self.popts.has_key('bs'):
|
if 'bs' in self.popts:
|
||||||
return int(self.popts['bs'])
|
return int(self.popts['bs'])
|
||||||
elif not empty:
|
elif not empty:
|
||||||
return 512
|
return 512
|
||||||
@ -399,22 +399,22 @@ class PartEditCommand(Command):
|
|||||||
|
|
||||||
def get_more_dos_env_info(self):
|
def get_more_dos_env_info(self):
|
||||||
valid_keys = PartitionDosEnv.valid_keys
|
valid_keys = PartitionDosEnv.valid_keys
|
||||||
info = map(lambda x : "[%s=<n>]" % x, valid_keys)
|
info = ["[%s=<n>]" % x for x in valid_keys]
|
||||||
return " ".join(info)
|
return " ".join(info)
|
||||||
|
|
||||||
def get_cyl_range(self):
|
def get_cyl_range(self):
|
||||||
start = None
|
start = None
|
||||||
if self.popts.has_key('start'):
|
if 'start' in self.popts:
|
||||||
start = int(self.popts['start'])
|
start = int(self.popts['start'])
|
||||||
# range with start=<n> end=<n>
|
# range with start=<n> end=<n>
|
||||||
if self.popts.has_key('end'):
|
if 'end' in self.popts:
|
||||||
end = int(self.popts['end'])
|
end = int(self.popts['end'])
|
||||||
if start == None or end <= start:
|
if start == None or end <= start:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return (start, end)
|
return (start, end)
|
||||||
# expect a size
|
# expect a size
|
||||||
elif self.popts.has_key('size'):
|
elif 'size' in self.popts:
|
||||||
size = self.popts['size']
|
size = self.popts['size']
|
||||||
cyls = None
|
cyls = None
|
||||||
if type(size) == int:
|
if type(size) == int:
|
||||||
@ -524,7 +524,7 @@ class ExportCommand(Command):
|
|||||||
(p.get_drive_name(), num_blks, file_name))
|
(p.get_drive_name(), num_blks, file_name))
|
||||||
try:
|
try:
|
||||||
with open(file_name, "wb") as fh:
|
with open(file_name, "wb") as fh:
|
||||||
for b in xrange(num_blks):
|
for b in range(num_blks):
|
||||||
data = blkdev.read_block(b)
|
data = blkdev.read_block(b)
|
||||||
fh.write(data)
|
fh.write(data)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
@ -569,7 +569,7 @@ class ImportCommand(Command):
|
|||||||
(file_name, file_blks, p.get_drive_name(), part_blks))
|
(file_name, file_blks, p.get_drive_name(), part_blks))
|
||||||
# copy image
|
# copy image
|
||||||
with open(file_name, "rb") as fh:
|
with open(file_name, "rb") as fh:
|
||||||
for b in xrange(file_blks):
|
for b in range(file_blks):
|
||||||
data = fh.read(blk_size)
|
data = fh.read(blk_size)
|
||||||
part_dev.write_block(b, data)
|
part_dev.write_block(b, data)
|
||||||
part_dev.close()
|
part_dev.close()
|
||||||
@ -659,9 +659,9 @@ class FSAddCommand(Command):
|
|||||||
self.popts = KeyValue.parse_key_value_strings(self.opts)
|
self.popts = KeyValue.parse_key_value_strings(self.opts)
|
||||||
|
|
||||||
def get_dos_type(self):
|
def get_dos_type(self):
|
||||||
if self.popts.has_key('fs'):
|
if 'fs' in self.popts:
|
||||||
fs_str = self.popts['fs']
|
fs_str = self.popts['fs']
|
||||||
elif self.popts.has_key('dostype'):
|
elif 'dostype' in self.popts:
|
||||||
fs_str = self.popts['dostype']
|
fs_str = self.popts['dostype']
|
||||||
else:
|
else:
|
||||||
fs_str = self.args.dostype
|
fs_str = self.args.dostype
|
||||||
@ -671,7 +671,7 @@ class FSAddCommand(Command):
|
|||||||
self.parse_opts()
|
self.parse_opts()
|
||||||
valid_flags = FSHeaderDeviceNode.valid_flags
|
valid_flags = FSHeaderDeviceNode.valid_flags
|
||||||
if len(self.opts) < 1:
|
if len(self.opts) < 1:
|
||||||
flag_info = map(lambda x : "[%s=<n>]" % x, valid_flags)
|
flag_info = ["[%s=<n>]" % x for x in valid_flags]
|
||||||
flag_info = " ".join(flag_info)
|
flag_info = " ".join(flag_info)
|
||||||
print("Usage: fsadd <file_name> [dostype=<n|tag>] [version=<n.m>] " + flag_info)
|
print("Usage: fsadd <file_name> [dostype=<n|tag>] [version=<n.m>] " + flag_info)
|
||||||
return 1
|
return 1
|
||||||
@ -691,7 +691,7 @@ class FSAddCommand(Command):
|
|||||||
if ver == None:
|
if ver == None:
|
||||||
ver = (0,0)
|
ver = (0,0)
|
||||||
# overwrite version from options
|
# overwrite version from options
|
||||||
if opts.has_key('version'):
|
if 'version' in opts:
|
||||||
vstr = opts['version']
|
vstr = opts['version']
|
||||||
pos = vstr.find('.')
|
pos = vstr.find('.')
|
||||||
if pos != -1:
|
if pos != -1:
|
||||||
@ -782,7 +782,7 @@ def main():
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('image_file')
|
parser.add_argument('image_file')
|
||||||
parser.add_argument('command_list', nargs='+', help="command: "+",".join(cmd_map.keys()))
|
parser.add_argument('command_list', nargs='+', help="command: "+",".join(list(cmd_map.keys())))
|
||||||
parser.add_argument('-v', '--verbose', action='store_true', default=False, help="be more verbos")
|
parser.add_argument('-v', '--verbose', action='store_true', default=False, help="be more verbos")
|
||||||
parser.add_argument('-s', '--seperator', default='+', help="set the command separator char sequence")
|
parser.add_argument('-s', '--seperator', default='+', help="set the command separator char sequence")
|
||||||
parser.add_argument('-r', '--read-only', action='store_true', default=False, help="read-only operation")
|
parser.add_argument('-r', '--read-only', action='store_true', default=False, help="read-only operation")
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
# romtool
|
# romtool
|
||||||
#
|
#
|
||||||
# work with Amiga ROM files aka Kickstarts
|
# work with Amiga ROM files aka Kickstarts
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
@ -100,7 +100,7 @@ def do_build_cmd(args):
|
|||||||
fill_byte = int(args.fill_byte, 16)
|
fill_byte = int(args.fill_byte, 16)
|
||||||
rom_rev = args.rom_rev
|
rom_rev = args.rom_rev
|
||||||
if rom_rev is not None:
|
if rom_rev is not None:
|
||||||
rom_rev = map(int, rom_rev.split("."))
|
rom_rev = list(map(int, rom_rev.split(".")))
|
||||||
add_footer = args.add_footer
|
add_footer = args.add_footer
|
||||||
# select rom builder
|
# select rom builder
|
||||||
if rom_type == 'kick':
|
if rom_type == 'kick':
|
||||||
@ -270,7 +270,7 @@ def do_info_cmd(args):
|
|||||||
('magic_reset', kh.check_magic_reset()),
|
('magic_reset', kh.check_magic_reset()),
|
||||||
('is_kick', kh.is_kick_rom())
|
('is_kick', kh.is_kick_rom())
|
||||||
]
|
]
|
||||||
c = map(lambda x:"%-20s %s" % (x[0], "ok" if x[1] else "NOK"), checks)
|
c = ["%-20s %s" % (x[0], "ok" if x[1] else "NOK") for x in checks]
|
||||||
for i in c:
|
for i in c:
|
||||||
print(i)
|
print(i)
|
||||||
values = [
|
values = [
|
||||||
@ -280,7 +280,7 @@ def do_info_cmd(args):
|
|||||||
('rom_rev', '%d.%d', kh.read_rom_ver_rev()),
|
('rom_rev', '%d.%d', kh.read_rom_ver_rev()),
|
||||||
('exec_rev', '%d.%d', kh.read_exec_ver_rev())
|
('exec_rev', '%d.%d', kh.read_exec_ver_rev())
|
||||||
]
|
]
|
||||||
v = map(lambda x:"%-20s %s" % (x[0], x[1] % x[2]), values)
|
v = ["%-20s %s" % (x[0], x[1] % x[2]) for x in values]
|
||||||
for i in v:
|
for i in v:
|
||||||
print(i)
|
print(i)
|
||||||
|
|
||||||
@ -387,7 +387,7 @@ def do_scan_cmd(args):
|
|||||||
logging.error("can't guess base address of ROM!")
|
logging.error("can't guess base address of ROM!")
|
||||||
return 1
|
return 1
|
||||||
elif type(base_addr) is list:
|
elif type(base_addr) is list:
|
||||||
addrs = map(hex, base_addr)
|
addrs = list(map(hex, base_addr))
|
||||||
logging.error("multiple addresses guessed: %s", ",".join(addrs))
|
logging.error("multiple addresses guessed: %s", ",".join(addrs))
|
||||||
return 2
|
return 2
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# typetool [options] <path>
|
# typetool [options] <path>
|
||||||
#
|
#
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# vamos [optoins] <amiga binary> [args ...]
|
# vamos [optoins] <amiga binary> [args ...]
|
||||||
#
|
#
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# vamospath [options] <path>
|
# vamospath [options] <path>
|
||||||
#
|
#
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# vamostool
|
# vamostool
|
||||||
#
|
#
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
# xdfscan
|
# xdfscan
|
||||||
# quickly scan large sets of Amiga disk image files
|
# quickly scan large sets of Amiga disk image files
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
# xdftool
|
# xdftool
|
||||||
# swiss army knife for adf and hdf amiga disk images
|
# swiss army knife for adf and hdf amiga disk images
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
@ -819,7 +819,7 @@ def main():
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('image_file')
|
parser.add_argument('image_file')
|
||||||
parser.add_argument('command_list', nargs='+', help="command: "+",".join(cmd_map.keys()))
|
parser.add_argument('command_list', nargs='+', help="command: "+",".join(list(cmd_map.keys())))
|
||||||
parser.add_argument('-v', '--verbose', action='store_true', default=False, help="be more verbos")
|
parser.add_argument('-v', '--verbose', action='store_true', default=False, help="be more verbos")
|
||||||
parser.add_argument('-s', '--seperator', default='+', help="set the command separator char sequence")
|
parser.add_argument('-s', '--seperator', default='+', help="set the command separator char sequence")
|
||||||
parser.add_argument('-r', '--read-only', action='store_true', default=False, help="read-only operation")
|
parser.add_argument('-r', '--read-only', action='store_true', default=False, help="read-only operation")
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
# based heavily on "iops" by Benjamin Schweizer
|
# based heavily on "iops" by Benjamin Schweizer
|
||||||
# https://github.com/gopher/iops
|
# https://github.com/gopher/iops
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import array
|
import array
|
||||||
@ -20,10 +20,10 @@ def getblkdevsize(dev):
|
|||||||
DKIOCGETBLOCKCOUNT = 0x40086419 # _IOR('d', 25, uint64_t)
|
DKIOCGETBLOCKCOUNT = 0x40086419 # _IOR('d', 25, uint64_t)
|
||||||
|
|
||||||
fh = open(dev, 'r')
|
fh = open(dev, 'r')
|
||||||
buf = array.array('B', range(0,4)) # uint32
|
buf = array.array('B', list(range(0,4))) # uint32
|
||||||
r = fcntl.ioctl(fh.fileno(), DKIOCGETBLOCKSIZE, buf, 1)
|
r = fcntl.ioctl(fh.fileno(), DKIOCGETBLOCKSIZE, buf, 1)
|
||||||
blocksize = struct.unpack('I', buf)[0]
|
blocksize = struct.unpack('I', buf)[0]
|
||||||
buf = array.array('B', range(0,8)) # uint64
|
buf = array.array('B', list(range(0,8))) # uint64
|
||||||
r = fcntl.ioctl(fh.fileno(), DKIOCGETBLOCKCOUNT, buf, 1)
|
r = fcntl.ioctl(fh.fileno(), DKIOCGETBLOCKCOUNT, buf, 1)
|
||||||
blockcount = struct.unpack('Q', buf)[0]
|
blockcount = struct.unpack('Q', buf)[0]
|
||||||
fh.close()
|
fh.close()
|
||||||
@ -35,7 +35,7 @@ def getblkdevsize(dev):
|
|||||||
DIOCGMEDIASIZE = 0x40086481 # _IOR('d', 129, uint64_t)
|
DIOCGMEDIASIZE = 0x40086481 # _IOR('d', 129, uint64_t)
|
||||||
|
|
||||||
fh = open(dev, 'r')
|
fh = open(dev, 'r')
|
||||||
buf = array.array('B', range(0,8)) # off_t / int64
|
buf = array.array('B', list(range(0,8))) # off_t / int64
|
||||||
r = fcntl.ioctl(fh.fileno(), DIOCGMEDIASIZE, buf, 1)
|
r = fcntl.ioctl(fh.fileno(), DIOCGMEDIASIZE, buf, 1)
|
||||||
size = struct.unpack('q', buf)[0]
|
size = struct.unpack('q', buf)[0]
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|||||||
@ -55,7 +55,7 @@ def parse_byte_size_str(s):
|
|||||||
unit = 1000
|
unit = 1000
|
||||||
# check for scale
|
# check for scale
|
||||||
scale = s[-1]
|
scale = s[-1]
|
||||||
if scale in scale_map.keys():
|
if scale in list(scale_map.keys()):
|
||||||
factor = unit ** scale_map[scale]
|
factor = unit ** scale_map[scale]
|
||||||
if n == 1:
|
if n == 1:
|
||||||
return None
|
return None
|
||||||
@ -76,7 +76,7 @@ if __name__ == '__main__':
|
|||||||
for a in sys.argv[1:]:
|
for a in sys.argv[1:]:
|
||||||
v = parse_byte_size_str(a)
|
v = parse_byte_size_str(a)
|
||||||
if v != None:
|
if v != None:
|
||||||
print(a, ":", v, "=", to_byte_size_str(v), "=", to_byte_size_str(v, False))
|
print((a, ":", v, "=", to_byte_size_str(v), "=", to_byte_size_str(v, False)))
|
||||||
else:
|
else:
|
||||||
print(a, ":", v)
|
print((a, ":", v))
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
class CommandQueue:
|
class CommandQueue:
|
||||||
def __init__(self, cmd_list, sep, cmd_map):
|
def __init__(self, cmd_list, sep, cmd_map):
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# DataDir.py - return location of my data directory
|
# DataDir.py - return location of my data directory
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user