|
/*
Fake NetSend for Windows NT/2000/XP v1.01
Written by me (Caio Proiete).
mailto:caio@proiete.com.br
Copyright (c) 2003.
If you find any bugs, please notify me!
You may use it, abuse it, redistribute it, in any way
you desire, but don't change the author credits ;)
HISTORY
2003-06-08 - First version. Bugs: Zero, I hope :)
2003-06-11 - Version 1.01. Just improving the code.
*/
const char szAbout[] = \
"Fake NetSend for Windows NT/2000/XP v1.01\n" \
"by Caio Proiete (caio@proiete.com.br)\n";
const char szUsage[] = \
"Usage: FakeSend [Sender] [Receiver] \"[Message]\"\n" \
"Example: FakeSend James Kevin \"Hi Kevin this is James!\"\n";
const char szMailSlotPath[] = "\\\\%s\\MAILSLOT\\messngr";
const char szMsgFormat[] = "%s\r%s\r%s\r";
const unsigned char nTotalParam = 4;
bool NetSend(const char * szSender, const char * szReceiver,
const char * szMessage);
// Exclude rarelly used Windows stuff
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <windows.h>
int main(int argc, char **argv)
{
///////////////////////////////////////////
// What do we expect in argv variable? //
///////////////////////////////////////////
// argv[0] = Application PathName //
// argv[1] = Sender's Name //
// argv[2] = Receiver's Login or Machine //
// argv[3] = Message //
///////////////////////////////////////////
// We have all needed parameters?
if (argc == nTotalParam)
{
// Just showing a status
printf("%s\n" \
"Sending Fake Message:\n" \
"Sender...: %s\n" \
"Receiver.: %s\n" \
"Message..: %s\n",
szAbout,
argv[1],
argv[2],
argv[3]);
if (NetSend(argv[1], argv[2], argv[3]))
printf("Message sent!\n");
else
printf("Error sending the message!\n");
}
else
printf("%s\n%s", szAbout, szUsage); // Show About and Usage descriptions
return 0;
}
/*
This function takes the Sender's and Receiver's Name,
the Message and then send the "Fake" message
*/
bool NetSend(const char * szSender, const char * szReceiver,
const char * szMessage)
{
// Our main variables
char * pszMailSlot = NULL;
unsigned char * pucMessage = NULL;
unsigned int nMailSlotLen, nMsgFormatLen;
HANDLE hHandle;
DWORD dwBytesWritten;
bool bRet = false;
// Get the length of the strings
nMailSlotLen = strlen(szReceiver) + sizeof(szMailSlotPath);
nMsgFormatLen = strlen(szSender) + strlen(szReceiver) +
strlen(szMessage) + sizeof(szMsgFormat);
// Allocate necessary memory
pszMailSlot = new char[nMailSlotLen];
pucMessage = new unsigned char[nMsgFormatLen];
// Network path for <Receiver> MailSlot:
// "\\Receiver\MAILSLOT\messngr"
sprintf(pszMailSlot, szMailSlotPath, szReceiver);
// Message Format:
// "Sender\0Receiver\0Message\0"
// sprintf doesn't work with \0 so here I'm using \r
sprintf((char *)pucMessage, szMsgFormat, szSender,
szReceiver, szMessage);
// Replace all '\r' characters with '\0'
for (unsigned short i = 0; i < nMsgFormatLen; i++)
{
if (pucMessage[i] == '\r')
pucMessage[i] = '\0';
else if (pucMessage[i] == '\0')
break;
}
// Create the file into Receiver's MailSlot and get a Handle to this file
hHandle = CreateFile(pszMailSlot, GENERIC_WRITE, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
// We have a valid handle?
if (hHandle)
{
// Write the message to file
bRet = (WriteFile(hHandle, pucMessage, (DWORD)nMsgFormatLen,
&dwBytesWritten, NULL) == TRUE);
// Free the handle
CloseHandle(hHandle);
}
return bRet;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.