Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement checksumming in goke_p2pcam_param #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions source/goke_p2pcam_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,33 @@ void param_set_string(size_t offset, size_t size, char *data) {
free(buffer);
}

uint32_t checksum() {
uint32_t sum = 0;
uint16_t word;
FILE *file = fopen(filename, "r+b");
if(file == NULL) {
error(1, errno, "error: cannot open file: %s", filename);
}
fseek(file, 0xC, SEEK_SET);
while (!feof(file)) {
fread(&word, 2, 1, file);
sum+=word;
}
return sum;
}

void update_checksum() {
uint32_t sum;
FILE *file = fopen(filename, "r+b");
if(file == NULL) {
error(1, errno, "error: cannot open file: %s", filename);
}
fseek(file, 0x4, SEEK_SET);
sum = checksum();
fwrite(&sum, 4, 1, file);
}


int main(int argc, char *argv[]) {
int option = 0, option_index = 0, index = 0;

Expand Down Expand Up @@ -111,48 +138,55 @@ int main(int argc, char *argv[]) {
case 'n':
if(optarg) {
param_set_int(0xf6, 1, strtol(optarg, NULL, 0));
update_checksum();
} else {
param_get(0xf6, 1);
}
break;
case 'o':
if(optarg) {
param_set_int(0xf8, 1, strtol(optarg, NULL, 0));
update_checksum();
} else {
param_get(0xf8, 1);
}
break;
case 'q':
if(optarg) {
param_set_int(0xec, 1, strtol(optarg, NULL, 0));
update_checksum();
} else {
param_get(0xec, 1);
}
break;
case 'w':
if(optarg) {
param_set_string(0x128, 32, optarg);
update_checksum();
} else {
param_get_string(0x128, 32);
}
break;
case 'k':
if(optarg) {
param_set_string(0x154, 8, optarg);
update_checksum();
} else {
param_get_string(0x154, 8);
}
break;
case 'u':
if(optarg) {
param_set_string(0x1fc, 16, optarg);
update_checksum();
} else {
param_get_string(0x1fc, 16);
}
break;
case 'p':
if(optarg) {
param_set_string(0x20c, 16, optarg);
update_checksum();
} else {
param_get_string(0x20c, 16);
}
Expand Down