예제 #1
0
PluginReceiveResult FileListTransfer::OnReceive(Packet *packet)
{
	switch (packet->data[0]) 
	{
	case ID_FILE_LIST_TRANSFER_HEADER:
		DecodeSetHeader(packet);
		return RR_STOP_PROCESSING_AND_DEALLOCATE;
	case ID_FILE_LIST_TRANSFER_FILE:
		DecodeFile(packet, true);
		return RR_STOP_PROCESSING_AND_DEALLOCATE;
	case ID_FILE_LIST_REFERENCE_PUSH:
		OnReferencePush(packet, true);
		return RR_STOP_PROCESSING_AND_DEALLOCATE;
	case ID_FILE_LIST_REFERENCE_PUSH_ACK:
		OnReferencePushAck(packet);
		return RR_STOP_PROCESSING_AND_DEALLOCATE;
	case ID_DOWNLOAD_PROGRESS:
		if (packet->length>sizeof(MessageID)+sizeof(unsigned int)*3)
		{
			if (packet->data[sizeof(MessageID)+sizeof(unsigned int)*3]==ID_FILE_LIST_TRANSFER_FILE)
			{
				DecodeFile(packet, false);
				return RR_STOP_PROCESSING_AND_DEALLOCATE;
			}
			if (packet->data[sizeof(MessageID)+sizeof(unsigned int)*3]==ID_FILE_LIST_REFERENCE_PUSH)
			{
				OnReferencePush(packet, false);
				return RR_STOP_PROCESSING_AND_DEALLOCATE;
			}
		}
		break;
	}

	return RR_CONTINUE_PROCESSING;
}
예제 #2
0
TEST_P (DecoderOutputTest, CompareOutput) {
  FileParam p = GetParam();
#if defined(ANDROID_NDK)
  std::string filename = std::string ("/sdcard/") + p.fileName;
  DecodeFile (filename.c_str(), this);
#else
  DecodeFile (p.fileName, this);
#endif

  unsigned char digest[SHA_DIGEST_LENGTH];
  SHA1Result (&ctx_, digest);
  if (!HasFatalFailure()) {
    CompareHash (digest, p.hashStr);
  }
}
예제 #3
0
int main()
{
//Local Declarations of main
    char actualStr[MAX_CHARS]="";
    char codeStr[MAX_CHARS]="";
    char forEncodingStr[MAX_CHARS]="";
    FILE*infile;
    FILE*outfile;
    FILE*codefile;

//Prompt user for code file name and read into two strings.
    while(ReadCodeFile(codefile,actualStr,codeStr));
    fputs("Code File Read Successfully\n",stdout);
//while loop until the user inputs QUIT or file is NULL
    while ((infile = OpenFile("Enter the name of the file to encode (or QUIT to end program): ", "r")) != NULL &&
           (outfile = OpenFile("Enter the name of the file to store the encoded data (or QUIT to end the program): ", "w+")) != NULL)
    {
        ReadChar(infile,outfile,actualStr,codeStr); //reads infile and outfile and uses the actualStr/codeStr to encode the infile and print to outfile
        DecodeFile(infile,outfile,actualStr,codeStr); //Decodes outfile by using actualStr and codeStr and compares if it is the same as the text in infile. Prints the decoded line onto standard output
        fclose(infile);
        fclose(outfile);
    }
    puts("\nEnding program.");
    return 0;
}
예제 #4
0
TEST_P(DecoderOutputTest, CompareOutput) {
  FileParam p = GetParam();
  DecodeFile(p.fileName, this);

  unsigned char digest[SHA_DIGEST_LENGTH];
  SHA1Result(&ctx_, digest);
  if (!HasFatalFailure()) {
    CompareHash(digest, p.hashStr);
  }
}
예제 #5
0
u32 ppmd_decompress	(void *dest_buffer, const u32 &dest_buffer_size, const void *source_buffer, const u32 &source_buffer_size)
{
    PPMd_Lock();
	ppmd_initialize	();

	stream			source(source_buffer,source_buffer_size);
	stream			dest(dest_buffer,dest_buffer_size);
	DecodeFile		(&dest,&source,order_model,restoration_method_cut_off);

	PPMd_Unlock();
	return			(dest.tell());
}
예제 #6
0
PluginReceiveResult FileListTransfer::OnReceive(RakPeerInterface *peer, Packet *packet)
{
	switch (packet->data[0]) 
	{
	case ID_CONNECTION_LOST:
	case ID_DISCONNECTION_NOTIFICATION:
		RemoveReceiver(packet->playerId);
	break;
	case ID_FILE_LIST_TRANSFER_HEADER:
		DecodeSetHeader(packet);
		return RR_STOP_PROCESSING_AND_DEALLOCATE;
	case ID_FILE_LIST_TRANSFER_FILE:
		DecodeFile(packet);
		return RR_STOP_PROCESSING_AND_DEALLOCATE;
	}

	return RR_CONTINUE_PROCESSING;
}
예제 #7
0
HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
    const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
{
  if (!m_InStream.Create(kBufferSize))
    return E_OUTOFMEMORY;
  if (!m_OutStream.Create(kBufferSize))
    return E_OUTOFMEMORY;

  m_InStream.SetStream(inStream);
  m_InStream.Init();

  m_OutStream.SetStream(outStream);
  m_OutStream.Init();

  CDecoderFlusher flusher(this);

  bool isBZ;
  RINOK(DecodeFile(isBZ, progress));
  return isBZ ? S_OK: S_FALSE;
}
예제 #8
0
HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
    ICompressProgressInfo *progress)
{
  IsBz = false;
  BzWasFinished = false;
  CrcError = false;

  try
  {

  if (!Base.BitDecoder.Create(kBufferSize))
    return E_OUTOFMEMORY;
  if (!m_OutStream.Create(kBufferSize))
    return E_OUTOFMEMORY;

  if (inStream)
    Base.BitDecoder.SetStream(inStream);

  CDecoderFlusher flusher(this);

  if (_needInStreamInit)
  {
    Base.BitDecoder.Init();
    _needInStreamInit = false;
  }
  _inStart = Base.BitDecoder.GetProcessedSize();

  Base.BitDecoder.AlignToByte();

  m_OutStream.SetStream(outStream);
  m_OutStream.Init();

  RINOK(DecodeFile(progress));
  flusher.NeedFlush = false;
  return Flush();

  }
  catch(const CInBufferException &e)  { return e.ErrorCode; }
  catch(const COutBufferException &e) { return e.ErrorCode; }
  catch(...) { return E_FAIL; }
}
예제 #9
0
HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
    bool &isBZ, ICompressProgressInfo *progress)
{
  isBZ = false;
  try
  {

  if (!m_InStream.Create(kBufferSize))
    return E_OUTOFMEMORY;
  if (!m_OutStream.Create(kBufferSize))
    return E_OUTOFMEMORY;

  if (inStream)
    m_InStream.SetStream(inStream);

  CDecoderFlusher flusher(this, inStream != NULL);

  if (_needInStreamInit)
  {
    m_InStream.Init();
    _needInStreamInit = false;
  }
  _inStart = m_InStream.GetProcessedSize();

  m_InStream.AlignToByte();

  m_OutStream.SetStream(outStream);
  m_OutStream.Init();

  RINOK(DecodeFile(isBZ, progress));
  flusher.NeedFlush = false;
  return Flush();

  }
  catch(const CInBufferException &e)  { return e.ErrorCode; }
  catch(const COutBufferException &e) { return e.ErrorCode; }
  catch(...) { return E_FAIL; }
}
예제 #10
0
main() {
    struct sockaddr_in server;
    struct sockaddr_in client;
    pid_t pid;
    int sock;
    int sock_client;
    int sin_size;
    int byte_recv;
    char send_data[1024];
    char recv_data[1024];
    struct hostent *host;
    int stat_val;
    pid_t child_pid;

    int checkuser, checkpass;

    huffman_node_t *huffmanTree;        /* root of huffman tree */
    int opt;
    char *inFile, *outFile;
    MODES mode;
    long numbyte; // number of byte receive
    // Tao kiem soat tin hieu
    signal(SIGCHLD, handle_child);

    if((sock = socket(AF_INET,SOCK_STREAM,0)) == -1) {
        perror("Socket");
        exit(0);
    }
    server.sin_family = AF_INET;
    server.sin_port  = htons(PORT);
    server.sin_addr.s_addr = INADDR_ANY;
    /*   Cach Khac Lay LocalHost
    server.sin_addr = *((struct in_addr *)host->h_addr);
    server.sin_addr.s_addr=inet_ntoa();
    */
    bzero(&(server.sin_zero),8);
    if(bind(sock,(struct sockaddr*)&server,sizeof(struct sockaddr)) == -1) {
        perror("bind() error!!");
        exit(0);
    }
    if(listen(sock,BACKLOG) == -1) {
        perror("Listen() error!!");
        exit(0);
    }


    while(1) {
        sin_size = sizeof(struct sockaddr_in);
        sock_client = accept(sock,(struct sockaddr*)&client,&sin_size);
        if( sock_client == -1) {
            perror("Accept() error!!\n");
            exit(0);
        }

        // Forking Server
        pid = fork();
        switch(pid) {
        case -1: //khong the tao them chuong trinh con
            printf("can't fork()\n");
            break;
        case 0:
            close(sock);       /* Child Socket Listening ; */
            printf("Have a connection from:%s\n\n",inet_ntoa(client.sin_addr));
            send(sock_client,"\t\tDang nhap he thong!\n\t\tUsername:"******"Username: %s \n" , recv_data);
            //kiem tra username
            recv_data[byte_recv-1] = '\0';
            if(strcmp(recv_data,"conghoan")!=0)
            {
                send(sock_client,"sai",50,0);//neu sai ten
                checkuser =-1;
            } else
            {
                send(sock_client,"dung",50,0);//neu dung user
                checkuser =0;
            }
            if(checkuser == -1)
            {
                //send(sock_client,"0",1,0);
                send(sock_client,"\tTai khoan nay chua ton tai, nhap Username => Dang ki\n\t\tUsername:"******"New Username: %s \n" , recv_data);
                send(sock_client,"\tNhap Password => Dang ki\n\t\tPassword:"******"New Password: %s \n" , recv_data);
                send(sock_client,"Dang ki thanh cong",50,0);
                close(sock_client); /* Close With terminal of Child Socket */
                break;
            }
            else {
                send(sock_client,"\n\t\tPassword:"******"Password: %s \n" , recv_data);
                //kiem tra password
                recv_data[byte_recv-1] = '\0';
                if(strcmp(recv_data,"conghoan")!=0)
                {
                    send(sock_client,"sai2",50,0);//sai pass
                    checkpass =-1;
                } else
                {
                    send(sock_client,"dung2",50,0);//dung pass
                    checkpass = 0;
                }
                if(checkpass == -1)//neu sai
                {
                    //send(sock_client,"Dang nhap khong thanh cong",50,0);
                    close(sock_client); /* Close With terminal of Child Socket */
                    break;
                }
                else
                {
                    //menu chuong trinh
                    //send(sock_client,"\t\tWelcome to my server!\n\t\tMenu:\n\t\t1: Ma hoa.\n\t\t2: Giai ma.\n\t\t3: Thoat.",100,0);
                    send(sock_client,"\t\tWelcome to my server!\n\t\tMenu:\n\t\t1: Ma hoa.\n\t\t2: Giai ma.\n\t\t3: Thoat.",200,0);
                    //while(1)
                    //{
                    byte_recv = recv(sock_client,recv_data,1024,0);
                    recv_data[byte_recv] = '\0';
                    if(strcmp(recv_data,"3")==0)
                    {
                        close(sock_client); /* Close With terminal of Child Socket */
                        break;
                    }
                    //if(strcmp(recv_data,"1")==0){
                    else {
                        printf("\nClient da chon: %s -- Ma hoa\n" , recv_data);
                        //nhan file va luu file
                        FILE *pFileluu;
                        pFileluu = fopen ("mahoa.txt", "wb");
                        if ((numbyte = recv(sock_client,recv_data,MAXSIZE,0)) == -1) { /* calls recv() */
                            printf("recv() error\n");
                            exit(-1);
                        }
                        printf ("Da nhan -%ld-ki tu", numbyte);
                        fwrite(recv_data,1,numbyte,pFileluu);//luu lai file da nhan
                        //fclose(pFileluu);
                        printf("File tu Client da Upload: \n%s\n",recv_data); /* it prints server's welcome message =) */
                        fclose(pFileluu);
                        //ma hoa
                        DecodeFile(huffmanArray,"mahoa.txt","ketqua.txt");
                        {
                            FILE * pFile;
                            FILE *pFile1;
                            long lSize;
                            char * buffer;
                            size_t result;

                            int fd, numbytes;	  /* files descriptors */
                            char buf[MAXDATASIZE];  /* buf will store received text */
                            char buf1[MAXDATASIZE];

                            pFile = fopen ("ketqua.txt", "rb" );
                            // pFile1 = fopen ("myfile1.txt", "wb");

                            if (pFile==NULL) {
                                fputs ("File error",stderr);
                                exit (1);
                            }

                            // obtain file size:
                            fseek (pFile , 0 , SEEK_END);
                            lSize = ftell (pFile);
                            rewind (pFile);

                            // allocate memory to contain the whole file:
                            buffer = (char*) malloc (sizeof(char)*lSize);
                            if (buffer == NULL) {
                                fputs ("Memory error",stderr);
                                exit (2);
                            }

                            // copy the file into the buffer:
                            result = fread (buffer,1,lSize,pFile);
                            if (result != lSize) {
                                fputs ("Reading error",stderr);
                                exit (3);
                            }
                            if ((numbytes = send (sock_client, buffer, lSize, 0)) == -1) {
                                printf ("send()error\n");
                                exit(-1);
                            }
                            printf("--%ld ki tu da duoc gui di--\n", lSize);

                            printf ("Ket thuc gui\n");
                            exit(-1);
                            if ((numbytes=recv(fd,buf,MAXDATASIZE,0)) == -1) { /* calls recv() */
                                printf("recv() error\n");
                                exit(-1);
                            }
                        }
                        close(sock_client); /* Close With terminal of Child Socket */
                        break;
                    }
                }
            }
//    if(strcmp(recv_data,"2")==0){//giai ma file
//	    printf("\nClient da chon: %s : Giai ma\n" , recv_data);
//	    //nhan file va hien thi file
//   if ((numbyte = recv(sock_client,recv_data,MAXSIZE,0)) == -1){  /* calls recv() */
//    printf("recv() error\n");
//    exit(-1);
//  }
//   printf ("-%ld-\n", numbyte);
//   printf("File tu Client da Upload: %s\n",recv_data); /* it prints server's welcome message =) */
//   exit(-1);
//        //giai ma
//	  close(sock_client); /* Close With terminal of Child Socket */
//	  break;
//	  }
        //}
        //break;
        case 1:
            if(strcmp(recv_data,"3")==0) {
                close(sock); /* Close Listening */
                break;
            }
            break;
        }
    }

    close(sock_client); /* Parent Close Connect Socket */
}
예제 #11
0
int main(int ac, char * av[])
	{
	APIRET rc;
	HDIR hdir=HDIR_CREATE;
	FILEFINDBUF3 findBuffer;
	ULONG findCount=1;
	char mask[260];
	char * cp;

	errors=0;  //  Counter for batch decoder errors
	errfiles=0;
	errparts=0;

	aDsp=0;            // all debug display
	datadir[0]=0;      // Target directory is actual directory
	ad_despath[260]=0;

	ad_cleanmode=0;    // No special modes for standalone decoder
	ad_crcmode=0;

	print("\r\n");
	print("yDec-v1 (14.Nov.2001) - Public Domain - by Juergen Helbing - www.yenc.org\r\n\r\n");

//	if (ac>=1) print("[0]: %s\r\n",av[0]);
//	if (ac>=2) print("[1]: %s\r\n",av[1]);
//	if (ac>=3) print("[2]: %s\r\n",av[2]);

	if (ac<2)
		{
		print("Missing parameter (filename or filename*.* required) !\r\n");
		usage();
		return(1);
		}
	if (ac>3)
		{
		print("Illegal additional parameters !\r\n");
		usage();
		return(1);
		}

	if (ac==3)
		{
		if (strstr(av[2],"/a")) aDsp=1;
		}

	strcpy(mask,av[1]);

	// local test only
	//	strcpy(mask,"*.ntx");

	// Now find all the mesages and decode them

	if (strchr(mask,'\\')) // Full path found -> is Drag and drop
		{
		strcpy(ad_despath,mask);
		cp=strrchr(ad_despath,'\\');
		if (cp) { *(cp+1)=0; };  // Path for temp and target files

		DecodeFile(mask);

		// For drag and drop support !
		if (errors==0)
			{
			WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,"End of decoder","yDecode",0,MB_OK | MB_INFORMATION);
			}

		goto done;
		}

	// Seek all matching files

	// Find all files which are matching the seek-mask
	rc=DosFindFirst(mask,&hdir,FILE_ARCHIVED|FILE_READONLY,&findBuffer,sizeof(FILEFINDBUF3),&findCount,FIL_STANDARD);
	if (rc) {
		print("No files found to match (%s)\r\n",mask);
		goto done;
	}
	do {
		if (!strstr(findBuffer.achName,".exe")) {
			if (aDsp) print("Decode file: (%s)\r\n",findBuffer.achName);
			DecodeFile(findBuffer.achName);
		}
		rc=DosFindNext(hdir,&findBuffer,sizeof(FILEFINDBUF3),&findCount);
	} while(rc==NO_ERROR);
	DosFindClose(hdir);

done:
	if (errors|errfiles|errparts)
		{
		print("\r\n");
		if (errors) print("%d error(s) during decoding.\r\n",errors);
		if (errfiles) print("%d file(s) with errors stored to disk\r\n",errfiles);
		if (errparts) print("%d corrupt part(s) detected.\r\n",errparts);

		WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,"Decoder terminated. \r\n\r\n Errors found !","yDecode",0,MB_OK|MB_ERROR);
		}

	return(0);
	}
예제 #12
0
int main(int argc, char **argv) {
	int retval = 0;
	char *dparams[2];
	int paramc = 0, params = -1;

	char temp[0x1000];
	int done = 0;
	char *source = NULL;
	int n = 0;

	// Acción a realizar
	int action = ACTION_NONE;

	if (argc <= 1) {
		action = ACTION_HELP;
		setparams(0);
	}

	for (n = 1; n <= argc; n++) {
		char *arg;
		arg = (n < argc) ? argv[n] : "";

		//printf("%s\n", arg);

		// Muestra la ayuda y sale
		if (strcmp(arg, "-?") == 0 || strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
			//show_help();
			action = ACTION_HELP;
			setparams(0);
		}

		// Modificadores
		{
			// Modo raw (sin cabeceras de compresión)
			if (strcmp(arg, "-r") == 0 || strcmp(arg, "-raw") == 0) { raw = 1; continue; }

			// Modo silencioso
			if (strcmp(arg, "-s") == 0) { silent = 1; fclose(stdout); continue; }
		}

		// Acciones
		{
			if (arg[0] == '-') {
				int cnt = 1;

				switch (arg[1]) {
					// Codificad
					case 'c': action = ACTION_ENCODE ; setparams(2); break;
					// Decodificia
					case 'd': action = ACTION_DECODE ; setparams(2); break;
					// Comprueba
					case 't': action = ACTION_TEST   ; setparams(1); break;
					// Crea un perfil de compresión
					case 'p': action = ACTION_PROFILE; setparams(1); break;
					// Dumpea el text_buffer inicial
					case 'b': action = ACTION_BDUMP  ; setparams(1); break;
					default:  cnt = 0; break;
				}

				if (cnt) {
					done = 0;
					modifier = (strlen(arg) >= 3) ? atoi(arg + 2) : 3;
					continue;
				}
			}
		}

		if ((n < argc) && (paramc < params)) {
			dparams[paramc++] = arg;
		}

		if (paramc >= params) {
			show_header_once();

			done = 1;
			switch (action) {
				case ACTION_ENCODE:
					if (strcmp(dparams[0], dparams[1]) != 0) {
						retval |= EncodeFile(dparams[0], dparams[1], raw, modifier);
					} else {
						fprintf(stderr, "Can't use same file for input and output\n");
						retval |= -1;
					}
				break;
				case ACTION_DECODE:
					if (strcmp(dparams[0], dparams[1]) != 0) {
						retval |= DecodeFile(dparams[0], dparams[1], raw, modifier);
					} else {
						fprintf(stderr, "Can't use same file for input and output\n");
						retval |= -1;
					}
				break;
				case ACTION_PROFILE:
					if (strlen(arg) < 0x900) {
						sprintf(temp, "%s.profile", arg);
						ProfileStart(temp);
							retval |= DecodeFile(dparams[0], NULL, raw, modifier);
						ProfileEnd();
					}
				break;
				case ACTION_BDUMP:
					DumpTextBuffer(dparams[0]);
				break;
				case ACTION_TEST:
					retval |= CheckCompression(dparams[0], modifier);
				break;
				case ACTION_HELP:
					show_help();
				break;
				default:
					if (n == argc) {
						if (paramc == params || params == 0) exit(retval);
						if (params == -1) show_help();
						fprintf(stderr, "Expected %d params, but %d given\n", params, paramc);
						exit(-1);
					}
					fprintf(stderr, "Unknown parameter '%s'\n", arg);
					exit(-1);
				break;
			}

			paramc = params = 0;
			action = ACTION_NONE;
		}
	}

	show_header_once();

	fprintf(stderr, "Expected %d params, but %d given\n", params, paramc);
	exit(-1);

	return 0;
}