1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
import _rawffi, sys
try:
from _thread import _local as local
except ImportError:
class local(object): # no threads
pass
class ConvMode:
encoding = 'ascii'
errors = 'strict'
_memmove_addr = _rawffi.get_libc().getaddressindll('memmove')
_memset_addr = _rawffi.get_libc().getaddressindll('memset')
def _string_at_addr(addr, lgt):
# address here can be almost anything
import ctypes
cobj = ctypes.c_void_p.from_param(addr)
arg = cobj._get_buffer_value()
return _rawffi.charp2rawstring(arg, lgt)
def set_conversion_mode(encoding, errors):
old_cm = ConvMode.encoding, ConvMode.errors
ConvMode.errors = errors
ConvMode.encoding = encoding
return old_cm
def _wstring_at_addr(addr, lgt):
import ctypes
cobj = ctypes.c_void_p.from_param(addr)
arg = cobj._get_buffer_value()
return _rawffi.wcharp2rawunicode(arg, lgt)
_err = local()
def get_errno():
return getattr(_err, "errno", 0)
def set_errno(errno):
old_errno = get_errno()
_err.errno = errno
return old_errno
def get_last_error():
return getattr(_err, "winerror", 0)
def set_last_error(winerror):
old_winerror = get_last_error()
_err.winerror = winerror
return old_winerror
|