Created
December 8, 2024 09:26
-
-
Save faizul726/18dfecabe0ea1834da236561f1a741e6 to your computer and use it in GitHub Desktop.
C program made by ChatGPT to update Minecraft iOS materials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <dirent.h> | |
#define HEX_PATTERN1 "\x4D\x65\x74\x61\x6C\x00\x0B" | |
#define REPLACEMENT1 "\x4D\x65\x74\x61\x6C\x00\x0A" | |
#define HEX_PATTERN2 "\x4D\x65\x74\x61\x6C\x01\x0B" | |
#define REPLACEMENT2 "\x4D\x65\x74\x61\x6C\x01\x0A" | |
void process_file(const char *filename) { | |
FILE *file = fopen(filename, "r+b"); | |
if (file == NULL) { | |
perror("Error opening file"); | |
return; | |
} | |
// Get the file size | |
fseek(file, 0, SEEK_END); | |
long file_size = ftell(file); | |
fseek(file, 0, SEEK_SET); | |
// Allocate buffer to read file contents | |
unsigned char *buffer = (unsigned char *)malloc(file_size); | |
if (buffer == NULL) { | |
perror("Memory allocation failed"); | |
fclose(file); | |
return; | |
} | |
// Read the entire file into the buffer | |
fread(buffer, 1, file_size, file); | |
// Look for the patterns and replace them | |
for (long i = 0; i < file_size - 7; i++) { | |
if (memcmp(&buffer[i], HEX_PATTERN1, 7) == 0) { | |
memcpy(&buffer[i], REPLACEMENT1, 7); | |
} else if (memcmp(&buffer[i], HEX_PATTERN2, 7) == 0) { | |
memcpy(&buffer[i], REPLACEMENT2, 7); | |
} | |
} | |
// Move file pointer back to the beginning to write the modified data | |
fseek(file, 0, SEEK_SET); | |
fwrite(buffer, 1, file_size, file); | |
// Clean up | |
free(buffer); | |
fclose(file); | |
} | |
int main() { | |
DIR *dir = opendir("."); | |
if (dir == NULL) { | |
perror("Unable to open directory"); | |
return 1; | |
} | |
struct dirent *entry; | |
while ((entry = readdir(dir)) != NULL) { | |
// Check if the file ends with ".material.bin" | |
if (strstr(entry->d_name, ".material.bin") != NULL) { | |
printf("Processing file: %s\n", entry->d_name); | |
process_file(entry->d_name); | |
} | |
} | |
closedir(dir); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment