diff --git a/_Projects_/ps3netsrv/Makefile b/_Projects_/ps3netsrv/Makefile index 128e7e303..6232ca8e2 100644 --- a/_Projects_/ps3netsrv/Makefile +++ b/_Projects_/ps3netsrv/Makefile @@ -13,6 +13,10 @@ CPPFLAGS += -Wall -Wno-format -I./include -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_B #CFLAGS += -DOPT_FILE_SEEK #CPPFLAGS += -DOPT_FILE_SEEK +#OUTPUT := makeiso +#CFLAGS += -DMAKEISO +#CPPFLAGS += -DMAKEISO + #CFLAGS += -DNOSSL #CPPFLAGS +=-DNOSSL #OBJS = src/main.o src/compat.o src/mem.o src/File.o src/VIsoFile.o diff --git a/_Projects_/ps3netsrv/bins/Windows/makeiso.exe b/_Projects_/ps3netsrv/bins/Windows/makeiso.exe new file mode 100644 index 000000000..bed3a64a6 Binary files /dev/null and b/_Projects_/ps3netsrv/bins/Windows/makeiso.exe differ diff --git a/_Projects_/ps3netsrv/bins/Windows/ps3netsrv.exe b/_Projects_/ps3netsrv/bins/Windows/ps3netsrv.exe index 443e49248..ed1f667ef 100644 Binary files a/_Projects_/ps3netsrv/bins/Windows/ps3netsrv.exe and b/_Projects_/ps3netsrv/bins/Windows/ps3netsrv.exe differ diff --git a/_Projects_/ps3netsrv/include/color.h b/_Projects_/ps3netsrv/include/color.h index be8f3b3de..66b62b363 100644 --- a/_Projects_/ps3netsrv/include/color.h +++ b/_Projects_/ps3netsrv/include/color.h @@ -48,6 +48,7 @@ static void set_red_text(void) #endif } +#ifndef MAKEISO static void set_gray_text(void) { #ifdef WIN32 @@ -56,5 +57,6 @@ static void set_gray_text(void) printf("\033[1;30m"); #endif } +#endif #endif \ No newline at end of file diff --git a/_Projects_/ps3netsrv/src/File.cpp b/_Projects_/ps3netsrv/src/File.cpp index 53d204de6..69e6a635e 100644 --- a/_Projects_/ps3netsrv/src/File.cpp +++ b/_Projects_/ps3netsrv/src/File.cpp @@ -8,6 +8,8 @@ #include "common.h" #include "compat.h" +extern int make_iso; + static const int FAILED = -1; static const int SUCCEEDED = 0; @@ -98,7 +100,7 @@ int File::open(const char *path, int flags) path_ps3iso_loc = strstr((char *)path, (char *)"ps3iso"); char *path_ext_loc = NULL; - if (path_ps3iso_loc) + if (path_ps3iso_loc || make_iso) { path_ext_loc = strstr((char *)(path + flen), (char *)".iso"); if (path_ext_loc == NULL) @@ -106,7 +108,9 @@ int File::open(const char *path, int flags) } // Encryption only makes sense for .iso or .ISO files in the .../PS3ISO/ folder so exit quick if req is is not related. - if (is_multipart || (path_ps3iso_loc == NULL) || (path_ext_loc == NULL) || (path_ext_loc < path_ps3iso_loc)) + if(make_iso) + ; + else if (is_multipart || (path_ps3iso_loc == NULL) || (path_ext_loc == NULL) || (path_ext_loc < path_ps3iso_loc)) { // Clean-up old region_info_ (even-though it shouldn't be needed). if (region_info_ != NULL) @@ -161,9 +165,9 @@ int File::open(const char *path, int flags) key_path[path_ext_loc - path + 4] = 'y'; key_path[path_ext_loc - path + 5] = '\0'; - key_fd = open_file(key_path, flags); + key_fd = open_file(key_path, O_RDONLY); - if (!FD_OK(key_fd)) + if (!FD_OK(key_fd) && (path_ext_loc > path)) { // Check for redump encrypted mode by looking for the ".key" is the same path of the ".iso". key_path[path_ext_loc - path + 1] = 'k'; @@ -171,10 +175,10 @@ int File::open(const char *path, int flags) key_path[path_ext_loc - path + 3] = 'y'; key_path[path_ext_loc - path + 4] = '\0'; - key_fd = open_file(key_path, flags); + key_fd = open_file(key_path, O_RDONLY); } - if (!FD_OK(key_fd)) + if (!FD_OK(key_fd) && (path_ps3iso_loc > path)) { // Check for redump encrypted mode by looking for the ".key" or ".dkey" file in the "REDKEY" folder. key_path[path_ps3iso_loc - path + 0] = 'R'; @@ -184,7 +188,7 @@ int File::open(const char *path, int flags) key_path[path_ps3iso_loc - path + 4] = 'E'; key_path[path_ps3iso_loc - path + 5] = 'Y'; - key_fd = open_file(key_path, flags); + key_fd = open_file(key_path, O_RDONLY); if (!FD_OK(key_fd)) { @@ -195,7 +199,7 @@ int File::open(const char *path, int flags) key_path[path_ext_loc - path + 4] = 'y'; key_path[path_ext_loc - path + 5] = '\0'; - key_fd = open_file(key_path, flags); + key_fd = open_file(key_path, O_RDONLY); } } diff --git a/_Projects_/ps3netsrv/src/main.cpp b/_Projects_/ps3netsrv/src/main.cpp index 83b460526..b5e0496dc 100644 --- a/_Projects_/ps3netsrv/src/main.cpp +++ b/_Projects_/ps3netsrv/src/main.cpp @@ -61,11 +61,14 @@ typedef struct _client_t int subdirs; } client_t; -static client_t clients[MAX_CLIENTS]; +int make_iso = VISO_NONE; static char root_directory[MAX_PATH_LEN]; static size_t root_len = 0; +#ifndef MAKEISO +static client_t clients[MAX_CLIENTS]; + static int initialize_socket(uint16_t port) { int s; @@ -109,6 +112,7 @@ static int initialize_socket(uint16_t port) return s; } +#endif #ifndef WIN32 static int recv_all(int s, void *buf, int size) @@ -237,6 +241,115 @@ static void finalize_client(client_t *client) memset(client, 0, sizeof(client_t)); } +static int create_iso(char *folder_path, char *fileout, int viso) +{ + int ret = FAILED; + char *filepath = NULL; + client_t client; + + if(!folder_path || *folder_path == '\0' || !fileout || *fileout == '\0') + { + printf("ERROR: invalid path length for open command\n"); + goto exit_function; + } + + initialize_client(&client); + + if(!client.buf) + { + printf("CRITICAL: memory allocation error\n"); + goto exit_function; + } + + filepath = (char *)malloc(MAX_PATH_LEN + strlen(folder_path) + 1); + if(!filepath) + { + printf("CRITICAL: memory allocation error\n"); + goto exit_function; + } + + strcpy(filepath, folder_path); + + if(strstr(filepath, ".iso") || strstr(filepath, ".ISO")) + { + client.ro_file = new File(); + viso = VISO_NONE; + } + else + { + printf("building virtual iso...\n"); + client.ro_file = new VIsoFile((viso == VISO_PS3)); + } + + if(client.ro_file->open(filepath, O_RDONLY) < 0) + { + printf("open error on \"%s\" (viso=%d)\n", filepath, viso); + + delete client.ro_file; + client.ro_file = NULL; + goto exit_function; + } + else + { + file_stat_t st; + if(client.ro_file->fstat(&st) < 0) + { + printf("fstat error on \"%s\" (viso=%d)\n", filepath, viso); + + delete client.ro_file; + client.ro_file = NULL; + goto exit_function; + } + else + { + printf("output: %s\n", fileout); + client.wo_file = new File(); + + if(client.wo_file->open(fileout, O_WRONLY|O_CREAT|O_TRUNC) < 0) + { + printf("ERROR: create error on \"%s\"\n", filepath); + } + else + { + char *buffer = (char *)client.buf; + uint64_t offset = 0; + uint64_t rem_size = st.file_size % BUFFER_SIZE; + uint64_t iso_size = st.file_size - rem_size; + if(iso_size >= BUFFER_SIZE) + { + for(; offset < iso_size; offset += BUFFER_SIZE) + { + printf("Dumping ISO: offset %llu of %llu\n", (long long unsigned int)offset, (long long unsigned int)st.file_size); + client.ro_file->seek(offset, SEEK_SET); + client.ro_file->read(buffer, BUFFER_SIZE); + client.wo_file->write(buffer, BUFFER_SIZE); + } + } + if(rem_size > 0) + { + printf("Dumping ISO: offset %llu of %llu\n", (long long unsigned int)offset, (long long unsigned int)st.file_size); + client.ro_file->seek(offset, SEEK_SET); + client.ro_file->read(buffer, rem_size); + client.wo_file->write(buffer, rem_size); + } + } + + delete client.wo_file; + client.wo_file = NULL; + + ret = SUCCEEDED; + } + } + +exit_function: + + finalize_client(&client); + + if(filepath) free(filepath); + + return ret; +} + static char *translate_path(char *path, int *viso) { if(!path) return NULL; @@ -377,6 +490,8 @@ static char *translate_path(char *path, int *viso) return p; } +#ifndef MAKEISO + static int64_t calculate_directory_size(char *path) { int64_t result = 0; @@ -1659,19 +1774,26 @@ void *client_thread(void *arg) finalize_client(client); return NULL; } +#endif //#ifndef MAKEISO int main(int argc, char *argv[]) { +#ifndef MAKEISO int s; uint16_t port = NETISO_PORT; uint32_t whitelist_start = 0; uint32_t whitelist_end = 0; +#endif get_normal_color(); // Show build number set_white_text(); - printf("ps3netsrv build 20231215"); +#ifndef MAKEISO + printf("ps3netsrv build 20240210"); +#else + printf("makeiso build 20240210"); +#endif set_red_text(); printf(" (mod by aldostools)\n"); @@ -1685,10 +1807,13 @@ int main(int argc, char *argv[]) } #endif - file_stat_t fs; - if(argc < 2) { +#ifdef MAKEISO + printf( "\nUsage: makeiso [directory] [PS3/ISO]\n"); + goto exit_error; +#else + file_stat_t fs; char *filename = strrchr(argv[0], '/'); if(!filename) filename = strrchr(argv[0], '\\'); if( filename) filename++; @@ -1746,6 +1871,7 @@ int main(int argc, char *argv[]) goto exit_error; } +#endif //#ifdef MAKEISO } // Check shared directory @@ -1758,6 +1884,23 @@ int main(int argc, char *argv[]) strcpy(root_directory, argv[1]); normalize_path(root_directory, true); + if(argc < 3) + { + char sfo_path[MAX_PATH]; + snprintf(sfo_path, sizeof(sfo_path) - 1, "%s/PS3_GAME/PARAM.SFO", root_directory); + + file_stat_t fs; + if(stat_file(sfo_path, &fs) >= 0) + make_iso = VISO_PS3; + else if(strstr(root_directory, ".iso") || strstr(root_directory, ".ISO")) + make_iso = VISO_ISO; +#ifdef MAKEISO + else + make_iso = VISO_ISO; +#endif + } + +#ifndef MAKEISO // Use current path as default if(*root_directory == 0) { @@ -1787,23 +1930,32 @@ int main(int argc, char *argv[]) if(sscanf(argv[2], "%u", &u) != 1) { - printf("Wrong port specified.\n"); - goto exit_error; + if(strstr(argv[2], "PS3") || strstr(argv[2], "ps3")) + make_iso = VISO_PS3; + else if(strstr(argv[2], "ISO") || strstr(argv[2], "iso")) + make_iso = VISO_ISO; + else + { + printf("Wrong port specified.\n"); + goto exit_error; + } } - + else + { #ifdef WIN32 - uint32_t min = 1; + uint32_t min = 1; #else - uint32_t min = 1024; + uint32_t min = 1024; #endif - if ((u < min) || (u > 65535)) - { - printf("Port must be in %d-65535 range.\n", min); - goto exit_error; - } + if ((u < min) || (u > 65535)) + { + printf("Port must be in %d-65535 range.\n", min); + goto exit_error; + } - port = u; + port = u; + } } // Parse whitelist argument @@ -1885,6 +2037,7 @@ int main(int argc, char *argv[]) ///////////////// // Show Host IP ///////////////// + if(make_iso == VISO_NONE) #ifdef WIN32 { char host[256]; @@ -1929,7 +2082,22 @@ int main(int argc, char *argv[]) freeifaddrs(addrs); } #endif + +#endif // #ifndef MAKEISO + + if(make_iso) + { + char outfile[MAX_PATH_LEN]; + sprintf(outfile, "%s.iso", strrchr(root_directory, '/') + 1); + + char *pos1 = strstr(outfile, ".iso."); if(pos1) sprintf(pos1, ".new.iso"); + char *pos2 = strstr(outfile, ".ISO."); if(pos2) sprintf(pos2, ".new.iso"); + + create_iso(root_directory, outfile, make_iso); + goto exit_error; + } +#ifndef MAKEISO ////////////// // main loop ////////////// @@ -2034,7 +2202,8 @@ int main(int argc, char *argv[]) #endif return SUCCEEDED; - +#endif //#ifndef MAKEISO + exit_error: printf("\n\nPress ENTER to continue..."); getchar();