How to use byte2int method in pyresttest

Best Python code snippet using pyresttest_python

ELF.py

Source:ELF.py Github

copy

Full Screen

...52 self.size = size53 self.read_header(size)54 55 # Read in program header56 self.obj.seek(byte2int(self.header.e_phoff))57 #phnum = utils.byte2int(self.header.e_phnum)58 for i in range(0, (byte2int(self.header.e_phnum))):59 self.read_program_header(size)60 # Read in section header61 self.obj.seek(byte2int(self.header.e_shoff))62 #shnum = utils.byte2int(self.header.e_shoff)63 shnum = byte2int(self.header.e_shnum)64 for i in range(0, shnum):65 self.read_section_header(size)66 s_type = byte2int(self.section_header[i].sh_type)67 if s_type is SH_TYPE.SHT_SYMTAB:68 self.obj.seek(byte2int(69 self.section_header[i].sh_offset), 0)70 symbol_tbl = self.obj.read(71 byte2int(self.section_header[i].sh_size))72 offset = 073 for j in range (0, (int(74 byte2int(self.section_header[i].sh_size) / 24))):75 self.read_symtab_entry(symbol_tbl[offset:offset+24],76 self.string_tb)77 offset += 2478 elif s_type is SH_TYPE.SHT_DYNSYM:79 self.obj.seek(byte2int(80 self.section_header[i].sh_offset), 0)81 symbol_tbl = self.obj.read(82 byte2int(self.section_header[i].sh_size))83 offset = 084 for j in range(0, (int(85 byte2int(self.section_header[i].sh_size) / 24))):86 self.read_symtab_entry(symbol_tbl[offset:offset+24],87 self.string_tb_dyn)88 offset += 2489 90 self.pop_data_section()91 self.pop_text_section()92 # Debug stuff93 # print(str(self.text_section.hex()))94 # print(type(self.text_section))95 # print("Got here")96 # input()97 # end Debug stuff98 self.get_program_header_dynamic_entries()99 self.pop_dynamic_entries(".dynamic", 100 self.dyn_section_entries)101 self.pop_rela(".rela.plt", self.rela_plt, self.rela_plt_entries)102 self.pop_rela(".rela.dyn", self.rela_dyn, self.rela_dyn_entries)103 def read_header(self, size):104 """ 105 Parse the header from the file: self.obj106 """107 assert type(size) is int108 self.header.ei_mag = self.obj.read(4)109 self.header.ei_class = self.obj.read(1)110 self.header.ei_data = self.obj.read(1)111 self.header.ei_version = self.obj.read(1)112 self.header.ei_osabi = self.obj.read(1)113 self.header.ei_abiversion = self.obj.read(1)114 self.header.ei_pad = self.obj.read(7)115 self.header.e_type = self.obj.read(2)116 self.header.e_machine = self.obj.read(2)117 self.header.e_version = self.obj.read(4)118 # e_entry, e_phoff, e_shoff depend on size: 32 vs 64119 if size == 32:120 self.header.e_entry = self.obj.read(4)121 self.header.e_phoff = self.obj.read(4)122 self.header.e_shoff = self.obj.read(4)123 elif size == 64:124 self.header.e_entry = self.obj.read(8)125 self.header.e_phoff = self.obj.read(8)126 self.header.e_shoff = self.obj.read(8)127 self.header.e_flags = self.obj.read(4)128 self.header.e_ehsize = self.obj.read(2)129 self.header.e_phentsize = self.obj.read(2)130 self.header.e_phnum = self.obj.read(2)131 self.header.e_shentsize = self.obj.read(2)132 self.header.e_shnum = self.obj.read(2)133 self.header.e_shstrndx = self.obj.read(2)134 def read_program_header(self, size):135 tmp = PROGRAM_HEADER(0,0,0,0,0,0,0,0,0)136 tmp.p_type = self.obj.read(4)137 if size == 32:138 tmp.offset = self.obj.read(4)139 tmp.p_vaddr = self.obj.read(4)140 tmp.p_paddr = self.obj.read(4)141 tmp.p_filesz = self.obj.read(4)142 tmp.p_memsz = self.obj.read(4)143 tmp.p_flags32 = self.obj.read(4)144 tmp.p_align = self.obj.read(4)145 elif size == 64:146 tmp.p_flags = self.obj.read(4)147 tmp.p_offset = self.obj.read(8)148 tmp.p_vaddr = self.obj.read(8)149 tmp.p_paddr = self.obj.read(8)150 tmp.p_filesz = self.obj.read(8)151 tmp.p_memsz = self.obj.read(8)152 tmp.p_align = self.obj.read(8)153 self.program_header.append(tmp)154 def read_section_header(self, size):155 tmp = SECTION_HEADER(0,0,0,0,0,0,0,0,0,0)156 tmp.sh_name = self.obj.read(4)157 tmp.sh_type = self.obj.read(4)158 if size == 32:159 tmp.sh_flags = self.obj.read(4)160 tmp.sh_addr = self.obj.read(4)161 tmp.sh_offset = self.obj.read(4)162 tmp.sh_size = self.obj.read(4)163 tmp.sh_link = self.obj.read(4)164 tmp.sh_info = self.obj.read(4)165 tmp.sh_addralign = self.obj.read(4)166 tmp.sh_entsize = self.obj.read(4)167 elif size == 64:168 tmp.sh_flags = self.obj.read(8)169 tmp.sh_addr = self.obj.read(8)170 tmp.sh_offset = self.obj.read(8)171 tmp.sh_size = self.obj.read(8)172 tmp.sh_link = self.obj.read(4)173 tmp.sh_info = self.obj.read(4)174 tmp.sh_addralign = self.obj.read(8)175 tmp.sh_entsize = self.obj.read(8)176 self.section_header.append(tmp)177 def read_symtab_entry(self, symtab, entries):178 tmp = SYMTAB_ENTRY64(0,0,0,0,0,0,0,0)179 tmp.st_name = symtab[0:4]180 tmp.st_info = symtab[4:5]181 tmp.st_other = symtab[5:6]182 tmp.st_shndx = symtab[6:8]183 tmp.st_value = symtab[8:16]184 tmp.st_size = symtab[16:24]185 tmp.st_bind = byte2int(tmp.st_info) >> 4186 tmp.st_type = byte2int(tmp.st_info) & 0x0f187 def read_section_name(self, index):188 shstrtab_ndx = byte2int(self.header.e_shstrndx)189 name = ""190 self.obj.seek(byte2int(self.section_header[shstrtab_ndx].sh_offset),191 0)192 strs = self.obj.read(byte2int(193 self.section_header[shstrtab_ndx].sh_size))194 c = strs[index]195 while chr(c) != '\0':196 index += 1197 name += chr(c)198 c = strs[index]199 return name200 def pop_data_section(self):201 for section in self.section_header:202 name = self.read_section_name(byte2int(section.sh_name))203 if name == '.data':204 self.obj.seek(byte2int(section.sh_offset))205 self.data_section = self.obj.read(byte2int(section.sh_name))206 def pop_text_section(self):207 for section in self.section_header:208 name = self.read_section_name(byte2int(section.sh_name))209 if name == '.text':210 self.obj.seek(byte2int(section.sh_offset))211 self.text_section = self.obj.read(byte2int(section.sh_size))212 def get_program_header_dynamic_entries(self):213 size = 0214 for program_header in self.program_header:215 if byte2int(program_header.p_type) == p_type.PT_DYNAMIC:216 self.obj.seek(byte2int(program_header.p_offset), 0)217 size = byte2int(program_header.p_filesz)218 program_header_dyn = self.obj.read(size)219 for i in range(int(size/8)):220 d_tag = byte2int(program_header_dyn[8*i:8*i+4])221 d_un = byte2int(program_header_dyn[8*i + 4 : 8*i + 8])222 self.ph_dyn_entries.append(program_header_dynamic_entry(d_tag, d_un))223 def pop_dynamic_entries(self, section_name, pop_target):224 for section in self.section_header:225 name = self.read_section_name(byte2int(section.sh_name))226 if name == section_name:227 self.obj.seek(byte2int(section.sh_offset))228 self.dyn_section = self.obj.read(byte2int(section.sh_size))229 sec_length = int(len(self.dyn_section))230 tmp = {}231 if self.size == 64: 232 jump_value = 8233 elif self.size == 32:234 jump_value = 4235 else:236 jump_value = 8237 print("self.size is not 32/64. Setting default jump value to 8")238 for offset in range(0, sec_length, jump_value*2):239 d_tag_type = byte2int(self.dyn_section[offset:offset+jump_value])240 tmp["dtag"] = d_tag_type241 value = byte2int(self.dyn_section[offset+jump_value:offset+2*jump_value])242 tmp["value"] = value243 tag_type_str = get_program_header_dynamic_entries_d_tag_type(d_tag_type)244 tmp["tag_type_str"] = tag_type_str245 # tag_type_str = ""246 pop_target.append(tmp)247 # tmp = {}248 def pop_rela(self, section_name, section_content, pop_target):249 size = int()250 entsize = int()251 tmp = {}252 step = int()253 if self.size == 64:254 step = 8255 elif self.size == 32:256 step = 4257 for section in self.section_header:258 name = self.read_section_name(byte2int(section.sh_name))259 if name == section_name:260 self.obj.seek(byte2int(section.sh_offset))261 section_content = self.obj.read(byte2int(section.sh_size))262 size = byte2int(section.sh_size)263 entsize = byte2int(section.sh_entsize)264 if entsize != 0:265 for i in range(0, int(size/entsize)):266 tmp["r_offset"] = byte2int(section_content[i*entsize:i*entsize+step])267 tmp["r_info"] = byte2int(section_content[i*entsize+step:i*entsize+(step*2)])268 tmp["r_append"] = byte2int(section_content[i*entsize+(step*2):i*entsize+(step*3)], sign=True)269 pop_target.append(tmp)...

Full Screen

Full Screen

actr.py

Source:actr.py Github

copy

Full Screen

...6def dprint(msg):7 pass8def byte2str(input_, signed=False):9 return str(int.from_bytes(input_, byteorder='little', signed=signed))10def byte2int(input_, signed=False):11 return int.from_bytes(input_, byteorder='little', signed=signed)12def parse_act(filename):13 act = Act()14 with open(filename, 'rb') as f:15 data = f.read()16 dprint(data)17 offset = 018 act_header = data[:2]19 act.header = act_header20 dprint('Act Header: ' + str(act_header))21 act_sub_version = data[2:3]22 act.sub_version = byte2int(act_sub_version)23 dprint('Sub Version: ' + byte2str(act_sub_version))24 act_sub_version = byte2int(act_sub_version)25 act_version = data[3:4]26 act.version = byte2int(act_version)27 dprint('Version: ' + byte2str(act_version))28 nanimations = data[4:6]29 dprint('# Animations: ' + byte2str(nanimations) + ' | ' + str(nanimations))30 unknown = data[6:16]31 # not in act object, cause not needed32 dprint('Unknown: ' + byte2str(unknown))33 b = 1234 e = 1635 offset += 436 animations = []37 # temp not needed38 # animations['count'] = byte2int(nanimations)39 for k in range(byte2int(nanimations)):40 animation = Animation()41 nframes = data[b + offset:e + offset]42 offset += 443 dprint('# Frames: ' + byte2str(nframes) + ' | ' + str(nframes))44 frames = []45 # temp not needed46 # frames['count'] = byte2int(nframes)47 for j in range(byte2int(nframes)):48 frame = Frame()49 frame.id = j50 # unused = data[20:52]51 offset += 3252 # dprint('Unused: ' + byte2str(unused))53 nsubframes = data[b + offset:e + offset]54 offset += 455 dprint('# SubFrames: ' + byte2str(nsubframes))56 subframes = []57 # temp not needed58 # subframes['count'] = byte2int(nsubframes)59 for i in range(byte2int(nsubframes)):60 subframe = Subframe()61 dprint('---- Subframe ' + str(i + 1) + ' ----')62 offset_x = data[b + offset:e + offset]63 subframe.offset_x = byte2int(offset_x, True)64 offset += 465 dprint('Offset X: ' + byte2str(offset_x, True) + ' | ' + str(66 offset_x))67 offset_y = data[b + offset:e + offset]68 subframe.offset_y = byte2int(offset_y, True)69 offset += 470 dprint('Offset Y: ' + byte2str(offset_y, True) + ' | ' + str(71 offset_y))72 image = data[b + offset:e + offset]73 subframe.image = byte2int(image, True)74 offset += 475 dprint('Image: ' + byte2str(image, True) + ' | ' + str(image))76 direction = data[b + offset:e + offset]77 subframe.mirror = byte2int(direction)78 offset += 479 dprint('Mirror: ' + byte2str(direction) + ' | ' + str(80 direction))81 color = data[b + offset:e + offset]82 subframe.color = byte2int(color)83 offset += 484 dprint('Color: ' + byte2str(color) + ' | ' + str(color))85 if act_sub_version >= 2:86 scale_x = data[b + offset:e + offset]87 subframe.scale_x = struct.unpack('f', scale_x)88 offset += 489 dprint(struct.unpack('f', scale_x))90 dprint('Scale X: ' + ' | ' + str(scale_x))91 if act_sub_version >= 4:92 scale_y = data[b + offset:e + offset]93 subframe.scale_y = struct.unpack('f', scale_y)94 offset += 495 dprint(struct.unpack('f', scale_y))96 dprint('Scale Y:' + ' | ' + str(scale_y))97 else:98 scale_y = scale_x99 subframe.scale_y = struct.unpack('f', scale_y)100 dprint('Scale Y:' + byte2str(scale_y))101 if act_sub_version >= 2:102 rotation = data[b + offset:e + offset]103 subframe.rotation = byte2int(rotation)104 offset += 4105 dprint('Rotation: ' + byte2str(rotation))106 jump = data[b + offset:e + offset]107 # currently not needed in108 offset += 4109 dprint('Jump: ' + byte2str(jump) + ' | ' + str(jump))110 if not jump:111 offset += 12112 if act_sub_version >= 5:113 size_x = data[b + offset:e + offset]114 subframe.size_x = byte2int(size_x)115 offset += 4116 dprint('Size X: ' + byte2str(size_x))117 size_y = data[b + offset:e + offset]118 subframe.size_y = byte2int(size_y)119 offset += 4120 dprint('Size Y: ' + byte2str(size_y))121 subframes.append(subframe)122 frame.subframes = subframes123 sound = data[b + offset:e + offset]124 frame.sound = byte2int(sound, True)125 offset += 4126 dprint('Sound: ' + byte2str(sound, True))127 if act_sub_version >= 2:128 extra_info = data[b + offset:e + offset]129 frame.extra_info = byte2int(extra_info, True)130 offset += 4131 dprint('Extra Info: ' + byte2str(extra_info, True))132 if byte2int(extra_info, True) < 0:133 raise ValueError('Extra Info cant be negative')134 for _ in range(byte2int(extra_info)):135 offset += 4136 extra_x = data[b + offset:e + offset]137 frame.extra_x = byte2int(extra_x, True)138 offset += 4139 dprint('Extra X: ' + byte2str(extra_x, True))140 extra_y = data[b + offset:e + offset]141 frame.extra_y = byte2int(extra_y, True)142 offset += 4143 dprint('Extra Y: ' + byte2str(extra_y, True))144 sound_file = data[b + offset:e + offset]145 frame.sound_file = byte2int(sound_file)146 offset += 4147 dprint('Sound File: ' + byte2str(sound_file))148 for _ in range(byte2int(sound_file)):149 offset += 40150 frames.append(frame)151 animation.frames = frames152 animations.append(animation)153 act.animations = animations154 # dprint(animations.__len__())155 # animation speed not needed currently156 # for _ in range(byte2int(nframes)):157 # offset += 4158 return act159def main():160 # filename = 'Black_Valkyrie_Helm.act'161 filename = 'wizard.act'162 dprint(parse_act(filename))163if __name__ == '__main__':...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1import struct2def byte2str(input_, signed=False):3 return str(int.from_bytes(input_, byteorder='little', signed=signed))4def byte2int(input_, signed=False):5 return int.from_bytes(input_, byteorder='little', signed=signed)6def parse_act(filename):7 act = {}8 with open(filename, 'rb') as f:9 data = f.read()10 print(data)11 offset = 012 act_header = data[:2]13 act['act_header'] = act_header14 print('Act Header: ' + str(act_header))15 act_sub_version = data[2:3]16 act['act_sub_version'] = byte2int(act_sub_version)17 print('Sub Version: ' + byte2str(act_sub_version))18 act_sub_version = byte2int(act_sub_version)19 act_version = data[3:4]20 act['act_version'] = byte2int(act_version)21 print('Version: ' + byte2str(act_version))22 nanimations = data[4:6]23 print('# Animations: ' + byte2str(nanimations) + ' | ' + str(nanimations))24 unknown = data[6:16]25 # not in act object, cause not needed26 print('Unknown: ' + byte2str(unknown))27 b = 1228 e = 1629 offset += 430 animations = {}31 animations['count'] = byte2int(nanimations)32 for k in range(byte2int(nanimations)):33 animation = {}34 nframes = data[b + offset:e + offset]35 offset += 436 print('# Frames: ' + byte2str(nframes) + ' | ' + str(nframes))37 frames = {}38 frames['count'] = byte2int(nframes)39 for j in range(byte2int(nframes)):40 frame = {}41 # unused = data[20:52]42 offset += 3243 # print('Unused: ' + byte2str(unused))44 nsubframes = data[b + offset:e + offset]45 offset += 446 print('# SubFrames: ' + byte2str(nsubframes))47 subframes = {}48 subframes['count'] = byte2int(nsubframes)49 for i in range(byte2int(nsubframes)):50 subframe = {}51 print('---- Subframe ' + str(i + 1) + ' ----')52 offset_x = data[b + offset:e + offset]53 subframe['offset_x'] = byte2int(offset_x, True)54 offset += 455 print('Offset X: ' + byte2str(offset_x, True) + ' | ' + str(56 offset_x))57 offset_y = data[b + offset:e + offset]58 subframe['offset_y'] = byte2int(offset_y, True)59 offset += 460 print('Offset Y: ' + byte2str(offset_y, True) + ' | ' + str(61 offset_y))62 image = data[b + offset:e + offset]63 subframe['image'] = byte2int(image, True)64 offset += 465 print('Image: ' + byte2str(image, True) + ' | ' + str(image))66 direction = data[b + offset:e + offset]67 subframe['direction'] = byte2int(direction)68 offset += 469 print('Direction: ' + byte2str(direction) + ' | ' + str(70 direction))71 color = data[b + offset:e + offset]72 subframe['color'] = byte2int(color)73 offset += 474 print('Color: ' + byte2str(color) + ' | ' + str(color))75 if act_sub_version >= 2:76 scale_x = data[b + offset:e + offset]77 subframe['scale_x'] = struct.unpack('f', scale_x)78 offset += 479 print(struct.unpack('f', scale_x))80 print('Scale X: ' + ' | ' + str(scale_x))81 if act_sub_version >= 4:82 scale_y = data[b + offset:e + offset]83 subframe['scale_y'] = struct.unpack('f', scale_y)84 offset += 485 print(struct.unpack('f', scale_y))86 print('Scale Y:' + ' | ' + str(scale_y))87 else:88 scale_y = scale_x89 subframe['scale_y'] = struct.unpack('f', scale_y)90 print('Scale Y:' + byte2str(scale_y))91 if act_sub_version >= 2:92 rotation = data[b + offset:e + offset]93 subframe['rotation'] = byte2int(rotation)94 offset += 495 print('Rotation: ' + byte2str(rotation))96 jump = data[b + offset:e + offset]97 # currently not needed in98 offset += 499 print('Jump: ' + byte2str(jump) + ' | ' + str(jump))100 if not jump:101 offset += 12102 if act_sub_version >= 5:103 size_x = data[b + offset:e + offset]104 subframe[size_x] = byte2int(size_x)105 offset += 4106 print('Size X: ' + byte2str(size_x))107 size_y = data[b + offset:e + offset]108 subframe[size_y] = byte2int(size_y)109 offset += 4110 print('Size Y: ' + byte2str(size_y))111 subframes['subframe' + str(i)] = subframe112 frame['subframes'] = subframes113 sound = data[b + offset:e + offset]114 frame['sound'] = byte2int(sound, True)115 offset += 4116 print('Sound: ' + byte2str(sound, True))117 if act_sub_version >= 2:118 extra_info = data[b + offset:e + offset]119 frame['extra_info'] = byte2int(extra_info, True)120 offset += 4121 print('Extra Info: ' + byte2str(extra_info, True))122 if byte2int(extra_info, True) < 0:123 raise ValueError('Extra Info cant be negative')124 for _ in range(byte2int(extra_info)):125 offset += 4126 extra_x = data[b + offset:e + offset]127 frame['extra_x'] = byte2int(extra_x, True)128 offset += 4129 print('Extra X: ' + byte2str(extra_x, True))130 extra_y = data[b + offset:e + offset]131 frame['extra_y'] = byte2int(extra_y, True)132 offset += 4133 print('Extra Y: ' + byte2str(extra_y, True))134 sound_file = data[b + offset:e + offset]135 frame['sound_file'] = byte2int(sound_file)136 offset += 4137 print('Sound File: ' + byte2str(sound_file))138 for _ in range(byte2int(sound_file)):139 offset += 40140 frames['frame' + str(j)] = frame141 animation['frames'] = frames142 animations['animation' + str(k)] = animation143 act['animations'] = animations144 # animation speed not needed currently145 # for _ in range(byte2int(nframes)):146 # offset += 4147 return act148def main():149 # filename = 'Black_Valkyrie_Helm.act'150 filename = 'kopf_1.act'151 print(parse_act(filename))152if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyresttest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful