ajpc500 / NimlineWhispers

A very proof-of-concept port of InlineWhispers for using syscalls in Nim projects.
164 stars 19 forks source link

Define procs as global and add types #2

Open chvancooten opened 3 years ago

chvancooten commented 3 years ago

First of all - thanks for the excellent work on this Repo! I haven't gotten static syscalls to work yet in plain Nim, but that's likely due to my own newbieness with the subject. This repo seems very promising in making that possible (and quite easy).

Some observations from playing with this myself:

  1. Procs defined in syscalls.nim should probably be defined as globals (i.e. NtAllocateVirtualMemory*(...) instead of NtAllocateVirtualMemory(...)) so that they can be imported.

  2. It would be great if the script takes care of adding the right types (also as globals) right there within syscalls.nim, so we don't have to go and specify these manually every time (when winim is not imported). An example, but there are probably some missing (this is only for NtAllocateVirtualMemory and NtProtectVirtualMemory).

type
    DWORD* = int32
    SIZE_T* = int64
    HANDLE* = int
    PVOID* = pointer
    PULONG* = ptr int32
    ULONG* = int32
    PSIZE_T* = ptr int64
    NTSTATUS* = int32
  1. Some examples of Nim scripts that actually use these calls would be greatly appreciated. I've been trying for a bit to get the abovementioned functions to work in Nim, but no love yet 😅. It seems quite easy to do in C/C++, but translating that to Nim syntax remains a challenge for me (and I'm sure others with me).

Thanks again for your great work!

ajpc500 commented 3 years ago

Hey Cas, appreciate the kind words!🙂 There's definitely refinements to be made - some I expect will become obvious as I use the language more. On your points:

  1. Completely right - i've pushed a fix to address that now.

  2. Yeah, this is a big one. As you'll see in point 3, even including winim doesn't solve all the struct definitions for every use case. Might be a case of manually building some structs dynamically, much like we're doing already with the function definition.

  3. I did a small writeup here with example code here. Not many examples atm (one 😛), but I'll add some more in due course!

chvancooten commented 3 years ago

Superb! I think that example is already very helpful, since it makes use of various direct syscalls and showcases well how to "translate" the data types required. The blog post is also inspiring, thanks for this!

If I find some time on short notice I'll look into the type definition without needing Winim and submit a PR if I can figure it out. I think that would take the 'sharp edge' off of using Nimline Whispers for many!