2000-09-14 19:02:50 +04:00
|
|
|
/*
|
|
|
|
* Pageant client code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-12-12 13:33:13 +03:00
|
|
|
#include "puttymem.h"
|
|
|
|
|
2000-09-19 20:29:28 +04:00
|
|
|
#define AGENT_COPYDATA_ID 0x804e50ba /* random goop */
|
|
|
|
#define AGENT_MAX_MSGLEN 8192
|
|
|
|
|
2000-09-14 19:02:50 +04:00
|
|
|
#ifdef TESTMODE
|
|
|
|
#define debug(x) (printf x)
|
|
|
|
#else
|
|
|
|
#define debug(x)
|
|
|
|
#endif
|
|
|
|
|
2000-09-19 20:29:28 +04:00
|
|
|
#define GET_32BIT(cp) \
|
|
|
|
(((unsigned long)(unsigned char)(cp)[0] << 24) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[1] << 16) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[2] << 8) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[3]))
|
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
int agent_exists(void)
|
|
|
|
{
|
2000-09-14 19:02:50 +04:00
|
|
|
HWND hwnd;
|
|
|
|
hwnd = FindWindow("Pageant", "Pageant");
|
|
|
|
if (!hwnd)
|
2001-05-06 18:35:20 +04:00
|
|
|
return FALSE;
|
2000-09-14 19:02:50 +04:00
|
|
|
else
|
2001-05-06 18:35:20 +04:00
|
|
|
return TRUE;
|
2000-09-14 19:02:50 +04:00
|
|
|
}
|
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
void agent_query(void *in, int inlen, void **out, int *outlen)
|
|
|
|
{
|
2000-09-14 19:02:50 +04:00
|
|
|
HWND hwnd;
|
|
|
|
char mapname[64];
|
|
|
|
HANDLE filemap;
|
2000-09-19 20:29:28 +04:00
|
|
|
unsigned char *p, *ret;
|
2000-09-14 19:02:50 +04:00
|
|
|
int id, retlen;
|
|
|
|
COPYDATASTRUCT cds;
|
|
|
|
|
|
|
|
*out = NULL;
|
|
|
|
*outlen = 0;
|
|
|
|
|
|
|
|
hwnd = FindWindow("Pageant", "Pageant");
|
|
|
|
debug(("hwnd is %p\n", hwnd));
|
|
|
|
if (!hwnd)
|
2001-05-06 18:35:20 +04:00
|
|
|
return;
|
2001-05-13 18:02:28 +04:00
|
|
|
sprintf(mapname, "PageantRequest%08x", (unsigned)GetCurrentThreadId());
|
2000-09-19 20:29:28 +04:00
|
|
|
filemap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
|
2001-05-06 18:35:20 +04:00
|
|
|
0, AGENT_MAX_MSGLEN, mapname);
|
2000-09-19 20:29:28 +04:00
|
|
|
if (!filemap)
|
2001-05-06 18:35:20 +04:00
|
|
|
return;
|
2000-09-19 20:29:28 +04:00
|
|
|
p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
|
|
|
|
memcpy(p, in, inlen);
|
|
|
|
cds.dwData = AGENT_COPYDATA_ID;
|
2001-05-06 18:35:20 +04:00
|
|
|
cds.cbData = 1 + strlen(mapname);
|
2000-09-19 20:29:28 +04:00
|
|
|
cds.lpData = mapname;
|
2001-05-06 18:35:20 +04:00
|
|
|
id = SendMessage(hwnd, WM_COPYDATA, (WPARAM) NULL, (LPARAM) & cds);
|
2000-09-14 19:02:50 +04:00
|
|
|
debug(("return is %d\n", id));
|
|
|
|
if (id > 0) {
|
2001-05-06 18:35:20 +04:00
|
|
|
retlen = 4 + GET_32BIT(p);
|
|
|
|
debug(("len is %d\n", retlen));
|
|
|
|
ret = smalloc(retlen);
|
|
|
|
if (ret) {
|
|
|
|
memcpy(ret, p, retlen);
|
|
|
|
*out = ret;
|
|
|
|
*outlen = retlen;
|
|
|
|
}
|
2000-09-14 19:02:50 +04:00
|
|
|
}
|
2000-09-19 20:29:28 +04:00
|
|
|
UnmapViewOfFile(p);
|
|
|
|
CloseHandle(filemap);
|
2000-09-14 19:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TESTMODE
|
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
int main(void)
|
|
|
|
{
|
2000-09-14 19:02:50 +04:00
|
|
|
void *msg;
|
|
|
|
int len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
agent_query("\0\0\0\1\1", 5, &msg, &len);
|
|
|
|
debug(("%d:", len));
|
|
|
|
for (i = 0; i < len; i++)
|
2001-05-06 18:35:20 +04:00
|
|
|
debug((" %02x", ((unsigned char *) msg)[i]));
|
2000-09-14 19:02:50 +04:00
|
|
|
debug(("\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|