コード例 #1
0
        private static byte[] DecodingByteArrayHelper(BerSafeHandle berElement, char fmt, ref int error)
        {
            error = 0;
            IntPtr zero      = IntPtr.Zero;
            berval structure = new berval();

            byte[] destination = null;
            error = Wldap32.ber_scanf_ptr(berElement, new string(fmt, 1), ref zero);
            try
            {
                if ((error == 0) && (zero != IntPtr.Zero))
                {
                    Marshal.PtrToStructure(zero, structure);
                    destination = new byte[structure.bv_len];
                    Marshal.Copy(structure.bv_val, destination, 0, structure.bv_len);
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    Wldap32.ber_bvfree(zero);
                }
            }
            return(destination);
        }
コード例 #2
0
ファイル: BerConverter.cs プロジェクト: modulexcite/pash-1
        private static byte[] DecodingByteArrayHelper(BerSafeHandle berElement, char fmt, ref int error)
        {
            error = 0;
            IntPtr intPtr  = (IntPtr)0;
            berval _berval = new berval();

            byte[] numArray = null;
            error = Wldap32.ber_scanf_ptr(berElement, new string(fmt, 1), ref intPtr);
            try
            {
                if (error == 0 && intPtr != (IntPtr)0)
                {
                    Marshal.PtrToStructure(intPtr, _berval);
                    numArray = new byte[_berval.bv_len];
                    Marshal.Copy(_berval.bv_val, numArray, 0, _berval.bv_len);
                }
            }
            finally
            {
                if (intPtr != (IntPtr)0)
                {
                    Wldap32.ber_bvfree(intPtr);
                }
            }
            return(numArray);
        }
コード例 #3
0
        private static byte[][] DecodingMultiByteArrayHelper(BerSafeHandle berElement, char fmt, ref int error)
        {
            error = 0;
            // several berval
            IntPtr    ptrResult  = IntPtr.Zero;
            int       i          = 0;
            ArrayList binaryList = new ArrayList();
            IntPtr    tempPtr    = IntPtr.Zero;

            byte[][] result = null;

            try
            {
                error = Wldap32.ber_scanf_ptr(berElement, new string(fmt, 1), ref ptrResult);

                if (error == 0)
                {
                    if (ptrResult != IntPtr.Zero)
                    {
                        tempPtr = Marshal.ReadIntPtr(ptrResult);
                        while (tempPtr != IntPtr.Zero)
                        {
                            berval ber = new berval();
                            Marshal.PtrToStructure(tempPtr, ber);

                            byte[] berArray = new byte[ber.bv_len];
                            Marshal.Copy(ber.bv_val, berArray, 0, ber.bv_len);

                            binaryList.Add(berArray);

                            i++;
                            tempPtr = Marshal.ReadIntPtr(ptrResult, i * IntPtr.Size);
                        }

                        result = new byte[binaryList.Count][];
                        for (int j = 0; j < binaryList.Count; j++)
                        {
                            result[j] = (byte[])binaryList[j];
                        }
                    }
                }
                else
                {
                    Debug.WriteLine("ber_scanf for format character 'V' failed");
                }
            }
            finally
            {
                if (ptrResult != IntPtr.Zero)
                {
                    Wldap32.ber_bvecfree(ptrResult);
                }
            }

            return(result);
        }
コード例 #4
0
        private static byte[][] DecodingMultiByteArrayHelper(BerSafeHandle berElement, char fmt, ref int error)
        {
            error = 0;
            IntPtr    zero = IntPtr.Zero;
            int       num  = 0;
            ArrayList list = new ArrayList();
            IntPtr    ptr  = IntPtr.Zero;

            byte[][] bufferArray = null;
            try
            {
                error = Wldap32.ber_scanf_ptr(berElement, new string(fmt, 1), ref zero);
                if ((error != 0) || !(zero != IntPtr.Zero))
                {
                    return(bufferArray);
                }
                for (ptr = Marshal.ReadIntPtr(zero); ptr != IntPtr.Zero; ptr = Marshal.ReadIntPtr(zero, num * Marshal.SizeOf(typeof(IntPtr))))
                {
                    berval structure = new berval();
                    Marshal.PtrToStructure(ptr, structure);
                    byte[] destination = new byte[structure.bv_len];
                    Marshal.Copy(structure.bv_val, destination, 0, structure.bv_len);
                    list.Add(destination);
                    num++;
                }
                bufferArray = new byte[list.Count][];
                for (int i = 0; i < list.Count; i++)
                {
                    bufferArray[i] = (byte[])list[i];
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    Wldap32.ber_bvecfree(zero);
                }
            }
            return(bufferArray);
        }
コード例 #5
0
        private static byte[] DecodingByteArrayHelper(BerSafeHandle berElement, char fmt, ref int error)
        {
            error = 0;
            IntPtr result      = IntPtr.Zero;
            berval binaryValue = new berval();

            byte[] byteArray = null;

            // can't use SafeBerval here as CLR creates a SafeBerval which points to a different memory location, but when doing memory
            // deallocation, wldap has special check. So have to use IntPtr directly here.
            error = Wldap32.ber_scanf_ptr(berElement, new string(fmt, 1), ref result);

            try
            {
                if (error == 0)
                {
                    if (result != IntPtr.Zero)
                    {
                        Marshal.PtrToStructure(result, binaryValue);

                        byteArray = new byte[binaryValue.bv_len];
                        Marshal.Copy(binaryValue.bv_val, byteArray, 0, binaryValue.bv_len);
                    }
                }
                else
                {
                    Debug.WriteLine("ber_scanf for format character 'O' failed");
                }
            }
            finally
            {
                if (result != IntPtr.Zero)
                {
                    Wldap32.ber_bvfree(result);
                }
            }

            return(byteArray);
        }
コード例 #6
0
ファイル: BerConverter.cs プロジェクト: modulexcite/pash-1
        private static byte[][] DecodingMultiByteArrayHelper(BerSafeHandle berElement, char fmt, ref int error)
        {
            error = 0;
            IntPtr    intPtr     = (IntPtr)0;
            int       num        = 0;
            ArrayList arrayLists = new ArrayList();

            byte[][] item = null;
            try
            {
                error = Wldap32.ber_scanf_ptr(berElement, new string(fmt, 1), ref intPtr);
                if (error == 0 && intPtr != (IntPtr)0)
                {
                    for (IntPtr i = Marshal.ReadIntPtr(intPtr); i != (IntPtr)0; i = Marshal.ReadIntPtr(intPtr, num * Marshal.SizeOf(typeof(IntPtr))))
                    {
                        berval _berval = new berval();
                        Marshal.PtrToStructure(i, _berval);
                        byte[] numArray = new byte[_berval.bv_len];
                        Marshal.Copy(_berval.bv_val, numArray, 0, _berval.bv_len);
                        arrayLists.Add(numArray);
                        num++;
                    }
                    item = new byte[arrayLists.Count][];
                    for (int j = 0; j < arrayLists.Count; j++)
                    {
                        item[j] = (byte[])arrayLists[j];
                    }
                }
            }
            finally
            {
                if (intPtr != (IntPtr)0)
                {
                    Wldap32.ber_bvecfree(intPtr);
                }
            }
            return(item);
        }