Lua and Alien Structures

I am trying to override this C structure in Lua using the 0.50 module, but I have two char arrays at the end. Both szLibraryPath, and are szLibraryNameinitially defined as   char szLibraryPath[MAX_PATH]in C. Can this be done with aliens?

LIBRARY_ITEM_DATA = alien.defstruct{
  { "hFile", "long" },
  { "BaseOfDll", "long" },
  { "hFileMapping", "long" },
  { "hFileMappingView", "long" },
  { "szLibraryPath", "byte" },  -- fix to MAX_PATH
  { "szLibraryName", "byte" }   -- fix to MAX_PATH
}
+3
source share
1 answer

Check out this answer by Alien.

Your structure should look like this:

LIBRARY_ITEM_DATA = alien.defstruct{
  { "hFile", "long" },
  { "BaseOfDll", "long" },
  { "hFileMapping", "long" },
  { "hFileMappingView", "long" },
  { "additionalFields", "char" }
}
LIBRARY_ITEM_DATA.size = LIBRARY_ITEM_DATA.size + 2*MAX_PATH - 1

And you will get / set the arrays by manually reading / writing bytes at the end of the structure (using the code in the link). To access the second array, add MAX_PATH to all offsets.

+2
source

Source: https://habr.com/ru/post/1726653/


All Articles