Created
April 13, 2022 15:26
-
-
Save Lessica/2b25d965bfcea382bf1f194343322d07 to your computer and use it in GitHub Desktop.
Static patch of idevicerestore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/fdr.c b/src/fdr.c | |
index ee76de6..c092b0b 100644 | |
--- a/src/fdr.c | |
+++ b/src/fdr.c | |
@@ -549,7 +549,7 @@ static int fdr_handle_proxy_cmd(fdr_client_t fdr) | |
} | |
/* else wait for messages and forward them */ | |
- int sockfd = socket_connect(host, port); | |
+ int sockfd = idevicerestore_socket_connect(host, port); | |
free(host); | |
if (sockfd < 0) { | |
free(buf); | |
@@ -579,7 +579,7 @@ static int fdr_handle_proxy_cmd(fdr_client_t fdr) | |
debug("Sending %u bytes of data\n", bytes); | |
sent = 0; | |
while (sent < bytes) { | |
- int s = socket_send(sockfd, buf + sent, bytes - sent); | |
+ int s = idevicerestore_socket_send(sockfd, buf + sent, bytes - sent); | |
if (s < 0) { | |
break; | |
} | |
@@ -587,12 +587,12 @@ static int fdr_handle_proxy_cmd(fdr_client_t fdr) | |
} | |
if (sent != bytes) { | |
error("ERROR: Sending proxy payload failed: %s. Sent %u of %u bytes. \n", strerror(errno), sent, bytes); | |
- socket_close(sockfd); | |
+ idevicerestore_socket_close(sockfd); | |
res = -1; | |
break; | |
} | |
} | |
- bytes_ret = socket_receive_timeout(sockfd, buf, bufsize, 0, 100); | |
+ bytes_ret = idevicerestore_idevicerestore_socket_receive_timeout(sockfd, buf, bufsize, 0, 100); | |
if (bytes_ret < 0) { | |
if (errno) | |
error("ERROR: FDR %p receiving proxy payload failed: %s\n", | |
@@ -623,7 +623,7 @@ static int fdr_handle_proxy_cmd(fdr_client_t fdr) | |
} | |
} else serial++; | |
} | |
- socket_close(sockfd); | |
+ idevicerestore_socket_close(sockfd); | |
free(buf); | |
return res; | |
} | |
diff --git a/src/socket.c b/src/socket.c | |
index 777b23e..5f55511 100644 | |
--- a/src/socket.c | |
+++ b/src/socket.c | |
@@ -58,13 +58,13 @@ static int wsa_init = 0; | |
static int verbose = 0; | |
-void socket_set_verbose(int level) | |
+void idevicerestore_socket_set_verbose(int level) | |
{ | |
verbose = level; | |
} | |
#ifndef WIN32 | |
-int socket_create_unix(const char *filename) | |
+int idevicerestore_socket_create_unix(const char *filename) | |
{ | |
struct sockaddr_un name; | |
int sock; | |
@@ -85,7 +85,7 @@ int socket_create_unix(const char *filename) | |
#ifdef SO_NOSIGPIPE | |
if (setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void*)&yes, sizeof(int)) == -1) { | |
perror("setsockopt()"); | |
- socket_close(sock); | |
+ idevicerestore_socket_close(sock); | |
return -1; | |
} | |
#endif | |
@@ -97,20 +97,20 @@ int socket_create_unix(const char *filename) | |
if (bind(sock, (struct sockaddr*)&name, sizeof(name)) < 0) { | |
perror("bind"); | |
- socket_close(sock); | |
+ idevicerestore_socket_close(sock); | |
return -1; | |
} | |
if (listen(sock, 10) < 0) { | |
perror("listen"); | |
- socket_close(sock); | |
+ idevicerestore_socket_close(sock); | |
return -1; | |
} | |
return sock; | |
} | |
-int socket_connect_unix(const char *filename) | |
+int idevicerestore_socket_connect_unix(const char *filename) | |
{ | |
struct sockaddr_un name; | |
int sfd = -1; | |
@@ -152,7 +152,7 @@ int socket_connect_unix(const char *filename) | |
#ifdef SO_NOSIGPIPE | |
if (setsockopt(sfd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&yes, sizeof(int)) == -1) { | |
perror("setsockopt()"); | |
- socket_close(sfd); | |
+ idevicerestore_socket_close(sfd); | |
return -1; | |
} | |
#endif | |
@@ -162,7 +162,7 @@ int socket_connect_unix(const char *filename) | |
name.sun_path[sizeof(name.sun_path) - 1] = 0; | |
if (connect(sfd, (struct sockaddr*)&name, sizeof(name)) < 0) { | |
- socket_close(sfd); | |
+ idevicerestore_socket_close(sfd); | |
if (verbose >= 2) | |
fprintf(stderr, "%s: connect: %s\n", __func__, | |
strerror(errno)); | |
@@ -173,7 +173,7 @@ int socket_connect_unix(const char *filename) | |
} | |
#endif | |
-int socket_create(uint16_t port) | |
+int idevicerestore_socket_create(uint16_t port) | |
{ | |
int sfd = -1; | |
int yes = 1; | |
@@ -196,14 +196,14 @@ int socket_create(uint16_t port) | |
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(int)) == -1) { | |
perror("setsockopt()"); | |
- socket_close(sfd); | |
+ idevicerestore_socket_close(sfd); | |
return -1; | |
} | |
#ifdef SO_NOSIGPIPE | |
if (setsockopt(sfd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&yes, sizeof(int)) == -1) { | |
perror("setsockopt()"); | |
- socket_close(sfd); | |
+ idevicerestore_socket_close(sfd); | |
return -1; | |
} | |
#endif | |
@@ -215,20 +215,20 @@ int socket_create(uint16_t port) | |
if (0 > bind(sfd, (struct sockaddr *) &saddr, sizeof(saddr))) { | |
perror("bind()"); | |
- socket_close(sfd); | |
+ idevicerestore_socket_close(sfd); | |
return -1; | |
} | |
if (listen(sfd, 1) == -1) { | |
perror("listen()"); | |
- socket_close(sfd); | |
+ idevicerestore_socket_close(sfd); | |
return -1; | |
} | |
return sfd; | |
} | |
-int socket_connect(const char *addr, uint16_t port) | |
+int idevicerestore_socket_connect(const char *addr, uint16_t port) | |
{ | |
int sfd = -1; | |
int yes = 1; | |
@@ -279,7 +279,7 @@ int socket_connect(const char *addr, uint16_t port) | |
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(int)) == -1) { | |
perror("setsockopt()"); | |
- socket_close(sfd); | |
+ idevicerestore_socket_close(sfd); | |
continue; | |
} | |
@@ -314,7 +314,7 @@ int socket_connect(const char *addr, uint16_t port) | |
} | |
} | |
} | |
- socket_close(sfd); | |
+ idevicerestore_socket_close(sfd); | |
} | |
freeaddrinfo(result); | |
@@ -335,7 +335,7 @@ int socket_connect(const char *addr, uint16_t port) | |
#ifdef SO_NOSIGPIPE | |
if (setsockopt(sfd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&yes, sizeof(int)) == -1) { | |
perror("setsockopt()"); | |
- socket_close(sfd); | |
+ idevicerestore_socket_close(sfd); | |
return -1; | |
} | |
#endif | |
@@ -355,7 +355,7 @@ int socket_connect(const char *addr, uint16_t port) | |
return sfd; | |
} | |
-int socket_check_fd(int fd, fd_mode fdm, unsigned int timeout) | |
+int idevicerestore_socket_check_fd(int fd, fd_mode fdm, unsigned int timeout) | |
{ | |
fd_set fds; | |
int sret; | |
@@ -425,7 +425,7 @@ int socket_check_fd(int fd, fd_mode fdm, unsigned int timeout) | |
return sret; | |
} | |
-int socket_accept(int fd, uint16_t port) | |
+int idevicerestore_socket_accept(int fd, uint16_t port) | |
{ | |
#ifdef WIN32 | |
int addr_len; | |
@@ -446,12 +446,12 @@ int socket_accept(int fd, uint16_t port) | |
return result; | |
} | |
-int socket_shutdown(int fd, int how) | |
+int idevicerestore_socket_shutdown(int fd, int how) | |
{ | |
return shutdown(fd, how); | |
} | |
-int socket_close(int fd) { | |
+int idevicerestore_socket_close(int fd) { | |
#ifdef WIN32 | |
return closesocket(fd); | |
#else | |
@@ -459,24 +459,24 @@ int socket_close(int fd) { | |
#endif | |
} | |
-int socket_receive(int fd, void *data, size_t length) | |
+int idevicerestore_socket_receive(int fd, void *data, size_t length) | |
{ | |
- return socket_receive_timeout(fd, data, length, 0, RECV_TIMEOUT); | |
+ return idevicerestore_idevicerestore_socket_receive_timeout(fd, data, length, 0, RECV_TIMEOUT); | |
} | |
-int socket_peek(int fd, void *data, size_t length) | |
+int idevicerestore_socket_peek(int fd, void *data, size_t length) | |
{ | |
- return socket_receive_timeout(fd, data, length, MSG_PEEK, RECV_TIMEOUT); | |
+ return idevicerestore_idevicerestore_socket_receive_timeout(fd, data, length, MSG_PEEK, RECV_TIMEOUT); | |
} | |
-int socket_receive_timeout(int fd, void *data, size_t length, int flags, | |
+int idevicerestore_idevicerestore_socket_receive_timeout(int fd, void *data, size_t length, int flags, | |
unsigned int timeout) | |
{ | |
int res; | |
int result; | |
// check if data is available | |
- res = socket_check_fd(fd, FDM_READ, timeout); | |
+ res = idevicerestore_socket_check_fd(fd, FDM_READ, timeout); | |
if (res <= 0) { | |
return res; | |
} | |
@@ -494,7 +494,7 @@ int socket_receive_timeout(int fd, void *data, size_t length, int flags, | |
return result; | |
} | |
-int socket_send(int fd, void *data, size_t length) | |
+int idevicerestore_socket_send(int fd, void *data, size_t length) | |
{ | |
int flags = 0; | |
#ifdef MSG_NOSIGNAL | |
diff --git a/src/socket.h b/src/socket.h | |
index e31de6b..e907c2c 100644 | |
--- a/src/socket.h | |
+++ b/src/socket.h | |
@@ -42,24 +42,24 @@ typedef enum fd_mode fd_mode; | |
#endif | |
#ifndef WIN32 | |
-int socket_create_unix(const char *filename); | |
-int socket_connect_unix(const char *filename); | |
+int idevicerestore_socket_create_unix(const char *filename); | |
+int idevicerestore_socket_connect_unix(const char *filename); | |
#endif | |
-int socket_create(uint16_t port); | |
-int socket_connect(const char *addr, uint16_t port); | |
-int socket_check_fd(int fd, fd_mode fdm, unsigned int timeout); | |
-int socket_accept(int fd, uint16_t port); | |
+int idevicerestore_socket_create(uint16_t port); | |
+int idevicerestore_socket_connect(const char *addr, uint16_t port); | |
+int idevicerestore_socket_check_fd(int fd, fd_mode fdm, unsigned int timeout); | |
+int idevicerestore_socket_accept(int fd, uint16_t port); | |
-int socket_shutdown(int fd, int how); | |
-int socket_close(int fd); | |
+int idevicerestore_socket_shutdown(int fd, int how); | |
+int idevicerestore_socket_close(int fd); | |
-int socket_receive(int fd, void *data, size_t size); | |
-int socket_peek(int fd, void *data, size_t size); | |
-int socket_receive_timeout(int fd, void *data, size_t size, int flags, | |
+int idevicerestore_socket_receive(int fd, void *data, size_t size); | |
+int idevicerestore_socket_peek(int fd, void *data, size_t size); | |
+int idevicerestore_idevicerestore_socket_receive_timeout(int fd, void *data, size_t size, int flags, | |
unsigned int timeout); | |
-int socket_send(int fd, void *data, size_t size); | |
+int idevicerestore_socket_send(int fd, void *data, size_t size); | |
-void socket_set_verbose(int level); | |
+void idevicerestore_socket_set_verbose(int level); | |
#endif /* SOCKET_SOCKET_H */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment