Compare commits
No commits in common. "d45aacdcf25b98d90f4144bfab77d4983b4dc85f" and "cc06aaad96881792b944528c42376a43f2704c4b" have entirely different histories.
d45aacdcf2
...
cc06aaad96
3 changed files with 10 additions and 102 deletions
|
@ -43,15 +43,13 @@ match_rule(config_t *conf, dosfile_t *file)
|
||||||
int
|
int
|
||||||
corrupt_file(dosfs_t *fsd, dosfile_t *file, config_t *conf, uint32_t *state)
|
corrupt_file(dosfs_t *fsd, dosfile_t *file, config_t *conf, uint32_t *state)
|
||||||
{
|
{
|
||||||
uint32_t off, end;
|
uint32_t off;
|
||||||
int real_off;
|
int real_off;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
struct conf_opts_t opts;
|
struct conf_opts_t opts;
|
||||||
|
|
||||||
end = (conf->end) ? conf->end : file->ent.size;
|
|
||||||
|
|
||||||
opts = conf->opts;
|
opts = conf->opts;
|
||||||
for (off = conf->start; (off < end) && (off < file->ent.size);
|
for (off = conf->start; (off < conf->end) && (off < file->ent.size);
|
||||||
off += xs_randb(state, conf->skip_a, conf->skip_b)) {
|
off += xs_randb(state, conf->skip_a, conf->skip_b)) {
|
||||||
real_off = get_byte_offset(fsd, file, off);
|
real_off = get_byte_offset(fsd, file, off);
|
||||||
if (real_off < 0) {
|
if (real_off < 0) {
|
||||||
|
|
|
@ -34,8 +34,7 @@ open_image(const char *path, int flags, dosfs_t *fsd)
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fsd->ib.jmp[0] != 0xEB || fsd->ib.jmp[2] != 0x90) && /* JMP rel8 */
|
if (fsd->ib.jmp[0] != 0xEB || fsd->ib.jmp[2] != 0x90) {
|
||||||
fsd->ib.jmp[0] != 0xE9) { /* JMP rel16 */
|
|
||||||
DPRINTF(("hm... doesn't look like a FAT image?\n"));
|
DPRINTF(("hm... doesn't look like a FAT image?\n"));
|
||||||
close(ifd);
|
close(ifd);
|
||||||
return EOPNOTSUPP;
|
return EOPNOTSUPP;
|
||||||
|
|
101
src/main.c
101
src/main.c
|
@ -1,59 +1,26 @@
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "corrupt.h"
|
|
||||||
#include "dosfs.h"
|
#include "dosfs.h"
|
||||||
|
|
||||||
static void usage(void) __dead;
|
static void usage(void) __dead;
|
||||||
static int list_img(char *);
|
static int list_img(char *);
|
||||||
static int do_corrupt(char *, config_t *, uint32_t);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ch, list_mode, res, preseed;
|
int ch, list_mode;
|
||||||
uint32_t seed;
|
|
||||||
char *cfg_path, *ep;
|
|
||||||
config_t *conf;
|
|
||||||
|
|
||||||
setprogname(argv[0]);
|
setprogname(argv[0]);
|
||||||
|
|
||||||
list_mode = 0;
|
list_mode = 0;
|
||||||
seed = 0;
|
while ((ch = getopt(argc, argv, "l")) != -1) {
|
||||||
preseed = 0;
|
|
||||||
cfg_path = NULL;
|
|
||||||
while ((ch = getopt(argc, argv, "lc:s:")) != -1) {
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'l':
|
case 'l':
|
||||||
list_mode = 1;
|
list_mode = 1;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
|
||||||
cfg_path = optarg;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
errno = 0;
|
|
||||||
if (optarg[0] == '0' && optarg[1] == 'x') {
|
|
||||||
// strtoul hex
|
|
||||||
optarg += 2;
|
|
||||||
seed = strtoul(optarg, &ep, 16);
|
|
||||||
} else {
|
|
||||||
seed = strtoul(optarg, &ep, 10);
|
|
||||||
}
|
|
||||||
if (errno) {
|
|
||||||
perror("couldn't parse seed parameter");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
} else if (optarg == ep || *ep != 0) {
|
|
||||||
fprintf(stderr, "defined seed is malformed\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
preseed = 1;
|
|
||||||
break;
|
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
@ -72,29 +39,11 @@ main(int argc, char *argv[])
|
||||||
return list_img(argv[0]);
|
return list_img(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preseed) {
|
/* TODO: rest of the owl */
|
||||||
seed = time(NULL) & 0xffffffff;
|
fprintf(stderr, "not yet implemented :(\n");
|
||||||
}
|
|
||||||
|
|
||||||
printf("using seed 0x%x\n", seed);
|
|
||||||
|
|
||||||
if (cfg_path != NULL) {
|
|
||||||
conf = parse_config(cfg_path);
|
|
||||||
if (conf == NULL) {
|
|
||||||
fprintf(stderr, "failed to parse config\n");
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fprintf(stderr, "no default config implemented\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = do_corrupt(argv[0], conf, seed);
|
|
||||||
|
|
||||||
free_config(conf);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
list_img(char *path)
|
list_img(char *path)
|
||||||
|
@ -105,7 +54,7 @@ list_img(char *path)
|
||||||
|
|
||||||
res = open_image(path, O_RDONLY, &img);
|
res = open_image(path, O_RDONLY, &img);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
fprintf(stderr, "err: couldn't open image: %s\n", strerror(res));
|
fprintf(stderr, "err: couldn't open image (errno %d)\n", res);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,48 +77,10 @@ list_img(char *path)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
do_corrupt(char *path, config_t *conf, uint32_t seed)
|
|
||||||
{
|
|
||||||
dosfs_t img = { 0 };
|
|
||||||
dosfile_t *rootdir, *cur;
|
|
||||||
config_t *match;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
res = open_image(path, O_RDWR, &img);
|
|
||||||
if (res != 0) {
|
|
||||||
fprintf(stderr, "err: couldn't open image: %s\n", strerror(res));
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
rootdir = dos_listdir(&img, img.root_loc);
|
|
||||||
if (rootdir == NULL) {
|
|
||||||
perror("couldn't read root dir");
|
|
||||||
close_image(&img);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (cur = rootdir; cur->next != NULL; cur = cur->next) {
|
|
||||||
match = match_rule(conf, cur);
|
|
||||||
if (match != NULL) {
|
|
||||||
printf("Corrupting %s.%s... (x%u a%u l%u r%u)\n",
|
|
||||||
cur->fname, cur->fext, match->opts.bit_xor,
|
|
||||||
match->opts.add, match->opts.shl, match->opts.shr);
|
|
||||||
res = corrupt_file(&img, cur, match, &seed);
|
|
||||||
if (res != 0) {
|
|
||||||
fprintf(stderr, "Corrupting file failed...\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close_image(&img);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s [-l] [-s seed] [-c config] image\n", getprogname());
|
fprintf(stderr, "usage: %s [-l] image\n", getprogname());
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue