def initialize_all(self): print('Welcome to Kafustrok. Light blesses you. ') self.__lands = [] for i in range(0, self.__D): new = [] for j in range(0, self.__D): new.append(land()) self.__lands.append(new) for i in range(0, self.__total_num): pos = self.unoccupied_position if i < self.__m: self.__lands[pos.x][pos.y].occupied_obj = monster( pos.x, pos.y, i, self) elif i < self.__m + self.__e: self.__lands[pos.x][pos.y].occupied_obj = elf( pos.x, pos.y, i - self.__m, self) elif i < self.__m + self.__e + self.__p: self.__lands[pos.x][pos.y].occupied_obj = potion( pos.x, pos.y, i - self.__m - self.__e, self) self.__teleportable_obj.append( self.__lands[pos.x][pos.y].occupied_obj) else: self.__lands[pos.x][pos.y].occupied_obj = warrior( pos.x, pos.y, i - self.__m - self.__e - self.__p, self) self.__teleportable_obj.append( self.__lands[pos.x][pos.y].occupied_obj)
def home_POST(): f = request.files["fileToUpload"] sf = cwd + "tmp" elf.rm(sf) elf.rm("subin") elf.rm("subout") elf.rm("out") f.save(sf) os.chmod(sf, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) result = elf.elf(sf) if result == None: return "false" template = env.get_template("inf.html") ss = result["sh"] ps = result["ph"] result.pop("sh") result.pop("ph") session["class"] = result["class"] session["ro_addr"] = result["ro_addr"] session["ro_size"] = result["ro_size"] session["outLines"] = 0 funcs = config.get_inter_funcs() api32e = funcs["32"] api32n = config.get_api_name(32) comm_api = [] for i in api32n: if i in api32e: comm_api.append(i) for i in comm_api: api32n.remove(i) api64e = funcs["64"] api64n = config.get_api_name(64) comm_api = [] for i in api64n: if i in api64e: comm_api.append(i) for i in comm_api: api64n.remove(i) return template.render( header=result, sections=ss, programs=ps, apis32e=api32e, apis64e=api64e, apis32n=api32n, apis64n=api64n )
def do_file(f): print 'Opening %s'%f.name e = elf.elf(f) ehdr = e.ehdr print 'ELF Header:' print ' Magic: %s'%(' '.join(map(lambda x:'%.2x'%x, ehdr.e_ident))) print ' Class: ELF%d'%e.bits print ' Data: %s'%e.data print ' Version: %d'%ehdr.e_ident[elf.EI_VERSION] print ' OS/ABI: %s'%e.osabi print ' ABI Version: %d'%ehdr.e_ident[elf.EI_ABIVERSION] print ' Type: %s'%e.type print ' Machine: %s'%e.machine print print 'Section Headers:' print ' [Nr] Name Type Addr Off Size ES Flg Lk Inf Al' i = 0 for s in e.shdr: name = e.str(s) if name is None: name = '' t = s.type if t is None: t = '0x%x'%s.sh_type print ' [%2d] %s %s %08x %06x %06x ,,,'%(i, name.ljust(17), t.ljust(15), s.sh_addr, s.sh_offset, s.sh_size) #print ' '.join(map(lambda x:'%.2x'%x, (e.rawdata(s)))) #print '%r'%e.rawdata(s) i += 1 print """Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) """ print 'Program Headers: %d'%ehdr.e_phnum print ' Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align' for p in e.phdr: print ' ... %r'%p print
def main(src_name: str, dest_name: str) -> None: refs = { # constants b"NULL": int64(0), b"OK": int64(0), b"STDIN": int64(0), b"TRUE": int64(1), b"STDOUT": int64(1), b"INET": int64(2), b"END": int64(2), b"STREAM": int64(1), b"CREAT": int64(0o1000 + 0o100 + 0o2), # O_TRUNC |O_CREAT | O_RDWR # syscalls b"read": int64(0), b"write": int64(1), b"open": int64(2), b"lseek": int64(8), b"socket": int64(41), b"connect": int64(42), b"accept": int64(43), b"sendto": int64(44), b"recvfrom": int64(45), b"bind": int64(49), b"listen": int64(50), b"exit": int64(60), } lens = {} token = b"" i = 0 with open(src_name, "rb") as src, open(dest_name, "wb") as dest: dest.write(elf(0)) dest.write(b"\x48\xb8") dest.write(int64(0)) dest.write(b"\xff\xd0") while True: c = src.read(1) #print(c.decode(), end="") if not c: break if c == b"\n": pass elif c == b" ": if token != b"": dest.write(MOV_REG[i]) dest.write(refs[token]) i += 1 token = b"" elif c == b"*": dest.write(MOV_REG[i]) dest.write(lens[token]) i += 1 token = b"" elif c == b">": dest.write(DEREF[i - 1]) elif c == b"+": dest.write(b"\x48\x01\xf8") # add rax, rdi i = 1 elif c == b"-": dest.write(b"\x48\x29\xf8") # sub rax, rdi i = 1 elif c == b"<": dest.write(b"\x48\xA3") # mov [qword ], rax dest.write(refs[token]) token = b"" i = 0 elif c == b"[": dest.write(MOV_REG[6]) # mov r9 dest.write(refs[token]) dest.write(DEREF[6]) # mov r9,[r9] dest.write(b"\x49\x89\x01") # mov [r9], rax token = b"" i = 0 elif c == b"|": dest.write(b"\x58") # pop rax elif c == b"!": dest.write(b"\xff\xd0") # call i = 0 elif c == b"$": dest.write(b"\x0f\x05") # syscall i = 0 elif c == b"=": dest.write(b"\x48\x39\xf8") # cmp rax, rdi dest.write(b"\x75\x02") # jne 2 dest.write(b"\xff\xd6") # call rsi i = 0 elif c == b"~": dest.write(b"\x48\x39\xf8") # cmp rax, rdi dest.write(b"\x74\x02") # je 2 dest.write(b"\xff\xd6") # call rsi i = 0 elif c == b":": dest.write(b"\xc3") # ret print(token.decode(), "offset", dest.tell()) refs[token] = int64(0x08048000 + dest.tell()) lens[token] = 0 c = src.read(1) in_str = False in_byte = False tmp = 0 while c != b"\n": if in_str: if c == b'"': in_str = False else: dest.write(c) lens[token] += 1 else: if c == b'"': in_str = True elif c == b" ": if in_byte: dest.write( int(tmp).to_bytes(1, byteorder="little")) lens[token] += 1 tmp = 0 in_byte = False elif c == b"*": mul = b"" c = src.read(1) while c not in b" \n": mul += c c = src.read(1) for _ in range(int(mul) - 1): dest.write( int(tmp).to_bytes(1, byteorder="little")) lens[token] += 1 tmp = 0 continue else: tmp <<= 4 tmp += int(c, 16) in_byte = True c = src.read(1) if in_byte: dest.write(int(tmp).to_bytes(1, byteorder="little")) lens[token] += 1 lens[token] = int64(lens[token]) token = b"" else: token += c size = dest.tell() dest.seek(0x60) dest.write(int64(size)) # p_filesz dest.write(int64(size)) # p_memsz dest.seek(0x7A) dest.write(refs[b"main"]) # call main os.chmod(dest_name, 0o777)