Ejemplo n.º 1
0
        public void PointTest()
        {
            Point origin = new Point(0, 0);
            StructWrapper <Point> wrapper = new StructWrapper <Point>(origin);

            Assert.AreEqual(origin, wrapper.Instance);
        }
Ejemplo n.º 2
0
        public static bool Build_Volume_Mapping(SafeFileHandle roothandle, Win32Api.USN_JOURNAL_DATA currentUsnState, Action <Win32Api.UsnEntry> func)
        {
            Debug.WriteLine("Starting Build_Volume_Mapping");

            DateTime startTime = DateTime.Now;

            Win32Api.MFT_ENUM_DATA med;
            med.StartFileReferenceNumber = 0;
            med.LowUsn  = 0;
            med.HighUsn = currentUsnState.NextUsn;

            using (var med_struct = new StructWrapper(med))
                using (var rawdata = new Raw_Array_Wrapper(BUF_LEN))
                {
                    uint outBytesReturned = 0;

                    while (Win32Api.DeviceIoControl(
                               roothandle.DangerousGetHandle(),
                               Win32Api.FSCTL_ENUM_USN_DATA,
                               med_struct.Ptr,
                               med_struct.Size,
                               rawdata.Ptr,
                               rawdata.Size,
                               out outBytesReturned,
                               IntPtr.Zero))
                    {
                        outBytesReturned = outBytesReturned - sizeof(Int64);
                        IntPtr pUsnRecord = System.IntPtr.Add(rawdata.Ptr, sizeof(Int64));//need to skip 8 bytes because the first 8 bytes are to a usn number, which isnt in the structure
                        while (outBytesReturned > 60)
                        {
                            var usnEntry = new Win32Api.UsnEntry(pUsnRecord);
                            pUsnRecord = System.IntPtr.Add(pUsnRecord, (int)usnEntry.RecordLength);
                            func(usnEntry);

                            if (usnEntry.RecordLength > outBytesReturned)
                            {
                                outBytesReturned = 0;// prevent overflow
                            }
                            else
                            {
                                outBytesReturned -= usnEntry.RecordLength;
                            }
                        }
                        Marshal.WriteInt64(med_struct.Ptr, Marshal.ReadInt64(rawdata.Ptr, 0));//read the usn that we skipped and place it into the nextusn
                    }
                    var possiblerror = Marshal.GetLastWin32Error();
                    if (possiblerror < 0)
                    {
                        throw new Win32Exception(possiblerror);
                    }
                }
            Debug.WriteLine("Time took: " + (DateTime.Now - startTime).TotalMilliseconds + "ms");
            return(true);
        }
Ejemplo n.º 3
0
        public static void GetUsnJournalEntries(SafeFileHandle roothandle, Win32Api.USN_JOURNAL_DATA previousUsnState,
                                                UInt32 reasonMask,
                                                out List <Win32Api.UsnEntry> usnEntries,
                                                out Win32Api.USN_JOURNAL_DATA newUsnState)
        {
            usnEntries  = new List <Win32Api.UsnEntry>();
            newUsnState = new Win32Api.USN_JOURNAL_DATA();

            QueryUsnJournal(roothandle, ref newUsnState);

            Win32Api.READ_USN_JOURNAL_DATA rujd = new Win32Api.READ_USN_JOURNAL_DATA();
            rujd.StartUsn          = previousUsnState.NextUsn;
            rujd.ReasonMask        = reasonMask;
            rujd.ReturnOnlyOnClose = 0;
            rujd.Timeout           = 0;
            rujd.bytesToWaitFor    = 0;
            rujd.UsnJournalId      = previousUsnState.UsnJournalID;

            using (var med_struct = new StructWrapper(rujd))
                using (var rawdata = new Raw_Array_Wrapper(BUF_LEN))
                {
                    uint outBytesReturned = 0;
                    var  nextusn          = previousUsnState.NextUsn;
                    while (nextusn < newUsnState.NextUsn && Win32Api.DeviceIoControl(
                               roothandle.DangerousGetHandle(),
                               Win32Api.FSCTL_READ_USN_JOURNAL,
                               med_struct.Ptr,
                               med_struct.Size,
                               rawdata.Ptr,
                               rawdata.Size,
                               out outBytesReturned,
                               IntPtr.Zero))
                    {
                        outBytesReturned = outBytesReturned - sizeof(Int64);
                        IntPtr pUsnRecord = System.IntPtr.Add(rawdata.Ptr, sizeof(Int64)); //point safe arithmetic!~!!
                        while (outBytesReturned > 60)                                      // while there are at least one entry in the usn journal
                        {
                            var usnEntry = new Win32Api.UsnEntry(pUsnRecord);
                            if (usnEntry.USN > newUsnState.NextUsn)
                            {
                                break;
                            }
                            usnEntries.Add(usnEntry);
                            pUsnRecord        = System.IntPtr.Add(pUsnRecord, (int)usnEntry.RecordLength);//point safe arithmetic!~!!
                            outBytesReturned -= usnEntry.RecordLength;
                        }
                        nextusn = Marshal.ReadInt64(rawdata.Ptr, 0);
                        Marshal.WriteInt64(med_struct.Ptr, nextusn);//read the usn that we skipped and place it into the nextusn
                    }
                }
        }
Ejemplo n.º 4
0
        private static readonly int BUF_LEN = 8192 + 8; //8 bytes for the leading USN

        #endregion Fields

        #region Methods

        public static bool Build_Volume_Mapping(SafeFileHandle roothandle, Win32Api.USN_JOURNAL_DATA currentUsnState, Action<Win32Api.UsnEntry> func)
        {
            Debug.WriteLine("Starting Build_Volume_Mapping");

            DateTime startTime = DateTime.Now;

            Win32Api.MFT_ENUM_DATA med;
            med.StartFileReferenceNumber = 0;
            med.LowUsn = 0;
            med.HighUsn = currentUsnState.NextUsn;

            using(var med_struct = new StructWrapper(med))
            using(var rawdata = new Raw_Array_Wrapper(BUF_LEN))
            {
                uint outBytesReturned = 0;

                while(Win32Api.DeviceIoControl(
                    roothandle.DangerousGetHandle(),
                    Win32Api.FSCTL_ENUM_USN_DATA,
                    med_struct.Ptr,
                    med_struct.Size,
                    rawdata.Ptr,
                    rawdata.Size,
                    out outBytesReturned,
                    IntPtr.Zero))
                {
                    outBytesReturned = outBytesReturned - sizeof(Int64);
                    IntPtr pUsnRecord = System.IntPtr.Add(rawdata.Ptr, sizeof(Int64));//need to skip 8 bytes because the first 8 bytes are to a usn number, which isnt in the structure
                    while(outBytesReturned > 60)
                    {
                        var usnEntry = new Win32Api.UsnEntry(pUsnRecord);
                        pUsnRecord = System.IntPtr.Add(pUsnRecord, (int)usnEntry.RecordLength);
                        func(usnEntry);

                        if(usnEntry.RecordLength > outBytesReturned)
                            outBytesReturned = 0;// prevent overflow
                        else
                            outBytesReturned -= usnEntry.RecordLength;
                    }
                    Marshal.WriteInt64(med_struct.Ptr, Marshal.ReadInt64(rawdata.Ptr, 0));//read the usn that we skipped and place it into the nextusn
                }
                var possiblerror = Marshal.GetLastWin32Error();
                if(possiblerror < 0)
                    throw new Win32Exception(possiblerror);
            }
            Debug.WriteLine("Time took: " + (DateTime.Now - startTime).TotalMilliseconds + "ms");
            return true;
        }
Ejemplo n.º 5
0
    public static void TestContains()
    {
        {
            // Should be compared with IEquatable
            Driver <EquatableElement1> .TestContains(Producer.Produce <EquatableElement1>(5), new EquatableElement1 { IntValue = 1 }, true);

            Driver <EquatableElement1> .TestContains(Producer.Produce <EquatableElement1>(5), new EquatableElement1 { IntValue = 5 }, false);

            // Should be compared by calling Equals(object other)
            NonGenericElement10 item = new NonGenericElement10();
            Driver <NonGenericElement10> .TestContains(Producer.MakeEnumerable(item), item, true);

            Driver <NonGenericElement10> .TestContains(Producer.MakeEnumerable(item), new NonGenericElement10(), false);
        }

        // Struct version of the above two
        {
            // Should be compared with IEquatable
            Driver <EquatableStructWrapper <EquatableElement1> > .TestContains(
                Producer.WrapInEquatableStructWrapper(Producer.Produce <EquatableElement1>(5)),
                new EquatableStructWrapper <EquatableElement1> {
                Reference = new EquatableElement1 {
                    IntValue = 1
                }
            },
                true);

            Driver <EquatableStructWrapper <EquatableElement1> > .TestContains(
                Producer.WrapInEquatableStructWrapper(Producer.Produce <EquatableElement1>(5)),
                new EquatableStructWrapper <EquatableElement1> {
                Reference = new EquatableElement1 {
                    IntValue = 5
                }
            },
                false);

            // Should be compared by calling Equals(object other)
            StructWrapper <NonGenericElement10> item = new StructWrapper <NonGenericElement10> {
                Reference = new NonGenericElement10()
            };
            Driver <StructWrapper <NonGenericElement10> > .TestContains(Producer.MakeEnumerable(item), item, true);

            Driver <StructWrapper <NonGenericElement10> > .TestContains(Producer.MakeEnumerable(item), new StructWrapper <NonGenericElement10> {
                Reference = new NonGenericElement10()
            }, false);
        }
    }
        public static unsafe Task <bool> SendPushToUser(string frontendId, string serverType, string route, string uid,
                                                        object pushMsg)
        {
            return(_rpcTaskFactory.StartNew(() =>
            {
                bool ok = false;
                MemoryBuffer inMemBuf = new MemoryBuffer();
                MemoryBuffer *outMemBufPtr = null;
                var retError = new Error();

                var push = new Push
                {
                    Route = route,
                    Uid = uid,
                    Data = ByteString.CopyFrom(SerializerUtils.SerializeOrRaw(pushMsg, _serializer))
                };

                try
                {
                    var data = push.ToByteArray();
                    fixed(byte *p = data)
                    {
                        inMemBuf.data = (IntPtr)p;
                        inMemBuf.size = data.Length;
                        IntPtr inMemBufPtr = new StructWrapper(inMemBuf);

                        ok = PushInternal(frontendId, serverType, inMemBufPtr, &outMemBufPtr, ref retError);
                        if (!ok) // error
                        {
                            Logger.Error($"Push failed: ({retError.code}: {retError.msg})");
                            return false;
                        }

                        return true;
                    }
                }
                finally
                {
                    if (outMemBufPtr != null)
                    {
                        FreeMemoryBufferInternal(outMemBufPtr);
                    }
                }
            }));
        }
Ejemplo n.º 7
0
        private void UpdateStyle()
        {
            //TODO: add "no split" style

            var info = new ButtonSplitInfo();

            info.Mask  = ButtonSplitInfo.MaskType.Style;
            info.Style = (
                (SplitButtonAlignLeft) ? ButtonSplitInfo.SplitStyle.AlignLeft : ButtonSplitInfo.SplitStyle.None
                );

            using (var hSplitInfo = new StructWrapper <ButtonSplitInfo>(info)) {
                Methods.SendMessage(Handle,
                                    (int)WindowMessage.BCM_SETSPLITINFO,
                                    IntPtr.Zero,
                                    hSplitInfo);
            }
        }
Ejemplo n.º 8
0
    public static void TestSortWithComparison()
    {
        {
            NonGenericElement11 item1 = new NonGenericElement11 {
                IntValue = 2
            };
            NonGenericElement11 item2 = new NonGenericElement11 {
                IntValue = 3
            };
            NonGenericElement11 item3 = new NonGenericElement11 {
                IntValue = 1
            };

            Driver <NonGenericElement11> .TestSortWithComparison(
                Producer.MakeEnumerable(item1, item2, item3),
                (x, y) => x.IntValue.CompareTo(y.IntValue),
                Producer.MakeEnumerable(item3, item1, item2));
        }

        {
            StructWrapper <NonGenericElement11> item1 = new StructWrapper <NonGenericElement11> {
                Reference = new NonGenericElement11 {
                    IntValue = 2
                }
            };
            StructWrapper <NonGenericElement11> item2 = new StructWrapper <NonGenericElement11> {
                Reference = new NonGenericElement11 {
                    IntValue = 3
                }
            };
            StructWrapper <NonGenericElement11> item3 = new StructWrapper <NonGenericElement11> {
                Reference = new NonGenericElement11 {
                    IntValue = 1
                }
            };

            Driver <StructWrapper <NonGenericElement11> > .TestSortWithComparison(
                Producer.MakeEnumerable(item1, item2, item3),
                (x, y) => x.Reference.IntValue.CompareTo(y.Reference.IntValue),
                Producer.MakeEnumerable(item3, item1, item2));
        }
    }
        public static void Initialize(GrpcConfig grpcCfg,
                                      SDConfig sdCfg,
                                      Server server,
                                      NativeLogLevel logLevel,
                                      ServiceDiscoveryListener serviceDiscoveryListener = null,
                                      string logFile = "")
        {
            IntPtr grpcCfgPtr = new StructWrapper(grpcCfg);
            IntPtr sdCfgPtr   = new StructWrapper(sdCfg);
            IntPtr serverPtr  = new StructWrapper(server);

            bool ok = InitializeWithGrpcInternal(grpcCfgPtr, sdCfgPtr, serverPtr, logLevel,
                                                 logFile);

            if (!ok)
            {
                throw new PitayaException("Initialization failed");
            }

            AddServiceDiscoveryListener(serviceDiscoveryListener);
            ListenToIncomingRPCs();
        }
        public static unsafe Task <bool> SendKickToUser(string frontendId, string serverType, KickMsg kick)
        {
            return(_rpcTaskFactory.StartNew(() =>
            {
                bool ok = false;
                MemoryBuffer inMemBuf = new MemoryBuffer();
                MemoryBuffer *outMemBufPtr = null;
                var retError = new Error();

                try
                {
                    var data = kick.ToByteArray();
                    fixed(byte *p = data)
                    {
                        inMemBuf.data = (IntPtr)p;
                        inMemBuf.size = data.Length;
                        IntPtr inMemBufPtr = new StructWrapper(inMemBuf);
                        ok = KickInternal(frontendId, serverType, inMemBufPtr, &outMemBufPtr, ref retError);
                        if (!ok) // error
                        {
                            Logger.Error($"Push failed: ({retError.code}: {retError.msg})");
                            return false;
                        }

                        var kickAns = new KickAnswer();
                        kickAns.MergeFrom(new CodedInputStream(outMemBufPtr->GetData()));

                        return kickAns.Kicked;
                    }
                }
                finally
                {
                    if (outMemBufPtr != null)
                    {
                        FreeMemoryBufferInternal(outMemBufPtr);
                    }
                }
            }));
        }
Ejemplo n.º 11
0
        private unsafe void castSpellDetour(uint param1, uint param2, uint param3, uint param4, uint param5)
        {
            try
            {
                param1 = *(uint*) (*(uint*)(Memory.LOLBaseAddress+Offsets.LocalPlayer) + Offsets.Champion_SCI);
                uint spellSlot = *(uint*)(param1+0xC);

                Vector3 targetPos = Memory.ReadStruct<Vector3>(*(uint*)(Memory.LOLBaseAddress+Offsets.LocalPlayer)+Offsets.Position);

                Frame.Log("p1: " + param1.ToString("X") + " p2: " + param2.ToString("X") + " p3: " + param3.ToString("X") + " p4: " + param4.ToString("X") + " p5: " + param5.ToString("X") + " spellSlot: " + spellSlot);

                using (var s = new StructWrapper<Vector3>(targetPos)){
                    Memory.GetMagic.Detours["castSpell"].CallOriginal(param1,s.Ptr,s.Ptr,param4,param5);
                }

            }
            catch (Exception ex)
            {

                Frame.Log(ex.ToString());
            }
        }
Ejemplo n.º 12
0
 public int Compare(StructWrapper <T> x, StructWrapper <T> y)
 {
     return(x.Reference.IntValue.CompareTo(y.Reference.IntValue));
 }
Ejemplo n.º 13
0
        public unsafe void PrintToChat(string text, uint type = 4)
        {
            try
            {
                using (var s = new StructWrapper<string>(text)){
                    var chat = (PrintChat)Marshal.GetDelegateForFunctionPointer(new IntPtr(Memory.LOLBaseAddress+Offsets.PrintChat), typeof(PrintChat));
                    uint printArg = Memory.Read<uint>((Memory.LOLBaseAddress+0x2FC672C));

                    chat(printArg,s.Ptr,type);
                }

            } catch (Exception ex)
            {
                Frame.Log(ex.StackTrace);

            }
        }
Ejemplo n.º 14
0
        public static void GetUsnJournalEntries(SafeFileHandle roothandle, Win32Api.USN_JOURNAL_DATA previousUsnState,
            UInt32 reasonMask,
            out List<Win32Api.UsnEntry> usnEntries,
            out Win32Api.USN_JOURNAL_DATA newUsnState)
        {
            usnEntries = new List<Win32Api.UsnEntry>();
            newUsnState = new Win32Api.USN_JOURNAL_DATA();

            QueryUsnJournal(roothandle, ref newUsnState);

            Win32Api.READ_USN_JOURNAL_DATA rujd = new Win32Api.READ_USN_JOURNAL_DATA();
            rujd.StartUsn = previousUsnState.NextUsn;
            rujd.ReasonMask = reasonMask;
            rujd.ReturnOnlyOnClose = 0;
            rujd.Timeout = 0;
            rujd.bytesToWaitFor = 0;
            rujd.UsnJournalId = previousUsnState.UsnJournalID;

            using(var med_struct = new StructWrapper(rujd))
            using(var rawdata = new Raw_Array_Wrapper(BUF_LEN))
            {
                uint outBytesReturned = 0;
                var nextusn = previousUsnState.NextUsn;
                while(nextusn < newUsnState.NextUsn && Win32Api.DeviceIoControl(
                         roothandle.DangerousGetHandle(),
                        Win32Api.FSCTL_READ_USN_JOURNAL,
                        med_struct.Ptr,
                        med_struct.Size,
                        rawdata.Ptr,
                        rawdata.Size,
                        out outBytesReturned,
                        IntPtr.Zero))
                {
                    outBytesReturned = outBytesReturned - sizeof(Int64);
                    IntPtr pUsnRecord = System.IntPtr.Add(rawdata.Ptr, sizeof(Int64));//point safe arithmetic!~!!
                    while(outBytesReturned > 60)   // while there are at least one entry in the usn journal
                    {
                        var usnEntry = new Win32Api.UsnEntry(pUsnRecord);
                        if(usnEntry.USN > newUsnState.NextUsn)
                            break;
                        usnEntries.Add(usnEntry);
                        pUsnRecord = System.IntPtr.Add(pUsnRecord, (int)usnEntry.RecordLength);//point safe arithmetic!~!!
                        outBytesReturned -= usnEntry.RecordLength;
                    }
                    nextusn = Marshal.ReadInt64(rawdata.Ptr, 0);
                    Marshal.WriteInt64(med_struct.Ptr, nextusn);//read the usn that we skipped and place it into the nextusn
                }
            }
        }
Ejemplo n.º 15
0
        public void IntTest()
        {
            StructWrapper <int> wrapper = new StructWrapper <int>(42);

            Assert.AreEqual(42, wrapper.Instance);
        }
Ejemplo n.º 16
0
    public static void TestSortWithComparer()
    {
        // Provide a comparer
        {
            NonGenericElement12 item1 = new NonGenericElement12 {
                IntValue = 2
            };
            NonGenericElement12 item2 = new NonGenericElement12 {
                IntValue = 3
            };
            NonGenericElement12 item3 = new NonGenericElement12 {
                IntValue = 1
            };

            Driver <NonGenericElement12> .TestSortWithComparer(
                Producer.MakeEnumerable(item1, item2, item3),
                new NonGenericBaseComparer(),
                Producer.MakeEnumerable(item3, item1, item2));
        }

        // Rely on IComparable<T>
        {
            ComparableElement1 item1 = new ComparableElement1 {
                IntValue = 2
            };
            ComparableElement1 item2 = new ComparableElement1 {
                IntValue = 3
            };
            ComparableElement1 item3 = new ComparableElement1 {
                IntValue = 1
            };

            Driver <ComparableElement1> .TestSortWithComparer(
                Producer.MakeEnumerable(item1, item2, item3),
                null,
                Producer.MakeEnumerable(item3, item1, item2));
        }

        // Provide a comparer
        {
            StructWrapper <NonGenericElement12> item1 = new StructWrapper <NonGenericElement12> {
                Reference = new NonGenericElement12 {
                    IntValue = 2
                }
            };
            StructWrapper <NonGenericElement12> item2 = new StructWrapper <NonGenericElement12> {
                Reference = new NonGenericElement12 {
                    IntValue = 3
                }
            };
            StructWrapper <NonGenericElement12> item3 = new StructWrapper <NonGenericElement12> {
                Reference = new NonGenericElement12 {
                    IntValue = 1
                }
            };

            Driver <StructWrapper <NonGenericElement12> > .TestSortWithComparer(
                Producer.MakeEnumerable(item1, item2, item3),
                new NonGenericWrappedBaseComparer <NonGenericElement12>(),
                Producer.MakeEnumerable(item3, item1, item2));
        }

        // Rely on IComparable<T>
        {
            ComparableStructWrapper <ComparableElement1> item1 = new ComparableStructWrapper <ComparableElement1> {
                Reference = new ComparableElement1 {
                    IntValue = 2
                }
            };
            ComparableStructWrapper <ComparableElement1> item2 = new ComparableStructWrapper <ComparableElement1> {
                Reference = new ComparableElement1 {
                    IntValue = 3
                }
            };
            ComparableStructWrapper <ComparableElement1> item3 = new ComparableStructWrapper <ComparableElement1> {
                Reference = new ComparableElement1 {
                    IntValue = 1
                }
            };

            Driver <ComparableStructWrapper <ComparableElement1> > .TestSortWithComparer(
                Producer.MakeEnumerable(item1, item2, item3),
                null,
                Producer.MakeEnumerable(item3, item1, item2));
        }
    }
Ejemplo n.º 17
0
 public void MoveTo(Vector3 pos)
 {
     var moveTo = (DetourMoveTo.moveTo)Marshal.GetDelegateForFunctionPointer(new IntPtr(Memory.LOLBaseAddress+Offsets.MoveTo), typeof(DetourMoveTo.moveTo));
     using (var s = new StructWrapper<Vector3>(pos)){
         moveTo(BaseAddress,2,s.Ptr,0,1,0);
     }
 }