Ejemplo n.º 1
0
/* test code */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
{
	int clicked;
	char comments[32];
	HINSTANCE hTest = GetModuleHandle(NULL);
	assert(hInstance == hTest);

	if (sendbox_create(iCmdShow, 32)) {
		MessageBox(NULL, "sendbox_create failed!", "Failure", MB_ICONEXCLAMATION);
		return 1;
	}

	while ((clicked = sendbox_poll(comments)) == sendbox_CLICKED_NONE) {
		Sleep(100);
	}
	sendbox_destroy();
	if (clicked == sendbox_CLICKED_OK) {
		MessageBox(NULL, comments, "Success", MB_ICONEXCLAMATION);
	} else {
		MessageBox(NULL, "User cancelled", "Success", MB_ICONEXCLAMATION);
	}
	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
	sbdclnt_t *sbdclnt;
	int port;
	int clicked;
	clock_t timeout;
	aeh_t aeh;
	int ninst;
	char comments[sendcrsh_COMMENT_MAXLEN];
	int len, lensent;
	char buf[sbd_MAXLEN];
	int pos;
	unsigned long crc;
	char signature[10];
	int i = 0;

	logprint_setFile("sendcrsh.log");

	if (!checkEnvironment()) {
		DPRINT(("anet2.dll did not set our environment!\n"));
		return 1;
	}
	if (!checkUnique()) {
		DPRINT(("Another instance of sendcrsh was running!\n"));
		return 1;
	}

	if (argc <= 3) { /* Usage: sendcrsh <host> <port> <hexdata> */
		DPRINT(("sendcrsh invoked with fewer than 3 arguments\n"));
		return 1;
	}
	DPRINT(("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]));

	port = atoi(argv[2]);
	if ((port < 1024) || (port > 65536)) {
		DPRINT(("sendcrsh invoked with invalid port %d\n", port));
		return 1;
	}

	if (NULL == hex2buf(argv[3], buf, 2)) {
		DPRINT(("hex2buf(datalen) failed\n"));
		return 1;
	}
	len = dpMAKESHORT(buf[0], buf[1]);
	if (NULL == hex2buf(argv[3] + 4, buf, len)) {
		DPRINT(("hex2buf(data) failed\n"));
		return 1;
	}
	if (argv[3][4 + 2*len] != '\0') {
		DPRINT(("data does not end at datalen:%d\n", len));
		return 1;
	}
	if (len > sbd_MAXLEN) {
		DPRINT(("datalen:%d is greater than max:%d\n", len, sbd_MAXLEN));
		return 1;
	}
	pos = getLastRecord(buf, len, &aeh, &ninst);
	if (pos == -1) {
		DPRINT(("getLastRecord failed\n"));
		return 1;
	}
	if (aeh.nstk == 0) {
		DPRINT(("exception has 0 length stack trace\n"));
	}
	crc = aeh_getSignature(&aeh);
	if (crc == 0) {
		DPRINT(("aeh_getSignature returns 0 crc, error?\n"));
	}
	aeh_signature_toString(crc, signature);

	DPRINT(("%s to %s:%d len:%d data:%s\n", argv[0], argv[1], port, len,
		argv[3] + 4));
	sendbox_create(winCmdShow, signature, sendcrsh_COMMENT_MAXLEN, 120);
	while (1) {
		clock_t now = eclock();

		clicked = sendbox_poll(comments);
		if (clicked != sendbox_CLICKED_NONE) {
			DPRINT(("t:%d, clicked:%d, breaking\n", now, clicked));
			break;
		}
		Sleep(100);
		if (!((++i)%10)) {
			DPRINT(("%dth call to sendbox_poll at t:%d\n", i, now));
		}
	}
	sendbox_destroy();

	if (clicked != sendbox_CLICKED_OK) {
		DPRINT(("User cancelled send, clicked:%d\n", clicked));
		return 0;
	}

	timeout = eclock() + 30 * ECLOCKS_PER_SEC;
	/* add the comments to the buffer */
	if (comments[0]) {
		aeh_buf_t aehbuf;
		int commentlen = strlen(comments);
		int nwritten;

		if ((len + sizeof(unsigned int /* aeh_info_t.id */) + sizeof(commentlen) + commentlen) > sbd_MAXLEN) {
			DPRINT(("no room in buf for comment\n"));
			return 1;
		}
		/* stuff the comment into the info list */
		if (aeh_RES_OK != aeh_addComment(&aeh, comments)) {
			DPRINT(("aeh_addComment failed\n"));
			return 1;
		}
		/* convert it back to a buf */
		if (aeh_RES_OK != aeh_writeOutputStream(&aeh, &aehbuf)) {
			DPRINT(("can't convert aeh back to aehbuf\n"));
			return 1;
		}
		DPRINT(("writing new record at pos:%d buf:\n", pos));
		dumpbuf(aehbuf.buf, aehbuf.buflen);
		nwritten = aehlog_writetobuf(&aehbuf, ninst, buf+pos, sbd_MAXLEN-pos);
		if (-1 == nwritten) {
			DPRINT(("can't convert aehbuf back to buf\n"));
			return 1;
		}
		len = pos + nwritten;
	}
	aeh_Destroy(&aeh);

	/* send the buffer */
	sbdclnt = sbdclnt_create(buf, len, argv[1], (unsigned short)port);
	if (sbdclnt == NULL) {
		DPRINT(("sbdclnt_create failed\n"));
		return 1;
	}
	while ((long)(eclock() - timeout) < 0) {
		lensent = sbdclnt_poll(sbdclnt);
		if (lensent != 0)
			break;
		Sleep(100);
	}
	sbdclnt_destroy(sbdclnt);
	if (lensent != len) {
		DPRINT(("send only %d of %d bytes!\n", lensent, len));
		return 1;
	}
	DPRINT(("send completed successfully\n"));
	return 0;
}