1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-10-30 15:31:46 +00:00
nxdumptool/source/utils.h
Pablo Curiel 15431ec2c8 Many changes.
* AES: moved CTR initializing/updating functions here from nca.c.
* BKTR/RomFS/PFS: check if we're dealing with a NCA with titlekey crypto and the titlekey hasn't been retrieved.
* BFTTF: use void pointers for output font data.
* Mem: Only exclude Unmapped/Uo/ThreadLocal/Reserved memory pages if dealing with FS.
* NCA: use content type context pointers inside NCA contexts to manage ContentMeta, ProgramInfo, Nacp and LegalInfo contexts.
* NCA: added 'written' bool elements to patch structs to indicate patch write completion.
* NPDM: remove unnecessary inline functions, generate PFS patch right after changing ACID data, add a pfsWriteEntryPatchToMemoryBuffer wrapper.
* PFS: added PartitionFileSystemFileContext and related functions to deal with NSP headers.
* ProgramInfo: removed unnecessary inline functions.
* Save: added commented code to dump a full system savefile - will probably use it down the road.
* Tik: added support for volatile tickets (thanks to @shchmue and @Whovian9369!), added a rights ID string representation to the Ticket struct, clear Volatile and ELicenseRequired flags in conversions to common tickets.
* Title: added a function to calculate the number of titles (current + siblings) from a TItleInfo block.
* Utils: added a function to generate a dynamically allocated path string using a prefix, a filename and a extension.
* Removed explicit offset checks throughout all the code.
* Codestyle fixes.
* Updated to-do.
2020-10-21 00:27:48 -04:00

135 lines
4.1 KiB
C

/*
* utils.h
*
* Copyright (c) 2020, DarkMatterCore <pabloacurielz@gmail.com>.
*
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
*
* nxdumptool is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* nxdumptool is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef __UTILS_H__
#define __UTILS_H__
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdarg.h>
#include <malloc.h>
#include <errno.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <sys/stat.h>
#include <stdatomic.h>
#include <switch.h>
#include "common.h"
#define APP_BASE_PATH "sdmc:/switch/" APP_TITLE "/"
#define MEMBER_SIZE(type, member) sizeof(((type*)NULL)->member)
#define MAX_ELEMENTS(x) ((sizeof((x))) / (sizeof((x)[0])))
#define LOGFILE(fmt, ...) utilsWriteMessageToLogFile(__func__, fmt, ##__VA_ARGS__)
#define LOGBUF(dst, dst_size, fmt, ...) utilsWriteMessageToLogBuffer(dst, dst_size, __func__, fmt, ##__VA_ARGS__)
#define BIT_LONG(n) (1UL << (n))
#define ALIGN_DOWN(x, y) ((x) & ~((y) - 1))
#define ALIGN_UP(x, y) ((((y) - 1) + (x)) & ~((y) - 1))
#define IS_ALIGNED(x, y) (((x) & ((y) - 1)) == 0)
#define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0)
#define BIS_SYSTEM_PARTITION_MOUNT_NAME "sys:"
#define KEY_NONE 0
typedef enum {
UtilsCustomFirmwareType_Unknown = 0,
UtilsCustomFirmwareType_Atmosphere = 1,
UtilsCustomFirmwareType_SXOS = 2,
UtilsCustomFirmwareType_ReiNX = 3
} UtilsCustomFirmwareType;
bool utilsInitializeResources(void);
void utilsCloseResources(void);
bool utilsCreateThread(Thread *out_thread, ThreadFunc func, void *arg, int cpu_id);
void utilsJoinThread(Thread *thread);
bool utilsIsDevelopmentUnit(void);
/// hidScanInput() must be called before any of these functions.
u64 utilsHidKeysAllDown(void);
u64 utilsHidKeysAllHeld(void);
void utilsWaitForButtonPress(u64 flag);
bool utilsAppendFormattedStringToBuffer(char **dst, size_t *dst_size, const char *fmt, ...);
void utilsWriteMessageToLogFile(const char *func_name, const char *fmt, ...);
void utilsWriteMessageToLogBuffer(char **dst, size_t *dst_size, const char *func_name, const char *fmt, ...);
void utilsWriteLogBufferToLogFile(const char *src);
void utilsLogFileMutexControl(bool lock);
void utilsReplaceIllegalCharacters(char *str, bool ascii_only);
void utilsTrimString(char *str);
void utilsGenerateHexStringFromData(char *dst, size_t dst_size, const void *src, size_t src_size);
void utilsGenerateFormattedSizeString(u64 size, char *dst, size_t dst_size);
bool utilsGetFreeSpaceFromFileSystem(FsFileSystem *fs, u64 *out);
bool utilsGetFreeSpaceFromFileSystemByPath(const char *path, u64 *out);
bool utilsGetFreeSdCardFileSystemSpace(u64 *out);
bool utilsCommitFileSystemChangesByPath(const char *path);
bool utilsCommitSdCardFileSystemChanges(void);
bool utilsCheckIfFileExists(const char *path);
bool utilsCreateConcatenationFile(const char *path);
void utilsCreateDirectoryTree(const char *path, bool create_last_element);
char *utilsGeneratePath(const char *prefix, const char *filename, const char *extension);
bool utilsAppletModeCheck(void);
void utilsChangeHomeButtonBlockStatus(bool block);
u8 utilsGetCustomFirmwareType(void); ///< UtilsCustomFirmwareType.
FsStorage *utilsGetEmmcBisSystemPartitionStorage(void);
void utilsOverclockSystem(bool overclock);
NX_INLINE void utilsSleep(u64 seconds)
{
if (seconds) svcSleepThread(seconds * (u64)1000000000);
}
#endif /* __UTILS_H__ */