Go Back   Velocity Reviews > Newsgroups > Computer Security
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Computer Security - How do I create a UUDECODE program in C or c++

 
Thread Tools Search this Thread
Old 07-21-2004, 12:40 AM   #1
Default How do I create a UUDECODE program in C or c++


This is the answer to your question:



// UUDECODE - a Win32 utility to uudecode single files.

// Copyright (C) 1998 Clem Dye

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

// Modified 13 July 2001 by Clem Dye to allow any character in the
range 0 to
// 7 in the 'begin' statement within the header of the uuencoded file
being
// decoded.


#include <stdio.h>
#include <string.h>
#define DEC(c) (((c) - ' ') & 077)
static char outname[200];
int ReadDataLine(FILE *f,char *buf)
{
int c,i;

i=0;
while ((c=fgetc(f)) != EOF) {
if (c == '\n') break;
if (c != '\r') {
buf[i++] = c;
}
}
buf[i] = 0;
return(c == EOF ? 0 : 1);
}

static char *uudecode (FILE *f)
{
register int n;
register char ch, *p;
char buf[2 * BUFSIZ];
FILE *out;

do {
if (!ReadDataLine(f,buf)) return(NULL);
}
while (strncmp(buf,"begin",5));
p = buf + 6;


while(*p && (strchr(" 01234567",*p))) p++;
//while (*p && (*p == ' '|| *p == '0' || *p == '6')) p++; // Clem
Dye, 13 July 2001.
strcpy(outname,p);
/* Create output file and set mode. */
out = fopen(outname,"wb");
/* For each input line: */
while (1)
{
if (!ReadDataLine(f,buf)) break;
if (!strncmp(buf,"end\r\n",5)) break;
p = buf;

/* N is used to avoid writing out all the characters at the end
of the file. */

n = DEC (*p);
if (n <= 0)
break;
for (++p; n > 0; p += 4, n -= 3)
{
if (n >= 3)
{
ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
fputc(ch,out);
ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
fputc (ch,out);
ch = DEC (p[2]) << 6 | DEC (p[3]);
fputc (ch,out);
}
else
{
if (n >= 1)
{
ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
fputc (ch,out);
}
if (n >= 2)
{
ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
fputc (ch,out);
}
}
}
}

fclose(out);
return outname;
}

int main(int argc,char *argv[])
{
FILE *f;

if (argc <= 1) {
printf("Usage: %s <input file>\n",argv[0]);
return(1);
}
f = fopen(argv[1],"rb");
if (f == NULL) {
printf("I can't find %s\n",argv[1]);
return(1);
}
uudecode(f);
fclose(f);
printf("Result decoded in %s\n",outname);
return(0);
}


Anonieko Ramos
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to burn copy CD/DVD and create Data/Audio/Video Disc? dvdloveri Software 6 07-27-2009 07:58 AM
Create Your FREE Niche Search Engine For Earning Affiliate Program Bonita F. Steele MCTS 0 03-16-2009 12:01 AM
Create Your FREE Niche Search Engine For Earning Affiliate Program Bonita F. Steele MCITP 0 03-16-2009 12:01 AM
There Is A Program To Easily Create Auction Templates? robinhood General Help Related Topics 0 09-26-2007 03:09 PM
This is incredible! jc_ice DVD Video 1 08-13-2006 10:47 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46