Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fmask [c posix]

Name: Anonymous 2014-05-03 7:06

This is the main code, resize.c, reverse.c, xor.c, swap.c, rswap.c will be posted you want to see them. Hope you like...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

#define PROGRAM_VERSION "1.1"
#define BIN_PATH "bin/"

struct { const char *p, *s; } cmds[] = {
{ "swap", "rswap" },
{ "blowfish", "blowfish_dec" },
{ "rc4", "rc4_dec" },
{ "aes", "aes_dec" }
};

void help(void)
{
printf("fmask v. %s -- apply masks to files\n"
"fmask [operation_1 ... operation_k] <file>\n"
"operation may be: reverse, swap, xor, aes, "
"blowfish or rc4\n", PROGRAM_VERSION);
}

char **push(char *p)
{
static char *s[128], **q = s + 1;
*q = malloc(strlen(p) + 1);
strcpy(*q, p);
return q++;
}

char *inversecmd(char *p)
{
static char r[128];
size_t i;
char *s = strchr(p, ' ');

if(s && s - p < sizeof r) {
strncpy(r, p, s - p);
r[s - p] = 0;
} else *r = 0;
for(i = 0; i < sizeof cmds / sizeof *cmds; i++)
if(strcmp(r, cmds[i].p) == 0) {
strcpy(r, cmds[i].s);
break;
} else if(strcmp(r, cmds[i].s) == 0) {
strcpy(r, cmds[i].p);
break;
}
return r;
}

char *cmd(char *p, char *s)
{
size_t i, j = strlen(p), k = strlen(s), n = strlen(BIN_PATH);
char *r;

if(r = malloc(j + k + n + 2)) {
strncpy(r, BIN_PATH, n);
r += n;
for(i = 0; i < j; i++)
r[i] = p[i] == ':' ? ' ' : p[i];
r[i] = ' ';
strcpy(r + i + 1, s);
}
return r ? r - n : 0;
}

int main(int argc, char **argv)
{
char *file, *p, *q, *qq, qqq[128], **stack = 0;
int i;
unsigned long lu = 0, b = 0;
struct stat s;
FILE *fp;

if(argc < 3) {
help();
return 0;
}
else file = argv[--argc];
if(stat(file, &s) == -1) return 0;
for(i = 1; i < argc; i++) {
p = cmd(argv[i], file);
if(p == NULL) return 0;
if(fp = popen(p, "r")) {
q = inversecmd(p + sizeof BIN_PATH - 1);
if(fscanf(fp, "%lu", &lu) == 1) {
b = 1;
qq = strchr(argv[i], ':');
if(lu)
sprintf(qqq, "%s%s resize:%lu", q, qq ? qq : "",
(s.st_size += lu) - lu), lu = 0;
else
sprintf(qqq, "%s%s", q, qq ? qq : "");
stack = push(qqq);
}
pclose(fp);
}
free(p);
}
while(stack && *stack) {
printf("%s ", *stack);
free(*stack--);
}
if(b) puts(file);
return 0;
}

Name: Anonymous 2015-12-31 1:02

>>9
No comments? This is depressing.

Yes, it's very depressing to see the lack of comments in your code, you piece of shit. Nobody wants to look at that wall of uncommented single-character variable names.

It's not like smaller source code makes it run faster, you know.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List