public IMemory <T> GetMemory <T>(params IMemoryOffset[] offsets) { UIntPtr address = this.GetAddress(offsets); string offsetString = string.Empty; foreach (IMemoryOffset offset in offsets) { offsetString += " " + GetString(offset) + ","; } offsetString = offsetString.Trim(' ', ','); Type wrapperType = this.GetMemoryType(typeof(T)); try { MemoryBase <T> memory = (MemoryBase <T>)Activator.CreateInstance(wrapperType, this.Process, address); memory.Description = offsetString + " (" + address + ")"; return(memory); } catch (TargetInvocationException ex) { throw ex.InnerException; } }
public C64Bus(Cia1 cia, Cia2 cia2, VicIi vic) : base(0x10000) { //_memory.FillWithRandomData(); // Intialize processor addressing mode with default values // http://sta.c64.org/cbm64mem.html _memory[0] = C64MemoryValues.PROCESSOR_PORT_DIRECTION_REGISTER_DEFAULT; _memory[1] = C64MemoryValues.PROCESSOR_PORT_REGISTER_DEFAULT; _romBasic = new MemoryBase <byte>(File.ReadAllBytes("basic.rom")) { IsReadOnly = true }; _romCharacter = new MemoryBase <byte>(File.ReadAllBytes("char.rom")) { IsReadOnly = true }; _romKernal = new MemoryBase <byte>(File.ReadAllBytes("kernal.rom")) { IsReadOnly = true }; _cia = cia; _cia2 = cia2; _vic = vic; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyFactory" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> internal AssemblyFactory(MemoryBase memorySharp) { // Save the parameter MemorySharp = memorySharp; // Create the tool Assembler = new Fasm32Assembler(); }
/// <summary> /// Initializes a new instance of the <see cref="ModuleFactory" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemoryManagement.MemorySharp" /> object.</param> internal ModuleFactory(MemoryBase memorySharp) { // Save the parameter MemorySharp = memorySharp; // Create a list containing all injected modules InternalInjectedModules = new List<InjectedModule>(); }
public FormMemoryMap(MemoryBase memory) { m_memory = memory; InitializeComponent(); propGrid.SelectedObject = new BusDeviceProxy(m_memory); var tc = TypeDescriptor.GetConverter(typeof(BusDeviceProxy)); var propCount = tc .GetProperties(propGrid.SelectedObject) .Count; var gridVisible = propCount > 0; propGrid.Visible = gridVisible; if (!gridVisible) { ClientSize = new Size( ClientSize.Width, lblWndC000.Location.Y + lblWndC000.Height + 8); } else { var height = (propCount + 5) * 16; if (height > 1600) { height = 1600; } propGrid.Height = height; ClientSize = new Size( ClientSize.Width, propGrid.Location.Y + propGrid.Height); } }
/// <summary> /// Initializes a new instance of the <see cref="ModuleFactory" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemoryManagement.MemorySharp" /> object.</param> internal ModuleFactory(MemoryBase memorySharp) { // Save the parameter MemorySharp = memorySharp; // Create a list containing all injected modules InternalInjectedModules = new List <InjectedModule>(); }
private void TickMemoryThread() { try { IActorRefreshService refreshService = Services.Get <IActorRefreshService>(); while (this.isActive) { Thread.Sleep(16); if (!this.ProcessIsAlive) { return; } while (refreshService.IsRefreshing) { Thread.Sleep(64); } MemoryBase.TickAllActiveMemory(); } } catch (Exception ex) { Log.Write(new Exception("Memory thread exception", ex)); } }
private void cbxType_SelectedIndexChanged(object sender, EventArgs e) { var bdd = (BusDeviceDescriptor)cbxType.SelectedItem; if (bdd == null || !typeof(MemoryBase).IsAssignableFrom(bdd.Type)) { lblRomSet.Visible = false; cbxRomSet.Visible = false; return; } MemoryBase memory = null; if (bdd.Type == m_device.GetType()) { memory = (MemoryBase)m_device; } if (memory == null) { memory = (MemoryBase)Activator.CreateInstance(bdd.Type); } cbxRomSet.SelectedIndex = -1; for (var i = 0; i < cbxRomSet.Items.Count; i++) { if (string.Compare(memory.RomSetName, (String)cbxRomSet.Items[i], true) == 0) { cbxRomSet.SelectedIndex = i; break; } } }
internal Detour(Delegate target, Delegate hook, string name, MemoryBase memory) { _memory = memory; Name = name; _targetDelegate = target; _target = Marshal.GetFunctionPointerForDelegate(target); _hookDelegate = hook; _hook = Marshal.GetFunctionPointerForDelegate(hook); //Store the orginal bytes _orginal = new List <byte>(); _orginal.AddRange(memory.ReadBytes(_target, 6)); //Setup the detour bytes _new = new List <byte> { 0x68 }; var tmp = BitConverter.GetBytes(_hook.ToInt32()); _new.AddRange(tmp); _new.Add(0xC3); var parHack = new Hack(_target, _orginal.ToArray(), _new.ToArray(), Name); HookWardenMemScan.AddHack(parHack); }
/// <summary> /// Initializes a new instance of the <see cref="MemoryFactory" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> internal MemoryFactory(MemoryBase memorySharp) { // Save the parameter MemorySharp = memorySharp; // Create a list containing all allocated memory InternalRemoteAllocations = new List<RemoteAllocation>(); }
/// <summary> /// Initializes a new instance of the <see cref="MemoryFactory" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> internal MemoryFactory(MemoryBase memorySharp) { // Save the parameter MemorySharp = memorySharp; // Create a list containing all allocated memory InternalRemoteAllocations = new List <RemoteAllocation>(); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteModule" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="module">The native <see cref="ProcessModule" /> object corresponding to this module.</param> internal RemoteModule(MemoryBase memorySharp, ProcessModule module) : base(memorySharp, module.BaseAddress) { // Save the parameter Native = module; LazyData = new Lazy<byte[]>( () => MemoryCore.ReadBytes(memorySharp.Handle, module.BaseAddress, module.ModuleMemorySize)); }
/// <summary> /// Initializes a new instance of the <see cref="MarshalledValue{T}" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="value">The value to marshal.</param> public MarshalledValue(MemoryBase memorySharp, T value) { // Save the parameters MemorySharp = memorySharp; Value = value; // Marshal the value Marshal(); }
/// <summary> /// Initializes a new instance of the <see cref="Patch" /> class. /// </summary> /// <param name="address">The address where the patch is located in Memory.</param> /// <param name="patchWith">The bytes to be written.</param> /// <param name="name">The name that represents the current instance.</param> /// <param name="memoryBase">The <see cref="MemoryManagement.MemoryBase" /> reference.</param> public Patch(IntPtr address, byte[] patchWith, string name, MemoryBase memoryBase) { Name = name; MemoryBase = memoryBase; Address = address; PatchBytes = patchWith; OriginalBytes = memoryBase.ReadBytes(address, patchWith.Length); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteModule" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="module">The native <see cref="ProcessModule" /> object corresponding to this module.</param> internal RemoteModule(MemoryBase memorySharp, ProcessModule module) : base(memorySharp, module.BaseAddress) { // Save the parameter Native = module; LazyData = new Lazy <byte[]>( () => MemoryCore.ReadBytes(memorySharp.Handle, module.BaseAddress, module.ModuleMemorySize)); }
internal Patch(IntPtr address, byte[] patchWith, string name, MemoryBase memory) { Name = name; _memory = memory; _address = address; _patchBytes = patchWith; _originalBytes = _memory.ReadBytes(address, patchWith.Length); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteWindow" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemoryManagement.MemorySharp" /> object.</param> /// <param name="handle">The handle of a window.</param> internal RemoteWindow(MemoryBase memorySharp, IntPtr handle) { // Save the parameters MemorySharp = memorySharp; Handle = handle; // Create the tools Keyboard = new MessageKeyboard(this); Mouse = new SendInputMouse(this); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteAllocation" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="size">The size of the allocated memory.</param> /// <param name="protection">The protection of the allocated memory.</param> /// <param name="mustBeDisposed">The allocated memory will be released when the finalizer collects the object.</param> internal RemoteAllocation(MemoryBase memorySharp, int size, MemoryProtectionFlags protection = MemoryProtectionFlags.ExecuteReadWrite, bool mustBeDisposed = true) : base(memorySharp, MemoryCore.Allocate(memorySharp.Handle, size, protection)) { // Set local vars MustBeDisposed = mustBeDisposed; IsDisposed = false; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyTransaction" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="address">The address where the assembly code is injected.</param> /// <param name="autoExecute">Indicates whether the assembly code is executed once the object is disposed.</param> public AssemblyTransaction(MemoryBase memorySharp, IntPtr address, bool autoExecute) { // Save the parameters MemorySharp = memorySharp; IsAutoExecuted = autoExecute; Address = address; // Initialize the string builder Mnemonics = new StringBuilder(); }
/// <summary> /// Injects the specified module into the address space of the remote process. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="path"> /// The path of the module. This can be either a library module (a .dll file) or an executable module /// (an .exe file). /// </param> /// <returns>A new instance of the <see cref="InjectedModule" />class.</returns> internal static InjectedModule InternalInject(MemoryBase memorySharp, string path) { // Call LoadLibraryA remotely var thread = memorySharp.Threads.CreateAndJoin(memorySharp["kernel32"]["LoadLibraryA"].BaseAddress, path); // Get the inject module if (thread.GetExitCode<IntPtr>() != IntPtr.Zero) return new InjectedModule(memorySharp, memorySharp.Modules.NativeModules.First(m => m.BaseAddress == thread.GetExitCode<IntPtr>())); return null; }
public Memory(MemoryBase memory) { _id = memory.MemoryBaseId; Name = memory.Name; CoverImage = new Image(memory.CoverImage); BgmFile = memory.BgmFile; Images = memory.Images == null ? new List <Image>() : memory.Images.Select(image => new Image(image)).ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteThread" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemoryManagement.MemorySharp" /> object.</param> /// <param name="thread">The native <see cref="ProcessThread" /> object.</param> /// <param name="parameter">The parameter passed to the thread when it was created.</param> internal RemoteThread(MemoryBase memorySharp, ProcessThread thread, IMarshalledValue parameter = null) : this(memorySharp, thread) { // Save the parameter _parameter = parameter; // Create the task _parameterCleaner = new Task(() => { Join(); _parameter.Dispose(); }); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteThread" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemoryManagement.MemorySharp" /> object.</param> /// <param name="thread">The native <see cref="ProcessThread" /> object.</param> internal RemoteThread(MemoryBase memorySharp, ProcessThread thread) { // Save the parameters MemorySharp = memorySharp; Native = thread; // Save the thread id Id = thread.Id; // Open the thread Handle = ThreadCore.OpenThread(ThreadAccessFlags.AllAccess, Id); // Initialize the TEB Teb = new ManagedTeb(MemorySharp, ManagedTeb.FindTeb(Handle)); }
/// <summary> /// Disables the memorySharp patch. /// </summary> public void Disable() { try { MemoryBase.WriteBytes(Address, OriginalBytes); IsApplied = false; } catch { IsApplied = false; // Ignored. } }
/// <summary> /// Injects the specified module into the address space of the remote process. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="path"> /// The path of the module. This can be either a library module (a .dll file) or an executable module /// (an .exe file). /// </param> /// <returns>A new instance of the <see cref="InjectedModule" />class.</returns> internal static InjectedModule InternalInject(MemoryBase memorySharp, string path) { // Call LoadLibraryA remotely var thread = memorySharp.Threads.CreateAndJoin(memorySharp["kernel32"]["LoadLibraryA"].BaseAddress, path); // Get the inject module if (thread.GetExitCode <IntPtr>() != IntPtr.Zero) { return(new InjectedModule(memorySharp, memorySharp.Modules.NativeModules.First(m => m.BaseAddress == thread.GetExitCode <IntPtr>()))); } return(null); }
/// <summary> /// Enables the memorySharp patch. /// </summary> public void Enable() { try { MemoryBase.WriteBytes(Address, PatchBytes); IsApplied = true; } catch { IsApplied = false; // Ignored } }
/// <summary> /// Initializes a new instance of the <see cref="MemoryProtection" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="baseAddress">The base address of the memory to change the protection.</param> /// <param name="size">The size of the memory to change.</param> /// <param name="protection">The new protection to apply.</param> /// <param name="mustBeDisposed">The resource will be automatically disposed when the finalizer collects the object.</param> public MemoryProtection(MemoryBase memorySharp, IntPtr baseAddress, int size, MemoryProtectionFlags protection = MemoryProtectionFlags.ExecuteReadWrite, bool mustBeDisposed = true) { // Save the parameters _memorySharp = memorySharp; BaseAddress = baseAddress; NewProtection = protection; Size = size; MustBeDisposed = mustBeDisposed; // Change the memory protection OldProtection = MemoryCore.ChangeProtection(_memorySharp.Handle, baseAddress, size, protection); }
private void TickMemoryThread() { try { while (this.isActive) { Thread.Sleep(16); MemoryBase.TickAllActiveMemory(); } } catch (Exception ex) { Log.Write(new Exception("Memory thread exception", ex)); } }
internal Detour(Delegate target, Delegate hook, string name, MemoryBase memory) { _memory = memory; Name = name; _targetDelegate = target; _target = (uint)Marshal.GetFunctionPointerForDelegate(target); _hookDelegate = hook; _hook = Marshal.GetFunctionPointerForDelegate(hook); //Store the orginal bytes _orginal = new List <byte>(); _orginal.AddRange(memory.ReadBytes(_target, 6)); //Setup the detour bytes _new = new List <byte> { 0x68 }; byte[] tmp = BitConverter.GetBytes(_hook.ToInt32()); _new.AddRange(tmp); _new.Add(0xC3); }
/// <summary> /// Initializes a new instance of the <see cref="WindowFactory" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemoryManagement.MemorySharp" /> object.</param> internal WindowFactory(MemoryBase memorySharp) { // Save the parameter MemorySharp = memorySharp; }
/// <summary> /// Frees the loaded dynamic-link library (DLL) module and, if necessary, decrements its reference count. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="module">The module to eject.</param> internal static void InternalEject(MemoryBase memorySharp, RemoteModule module) { // Call FreeLibrary remotely memorySharp.Threads.CreateAndJoin(memorySharp["kernel32"]["FreeLibrary"].BaseAddress, module.BaseAddress); }
/// <summary> /// Initializes a new instance of the <see cref="RemotePointer" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemoryManagement.MemorySharp" /> object.</param> /// <param name="address">The location where the pointer points in the remote process.</param> public RemotePointer(MemoryBase memorySharp, IntPtr address) { // Save the parameters MemorySharp = memorySharp; BaseAddress = address; }
/// <summary> /// Initializes a new instance of the <see cref="Manager<T>" /> class. /// </summary> /// <param name="memory">The memory.</param> /// <remarks> /// Created 2012-01-16 17:43 by Nesox. /// </remarks> internal Manager(MemoryBase memory) { Memory = memory; }
public RemoteFunction(MemoryBase memorySharp, IntPtr address, string functionName) : base(memorySharp, address) { // Save the parameter Name = functionName; }
/// <summary> /// Initializes a new instance of the <see cref="InjectedModule" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="module">The native <see cref="ProcessModule" /> object corresponding to the injected module.</param> /// <param name="mustBeDisposed">The module will be ejected when the finalizer collects the object.</param> internal InjectedModule(MemoryBase memorySharp, ProcessModule module, bool mustBeDisposed = true) : base(memorySharp, module) { // Save the parameter MustBeDisposed = mustBeDisposed; }
/// <summary> /// RemoteCall constructor. /// </summary> /// <param name="sharp">The <see cref="MemoryManagement.MemoryBase" /> Instance to use.</param> /// <param name="address">The address where the RemoteCall function is stored in memory.</param> /// <param name="callingConvention">The <see cref="CallingConventions" /> the RemoteCall uses.</param> public RemoteCall(MemoryBase sharp, IntPtr address, CallingConventions callingConvention) { Memory = sharp; BaseAddress = address; CallingConvention = callingConvention; }
internal DetourManager(MemoryBase memory) : base(memory) { }
/// <summary> /// Initializes a new instance of the <see cref="ManagedTeb" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> /// <param name="address">The location of the teb.</param> internal ManagedTeb(MemoryBase memorySharp, IntPtr address) : base(memorySharp, address) { }
/// <summary> /// Initializes a new instance of the <see cref="ThreadFactory" /> class. /// </summary> /// <param name="memorySharp">The reference of the <see cref="MemorySharp" /> object.</param> internal ThreadFactory(MemoryBase memorySharp) { // Save the parameter MemorySharp = memorySharp; }