I have a buffer (an array of chars) that I am using to read data in from a socket, which contains an HTTP request. I have some regular expressions that work nicely for extracting relevant info from strings, and I am looking for a way to use those regular expressions to extract the same info from an array instead, without having to build a string out of the array. Is this possible with ctypes? This is an example of how I am getting the data right now.
import socket, array, ctypes
libc = ctypes.cdll.LoadLibrary('libc.so.6')
buff = array.array('c', '\0'*4096)
a, b = socket.socketpair()
fd = a.fileno()
buff_pointer = buff.buffer_info()[0]
b.send('a'*100)
bytes_read = libc.recv(fd, buff_pointer, len(buff), 0)
print buff #prints a zeroed array of length 4096 with 100 chars of 'a' in front
This is purely for fun/for lulz btw, inb4 it's unpythonic.
reseems to support searching in anything that supports the buffer interface. That includesarray.arrayinstances.buff = bytearray(4096); bytes_read = a.recv_into(buff).buff = (ctypes.c_char * 4096)(). Then you don't have to getbuff_pointer, unless you're doing that for fun, too.recaches them.