Giter Site home page Giter Site logo

bluerain's People

Contributors

aevitas avatar psytrx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bluerain's Issues

`ExternalProcessMemory` throws `NullReferenceException` when `createInjector = true`

MCVE:

    internal class Program
    {
        private static void Main(string[] args)
        {
            var dllPath = @"C:\mydll.dll";
            var process = Process.GetProcessesByName("csgo").Single();
            var memory = new ExternalProcessMemory(process, true);
            var module = memory.Injector.Inject(dllPath);
        }
    }

The ExternalProcessMemory constructor throws a NullReferenceException when being called with createInjector = true. This is due to the constructor in question calling its base constructor (in which the Injector gets instantiated) before the ProcessHandle gets instantiated, which is required for injection.

See https://github.com/aevitas/bluerain/blob/v2/src/BlueRain/ExternalProcessMemory.cs#L36

My suggestion is to move
ProcessHandle = OpenProcess(access, false, process.Id);
up into its base constructor with sane ProcessAccess defaults.

Any thoughts?

Optimize Read<T> to avoid marshalling of primitive types

Currently, the implementation of ExternalProcessMemory simply calls ReadBytes to read the length of type T from memory, and then feeds it to the marshal. Since marshalling is relatively expensive (read: very expensive), we should consider directly dereferencing the buffer ptr, and avoid the marshal entirely.

about marshalling

hi, i tested a method inspirated by yours like ๐Ÿ‘

Marshal.SizeOf(typeof(T)); to get the buffer size in generic Read method... i got it work with an integer

is that a correct way to doit?

There's no public API for setting Injector._ejectOnDispose

As the Injector constructor is internal, theres just ExternalProcessMemory.ctor to instantiate an Injector. However, there's no way to set _ejectOnDispose if you want the injected modules to get free'd.

Ideas:

  • Expose _ejectOnDispose as a public get/set property
    • as long as there aren't too many options to pass, this might be a simple and clean solution
  • Add InjectorInitializationParameters to the ExternalProcessMemory.ctor
    • This can also bundle createInjector, which seems like a clean approach
  • Pass it as an optional argument to ExternalProcessMemory.ctor
    • this may clutter the API as well as being a breaking change

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.