Advertisement
Guest User

Untitled

a guest
Sep 9th, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Reflection;
  5. using System.Runtime.InteropServices;
  6. using System.IO;
  7. using ProcessDotNet;
  8. using ProcessDotNet.Applied.Detours;
  9.  
  10. namespace Bootstrap
  11. {
  12.  
  13.     [UnmanagedFunctionPointer(CallingConvention.Winapi)]
  14.     public delegate void GetSystemInfoDelegate(ref SYSTEM_INFO info);
  15.  
  16.     [StructLayout(LayoutKind.Sequential)]
  17.     public struct SYSTEM_INFO
  18.     {
  19.         public ushort processorArchitecture;
  20.         ushort reserved;
  21.         public uint pageSize;
  22.         public IntPtr minimumApplicationAddress;
  23.         public IntPtr maximumApplicationAddress;
  24.         public IntPtr activeProcessorMask;
  25.         public uint numberOfProcessors;
  26.         public uint processorType;
  27.         public uint allocationGranularity;
  28.         public ushort processorLevel;
  29.         public ushort processorRevision;
  30.     }
  31.  
  32.     class Loader
  33.     {
  34.         List<Proxy> _myProxys = new List<Proxy>();
  35.  
  36.         static void GetSystemInfoDetoured(ref SYSTEM_INFO info)
  37.         {
  38.             info = new SYSTEM_INFO();
  39.             GetSystemInfoDetour.Disable();
  40.             GetSystemInfo(ref info);
  41.  
  42.             info.allocationGranularity = 1000000;
  43.  
  44.             GetSystemInfoDetour.Enable();
  45.         }
  46.  
  47.         static Detour GetSystemInfoDetour;
  48.         static GetSystemInfoDelegate GetSystemInfo;
  49.        
  50.         static void Main(string[] args)
  51.         {
  52.             TestDomainCreation();
  53.         }
  54.  
  55.         static void TestDomainCreation()
  56.         {
  57.             AppDomainSetup setup = new AppDomainSetup();
  58.  
  59.             ProcessSharp s = new ProcessSharp(Process.GetCurrentProcess(), ProcessDotNet.Memory.MemoryType.Local);
  60.  
  61.             GetSystemInfo = s["kernel32"]["GetSystemInfo"].GetDelegate<GetSystemInfoDelegate>();
  62.             DetourManager dtm = new DetourManager(s.Memory);
  63.             GetSystemInfoDetour = dtm.CreateAndApply(GetSystemInfo, new GetSystemInfoDelegate(GetSystemInfoDetoured), "GetSystemInfoDetour");
  64.  
  65.             var tempDomain = AppDomain.CreateDomain("HappyDomain", null, setup);
  66.  
  67.             GetSystemInfoDetour.Disable();
  68.             GetSystemInfoDetour.Dispose();
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement