示例#1
0
        NtStatus NtAllocateVirtualMemory(ref uint baseAddress, GuestMemory <uint> zeroBits,
                                         ref uint regionSize, AllocationType allocationType, uint protect)
        {
            baseAddress &= 0xFFFFF000;
            if ((regionSize & 0xFFF) != 0)
            {
                regionSize = (regionSize & 0xFFFFF000) + 4096;
            }
            Console.WriteLine($"Allocating 0x{regionSize:X} bytes at {baseAddress:X} ({allocationType})");

            if (allocationType.HasFlag(AllocationType.Commit) || allocationType.HasFlag(AllocationType.Reserve))
            {
                if (baseAddress != 0 && Box.Cpu.IsMapped(baseAddress))
                {
                    return(NtStatus.Success);
                }
                var virt = Box.PageManager.AllocVirtPages((int)regionSize / 4096, at: baseAddress != 0 ? (uint?)baseAddress : null);
                var phys = Box.PageManager.AllocPhysPages((int)regionSize / 4096);
                Box.Cpu.MapPages(virt, phys, (int)regionSize / 4096, true);
                baseAddress = virt;
            }
            else
            {
                throw new Exception($"Unsupported allocation type {allocationType}");
            }

            Console.WriteLine($"Output address is {baseAddress:X}");

            return(NtStatus.Success);
        }
示例#2
0
 void HalReadSMCTrayState(GuestMemory <uint> count, out uint state)
 {
     if (count)
     {
         count.Value = 1;
     }
     state = 16;             // Tray open
 }
示例#3
0
        void RtlInitAnsiString(out AnsiString dest, GuestMemory <byte> source)
        {
            var slen = source == 0 ? 0 : PStrlen(source);

            dest = new AnsiString {
                Buffer    = source,
                Length    = (ushort)slen,
                MaxLength = (ushort)(slen + 1)
            };
        }
示例#4
0
        int PStrlen(GuestMemory <byte> gm)
        {
            var len = 0;

            while (gm[len] != 0)
            {
                len++;
            }
            return(len);
        }
示例#5
0
文件: Misc.cs 项目: daeken/PaleFlag
        NtStatus IoCreateDevice(uint driverObject, uint deviceExtensionSize, GuestMemory <AnsiString> deviceName, uint deviceType,
                                bool exclusive, out uint deviceObject
                                )
        {
            deviceObject = Box.MemoryAllocator.Allocate(65536);             // XXX: Bullshit
            var gm = new GuestMemory <uint>(deviceObject + 0x18)
            {
                Value = deviceObject + 0x1000
            };

            return(NtStatus.Success);
        }
示例#6
0
文件: Misc.cs 项目: daeken/PaleFlag
 void KeInitializeTimerEx(GuestMemory <Ktimer> timer, TimerType type)
 {
     timer.Value = new Ktimer {
         Header = new DispatcherHeader {
             Type         = (byte)(type + 8),
             Size         = 10,
             WaitListHead = new ListEntry {
                 Flink = timer + 8,
                 Blink = timer + 8
             }
         }
     };
 }
示例#7
0
文件: Misc.cs 项目: daeken/PaleFlag
 NtStatus ExQueryNonVolatileSetting(uint valueIndex, GuestMemory <uint> type, GuestMemory <uint> value, uint valueLength, GuestMemory <uint> resultLength)
 {
     if (type)
     {
         type.Value = 4;
     }
     if (value)
     {
         value.Value = 0;
     }
     if (resultLength)
     {
         resultLength.Value = 4;
     }
     return(NtStatus.Success);
 }
示例#8
0
文件: Misc.cs 项目: daeken/PaleFlag
 bool KeSetTimer(GuestMemory <Ktimer> timer, ulong dueTime, GuestMemory <Kdpc> dpc)
 {
     return(true);
 }
示例#9
0
        NtStatus PsCreateSystemThreadEx(
            out uint threadHandle, uint threadExtraSize, uint kernelStackSize, uint tlsDataSize, GuestMemory <uint> threadId,
            uint startContext1, uint startContext2, bool createSuspended, bool debugStack, uint startRoutine
            )
        {
            var sp = Box.MemoryAllocator.Allocate(32768) + 32768;

            Console.WriteLine($"Creating new thread with stack top at {sp:X}");
            sp -= 12;
            new GuestMemory <uint>(sp)
            {
                [0] = 0xDEADBEEFU,
                [1] = startContext1,
                [2] = startContext2
            };
            var thread = Box.ThreadManager.Add(startRoutine, sp);

            thread.Ebp   = sp + 4;
            threadHandle = Box.HandleManager.Add(thread);
            if (threadId.GuestAddr != 0)
            {
                threadId.Value = thread.Id;
            }

            Tib.Create(Box, thread);

            return(NtStatus.Success);
        }