/
sget.c
124 lines (110 loc) · 2.8 KB
/
sget.c
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
117
118
119
120
121
122
123
124
#include "usbtransfer.h"
void usage();
void getOptions(int argc, char **argv, uint8_t * readBuffer,usb_dev_handle *dev);
void getSlotNo(int slotno,usb_dev_handle *dev);
void getFilename(char *filename,int slotno,usb_dev_handle *dev);
int main(int argc, char **argv) {
usb_dev_handle *dev = NULL; /* the device handle */
uint8_t readBuffer[0x200*0x100];
/* Set up USB */
usb_init();
usb_find_busses();
usb_find_devices();
if (!(dev = open_dev())) {
perror("device not found!\n");
exit(EXIT_FAILURE);
}
/*
if (usb_set_configuration(dev, 1) < 0) {
perror("setting config 1 failed\n");
usb_close(dev);
exit(EXIT_FAILURE);
}
*/
if (usb_claim_interface(dev, 0) < 0)
{
perror("claiming interface failed\n");
usb_close(dev);
exit(EXIT_FAILURE);
}
getOptions(argc,argv,readBuffer,dev);
/* Clean up */
usb_release_interface(dev, 0);
usb_close(dev);
exit(0);
}
void usage() {
printf("Sundriver get iso v 0.1: \n");
printf("Usage: \n");
printf("-s slotno 0..66\n");
printf("-h print this text\n");
}
void getOptions(int argc, char **argv, uint8_t * readBuffer,usb_dev_handle *dev) {
int c;
opterr = 0; //clear errors
int slotno;
while ((c = getopt (argc, argv, "s:h")) != -1)
switch (c) {
case 's':
slotno=atoi(optarg);
break;
case 'h':
usage();
exit(0);
break;
case '?':
usage();
exit(0);
default:
abort ();
}
getSlotNo(slotno,dev);
}
void getSlotNo(int slotno,usb_dev_handle *dev){
char filename[0xee];
uint8_t readBuffer[0x80*0x200];
printf("options %i\n",slotno,filename);
getFilename(filename,slotno,dev);
//open device for write
int fd;
/* open64 file for write */
fd = open64( filename,O_CREAT|O_WRONLY|O_TRUNC, 0777);
if (fd==-1) {
perror("open( filename,O_CREAT|O_WRONLY|O_TRUNC, 0777)\n");
exit(EXIT_FAILURE);
}
int i;
int bytesRead = 0;
//0x380000 start of isos
//slotno -1 *0x8c4000 + start
int startblock = (slotno-1)*0x8c4000+0x380000;
int end = slotno*0x8c4000+0x380000;
for(i=startblock;i<=end;i=i+0x80){
read10(readBuffer,0x80,i,dev);
write(fd,readBuffer,0x80*0x200);
}
/*int j=0;
for (j=0;j<1;j++) {
//numberOfBlocks,uint32_t startBlock
read10(0x80,0x0,dev,fd);
}
*/
if (close(fd) == -1) {
perror("close(fd)\n");
exit(EXIT_FAILURE);
}
/*
bytesWrite = write(fd,tmpBuffer,bytesRead);
if (bytesWrite == -1) {
perror("write to file\n");
exit(EXIT_FAILURE);
}
*/
}
void getFilename(char *filename,int slotno,usb_dev_handle *dev){
uint8_t readBuffer[0x200*0x100];
read10(readBuffer,0x100,0x0,dev);
memset(filename,0,0xee);
memcpy(filename,&readBuffer[slotno*0x100+0x1],0xee);
printf("Slot:\t%i\tISO name: %s\n",slotno,filename);
}