Improve version checks

This commit is contained in:
Maschell 2022-09-03 14:19:11 +02:00
parent ee16425e88
commit 691d797693
3 changed files with 194 additions and 116 deletions

View File

@ -6,25 +6,27 @@ extern "C" {
#include <stdint.h>
enum WUHBUtilsStatus {
typedef enum WUHBUtilsStatus {
WUHB_UTILS_RESULT_SUCCESS = 0,
WUHB_UTILS_RESULT_MODULE_NOT_FOUND = -1,
WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT = -2,
WUHB_UTILS_RESULT_UNSUPPORTED_VERSION = -3,
WUHB_UTILS_RESULT_INVALID_ARG = -10,
WUHB_UTILS_RESULT_NO_MEMORY = -11,
WUHB_UTILS_RESULT_MOUNT_NAME_TAKEN = -12,
WUHB_UTILS_RESULT_MOUNT_NOT_FOUND = -13,
WUHB_UTILS_RESULT_FILE_NOT_FOUND = -14,
WUHB_UTILS_RESULT_FILE_HANDLE_NOT_FOUND = -15,
WUHB_UTILS_RESULT_MOUNT_FAILED = -16,
WUHB_UTILS_RESULT_LIB_UNINITIALIZED = -20,
WUHB_UTILS_RESULT_UNKNOWN_ERROR = -1000,
};
WUHB_UTILS_RESULT_MODULE_NOT_FOUND = -0x1,
WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT = -0x2,
WUHB_UTILS_RESULT_UNSUPPORTED_VERSION = -0x3,
WUHB_UTILS_RESULT_INVALID_ARGUMENT = -0x10,
WUHB_UTILS_RESULT_NO_MEMORY = -0x11,
WUHB_UTILS_RESULT_MOUNT_NAME_TAKEN = -0x12,
WUHB_UTILS_RESULT_MOUNT_NOT_FOUND = -0x13,
WUHB_UTILS_RESULT_FILE_NOT_FOUND = -0x14,
WUHB_UTILS_RESULT_FILE_HANDLE_NOT_FOUND = -0x15,
WUHB_UTILS_RESULT_MOUNT_FAILED = -0x16,
WUHB_UTILS_RESULT_LIB_UNINITIALIZED = -0x20,
WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND = -0x21,
WUHB_UTILS_RESULT_UNKNOWN_ERROR = -0x100,
} WUHBUtilsStatus;
typedef uint32_t WUHBUtilsVersion;
typedef uint32_t WUHBFileHandle;
#define WUHB_UTILS_MODULE_VERSION 0x00000001
#define WUHB_UTILS_MODULE_VERSION_ERROR 0xFFFFFFFF
typedef enum WUHBUtilsApiErrorType {
WUHB_UTILS_API_ERROR_NONE = 0,
@ -50,36 +52,48 @@ typedef enum {
/**
* This function has to be called before any other function of this lib (except WUHBUtils_GetVersion) can be used.
*
* @return WUHB_UTILS_RESULT_SUCCESS: The library has been initialized successfully. Other functions can now be used.
* WUHB_UTILS_RESULT_MODULE_NOT_FOUND: The module could not be found. Make sure the module is loaded.
* WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT: The module is missing an expected export.
* @return WUHB_UTILS_RESULT_SUCCESS: The library has been initialized successfully. Other functions can now be used. <br>
* WUHB_UTILS_RESULT_MODULE_NOT_FOUND: The module could not be found. Make sure the module is loaded.<br>
* WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT: The module is missing an expected export.<br>
* WUHB_UTILS_RESULT_UNSUPPORTED_VERSION: The version of the loaded module is not compatible with this version of the lib.
*/
WUHBUtilsStatus WUHBUtils_InitLibrary();
/**
* Deinitializes the WUHBUtils lib
* @return WUHB_UTILS_RESULT_SUCCESS
*/
WUHBUtilsStatus WUHBUtils_DeInitLibrary();
/**
* Returns the API Version of the WUHBUtils Module.
* @return The WUHBUtilsVersion of the Module
* Retrieves the API Version of the loaded WUHBUtils.<br>
* <br>
* @param outVersion pointer to the variable where the version will be stored.
*
* @return WUHB_UTILS_RESULT_SUCCESS: The API version has been store in the version ptr.<br>
* WUHB_UTILS_RESULT_MODULE_NOT_FOUND: The module could not be found. Make sure the module is loaded.<br>
* WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT: The module is missing an expected export.<br>
* WUHB_UTILS_RESULT_INVALID_ARGUMENT: Invalid version pointer.<br>
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Retrieving the module version failed.
*/
WUHBUtilsVersion WUHBUtils_GetVersion();
WUHBUtilsStatus WUHBUtils_GetVersion(WUHBUtilsVersion *outVersion);
/**
* Mounts a given bundle to a given mount path. Use WUHBUtils_UnmountBundle to unmount it.
*
* Caution: the mounted path is only available via the WUHBUtils_FileXXX functions.
* Mounts a given bundle to a given mount path. Use WUHBUtils_UnmountBundle to unmount it.<br>
*<br>
* Caution: the mounted path is only available via the WUHBUtils_FileXXX functions.<br>
*
* @param name path the bundle should be mounted to (e.g. "bundle")
* @param bundle_path path to the bundle file (path may depend on the BundleSource)
* @param source type of source. See BundleSource for more information.
* @param outRes on success the result of the function will be stored here.
* @return WUHB_UTILS_RESULT_SUCCESS: MountBundle has been called successfully. The result has been written to outRes.
* *outRes is >= 0 on success.
* *outRes is < 0 on error.
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.
* WUHB_UTILS_RESULT_INVALID_ARG: "name", "path" or "outRes" was NULL
* WUHB_UTILS_RESULT_MOUNT_NAME_TAKEN: The given name has been already taken.
* @return WUHB_UTILS_RESULT_SUCCESS: MountBundle has been called successfully. The result has been written to outRes.<br>
* *outRes is >= 0 on success.<br>
* *outRes is < 0 on error.<br>
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.<br>
* WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded WUHBUtilsModule version.<br>
* WUHB_UTILS_RESULT_INVALID_ARGUMENT: "name", "path" or "outRes" was NULL<br>
* WUHB_UTILS_RESULT_MOUNT_NAME_TAKEN: The given name has been already taken.<br>
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
*/
WUHBUtilsStatus WUHBUtils_MountBundle(const char *name, const char *path, BundleSource source, int32_t *outRes);
@ -88,34 +102,36 @@ WUHBUtilsStatus WUHBUtils_MountBundle(const char *name, const char *path, Bundle
*
* @param name path the bundle should be unmounted to (e.g. "bundle")
* @param outRes (optional) on success the result of the function will be stored here.
* @return WUHB_UTILS_RESULT_SUCCESS: UnmountBundle has been called successfully. The result has been written to outRes.
* *outRes is >= 0 on success.
* *outRes is < 0 on error.
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.
* WUHB_UTILS_RESULT_INVALID_ARG: "name", was NULL
* WUHB_UTILS_API_ERROR_MOUNT_NOT_FOUND: "name" was not mounted.
* @return WUHB_UTILS_RESULT_SUCCESS: UnmountBundle has been called successfully. The result has been written to outRes.<br>
* *outRes is >= 0 on success.<br>
* *outRes is < 0 on error.<br>
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.<br>
* WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded WUHBUtilsModule version.<br><br>
* WUHB_UTILS_RESULT_INVALID_ARGUMENT: "name", was NULL<br>
* WUHB_UTILS_API_ERROR_MOUNT_NOT_FOUND: "name" was not mounted.<br>
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
*/
WUHBUtilsStatus WUHBUtils_UnmountBundle(const char *name, int32_t *outRes);
/**
* Opens a file inside a mounted bundle.
* (only read only is supported and is default)
*
* Make sure the bundle is mounted via WUHBUtils_MountBundle.
*
* If a given files does not exists, it's checks for a compressed version
* (at name + ".gz). If a compressed file was found, all file reads will be
* decompressed on the fly.
* Opens a file inside a mounted bundle.<br>
* (only read only is supported and is default)<br>
* <br>
* Make sure the bundle is mounted via WUHBUtils_MountBundle.<br>
* <br>
* If a given files does not exists, it's checks for a compressed version<br>
* (at name + ".gz). If a compressed file was found, all file reads will be<br>
* decompressed on the fly.<br>
*
* @param name path to the file that should be opened.
* @param outHandle on success the result of the function will be stored here.
* @return WUHB_UTILS_RESULT_SUCCESS: file has been opened successfully.
* The file handle has been stored in *outHandle
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.
* WUHB_UTILS_RESULT_INVALID_ARG: "name", was NULL
* WUHB_UTILS_API_ERROR_FILE_NOT_FOUND: file at path "name" was not found.
* WUHB_UTILS_API_ERROR_NO_MEMORY: not enough memory.
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.<br>
* WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded WUHBUtilsModule version.<br><br>
* WUHB_UTILS_RESULT_INVALID_ARGUMENT: "name", was NULL<br>
* WUHB_UTILS_API_ERROR_FILE_NOT_FOUND: file at path "name" was not found.<br>
* WUHB_UTILS_API_ERROR_NO_MEMORY: not enough memory.<br>
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
*/
WUHBUtilsStatus WUHBUtils_FileOpen(const char *name, WUHBFileHandle *outHandle);
@ -127,15 +143,16 @@ WUHBUtilsStatus WUHBUtils_FileOpen(const char *name, WUHBFileHandle *outHandle);
* @param buffer buffer where data will be written to.
* Align to 0x40 for best performance
* @param size maximum bytes this function should read into buffer
* @return WUHB_UTILS_RESULT_SUCCESS file read has been called successfully. The result has been written to *outRes.
* On success, the number of bytes read is set to *outRes (zero indicates
* end of file), and the file position is advanced by this number.
* It is not an error if this number is smaller than the number of
* bytes requested.
* On error, *outRes is set to -1.
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.
* WUHB_UTILS_RESULT_INVALID_ARG: "buffer" or "outRes" is NULL
* WUHB_UTILS_API_ERROR_FILE_HANDLE_NOT_FOUND: file handle is invalid.
* @return WUHB_UTILS_RESULT_SUCCESS file read has been called successfully. The result has been written to *outRes.<br>
* On success, the number of bytes read is set to *outRes (zero indicates<br>
* end of file), and the file position is advanced by this number.<br>
* It is not an error if this number is smaller than the number of<br>
* bytes requested.<br>
* On error, *outRes is set to -1.<br>
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.<br>
* WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded WUHBUtilsModule version.<br>
* WUHB_UTILS_RESULT_INVALID_ARGUMENT: "buffer" or "outRes" is NULL<br>
* WUHB_UTILS_API_ERROR_FILE_HANDLE_NOT_FOUND: file handle is invalid.<br>
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
*/
WUHBUtilsStatus WUHBUtils_FileRead(WUHBFileHandle handle, uint8_t *buffer, uint32_t size, int32_t *outRes);
@ -146,9 +163,10 @@ WUHBUtilsStatus WUHBUtils_FileRead(WUHBFileHandle handle, uint8_t *buffer, uint3
* example: if(WUHBUtils_FileClose(fileHandle) != WUHB_UTILS_RESULT_SUCCESS) { //error while closing the file }
*
* @param handle File to be closed
* @return WUHB_UTILS_RESULT_SUCCESS file handle has been closed successfully.
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.
* WUHB_UTILS_API_ERROR_FILE_HANDLE_NOT_FOUND: file handle is invalid.
* @return WUHB_UTILS_RESULT_SUCCESS file handle has been closed successfully.<br>
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.<br>
* WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded WUHBUtilsModule version.<br>
* WUHB_UTILS_API_ERROR_FILE_HANDLE_NOT_FOUND: file handle is invalid.<br>
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
*/
WUHBUtilsStatus WUHBUtils_FileClose(WUHBFileHandle handle);
@ -160,27 +178,29 @@ WUHBUtilsStatus WUHBUtils_FileClose(WUHBFileHandle handle);
*
* @param name Paths to be checked
* @param outRes PTR to the int where the file check result will be stored.
* @return WUHB_UTILS_RESULT_SUCCESS file exists check has been called. The result has been written to *outRes.
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.
* WUHB_UTILS_API_ERROR_INVALID_ARG: "name" or "outRes" is NULL.
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
* @return WUHB_UTILS_RESULT_SUCCESS file exists check has been called. The result has been written to *outRes. <br>
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.<br>
* WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded WUHBUtilsModule version.<br>
* WUHB_UTILS_API_ERROR_INVALID_ARG: "name" or "outRes" is NULL.<br>
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
*/
WUHBUtilsStatus WUHBUtils_FileExists(const char *name, int32_t *outRes);
/**
* Opens a file, reads it completely and returns the data as new buffer,
* Onn success the the caller has to call "free()" on the returned buffer after using it.
* Opens a file, reads it completely and returns the data as new buffer, <br>
* On success the the caller has to call "free()" on the returned buffer after using it.
*
* @param path path to the file.
* @param buffer address where the buffer address will be stored
* @param size address where the size will be stored
* @return WUHB_UTILS_RESULT_SUCCESS file read has been done. The new buffer been written to *outBuf.
* The size of the buffer will be written to *outSize.
* @return WUHB_UTILS_RESULT_SUCCESS file read has been done. The new buffer been written to *outBuf. <br>
* The size of the buffer will be written to *outSize. <br>
* The buffer returned in *outBuf has be cleaned up via "free()"
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.
* WUHB_UTILS_API_ERROR_INVALID_ARG: "outBuf" or "outSize" is NULL.
* WUHB_UTILS_RESULT_NO_MEMORY: Not enough memory.
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before. <br>
* WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded WUHBUtilsModule version.<br>
* WUHB_UTILS_API_ERROR_INVALID_ARG: "outBuf" or "outSize" is NULL. <br>
* WUHB_UTILS_RESULT_NO_MEMORY: Not enough memory. <br>
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
*/
WUHBUtilsStatus WUHBUtils_ReadWholeFile(const char *path, uint8_t **outBuf, uint32_t *outSize);
@ -190,13 +210,14 @@ WUHBUtilsStatus WUHBUtils_ReadWholeFile(const char *path, uint8_t **outBuf, uint
* @param bundle_path path to the bundle file (path may depend on the BundleSource)
* @param source type of source. See BundleSource for more information.
* @param outFileInfo on success the result file info will be stored he
* @return WUHB_UTILS_RESULT_SUCCESS GetRPXInfo check has been done successfully.
* @return WUHB_UTILS_RESULT_SUCCESS GetRPXInfo check has been done successfully. <br>
* The result of the check has been written to outFileInfo.
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before.
* WUHB_UTILS_API_ERROR_INVALID_ARG: "bundle_path" or "outFileInfo" is NULL.
* WUHB_UTILS_RESULT_MOUNT_FAILED: failed to mount bundle.
* WUHB_UTILS_RESULT_FILE_NOT_FOUND: No .rpx inside [bundle]/code/ found.
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
* WUHB_UTILS_RESULT_LIB_UNINITIALIZED: "WUHBUtils_Init()" was not called before. <br>
* WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded WUHBUtilsModule version.<br>
* WUHB_UTILS_RESULT_INVALID_ARGUMENT: "bundle_path" or "outFileInfo" is NULL. <br>
* WUHB_UTILS_RESULT_MOUNT_FAILED: failed to mount bundle. <br>
* WUHB_UTILS_RESULT_FILE_NOT_FOUND: No .rpx inside [bundle]/code/ found. <br>
* WUHB_UTILS_RESULT_UNKNOWN_ERROR: Unknown error.
*/
WUHBUtilsStatus WUHBUtils_GetRPXInfo(const char *bundle_path, BundleSource source, WUHBRPXInfo *outFileInfo);

23
source/logger.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include <coreinit/debug.h>
#include <cstring>
#define __FILENAME__ ({ \
const char *__filename = __FILE__; \
const char *__pos = strrchr(__filename, '/'); \
if (!__pos) __pos = strrchr(__filename, '\\'); \
__pos ? __pos + 1 : __filename; \
})
#define LOG_APP_TYPE "L"
#define LOG_APP_NAME "libwuhbutils"
#define LOG_EX(FILENAME, FUNCTION, LINE, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) \
do { \
LOG_FUNC("[(%s)%18s][%23s]%30s@L%04d: " LOG_LEVEL "" FMT "" LINE_END, LOG_APP_TYPE, LOG_APP_NAME, FILENAME, FUNCTION, LINE, ##ARGS); \
} while (0)
#define LOG_EX_DEFAULT(LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) LOG_EX(__FILENAME__, __FUNCTION__, __LINE__, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##WARNING## ", "\n", FMT, ##ARGS)

View File

@ -1,3 +1,4 @@
#include "logger.h"
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <cstring>
@ -15,54 +16,57 @@ static WUHBUtilsApiErrorType (*sWUUFileClose)(WUHBFileHandle)
static WUHBUtilsApiErrorType (*sWUUFileExists)(const char *, int32_t *) = nullptr;
static WUHBUtilsApiErrorType (*sWUUGetRPXInfo)(const char *, BundleSource, WUHBRPXInfo *) = nullptr;
static WUHBUtilsVersion wuhbUtilsVersion = WUHB_UTILS_MODULE_VERSION_ERROR;
WUHBUtilsStatus WUHBUtils_InitLibrary() {
if (OSDynLoad_Acquire("homebrew_wuhb_utils", &sModuleHandle) != OS_DYNLOAD_OK) {
OSReport("WUHBUtils_Init: OSDynLoad_Acquire failed.\n");
DEBUG_FUNCTION_LINE_ERR("OSDynLoad_Acquire homebrew_wuhb_utils failed.");
return WUHB_UTILS_RESULT_MODULE_NOT_FOUND;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUU_GetVersion", (void **) &sWUUGetVersion) != OS_DYNLOAD_OK) {
OSReport("WUHBUtils_Init: WUU_GetVersion failed.\n");
DEBUG_FUNCTION_LINE_ERR("FindExport WUU_GetVersion failed.");
return WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT;
}
auto res = WUHBUtils_GetVersion();
if (res != WUHB_UTILS_MODULE_VERSION) {
auto res = WUHBUtils_GetVersion(&wuhbUtilsVersion);
if (res != WUHB_UTILS_RESULT_SUCCESS) {
return WUHB_UTILS_RESULT_UNSUPPORTED_VERSION;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUU_MountBundle", (void **) &sWUUMountBundle) != OS_DYNLOAD_OK) {
OSReport("WUHBUtils_Init: WUU_MountBundle failed.\n");
return WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT;
DEBUG_FUNCTION_LINE_WARN("FindExport WUU_MountBundle failed.");
sWUUMountBundle = nullptr;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUU_UnmountBundle", (void **) &sWUUUnmountBundle) != OS_DYNLOAD_OK) {
OSReport("WUHBUtils_Init: WUU_UnmountBundle failed.\n");
return WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT;
DEBUG_FUNCTION_LINE_WARN("FindExport WUU_UnmountBundle failed.");
sWUUUnmountBundle = nullptr;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUU_FileOpen", (void **) &sWUUFileOpen) != OS_DYNLOAD_OK) {
OSReport("WUHBUtils_Init: WUU_FileOpen failed.\n");
return WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT;
DEBUG_FUNCTION_LINE_WARN("FindExport WUU_FileOpen failed.");
sWUUFileOpen = nullptr;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUU_FileRead", (void **) &sWUUFileRead) != OS_DYNLOAD_OK) {
OSReport("WUHBUtils_Init: WUU_FileRead failed.\n");
return WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT;
DEBUG_FUNCTION_LINE_WARN("FindExport WUU_FileRead failed.");
sWUUFileRead = nullptr;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUU_FileClose", (void **) &sWUUFileClose) != OS_DYNLOAD_OK) {
OSReport("WUHBUtils_Init: WUU_FileClose failed.\n");
return WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT;
DEBUG_FUNCTION_LINE_WARN("FindExport WUU_FileClose failed.");
sWUUFileClose = nullptr;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUU_FileExists", (void **) &sWUUFileExists) != OS_DYNLOAD_OK) {
OSReport("WUHBUtils_Init: WUU_FileExists failed.\n");
return WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT;
DEBUG_FUNCTION_LINE_WARN("FindExport WUU_FileExists failed.");
sWUUFileExists = nullptr;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUU_GetRPXInfo", (void **) &sWUUGetRPXInfo) != OS_DYNLOAD_OK) {
OSReport("WUHBUtils_Init: WUU_GetRPXInfo failed.\n");
return WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT;
DEBUG_FUNCTION_LINE_WARN("FindExport WUU_GetRPXInfo failed.");
sWUUGetRPXInfo = nullptr;
}
return WUHB_UTILS_RESULT_SUCCESS;
@ -72,27 +76,41 @@ WUHBUtilsStatus WUHBUtils_DeInitLibrary() {
return WUHB_UTILS_RESULT_SUCCESS;
}
WUHBUtilsVersion GetVersion();
WUHBUtilsVersion WUHBUtils_GetVersion() {
WUHBUtilsStatus GetVersion(WUHBUtilsVersion *);
WUHBUtilsStatus WUHBUtils_GetVersion(WUHBUtilsVersion *outVersion) {
if (sWUUGetVersion == nullptr) {
return WUHB_UTILS_RESULT_LIB_UNINITIALIZED;
if (OSDynLoad_Acquire("homebrew_wuhb_utils", &sModuleHandle) != OS_DYNLOAD_OK) {
DEBUG_FUNCTION_LINE_WARN("OSDynLoad_Acquire failed.");
return WUHB_UTILS_RESULT_MODULE_NOT_FOUND;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUU_GetVersion", (void **) &sWUUGetVersion) != OS_DYNLOAD_OK) {
DEBUG_FUNCTION_LINE_WARN("FindExport WUU_GetVersion failed.");
return WUHB_UTILS_RESULT_MODULE_MISSING_EXPORT;
}
}
if (outVersion == nullptr) {
return WUHB_UTILS_RESULT_INVALID_ARGUMENT;
}
return reinterpret_cast<decltype(&GetVersion)>(sWUUGetVersion)();
return reinterpret_cast<decltype(&GetVersion)>(sWUUGetVersion)(outVersion);
}
WUHBUtilsApiErrorType MountBundle(const char *, const char *, BundleSource, int32_t *);
WUHBUtilsStatus WUHBUtils_MountBundle(const char *name, const char *path, BundleSource source, int32_t *outRes) {
if (sWUUMountBundle == nullptr) {
if (wuhbUtilsVersion == WUHB_UTILS_MODULE_VERSION_ERROR) {
return WUHB_UTILS_RESULT_LIB_UNINITIALIZED;
}
if (sWUUMountBundle == nullptr || wuhbUtilsVersion < 1) {
return WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND;
}
auto res = reinterpret_cast<decltype(&MountBundle)>(sWUUMountBundle)(name, path, source, outRes);
switch (res) {
case WUHB_UTILS_API_ERROR_NONE:
return WUHB_UTILS_RESULT_SUCCESS;
case WUHB_UTILS_API_ERROR_INVALID_ARG:
return WUHB_UTILS_RESULT_INVALID_ARG;
return WUHB_UTILS_RESULT_INVALID_ARGUMENT;
case WUHB_UTILS_API_ERROR_MOUNT_NAME_TAKEN:
return WUHB_UTILS_RESULT_MOUNT_NAME_TAKEN;
default:
@ -102,16 +120,19 @@ WUHBUtilsStatus WUHBUtils_MountBundle(const char *name, const char *path, Bundle
WUHBUtilsApiErrorType UnmountBundle(const char *, int32_t *);
WUHBUtilsStatus WUHBUtils_UnmountBundle(const char *name, int32_t *outRes) {
if (sWUUUnmountBundle == nullptr) {
if (wuhbUtilsVersion == WUHB_UTILS_MODULE_VERSION_ERROR) {
return WUHB_UTILS_RESULT_LIB_UNINITIALIZED;
}
if (sWUUUnmountBundle == nullptr || wuhbUtilsVersion < 1) {
return WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND;
}
auto res = reinterpret_cast<decltype(&UnmountBundle)>(sWUUUnmountBundle)(name, outRes);
switch (res) {
case WUHB_UTILS_API_ERROR_NONE:
return WUHB_UTILS_RESULT_SUCCESS;
case WUHB_UTILS_API_ERROR_INVALID_ARG:
return WUHB_UTILS_RESULT_INVALID_ARG;
return WUHB_UTILS_RESULT_INVALID_ARGUMENT;
case WUHB_UTILS_API_ERROR_MOUNT_NOT_FOUND:
return WUHB_UTILS_RESULT_MOUNT_NOT_FOUND;
default:
@ -121,15 +142,18 @@ WUHBUtilsStatus WUHBUtils_UnmountBundle(const char *name, int32_t *outRes) {
WUHBUtilsApiErrorType FileOpen(const char *, WUHBFileHandle *);
WUHBUtilsStatus WUHBUtils_FileOpen(const char *name, WUHBFileHandle *outHandle) {
if (sWUUFileOpen == nullptr) {
if (wuhbUtilsVersion == WUHB_UTILS_MODULE_VERSION_ERROR) {
return WUHB_UTILS_RESULT_LIB_UNINITIALIZED;
}
if (sWUUFileOpen == nullptr || wuhbUtilsVersion < 1) {
return WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND;
}
auto res = reinterpret_cast<decltype(&FileOpen)>(sWUUFileOpen)(name, outHandle);
switch (res) {
case WUHB_UTILS_API_ERROR_NONE:
return WUHB_UTILS_RESULT_SUCCESS;
case WUHB_UTILS_API_ERROR_INVALID_ARG:
return WUHB_UTILS_RESULT_INVALID_ARG;
return WUHB_UTILS_RESULT_INVALID_ARGUMENT;
case WUHB_UTILS_API_ERROR_FILE_NOT_FOUND:
return WUHB_UTILS_RESULT_FILE_NOT_FOUND;
case WUHB_UTILS_API_ERROR_NO_MEMORY:
@ -141,16 +165,19 @@ WUHBUtilsStatus WUHBUtils_FileOpen(const char *name, WUHBFileHandle *outHandle)
WUHBUtilsApiErrorType FileRead(WUHBFileHandle, uint8_t *, uint32_t, int32_t *);
WUHBUtilsStatus WUHBUtils_FileRead(WUHBFileHandle handle, uint8_t *buffer, uint32_t size, int32_t *outRes) {
if (sWUUFileRead == nullptr) {
if (wuhbUtilsVersion == WUHB_UTILS_MODULE_VERSION_ERROR) {
return WUHB_UTILS_RESULT_LIB_UNINITIALIZED;
}
if (sWUUFileRead == nullptr || wuhbUtilsVersion < 1) {
return WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND;
}
auto res = reinterpret_cast<decltype(&FileRead)>(sWUUFileRead)(handle, buffer, size, outRes);
switch (res) {
case WUHB_UTILS_API_ERROR_NONE:
return WUHB_UTILS_RESULT_SUCCESS;
case WUHB_UTILS_API_ERROR_INVALID_ARG:
return WUHB_UTILS_RESULT_INVALID_ARG;
return WUHB_UTILS_RESULT_INVALID_ARGUMENT;
case WUHB_UTILS_API_ERROR_FILE_HANDLE_NOT_FOUND:
return WUHB_UTILS_RESULT_FILE_HANDLE_NOT_FOUND;
default:
@ -160,9 +187,12 @@ WUHBUtilsStatus WUHBUtils_FileRead(WUHBFileHandle handle, uint8_t *buffer, uint3
WUHBUtilsApiErrorType FileClose(WUHBFileHandle);
WUHBUtilsStatus WUHBUtils_FileClose(WUHBFileHandle handle) {
if (sWUUFileClose == nullptr) {
if (wuhbUtilsVersion == WUHB_UTILS_MODULE_VERSION_ERROR) {
return WUHB_UTILS_RESULT_LIB_UNINITIALIZED;
}
if (sWUUFileClose == nullptr || wuhbUtilsVersion < 1) {
return WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND;
}
auto res = reinterpret_cast<decltype(&FileClose)>(sWUUFileClose)(handle);
switch (res) {
@ -177,34 +207,39 @@ WUHBUtilsStatus WUHBUtils_FileClose(WUHBFileHandle handle) {
WUHBUtilsApiErrorType FileExists(const char *, int32_t *);
WUHBUtilsStatus WUHBUtils_FileExists(const char *name, int32_t *outRes) {
if (sWUUFileExists == nullptr) {
if (wuhbUtilsVersion == WUHB_UTILS_MODULE_VERSION_ERROR) {
return WUHB_UTILS_RESULT_LIB_UNINITIALIZED;
}
if (sWUUFileExists == nullptr || wuhbUtilsVersion < 1) {
return WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND;
}
auto res = reinterpret_cast<decltype(&FileExists)>(sWUUFileExists)(name, outRes);
switch (res) {
case WUHB_UTILS_API_ERROR_NONE:
return WUHB_UTILS_RESULT_SUCCESS;
case WUHB_UTILS_API_ERROR_INVALID_ARG:
return WUHB_UTILS_RESULT_INVALID_ARG;
return WUHB_UTILS_RESULT_INVALID_ARGUMENT;
default:
return WUHB_UTILS_RESULT_UNKNOWN_ERROR;
}
}
WUHBUtilsApiErrorType GetRPXInfo(const char *, BundleSource, WUHBRPXInfo *);
WUHBUtilsStatus WUHBUtils_GetRPXInfo(const char *path, BundleSource source, WUHBRPXInfo *outFileInfo) {
if (sWUUGetRPXInfo == nullptr) {
if (wuhbUtilsVersion == WUHB_UTILS_MODULE_VERSION_ERROR) {
return WUHB_UTILS_RESULT_LIB_UNINITIALIZED;
}
if (sWUUGetRPXInfo == nullptr || wuhbUtilsVersion < 1) {
return WUHB_UTILS_RESULT_UNSUPPORTED_COMMAND;
}
auto res = reinterpret_cast<decltype(&GetRPXInfo)>(sWUUGetRPXInfo)(path, source, outFileInfo);
switch (res) {
case WUHB_UTILS_API_ERROR_NONE:
return WUHB_UTILS_RESULT_SUCCESS;
case WUHB_UTILS_API_ERROR_INVALID_ARG:
return WUHB_UTILS_RESULT_INVALID_ARG;
return WUHB_UTILS_RESULT_INVALID_ARGUMENT;
case WUHB_UTILS_API_ERROR_MOUNT_FAILED:
return WUHB_UTILS_RESULT_MOUNT_FAILED;
case WUHB_UTILS_API_ERROR_FILE_NOT_FOUND:
@ -214,10 +249,9 @@ WUHBUtilsStatus WUHBUtils_GetRPXInfo(const char *path, BundleSource source, WUHB
}
}
WUHBUtilsStatus WUHBUtils_ReadWholeFile(const char *name, uint8_t **outBuf, uint32_t *outSize) {
if (!outBuf || !outSize) {
return WUHB_UTILS_RESULT_INVALID_ARG;
return WUHB_UTILS_RESULT_INVALID_ARGUMENT;
}
auto DEFAULT_READ_BUFFER_SIZE = 128 * 1024;
WUHBFileHandle handle;