Skip to content

Commit

Permalink
fixed compile on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jan 1, 2010
1 parent c5aa747 commit 8035c42
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ macosx:
linux:
$(CC) irecovery.c -o irecovery $(CFLAGS_LNX)

clean:
rm -rf *.o irecovery
35 changes: 24 additions & 11 deletions irecovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ void irecv_close(struct usb_dev_handle *handle) {
}
}

void irecv_reset(struct usb_dev_handle *handle) {
if (handle != NULL) {
usb_reset(handle);
}
}

int irecv_sendfile(struct usb_dev_handle *handle, char *filename) {
FILE* file = fopen(filename, "rb");
if (file == NULL) {
Expand Down Expand Up @@ -201,7 +207,7 @@ int irecv_sendcmd(struct usb_dev_handle *handle, char *command) {
return 1;
}

if (!usb_control_msg(handle, 0x40, 0, 0, 0, command, length + 1, 10)) {
if (!usb_control_msg(handle, 0x40, 0, 0, 0, command, length + 1, 1000)) {
printf("[!] %s", usb_strerror());
}

Expand All @@ -221,7 +227,15 @@ int irecv_parsecmd(struct usb_dev_handle *handle, char *command) {
char* filename = strtok(NULL, " ");
if (filename != NULL) {
irecv_sendfile(handle, filename);
irecv_sendcmd(handle, &command[strlen(action) + 1]);
irecv_reset(handle);

char* cmd = "bgcolor";
char* args = strtok(NULL, "\n");
char* send = malloc(strlen(cmd) + strlen(args) + 1000);
printf("Sending %s %s\n", filename, args);
sprintf(send, "%s %s", cmd, args);
irecv_sendcmd(handle, send);
free(send);
}
}

Expand All @@ -230,6 +244,11 @@ int irecv_parsecmd(struct usb_dev_handle *handle, char *command) {
}

void irecv_console(struct usb_dev_handle *handle) {
if (usb_set_configuration(handle, 1) < 0) {
printf("%s\n", usb_strerror());
return;
}

if (usb_claim_interface(handle, 1) < 0) {
printf("%s\n", usb_strerror());
return;
Expand All @@ -256,7 +275,7 @@ void irecv_console(struct usb_dev_handle *handle) {
int bytes = 0;
while (bytes >= 0) {
memset(buffer, 0, BUF_SIZE);
bytes = usb_bulk_read(handle, 0x81, buffer, BUF_SIZE, 250);
bytes = usb_bulk_read(handle, 0x81, buffer, BUF_SIZE, 1000);
if (bytes > 0) {
int i = 0;
int next = 0;
Expand Down Expand Up @@ -288,17 +307,11 @@ void irecv_console(struct usb_dev_handle *handle) {
free(command);
}

fclose(fd);
usb_release_interface(handle, 0);
fclose(fd);
usb_release_interface(handle, 1);
free(buffer);
}

void irecv_reset(struct usb_dev_handle *handle) {
if (handle != NULL) {
usb_reset(handle);
}
}

void irecv_usage(void) {
printf("./irecovery [args]\n");
printf("\t-f <file>\t\tupload file.\n");
Expand Down

0 comments on commit 8035c42

Please sign in to comment.