parent
8f75c44bc1
commit
9cd9d68b57
94
buffer.py
94
buffer.py
|
@ -516,39 +516,46 @@ class AesBuffer(FileBuffer):
|
||||||
return aes.encrypt_data(data, self.password)
|
return aes.encrypt_data(data, self.password)
|
||||||
|
|
||||||
class Binary32Buffer(FileBuffer):
|
class Binary32Buffer(FileBuffer):
|
||||||
btype = 'bin32file'
|
btype = 'bin32file'
|
||||||
wordsize = 4
|
grouppad = 2
|
||||||
numwords = 4
|
groupsize = 8
|
||||||
data = None
|
numgroups = 2
|
||||||
|
bytepad = 1
|
||||||
|
data = None
|
||||||
def __init__(self, path, nl='\n', name=None):
|
def __init__(self, path, nl='\n', name=None):
|
||||||
'''fb = FileBuffer(path)'''
|
'''fb = FileBuffer(path)'''
|
||||||
FileBuffer.__init__(self, path, nl, name)
|
FileBuffer.__init__(self, path, nl, name)
|
||||||
def cursorx_to_datax(self, cy, cx):
|
def cursorx_to_datax(self, cy, cx):
|
||||||
if cx >= 0 and cx < 8:
|
bytespace = 2 + self.bytepad
|
||||||
ix = cx // 2
|
groupspace = bytespace * self.groupsize - 1 + self.grouppad
|
||||||
elif cx >= 9 and cx < 17:
|
|
||||||
ix = (cx - 1) // 2
|
groupmod = (cx + self.grouppad) % groupspace
|
||||||
elif cx >= 18 and cx < 26:
|
if groupmod < self.grouppad:
|
||||||
ix = (cx - 2) // 2
|
|
||||||
elif cx >= 27 and cx < 35:
|
|
||||||
ix = (cx - 3) // 2
|
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
groupdiv = (cx + 2) // groupspace
|
||||||
|
if groupdiv >= self.numgroups:
|
||||||
|
return None
|
||||||
|
|
||||||
|
bytemod = (cx + self.bytepad) % bytespace
|
||||||
|
if bytemod == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
bytediv = ((cx + self.bytepad) % groupspace) // bytespace
|
||||||
|
ix = self.groupsize * groupdiv + bytediv
|
||||||
if ix < len(self.rawdata[cy]):
|
if ix < len(self.rawdata[cy]):
|
||||||
return ix
|
return ix
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def datax_to_cursorx(self, ix):
|
def datax_to_cursorx(self, ix):
|
||||||
if ix >= 0 and ix < 4:
|
groupsize = (((2 + self.bytepad) * self.groupsize) + self.grouppad)
|
||||||
return ix * 2
|
maxsize = groupsize * self.numgroups - self.grouppad
|
||||||
elif ix >= 4 and ix < 8:
|
if ix < maxsize:
|
||||||
return ix * 2 + 1
|
return (ix // self.groupsize) * self.grouppad + ix * (2 + self.bytepad)
|
||||||
elif ix >= 8 and ix < 12:
|
|
||||||
return ix * 2 + 2
|
|
||||||
elif ix >= 12 and ix < 16:
|
|
||||||
return ix * 2 + 3
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def overwrite_char(self, p, c, act=ACT_NORM, force=False):
|
def overwrite_char(self, p, c, act=ACT_NORM, force=False):
|
||||||
ix = self.cursorx_to_datax(p.y, p.x)
|
ix = self.cursorx_to_datax(p.y, p.x)
|
||||||
if ix is None:
|
if ix is None:
|
||||||
|
@ -559,41 +566,26 @@ class Binary32Buffer(FileBuffer):
|
||||||
rawline = self.rawdata[p.y]
|
rawline = self.rawdata[p.y]
|
||||||
self.rawdata[p.y] = rawline[0:ix] + c + rawline[ix + 1:]
|
self.rawdata[p.y] = rawline[0:ix] + c + rawline[ix + 1:]
|
||||||
def read_filter(self, data):
|
def read_filter(self, data):
|
||||||
|
bytepad = ' ' * self.bytepad
|
||||||
|
grouppad = ' ' * self.grouppad
|
||||||
self.rawdata = []
|
self.rawdata = []
|
||||||
lines = []
|
lines = []
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(data):
|
while i < len(data):
|
||||||
self.rawdata.append(data[i:i + self.numwords * self.wordsize])
|
self.rawdata.append(data[i:i + self.numgroups * self.groupsize])
|
||||||
j = 0
|
j = 0
|
||||||
words = []
|
groups = []
|
||||||
while j < self.numwords * self.wordsize and i + j < len(data):
|
while j < self.numgroups * self.groupsize and i + j < len(data):
|
||||||
nibbles = []
|
bytes = []
|
||||||
for c in data[i + j:i + j + self.wordsize]:
|
for c in data[i + j:i + j + self.groupsize]:
|
||||||
nibbles.append(string.hexdigits[ord(c) / 16])
|
bytes.append(string.hexdigits[ord(c) / 16] + string.hexdigits[ord(c) % 16])
|
||||||
nibbles.append(string.hexdigits[ord(c) % 16])
|
groups.append(bytepad.join(bytes))
|
||||||
words.append(''.join(nibbles))
|
j += self.groupsize
|
||||||
j += self.wordsize
|
lines.append(grouppad.join(groups))
|
||||||
lines.append(' '.join(words))
|
i += self.numgroups * self.groupsize
|
||||||
i += self.numwords * self.wordsize
|
|
||||||
return '\n'.join(lines)
|
return '\n'.join(lines)
|
||||||
def write_filter(self, data):
|
def write_filter(self, data):
|
||||||
bytes = []
|
return ''.join(self.rawdata)
|
||||||
lastc = None
|
|
||||||
for c in data:
|
|
||||||
if c not in '0123456789abcdefABCDEF':
|
|
||||||
pass
|
|
||||||
elif lastc is None:
|
|
||||||
lastc = c
|
|
||||||
else:
|
|
||||||
bytes.append(chr(int(lastc + c, 16)))
|
|
||||||
lastc = None
|
|
||||||
if lastc is not None:
|
|
||||||
bytes.append(chr(int(lastc + '0', 16)))
|
|
||||||
return ''.join(bytes)
|
|
||||||
|
|
||||||
class Binary64Buffer(Binary32Buffer):
|
|
||||||
wordsize = 8
|
|
||||||
numwords = 2
|
|
||||||
|
|
||||||
class DirBuffer(Buffer):
|
class DirBuffer(Buffer):
|
||||||
btype = 'dir'
|
btype = 'dir'
|
||||||
|
|
11
mode/hex.py
11
mode/hex.py
|
@ -4,19 +4,8 @@ from lex import Grammar, PatternRule, RegionRule
|
||||||
from method import Method, Argument
|
from method import Method, Argument
|
||||||
from point import Point
|
from point import Point
|
||||||
|
|
||||||
class HexGrammar(Grammar):
|
|
||||||
rules = [
|
|
||||||
PatternRule(r'zero', r"00"),
|
|
||||||
PatternRule(r'byte', r'[0-f][0-f]'),
|
|
||||||
]
|
|
||||||
|
|
||||||
class Hex(mode.Fundamental):
|
class Hex(mode.Fundamental):
|
||||||
modename = 'Hex'
|
modename = 'Hex'
|
||||||
grammar = HexGrammar
|
|
||||||
colors = {
|
|
||||||
'zero': ('magenta', 'default'),
|
|
||||||
'byte': ('white', 'default'),
|
|
||||||
}
|
|
||||||
lmargin = 12
|
lmargin = 12
|
||||||
rmargin = 18
|
rmargin = 18
|
||||||
_ctrans = ['.'] * 256
|
_ctrans = ['.'] * 256
|
||||||
|
|
Loading…
Reference in New Issue