This commit is contained in:
Doridian 2022-06-11 16:16:56 -07:00
commit 83943aafc8
21 changed files with 123 additions and 119 deletions

View file

@ -76,8 +76,8 @@ static void create_table(struct table *tt, int d_1, int d_2) {
}
// create the path
// sprintf(tt->path, "/Volumes/2tb/%02X/%02X.bin", d_1 & 0xff, d_2 & 0xff);
sprintf(tt->path, "table/%02x/%02x.bin", d_1 & 0xff, d_2 & 0xff);
// snprintf(tt->path, sizeof(tt->path), "/Volumes/2tb/%02X/%02X.bin", d_1 & 0xff, d_2 & 0xff);
snprintf(tt->path, sizeof(tt->path), "table/%02x/%02x.bin", d_1 & 0xff, d_2 & 0xff);
}
@ -341,12 +341,12 @@ static void makedirs(void) {
}
for (i = 0; i < 0x100; i++) {
sprintf(path, "table/%02x", i);
snprintf(path, sizeof(path), "table/%02x", i);
if (mkdir(path, 0755)) {
printf("cannot make dir %s\n", path);
exit(1);
}
sprintf(path, "sorted/%02x", i);
snprintf(path, sizeof(path), "sorted/%02x", i);
if (mkdir(path, 0755)) {
printf("cannot make dir %s\n", path);
exit(1);
@ -387,7 +387,7 @@ static void *sorttable(void *dd) {
printf("sorttable: processing bytes 0x%02x/0x%02x\n", i, j);
// open file, stat it and mmap it
sprintf(infile, "table/%02x/%02x.bin", i, j);
snprintf(infile, sizeof(infile), "table/%02x/%02x.bin", i, j);
fdin = open(infile, O_RDONLY);
if (fdin <= 0) {
@ -424,7 +424,7 @@ static void *sorttable(void *dd) {
qsort_r(table, numentries, DATASIZE, datacmp, dummy);
// write to file
sprintf(outfile, "sorted/%02x/%02x.bin", i, j);
snprintf(outfile, sizeof(outfile), "sorted/%02x/%02x.bin", i, j);
fdout = open(outfile, O_WRONLY | O_CREAT, 0644);
if (fdout <= 0) {
printf("cannot create outfile %s\n", outfile);

View file

@ -25,7 +25,7 @@ static int makerandom(char *hex, unsigned int len, int fd) {
}
for (i = 0; i < len; i++) {
sprintf(hex + (2 * i), "%02X", raw[i]);
snprintf(hex + (2 * i), 3, "%02X", raw[i]);
}
return 1;
@ -65,7 +65,7 @@ int main(int argc, char *argv[]) {
makerandom(key, 6, urandomfd);
makerandom(uid, 4, urandomfd);
makerandom(nR, 4, urandomfd);
sprintf(filename, "keystream.key-%s.uid-%s.nR-%s", key, uid, nR);
snprintf(filename, sizeof(filename), "keystream.key-%s.uid-%s.nR-%s", key, uid, nR);
FILE *fp = fopen(filename, "w");
if (!fp) {

View file

@ -166,7 +166,7 @@ static int searchcand(unsigned char *c, unsigned char *rt, int fwd, unsigned cha
return 0;
}
sprintf(file, INPUTFILE, c[0], c[1]);
snprintf(file, sizeof(file), INPUTFILE, c[0], c[1]);
fd = open(file, O_RDONLY);
if (fd <= 0) {

View file

@ -153,17 +153,17 @@ static void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const siz
if (buf == NULL) return;
char *tmp = (char *)buf;
char *tmp_base = (char *)buf;
char *tmp = tmp_base;
size_t i;
memset(tmp, 0x00, hex_max_len);
size_t max_len = (hex_len > hex_max_len) ? hex_max_len : hex_len;
for (i = 0; i < max_len; ++i, tmp += 2 + spaces_between) {
sprintf(tmp, (uppercase) ? "%02X" : "%02x", (unsigned int) hex_data[i]);
snprintf(tmp, hex_max_len - (tmp - tmp_base), (uppercase) ? "%02X" : "%02x", (unsigned int) hex_data[i]);
for (size_t j = 0; j < spaces_between; j++)
sprintf(tmp + 2 + j, " ");
snprintf(tmp + 2 + j, hex_max_len - (2 + j + (tmp - tmp_base)), " ");
}
i *= (2 + spaces_between);
@ -173,11 +173,10 @@ static void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const siz
mlen = hex_max_len;
for (; i < mlen; i++, tmp += 1)
sprintf(tmp, " ");
snprintf(tmp, hex_max_len - (tmp - tmp_base), " ");
// remove last space
*tmp = '\0';
return;
}
static char *sprint_hex_inrow_ex(const uint8_t *data, const size_t len, const size_t min_str_len) {

View file

@ -139,17 +139,17 @@ static void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const siz
if (buf == NULL) return;
char *tmp = (char *)buf;
char *tmp_base = (char *)buf;
char *tmp = tmp_base;
size_t i;
memset(tmp, 0x00, hex_max_len);
size_t max_len = (hex_len > hex_max_len) ? hex_max_len : hex_len;
for (i = 0; i < max_len; ++i, tmp += 2 + spaces_between) {
sprintf(tmp, (uppercase) ? "%02X" : "%02x", (unsigned int) hex_data[i]);
snprintf(tmp, hex_max_len - (tmp - tmp_base), (uppercase) ? "%02X" : "%02x", (unsigned int) hex_data[i]);
for (size_t j = 0; j < spaces_between; j++)
sprintf(tmp + 2 + j, " ");
snprintf(tmp + 2 + j, hex_max_len - (2 + j + (tmp - tmp_base)), " ");
}
i *= (2 + spaces_between);
@ -159,11 +159,10 @@ static void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const siz
mlen = hex_max_len;
for (; i < mlen; i++, tmp += 1)
sprintf(tmp, " ");
snprintf(tmp, hex_max_len - (tmp - tmp_base), " ");
// remove last space
*tmp = '\0';
return;
}
static char *sprint_hex_inrow_ex(const uint8_t *data, const size_t len, const size_t min_str_len) {