58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
|
|
import lupa
|
|
from lupa import LuaRuntime
|
|
|
|
|
|
class save:
|
|
def __init__(self) -> None:
|
|
pass
|
|
def save(self,data:bytearray):
|
|
d=data[1:]
|
|
for i in range(20):
|
|
self.save_item(d[i*28:i*28+28])
|
|
def save_item(self,d:bytearray):
|
|
s='=\"'+d[0:8].hex()+'\"'+','
|
|
s+='=\"'+self.hex2bit(d[8:10])+'\"'+','
|
|
s+=self.hex2int(d[10:])
|
|
print(d[8:10].hex(' '))
|
|
print(s)
|
|
with open("./file/save.csv","+a") as f:
|
|
f.write(s+'\n')
|
|
def hex2int(self,d:bytearray):
|
|
s=""
|
|
for i in range(len(d)//2):
|
|
s+=str(d[i*2]|(d[i*2+1]<<8))+','
|
|
return s
|
|
def hex2bit(self,d:bytearray):
|
|
s=""
|
|
for i in range(len(d)*8):
|
|
if(d[i//8]&(1<<(i%8))!=0):
|
|
s+='1'
|
|
else:
|
|
s+='0'
|
|
if((i>0) and ((i+1)%8==0) and ((i+1)<len(d)*8)):
|
|
s+='_'
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sa=save()
|
|
print(sa.hex2bit(bytes([0xab,0xcd])))
|
|
lua = LuaRuntime(unpack_returned_tuples=True)
|
|
save_json=lua.eval("function(a) json=a end")
|
|
with open("file/json.lua",encoding="utf-8") as f:
|
|
save_json(lua.execute(f.read()))
|
|
save_prints=lua.eval("function(a) prints=a end")
|
|
with open("file/prints.lua",encoding="utf-8") as f:
|
|
save_prints(lua.execute(f.read()))
|
|
lua.execute("cfg_name=\"file/checker_ye_cfg.json\"\n")
|
|
lua.execute("check_data={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}\n")
|
|
with open("file/judge.lua",encoding="utf-8") as f:
|
|
lua.execute(f.read())
|
|
# lua_func = lua.eval('function(a, b) return a+b end')
|
|
# print(lua_func(1,2))
|
|
|