2020-07-13 07:36:17 +01:00
/*
* mem . h
*
* Copyright ( c ) 2019 , shchmue .
2024-04-12 10:47:36 +01:00
* Copyright ( c ) 2020 - 2024 , DarkMatterCore < pabloacurielz @ gmail . com > .
2020-07-13 07:36:17 +01:00
*
* This file is part of nxdumptool ( https : //github.com/DarkMatterCore/nxdumptool).
*
2021-03-25 19:26:58 +00:00
* 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 .
2020-07-13 07:36:17 +01:00
*
2021-03-25 19:26:58 +00:00
* 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 .
2020-07-13 07:36:17 +01:00
*
* You should have received a copy of the GNU General Public License
2021-03-25 19:26:58 +00:00
* along with this program . If not , see < https : //www.gnu.org/licenses/>.
2020-07-13 07:36:17 +01:00
*/
# pragma once
2021-03-24 17:25:19 +00:00
# ifndef __MEM_H__
# define __MEM_H__
2021-03-23 14:06:52 +00:00
# ifdef __cplusplus
extern " C " {
# endif
2020-07-13 07:36:17 +01:00
typedef enum {
2023-07-17 00:03:05 +01:00
MemoryProgramSegmentType_None = 0 ,
2020-07-13 07:36:17 +01:00
MemoryProgramSegmentType_Text = BIT ( 0 ) ,
MemoryProgramSegmentType_Rodata = BIT ( 1 ) ,
2023-07-17 00:03:05 +01:00
MemoryProgramSegmentType_Data = BIT ( 2 ) ,
MemoryProgramSegmentType_All = ( MemoryProgramSegmentType_Data | MemoryProgramSegmentType_Rodata | MemoryProgramSegmentType_Text ) ,
MemoryProgramSegmentType_Limit = ( MemoryProgramSegmentType_All + 1 ) ///< Placed here for convenience.
2020-07-13 07:36:17 +01:00
} 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.
2023-07-17 00:03:05 +01:00
/// These are memory pages with read permission (Perm_R) enabled, with type MemType_CodeStatic or MemType_CodeMutable and no MemoryAttribute flag set.
2020-07-13 07:36:17 +01:00
bool memRetrieveProgramMemorySegment ( MemoryLocation * location ) ;
/// Retrieves full memory data from a running program.
2020-10-21 05:27:48 +01:00
/// 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.
2020-07-13 07:36:17 +01:00
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 ;
}
2021-03-23 14:06:52 +00:00
# ifdef __cplusplus
}
2021-03-24 17:25:19 +00:00
# endif
# endif /* __MEM_H__ */