def GetVersion(self):
version = C.c_ushort()
self._GetVersion(self.handle, C.byref(version)) # int *
return version.value
python类c_ushort()的实例源码
def attach_filter(fd, iface, bpf_filter_string): # GV: move to a method of _L2bpfSocket
"""Attach a BPF filter to the BPF file descriptor"""
# Retrieve the BPF byte code in decimal
command = "%s -i %s -ddd -s 1600 '%s'" % (conf.prog.tcpdump, iface, bpf_filter_string)
try:
f = os.popen(command)
except OSError, msg:
raise Scapy_Exception("Failed to execute tcpdump: (%s)" % msg)
# Convert the byte code to a BPF program structure
lines = f.readlines()
if lines == []:
raise Scapy_Exception("Got an empty BPF filter from tcpdump !")
# Allocate BPF instructions
size = int(lines[0])
bpf_insn_a = bpf_insn * size
bip = bpf_insn_a()
# Fill the BPF instruction structures with the byte code
lines = lines[1:]
for i in xrange(len(lines)):
values = [int(v) for v in lines[i].split()]
bip[i].code = c_ushort(values[0])
bip[i].jt = c_ubyte(values[1])
bip[i].j = c_ubyte(values[2])
bip[i].k = c_uint(values[3])
# Create the BPF program and assign it to the interface
bp = bpf_program(size, bip)
ret = LIBC.ioctl(c_int(fd), BIOCSETF, cast(pointer(bp), c_char_p))
if ret < 0:
raise Scapy_Exception("Can't attach the BPF filter !")
# Interface manipulation functions
def __exma_bindRendezvous(self, outputs, namespaceUri, schemaVersion):
"""bindRendezvous taken from exma.dll"""
rendezvous = ctypes.c_ushort()
sock = ctypes.c_uint()
ret = exma.bindRendezvous(ctypes.pointer(rendezvous), ctypes.pointer(sock))
return (rendezvous.value, sock.value)
def doRendezvousServer(self, rendezvous, sock):
"""Setup the rendezvous server so the next plugin can talk 'through' us"""
if sock is not None:
r = ctypes.c_uint(sock)
if -1 == exma.sendSockets(r):
return -1
exma.closeRendezvous( ctypes.c_ushort(rendezvous), r)
sock = None
return 0
#
# These need to be implemented by the exploit
#
build_twlbg_code_from_dev_launcher_srl_n3ds.py 文件源码
项目:twl_firm_patcher
作者: ahezard
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def init_crc16(self):
"""The algorithm uses tables with precalculated values"""
for i in range(0, 256):
crc = c_ushort(i).value
for j in range(0, 8):
if crc & 0x0001:
crc = c_ushort(crc >> 1).value ^ self.crc16_constant
else:
crc = c_ushort(crc >> 1).value
self.crc16_tab.append(crc)
extract_dev_launcher_srl_from_twlbg_cxi_n3ds.py 文件源码
项目:twl_firm_patcher
作者: ahezard
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def init_crc16(self):
"""The algorithm uses tables with precalculated values"""
for i in range(0, 256):
crc = c_ushort(i).value
for j in range(0, 8):
if crc & 0x0001:
crc = c_ushort(crc >> 1).value ^ self.crc16_constant
else:
crc = c_ushort(crc >> 1).value
self.crc16_tab.append(crc)
def init_crc16(self):
"""The algorithm uses tables with precalculated values"""
for i in range(0, 256):
crc = c_ushort(i).value
for j in range(0, 8):
if crc & 0x0001:
crc = c_ushort(crc >> 1).value ^ self.crc16_constant
else:
crc = c_ushort(crc >> 1).value
self.crc16_tab.append(crc)
extract_dev_launcher_srl_from_twlbg_cxi_o3ds.py 文件源码
项目:twl_firm_patcher
作者: ahezard
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def init_crc16(self):
"""The algorithm uses tables with precalculated values"""
for i in range(0, 256):
crc = c_ushort(i).value
for j in range(0, 8):
if crc & 0x0001:
crc = c_ushort(crc >> 1).value ^ self.crc16_constant
else:
crc = c_ushort(crc >> 1).value
self.crc16_tab.append(crc)
build_twlbg_code_from_dev_launcher_srl_o3ds.py 文件源码
项目:twl_firm_patcher
作者: ahezard
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def init_crc16(self):
"""The algorithm uses tables with precalculated values"""
for i in range(0, 256):
crc = c_ushort(i).value
for j in range(0, 8):
if crc & 0x0001:
crc = c_ushort(crc >> 1).value ^ self.crc16_constant
else:
crc = c_ushort(crc >> 1).value
self.crc16_tab.append(crc)
def _getitem(self, start, end):
if self.itemsize == 1:
# byte-wise access
return self.source[start:end]
# move the pointer to the correct location
src = ctypes.byref(self.source.contents, start)
casttype = ctypes.c_ubyte
if self.itemsize == 2:
casttype = ctypes.c_ushort
elif self.itemsize == 3:
# TODO
raise NotImplementedError("unsupported bpp")
elif self.itemsize == 4:
casttype = ctypes.c_uint
return ctypes.cast(src, ctypes.POINTER(casttype)).contents.value
def _setitem(self, start, end, value):
target = None
if self.itemsize == 1:
target = ctypes.cast(self.source, ctypes.POINTER(ctypes.c_ubyte))
elif self.itemsize == 2:
target = ctypes.cast(self.source, ctypes.POINTER(ctypes.c_ushort))
elif self.itemsize == 3:
# TODO
raise NotImplementedError("unsupported bpp")
elif self.itemsize == 4:
target = ctypes.cast(self.source, ctypes.POINTER(ctypes.c_uint))
value = prepare_color(value, self._surface)
target[start // self.itemsize] = value
def test_to_ctypes(self):
for seq, dtype in ((singlebyteseq, ctypes.c_ubyte),
(singlebytebuf, ctypes.c_ubyte),
(doublebyteseq, ctypes.c_ushort),
(doublebytebuf, ctypes.c_ushort),
(quadbyteseq, ctypes.c_uint),
(quadbytebuf, ctypes.c_uint)):
bytebuf, size = sdlextarray.to_ctypes(seq, dtype)
self.assertEqual(size, len(seq))
for index, x in enumerate(bytebuf):
self.assertEqual(x, seq[index])
def win32_version_string():
import ctypes
class OSVERSIONINFOEXW(ctypes.Structure):
_fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
('dwMajorVersion', ctypes.c_ulong),
('dwMinorVersion', ctypes.c_ulong),
('dwBuildNumber', ctypes.c_ulong),
('dwPlatformId', ctypes.c_ulong),
('szCSDVersion', ctypes.c_wchar*128),
('wServicePackMajor', ctypes.c_ushort),
('wServicePackMinor', ctypes.c_ushort),
('wSuiteMask', ctypes.c_ushort),
('wProductType', ctypes.c_byte),
('wReserved', ctypes.c_byte)]
"""
Get's the OS major and minor versions. Returns a tuple of
(OS_MAJOR, OS_MINOR).
"""
os_version = OSVERSIONINFOEXW()
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
raise Exception("Failed to get OS version")
version_string = "Version:%d-%d; Build:%d; Platform:%d; CSD:%s; ServicePack:%d-%d; Suite:%d; ProductType:%d" % (
os_version.dwMajorVersion, os_version.dwMinorVersion,
os_version.dwBuildNumber,
os_version.dwPlatformId,
os_version.szCSDVersion,
os_version.wServicePackMajor, os_version.wServicePackMinor,
os_version.wSuiteMask,
os_version.wReserved
)
return version_string
def __exma_bindRendezvous(self, outputs, namespaceUri, schemaVersion):
"""bindRendezvous taken from exma.dll"""
rendezvous = ctypes.c_ushort()
sock = ctypes.c_uint()
ret = exma.bindRendezvous(ctypes.pointer(rendezvous), ctypes.pointer(sock))
return (rendezvous.value, sock.value)
def doRendezvousServer(self, rendezvous, sock):
"""Setup the rendezvous server so the next plugin can talk 'through' us"""
if sock is not None:
r = ctypes.c_uint(sock)
if -1 == exma.sendSockets(r):
return -1
exma.closeRendezvous( ctypes.c_ushort(rendezvous), r)
sock = None
return 0
#
# These need to be implemented by the exploit
#
def win32_version_string():
import ctypes
class OSVERSIONINFOEXW(ctypes.Structure):
_fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
('dwMajorVersion', ctypes.c_ulong),
('dwMinorVersion', ctypes.c_ulong),
('dwBuildNumber', ctypes.c_ulong),
('dwPlatformId', ctypes.c_ulong),
('szCSDVersion', ctypes.c_wchar*128),
('wServicePackMajor', ctypes.c_ushort),
('wServicePackMinor', ctypes.c_ushort),
('wSuiteMask', ctypes.c_ushort),
('wProductType', ctypes.c_byte),
('wReserved', ctypes.c_byte)]
"""
Get's the OS major and minor versions. Returns a tuple of
(OS_MAJOR, OS_MINOR).
"""
os_version = OSVERSIONINFOEXW()
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
raise Exception("Failed to get OS version")
version_string = "Version:%d-%d; Build:%d; Platform:%d; CSD:%s; ServicePack:%d-%d; Suite:%d; ProductType:%d" % (
os_version.dwMajorVersion, os_version.dwMinorVersion,
os_version.dwBuildNumber,
os_version.dwPlatformId,
os_version.szCSDVersion,
os_version.wServicePackMajor, os_version.wServicePackMinor,
os_version.wSuiteMask,
os_version.wReserved
)
return version_string
def _getitem(self, start, end):
if self.itemsize == 1:
# byte-wise access
return self.source[start:end]
# move the pointer to the correct location
src = ctypes.byref(self.source.contents, start)
casttype = ctypes.c_ubyte
if self.itemsize == 2:
casttype = ctypes.c_ushort
elif self.itemsize == 3:
# TODO
raise NotImplementedError("unsupported bpp")
elif self.itemsize == 4:
casttype = ctypes.c_uint
return ctypes.cast(src, ctypes.POINTER(casttype)).contents.value
def _setitem(self, start, end, value):
target = None
if self.itemsize == 1:
target = ctypes.cast(self.source, ctypes.POINTER(ctypes.c_ubyte))
elif self.itemsize == 2:
target = ctypes.cast(self.source, ctypes.POINTER(ctypes.c_ushort))
elif self.itemsize == 3:
# TODO
raise NotImplementedError("unsupported bpp")
elif self.itemsize == 4:
target = ctypes.cast(self.source, ctypes.POINTER(ctypes.c_uint))
value = prepare_color(value, self._surface)
target[start // self.itemsize] = value
def test_to_ctypes(self):
for seq, dtype in ((singlebyteseq, ctypes.c_ubyte),
(singlebytebuf, ctypes.c_ubyte),
(doublebyteseq, ctypes.c_ushort),
(doublebytebuf, ctypes.c_ushort),
(quadbyteseq, ctypes.c_uint),
(quadbytebuf, ctypes.c_uint)):
bytebuf, size = sdlextarray.to_ctypes(seq, dtype)
self.assertEqual(size, len(seq))
for index, x in enumerate(bytebuf):
self.assertEqual(x, seq[index])
def prepare(self, query_string):
"""prepare a query"""
#self._free_results(FREE_STATEMENT)
if not self.connection:
self.close()
if type(query_string) == unicode:
c_query_string = wchar_pointer(UCS_buf(query_string))
ret = ODBC_API.SQLPrepareW(self.stmt_h, c_query_string, len(query_string))
else:
c_query_string = ctypes.c_char_p(query_string)
ret = ODBC_API.SQLPrepare(self.stmt_h, c_query_string, len(query_string))
if ret != SQL_SUCCESS:
check_success(self, ret)
self._PARAM_SQL_TYPE_LIST = []
if self.connection.support_SQLDescribeParam:
# SQLServer's SQLDescribeParam only supports DML SQL, so avoid the SELECT statement
if True:# 'SELECT' not in query_string.upper():
#self._free_results(NO_FREE_STATEMENT)
NumParams = c_short()
ret = ODBC_API.SQLNumParams(self.stmt_h, ADDR(NumParams))
if ret != SQL_SUCCESS:
check_success(self, ret)
for col_num in range(NumParams.value):
ParameterNumber = ctypes.c_ushort(col_num + 1)
DataType = c_short()
ParameterSize = ctypes.c_size_t()
DecimalDigits = c_short()
Nullable = c_short()
ret = ODBC_API.SQLDescribeParam(
self.stmt_h,
ParameterNumber,
ADDR(DataType),
ADDR(ParameterSize),
ADDR(DecimalDigits),
ADDR(Nullable),
)
if ret != SQL_SUCCESS:
try:
check_success(self, ret)
except DatabaseError:
if sys.exc_info()[1].value[0] == '07009':
self._PARAM_SQL_TYPE_LIST = []
break
else:
raise sys.exc_info()[1]
except:
raise sys.exc_info()[1]
self._PARAM_SQL_TYPE_LIST.append((DataType.value,DecimalDigits.value))
self.statement = query_string