Finished libarchive port

This commit is contained in:
TheFloW 2017-12-30 23:08:04 +01:00
parent cc320b16d4
commit 77bddb8836
22 changed files with 169 additions and 3070 deletions

View File

@ -98,7 +98,6 @@ add_executable(VitaShell
elf.c
sha1.c
minizip/zip.c
minizip/unzip.c
minizip/ioapi.c
bm.c
audio/vita_audio.c

View File

@ -32,11 +32,88 @@ char *uncompressBuffer(const Elf32_Ehdr *ehdr, const Elf32_Phdr *phdr, const seg
const char *buffer);
int archiveCheckFilesForUnsafeFself() {
// TODO
FileListEntry *archive_entry = archive_list.head;
int i;
for (i = 0; i < archive_list.length; i++) {
char path[MAX_PATH_LENGTH];
snprintf(path, MAX_PATH_LENGTH - 1, "%s/%s", archive_file, archive_entry->name);
// Open
SceUID fd = archiveFileOpen(path, SCE_O_RDONLY, 0);
if (fd >= 0) {
uint32_t magic = 0;
archiveFileRead(fd, &magic, sizeof(uint32_t));
// SCE magic
if (magic == 0x00454353) {
char sce_header[0x84];
archiveFileRead(fd, sce_header, sizeof(sce_header));
uint64_t elf1_offset = *(uint64_t *)(sce_header + 0x3C);
uint64_t phdr_offset = *(uint64_t *)(sce_header + 0x44);
uint64_t section_info_offset = *(uint64_t *)(sce_header + 0x54);
// jump to elf1
// Until here we have read 0x88 bytes
int i;
for (i = 0; i < elf1_offset - 0x88; i += sizeof(uint32_t)) {
uint32_t dummy = 0;
archiveFileRead(fd, &dummy, sizeof(uint32_t));
}
// Check imports
char *buffer = malloc(archive_entry->size);
if (buffer) {
archiveFileRead(fd, buffer, archive_entry->size);
Elf32_Ehdr *elf1 = (Elf32_Ehdr*)buffer;
Elf32_Phdr *phdr = (Elf32_Phdr*)(buffer + phdr_offset - elf1_offset);
segment_info *info = (segment_info*)(buffer + section_info_offset - elf1_offset);
// segment is elf2 section
char *segment = buffer + info->offset - elf1_offset;
// zlib compress magic
char *uncompressed_buffer = NULL;
if (segment[0] == 0x78) {
// uncompressedBuffer will return elf2 section
uncompressed_buffer = uncompressBuffer(elf1, phdr, info, segment);
if (uncompressed_buffer) {
segment = uncompressed_buffer;
}
}
int unsafe = checkForUnsafeImports(segment);
if (uncompressed_buffer)
free(uncompressed_buffer);
free(buffer);
if (unsafe) {
archiveFileClose(fd);
return unsafe;
}
}
// Check authid flag
uint64_t authid = *(uint64_t *)(sce_header + 0x7C);
if (authid != 0x2F00000000000002) {
archiveFileClose(fd);
return 1; // Unsafe
}
}
archiveFileClose(fd);
}
// Next
archive_entry = archive_entry->next;
}
return 0; // Safe
}
// TODO: improve traversal
int fileListGetArchiveEntries(FileList *list, const char *path, int sort) {
int res;
@ -74,12 +151,13 @@ int fileListGetArchiveEntries(FileList *list, const char *path, int sort) {
strcpy(entry->name, archive_entry->name + name_length);
entry->is_folder = archive_entry->is_folder;
if (entry->is_folder) {
if (p || archive_entry->is_folder) {
addEndSlash(entry->name);
entry->is_folder = 1;
entry->type = FILE_TYPE_UNKNOWN;
list->folders++;
} else {
entry->is_folder = 0;
entry->type = getFileType(entry->name);
list->files++;
}
@ -295,7 +373,6 @@ int archiveFileGetstat(const char *file, SceIoStat *stat) {
return -1;
}
// TODO: use cache
int archiveFileOpen(const char *file, int flags, SceMode mode) {
int res;
@ -307,6 +384,7 @@ int archiveFileOpen(const char *file, int flags, SceMode mode) {
// Initialize
archive_fd = archive_read_new();
archive_read_support_filter_gzip(archive_fd);
archive_read_support_format_all(archive_fd);
// Open archive file
@ -383,6 +461,7 @@ int archiveOpen(const char *file) {
// Initialize
struct archive *archive = archive_read_new();
archive_read_support_filter_gzip(archive);
archive_read_support_format_all(archive);
// Open archive file

View File

@ -1,219 +0,0 @@
#include "archiveRAR.h"
#include "main.h"
static ArchiveFileNode* root = NULL;
static int32_t filePathLength = -1;
int archiveRAROpen(const char *file) {
root = openRARFile(file);
if (!root) {
return -1;
}
filePathLength = strlen(file);
return 1;
}
int fileListGetRARArchiveEntries(FileList *list, const char *path, int sort) {
if (!root)
return -1;
FileListEntry *entry = malloc(sizeof(FileListEntry));
strcpy(entry->name, DIR_UP);
entry->name_length = strlen(DIR_UP);
entry->is_folder = 1;
entry->type = FILE_TYPE_UNKNOWN;
fileListAddEntry(list, entry, sort);
ArchiveFileNode* node = NULL;
if (strlen(path) == (filePathLength + sizeof(char)))
node = root;
else
node = getFloderNodeFromPath(root,path + filePathLength + sizeof(char));
uint32_t i = 0;
for (; i < node->childCount; i++) {
ArchiveFileNode* _t = (ArchiveFileNode*)(node->childPt[i]);
FileListEntry * childentry = malloc(sizeof(FileListEntry));
strcpy(childentry->name,_t->nodeName);
childentry->name_length = strlen(childentry->name);
childentry->size = _t->data.UnpSize;
childentry->size2 = _t->data.PackSize;
sceRtcSetDosTime(&childentry->atime,_t->data.FileTime);
sceRtcSetDosTime(&childentry->ctime,_t->data.FileTime);
sceRtcSetDosTime(&childentry->mtime,_t->data.FileTime);
if (_t->data.Flags == 0x20) {
addEndSlash(childentry->name);
childentry->is_folder = 1;
list->folders++;
} else {
childentry->type = getFileType(childentry->name);
childentry->is_folder = 0;
list->files++;
}
fileListAddEntry(list, childentry, sort);
}
return 1;
}
int ReadArchiveRARFile(const char *file, void *buf, int size) {
if (filePathLength < 0)
return -1;
char filepath[filePathLength + sizeof(char)];
strncpy(filepath,file,filePathLength);
filepath[filePathLength] = '\0';
struct ExtractHeader header = {memPtr:buf,offset:0,bufferSize:size,file:0,param:NULL};
if (extractRAR(filepath,file + (filePathLength + sizeof(char)),&header) > 0)
return header.offset;
else
return -1;
}
int archiveRARFileGetstat(const char *file, SceIoStat *stat) {
if (!root)
return -1;
const char* p = file + (filePathLength + sizeof(char));
uint32_t p_length = strlen(p);
if (p[p_length-1] == '/')
return -1;
ArchiveFileNode* filenode = getFileNodeFromFilePath(root,p);
if (!filenode)
return -1;
if (stat) {
stat->st_size = filenode->data.UnpSize;
sceRtcSetDosTime(&stat->st_atime,filenode->data.FileTime);
sceRtcSetDosTime(&stat->st_ctime,filenode->data.FileTime);
sceRtcSetDosTime(&stat->st_mtime,filenode->data.FileTime);
}
return 1;
}
int getRARArchivePathInfo(const char *path, uint64_t *size, uint32_t *folders, uint32_t *files) {
if (!root)
return -1;
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
if (archiveRARFileGetstat(path, &stat) < 0) {
FileList list;
memset(&list, 0, sizeof(FileList));
fileListGetRARArchiveEntries(&list, path, SORT_NONE);
FileListEntry *entry = list.head->next; // Ignore ..
int i;
for (i = 0; i < list.length-1; i++) {
char *new_path = malloc(strlen(path) + strlen(entry->name) + 2);
snprintf(new_path, MAX_PATH_LENGTH, "%s%s", path, entry->name);
getRARArchivePathInfo(new_path, size, folders, files);
free(new_path);
entry = entry->next;
}
if (folders)
(*folders)++;
fileListEmpty(&list);
} else {
if (size)
(*size) += stat.st_size;
if (files)
(*files)++;
}
return 0;
}
int extractRARArchivePath(const char *src, const char *dst, FileProcessParam *param) {
if (!root)
return -1;
SceIoStat stat;
memset(&stat, 0, sizeof(SceIoStat));
if (archiveRARFileGetstat(src, &stat) < 0) {
FileList list;
memset(&list, 0, sizeof(FileList));
fileListGetRARArchiveEntries(&list, src, SORT_NONE);
int ret = sceIoMkdir(dst, 0777);
if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) {
fileListEmpty(&list);
return ret;
}
if (param) {
if (param->value)
(*param->value) += DIRECTORY_SIZE;
if (param->SetProgress)
param->SetProgress(param->value ? *param->value : 0, param->max);
if (param->cancelHandler && param->cancelHandler()) {
fileListEmpty(&list);
return 0;
}
}
FileListEntry *entry = list.head->next; // Ignore ..
int i;
for (i = 0; i < list.length-1; i++) {
char *src_path = malloc(strlen(src) + strlen(entry->name) + 2);
snprintf(src_path, MAX_PATH_LENGTH, "%s%s", src, entry->name);
char *dst_path = malloc(strlen(dst) + strlen(entry->name) + 2);
snprintf(dst_path, MAX_PATH_LENGTH, "%s%s", dst, entry->name);
int ret = extractRARArchivePath(src_path, dst_path, param);
free(dst_path);
free(src_path);
if (ret <= 0) {
fileListEmpty(&list);
return ret;
}
entry = entry->next;
}
fileListEmpty(&list);
} else {
char filepath[filePathLength + sizeof(char)];
strncpy(filepath,src,filePathLength);
filepath[filePathLength] = '\0';
SceUID fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777);
struct ExtractHeader header = {file:fddst,offset:0,memPtr:NULL,bufferSize:0,param:param};
int result = extractRAR(filepath, (const char *)(src + (filePathLength + sizeof(char))), &header);
sceIoClose(fddst);
return result;
}
return 1;
}
int archiveRARClose() {
filePathLength = -1;
if (!root) {
closeRARFile(root);
root = NULL;
}
return 1;
}

View File

@ -1,28 +0,0 @@
#ifndef ARCHIVERAR_H_INC
#define ARCHIVERAR_H_INC
#include <psp2/types.h>
#include <psp2/io/stat.h>
#include <psp2/rtc.h>
#include "file.h"
#include "unrarlib/unrarlibutils.h"
#include "utils.h"
int fileListGetRARArchiveEntries(FileList *list, const char *path, int sort);
int getRARArchivePathInfo(const char *path, uint64_t *size, uint32_t *folders, uint32_t *files);
int extractRARArchivePath(const char *src, const char *dst, FileProcessParam *param);
int archiveRARFileGetstat(const char *file, SceIoStat *stat);
int archiveRARFileOpen(const char *file, int flags, SceMode mode);
int archiveRARFileRead(SceUID fd, void *data, SceSize size);
int archiveRARFileClose(SceUID fd);
int ReadArchiveRARFile(const char *file, void *buf, int size);
int archiveRARClose();
int archiveRAROpen(const char *file);
#endif // ARCHIVERAR_H_INC

View File

@ -137,13 +137,13 @@ vita2d_texture *getAlternativeCoverImage(const char *file) {
if (p) {
*p = '\0';
snprintf(path, MAX_PATH_LENGTH, "%s/cover.jpg", file);
snprintf(path, MAX_PATH_LENGTH - 1, "%s/cover.jpg", file);
if (checkFileExist(path)) {
*p = '/';
return vita2d_load_JPEG_file(path);
}
snprintf(path, MAX_PATH_LENGTH, "%s/folder.jpg", file);
snprintf(path, MAX_PATH_LENGTH - 1, "%s/folder.jpg", file);
if (checkFileExist(path)) {
*p = '/';
return vita2d_load_JPEG_file(path);
@ -327,7 +327,7 @@ int audioPlayer(const char *file, int type, FileList *list, FileListEntry *entry
if (!entry->is_folder) {
char path[MAX_PATH_LENGTH];
snprintf(path, MAX_PATH_LENGTH, "%s%s", list->path, entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", list->path, entry->name);
int type = getFileType(path);
if (type == FILE_TYPE_MP3 || type == FILE_TYPE_OGG) {
file = path;

47
file.c
View File

@ -594,21 +594,24 @@ typedef struct {
static ExtensionType extension_types[] = {
{ ".PSP2DMP", FILE_TYPE_PSP2DMP },
{ ".TMP", FILE_TYPE_PSP2DMP },
{ ".BMP", FILE_TYPE_BMP },
{ ".INI", FILE_TYPE_INI },
{ ".JPG", FILE_TYPE_JPEG },
{ ".JPEG", FILE_TYPE_JPEG },
{ ".MP3", FILE_TYPE_MP3 },
{ ".MP4", FILE_TYPE_MP4 },
{ ".OGG", FILE_TYPE_OGG },
{ ".PNG", FILE_TYPE_PNG },
{ ".RAR", FILE_TYPE_RAR },
{ ".SFO", FILE_TYPE_SFO },
{ ".TXT", FILE_TYPE_TXT },
{ ".VPK", FILE_TYPE_VPK },
{ ".XML", FILE_TYPE_XML },
{ ".ZIP", FILE_TYPE_ZIP },
{ ".TMP", FILE_TYPE_PSP2DMP },
{ ".7Z", FILE_TYPE_7Z },
{ ".BMP", FILE_TYPE_BMP },
{ ".GZ", FILE_TYPE_GZ },
{ ".INI", FILE_TYPE_INI },
{ ".ISO", FILE_TYPE_ISO },
{ ".JPG", FILE_TYPE_JPEG },
{ ".JPEG", FILE_TYPE_JPEG },
{ ".MP3", FILE_TYPE_MP3 },
{ ".MP4", FILE_TYPE_MP4 },
{ ".OGG", FILE_TYPE_OGG },
{ ".PNG", FILE_TYPE_PNG },
{ ".RAR", FILE_TYPE_RAR },
{ ".SFO", FILE_TYPE_SFO },
{ ".TXT", FILE_TYPE_TXT },
{ ".VPK", FILE_TYPE_VPK },
{ ".XML", FILE_TYPE_XML },
{ ".ZIP", FILE_TYPE_ZIP },
};
int getFileType(const char *file) {
@ -625,6 +628,20 @@ int getFileType(const char *file) {
return FILE_TYPE_UNKNOWN;
}
int isArchiveType(int type) {
switch (type) {
case FILE_TYPE_7Z:
case FILE_TYPE_GZ:
case FILE_TYPE_ISO:
case FILE_TYPE_RAR:
case FILE_TYPE_ZIP:
return 1;
default:
return 0;
}
}
int getNumberOfDevices() {
return N_DEVICES;
}

6
file.h
View File

@ -37,8 +37,11 @@
enum FileTypes {
FILE_TYPE_UNKNOWN,
FILE_TYPE_PSP2DMP,
FILE_TYPE_7Z,
FILE_TYPE_BMP,
FILE_TYPE_GZ,
FILE_TYPE_INI,
FILE_TYPE_ISO,
FILE_TYPE_JPEG,
FILE_TYPE_MP3,
FILE_TYPE_MP4,
@ -61,7 +64,7 @@ enum FileSortFlags {
enum FileMoveFlags {
MOVE_INTEGRATE = 0x1, // Integrate directories
MOVE_REPLACE = 0x2, // Replace files
MOVE_REPLACE = 0x2, // Replace files
};
typedef struct {
@ -111,6 +114,7 @@ int copyPath(const char *src_path, const char *dst_path, FileProcessParam *param
int movePath(const char *src_path, const char *dst_path, int flags, FileProcessParam *param);
int getFileType(const char *file);
int isArchiveType(int type);
int getNumberOfDevices();
char **getDevices();

View File

@ -117,7 +117,7 @@ int delete_thread(SceSize args_size, DeleteArguments *args) {
int i;
for (i = 0; i < count; i++) {
snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", args->file_list->path, mark_entry->name);
getPathInfo(path, NULL, &folders, &files, NULL);
mark_entry = mark_entry->next;
}
@ -131,7 +131,7 @@ int delete_thread(SceSize args_size, DeleteArguments *args) {
mark_entry = head;
for (i = 0; i < count; i++) {
snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", args->file_list->path, mark_entry->name);
FileProcessParam param;
param.value = &value;
@ -531,7 +531,7 @@ int export_thread(SceSize args_size, ExportArguments *args) {
int i;
for (i = 0; i < count; i++) {
snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", args->file_list->path, mark_entry->name);
getPathInfo(path, &size, NULL, &files, mediaPathHandler);
mark_entry = mark_entry->next;
}
@ -557,7 +557,7 @@ int export_thread(SceSize args_size, ExportArguments *args) {
mark_entry = head;
for (i = 0; i < count; i++) {
snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", args->file_list->path, mark_entry->name);
FileProcessParam param;
param.value = &value;

View File

@ -260,7 +260,7 @@ void loadLanguage(int id) {
if (use_custom_config) {
if (id >= 0 && id < (sizeof(lang) / sizeof(char *))) {
char path[MAX_PATH_LENGTH];
snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/language/%s.txt", lang[id]);
snprintf(path, MAX_PATH_LENGTH - 1, "ux0:VitaShell/language/%s.txt", lang[id]);
readConfig(path, language_entries, sizeof(language_entries) / sizeof(ConfigEntry));
}
}

28
main.c
View File

@ -74,7 +74,6 @@ int file_type = FILE_TYPE_UNKNOWN;
// Archive
static int is_in_archive = 0;
static char dir_level_archive = -1;
enum FileTypes archive_type = FILE_TYPE_ZIP;
// FTP
static char vita_ip[16];
@ -119,10 +118,6 @@ void dirLevelUp() {
rel_pos = 0;
}
enum FileTypes getArchiveType(){
return archive_type;
}
int isInArchive() {
return is_in_archive;
}
@ -233,7 +228,7 @@ static void refreshMarkList() {
FileListEntry *next = entry->next;
char path[MAX_PATH_LENGTH];
snprintf(path, MAX_PATH_LENGTH, "%s%s", file_list.path, entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", file_list.path, entry->name);
// Check if the entry still exits. If not, remove it from list
SceIoStat stat;
@ -257,7 +252,7 @@ static void refreshCopyList() {
FileListEntry *next = entry->next;
char path[MAX_PATH_LENGTH];
snprintf(path, MAX_PATH_LENGTH, "%s%s", copy_list.path, entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", copy_list.path, entry->name);
// Check if the entry still exits. If not, remove it from list
SceIoStat stat;
@ -278,6 +273,9 @@ static int handleFile(const char *file, FileListEntry *entry) {
switch (type) {
case FILE_TYPE_PSP2DMP:
case FILE_TYPE_7Z:
case FILE_TYPE_GZ:
case FILE_TYPE_ISO:
case FILE_TYPE_MP3:
case FILE_TYPE_OGG:
case FILE_TYPE_RAR:
@ -312,10 +310,6 @@ static int handleFile(const char *file, FileListEntry *entry) {
res = audioPlayer(file, type, &file_list, entry, &base_pos, &rel_pos);
break;
case FILE_TYPE_RAR:
res = archiveOpen(file);
break;
case FILE_TYPE_SFO:
res = SFOReader(file);
break;
@ -325,6 +319,10 @@ static int handleFile(const char *file, FileListEntry *entry) {
setDialogStep(DIALOG_STEP_INSTALL_QUESTION);
break;
case FILE_TYPE_7Z:
case FILE_TYPE_GZ:
case FILE_TYPE_ISO:
case FILE_TYPE_RAR:
case FILE_TYPE_ZIP:
res = archiveOpen(file);
break;
@ -884,7 +882,7 @@ static int dialogSteps() {
setDialogStep(DIALOG_STEP_NONE);
} else {
char path[MAX_PATH_LENGTH];
snprintf(path, MAX_PATH_LENGTH, "%s%s", file_list.path, name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", file_list.path, name);
int res = sceIoMkdir(path, 0777);
if (res < 0) {
@ -1392,9 +1390,8 @@ static int fileBrowserMenuCtrl() {
int type = handleFile(cur_file, file_entry);
// Archive mode
if (type == FILE_TYPE_ZIP || type == FILE_TYPE_RAR) {
if (isArchiveType(type)) {
is_in_archive = 1;
archive_type = type;
dir_level_archive = dir_level;
snprintf(archive_path, MAX_PATH_LENGTH, "%s%s", file_list.path, file_entry->name);
@ -1545,6 +1542,9 @@ static int shellMain() {
icon = image_icon;
break;
case FILE_TYPE_7Z:
case FILE_TYPE_GZ:
case FILE_TYPE_ISO:
case FILE_TYPE_RAR:
case FILE_TYPE_VPK:
case FILE_TYPE_ZIP:

View File

@ -436,7 +436,7 @@ void setContextMenuMoreVisibilities() {
menu_more_entries[MENU_MORE_ENTRY_OPEN_DECRYPTED].visibility = CTX_INVISIBLE;
} else {
char path[MAX_PATH_LENGTH];
snprintf(path, MAX_PATH_LENGTH, "%s%ssce_pfs", file_list.path, file_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%ssce_pfs", file_list.path, file_entry->name);
if (!checkFolderExist(path))
menu_more_entries[MENU_MORE_ENTRY_OPEN_DECRYPTED].visibility = CTX_INVISIBLE;
@ -713,9 +713,9 @@ static int contextMenuMainEnterCallback(int sel, void *context) {
int count = 1;
while (1) {
if (count == 1) {
snprintf(path, MAX_PATH_LENGTH, "%s%s", file_list.path, language_container[NEW_FOLDER]);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", file_list.path, language_container[NEW_FOLDER]);
} else {
snprintf(path, MAX_PATH_LENGTH, "%s%s (%d)", file_list.path, language_container[NEW_FOLDER], count);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s (%d)", file_list.path, language_container[NEW_FOLDER], count);
}
if (!checkFolderExist(path))
@ -824,7 +824,7 @@ static int contextMenuMoreEnterCallback(int sel, void *context) {
int i;
for (i = 0; i < file_list.length - 1; i++) {
char path[MAX_PATH_LENGTH];
snprintf(path, MAX_PATH_LENGTH, "%s%s", file_list.path, file_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", file_list.path, file_entry->name);
int type = getFileType(path);
if (type == FILE_TYPE_VPK) {
@ -894,14 +894,14 @@ static int contextMenuMoreEnterCallback(int sel, void *context) {
gameDataUmount();
snprintf(path, MAX_PATH_LENGTH, "%s%s", file_list.path, file_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", file_list.path, file_entry->name);
res = gameDataMount(path);
// In case we're at ux0:patch or grw0:patch we need to apply the mounting at ux0:app or gro0:app
snprintf(path, MAX_PATH_LENGTH, "ux0:app/%s", file_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "ux0:app/%s", file_entry->name);
if (res < 0)
res = gameDataMount(path);
snprintf(path, MAX_PATH_LENGTH, "gro:app/%s", file_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "gro:app/%s", file_entry->name);
if (res < 0)
res = gameDataMount(path);

View File

@ -275,7 +275,7 @@ int compress_thread(SceSize args_size, CompressArguments *args) {
int i;
for (i = 0; i < count; i++) {
snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", args->file_list->path, mark_entry->name);
getPathInfo(path, &size, &folders, &files, NULL);
mark_entry = mark_entry->next;
}
@ -294,7 +294,7 @@ int compress_thread(SceSize args_size, CompressArguments *args) {
mark_entry = head;
for (i = 0; i < count; i++) {
snprintf(path, MAX_PATH_LENGTH, "%s%s", args->file_list->path, mark_entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", args->file_list->path, mark_entry->name);
FileProcessParam param;
param.value = &value;

File diff suppressed because it is too large Load Diff

View File

@ -1,319 +0,0 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 1.1, February 14h, 2010
part of the MiniZip project
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault
Modifications for Zip64 support on both zip and unzip
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _UNZ_H
#define _UNZ_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"
#endif
#ifdef HAVE_BZIP2
#include "bzlib.h"
#endif
#define Z_BZIP2ED 12
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagunzFile__ { int unused; } unzFile__;
typedef unzFile__ *unzFile;
#else
typedef voidp unzFile;
#endif
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
#define UNZ_EOF (0)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
#define UNZ_INTERNALERROR (-104)
#define UNZ_CRCERROR (-105)
/* tm_unz contain date/time info */
typedef struct tm_unz_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_unz;
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
typedef struct unz_global_info64_s
{
ZPOS64_T number_entry; /* total number of entries in the central dir on this disk */
uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info64;
typedef struct unz_global_info_s
{
uLong number_entry; /* total number of entries in the central dir on this disk */
uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info;
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info64_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
ZPOS64_T compressed_size; /* compressed size 8 bytes */
ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
ZPOS64_T disk_offset;
uLong size_file_extra_internal;
} unz_file_info64;
typedef struct unz_file_info_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
uLong compressed_size; /* compressed size 4 bytes */
uLong uncompressed_size; /* uncompressed size 4 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
uLong disk_offset;
} unz_file_info;
/***************************************************************************/
/* Opening and close a zip file */
extern unzFile ZEXPORT unzOpen OF((const char *path));
extern unzFile ZEXPORT unzOpen64 OF((const void *path));
/* Open a Zip file.
path should contain the full pathname (by example, on a Windows XP computer
"c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
return NULL if zipfile cannot be opened or doesn't exist
return unzFile handle if no error
NOTE: The "64" function take a const void* pointer, because the path is just the value passed to the
open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* does not describe the reality */
extern unzFile ZEXPORT unzOpen2 OF((const char *path, zlib_filefunc_def* pzlib_filefunc_def));
/* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */
extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, zlib_filefunc64_def* pzlib_filefunc_def));
/* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write 64-bit operations */
extern int ZEXPORT unzClose OF((unzFile file));
/* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile,
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no error */
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, unz_global_info *pglobal_info));
extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, unz_global_info64 *pglobal_info));
/* Write info about the ZipFile in the *pglobal_info structure.
return UNZ_OK if no error */
extern int ZEXPORT unzGetGlobalComment OF((unzFile file, char *comment, uLong comment_size));
/* Get the global comment string of the ZipFile, in the comment buffer.
uSizeBuf is the size of the szComment buffer.
return the number of byte copied or an error code <0 */
/***************************************************************************/
/* Reading the content of the current zipfile, you can open it, read data from it, and close it
(you can close it before reading all the file) */
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
/* Open for reading data the current file in the zipfile.
return UNZ_OK if no error */
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, const char* password));
/* Open for reading data the current file in the zipfile.
password is a crypting password
return UNZ_OK if no error */
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, int* method, int* level, int raw));
/* Same as unzOpenCurrentFile, but open for read raw the file (not uncompress)
if raw==1 *method will receive method of compression, *level will receive level of compression
NOTE: you can set level parameter as NULL (if you did not want known level,
but you CANNOT set method parameter as NULL */
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, int* method, int* level, int raw, const char* password));
/* Same as unzOpenCurrentFile, but takes extra parameter password for encrypted files */
extern int ZEXPORT unzReadCurrentFile OF((unzFile file, voidp buf, unsigned len));
/* Read bytes from the current file (opened by unzOpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of byte copied if somes bytes are copied
return 0 if the end of file was reached
return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, unz_file_info *pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, unz_file_info64 *pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
/* Get Info about the current file
pfile_info if != NULL, the *pfile_info structure will contain somes info about the current file
filename if != NULL, the file name string will be copied in filename
filename_size is the size of the filename buffer
extrafield if != NULL, the extra field information from the central header will be copied in to
extrafield_size is the size of the extraField buffer
comment if != NULL, the comment string of the file will be copied in to
comment_size is the size of the comment buffer */
extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, voidp buf, unsigned len));
/* Read extra field from the current file (opened by unzOpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf == NULL, it return the size of the local extra field
if buf != NULL, len is the size of the buffer, the extra header is copied in buf.
return number of bytes copied in buf, or (if <0) the error code */
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
/* Close the file in zip opened with unzOpenCurrentFile
return UNZ_CRCERROR if all the file was read but the CRC is not good */
/***************************************************************************/
/* Browse the directory of the zipfile */
typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2);
typedef int (*unzIteratorFunction)(unzFile file);
typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size);
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
/* Set the current file of the zipfile to the first file.
return UNZ_OK if no error */
extern int ZEXPORT unzGoToFirstFile2 OF((unzFile file, unz_file_info64 *pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
/* Set the current file of the zipfile to the first file and retrieves the current info on success.
Not as seek intensive as unzGoToFirstFile + unzGetCurrentFileInfo.
return UNZ_OK if no error */
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
/* Set the current file of the zipfile to the next file.
return UNZ_OK if no error
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
extern int ZEXPORT unzGoToNextFile2 OF((unzFile file, unz_file_info64 *pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size));
/* Set the current file of the zipfile to the next file and retrieves the current
info on success. Does less seeking around than unzGotoNextFile + unzGetCurrentFileInfo.
return UNZ_OK if no error
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
extern int ZEXPORT unzLocateFile OF((unzFile file, const char *filename, unzFileNameComparer filename_compare_func));
/* Try locate the file szFileName in the zipfile. For custom filename comparison pass in comparison function.
return UNZ_OK if the file is found (it becomes the current file)
return UNZ_END_OF_LIST_OF_FILE if the file is not found */
/***************************************************************************/
/* Raw access to zip file */
typedef struct unz_file_pos_s
{
uLong pos_in_zip_directory; /* offset in zip file directory */
uLong num_of_file; /* # of file */
} unz_file_pos;
extern int ZEXPORT unzGetFilePos OF((unzFile file, unz_file_pos* file_pos));
extern int ZEXPORT unzGoToFilePos OF((unzFile file, unz_file_pos* file_pos));
typedef struct unz64_file_pos_s
{
ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
ZPOS64_T num_of_file; /* # of file */
} unz64_file_pos;
extern int ZEXPORT unzGetFilePos64 OF((unzFile file, unz64_file_pos* file_pos));
extern int ZEXPORT unzGoToFilePos64 OF((unzFile file, const unz64_file_pos* file_pos));
extern uLong ZEXPORT unzGetOffset OF((unzFile file));
extern ZPOS64_T ZEXPORT unzGetOffset64 OF((unzFile file));
/* Get the current file offset */
extern int ZEXPORT unzSetOffset OF((unzFile file, uLong pos));
extern int ZEXPORT unzSetOffset64 OF((unzFile file, ZPOS64_T pos));
/* Set the current file offset */
extern z_off_t ZEXPORT unztell OF((unzFile file));
extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
/* return current position in uncompressed data */
extern int ZEXPORT unzseek OF((unzFile file, z_off_t offset, int origin));
extern int ZEXPORT unzseek64 OF((unzFile file, ZPOS64_T offset, int origin));
/* Seek within the uncompressed data if compression method is storage */
extern int ZEXPORT unzeof OF((unzFile file));
/* return 1 if the end of file was reached, 0 elsewhere */
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* _UNZ_H */

View File

@ -318,7 +318,7 @@ int install_thread(SceSize args_size, InstallArguments *args) {
if (SCE_S_ISDIR(stat.st_mode)) {
// Check for param.sfo
snprintf(path, MAX_PATH_LENGTH, "%s/sce_sys/param.sfo", args->file);
snprintf(path, MAX_PATH_LENGTH - 1, "%s/sce_sys/param.sfo", args->file);
if (sceIoGetstat(path, &stat) < 0 || SCE_S_ISDIR(stat.st_mode)) {
closeWaitDialog();
errorDialog(-2);
@ -326,7 +326,7 @@ int install_thread(SceSize args_size, InstallArguments *args) {
}
// Check permissions
snprintf(path, MAX_PATH_LENGTH, "%s/eboot.bin", args->file);
snprintf(path, MAX_PATH_LENGTH - 1, "%s/eboot.bin", args->file);
SceUID fd = sceIoOpen(path, SCE_O_RDONLY, 0);
if (fd >= 0) {
char buffer[0x88];
@ -388,7 +388,7 @@ int install_thread(SceSize args_size, InstallArguments *args) {
}
// Check for param.sfo
snprintf(path, MAX_PATH_LENGTH, "%s/sce_sys/param.sfo", args->file);
snprintf(path, MAX_PATH_LENGTH - 1, "%s/sce_sys/param.sfo", args->file);
if (archiveFileGetstat(path, NULL) < 0) {
closeWaitDialog();
errorDialog(-2);

View File

@ -224,7 +224,7 @@ int photoViewer(const char *file, int type, FileList *list, FileListEntry *entry
if (!entry->is_folder) {
char path[MAX_PATH_LENGTH];
snprintf(path, MAX_PATH_LENGTH, "%s%s", list->path, entry->name);
snprintf(path, MAX_PATH_LENGTH - 1, "%s%s", list->path, entry->name);
int type = getFileType(path);
if (type == FILE_TYPE_BMP || type == FILE_TYPE_JPEG || type == FILE_TYPE_PNG) {
vita2d_wait_rendering_done();

View File

@ -64,7 +64,7 @@ PropertyEntry property_entries[] = {
{ PROPERTY_TYPE, PROPERTY_ENTRY_VISIBLE, property_type, sizeof(property_type) },
{ PROPERTY_FSELF_MODE, PROPERTY_ENTRY_VISIBLE, property_fself_mode, sizeof(property_fself_mode) },
{ PROPERTY_SIZE, PROPERTY_ENTRY_VISIBLE, property_size, sizeof(property_size) },
{ PROPERTY_COMPRESSED_SIZE, PROPERTY_ENTRY_VISIBLE, property_compressed_size, sizeof(property_compressed_size) },
// { PROPERTY_COMPRESSED_SIZE, PROPERTY_ENTRY_VISIBLE, property_compressed_size, sizeof(property_compressed_size) },
{ PROPERTY_CONTAINS, PROPERTY_ENTRY_VISIBLE, property_contains, sizeof(property_contains) },
{ -1, PROPERTY_ENTRY_UNUSED, NULL },
{ PROPERTY_CREATION_DATE, PROPERTY_ENTRY_VISIBLE, property_creation_date, sizeof(property_creation_date) },
@ -76,7 +76,7 @@ enum PropertyEntries {
PROPERTY_ENTRY_TYPE,
PROPERTY_ENTRY_FSELF_MODE,
PROPERTY_ENTRY_SIZE,
PROPERTY_ENTRY_COMPRESSED_SIZE,
// PROPERTY_ENTRY_COMPRESSED_SIZE,
PROPERTY_ENTRY_CONTAINS,
PROPERTY_ENTRY_EMPTY_1,
PROPERTY_ENTRY_CREATION_DATE,
@ -287,18 +287,18 @@ int initPropertyDialog(char *path, FileListEntry *entry) {
property_entries[PROPERTY_ENTRY_CONTAINS].visibility = PROPERTY_ENTRY_VISIBLE;
}
property_entries[PROPERTY_ENTRY_COMPRESSED_SIZE].visibility = PROPERTY_ENTRY_INVISIBLE;
// property_entries[PROPERTY_ENTRY_COMPRESSED_SIZE].visibility = PROPERTY_ENTRY_INVISIBLE;
} else {
getSizeString(property_size, entry->size);
property_entries[PROPERTY_ENTRY_CONTAINS].visibility = PROPERTY_ENTRY_INVISIBLE;
/*
// Compressed size
if (isInArchive()) {
getSizeString(property_compressed_size, entry->size2);
property_entries[PROPERTY_ENTRY_COMPRESSED_SIZE].visibility = PROPERTY_ENTRY_VISIBLE;
} else {
property_entries[PROPERTY_ENTRY_COMPRESSED_SIZE].visibility = PROPERTY_ENTRY_INVISIBLE;
}
}*/
}
// Dates

View File

@ -199,7 +199,7 @@ void app_callback(void* data, const char* dir, const char* subdir)
return;
if (refresh_data->refresh_pass) {
snprintf(path, MAX_PATH_LENGTH, "%s/%s", dir, subdir);
snprintf(path, MAX_PATH_LENGTH - 1, "%s/%s", dir, subdir);
if (refreshNeeded(path)) {
// Move the directory to temp for installation
removePath(APP_TEMP, NULL);
@ -226,7 +226,7 @@ void dlc_callback_inner(void* data, const char* dir, const char* subdir)
return;
if (dlc_data->refresh_data->refresh_pass) {
snprintf(path, MAX_PATH_LENGTH, "%s/%s", dir, subdir);
snprintf(path, MAX_PATH_LENGTH - 1, "%s/%s", dir, subdir);
if (dlc_data->list_size < MAX_DLC_PER_TITLE)
dlc_data->list[dlc_data->list_size++] = strdup(path);
} else {
@ -252,7 +252,7 @@ void dlc_callback_outer(void* data, const char* dir, const char* subdir)
// 2. Refresh the moved dlc_data
for (int i = 0; i < dlc_data.list_size; i++) {
if (refreshNeeded(dlc_data.list[i])) {
snprintf(path, MAX_PATH_LENGTH, DLC_TEMP "/%s", &dlc_data.list[i][len + 1]);
snprintf(path, MAX_PATH_LENGTH - 1, DLC_TEMP "/%s", &dlc_data.list[i][len + 1]);
removePath(path, NULL);
sceIoRename(dlc_data.list[i], path);
} else {
@ -265,7 +265,7 @@ void dlc_callback_outer(void* data, const char* dir, const char* subdir)
// Now that the dlc we need are out of addcont/title_id, refresh them
for (int i = 0; i < dlc_data.list_size; i++) {
if (dlc_data.list[i] != NULL) {
snprintf(path, MAX_PATH_LENGTH, DLC_TEMP "/%s", &dlc_data.list[i][len + 1]);
snprintf(path, MAX_PATH_LENGTH - 1, DLC_TEMP "/%s", &dlc_data.list[i][len + 1]);
if (refreshApp(path) == 1)
refresh_data->refreshed++;
else

View File

@ -241,16 +241,16 @@ void loadTheme() {
if (theme_name) {
// Load colors config
snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/theme/%s/colors.txt", theme_name);
snprintf(path, MAX_PATH_LENGTH - 1, "ux0:VitaShell/theme/%s/colors.txt", theme_name);
readConfig(path, colors_entries, sizeof(colors_entries) / sizeof(ConfigEntry));
// Font
snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/theme/%s/font.pgf", theme_name);
snprintf(path, MAX_PATH_LENGTH - 1, "ux0:VitaShell/theme/%s/font.pgf", theme_name);
font = vita2d_load_custom_pgf(path);
// Load theme
for (i = 0; i < N_THEME_IMAGES; i++) {
snprintf(path, MAX_PATH_LENGTH, "ux0:VitaShell/theme/%s/%s", theme_name, theme_images[i].name);
snprintf(path, MAX_PATH_LENGTH - 1, "ux0:VitaShell/theme/%s/%s", theme_name, theme_images[i].name);
if (theme_images[i].texture && *(theme_images[i].texture) == NULL)
*(theme_images[i].texture) = vita2d_load_PNG_file(path);
}

View File

@ -1,155 +0,0 @@
#include <stdbool.h>
#ifndef _UNRAR_C_WRAPPER_H_INC
#define _UNRAR_C_WRAPPER_H_INC
#define ERAR_SUCCESS 0
#define ERAR_END_ARCHIVE 10
#define ERAR_NO_MEMORY 11
#define ERAR_BAD_DATA 12
#define ERAR_BAD_ARCHIVE 13
#define ERAR_UNKNOWN_FORMAT 14
#define ERAR_EOPEN 15
#define ERAR_ECREATE 16
#define ERAR_ECLOSE 17
#define ERAR_EREAD 18
#define ERAR_EWRITE 19
#define ERAR_SMALL_BUF 20
#define ERAR_UNKNOWN 21
#define ERAR_MISSING_PASSWORD 22
#define ERAR_EREFERENCE 23
#define ERAR_BAD_PASSWORD 24
#define RAR_OM_LIST 0
#define RAR_OM_EXTRACT 1
#define RAR_OM_LIST_INCSPLIT 2
#define RAR_SKIP 0
#define RAR_TEST 1
#define RAR_EXTRACT 2
#define RAR_VOL_ASK 0
#define RAR_VOL_NOTIFY 1
#define RAR_DLL_VERSION 6
#define RAR_HASH_NONE 0
#define RAR_HASH_CRC32 1
#define RAR_HASH_BLAKE2 2
#ifdef _UNIX
#define CALLBACK
#define PASCAL
#define LONG long
#define HANDLE void *
#define LPARAM long
#define UINT unsigned int
#endif
#define RHDF_SPLITBEFORE 0x01
#define RHDF_SPLITAFTER 0x02
#define RHDF_ENCRYPTED 0x04
#define RHDF_SOLID 0x10
#define RHDF_DIRECTORY 0x20
struct RARHeaderData
{
char ArcName[260];
char FileName[260];
unsigned int Flags;
unsigned int PackSize;
unsigned int UnpSize;
unsigned int HostOS;
unsigned int FileCRC;
unsigned int FileTime;
unsigned int UnpVer;
unsigned int Method;
unsigned int FileAttr;
char *CmtBuf;
unsigned int CmtBufSize;
unsigned int CmtSize;
unsigned int CmtState;
};
struct RARHeaderDataEx
{
char ArcName[1024];
wchar_t ArcNameW[1024];
char FileName[1024];
wchar_t FileNameW[1024];
unsigned int Flags;
unsigned int PackSize;
unsigned int PackSizeHigh;
unsigned int UnpSize;
unsigned int UnpSizeHigh;
unsigned int HostOS;
unsigned int FileCRC;
unsigned int FileTime;
unsigned int UnpVer;
unsigned int Method;
unsigned int FileAttr;
char *CmtBuf;
unsigned int CmtBufSize;
unsigned int CmtSize;
unsigned int CmtState;
unsigned int DictSize;
unsigned int HashType;
char Hash[32];
unsigned int Reserved[1014];
};
struct RAROpenArchiveData
{
char *ArcName;
unsigned int OpenMode;
unsigned int OpenResult;
char *CmtBuf;
unsigned int CmtBufSize;
unsigned int CmtSize;
unsigned int CmtState;
};
typedef int (CALLBACK *UNRARCALLBACK)(UINT msg,LPARAM UserData,LPARAM P1,LPARAM P2);
struct RAROpenArchiveDataEx
{
char *ArcName;
wchar_t *ArcNameW;
unsigned int OpenMode;
unsigned int OpenResult;
char *CmtBuf;
unsigned int CmtBufSize;
unsigned int CmtSize;
unsigned int CmtState;
unsigned int Flags;
UNRARCALLBACK Callback;
LPARAM UserData;
unsigned int Reserved[28];
};
enum UNRARCALLBACK_MESSAGES {
UCM_CHANGEVOLUME,UCM_PROCESSDATA,UCM_NEEDPASSWORD,UCM_CHANGEVOLUMEW,
UCM_NEEDPASSWORDW
};
typedef int (PASCAL *CHANGEVOLPROC)(char *ArcName,int Mode);
typedef int (PASCAL *PROCESSDATAPROC)(unsigned char *Addr,int Size);
extern HANDLE PASCAL RAROpenArchive(struct RAROpenArchiveData *ArchiveData);
extern HANDLE PASCAL RAROpenArchiveEx(struct RAROpenArchiveDataEx *ArchiveData);
extern int PASCAL RARCloseArchive(HANDLE hArcData);
extern int PASCAL RARReadHeader(HANDLE hArcData,struct RARHeaderData *HeaderData);
extern int PASCAL RARReadHeaderEx(HANDLE hArcData,struct RARHeaderDataEx *HeaderData);
extern int PASCAL RARProcessFile(HANDLE hArcData,int Operation,char *DestPath,char *DestName, bool TestMode);
extern int PASCAL RARProcessFileW(HANDLE hArcData,int Operation,wchar_t *DestPath,wchar_t *DestName, bool TestMode);
extern void PASCAL RARSetCallback(HANDLE hArcData,UNRARCALLBACK Callback,LPARAM UserData);
extern void PASCAL RARSetChangeVolProc(HANDLE hArcData,CHANGEVOLPROC ChangeVolProc);
extern void PASCAL RARSetProcessDataProc(HANDLE hArcData,PROCESSDATAPROC ProcessDataProc);
extern void PASCAL RARSetPassword(HANDLE hArcData,char *Password);
extern int PASCAL RARGetDllVersion();
#endif

View File

@ -1,275 +0,0 @@
#include "unrarlibutils.h"
int getcwd() {
return 0;
}
int fsync() {
return 0;
}
static void *rar_open(const char *filename, unsigned int om) {
struct RAROpenArchiveData arc_open;
arc_open.ArcName = (char*)filename;
arc_open.OpenMode = om;
arc_open.CmtBuf = NULL;
HANDLE rar_file = RAROpenArchive(&arc_open);
if (arc_open.OpenResult != 0) {
return NULL;
}
return rar_file;
}
ArchiveFileNode *createNode(const char *name) {
ArchiveFileNode *node = malloc(sizeof(ArchiveFileNode));
node->nodeName = malloc((strlen(name) + 2) *sizeof(char));
strcpy(node->nodeName, name);
node->childCount = 0;
node->childPt = NULL;
node->fatherPt = NULL;
node->maxCount = 0;
return node;
}
void add_node(ArchiveFileNode *father, ArchiveFileNode *child) {
uint32_t count = father->childCount;
if( (count + 1) > father->maxCount ) {
if(father->maxCount == 0) {
father->maxCount = 16;
father->childPt = malloc(16 *sizeof(void*));
} else {
void *n_ptr = realloc((void*)father->childPt,2 *father->maxCount *sizeof(void*));
if(n_ptr) {
father->childPt = n_ptr;
father->maxCount *= 2;
}
}
}
father->childPt[count] = (void*)child;
father->childCount++;
child->fatherPt = father;
}
ArchiveFileNode *getChildNodeByName(ArchiveFileNode *node, const char *name) {
if(node->childCount <= 0 )
return NULL;
uint32_t i;
for(i = 0; i < node->childCount; i++) {
ArchiveFileNode *_n = (ArchiveFileNode*)(node->childPt[i]);
if(strcmp(_n->nodeName,name) == 0) {
return _n;
}
}
return NULL;
}
void free_node(ArchiveFileNode *node) {
uint32_t count = node->childCount;
int i = 0;
for(; i < count; i++) {
ArchiveFileNode *_n = (ArchiveFileNode*)(node->childPt[i]);
free_node(_n);
}
if(node->childPt != NULL) {
free(node->childPt);
}
if(node->nodeName != NULL) {
free(node->nodeName);
}
free(node);
}
void parse_path(const char *name, struct filelayer *layer) {
char *p;
char _name[RARMAX_FILENAME];
strcpy(_name, name);
uint32_t depth = 0;
while(1) {
p = strrchr(_name, '/');
if(!p)
break;
strcpy(&(layer->name[depth][0]), p + sizeof(char));
layer->depth = ++depth;
*p = '\0';
}
strcpy(&(layer->name[depth][0]), _name);
}
ArchiveFileNode *openRARFile(const char *filename) {
ArchiveFileNode *root = createNode("root");
HANDLE RARFile = rar_open(filename,RAR_OM_LIST);
if(!RARFile) {
free_node(root);
return NULL;
}
struct RARHeaderData data;
while (!RARReadHeader(RARFile, &data)) {
struct filelayer layer = {0};
parse_path(data.FileName,&layer);
ArchiveFileNode *_up = root;
int i = layer.depth;
for(; i > 0; i--) {
ArchiveFileNode *father = getChildNodeByName(_up, &(layer.name[i][0]));
if(!father) {
father = createNode(&(layer.name[i][0]));
add_node(_up,father);
}
_up = father;
}
ArchiveFileNode *filenode = getChildNodeByName(_up,&(layer.name[0][0]));
if(!filenode) {
filenode = createNode(&(layer.name[0][0]));
add_node(_up, filenode);
}
filenode->data = data;
RARProcessFile(RARFile, RAR_SKIP,NULL,NULL,false);
}
RARCloseArchive(RARFile);
return root;
}
int extractToMem(struct ExtractHeader *header, char *extractBuffer, uint64_t bufferSize) {
if(header->offset >= header->bufferSize)
return -1;
if((header->offset + bufferSize) > header->bufferSize)
bufferSize = (header->bufferSize - header->offset);//no enough memory
memcpy((header->memPtr + header->offset),extractBuffer,bufferSize);
header->offset += bufferSize;
return 1;
}
int extractToFile(struct ExtractHeader *header, char *extractBuffer, uint64_t bufferSize) {
if(!header->file)
return -1;
FileProcessParam *param = header->param;
if (param) {
if (param->value)
(*param->value) += bufferSize;
if (param->SetProgress)
param->SetProgress(param->value ? *param->value : 0, param->max);
if (param->cancelHandler && param->cancelHandler()) {
return -1;
}
}
sceIoLseek(header->file,header->offset,SCE_SEEK_SET);
sceIoWrite(header->file,extractBuffer,bufferSize);
header->offset += bufferSize;
return 1;
}
static int CALLBACK rarCallback(UINT msg,LPARAM UserData,LPARAM P1,LPARAM P2) {
struct ExtractHeader *header;
int rtn = 1;
switch(msg) {
case UCM_CHANGEVOLUME:
if(P2 != RAR_VOL_NOTIFY) {
rtn = -1;
}
break;
case UCM_PROCESSDATA:
header = (struct ExtractHeader*)UserData;
if(header->memPtr)
extractToMem(header,(char*)P1,P2);
else
rtn = extractToFile(header,(char*)P1,P2);
break;
default:
rtn = -1;
break;
}
return rtn;
}
int extractRAR(const char *path, const char *filename, struct ExtractHeader *header) {
HANDLE RARFile = rar_open(path,RAR_OM_EXTRACT);
if(!RARFile)
return -1;
struct RARHeaderData data;
int rtn = -1;
while (!RARReadHeader(RARFile, &data)) {
if(!(strcmp(data.FileName,filename))) {
rtn = 1;
break;
}
RARProcessFile(RARFile, RAR_SKIP,NULL,NULL,false);
}
if(rtn > 0) {
RARSetCallback(RARFile,rarCallback,(LPARAM)header);
int result = RARProcessFile(RARFile, RAR_TEST,NULL,NULL,false);
if(result >= 0)
rtn = 1;
else if(result == -2)
rtn = 0;
}
RARCloseArchive(RARFile);
return rtn;
}
ArchiveFileNode *getFileNodeFromFilePath(ArchiveFileNode *root,const char *filepath) {
struct filelayer layer = {0};
parse_path(filepath,&layer);
int i = layer.depth;
ArchiveFileNode *_up = root;
for(; i > 0; i--) {
_up = getChildNodeByName(_up, &(layer.name[i][0]));
if(!_up)
return NULL;
}
return getChildNodeByName(_up,&(layer.name[0][0]));
}
int getRARArchiveNodeInfo(ArchiveFileNode *root, uint64_t *size, uint32_t *folders, uint32_t *files) {
if(root->childCount > 0) {
uint32_t count = root->childCount;
int i = 0;
for(; i < count; i++) {
ArchiveFileNode *_n = (ArchiveFileNode*)(root->childPt[i]);
getRARArchiveNodeInfo(_n,size,folders,files);
}
}
if(root->data.Flags == 0x20) {
if(folders)
(*folders)++;
} else {
if(size)
(*size) += root->data.UnpSize;
if(files)
(*files) ++;
}
return 1;
}
ArchiveFileNode *getFloderNodeFromPath(ArchiveFileNode *root,const char *path) {
uint32_t pathlen = strlen(path);
char temp[pathlen];
strcpy(temp,path);
temp[pathlen - 1] ='\0';
return getFileNodeFromFilePath(root,temp);
}
void closeRARFile(ArchiveFileNode *root) {
free_node(root);
}

View File

@ -1,52 +0,0 @@
#ifndef UNRARLIBUTILS_H_INC
#define UNRARLIBUTILS_H_INC
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include <psp2/io/stat.h>
#include <psp2/io/fcntl.h>
#include "../file.h"
#define _UNIX
#include "unrar_c_wrapper.h"
#define RARMAX_HIERARCHY 32//max hierarchy for folder
#define RARMAX_FILENAME 262
typedef struct {
char *nodeName;
void *fatherPt;
void* *childPt;
uint32_t childCount;
uint32_t maxCount;
struct RARHeaderData data;
} ArchiveFileNode;
struct filelayer {
uint32_t depth;
char name[RARMAX_HIERARCHY][RARMAX_FILENAME];
};
struct ExtractHeader {
SceUID file;
uint64_t offset;
char *memPtr;
uint64_t bufferSize;
FileProcessParam *param;
};
ArchiveFileNode *openRARFile(const char *filename);//returns the number of files in the rar document archive
void closeRARFile(ArchiveFileNode *root);
ArchiveFileNode *createNode(const char *name);
ArchiveFileNode *getChildNodeByName(ArchiveFileNode *node, const char *name);
int extractRAR(const char *path, const char *filename, struct ExtractHeader *header);
ArchiveFileNode *getFileNodeFromFilePath(ArchiveFileNode *root, const char *filepath);
int getRARArchiveNodeInfo(ArchiveFileNode *root, uint64_t *size, uint32_t *folders, uint32_t *files);
void free_node(ArchiveFileNode *node);
ArchiveFileNode *getFloderNodeFromPath(ArchiveFileNode *root, const char *path);
#endif // UNRARLIBUTILS_H_INC