Browse Source

Removed corruption method system

master
parent
commit
b18c847a17
  1. 10
      README.md
  2. 28
      corrupt.c

10
README.md

@ -3,22 +3,20 @@
### Usage ### Usage
`corrupt -[hvm] FILE...` `corrupt -[hv] FILE...`
Flags Flags
- `-h` to see the relevant usage information - `-h` to see the relevant usage information
- `-v` to get version information - `-v` to get version information
- `-m METHOD (bit)` to specify corruption method (MORE TO BE ADDED)
### Examples ### Example
- `corrupt testfile.txt` - corrupt `testfile.txt` with default corruption method - `corrupt testfile.txt` - corrupt `testfile.txt`
- `corrupt -m bit testfile.txt` - corrupt `testfile.txt` with `bit` corruption method
### Build ### Build
Simply `make` or if you don't have it - compile `corrupt.c` with the compiler of choice. The only dependency is the () standart library Simply `make` or if you don't have it - compile `corrupt.c` with the compiler of choice. The only dependency is the standart library.
### License ### License

28
corrupt.c

@ -18,11 +18,6 @@ corrupt.c - a utility to corrupt FILE streams
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
// Corruption method. TODO(add more)
typedef enum Corruption {
CORRUPTION_BITMAGIC, // Corrupt each byte via bit manipulation
} Corruption;
// Possible funcion errors // Possible funcion errors
typedef enum CorruptResult { typedef enum CorruptResult {
SUCCESS, SUCCESS,
@ -42,7 +37,7 @@ int corrupt_char(int byte) {
Corrupts the file with specified corruption method. Returns 0 if Corrupts the file with specified corruption method. Returns 0 if
successful, 1 - if FILE is NULL. successful, 1 - if FILE is NULL.
*/ */
CorruptResult corrupt(FILE* file, Corruption corruption) { CorruptResult corrupt(FILE* file) {
if (!file) { if (!file) {
return ERR_NULLPTR; return ERR_NULLPTR;
} else if (feof(file)) { } else if (feof(file)) {
@ -60,12 +55,10 @@ CorruptResult corrupt(FILE* file, Corruption corruption) {
fseek(file, -read_bytes, SEEK_CUR); fseek(file, -read_bytes, SEEK_CUR);
// replace the original bytes with corrupted ones // replace the original bytes with corrupted ones
if (corruption == CORRUPTION_BITMAGIC) {
for (unsigned int i = 0; i < read_bytes; i++) { for (unsigned int i = 0; i < read_bytes; i++) {
corrupted_buf[i] = corrupt_char(buff[i]); corrupted_buf[i] = corrupt_char(buff[i]);
} }
fwrite(corrupted_buf, 1, read_bytes, file); fwrite(corrupted_buf, 1, read_bytes, file);
}
if (read_bytes < 1024 || feof(file)) { if (read_bytes < 1024 || feof(file)) {
break; break;
@ -79,7 +72,6 @@ int main(int argc, char** argv) {
char* file_paths[argc-1]; char* file_paths[argc-1];
unsigned int file_path_index = 0; unsigned int file_path_index = 0;
FILE* file = NULL; FILE* file = NULL;
Corruption corruption_method = CORRUPTION_BITMAGIC;
CorruptResult result; CorruptResult result;
unsigned int i = 1; unsigned int i = 1;
@ -88,27 +80,15 @@ int main(int argc, char** argv) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
fprintf( fprintf(
stdout, stdout,
"corrupt -[hvm] FILE...\n\n-h --help -> Print this message and exit\n-v --version -> Print version information and exit\n-m --method METHOD (bit) -> Specify corruption method\n" "corrupt -[hv] FILE...\n\n-h --help -> Print this message and exit\n-v --version -> Print version information and exit\n"
); );
return SUCCESS; return SUCCESS;
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
fprintf( fprintf(
stdout, stdout,
"corrupt v0.1.1 - a utility to corrupt FILE streams\n(c) Kasyanov Nikolay Alexeyevich (Unbewohnte)\n" "corrupt v0.1.2 - a utility to corrupt FILE streams\n(c) Kasyanov Nikolay Alexeyevich (Unbewohnte)\n"
); );
return SUCCESS; return SUCCESS;
} else if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--method") == 0) {
i++;
if (strcmp(argv[i], "bit") == 0) {
corruption_method = CORRUPTION_BITMAGIC;
} else {
corruption_method = CORRUPTION_BITMAGIC;
fprintf(
stdout,
"Invalid corruption method \"%s\". Defaulting to \"bit\"\n",
argv[i]
);
}
} else { } else {
// remember this path // remember this path
file_paths[file_path_index] = argv[i]; file_paths[file_path_index] = argv[i];
@ -134,7 +114,7 @@ int main(int argc, char** argv) {
); );
// corrupt the whole stream // corrupt the whole stream
result = corrupt(file, corruption_method); result = corrupt(file);
if (result == ERR_NULLPTR) { if (result == ERR_NULLPTR) {
fprintf( fprintf(
stdout, stdout,

Loading…
Cancel
Save