Homebrew Question Can anyone show me how to use syscall 0x6A & 0x6B in a C++ project?

CosmoCortney

i snack raw pasta and chew lollipops
OP
Member
Joined
Apr 18, 2013
Messages
1,768
Trophies
2
Location
on the cool side of the pillow
Website
follow-the-white-rabbit.wtf
XP
3,007
Country
Germany
Hello,

the title says all...
I need some examples on how to read/write data from/into memory using syscalls svcReadDebugProcessMemory and svcWriteDebugProcessMemory.
I'm very uncertain about how to implement everything in my C++ project and how to use the parameters.
(this is related to an older thread of mine when I was planning on making decent code types for cheats).

X0=buffer*, X1=debug_handle, X2=src_addr, X3=size
  • what size should X0 (dereferenced value) be? Same as X3?
  • how do I set a debug_handle?
  • should the size value represent the number of bytes or bits? Is it restricted to sizes like 1, 2, 4, 8 bytes or can it be anything even higher than 16 bytes?
So an example on how to read or write a 1-byte value, a 4-byte would be really helpful (a program that does nothing more than that + which files to include).

thanks
 

The Real Jdbye

*is birb*
Member
Joined
Mar 17, 2010
Messages
23,286
Trophies
4
Location
Space
XP
13,844
Country
Norway
Hello,

the title says all...
I need some examples on how to read/write data from/into memory using syscalls svcReadDebugProcessMemory and svcWriteDebugProcessMemory.
I'm very uncertain about how to implement everything in my C++ project and how to use the parameters.
(this is related to an older thread of mine when I was planning on making decent code types for cheats).

X0=buffer*, X1=debug_handle, X2=src_addr, X3=size
  • what size should X0 (dereferenced value) be? Same as X3?
  • how do I set a debug_handle?
  • should the size value represent the number of bytes or bits? Is it restricted to sizes like 1, 2, 4, 8 bytes or can it be anything even higher than 16 bytes?
So an example on how to read or write a 1-byte value, a 4-byte would be really helpful (a program that does nothing more than that + which files to include).

thanks
0 and 3 look fairly standard, meaning the buffer should be at least as large as the size (because the size is the number of bytes to be read into the buffer), but depending on how you're using it you may sometimes want a bigger buffer. It's probably in bytes, as I've never seen memory being read bit by bit.

As for debug_handle, I'm not sure about that one. The way it works on PC is that you have to attach to a process (using another API function) to get a handle to use, I guess it would work the same way on Switch?
I looked it up and it looks like svcDebugActiveProcess might be what you want: https://switchbrew.org/wiki/SVC - it takes a pid and returns a debug_handle. And then when you are done, svcBreakDebugProcess seems like it would detach the debugger, though the naming is odd so I might be wrong.
There are also some related functions in pm: https://switchbrew.org/wiki/Process_Manager_services
 
Last edited by The Real Jdbye,
  • Like
Reactions: CosmoCortney

CosmoCortney

i snack raw pasta and chew lollipops
OP
Member
Joined
Apr 18, 2013
Messages
1,768
Trophies
2
Location
on the cool side of the pillow
Website
follow-the-white-rabbit.wtf
XP
3,007
Country
Germany
Thanks! Yea, I know such debug_handles from the Windows API. Using/obtaining them on the Switch is new territory tho.
The Process Manager Services page looks promising. Do you know any project on Git that uses sys calls 0x6A and 0x6B and builds up a handle? Maybe that'll be good enough as an example for me
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: @Psionic Roshambo, I always see this dude's shorts, he sounds pretty annoying.