Esempio n. 1
0
        public static unsafe ConsoleKeyInfo ReadKey(bool intercept)
        {
            // mov ah,08h
            // int 21h
            // ret
            byte *pCode = stackalloc byte[] { 0xB4, 0x08, 0xCD, 0x21, 0xC3 };
            char  c     = (char)ClassConstructorRunner.Call <byte>(new IntPtr(pCode));

            // Interpret WASD as arrow keys.
            ConsoleKey k = default;

            if (c == 'w')
            {
                k = ConsoleKey.UpArrow;
            }
            else if (c == 'd')
            {
                k = ConsoleKey.RightArrow;
            }
            else if (c == 's')
            {
                k = ConsoleKey.DownArrow;
            }
            else if (c == 'a')
            {
                k = ConsoleKey.LeftArrow;
            }

            return(new ConsoleKeyInfo(c, k, false, false, false));
        }
Esempio n. 2
0
        public static unsafe void Sleep(int delayMs)
        {
            // Place the sequence of bytes 0xF4, 0xC3 on the stack.
            // The bytes correspond to the following assembly instruction sequence:
            //
            // hlt
            // ret
            //
            ushort hlt = 0xc3f4;

            long expected = Environment.TickCount64 + delayMs;

            while (Environment.TickCount64 < expected)
            {
                // Call the helper we placed on the stack to halt the processor
                // for a little bit.
                // (Security people are crying in a corner right now).
                ClassConstructorRunner.Call <int>(new IntPtr(&hlt));
            }
        }
Esempio n. 3
0
        public static unsafe void EnsureClassConstructorRun(IntPtr staticClassConstructionContext)
        {
            StaticClassConstructionContext *context = (StaticClassConstructionContext *)staticClassConstructionContext;

            ClassConstructorRunner.EnsureClassConstructorRun(context);
        }
Esempio n. 4
0
 public static void InitializeLibrary()
 {
     PreallocatedOutOfMemoryException.Initialize();
     ClassConstructorRunner.Initialize();
     TypeLoaderExports.Initialize();
 }