This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.cpp
116 lines (96 loc) · 2.73 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <unistd.h>
#include <iostream>
#include "skylander.h"
using namespace std;
void usage() {
printf("\n"
"Usage:\n"
"SkyDumper [-o <filename> | -d] [-i <filename> [-r]]\n"
"-i <filename>\t read Skylander Image from file (default: read from portal)\n"
"-o <filename>\t write Skylander Image to file (default: write to portal)\n"
"-d\t\t write Skylander image to file <Skylander-ID>.bin\n"
"-r\t\t reset Skylander before writing (e.g. reset crystal)\n"
);
}
int main(int argc, char *argv[]) {
unsigned char *buffer;
bool dump, reset, verbose;
char *inFile, *outFile;
const static char *legal_flags = "hrdi:o:v";
inFile = NULL;
outFile = NULL;
dump = false;
reset = false;
verbose = false;
SkylanderIO *skio;
int k;
while ((k = getopt(argc, argv, legal_flags)) != -1) {
switch (k) {
case 'i':
inFile = new char[strlen(optarg) + 1];
strcpy(inFile, optarg);
break;
case 'd':
dump = true;
break;
case 'o':
outFile = new char[strlen(optarg) + 1];
strcpy(outFile, optarg);
break;
case 'r':
reset = true;
break;
case 'v':
verbose = true;
break;
case 'h':
usage();
exit(0);
default:
usage();
exit(0);
}
}
// validate command line options
if (!inFile && !outFile && !dump) {
printf("missing arguments -i <file> or -o <file>\n");
usage();
exit(0);
}
skio = new SkylanderIO();
if (inFile) {
printf("Read Skylander Image from %s\n", inFile);
skio->ReadSkylanderFile(inFile);
} else {
printf("Read/Dump Skylander from portal\n");
skio->ReadSkylander();
}
if (reset) {
printf("Reset Skylander\n");
skio->ResetSkylander();
}
buffer = skio->getSkylander();
if (verbose)
skio->dump(buffer, 1024);
if (dump) {
char f[16];
sprintf(f, "%02X%02X.bin", buffer[0x11], buffer[0x10]);
outFile = new char[strlen(f) + 1];
strcpy(outFile, f);
}
if (outFile) {
skio->FileExists(outFile);
printf("Write Skylander Image to %s\n", outFile);
skio->WriteSkylanderFile(outFile, buffer);
} else {
printf("Write Skylander to portal\n");
skio->WriteSkylander();
}
skio = NULL;
delete skio;
printf("\n... Success!\n");
return 0;
}