Skip to content

Commit 84c326e

Browse files
committed
Update copy function from PR comments
Replace spaces by tabs Invert src and dst in copy functions Signed-off-by: Stany MARCEL <[email protected]>
1 parent de4ffa1 commit 84c326e

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

amiibo.c

+18-19
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,22 @@ bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys * amiiboKeys, const char * path) {
158158
}
159159

160160

161-
void nfc3d_amiibo_copy_app_data(uint8_t * dst, const uint8_t * src) {
162-
163-
uint16_t *ami_nb_wr = (uint16_t*)(dst + 0x29);
164-
uint16_t *cfg_nb_wr = (uint16_t*)(dst + 0xB4);
165-
166-
/* increment write counters */
167-
*ami_nb_wr = htobe16(be16toh(*ami_nb_wr) + 1);
168-
*cfg_nb_wr = htobe16(be16toh(*cfg_nb_wr) + 1);
169-
170-
/* copy flags */
171-
dst[0x2C] = src[0x2C];
172-
/* copy programID */
173-
memcpy(dst + 0xAC, src + 0xAC, 8);
174-
/* copy AppID */
175-
memcpy(dst + 0xB6, src + 0xB6, 4);
176-
177-
/* copy AppData */
178-
memcpy(dst + 0xDC, src + 0xDC, 216);
179-
161+
void nfc3d_amiibo_copy_app_data(const uint8_t * src, uint8_t * dst) {
162+
163+
uint16_t *ami_nb_wr = (uint16_t*)(dst + 0x29);
164+
uint16_t *cfg_nb_wr = (uint16_t*)(dst + 0xB4);
165+
166+
/* increment write counters */
167+
*ami_nb_wr = htobe16(be16toh(*ami_nb_wr) + 1);
168+
*cfg_nb_wr = htobe16(be16toh(*cfg_nb_wr) + 1);
169+
170+
/* copy flags */
171+
dst[0x2C] = src[0x2C];
172+
/* copy programID */
173+
memcpy(dst + 0xAC, src + 0xAC, 8);
174+
/* copy AppID */
175+
memcpy(dst + 0xB6, src + 0xB6, 4);
176+
/* copy AppData */
177+
memcpy(dst + 0xDC, src + 0xDC, 216);
180178
}
179+

amiitool.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(int argc, char ** argv) {
3939
self = argv[0];
4040

4141
char * infile = NULL;
42-
char * savefile = NULL;
42+
char * savefile = NULL;
4343
char * outfile = NULL;
4444
char * keyfile = NULL;
4545
char op = '\0';
@@ -144,7 +144,7 @@ int main(int argc, char ** argv) {
144144
}
145145
}
146146

147-
nfc3d_amiibo_copy_app_data(plain_base, plain_save);
147+
nfc3d_amiibo_copy_app_data(plain_save, plain_base);
148148
nfc3d_amiibo_pack(&amiiboKeys, plain_base, modified);
149149
}
150150

@@ -169,4 +169,4 @@ int main(int argc, char ** argv) {
169169
fclose(f);
170170

171171
return 0;
172-
}
172+
}

include/nfc3d/amiibo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ typedef struct {
2424
bool nfc3d_amiibo_unpack(const nfc3d_amiibo_keys * amiiboKeys, const uint8_t * tag, uint8_t * plain);
2525
void nfc3d_amiibo_pack(const nfc3d_amiibo_keys * amiiboKeys, const uint8_t * plain, uint8_t * tag);
2626
bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys * amiiboKeys, const char * path);
27-
void nfc3d_amiibo_copy_app_data(uint8_t * dst, const uint8_t * src);
27+
void nfc3d_amiibo_copy_app_data(const uint8_t * src, uint8_t * dst);
2828

2929
#endif

0 commit comments

Comments
 (0)