Exemplo n.º 1
0
    public bool PosTest1()
    {
        bool retVal = true;

        const string c_TEST_ID = "P001";
        const string c_TEST_DESC = "PosTest1: random valid UInt64 value";
        string errorDesc;

        UIntPtr actualUIntPtr;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            UInt64 ui = this.GetValidUInt64();
            actualUIntPtr = new UIntPtr(ui);

            actualResult = actualUIntPtr.ToUInt64() == ui;

            if (!actualResult)
            {
                errorDesc = "Actual UIntPtr value is not " + ui + " as expected: Actual(" + actualUIntPtr + ")";
                TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
Exemplo n.º 2
0
        /// <summary>
        /// Reads a 2 byte value from an address and moves the address.
        /// </summary>
        /// <param name="code">address, module + pointer + offset, module + offset OR label in .ini file.</param>
        /// <param name="moveQty">Quantity to move.</param>
        /// <param name="file">path and name of ini file (OPTIONAL)</param>
        /// <returns></returns>
        public int Read2ByteMove(string code, int moveQty, string file = "")
        {
            byte[]  memory  = new byte[4];
            UIntPtr theCode = GetCode(code, file);

            if (theCode == null || theCode == UIntPtr.Zero || theCode.ToUInt64() < 0x10000)
            {
                return(0);
            }

            UIntPtr newCode = UIntPtr.Add(theCode, moveQty);

            if (ReadProcessMemory(mProc.Handle, newCode, memory, (UIntPtr)2, IntPtr.Zero))
            {
                return(BitConverter.ToInt32(memory, 0));
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 3
0
        internal static EntryInfo[] GetEntries(string prefix, NtType types)
        {
            UIntPtr size;

            byte[]  str           = CreateUTF8String(prefix, out size);
            UIntPtr arrSize       = UIntPtr.Zero;
            IntPtr  arr           = Interop.NT_GetEntryInfo(str, size, (uint)types, ref arrSize);
            int     entryInfoSize = Marshal.SizeOf(typeof(NtEntryInfo));
            int     arraySize     = (int)arrSize.ToUInt64();

            EntryInfo[] entryArray = new EntryInfo[arraySize];

            for (int i = 0; i < arraySize; i++)
            {
                IntPtr      data = new IntPtr(arr.ToInt64() + entryInfoSize * i);
                NtEntryInfo info = (NtEntryInfo)Marshal.PtrToStructure(data, typeof(NtEntryInfo));
                entryArray[i] = new EntryInfo(info.name.ToString(), info.type, (EntryFlags)info.flags, (long)info.last_change);
            }
            Interop.NT_DisposeEntryInfoArray(arr, arrSize);
            return(entryArray);
        }
        public IntPtr Allocate(UIntPtr sizeInBytes)
        {
            IntPtr nativePointer;
            ulong  size = sizeInBytes.ToUInt64();

            try
            {
                CompressedDataState state = new CompressedDataState(size);
                this.compressedData.Add(state);

                nativePointer = state.NativePointer;
            }
            catch (Exception ex)
            {
                this.ExceptionInfo = ExceptionDispatchInfo.Capture(ex);

                return(IntPtr.Zero);
            }

            return(nativePointer);
        }
Exemplo n.º 5
0
        public void Prepare(string commandText)
        {
            int status = 0;

            if (this.disposed)
            {
                throw new InvalidOperationException("StatementHandle is already disposed.");
            }

            ulong rsize = 0;

            byte [] buffer;

            UIntPtr rsizep = new UIntPtr(rsize);

            // Get size of buffer
            OciCalls.OCIUnicodeToCharSet(Parent, null, commandText, ref rsizep);
            rsize = rsizep.ToUInt64();

            //rsize = Encoding.UTF8.GetMaxByteCount (commandText.Length+1);

            // Fill buffer
            buffer = new byte[rsize];

            OciCalls.OCIUnicodeToCharSet(Parent, buffer, commandText, ref rsizep);

            // Execute statement
            status = OciCalls.OCIStmtPrepare(this,
                                             ErrorHandle,
                                             buffer,
                                             buffer.Length,
                                             OciStatementLanguage.NTV,
                                             OciStatementMode.Default);

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemplo n.º 6
0
        public static void SendClientMessage(UIntPtr display, UIntPtr window, UIntPtr messageType, UIntPtr message, IntPtr data = default)
        {
            var clientEvent = new XClientMessageEvent {
                type         = ClientMessage,
                serial       = UIntPtr.Zero,
                send_event   = True,
                display      = display,
                window       = window,
                message_type = messageType,
                format       = 32
            };

            if (Environment.Is64BitProcess)
            {
                var messageBits = message.ToUInt64();
                clientEvent.data.l[0] = unchecked ((IntPtr)(uint)messageBits);
                clientEvent.data.l[1] = (IntPtr)(uint)(messageBits >> 32);
                Assert(clientEvent.data.l[1] == IntPtr.Zero, Resources.ArgumentOutOfRangeExceptionMessage, nameof(message), message);

                var dataBits = data.ToInt64();
                clientEvent.data.l[2] = unchecked ((IntPtr)(uint)dataBits);
                clientEvent.data.l[3] = (IntPtr)(uint)(dataBits >> 32);
            }
            else
            {
                var messageBits = message.ToUInt32();
                clientEvent.data.l[0] = (IntPtr)messageBits;

                var dataBits = data.ToInt32();
                clientEvent.data.l[1] = (IntPtr)dataBits;
            }

            ThrowExternalExceptionIfZero(nameof(XSendEvent), XSendEvent(
                                             clientEvent.display,
                                             clientEvent.window,
                                             propagate: False,
                                             (IntPtr)NoEventMask,
                                             (XEvent *)&clientEvent
                                             ));
        }
Exemplo n.º 7
0
        public byte[] ReadRamLittleEndian(UIntPtr address, int length, bool absoluteAddress = false)
        {
            byte[] readBytes = new byte[length];
            uint   localAddress;

            if (absoluteAddress)
            {
                localAddress = (uint)(address.ToUInt64() - (ulong)ProcessMemoryOffset.ToInt64());
            }
            else
            {
                localAddress = ConvertAddressEndianess(address.ToUInt32() & ~0x80000000, length);
            }

            if (localAddress + length > _ram.Length)
            {
                return(new byte[length]);
            }

            Buffer.BlockCopy(_ram, (int)localAddress, readBytes, 0, length);
            return(readBytes);
        }
Exemplo n.º 8
0
        private UIntPtr OnAiFileReadProc(IntPtr file, IntPtr dataRead, UIntPtr sizeOfElemInBytes, UIntPtr numElements)
        {
            if (m_filePtr != file)
            {
                return(UIntPtr.Zero);
            }

            long longSize = (long)sizeOfElemInBytes.ToUInt64();
            long longNum  = (long)numElements.ToUInt64();
            long count    = longSize * longNum;

            byte[] byteBuffer = GetByteBuffer(longSize, longNum);

            long actualCount = 0;

            try {
                actualCount = Read(byteBuffer, count);
                MemoryHelper.Write <byte>(dataRead, byteBuffer, 0, (int)actualCount);
            } catch (Exception) { /*Assimp will report an IO error*/ }

            return(new UIntPtr((ulong)actualCount));
        }
Exemplo n.º 9
0
        internal static void InternalOnDataReceived(
            IntPtr room, IntPtr participant, IntPtr data, UIntPtr dataLength, bool isReliable,
            IntPtr userData)
        {
            Logger.d("Entering InternalOnDataReceived: " + userData.ToInt64());

            var callback = Callbacks.IntPtrToPermanentCallback
                           <Action <NativeRealTimeRoom, MultiplayerParticipant, byte[], bool> >(userData);

            using (var nativeRoom = NativeRealTimeRoom.FromPointer(room))
            {
                using (var nativeParticipant = MultiplayerParticipant.FromPointer(participant))
                {
                    if (callback == null)
                    {
                        return;
                    }

                    byte[] convertedData = null;

                    if (dataLength.ToUInt64() != 0)
                    {
                        convertedData = new byte[dataLength.ToUInt32()];
                        Marshal.Copy(data, convertedData, 0, (int)dataLength.ToUInt32());
                    }

                    try
                    {
                        callback(nativeRoom, nativeParticipant, convertedData, isReliable);
                    }
                    catch (Exception e)
                    {
                        Logger.e("Error encountered executing InternalOnDataReceived. " +
                                 "Smothering to avoid passing exception into Native: " + e);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public unsafe KernelObjectData[] EnumJobs()
        {
            int returned;

            if (!_initialized)
            {
                var symbol = new SymbolInfo();
                symbol.Init();
                if (_symbolHandler.GetSymbolFromName("PspGetNextJob", ref symbol))
                {
                    var offset = symbol.Address - _ntoskrnlBase;
                    Debug.Assert(_kernelAddress != UIntPtr.Zero);

                    var functions = new KernelFunctions {
                        PspGetNextJob = new UIntPtr(_kernelAddress.ToUInt64() + offset)
                    };
                    _initialized = DeviceIoControl(_hDevice, KExploreInitFunctions, ref functions, Marshal.SizeOf <KernelFunctions>(),
                                                   IntPtr.Zero, 0, out returned);
                }
            }
            if (!_initialized)
            {
                throw new InvalidOperationException("Failed to locate symbols");
            }

            var jobs   = new KernelObjectData[2048];                 // unlikely to be more... (famous last words)
            var access = (int)JobAccessMask.Query;

            if (DeviceIoControl(_hDevice, KExploreEnumJobs,
                                ref access, sizeof(int),
                                ref jobs[0], jobs.Length * Marshal.SizeOf <KernelObjectData>(), out returned))
            {
                Array.Resize(ref jobs, returned / Marshal.SizeOf <KernelObjectData>());
                return(jobs);
            }

            return(null);
        }
Exemplo n.º 11
0
        internal static List <EntryInfo> GetEntryInfo(string prefix, NtType types)
        {
            byte[]  str     = CreateUTF8String(prefix);
            UIntPtr arrSize = UIntPtr.Zero;
            IntPtr  arr     = Interop.NT_GetEntryInfo(str, (UIntPtr)(str.Length - 1), (uint)types, ref arrSize);

#pragma warning disable CS0618
            int entryInfoSize = Marshal.SizeOf(typeof(NtEntryInfo));
#pragma warning restore CS0618
            int arraySize = (int)arrSize.ToUInt64();
            List <EntryInfo> entryArray = new List <EntryInfo>(arraySize);

            for (int i = 0; i < arraySize; i++)
            {
                IntPtr data = new IntPtr(arr.ToInt64() + entryInfoSize * i);
#pragma warning disable CS0618
                NtEntryInfo info = (NtEntryInfo)Marshal.PtrToStructure(data, typeof(NtEntryInfo));
#pragma warning restore CS0618
                entryArray.Add(new EntryInfo(info.name.ToString(), info.type, (EntryFlags)info.flags, (long)info.last_change));
            }
            Interop.NT_DisposeEntryInfoArray(arr, arrSize);
            return(entryArray);
        }
Exemplo n.º 12
0
        internal static List <ConnectionInfo> GetConnections()
        {
            UIntPtr count       = UIntPtr.Zero;
            IntPtr  connections = Interop.NT_GetConnections(ref count);

#pragma warning disable CS0618
            int connectionInfoSize = Marshal.SizeOf(typeof(NtConnectionInfo));
#pragma warning restore CS0618
            int arraySize = (int)count.ToUInt64();

            List <ConnectionInfo> connectionsArray = new List <ConnectionInfo>(arraySize);

            for (int i = 0; i < arraySize; i++)
            {
                IntPtr data = new IntPtr(connections.ToInt64() + connectionInfoSize * i);
#pragma warning disable CS0618
                var con = (NtConnectionInfo)Marshal.PtrToStructure(data, typeof(NtConnectionInfo));
#pragma warning restore CS0618
                connectionsArray.Add(new ConnectionInfo(con.RemoteId.ToString(), ReadUTF8String(con.RemoteIp), (int)con.RemotePort, (long)con.LastUpdate, (int)con.ProtocolVersion));
            }
            Interop.NT_DisposeConnectionInfoArray(connections, count);
            return(connectionsArray);
        }
Exemplo n.º 13
0
    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID   = "P002";
        const string c_TEST_DESC = "PosTest2: UIntPtr with a random value between 0 and UInt32.MaxValue";
        string       errorDesc;

        UInt64  actualUI, expectedUI;
        UIntPtr uiPtr;
        bool    actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            expectedUI = this.GetUInt64() % ((UInt64)UInt32.MaxValue + 1);
            uiPtr      = new UIntPtr(expectedUI);
            actualUI   = uiPtr.ToUInt64();

            actualResult = actualUI == expectedUI;
            if (!actualResult)
            {
                errorDesc = "Actual UInt32 from UIntPtr is not " + expectedUI + " as expected: Actual(" + actualUI + ")";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return(retVal);
    }
Exemplo n.º 14
0
        /// <summary>
        /// Read a string value from an address.
        /// </summary>
        /// <param name="code">address, module + pointer + offset, module + offset OR label in .ini file.</param>
        /// <param name="file">path and name of ini file. (OPTIONAL)</param>
        /// <param name="length">length of bytes to read (OPTIONAL)</param>
        /// <param name="zeroTerminated">terminate string at null char</param>
        /// <param name="stringEncoding">System.Text.Encoding.UTF8 (DEFAULT). Other options: ascii, unicode, utf32, utf7</param>
        /// <returns></returns>
        public string ReadString(string code, string file = "", int length = 32, bool zeroTerminated = true, System.Text.Encoding stringEncoding = null)
        {
            if (stringEncoding == null)
            {
                stringEncoding = System.Text.Encoding.UTF8;
            }

            byte[]  memoryNormal = new byte[length];
            UIntPtr theCode      = GetCode(code, file);

            if (theCode == null || theCode == UIntPtr.Zero || theCode.ToUInt64() < 0x10000)
            {
                return("");
            }

            if (ReadProcessMemory(mProc.Handle, theCode, memoryNormal, (UIntPtr)length, IntPtr.Zero))
            {
                return((zeroTerminated) ? stringEncoding.GetString(memoryNormal).Split('\0')[0] : stringEncoding.GetString(memoryNormal));
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 15
0
        private int Read(IntPtr data, UIntPtr size, IntPtr userData)
        {
            if (data == IntPtr.Zero)
            {
                return(Failure);
            }

            ulong count = size.ToUInt64();

            if (count == 0)
            {
                return(Success);
            }

            try
            {
                return(ReadCore(data, checked ((long)count)) ? Success : Failure);
            }
            catch (Exception ex)
            {
                this.CallbackExceptionInfo = ExceptionDispatchInfo.Capture(ex);
                return(Failure);
            }
        }
Exemplo n.º 16
0
    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID   = "P002";
        const string c_TEST_DESC = "PosTest2: value is UInt64.MinValue"; // that is 0

        string errorDesc;

        UIntPtr actualUIntPtr;
        bool    actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            UInt64 ui = UInt64.MinValue;
            actualUIntPtr = new UIntPtr(ui);

            actualResult = actualUIntPtr.ToUInt64() == ui;

            if (!actualResult)
            {
                errorDesc = "Actual UIntPtr value is not " + ui + " as expected: Actual(" + actualUIntPtr + ")";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return(retVal);
    }
Exemplo n.º 17
0
    private static void VerifyPointer(UIntPtr ptr, ulong expected)
    {
        Assert.Equal(expected, ptr.ToUInt64());

        uint expected32 = (uint)expected;

        if (expected32 != expected)
        {
            Assert.Throws <OverflowException>(() => ptr.ToUInt32());
            return;
        }

        Assert.Equal(expected32, ptr.ToUInt32());

        Assert.Equal(expected.ToString(), ptr.ToString());

        Assert.Equal(ptr, new UIntPtr(expected));
        Assert.True(ptr == new UIntPtr(expected));
        Assert.False(ptr != new UIntPtr(expected));

        Assert.NotEqual(ptr, new UIntPtr(expected + 1));
        Assert.False(ptr == new UIntPtr(expected + 1));
        Assert.True(ptr != new UIntPtr(expected + 1));
    }
Exemplo n.º 18
0
    public bool PosTest3()
    {
        bool retVal = true;

        const string c_TEST_ID = "P003";
        string       testDesc  = string.Format("PosTest3: value is UInt{0}.MaxValue", 8 * UIntPtr.Size);

        string errorDesc;

        UIntPtr actualUIntPtr;
        bool    actualResult;

        TestLibrary.TestFramework.BeginScenario(testDesc);
        try
        {
            UInt64 ui = (UIntPtr.Size == 4) ? UInt32.MaxValue : UInt64.MaxValue;
            actualUIntPtr = new UIntPtr(ui);

            actualResult = actualUIntPtr.ToUInt64() == ui;

            if (!actualResult)
            {
                errorDesc = "Actual UIntPtr value is not " + ui + " as expected: Actual(" + actualUIntPtr + ")";
                TestLibrary.TestFramework.LogError("005" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("006" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return(retVal);
    }
Exemplo n.º 19
0
    private static void VerifyPointer(UIntPtr ptr, ulong expected)
    {
        Assert.Equal(expected, ptr.ToUInt64());

        uint expected32 = (uint)expected;
        if (expected32 != expected)
        {
            Assert.Throws<OverflowException>(() => ptr.ToUInt32());
            return;
        }

        Assert.Equal(expected32, ptr.ToUInt32());

        Assert.Equal(expected.ToString(), ptr.ToString());

        Assert.Equal(ptr, new UIntPtr(expected));
        Assert.True(ptr == new UIntPtr(expected));
        Assert.False(ptr != new UIntPtr(expected));

        Assert.NotEqual(ptr, new UIntPtr(expected + 1));
        Assert.False(ptr == new UIntPtr(expected + 1));
        Assert.True(ptr != new UIntPtr(expected + 1));
    }
Exemplo n.º 20
0
 public override string ToString()
 {
     byte[] arr = new byte[len.ToUInt64()];
     Marshal.Copy(str, arr, 0, (int)len.ToUInt64());
     return(Encoding.UTF8.GetString(arr));
 }
Exemplo n.º 21
0
    private static void TestPointer(UIntPtr p, ulong expected)
    {
        ulong l = p.ToUInt64();
        Assert.Equal(expected, l);

        uint expected32 = (uint)expected;
        if (expected32 != expected)
        {
            Assert.Throws<OverflowException>(() => p.ToUInt32());
            return;
        }

        {
            uint i = p.ToUInt32();
            Assert.Equal(expected32, i);
        }

        string s = p.ToString();
        string sExpected = expected.ToString();
        Assert.Equal(s, sExpected);

        Assert.True(p == new UIntPtr(expected));
        Assert.Equal(p, new UIntPtr(expected));
        Assert.False(p == new UIntPtr(expected + 1));
        Assert.NotEqual(p, new UIntPtr(expected + 1));
        Assert.False(p != new UIntPtr(expected));
        Assert.True(p != new UIntPtr(expected + 1));
    }
Exemplo n.º 22
0
        public int tag_inventory(
            PARAMETERS invenParams,
            UIntPtr hreader,
            Byte AIType,
            Byte AntennaSelCount,
            Byte[] AntennaSel,
            out List <UhfInventoryItem> results,
            // delegate_tag_report_handle tagReportHandler,
            ref UInt32 nTagCount)
        {
            results = new List <UhfInventoryItem>();

            int     iret;
            UIntPtr InvenParamSpecList = UIntPtr.Zero;

            InvenParamSpecList = RFIDLIB.rfidlib_reader.RDR_CreateInvenParamSpecList();
            if (InvenParamSpecList.ToUInt64() != 0)
            {
                /* set timeout */
                RFIDLIB.rfidlib_reader.RDR_SetInvenStopTrigger(InvenParamSpecList, RFIDLIB.rfidlib_def.INVEN_STOP_TRIGGER_TYPE_TIMEOUT, invenParams.m_timeout, 0);
                /* create ISO18000p6C air protocol inventory parameters */
                UIntPtr AIPIso18000p6c = RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_CreateInvenParam(InvenParamSpecList, 0, 0, RFIDLIB.rfidlib_def.ISO18000p6C_S0, RFIDLIB.rfidlib_def.ISO18000p6C_TARGET_A, RFIDLIB.rfidlib_def.ISO18000p6C_Dynamic_Q);
                if (AIPIso18000p6c.ToUInt64() != 0)
                {
                    //set selection parameters
                    if (invenParams.m_sel.m_enable)
                    {
                        Byte[] maskBits = invenParams.m_sel.m_maskBits.ToArray();
                        RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_SetInvenSelectParam(AIPIso18000p6c, invenParams.m_sel.m_target, invenParams.m_sel.m_action, invenParams.m_sel.m_memBank, invenParams.m_sel.m_pointer, maskBits, invenParams.m_sel.m_maskBitsLength, 0);
                    }
                    // set inventory read parameters
                    if (invenParams.m_read.m_enable)
                    {
                        RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_SetInvenReadParam(AIPIso18000p6c, invenParams.m_read.m_memBank, invenParams.m_read.m_wordPtr, (Byte)invenParams.m_read.m_wordCnt);
                    }

                    // Add Embedded commands
                    if (invenParams.m_write.m_enable)
                    {
                        Byte[] writeDatas = invenParams.m_write.m_datas.ToArray();

                        RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_CreateTAWrite(AIPIso18000p6c, invenParams.m_write.m_memBank, invenParams.m_write.m_wordPtr, invenParams.m_write.m_wordCnt, writeDatas, (UInt32)writeDatas.Length);
                    }

                    if (invenParams.m_lock.m_enable)
                    {
                        UInt16 mask, action;
                        mask = action = 0;
                        if (invenParams.m_lock.m_userMemSelected)
                        {
                            mask   |= 0x03;
                            action |= (UInt16)(invenParams.m_lock.m_userMem);
                        }
                        if (invenParams.m_lock.m_TIDMemSelected)
                        {
                            mask   |= (0x03 << 2);
                            action |= (UInt16)(invenParams.m_lock.m_TIDMem << 2);
                        }
                        if (invenParams.m_lock.m_EPCMemSelected)
                        {
                            mask   |= (0x03 << 4);
                            action |= (UInt16)(invenParams.m_lock.m_EPCMem << 4);
                        }
                        if (invenParams.m_lock.m_accessPwdSelected)
                        {
                            mask   |= (0x03 << 6);
                            action |= (UInt16)(invenParams.m_lock.m_accessPwd << 6);
                        }
                        if (invenParams.m_lock.m_killPwdSelected)
                        {
                            mask   |= (0x03 << 8);
                            action |= (UInt16)(invenParams.m_lock.m_killPwd << 8);
                        }

                        RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_CreateTALock(AIPIso18000p6c, mask, action);
                    }
                    // set meta flags
                    if (invenParams.m_metaFlags.m_enable)
                    {
                        UInt32 metaFlags = 0;
                        if (invenParams.m_metaFlags.m_EPC)
                        {
                            metaFlags |= RFIDLIB.rfidlib_def.ISO18000p6C_META_BIT_MASK_EPC;
                        }
                        if (invenParams.m_metaFlags.m_timestamp)
                        {
                            metaFlags |= RFIDLIB.rfidlib_def.ISO18000P6C_META_BIT_MASK_TIMESTAMP;
                        }
                        if (invenParams.m_metaFlags.m_frequency)
                        {
                            metaFlags |= RFIDLIB.rfidlib_def.ISO18000P6C_META_BIT_MASK_FREQUENCY;
                        }
                        if (invenParams.m_metaFlags.m_RSSI)
                        {
                            metaFlags |= RFIDLIB.rfidlib_def.ISO18000p6C_META_BIT_MASK_RSSI;
                        }
                        if (invenParams.m_metaFlags.m_readCnt)
                        {
                            metaFlags |= RFIDLIB.rfidlib_def.ISO18000P6C_META_BIT_MASK_READCOUNT;
                        }
                        if (invenParams.m_metaFlags.m_tagData)
                        {
                            metaFlags |= RFIDLIB.rfidlib_def.ISO18000P6C_META_BIT_MASK_TAGDATA;
                        }
                        RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_SetInvenMetaDataFlags(AIPIso18000p6c, metaFlags);
                    }
                    // set access password
                    if (invenParams.m_read.m_enable || invenParams.m_write.m_enable || invenParams.m_lock.m_enable)
                    {
                        RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_SetInvenAccessPassword(AIPIso18000p6c, invenParams.m_accessPwd);
                    }
                }
            }
            nTagCount = 0;
LABEL_TAG_INVENTORY:
            iret = RFIDLIB.rfidlib_reader.RDR_TagInventory(hreader, AIType, AntennaSelCount, AntennaSel, InvenParamSpecList);
            if (iret == 0 || iret == -21)
            {
                nTagCount += RFIDLIB.rfidlib_reader.RDR_GetTagDataReportCount(hreader);
                UIntPtr TagDataReport;
                TagDataReport = (UIntPtr)0;
                TagDataReport = RFIDLIB.rfidlib_reader.RDR_GetTagDataReport(hreader, RFIDLIB.rfidlib_def.RFID_SEEK_FIRST); //first
                while (TagDataReport.ToUInt64() > 0)
                {
                    UInt32 aip_id    = 0;
                    UInt32 tag_id    = 0;
                    UInt32 ant_id    = 0;
                    Byte[] tagData   = new Byte[256];
                    UInt32 nSize     = (UInt32)tagData.Length;
                    UInt32 metaFlags = 0;

                    iret = RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_ParseTagReport(TagDataReport, ref aip_id, ref tag_id, ref ant_id, ref metaFlags, tagData, ref nSize);
                    if (iret == 0)
                    {
                        String writeOper = "";
                        String lockOper  = "";
                        if (invenParams.m_write.m_enable)
                        {
                            iret = RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_CheckTAWriteResult(TagDataReport);
                            if (iret != 0)
                            {
                                writeOper = "fail";
                            }
                            else
                            {
                                writeOper = "success";
                            }
                        }
                        if (invenParams.m_lock.m_enable)
                        {
                            iret = RFIDLIB.rfidlib_aip_iso18000p6C.ISO18000p6C_CheckTALockResult(TagDataReport);
                            if (iret != 0)
                            {
                                lockOper = "fail";
                            }
                            else
                            {
                                lockOper = "success";
                            }
                        }

                        /*
                         * object[] pList = { aip_id, tag_id, ant_id, metaFlags, tagData, nSize, writeOper, lockOper };
                         * Invoke(tagReportHandler, pList);
                         */
                        results.Add(new UhfInventoryItem
                        {
                            aip_id    = aip_id,
                            tag_id    = tag_id,
                            ant_id    = ant_id,
                            metaFlags = metaFlags,
                            tagData   = tagData,
                            nSize     = nSize,
                            writeOper = writeOper,
                            lockOper  = lockOper
                        });
                    }

                    // TODO: 观察读到的 bank 数据
                    // invenParams.m_read.m_wordPtr, (Byte)invenParams.m_read.m_wordCnt);


                    TagDataReport = RFIDLIB.rfidlib_reader.RDR_GetTagDataReport(hreader, RFIDLIB.rfidlib_def.RFID_SEEK_NEXT); //next
                }
                if (iret == -21)                                                                                              // stop trigger occur,need to inventory left tags
                {
                    AIType = RFIDLIB.rfidlib_def.AI_TYPE_CONTINUE;                                                            //use only-new-tag inventory
                    goto LABEL_TAG_INVENTORY;
                }
                iret = 0;
            }
            if (InvenParamSpecList.ToUInt64() != 0)
            {
                RFIDLIB.rfidlib_reader.DNODE_Destroy(InvenParamSpecList);
            }
            return(iret);
        }
Exemplo n.º 23
0
 public void PushUIntPtr(UIntPtr i)
 {
     PushUInt64(i.ToUInt64());
 }
Exemplo n.º 24
0
        public override void EnumCodeContextsOfPosition(UIntPtr sourceContext, uint offset, uint length, out IEnumDebugCodeContexts enumContexts)
        {
            var del = RawCOMHelpers.GetMethodDelegate <RawEnumCodeContextsOfPosition>(pActiveScriptDebug, 5);

            RawCOMHelpers.HResult.Check(del(pActiveScriptDebug, sourceContext.ToUInt64(), offset, length, out enumContexts));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Array of Byte scan.
        /// </summary>
        /// <param name="start">Your starting address.</param>
        /// <param name="end">ending address</param>
        /// <param name="search">array of bytes to search for, OR your ini code label.</param>
        /// <param name="file">ini file (OPTIONAL)</param>
        /// <param name="readable">Include readable addresses in scan</param>
        /// <param name="writable">Include writable addresses in scan</param>
        /// <param name="executable">Include executable addresses in scan</param>
        /// <returns>IEnumerable of all addresses found.</returns>
        public Task <IEnumerable <long> > AoBScan(long start, long end, string search, bool readable, bool writable, bool executable, string file = "")
        {
            return(Task.Run(() =>
            {
                var memRegionList = new List <MemoryRegionResult>();

                string memCode = LoadCode(search, file);

                string[] stringByteArray = memCode.Split(' ');

                byte[] aobPattern = new byte[stringByteArray.Length];
                byte[] mask = new byte[stringByteArray.Length];

                for (var i = 0; i < stringByteArray.Length; i++)
                {
                    string ba = stringByteArray[i];

                    if (ba == "??" || (ba.Length == 1 && ba == "?"))
                    {
                        mask[i] = 0x00;
                        stringByteArray[i] = "0x00";
                    }
                    else if (Char.IsLetterOrDigit(ba[0]) && ba[1] == '?')
                    {
                        mask[i] = 0xF0;
                        stringByteArray[i] = ba[0] + "0";
                    }
                    else if (Char.IsLetterOrDigit(ba[1]) && ba[0] == '?')
                    {
                        mask[i] = 0x0F;
                        stringByteArray[i] = "0" + ba[1];
                    }
                    else
                    {
                        mask[i] = 0xFF;
                    }
                }


                for (int i = 0; i < stringByteArray.Length; i++)
                {
                    aobPattern[i] = (byte)(Convert.ToByte(stringByteArray[i], 16) & mask[i]);
                }

                SYSTEM_INFO sys_info = new SYSTEM_INFO();
                GetSystemInfo(out sys_info);

                UIntPtr proc_min_address = sys_info.minimumApplicationAddress;
                UIntPtr proc_max_address = sys_info.maximumApplicationAddress;

                if (start < (long)proc_min_address.ToUInt64())
                {
                    start = (long)proc_min_address.ToUInt64();
                }

                if (end > (long)proc_max_address.ToUInt64())
                {
                    end = (long)proc_max_address.ToUInt64();
                }

                Debug.WriteLine("[DEBUG] memory scan starting... (start:0x" + start.ToString(MSize()) + " end:0x" + end.ToString(MSize()) + " time:" + DateTime.Now.ToString("h:mm:ss tt") + ")");
                UIntPtr currentBaseAddress = new UIntPtr((ulong)start);

                MEMORY_BASIC_INFORMATION memInfo = new MEMORY_BASIC_INFORMATION();

                //Debug.WriteLine("[DEBUG] start:0x" + start.ToString("X8") + " curBase:0x" + currentBaseAddress.ToUInt64().ToString("X8") + " end:0x" + end.ToString("X8") + " size:0x" + memInfo.RegionSize.ToString("X8") + " vAloc:" + VirtualQueryEx(mProc.Handle, currentBaseAddress, out memInfo).ToUInt64().ToString());

                while (VirtualQueryEx(mProc.Handle, currentBaseAddress, out memInfo).ToUInt64() != 0 &&
                       currentBaseAddress.ToUInt64() < (ulong)end &&
                       currentBaseAddress.ToUInt64() + (ulong)memInfo.RegionSize >
                       currentBaseAddress.ToUInt64())
                {
                    bool isValid = memInfo.State == MEM_COMMIT;
                    isValid &= memInfo.BaseAddress.ToUInt64() < (ulong)proc_max_address.ToUInt64();
                    isValid &= ((memInfo.Protect & PAGE_GUARD) == 0);
                    isValid &= ((memInfo.Protect & PAGE_NOACCESS) == 0);
                    isValid &= (memInfo.Type == MEM_PRIVATE) || (memInfo.Type == MEM_IMAGE);

                    if (isValid)
                    {
                        bool isReadable = (memInfo.Protect & PAGE_READONLY) > 0;

                        bool isWritable = ((memInfo.Protect & PAGE_READWRITE) > 0) ||
                                          ((memInfo.Protect & PAGE_WRITECOPY) > 0) ||
                                          ((memInfo.Protect & PAGE_EXECUTE_READWRITE) > 0) ||
                                          ((memInfo.Protect & PAGE_EXECUTE_WRITECOPY) > 0);

                        bool isExecutable = ((memInfo.Protect & PAGE_EXECUTE) > 0) ||
                                            ((memInfo.Protect & PAGE_EXECUTE_READ) > 0) ||
                                            ((memInfo.Protect & PAGE_EXECUTE_READWRITE) > 0) ||
                                            ((memInfo.Protect & PAGE_EXECUTE_WRITECOPY) > 0);

                        isReadable &= readable;
                        isWritable &= writable;
                        isExecutable &= executable;

                        isValid &= isReadable || isWritable || isExecutable;
                    }

                    if (!isValid)
                    {
                        currentBaseAddress = new UIntPtr(memInfo.BaseAddress.ToUInt64() + (ulong)memInfo.RegionSize);
                        continue;
                    }

                    MemoryRegionResult memRegion = new MemoryRegionResult
                    {
                        CurrentBaseAddress = currentBaseAddress,
                        RegionSize = memInfo.RegionSize,
                        RegionBase = memInfo.BaseAddress
                    };

                    currentBaseAddress = new UIntPtr(memInfo.BaseAddress.ToUInt64() + (ulong)memInfo.RegionSize);

                    //Console.WriteLine("SCAN start:" + memRegion.RegionBase.ToString() + " end:" + currentBaseAddress.ToString());

                    if (memRegionList.Count > 0)
                    {
                        var previousRegion = memRegionList[memRegionList.Count - 1];

                        if ((long)previousRegion.RegionBase + previousRegion.RegionSize == (long)memInfo.BaseAddress)
                        {
                            memRegionList[memRegionList.Count - 1] = new MemoryRegionResult
                            {
                                CurrentBaseAddress = previousRegion.CurrentBaseAddress,
                                RegionBase = previousRegion.RegionBase,
                                RegionSize = previousRegion.RegionSize + memInfo.RegionSize
                            };

                            continue;
                        }
                    }

                    memRegionList.Add(memRegion);
                }

                ConcurrentBag <long> bagResult = new ConcurrentBag <long>();

                Parallel.ForEach(memRegionList,
                                 (item, parallelLoopState, index) =>
                {
                    long[] compareResults = CompareScan(item, aobPattern, mask);

                    foreach (long result in compareResults)
                    {
                        bagResult.Add(result);
                    }
                });

                Debug.WriteLine("[DEBUG] memory scan completed. (time:" + DateTime.Now.ToString("h:mm:ss tt") + ")");

                return bagResult.ToList().OrderBy(c => c).AsEnumerable();
            }));
        }
Exemplo n.º 26
0
 public override void ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo)
 {
     activeScriptParse.ParseScriptText(code, itemName, context, delimiter, sourceContext.ToUInt64(), startingLineNumber, flags, pVarResult, out excepInfo);
 }
Exemplo n.º 27
0
 /// <summary>Retrieves the low-order word from the specified 32-bit value.</summary>
 /// <param name="dwValue">The value to be converted.</param>
 /// <returns>The return value is the low-order word of the specified value.</returns>
 public static ushort LOWORD(UIntPtr dwValue) => LOWORD((uint)dwValue.ToUInt64());
Exemplo n.º 28
0
 public static ulong AsLong(this UIntPtr thisValue)
 {
     return(thisValue.ToUInt64());
 }
Exemplo n.º 29
0
    private static void TestPointer(UIntPtr p, ulong expected)
    {
        ulong l = p.ToUInt64();
        Assert.Equal(l, expected);

        uint expected32 = (uint)expected;
        if (expected32 != expected)
        {
            try
            {
                uint i = p.ToUInt32();
                Assert.True(false, "ToUInt32() should have thrown.");
            }
            catch (OverflowException)
            {
            }
            return;
        }

        {
            uint i = p.ToUInt32();
            Assert.Equal(i, expected32);
        }

        String s = p.ToString();
        String sExpected = expected.ToString();
        Assert.Equal(s, sExpected);

        bool b;

        b = (p == new UIntPtr(expected));
        Assert.True(b);

        b = (p == new UIntPtr(expected + 1));
        Assert.False(b);

        b = (p != new UIntPtr(expected));
        Assert.False(b);

        b = (p != new UIntPtr(expected + 1));
        Assert.True(b);
    }
Exemplo n.º 30
0
    public bool PosTest3()
    {
        bool retVal = true;

        const string c_TEST_ID = "P003";
        string testDesc = string.Format("PosTest3: value is UInt{0}.MaxValue", 8 * UIntPtr.Size);

        string errorDesc;

        UIntPtr actualUIntPtr;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(testDesc);
        try
        {
            UInt64 ui = (UIntPtr.Size == 4) ? UInt32.MaxValue : UInt64.MaxValue;
            actualUIntPtr = new UIntPtr(ui);

            actualResult = actualUIntPtr.ToUInt64() == ui;

            if (!actualResult)
            {
                errorDesc = "Actual UIntPtr value is not " + ui + " as expected: Actual(" + actualUIntPtr + ")";
                TestLibrary.TestFramework.LogError("005" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("006" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
Exemplo n.º 31
0
        private static readonly byte[] FrameMagicNumber = { 0x04, 0x22, 0x4D, 0x18 }; // 0x184D2204 (LE)
        #endregion

        #region Constructor
        /// <summary>
        /// Create compressing LZ4FrameStream.
        /// </summary>
        public unsafe LZ4FrameStream(Stream baseStream, LZ4FrameCompressOptions compOpts)
        {
            LZ4Init.Manager.EnsureLoaded();

            BaseStream = baseStream ?? throw new ArgumentNullException(nameof(baseStream));
            _mode      = Mode.Compress;
            _disposed  = false;

            // Check and set compress options
            _leaveOpen  = compOpts.LeaveOpen;
            _bufferSize = CheckBufferSize(compOpts.BufferSize);

            // Prepare cctx
            UIntPtr ret = LZ4Init.Lib.CreateFrameCompressContext(ref _cctx, FrameVersion);

            LZ4FrameException.CheckReturnValue(ret);

            // Prepare FramePreferences
            FramePreferences prefs = new FramePreferences
            {
                FrameInfo = new FrameInfo
                {
                    BlockSizeId         = compOpts.BlockSizeId,
                    BlockMode           = compOpts.BlockMode,
                    ContentChecksumFlag = compOpts.ContentChecksumFlag,
                    FrameType           = compOpts.FrameType,
                    ContentSize         = compOpts.ContentSize,
                    DictId            = 0,
                    BlockChecksumFlag = compOpts.BlockChecksumFlag,
                },
                CompressionLevel = compOpts.Level,
                AutoFlush        = compOpts.AutoFlush ? 1u : 0u,
                FavorDecSpeed    = compOpts.FavorDecSpeed ? 1u : 0u,
            };

            // Query the minimum required size of compress buffer
            // _bufferSize is the source size, frameSize is the (required) dest size
            UIntPtr frameSizeVal = LZ4Init.Lib.FrameCompressBound((UIntPtr)_bufferSize, prefs);

            Debug.Assert(frameSizeVal.ToUInt64() <= int.MaxValue);
            uint frameSize = frameSizeVal.ToUInt32();

            /*
             * if (_bufferSize < frameSize)
             *  _destBufSize = frameSize;
             */
            _destBufSize = (uint)_bufferSize;
            if (_bufferSize < frameSize)
            {
                _destBufSize = frameSize;
            }
            _workBuf = new byte[_destBufSize];

            // Write the frame header into _workBuf
            UIntPtr headerSizeVal;

            fixed(byte *dest = _workBuf)
            {
                headerSizeVal = LZ4Init.Lib.FrameCompressBegin(_cctx, dest, (UIntPtr)_bufferSize, prefs);
            }

            LZ4FrameException.CheckReturnValue(headerSizeVal);
            Debug.Assert(headerSizeVal.ToUInt64() < int.MaxValue);

            int headerSize = (int)headerSizeVal.ToUInt32();

            BaseStream.Write(_workBuf, 0, headerSize);
            TotalOut += headerSize;
        }
Exemplo n.º 32
0
 public static string GetCLanguageExpression(UIntPtr value) =>
 string.Format("((uintptr_t){0})", GetCLanguageExpression(value.ToUInt64()));
Exemplo n.º 33
0
        public unsafe int Read(Span <byte> span)
#endif
        {
            if (_mode != Mode.Decompress)
            {
                throw new NotSupportedException("Read() not supported on compression");
            }

            // Reached end of stream
            if (_decompSrcIdx == DecompressComplete)
            {
                return(0);
            }

            int readSize      = 0;
            int destSize      = span.Length;
            int destLeftBytes = span.Length;

            if (_firstRead)
            {
                // Write FrameMagicNumber into LZ4F_decompress
                UIntPtr headerSizeVal = (UIntPtr)4;
                UIntPtr destSizeVal   = (UIntPtr)destSize;

                UIntPtr ret;
                fixed(byte *header = FrameMagicNumber)
                fixed(byte *dest = span)
                {
                    ret = LZ4Init.Lib.FrameDecompress(_dctx, dest, ref destSizeVal, header, ref headerSizeVal, null);
                }
                LZ4FrameException.CheckReturnValue(ret);

                Debug.Assert(headerSizeVal.ToUInt64() <= int.MaxValue);
                Debug.Assert(destSizeVal.ToUInt64() <= int.MaxValue);

                if (headerSizeVal.ToUInt32() != 4u)
                {
                    throw new InvalidOperationException("Not enough dest buffer");
                }
                int destWritten = (int)destSizeVal.ToUInt32();

                span      = span.Slice(destWritten);
                TotalOut += destWritten;

                _firstRead = false;
            }

            while (0 < destLeftBytes)
            {
                if (_decompSrcIdx == _decompSrcCount)
                {
                    // Read from _baseStream
                    _decompSrcIdx   = 0;
                    _decompSrcCount = BaseStream.Read(_workBuf, 0, _workBuf.Length);
                    TotalIn        += _decompSrcCount;

                    // _baseStream reached its end
                    if (_decompSrcCount == 0)
                    {
                        _decompSrcIdx = DecompressComplete;
                        break;
                    }
                }

                UIntPtr srcSizeVal  = (UIntPtr)(_decompSrcCount - _decompSrcIdx);
                UIntPtr destSizeVal = (UIntPtr)(destLeftBytes);

                UIntPtr ret;
                fixed(byte *src = _workBuf.AsSpan(_decompSrcIdx))
                fixed(byte *dest = span)
                {
                    ret = LZ4Init.Lib.FrameDecompress(_dctx, dest, ref destSizeVal, src, ref srcSizeVal, null);
                }
                LZ4FrameException.CheckReturnValue(ret);

                // The number of bytes consumed from srcBuffer will be written into *srcSizePtr (necessarily <= original value).
                Debug.Assert(srcSizeVal.ToUInt64() <= int.MaxValue);
                int srcConsumed = (int)srcSizeVal.ToUInt32();
                _decompSrcIdx += srcConsumed;
                Debug.Assert(_decompSrcIdx <= _decompSrcCount);

                // The number of bytes decompressed into dstBuffer will be written into *dstSizePtr (necessarily <= original value).
                Debug.Assert(destSizeVal.ToUInt64() <= int.MaxValue);
                int destWritten = (int)destSizeVal.ToUInt32();

                span           = span.Slice(destWritten);
                destLeftBytes -= destWritten;
                TotalOut      += destWritten;
                readSize      += destWritten;
            }

            return(readSize);
        }
Exemplo n.º 34
0
    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "P002";
        const string c_TEST_DESC = "PosTest2: UIntPtr with a random value between 0 and UInt32.MaxValue";
        string errorDesc;

        UInt64 actualUI, expectedUI;
        UIntPtr uiPtr;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            expectedUI = this.GetUInt64() % ((UInt64)UInt32.MaxValue + 1);
            uiPtr = new UIntPtr(expectedUI);
            actualUI = uiPtr.ToUInt64();

            actualResult = actualUI == expectedUI;
            if (!actualResult)
            {
                errorDesc = "Actual UInt32 from UIntPtr is not " + expectedUI + " as expected: Actual(" + actualUI + ")";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
Exemplo n.º 35
0
 public virtual bool runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   UInt64 lValue;
   UIntPtr ip1;
   try {
   strLoc = "Loc_743wg";
   lValue = 16;
   ip1 = new UIntPtr(lValue);
   iCountTestcases++;
   if(ip1.ToUInt64() != lValue){
   iCountErrors++;
   Console.WriteLine("Err_2975sf! Wrong value returned");
   }
   strLoc = "Loc_0084wf";
   lValue = 0;
   ip1 = new UIntPtr(lValue);
   iCountTestcases++;
   if(ip1.ToUInt64() != UIntPtr.Zero.ToUInt64()){
   iCountErrors++;
   Console.WriteLine("Err_974325sdg! Wrong value returned");
   }
   strLoc = "Loc_93476sdg";
   lValue = UInt32.MaxValue;
   ip1 = new UIntPtr(lValue);
   iCountTestcases++;
   if(ip1.ToUInt64() != lValue){
   iCountErrors++;
   Console.WriteLine("Err_07536tsg! Wrong value returned");
   }
   lValue = UInt32.MinValue;
   ip1 = new UIntPtr(lValue);
   if(ip1.ToUInt64() != lValue){
   iCountErrors++;
   Console.WriteLine("Err_9875wrsg! Wrong value returned");
   }
   strLoc = "Loc_8745sdg";
   lValue = UInt64.MaxValue;
   iCountTestcases++;
   try{
   ip1 = new UIntPtr(lValue);
   iCountErrors++;
   Console.WriteLine("Err_874325sdg! No oexception thrown. Is this a 64 bit machine? or has the functionality changed?");
   }catch(OverflowException){
   }catch(Exception ex){
   iCountErrors++;
   Console.WriteLine("Err_82375d! Wrong Exception returned, " + ex.GetType().Name);
   }
   lValue = UInt64.MinValue;
   ip1 = new UIntPtr(lValue);
   if(ip1.ToUInt64() != lValue){
   iCountErrors++;
   Console.WriteLine("Err_87453wg! Wrong value returned");
   }             
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
     return true;
     }
   else
     {
     Console.Error.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
Exemplo n.º 36
0
 public static ulong ReadableBytes(UIntPtr startAddress)
 {
     return(MaxWritableExtent - startAddress.ToUInt64());
 }
Exemplo n.º 37
0
        private IntPtr WindowProc(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
                #region keyboard
            case 0x100:    /*WM_KEYDOWN*/
            {
                var keyCode = wParam.ToUInt32();
                if (wParam.ToUInt64() < 256)
                {
                    Keyboard.Instance.lastKeyStates[keyCode] = Keyboard.Instance.keyStates[keyCode];
                    Keyboard.Instance.keyStates[keyCode]     = KeyState.Down;
                }

                if (keyCode == (int)Key.Enter)
                {
                    Ime.ImeBuffer.Enqueue('\n');
                    return(new IntPtr(1));
                }

                //DEBUG only begin
                if (keyCode == (int)Key.Escape)
                {
                    Application.Quit();
                }
                //DEBUG only end

                return(IntPtr.Zero);
            }

            case 0x101:    /*WM_KEYUP*/
            {
                var keyCode = wParam.ToUInt32();
                if (wParam.ToUInt64() < 256)
                {
                    Keyboard.Instance.lastKeyStates[keyCode] = Keyboard.Instance.keyStates[keyCode];
                    Keyboard.Instance.keyStates[keyCode]     = KeyState.Up;
                }
                return(IntPtr.Zero);
            }

                #endregion
                #region mouse
            case 0x0201:    //WM_LBUTTONDOWN
                Mouse.Instance.LeftButtonState = KeyState.Down;
                return(IntPtr.Zero);

            case 0x0202:    //WM_LBUTTONUP
                Mouse.Instance.LeftButtonState = KeyState.Up;
                return(IntPtr.Zero);

            case 0x0203:    //WM_LBUTTONDBLCLK
                return(IntPtr.Zero);

            case 0x0206:    //WM_RBUTTONDBLCLK
                return(IntPtr.Zero);

            case 0x0204:    //WM_RBUTTONDOWN
                Mouse.Instance.RightButtonState = KeyState.Down;
                return(IntPtr.Zero);

            case 0x0205:    //WM_RBUTTONUP
                Mouse.Instance.RightButtonState = KeyState.Up;
                return(IntPtr.Zero);

            case 0x020A:    //WM_MOUSEWHEEL
                Mouse.Instance.MouseWheel = ((short)(wParam.ToUInt64() >> 16));
                return(IntPtr.Zero);

            case 0x0200:    //WM_MOUSEMOVE
                var p = new POINT
                {
                    X = unchecked ((short)lParam),
                    Y = unchecked ((short)((uint)lParam >> 16))
                };
                Mouse.Instance.Position = new Point(p.X, p.Y);
                return(IntPtr.Zero);

                #endregion
                #region ime
            //http://blog.csdn.net/shuilan0066/article/details/7679825
            case 0x0286:    /*WM_IME_CHAR*/
            {
                char c = (char)wParam;
                if (c > 0 && !char.IsControl(c))
                {
                    Ime.ImeBuffer.Enqueue(c);
                }
                return(IntPtr.Zero);
            }

            case 0x0102:    /*WM_CHAR*/
            {
                char c = (char)wParam;
                if (c > 0 && !char.IsControl(c))
                {
                    Ime.ImeBuffer.Enqueue(c);
                }
                return(IntPtr.Zero);
            }

                #endregion
            case 0x2:    //WM_DESTROY
                PostQuitMessage(0);
                //DEBUG only begin
                Application.Quit();
                //DEBUG only end
                return(IntPtr.Zero);
            }
            return(DefWindowProc(hWnd, msg, wParam, lParam));
        }