diff options
-rw-r--r-- | CHANGELOG.txt | 6 | ||||
-rw-r--r-- | README.txt | 35 | ||||
-rw-r--r-- | include/agbsum.h | 51 | ||||
-rw-r--r-- | src/chkpar.c | 29 | ||||
-rw-r--r-- | src/cpy.c | 39 | ||||
-rw-r--r-- | src/exi.c | 25 | ||||
-rw-r--r-- | src/getsum.c | 31 | ||||
-rw-r--r-- | src/hlp.c | 33 | ||||
-rw-r--r-- | src/inidat.c | 25 | ||||
-rw-r--r-- | src/main.c | 33 | ||||
-rw-r--r-- | src/opn.c | 31 | ||||
-rw-r--r-- | src/pat.c | 29 | ||||
-rw-r--r-- | src/red.c | 34 |
13 files changed, 306 insertions, 95 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index a72eab4..4db18ed 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,9 @@ +| E + +- Code style adjustments; +- Add readme; +- Update help screen; + | D - Update run-time copyright notices; diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..cd4142e --- /dev/null +++ b/README.txt @@ -0,0 +1,35 @@ +- AGBSUM + +AGB image header checksum patcher. + +- ABOUT + +Patches the image header checksum of an AGB image. + +The checksum is located at the offset 0xBD. See USAGE for more information. + +- USAGE + +agbsum [options] <image> + +Options: + --help -h Print the help screen + -p Patch the image file + -s Don't print results + --version Print the version number + +- COPYRIGHT & LICENSE + +Copyright 2022-2023 Gabriel Jensen. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see <https://www.gnu.org/licenses/>. diff --git a/include/agbsum.h b/include/agbsum.h index eab57e6..82cbac9 100644 --- a/include/agbsum.h +++ b/include/agbsum.h @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #ifndef agb_hdr @@ -15,19 +30,19 @@ #include <stdio.h> #if __STDC_VERSION__ >= 201112 -# include <stdnoreturn.h> +#include <stdnoreturn.h> #elif defined(__GNUC__) -# define noreturn __attribute__ ((__noreturn__)) +#define noreturn __attribute__ ((__noreturn__)) #elif defined (_MSC_VER) -# define noreturn __declspec (noreturn) +#define noreturn __declspec (noreturn) #else -# define noreturn +#define noreturn #endif -#define agb_rel ((uint64_t) + 0xDu) +#define agb_rel ((uint64_t)+0xEu) -#define agb_romsrt ((size_t) + 0xA0u) -#define agb_sumoff ((size_t) + 0xBDu-agb_romsrt) +#define agb_iptsrt ((size_t)+0xA0u) // The part of the header used for calculating the checksum. +#define agb_sumoff ((size_t)+0xBDu - agb_iptsrt) enum agb_cnd { agb_cnd_err, @@ -38,14 +53,14 @@ struct agb_dat { bool dopat; char const* pth; bool sil; - FILE * rom; + FILE* img; }; uint8_t -agb_getsum (void const* restrict rom); +agb_getsum (void const* restrict img); void -agb_pat (FILE * restrict rom, char unsigned sum); +agb_pat (FILE* restrict img, char unsigned sum); void agb_cpy (void); @@ -54,18 +69,18 @@ void agb_hlp (void); void -agb_chkpar (struct agb_dat * restrict dat, int argc, char const* const* restrict argv); +agb_chkpar (struct agb_dat* restrict dat, int argc, char const* const* restrict argv); void -agb_inidat (struct agb_dat * restrict dat); +agb_inidat (struct agb_dat* restrict dat); -FILE * +FILE* agb_opn (char const* restrict pth); void -agb_red (void * restrict buf, FILE * restrict rom); +agb_red (void* restrict buf, FILE* restrict img); noreturn void -agb_exi (enum agb_cnd stat, FILE * rom); +agb_exi (enum agb_cnd stat, FILE* img); #endif diff --git a/src/chkpar.c b/src/chkpar.c index f6edfe7..081173e 100644 --- a/src/chkpar.c +++ b/src/chkpar.c @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> @@ -14,7 +29,7 @@ #include <stdio.h> #include <string.h> -noreturn static void +noreturn static void agb_expparval (char const chrpar) { fprintf (stderr,"Expected value for character parameter '%c'\n", chrpar); @@ -22,7 +37,7 @@ agb_expparval (char const chrpar) } static bool -agb_chkchrpar (struct agb_dat * const restrict dat, char const* const restrict par) +agb_chkchrpar (struct agb_dat* const restrict dat, char const* const restrict par) { char const chrpar = par[0x0]; if (chrpar == '\x0') {return true;} @@ -52,7 +67,7 @@ agb_chkchrpar (struct agb_dat * const restrict dat, char const* const restrict p } void -agb_chkpar (struct agb_dat * const restrict dat, int const argc, char const* const* const argv) { +agb_chkpar (struct agb_dat* const restrict dat, int const argc, char const* const* const argv) { if (argc < 0x2) { agb_hlp (); agb_exi (agb_cnd_oky, NULL); @@ -83,7 +98,7 @@ agb_chkpar (struct agb_dat * const restrict dat, int const argc, char const* con agb_cpy(); agb_exi (agb_cnd_oky, NULL); } - + fprintf (stderr,"Invalid long parameter \"%s\"\n", lngparam); agb_exi (agb_cnd_err, NULL); } @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> @@ -19,14 +34,16 @@ agb_cpy (void) "agbsum #%" PRIX64 " - Copyright 2022-2023 Gabriel Jensen.\n" "\n" "This program is free software: you can redistribute it and/or modify it under\n" - " the terms of the GNU General Public License as published by the Free Software\n" - " Foundation, either version 3 of the License, or (at your option) any later\n" - " version.\n" - "This program is distributed in the hope that it will be useful, but WITHOUT ANY\n" - " WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n" - " A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n" - "You should have received a copy of the GNU General Public License along with\n" - " this program. If not, see <https://www.gnu.org/licenses/>.\n", + "the terms of the GNU General Public License as published by the Free Software\n" + "Foundation, either version 3 of the License, or (at your option) any later\n" + "version.\n" + "\n" + "This program is distributed in the hope that it will be useful, but WITHOUT ANY\n" + "WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\n" + "PARTICULAR PURPOSE. See the GNU General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License along with\n" + "this program. If not, see <https://www.gnu.org/licenses/>.\n", agb_rel ); } @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> @@ -13,9 +28,9 @@ #include <stdlib.h> noreturn void -agb_exi (enum agb_cnd const cnd, FILE * restrict rom) +agb_exi (enum agb_cnd const cnd, FILE* restrict img) { - if (rom != NULL) {fclose (rom);} + if (img != NULL) { fclose (img); } exit (cnd == agb_cnd_oky ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/src/getsum.c b/src/getsum.c index 31626fe..fd0e4a4 100644 --- a/src/getsum.c +++ b/src/getsum.c @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> @@ -12,14 +27,14 @@ #include <stdint.h> uint8_t -agb_getsum (void const* const restrict romptr) +agb_getsum (void const* const restrict imgptr) { - uint8_t const* restrict rom = romptr; - uint8_t sum = 0x0u; + uint8_t const* restrict img = imgptr; + uint8_t sum = UINT8_C(0x0); - for (char unsigned const* restrict pos = rom; pos != rom + agb_sumoff; ++pos) {sum += *pos;} + for (char unsigned const* restrict pos = img; pos != img + agb_sumoff; ++pos) { sum += *pos; } - sum = 0x0u - (0x19u + sum); + sum = -(UINT8_C(0x19) + sum); return sum; } @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> @@ -16,16 +31,16 @@ void agb_hlp (void) { fputs ( - "agbsum - Calculate GBA ROM header checksums.\n" + "agbsum - Patch AGB image header checksums.\n" "\n" - "Usage: agbsum [options] <ROM>\n" + "Usage: agbsum [options] <image>\n" "Options:\n" " --help -h Print the help screen\n" - " -p Patch the ROM\n" - " -s Don't print the results\n" - " --version Don't print the results\n" + " -p Patch the image file\n" + " -s Don't print results\n" + " --version Print the version number\n" "\n", stdout ); - agb_cpy(); + agb_cpy (); } diff --git a/src/inidat.c b/src/inidat.c index b31860a..05cd278 100644 --- a/src/inidat.c +++ b/src/inidat.c @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> @@ -12,10 +27,10 @@ #include <stddef.h> void -agb_inidat (struct agb_dat * const restrict dat) +agb_inidat (struct agb_dat* const restrict dat) { dat->dopat = false; dat->pth = NULL; dat->sil = false; - dat->rom = NULL; + dat->img = NULL; } @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> @@ -23,11 +38,11 @@ int main (int const argc, char const* const* const argv) agb_inidat (&dat); agb_chkpar (&dat, argc, argv); - dat.rom = agb_opn (dat.pth); + dat.img = agb_opn (dat.pth); char unsigned buf[agb_sumoff + 0x1]; - agb_red (buf, dat.rom); + agb_red (buf, dat.img); { char unsigned const sum = agb_getsum (buf); @@ -36,13 +51,13 @@ int main (int const argc, char const* const* const argv) if (romsum == sum || !dat.dopat) { // Don't patch the ROM if it's already okay or we're not allowed to. if (!dat.sil) {printf ("\"%s\": %hhX (%hhX in file)\n", dat.pth, sum, romsum);} - agb_exi (agb_cnd_oky, dat.rom); + agb_exi (agb_cnd_oky, dat.img); } - agb_pat (dat.rom, sum); + agb_pat (dat.img, sum); - if (!dat.sil) {printf ("\"%s\" @ %zX: %hhX => %hhX\n", dat.pth, agb_romsrt + agb_sumoff, romsum, sum);} // If we aren't supposed to print anything then don't. + if (!dat.sil) {printf ("\"%s\" @ %zX: %hhX => %hhX\n", dat.pth, agb_iptsrt + agb_sumoff, romsum, sum);} // If we aren't supposed to print anything then don't. } - agb_exi (agb_cnd_oky, dat.rom); + agb_exi (agb_cnd_oky, dat.img); } @@ -2,24 +2,39 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> #include <stdio.h> -FILE * +FILE* agb_opn (char const* const restrict pth) { - FILE * rom = fopen (pth,"r+"); - - if (rom == NULL) { + FILE* img = fopen (pth, "r+"); + + if (img == NULL) { fputs ("Unable to open ROM\n", stderr); agb_exi (agb_cnd_err, NULL); } - return rom; + return img; } @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> @@ -12,12 +27,12 @@ #include <stdio.h> void -agb_pat (FILE * const restrict rom, char unsigned sum) +agb_pat (FILE* const restrict img, char unsigned sum) { - fseek (rom, (long)(agb_romsrt + agb_sumoff), SEEK_SET); + fseek (img, (long)(agb_iptsrt + agb_sumoff), SEEK_SET); - if (fwrite (&sum,0x1u,0x1u, rom) != 0x1u) { + if (fwrite (&sum, 0x1u, 0x1u, img) != 0x1u) { fputs ("Unable to patch ROM\n", stderr); - agb_exi (agb_cnd_err, rom); + agb_exi (agb_cnd_err, img); } } @@ -2,9 +2,24 @@ Copyright 2022-2023 Gabriel Jensen. This file is part of agbsum. - agbsum is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - agbsum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - You should have received a copy of the GNU Affero General Public License along with agbsum. If not, see <https://www.gnu.org/licenses/>. + + agbsum is free software: you can redistribute it + and/or modify it under the terms of the GNU + Affero General Public License as published by + the Free Software Foundation, either version 3 + of the License, or (at your option) any later + version. + + agbsum is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more + details. + + You should have received a copy of the GNU + Affero General Public License along with agbsum. + If not, see <https://www.gnu.org/licenses/>. */ #include <agbsum.h> @@ -12,13 +27,16 @@ #include <stdio.h> void -agb_red (void * const restrict buf, FILE * restrict rom) +agb_red (void* const restrict buf, FILE* restrict img) { - fseek (rom, agb_romsrt, SEEK_SET); // We only need to read the part of the ROM that is used for the checksum. + // We only need to read the part of the image + // that is used for the checksum. + fseek (img, agb_iptsrt, SEEK_SET); + size_t const num = agb_sumoff + 0x1u; - - if (fread (buf,0x1u, num, rom) != num) { + + if (fread (buf, 0x1u, num, img) != num) { fputs ("Unable to read ROM\n", stderr); - agb_exi (agb_cnd_err, rom); + agb_exi (agb_cnd_err, img); } } |