47 lines
1010 B
C++
47 lines
1010 B
C++
#include <cstdio>
|
|||
|
|
#include <cstdlib>
|
||
|
|
|
||
|
|
#include <ctime>
|
||
|
|
#include <climits>
|
||
|
|
|
||
|
|
int main(int argc, char **argv) {
|
||
|
|
const char *filename = "a.bin";
|
||
|
|
int bytes_count = 256;
|
||
|
|
|
||
|
|
if (argc > 1)
|
||
|
|
filename = argv[1];
|
||
|
|
|
||
|
|
if (argc > 2)
|
||
|
|
bytes_count = atoi(argv[2]);
|
||
|
|
|
||
|
|
auto hex_file = fopen(filename, "wb");
|
||
|
|
|
||
|
|
if (hex_file == NULL) {
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
srand(time(NULL));
|
||
|
|
|
||
|
|
constexpr int chunk_size = 0x400;
|
||
|
|
unsigned char buffer[chunk_size];
|
||
|
|
for (int total_bytes = bytes_count; chunk_size < total_bytes; total_bytes -= chunk_size) {
|
||
|
|
memset(buffer, 0, chunk_size);
|
||
|
|
|
||
|
|
for (int i = 0; i < chunk_size; ++ i) {
|
||
|
|
buffer[i] = rand() % UCHAR_MAX;
|
||
|
|
}
|
||
|
|
|
||
|
|
fwrite(buffer, chunk_size, 1, hex_file);
|
||
|
|
}
|
||
|
|
|
||
|
|
memset(buffer, 0, chunk_size);
|
||
|
|
for (int i = 0; i < bytes_count % chunk_size; ++ i) {
|
||
|
|
buffer[i] = rand() % UCHAR_MAX;
|
||
|
|
}
|
||
|
|
fwrite(buffer, bytes_count % chunk_size, 1, hex_file);
|
||
|
|
|
||
|
|
fclose(hex_file);
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|