c code updated with discrete type conversions

This commit is contained in:
Nicolas 2025-11-03 09:43:05 +01:00
parent 2bbe6ad0ce
commit 8b69fa8ce7
2 changed files with 3 additions and 3 deletions

View File

@ -53,7 +53,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "Usage: %s <code_file> <memory_dump_file>\n", argv[0]);
return EXIT_FAILURE;
}
FILE *f = fopen(argv[2], "wb");
f = fopen(argv[2], "wb");
fwrite(executable_memory, 1, (size_t)executable_memory_len, f);
fclose(f);
}

View File

@ -28,9 +28,9 @@ void patch(uint8_t *patch_addr, uint32_t patch_mask, int32_t value) {
uint32_t *val_ptr = (uint32_t*)patch_addr;
uint32_t original = *val_ptr;
int32_t shift_factor = patch_mask & -patch_mask;
uint32_t shift_factor = patch_mask & -patch_mask;
uint32_t new_value = (original & ~patch_mask) | ((uint32_t)(value * shift_factor) & patch_mask);
uint32_t new_value = (original & ~patch_mask) | (((uint32_t)value * shift_factor) & patch_mask);
*val_ptr = new_value;
}