v1.1
This commit is contained in:
@@ -45,9 +45,11 @@ cp437 ansi parsing
|
|||||||
```
|
```
|
||||||
dr1p4ns1.py - main file, reads 'work.ans' and attempts to parse and display
|
dr1p4ns1.py - main file, reads 'work.ans' and attempts to parse and display
|
||||||
work.ans - this ansi file is loaded by 'dr1p4ns1.py', this is the logic testing
|
work.ans - this ansi file is loaded by 'dr1p4ns1.py', this is the logic testing
|
||||||
|
work.asc - escape codes/colors stripped in text for test referencing
|
||||||
test.py - used to generate test ansi file and presents table data
|
test.py - used to generate test ansi file and presents table data
|
||||||
```
|
```
|
||||||
- dr1p4ns1.py
|
- dr1p4ns1.py
|
||||||
- work.ans
|
- work.ans
|
||||||
|
- work.asc
|
||||||
- test.py
|
- test.py
|
||||||
```
|
```
|
||||||
|
|||||||
116
dr1p4ns1.py
116
dr1p4ns1.py
@@ -1,8 +1,43 @@
|
|||||||
############################################################################# SOF
|
################################################################################################ SOF
|
||||||
################################################################# CLASS DR1P4NS1
|
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh+MMMMMMMMMMMMMMhsMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMm/ oMMMMMMMMMMMMMMm +NMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMy` yMMMMMMMMMMMMMMM- -mMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMs+dMMMMMMMMMM+ sMMMMMMMMMMMMMMM- `dMMMMMMMMMMms/NMMMMMMMMM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Ny: ./sdNMMMh: `sNMMMNds/. .odMMM
|
||||||
|
MM+ :ymMMMMMMMMMMh. +NMMMMMMMMMMmo- /NM
|
||||||
|
MMMh: .sNMMMMMMMMMMMMMMN- `hMMMMMMMMMMMMMMMm+` :hMMM
|
||||||
|
MMMMMd:` ``-:+shmMMMMMMMMMMMMMMMMMMN. hMMMMMMMMMMMMMMMMMMMmhs+/-..``````./dMMMMM
|
||||||
|
MMMMMMMMMNNNNNNMMMMMMMMMMMMMMMMMMMMMMMMMMMo .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMy .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMN. /MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMN+` `+NMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNs. -hMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMdyymMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
|
||||||
|
##################################################################################### CLASS DR1P4NS1
|
||||||
|
|
||||||
class dr1p4ns1:
|
class dr1p4ns1:
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
commands = {
|
commands = {
|
||||||
'A': 'up',
|
'A': 'up',
|
||||||
'B': 'down',
|
'B': 'down',
|
||||||
@@ -18,25 +53,29 @@ class dr1p4ns1:
|
|||||||
'R': 'report_cursor_position'
|
'R': 'report_cursor_position'
|
||||||
}
|
}
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
asc_table="""
|
asc_table="""
|
||||||
ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒ\
|
ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒ\
|
||||||
áíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐\
|
áíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐\
|
||||||
└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀\
|
└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀\
|
||||||
αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■
|
αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■
|
||||||
"""
|
"""
|
||||||
|
#################################################################################
|
||||||
|
|
||||||
############################################################################
|
|
||||||
for r in (('\n',''),(' ','')):
|
for r in (('\n',''),(' ','')):
|
||||||
asc_table=asc_table.replace(*r)
|
asc_table=asc_table.replace(*r)
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
asc2uni=dict(zip([i for i in range(128,256)],[ord(c) for c in asc_table]))
|
asc2uni=dict(zip([i for i in range(128,256)],[ord(c) for c in asc_table]))
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
asc2chr=dict(zip([i for i in range(128,256)],[c for c in asc_table]))
|
asc2chr=dict(zip([i for i in range(128,256)],[c for c in asc_table]))
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def __init__(self,ansifile="",width=80,height=25,debug=False):
|
def __init__(self,ansifile="",width=80,height=25,debug=False):
|
||||||
self.DEBUG=debug
|
self.DEBUG=debug
|
||||||
self.width=width
|
self.width=width
|
||||||
@@ -48,19 +87,22 @@ class dr1p4ns1:
|
|||||||
print("\x1bc\x1b[1;31m[ DR1P ]\x1b[0m\n")
|
print("\x1bc\x1b[1;31m[ DR1P ]\x1b[0m\n")
|
||||||
self.boot()
|
self.boot()
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def openansi(self,s):
|
def openansi(self,s):
|
||||||
f=open(s,'rb')
|
f=open(s,'rb')
|
||||||
self.ansifile=f.read().decode('cp437')
|
self.ansifile=f.read().decode('cp437')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def openascii(self):
|
def openascii(self):
|
||||||
f=open('work.asc','r')
|
f=open('work.asc','r')
|
||||||
self.reference=f.read()
|
self.reference=f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def printascii(self):
|
def printascii(self):
|
||||||
for i,_ in enumerate(self.asc_table):
|
for i,_ in enumerate(self.asc_table):
|
||||||
_int=str(i+128).zfill(3)
|
_int=str(i+128).zfill(3)
|
||||||
@@ -68,7 +110,8 @@ class dr1p4ns1:
|
|||||||
_ord=str(ord(_)).zfill(4)
|
_ord=str(ord(_)).zfill(4)
|
||||||
print(f'{_} - {_int} - {_hex} - {_ord}')
|
print(f'{_} - {_int} - {_hex} - {_ord}')
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def printrange(self,n,nn):
|
def printrange(self,n,nn):
|
||||||
for index,_ in enumerate(self.ansifile):
|
for index,_ in enumerate(self.ansifile):
|
||||||
h=hex(_)[2:].upper()
|
h=hex(_)[2:].upper()
|
||||||
@@ -84,7 +127,8 @@ class dr1p4ns1:
|
|||||||
if index==nn:
|
if index==nn:
|
||||||
break
|
break
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def printhex(self):
|
def printhex(self):
|
||||||
theasc=[]
|
theasc=[]
|
||||||
thehex=[]
|
thehex=[]
|
||||||
@@ -99,7 +143,7 @@ class dr1p4ns1:
|
|||||||
thehex.append(subchunks.strip())
|
thehex.append(subchunks.strip())
|
||||||
for __ in thehex:
|
for __ in thehex:
|
||||||
buffer=''
|
buffer=''
|
||||||
for _ in __.split():
|
for _ in __.split():
|
||||||
i=int(_,16)
|
i=int(_,16)
|
||||||
if i>47 and i<127:
|
if i>47 and i<127:
|
||||||
buffer+=chr(i)
|
buffer+=chr(i)
|
||||||
@@ -112,7 +156,8 @@ class dr1p4ns1:
|
|||||||
if not buffer == old:
|
if not buffer == old:
|
||||||
print(f"{hex(16 * _)[2:].zfill(8)} {thehex[_]} {theasc[_]}")
|
print(f"{hex(16 * _)[2:].zfill(8)} {thehex[_]} {theasc[_]}")
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def hexdump(self):
|
def hexdump(self):
|
||||||
if self.DEBUG:
|
if self.DEBUG:
|
||||||
print("\n\x1b[1;31m[ HEXDUMP ]\x1b[0m\n")
|
print("\n\x1b[1;31m[ HEXDUMP ]\x1b[0m\n")
|
||||||
@@ -137,11 +182,13 @@ class dr1p4ns1:
|
|||||||
code=self.ansifile[code_start:code_end]
|
code=self.ansifile[code_start:code_end]
|
||||||
self.codes.append([code,code_start,code_end])
|
self.codes.append([code,code_start,code_end])
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def findall(self,s,w):
|
def findall(self,s,w):
|
||||||
return [i for i in range(len(s)) if s.startswith(w, i)]
|
return [i for i in range(len(s)) if s.startswith(w, i)]
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def getsauce(self):
|
def getsauce(self):
|
||||||
SPASS='\x1b[1;31m[ SAUCE INFO FOUND ] - X: {} Y: {}\x1b[0m\n'
|
SPASS='\x1b[1;31m[ SAUCE INFO FOUND ] - X: {} Y: {}\x1b[0m\n'
|
||||||
SFAIL='\x1b[1;31m[ NO SAUCE INFO FOUND ]\x1b[0m\n'
|
SFAIL='\x1b[1;31m[ NO SAUCE INFO FOUND ]\x1b[0m\n'
|
||||||
@@ -158,7 +205,8 @@ class dr1p4ns1:
|
|||||||
except:
|
except:
|
||||||
print(SFAIL)
|
print(SFAIL)
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def cmpans(self,s1,s2,n1=0,n2=0):
|
def cmpans(self,s1,s2,n1=0,n2=0):
|
||||||
_s1=''; _s2=''; _sn1=''; _sn2=''
|
_s1=''; _s2=''; _sn1=''; _sn2=''
|
||||||
_s1=self.stripcodes(s1)
|
_s1=self.stripcodes(s1)
|
||||||
@@ -179,11 +227,13 @@ class dr1p4ns1:
|
|||||||
n1+=self.width
|
n1+=self.width
|
||||||
n2+=self.width
|
n2+=self.width
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
def chunk(self,s,n):
|
|
||||||
|
def chunk(self,s,n):
|
||||||
return [s[i:i+n] for i in range(0,len(s),n)]
|
return [s[i:i+n] for i in range(0,len(s),n)]
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def stripcodes(self,s):
|
def stripcodes(self,s):
|
||||||
buffer=s
|
buffer=s
|
||||||
code_start=0
|
code_start=0
|
||||||
@@ -203,12 +253,14 @@ class dr1p4ns1:
|
|||||||
buffer=buffer.replace(code,'')
|
buffer=buffer.replace(code,'')
|
||||||
return buffer
|
return buffer
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def rgb(self,t='',r=0,g=0,b=0):
|
def rgb(self,t='',r=0,g=0,b=0):
|
||||||
"""colorize text with rgb values"""
|
"""colorize text with rgb values"""
|
||||||
return f"\033[38;2;{r};{g};{b}m{t}\033[38;2;255;255;255m"
|
return f"\033[38;2;{r};{g};{b}m{t}\033[38;2;255;255;255m"
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def vga(self,t='',i=0):
|
def vga(self,t='',i=0):
|
||||||
"""colorize text using vga color set"""
|
"""colorize text using vga color set"""
|
||||||
vga = [ '#000000','#aa0000','#00aa00','#aa5500',
|
vga = [ '#000000','#aa0000','#00aa00','#aa5500',
|
||||||
@@ -223,11 +275,13 @@ class dr1p4ns1:
|
|||||||
r,g,b=0,0,0
|
r,g,b=0,0,0
|
||||||
return f"\033[38;2;{r};{g};{b}m{t}\033[38;2;255;255;255m"
|
return f"\033[38;2;{r};{g};{b}m{t}\033[38;2;255;255;255m"
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def invert_dict(self,d):
|
def invert_dict(self,d):
|
||||||
return {v: k for k, v in d.items()}
|
return {v: k for k, v in d.items()}
|
||||||
|
|
||||||
############################################################################
|
#################################################################################
|
||||||
|
|
||||||
def boot(self):
|
def boot(self):
|
||||||
self.getsauce()
|
self.getsauce()
|
||||||
self.hexdump()
|
self.hexdump()
|
||||||
@@ -250,7 +304,7 @@ class dr1p4ns1:
|
|||||||
optype.append(2)
|
optype.append(2)
|
||||||
elif _op.endswith('C'):
|
elif _op.endswith('C'):
|
||||||
optype.append(3)
|
optype.append(3)
|
||||||
else:
|
else:
|
||||||
optype.append(0)
|
optype.append(0)
|
||||||
elif _op.startswith('\x1a'):
|
elif _op.startswith('\x1a'):
|
||||||
optype.append(4)
|
optype.append(4)
|
||||||
@@ -260,7 +314,7 @@ class dr1p4ns1:
|
|||||||
offsets=[]
|
offsets=[]
|
||||||
processed=[]
|
processed=[]
|
||||||
uniqued=[]
|
uniqued=[]
|
||||||
uniques=[]
|
uniques=[]
|
||||||
processing=''
|
processing=''
|
||||||
for i,_optype in enumerate(optype):
|
for i,_optype in enumerate(optype):
|
||||||
if _optype==2:
|
if _optype==2:
|
||||||
@@ -301,16 +355,16 @@ class dr1p4ns1:
|
|||||||
self.cmpans(s1=s1,s2=s2,n1=0,n2=self.width)
|
self.cmpans(s1=s1,s2=s2,n1=0,n2=self.width)
|
||||||
if i >= 128:
|
if i >= 128:
|
||||||
break
|
break
|
||||||
for i,_ in enumerate(self.cmps):
|
for i,_ in enumerate(self.cmps):
|
||||||
print(_+f' - {str(i).zfill(4)}')
|
print(_+f' - {str(i).zfill(4)}')
|
||||||
if self.DEBUG:
|
if self.DEBUG:
|
||||||
print("\n \x1b[1;31m[ PROCESSED ANSI ]\x1b[0m\n")
|
print("\n \x1b[1;31m[ PROCESSED ANSI ]\x1b[0m\n")
|
||||||
for _ in processed: print(_)
|
for _ in processed: print(_)
|
||||||
print('\n\x1b[1;31m[ DR0P ]\x1b[0m')
|
print('\n\x1b[1;31m[ DR0P ]\x1b[0m')
|
||||||
|
|
||||||
########################################################################### MAIN
|
############################################################################################### MAIN
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
d=dr1p4ns1(ansifile='work.ans',width=80,debug=False)
|
d=dr1p4ns1(ansifile='work.ans',width=80,debug=False)
|
||||||
|
|
||||||
############################################################################ EOF
|
################################################################################################ EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user