Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- class Var_struct:
- def __init__(self,name,vt):
- self.header = [0x2A, 0x2A, 0x54, 0x49, 0x38, 0x33, 0x46, 0x2A,
- #**TI83F*
- 0x1A, 0x0A, 0x00,
- #signature
- 0x41, 0x70, 0x70, 0x56, 0x61, 0x72, 0x69, 0x61,
- #comment area
- 0x62, 0x6c, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00]
- #data size
- self.varheader = [0x0D, 0x00,
- 0x00, 0x00,
- #length of variable in bytes
- vt,
- #variable type ID. 0x15 is for appvar, 0x06 is for locked prgm
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- #variable name (max 8 characters)
- 0x00,
- #version
- 0x80,
- #flag. 80h for archived variable. 00h otherwise
- 0x00, 0x00,
- #length of variable in bytes (copy)
- 0x00, 0x00]
- #length of variable in bytes (another copy...)
- self.checksum = -1
- if len(name)>8:
- self.name = name[0:7]
- elif len(name)==8:
- self.name = name
- else:
- self.name = name + "\x00"*(8-len(name))
- for i in range(8):
- self.varheader[i+5]=ord(self.name[i])
- def update(self,data=[]):
- if len(data)>0xFFEC:
- print("Error: Converted data too large!")
- return
- self.header[53]=(len(data)+19)%256
- self.header[54]=(len(data)+19)//256
- dl=len(data)
- self.varheader[2]=(dl+2)%256
- self.varheader[3]=(dl+2)//256
- self.varheader[15]=(dl+2)%256
- self.varheader[16]=(dl+2)//256
- self.varheader[17]=dl%256
- self.varheader[18]=dl//256
- self.data = self.header + self.varheader + data + [0,0]
- self.checksum=sum(self.varheader)+sum(data)
- self.data[-2]=self.checksum%256
- self.data[-1]=self.checksum//256
- for i in range(len(self.data)):
- self.data[i]%=256
- def write(self,file):
- try:
- with open(file,"wb") as f:
- f.write(bytes(self.data))
- return True
- except:
- print("Something went wrong writing!")
- return False
- if __name__=='__main__':
- try:
- file_name = sys.argv[1]
- except:
- file_name = input("File to convert?")
- try:
- with open(file_name,"rb") as f:
- data_in = list(f.read())
- except:
- print("Error: File does not exist!")
- exit()
- try:
- calc_name = sys.argv[4]
- except:
- calc_name = input("Name on calc?")
- try:
- vartype = str(sys.argv[3]).lower()
- except:
- vartype = input("variable type?")
- try:
- vartype = int(vartype)%256
- except:
- if "prot" in vartype:
- vartype=6
- elif "prgm" in vartype:
- vartype=5
- elif "appvar" in vartype or "avar" in vartype:
- vartype=21
- else:
- print("""Error: invalid variable type!
- defaulting to locked program...""")
- vartype=6
- calc_var = Var_struct(calc_name,vartype)
- calc_var.update(data_in)
- try:
- comp_name = sys.argv[2]
- except:
- comp_name = input("File name?")
- calc_var.write(comp_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement