tags:

views:

150

answers:

1

I'm trying to redefine this C structure to Lua with alien 0.50 module however I have a two arrays of char at the end. Both szLibraryPath and szLibraryName are originally defined as
char szLibraryPath[MAX_PATH] in C. Can this be done with alien?

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
}
+2  A: 

Take a look at this answer by the author of 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 would get/set the arrays by manually reading/writing bytes at the end of the struct (using the code in the link). To access the second array, add MAX_PATH to all the offsets.

interjay