Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tools to fill and dump memory #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions python-scripts/dump_dsp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

# Dumps the DSP memory

from xboxpy import *
import struct

f = open('dsp.bin', 'wb')

data = []

print("GP P")
for i in range(4096):
data += [apu.read_u32(NV_PAPU_GPPMEM + i*4)]
print("GP X")
for i in range(4096):
data += [apu.read_u32(NV_PAPU_GPXMEM + i*4)]
print("GP Y")
for i in range(2048):
data += [apu.read_u32(NV_PAPU_GPYMEM + i*4)]
print("GP MIXBUF")
for i in range(1024):
data += [apu.read_u32(NV_PAPU_GPMIXBUF + i*4)]

print("EP P")
for i in range(4096):
data += [apu.read_u32(NV_PAPU_EPPMEM + i*4)]
print("EP X")
for i in range(3072):
data += [apu.read_u32(NV_PAPU_EPXMEM + i*4)]
print("EP Y")
for i in range(256):
data += [apu.read_u32(NV_PAPU_EPYMEM + i*4)]


encoded = bytes(sum([list(struct.pack("<I", x)) for x in data], list()))
f.write(encoded)

f.close()
21 changes: 21 additions & 0 deletions python-scripts/dump_ram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

# Read all physical memory

from xboxpy import *

ram_size = 64 * 1024 * 1024

f = open('ram.bin', 'wb')

offset = 0
chunk_size = 0x1000
assert(ram_size % chunk_size == 0)
while offset < ram_size:
mapped = ke.MmMapIoSpace(offset, chunk_size, ke.PAGE_READWRITE)
PatrickvL marked this conversation as resolved.
Show resolved Hide resolved
data = memory.read(mapped, chunk_size)
f.write(data)
ke.MmUnmapIoSpace(mapped, chunk_size)
offset += chunk_size

f.close()
28 changes: 28 additions & 0 deletions python-scripts/fill_dsp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3

# Fills the DSP memory with known pattern

from xboxpy import *

print("GP P")
for i in range(4096):
apu.write_u32(NV_PAPU_GPPMEM + i*4, 0x313373)
print("GP X")
for i in range(4096):
apu.write_u32(NV_PAPU_GPXMEM + i*4, 0x313373)
print("GP Y")
for i in range(2048):
apu.write_u32(NV_PAPU_GPYMEM + i*4, 0x313373)
print("GP MIXBUF")
for i in range(1024):
apu.write_u32(NV_PAPU_GPMIXBUF + i*4, 0x313373)

print("EP P")
for i in range(4096):
apu.write_u32(NV_PAPU_EPPMEM + i*4, 0x313373)
print("EP X")
for i in range(3072):
apu.write_u32(NV_PAPU_EPXMEM + i*4, 0x313373)
print("EP Y")
for i in range(256):
apu.write_u32(NV_PAPU_EPYMEM + i*4, 0x313373)
27 changes: 27 additions & 0 deletions python-scripts/fill_ram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python3

# Search empty memory regions and fill them with a pattern

from xboxpy import *

pattern = b'JayFoxRox'
page_contents = (pattern * ((0x1000 // len(pattern) + 1)))[0:0x1000]
print(len(page_contents))
assert(len(page_contents) == 0x1000)

ram_size = 64 * 1024 * 1024

page_count = 0

#FIXME: Walk the pagetable instead and map memory using MmMapIoSpace!
offset = 0
while offset < ram_size:
allocated = ke.MmAllocateContiguousMemoryEx(0x1000, offset, offset + 0x1000, 0x1000, ke.PAGE_READWRITE)
if allocated != 0:
memory.write(allocated, page_contents[0:len(pattern)])
print("Filling 0x%08X" % ke.MmGetPhysicalAddress(allocated))
ke.MmFreeContiguousMemory(allocated)
page_count += 1
offset += 0x1000

print("Filled %d pages" % page_count)