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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstdint>
#include<cstring>
#include<iostream>
#include"Portable.h"
FILE* ifile;
FILE* ofile;
int32_t IfileSize = 0;
//Switches
bool saving = 0;
long long int handle_numbers(char NumbHandString[32])
{
unsigned char NumbHandPercent = 0;
long long double NumbHandDec;
long long double NumbHandInt;
NumbHandOut[32];
NumbHandPercent = strchr(NumbHandString[32],'%');
if(NumbHandPercent != NULL)
{
strncpy(NumbHandOut,NumbHandString,NumbHandPercent -1);
NumbHandDec = strtol(NumbHandOut,NULL,0);
NumbHandDec = NumbHandDec /100;
NumbHandDec = round(NumbHandDec *IfileSize);
NumbHandDec = NumbHandInt;
//NumbHandString = to_string(NumbHandInt);
}
return strtol(NumbHandString, NULL, 0);
}
int32_t GetIfileSize()
{
int32_t getifilesizesize = 0;
fseek(ifile, 0L, SEEK_SET);
while(fgetc(ifile) != EOF){getifilesizesize = getifilesizesize +1;}
fseek(ifile, 0L, SEEK_SET);
return getifilesizesize;
}
unsigned char load_ifile(char LoadIfileName[32])
{
ifile = fopen(LoadIfileName,"rb");
if(ifile == NULL){printf("%s","ifile does not exist.\n");return 1;}
IfileSize = GetIfileSize();
return 0;
}
unsigned char load_ofile(char LoadOfileName[32])
{
ofile = fopen(LoadOfileName,"wb");
if(ofile == NULL){printf("%s","An error occoured with the primary output file.\n");return 1;}
return 0;
}
void errormsg()
{
printf("%s","Syntax error. Syntax is:\n");
printf("%s","corrupt [switches] <ifile> <ofile> <start> <stop> <every> <operation> <additional>\n");
printf("%s","ifile is the path to the input file.\n");
printf("%s","ofile is the path to the output file.\n");
printf("%s","start is the position in the file to start corrupting.\n");
printf("%s","stop is the position in the file to stop corrupting.\n");
printf("%s","every is the frequency of memory to ignore.\n");
printf("%s","\n");
printf("%s","Operations:\n");
printf("%s","add Adds current byte to addative\n");
printf("%s","sub Subtracts current byte from addative\n");
printf("%s","mul Multiplies current byte by addative\n");
printf("%s","div Divides current byte by addative\n");
printf("%s","mod Modular current byte by addative\n");
printf("%s","xor Xor's current byte by addative\n");
printf("%s","and And's current byte by addative\n");
printf("%s"," or Or's current byte by addative\n");
printf("%s","ran Randomizes current byte\n");
printf("%s","not Not's current byte\n");
printf("%s","\n");
printf("%s","Switches:\n");
printf("%s","-l [file] Load corruption from file\n");
printf("%s","-v Output corruptor version\n");
printf("%s","-s [file] Save corruption to file\n");
exit(1);
}
char op(char oper[3],char a,char b)
{
if(strcmp(oper, "add") == 0){return a+b;}
else if(strcmp(oper, "sub") == 0){return a-b;}
else if(strcmp(oper, "mul") == 0){return a*b;}
else if(strcmp(oper, "div") == 0){return a/b;}
else if(strcmp(oper, "ran") == 0){return rand() % 128 -64;}
else if(strcmp(oper, "xor") == 0){return a xor b;}
else if(strcmp(oper, "and") == 0){return a and b;}
else if(strcmp(oper, "or") == 0){return a or b;}
else if(strcmp(oper, "not") == 0){return not(a);}
else if(strcmp(oper, "mod") == 0){return a % b;}
else{errormsg();}
}
void Old_Engine_While_Loop(unsigned long long int strt,unsigned long long int stop,unsigned int frequency,char* tempop,char addative)
{
unsigned long long int dimX = 0;
unsigned int FreqCounter = 0;
int regbyte;
while((regbyte = fgetc(ifile)) != EOF) //While we haven't reached the end of the file...
{
if((FreqCounter >= frequency) and ((dimX >= strt) and (dimX <= stop))) //And the conditions are juuust right...
{
regbyte = op(tempop,regbyte,addative);putc(regbyte, ofile);FreqCounter = 0; //corrupt dat byte!
}
else{putc(regbyte, ofile);} //Or don't...
FreqCounter = FreqCounter +1;dimX = dimX +1; //counting
}
printf("%s","The file seems to have been successfully corrupted...\n");
}
int main(int argc, char* argv[])
{
char loadarray[8][32];
FILE* savefile;
FILE* loadfile;
unsigned long long int fsize;
unsigned char arg = 1;
//Start the REAL code here
if(argc == 1){errormsg();return 1;}
if(strcmp(argv[arg],"-v") == 0){printf("%s","LAwl\n");arg = arg +1;return 0;}
if(strcmp(argv[arg],"-s") == 0)
{
saving = 1;arg = arg +1;
savefile = fopen(argv[arg],"wb");arg = arg +1;
}
if(strcmp(argv[arg],"-l") == 0)
{
arg = arg +1;
loadfile = fopen(argv[arg],"rb");arg = arg +1;
if(loadfile == NULL){printf("%s","loadfile does not exist.\n");return 1;}
if(load_ifile(argv[arg]) == 1){return 1;}arg = arg +1;
if(load_ofile(argv[arg]) == 1){return 1;}arg = arg +1;
fgets(loadarray[1],32,loadfile);
fgets(loadarray[2],32,loadfile);
fgets(loadarray[3],32,loadfile);
fgets(loadarray[4],32,loadfile);
fgets(loadarray[5],32,loadfile);loadarray[5][3] = '\0';
fgets(loadarray[6],32,loadfile);
Old_Engine_While_Loop(atoi(loadarray[2]),atoi(loadarray[3]),atoi(loadarray[4]),loadarray[5],atoi(loadarray[6]));
return 0;
}
if(load_ifile(argv[arg]) == 1){return 1;}arg = arg +1;
if(load_ofile(argv[arg]) == 1){return 1;}arg = arg +1;
//Onward
if((argc-arg) != 5){errormsg();return 1;}
Old_Engine_While_Loop(handle_numbers(argv[arg]),handle_numbers(argv[arg+1]),handle_numbers(argv[arg+2]),argv[arg+3],handle_numbers(argv[arg+4]));
if(saving)
{
fputs("[A.0.2.2]\n",savefile);
fputs(argv[arg],savefile);
fputs("\n",savefile);
fputs(argv[arg+1],savefile);
fputs("\n",savefile);
fputs(argv[arg+2],savefile);
fputs("\n",savefile);
fputs(argv[arg+3],savefile);
fputs("\n",savefile);
fputs(argv[arg+4],savefile);
fputs("\n",savefile);
}
return 0;
}
|