Created
June 27, 2021 00:35
-
-
Save luckytyphlosion/6a15c1d124eb2b250aa4eec140207d94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- ============================================================================= | |
| -- Copyright (c) 2021 luckytyphlosion | |
| -- | |
| -- Permission to use, copy, modify, and/or distribute this software for any | |
| -- purpose with or without fee is hereby granted. | |
| -- | |
| -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | |
| -- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | |
| -- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | |
| -- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
| -- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | |
| -- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |
| -- PERFORMANCE OF THIS SOFTWARE. | |
| -- ============================================================================= | |
| eventGUIDs = {}; | |
| function onExit() | |
| -- for _, guid in ipairs(eventGUIDs) do | |
| -- event.unregisterbyid(guid); | |
| -- end | |
| forms.destroyall(); | |
| print("Exited debug_first_battle.lua!"); | |
| end | |
| function onAccept() | |
| gHeap = 0x2000000; | |
| MemBlock_flag = 0; | |
| MemBlock_size = 4; | |
| MemBlock_prev = 8; | |
| MemBlock_next = 12; | |
| curMemBlock = gHeap; | |
| output = ""; | |
| foundBlocks = {}; | |
| while true do | |
| curMemBlockSize = memory.read_u32_le(curMemBlock + MemBlock_size); | |
| curMemBlockFlag = memory.read_u16_le(curMemBlock + MemBlock_flag); | |
| output = output .. string.format("memblock ptr: %08x, size: %d, inUse: %d\n", curMemBlock, curMemBlockSize, curMemBlockFlag); | |
| curMemBlock = memory.read_u32_le(curMemBlock + MemBlock_next); | |
| if curMemBlock == gHeap then | |
| break; | |
| elseif foundBlocks[curMemBlock] then | |
| output = "error! infinite memblock loop detected!\n" .. output; | |
| break; | |
| else | |
| foundBlocks[curMemBlock] = true; | |
| end | |
| end | |
| print(output); | |
| end | |
| function onCorruptMemblock() | |
| if memory.read_u8(0x2001648) == 14 then | |
| print(string.format("onCorruptMemblock pc: %07x", emu.getregister("R15"))); | |
| end | |
| end | |
| event.onexit(onExit); | |
| eventGUIDs[#eventGUIDs + 1] = event.onmemorywrite(onCorruptMemblock, 0x2001648); | |
| print("Running debug_first_battle.lua!"); | |
| formhandle = forms.newform(250, 130, "Print malloc blocks"); | |
| texthandle = forms.textbox(formhandle, "", 140, 30, nil, 45, 15); | |
| forms.button(formhandle, "Accept", onAccept, 75, 50, 80, 30); | |
| while true do | |
| emu.frameadvance(); | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment