typedef struct Data {
int len;
int flag;
char values[1000];
} *Data;
PData = *Data;
and the exports function of the DLL like below:
Data* GetData(int index, int flag); cdcel;
require "Win32API"
getData = Win32API.new('filename.dll', 'GetData', ['I', 'I'], 'P');
pdata = getData.call(100, 10)
We might not get the correct data by pdata, because the pdata might be truncated. The "P" declaration only worked for import sections but does not work as well for export section.
@CopyMemory = Win32API.new('Kernel32.dll', 'RtlMoveMemory', ['P', 'I', 'I'], '0')
then, we need to change the Win32API export of the API as 'L':
getData = Win32API.new('filename.dll', 'GetData', ['I', 'I'], 'L')
now, we can call the API like before:
pd = getData.call(100, 10)
Last, we get data by the pointer via CopyMemory API:
buf = Array.new(buf_size, 0).pack('L*')
@CopyMemory.call(buf, pd, buf_size)
The buf saved the returned data now. you can process them, for this tips, we can process the data like below:
len, flag = buf.unpack('I2')
values = buf[9, len]
Of course, you should give the right buf_size, otherwise you might get AV error or crash.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)