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,767
Trophies
1
Location
on the cool side of the pillow
Website
follow-the-white-rabbit.wtf
XP
2,967
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
22,599
Trophies
4
Location
Space
XP
12,575
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,767
Trophies
1
Location
on the cool side of the pillow
Website
follow-the-white-rabbit.wtf
XP
2,967
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
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • JuanMena @ JuanMena:
    Will you give me mouth to mouth oxygen if my throat closes?
  • K3N1 @ K3N1:
    Nah the air can do that
  • K3N1 @ K3N1:
    Ask @x65943 he's trained for that stuff
  • JuanMena @ JuanMena:
    Kissing random dudes choking in celery? Really? Need to study for that?
  • K3N1 @ K3N1:
    Yes it requires a degree
  • K3N1 @ K3N1:
    I could also yank out the rest of my teeth but theirs professionals for that
  • x65943 @ x65943:
    If your throat closes, putting oxygen in your mouth will not solve anything - as you will be introducing oxygen prior to the area of obstruction
  • JuanMena @ JuanMena:
    Just kiss me Kyle.
  • x65943 @ x65943:
    You either need to be intubated to bypass obstruction or create a stoma inferior to the the area of obstruction to survive
  • x65943 @ x65943:
    "Just kiss me Kyle." And I thought all the godreborn gay stuff was a smear campaign
  • JuanMena @ JuanMena:
    If I die, tell my momma I won't be carrying Baby Jesus this christmas :sad::cry:
  • K3N1 @ K3N1:
    Smear campaigns are in The political section now?
  • JuanMena @ JuanMena:
    Chary! Chary! Chary, Chary, Chary!
  • Sonic Angel Knight @ Sonic Angel Knight:
    Pork Provolone :P
  • Psionic Roshambo @ Psionic Roshambo:
    Sounds yummy
  • K3N1 @ K3N1:
    Sweet found my Wii u PSU right after I ordered a new one :tpi:
  • JuanMena @ JuanMena:
    It was waiting for you to order another one.
    Seems like, your PSU was waiting for a partner.
  • JuanMena @ JuanMena:
    Keep them both
    separated or you'll have more PSUs each year.
  • K3N1 @ K3N1:
    Well one you insert one PSU into the other one you get power
  • JuanMena @ JuanMena:
    It literally turns it on.
  • K3N1 @ K3N1:
    Yeah power supplies are filthy perverts
  • K3N1 @ K3N1:
    @Psionic Roshambo has a new friend
    +1
  • JuanMena @ JuanMena:
    It's Kyle, the guy that went to school to be a Certified man Kisser.
  • Psionic Roshambo @ Psionic Roshambo:
    Cartmans hand has taco flavored kisses
  • A @ abraarukuk:
    hi guys
    A @ abraarukuk: hi guys