diff options
Diffstat (limited to 'reloc.c')
-rw-r--r-- | reloc.c | 69 |
1 files changed, 0 insertions, 69 deletions
@@ -113,72 +113,3 @@ void reloc_replace(RelocMatch *match, const char *rstr) { // Destroy bytes between the end of the original data and the end of the replaced string memset(data, '\0', post - data); } - - -void show_version() { - printf("%s\n", VERSION); -} - - -int main(int argc, char *argv[]) { - char *program = argv[0]; - char *program_relative = strrchr(program, DIRSEP); - if (program_relative) { - program = program_relative + 1; - } - - for (int i = 0; i < argc; i++) { - if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-V")) { - show_version(); - exit(0); - } - } - - if (argc < 5) { - printf("%s [-V] <str1> <str2> <input_file> <output_file>\n" - "\n" - "Arguments:\n" - "--version (-V) - Display version and exit\n" - "str1 - Pattern to search for\n" - "str2 - Replace str1 with contents of str2\n" - "input_file - Path to input file\n" - "output_file - Path to output file\n" - "\n" - "Example:\n" - "%s /original/path /new/path input.bin output.bin\n" - "\n", program, program); - exit(1); - } - - char *needle = strdup(argv[1]); - char *replacement = strdup(argv[2]); - char *input_file = strdup(argv[3]); - char *output_file = strdup(argv[4]); - RelocData *info = reloc_read(input_file); - size_t records = 0; - - for (size_t i = 0; i < info->size; i++) { - RelocMatch *match = NULL; - if (!(match = reloc_match(&info->data[i], needle))) { - // No match found - continue; - } - // Replace string - reloc_replace(match, replacement); - free(match); - records++; - } - - // Write output file to disk - reloc_write(info, output_file); - - // Report number of strings processed - printf(SIZE_T_FMT"\n", records); - - free(needle); - free(replacement); - free(input_file); - free(output_file); - reloc_deinit_data(info); - return 0; -} |