Dewera / Lunar

A lightweight native DLL mapping library that supports mapping directly from memory
MIT License
585 stars 102 forks source link

Few features ideas/wishlist #32

Closed jesterret closed 3 years ago

jesterret commented 3 years ago

Hi, I would like to suggest some small, some big changes that might be useful:

  1. Expose image size of the mapped library,
  2. Add (optional?) argument to MapLibrary, for specifying desired allocation address, as in VirtualAllocEx.
  3. Allow for swapping pinvoke functionality with user defined code - would require swapping extension methods on Process, into some wrapper class, and some public interface taken as an argument in LibraryMapper constructor. Would allow users to bypass process protections etc.

Thanks for making this library, hope You'll consider some of those :)

Dewera commented 3 years ago

I'm opposed to adding niche features like suggested in 2 and 3 to avoid bloating the library with things that should really be done in personal copies/forks. The goal of this project is really just to be an emulation of the Windows loader (there's a few more things I need to port over from my private code to finish it off) which users can then adapt to their own personal needs based on what they are using it for.

Regarding the first suggestion, I'm not entirely sure what value this would add. If you really did need mapped image size, it can be derived from the headers prior to mapping using the following

using var peReader = new PEReader(imageBytes.ToArray().ToImmutableArray());
var imageSize = peReader.PEHeaders.PEHeader!.SizeOfImage;
jesterret commented 3 years ago

Honestly, first one, it's mostly convenience. I know I can read it from headers, it's basically doing the same thing twice, since it's read internally anyway. As for the rest, if that's the direction You intend the library to go, that's fair. I'll go with Your suggestion then probably.