Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/inlineExecute-Assembly.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ BOOL ReadSlot(char* output, HANDLE* mailHandle)
LPSTR lpszBuffer = NULL;
size_t size = 65535;
char* achID = (char*)intAlloc(size);
if (NULL == achID)
return FALSE;
memset(achID, 0, size);
DWORD cAllMessages = 0;
HANDLE hEvent;
OVERLAPPED ov;

_CloseHandle CloseHandle = (_CloseHandle) GetProcAddress(GetModuleHandleA("kernel32.dll"), "CloseHandle");

hEvent = KERNEL32$CreateEventA(NULL, FALSE, FALSE, NULL);
if (NULL == hEvent)
return FALSE;
Expand All @@ -53,11 +57,13 @@ BOOL ReadSlot(char* output, HANDLE* mailHandle)

if (!fResult)
{
CloseHandle (hEvent);
return FALSE;
}

if (cbMessage == MAILSLOT_NO_MESSAGE)
{
CloseHandle (hEvent);
return TRUE;
}

Expand All @@ -68,7 +74,10 @@ BOOL ReadSlot(char* output, HANDLE* mailHandle)
//Allocate memory for the message.
lpszBuffer = (LPSTR)KERNEL32$GlobalAlloc(GPTR, KERNEL32$lstrlenA((LPSTR)achID) * sizeof(CHAR) + cbMessage);
if (NULL == lpszBuffer)
{
CloseHandle (hEvent);
return FALSE;
}
lpszBuffer[0] = '\0';

fResult = KERNEL32$ReadFile(*mailHandle,
Expand All @@ -80,6 +89,7 @@ BOOL ReadSlot(char* output, HANDLE* mailHandle)
if (!fResult)
{
KERNEL32$GlobalFree((HGLOBAL)lpszBuffer);
CloseHandle (hEvent);
return FALSE;
}

Expand All @@ -94,14 +104,15 @@ BOOL ReadSlot(char* output, HANDLE* mailHandle)

if (!fResult)
{
KERNEL32$GlobalFree((HGLOBAL)lpszBuffer);
CloseHandle (hEvent);
return FALSE;
}

}

cbMessage = 0;
KERNEL32$GlobalFree((HGLOBAL)lpszBuffer);
_CloseHandle CloseHandle = (_CloseHandle) GetProcAddress(GetModuleHandleA("kernel32.dll"), "CloseHandle");
CloseHandle(hEvent);
return TRUE;
}
Expand Down Expand Up @@ -382,8 +393,8 @@ void go(char* args, int length) {//Executes .NET assembly in memory
int argumentCount = 0;
HANDLE stdOutput;
HANDLE stdError;
HANDLE mainHandle;
HANDLE hFile;
HANDLE mainHandle = INVALID_HANDLE_VALUE;
HANDLE hFile = INVALID_HANDLE_VALUE;
size_t wideSize = 0;
size_t wideSize2 = 0;
BOOL success = 1;
Expand Down Expand Up @@ -580,8 +591,10 @@ void go(char* args, int length) {//Executes .NET assembly in memory

//Close handles
_CloseHandle CloseHandle = (_CloseHandle) GetProcAddress(GetModuleHandleA("kernel32.dll"), "CloseHandle");
CloseHandle(mainHandle);
CloseHandle(hFile);
if (INVALID_HANDLE_VALUE != mainHandle)
CloseHandle(mainHandle);
if (INVALID_HANDLE_VALUE != hFile)
CloseHandle(hFile);

//Revert stdout back to original handles
success = SetStdHandle(((DWORD)-11), stdOutput);
Expand Down