mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-22 18:26:39 +00:00
00497b5181
Changes include: * mem: change all references to `Rodata` to `RoData`. * nso: change all references to `Rodata` to `RoData`. * nso: update `NsoModStart` struct. * nso: rename `NsoModuleInfo` struct to `NsoModulePath`. * nso: add `NsoRoDataStart` struct. * nso: update logic in both nsoIsNnSdkVersionWithinSegment() and nsoGetNnSdkVersion() functions to work entirely with memory-based offsets. * nso: rename nsoGetModuleInfoName() to nsoGetModulePath(). * nso: update logic in nsoInitializeContext() to always validate and use the NsoNnSdkVersion block offset from the NsoModStart block.
70 lines
2.6 KiB
C
70 lines
2.6 KiB
C
/*
|
|
* mem.h
|
|
*
|
|
* Copyright (c) 2019, shchmue.
|
|
* Copyright (c) 2020-2024, 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 of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* nxdumptool is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifndef __MEM_H__
|
|
#define __MEM_H__
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef enum {
|
|
MemoryProgramSegmentType_None = 0,
|
|
MemoryProgramSegmentType_Text = BIT(0),
|
|
MemoryProgramSegmentType_RoData = BIT(1),
|
|
MemoryProgramSegmentType_Data = BIT(2),
|
|
MemoryProgramSegmentType_All = (MemoryProgramSegmentType_Data | MemoryProgramSegmentType_RoData | MemoryProgramSegmentType_Text),
|
|
MemoryProgramSegmentType_Limit = (MemoryProgramSegmentType_All + 1) ///< Placed here for convenience.
|
|
} MemoryProgramSegmentType;
|
|
|
|
typedef struct {
|
|
u64 program_id;
|
|
u8 mask; ///< MemoryProgramSegmentType. Used with memRetrieveProgramMemorySegment(). Ignored in memRetrieveFullProgramMemory().
|
|
u8 *data;
|
|
u64 data_size;
|
|
} MemoryLocation;
|
|
|
|
/// Retrieves memory segment (.text, .rodata, .data) data from a running program.
|
|
/// These are memory pages with read permission (Perm_R) enabled, with type MemType_CodeStatic or MemType_CodeMutable and no MemoryAttribute flag set.
|
|
bool memRetrieveProgramMemorySegment(MemoryLocation *location);
|
|
|
|
/// Retrieves full memory data from a running program.
|
|
/// These are any type of memory pages with read permission (Perm_R) enabled and no MemoryAttribute flag set.
|
|
/// MemType_Unmapped, MemType_Io, MemType_ThreadLocal and MemType_Reserved memory pages are excluded if FS program memory is being retrieved, in order to avoid hangs.
|
|
bool memRetrieveFullProgramMemory(MemoryLocation *location);
|
|
|
|
/// Frees a populated MemoryLocation element.
|
|
NX_INLINE void memFreeMemoryLocation(MemoryLocation *location)
|
|
{
|
|
if (!location) return;
|
|
if (location->data) free(location->data);
|
|
location->data = NULL;
|
|
location->data_size = 0;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __MEM_H__ */
|