How to use _disconnect method in tavern

Best Python code snippet using tavern

proxy.py

Source:proxy.py Github

copy

Full Screen

...35 36 def _connect(self):37 self.sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM)38 self.sock.connect( (self.server_host, self.server_port) )39 def _disconnect(self):40 #self.sock.close()41 return42 43 def readmemory( self, memaddr, len):44 #self._connect()45 msglen = struct.pack("L", 8)46 mcode = struct.pack("L", PROXYCODE_READMEMORY)47 memaddr = struct.pack("L", memaddr) 48 memlen = struct.pack("L", len)49 msg = msglen + mcode + memaddr + memlen50 self.sock.send( msg )51 #answer = self.sock.recv(8192)52 answer = self._readanswer()53 self._disconnect()54 return answer[8:]5556 def writememory( self, memaddr, bufflen, data):57 #self._connect()58 tlen = 8 + bufflen59 msglen = struct.pack("L", 8+tlen)60 mcode = struct.pack("L", PROXYCODE_WRITEMEMORY)61 memaddr = struct.pack("L", memaddr)62 memlen = struct.pack("L", bufflen)63 msg = msglen + mcode + memaddr + memlen + data64 self.sock.send( msg )65 #answer = self.sock.recv(8192)66 answer = self._readanswer()67 self._disconnect()68 return answer[8:] 69 70 def allocmemory( self, bcount):71 #self._connect()72 msglen = struct.pack("L", 8)73 mcode = struct.pack("L", PROXYCODE_ALLOCMEM)74 bytecount = struct.pack("L", bcount)75 retvalue = struct.pack("L", 0)76 msg = msglen + mcode + bytecount + retvalue77 self.sock.send( msg )78 #answer = self.sock.recv(8192)79 answer = self._readanswer()80 self._disconnect()81 return (struct.unpack("L", answer[8:12])[0], struct.unpack("L", answer[12:16])[0])82 83 def callfunction( self, funcaddr, params_tuple):84 #self._connect()85 msglen = struct.pack("L", 8 + (len(params_tuple)*4) )86 mcode = struct.pack("L", PROXYCODE_CALLFUNCTION)87 addr = struct.pack("L", funcaddr)88 paramcount = struct.pack("L", len(params_tuple))89 msg = msglen + mcode + addr + paramcount90 for x in xrange(0, len(params_tuple)):91 msg += struct.pack("L", params_tuple[x])92 self.sock.send( msg )93 answer = self._readanswer()94 self._disconnect()95 return struct.unpack("L", answer[8:])[0]96 97 def freememory( self, inmemaddr):98 #self._connect()99 msglen = struct.pack("L", 4)100 mcode = struct.pack("L", PROXYCODE_FREEMEM)101 memaddr = struct.pack("L", inmemaddr)102 msg = msglen + mcode + memaddr103 self.sock.send( msg )104 #answer = self.sock.recv(8192)105 answer = self._readanswer()106 self._disconnect()107 return struct.unpack("L", answer[8:])[0]108109 def readasciiz(self, straddr):110 #self._connect()111 msglen = struct.pack("L", 4)112 mcode = struct.pack("L", PROXYCODE_READASCIIZ)113 memaddr = struct.pack("L", straddr)114 msg = msglen + mcode + memaddr115 self.sock.send(msg)116 #answer = self.sock.recv(8192)117 answer = self._readanswer()118 self._disconnect()119 str1 = answer[8:]120 str1 = str1.replace('\x00','')121 return str1122123 def readunicode(self, straddr):124 #self._connect()125 msglen = struct.pack("L", 4)126 mcode = struct.pack("L", PROXYCODE_READUNICODE)127 memaddr = struct.pack("L", straddr)128 msg = msglen + mcode + memaddr129 self.sock.send(msg)130 #answer = self.sock.recv(8192)131 answer = self._readanswer()132 self._disconnect()133 str1 = answer[8:]134 str1 = str1.replace('\x00','')135 return str1136137 def setbreakpoint(self, breakaddr):138 #self._connect()139 msglen = struct.pack("L", 4)140 mcode = struct.pack("L", PROXYCODE_SETBREAKPOINT)141 mbaddr = struct.pack("L", breakaddr)142 msg = msglen + mcode + mbaddr143 self.sock.send(msg)144 answer = self._readanswer()145 self._disconnect()146 return answer[8:]147148 def changeregs(self, threadid, regs):149 #self._connect()150 msglen = struct.pack("L", (4*16)+4)151 mcode = struct.pack("L", PROXYCODE_CHANGEREGS)152 tid = struct.pack("L", threadid)153 # now pack all the registers154 mregs = struct.pack("LLLLLLLLLLLLLLLL" ,regs['eax'], regs['ecx'], regs['edx'] , regs['ebx'], regs['esp'], regs['ebp'] , regs['esi'], regs['edi'], regs['eip'], regs['eflags'], regs['es'], regs['cs'], regs['ss'], regs['ds'], regs['fs'], regs['gs'] )155 msg = msglen + mcode + tid + mregs156 self.sock.send(msg)157 answer = self._readanswer()158 self._disconnect()159 return struct.unpack("L", answer[8:])[0]160161 def stepin(self, threadid):162 #self._connect()163 msglen = struct.pack("L", 4+(16*4))164 mcode = struct.pack("L", PROXYCODE_STEPIN)165 # pack threaid166 mthreadid = struct.pack("L", threadid)167 # pack empty registers so the server can return the new reg values to us168 mregs = struct.pack("LLLLLLLLLLLLLLLL", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)169 msg = msglen + mcode + mthreadid + mregs170 self.sock.send(msg)171 answer = self._readanswer()172 self._disconnect()173 # unmarshall retcode174 retcode = struct.unpack("L", answer[8:8+4])[0]175 # unmarshall new regs176 newregs = dict(zip(('eax', 'ecx','edx','ebx', 'esp', 'ebp','esi', 'edi', 'eip', 'eflags', 'es', 'cs', 'ss', 'ds', 'fs', 'gs'), struct.unpack("LLLLLLLLLLLLLLLL", answer[12:])))177 return (retcode, newregs)178179 180 def readbyte( self, byteaddr):181 t = self.readmemory(byteaddr, 1)182 return struct.unpack("B", t)[0]183 184 def readword( self, wordaddr):185 t = self.readmemory(wordaddr, 2)186 return struct.unpack("H", t)[0] ...

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 tavern 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