Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Added support for the Video Memory hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Feb 8, 2019
1 parent 40bb318 commit 7f491da
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "patcher/hooks_patcher.h"
#include "patcher/hooks_patcher_static.h"
#include "plugin/dynamic_linking_defines.h"
#include "myutils/mem_utils.h"
#include "myutils/mocha.h"
#include "myutils/libntfs.h"
#include "myutils/libfat.h"
Expand Down Expand Up @@ -135,6 +136,7 @@ extern "C" int32_t Menu_Main(int32_t argc, char **argv) {
CSettings::destroyInstance();
PluginLoader::destroyInstance();

MemoryUtils::init();
}

DEBUG_FUNCTION_LINE("Patch own stuff\n");
Expand Down Expand Up @@ -171,6 +173,7 @@ extern "C" int32_t Menu_Main(int32_t argc, char **argv) {
}

if(result == APPLICATION_CLOSE_APPLY || result == APPLICATION_CLOSE_APPLY_MEMORY) {
CallHook(WUPS_LOADER_HOOK_INIT_VID_MEM);
CallHook(WUPS_LOADER_HOOK_INIT_KERNEL);
CallHook(WUPS_LOADER_HOOK_INIT_FS);
CallHook(WUPS_LOADER_HOOK_INIT_OVERLAY);
Expand Down
8 changes: 8 additions & 0 deletions src/mymemory/memory_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ uint32_t MemoryMapping::getHeapSize() {
return getAreaSizeFromPageTable(MEMORY_START_PLUGIN_HEAP,MEMORY_START_PLUGIN_HEAP_END - MEMORY_START_PLUGIN_HEAP);
}

uint32_t MemoryMapping::getVideoMemoryAddress() {
return MEMORY_START_VIDEO_SPACE;
}

uint32_t MemoryMapping::getVideoMemorySize() {
return getAreaSizeFromPageTable(MEMORY_START_VIDEO_SPACE,MEMORY_START_VIDEO_SPACE_END - MEMORY_START_VIDEO_SPACE);
}

void MemoryMapping::searchEmptyMemoryRegions() {
DEBUG_FUNCTION_LINE("Searching for empty memory.\n");

Expand Down
37 changes: 37 additions & 0 deletions src/myutils/mem_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/****************************************************************************
* Copyright (C) 2018 Maschell
*
* This program 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.
*
* This program 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 <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <utils/logger.h>
#include <wups.h>
#include <stdarg.h>
#include "dynamic_libs/os_functions.h"
#include "mem_utils.h"
#include "mymemory/memory_mapping.h"


int32_t memHandle __attribute__((section(".data"))) = -1;

void MemoryUtils::init(){
memHandle = MEMCreateExpHeapEx((void*)MemoryMapping::getVideoMemoryAddress(), MemoryMapping::getVideoMemorySize(), 0);
}

void* MemoryUtils::alloc(uint32_t size, int32_t align){
return MEMAllocFromExpHeapEx(memHandle,size, align);
}

void MemoryUtils::free(void * ptr){
MEMFreeToExpHeap(memHandle,ptr);
}
32 changes: 32 additions & 0 deletions src/myutils/mem_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/****************************************************************************
* Copyright (C) 2018 Maschell
*
* This program 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.
*
* This program 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 <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef __MEMORY_UTILS_UTILS_H_
#define __SCREEN_UTILS_H_

class MemoryUtils {
public:
static void init();

static void* alloc(uint32_t size, int32_t align);

static void free(void * ptr);
private:
MemoryUtils() {}
~MemoryUtils() {}

};
#endif
8 changes: 7 additions & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "common/common.h"
#include "common/retain_vars.h"
#include "myutils/overlay_helper.h"
#include "myutils/mem_utils.h"
#include "kernel/syscalls.h"

void CallHook(wups_loader_hook_type_t hook_type) {
Expand Down Expand Up @@ -112,7 +113,12 @@ void CallHookEx(wups_loader_hook_type_t hook_type, int32_t plugin_index_needed)
((void (*)(wups_loader_init_kernel_args_t))((uint32_t*)func_ptr) )(args);
plugin_data->kernel_init_done = true;
}
} else {
} else if(hook_type == WUPS_LOADER_HOOK_INIT_VID_MEM){
wups_loader_init_vid_mem_args_t args;
args.vid_mem_alloc_ptr = &MemoryUtils::alloc;
args.vid_mem_free_ptr = &MemoryUtils::free;
((void (*)(wups_loader_init_vid_mem_args_t))((uint32_t*)func_ptr) )(args);
}else {
DEBUG_FUNCTION_LINE("ERROR: HOOK TYPE WAS NOT IMPLEMENTED %08X \n",hook_type);
}
} else {
Expand Down

0 comments on commit 7f491da

Please sign in to comment.