Homebrew How to get the consoles mac programmatically

sorunome

Well-Known Member
OP
Newcomer
Joined
Apr 13, 2024
Messages
71
Trophies
0
XP
277
Country
Germany
Hello,

Soru is playing around with some stuffs and wanted to, programmatically, get the mac address of the console. The IPC nwm::SOC apparently has a method GetMACAddress, however soru can't get it to work without a kernel panic. Furthermore, the file twln:/sys/log/inspect.log also includes the mac address, but soru can't figure out how to read files in twln. (would post links to 3dbrew for easier reference but soru doesn't have five posts yet :/ )

As for the GetMACAddress, soru attempted with this code:

Code:
Result getMac(u8 mac[6]) {	
	Handle handle;
	res = srvGetServiceHandle(&handle, "nwm::SOC");
	if (R_FAILED(res)) return res;

	u32 *cmdbuf = getThreadCommandBuffer();
	cmdbuf[0] = IPC_MakeHeader(8, 1, 0);
	cmdbuf[1] = 6;
	for (int i = 2; i < 0x100 / 8; i+=2) {
		cmdbuf[i] = IPC_Desc_StaticBuffer(0, 6);
		cmdbuf[i+1] = (u32)mac;
	}
	res = svcSendSyncRequest(handle);
	if (R_FAILED(res)) return res;
	res = (Result)cmdbuf[1];
	memcpy(mac, (u8*)cmdbuf[3], 6);
	return res;
}

Any help in either direction would be greatly appreciated, thank you in advance!
 

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,829
Trophies
2
Location
home
XP
9,423
Country
Hungary
  • Like
Reactions: sorunome

sorunome

Well-Known Member
OP
Newcomer
Joined
Apr 13, 2024
Messages
71
Trophies
0
XP
277
Country
Germany
Thanks a lot for the quick answer, the how to deal with static buffers was indeed what soru was missing. For anyone stumbling upon this thread, the working solution now is:

Code:
Result getMac(u8 mac[6]) {
    Result res = 0;
    Handle handle;
    res = srvGetServiceHandle(&handle, "nwm::SOC");
    if (R_FAILED(res)) return res;
    printf("inited nwm::SOC\n");
    u32 *cmdbuf = getThreadCommandBuffer();
    cmdbuf[0] = IPC_MakeHeader(8, 1, 0);
    cmdbuf[1] = 6;
    u32 saved_threadstorage[2];
    u32 *staticbufs = getThreadStaticBuffers();
    saved_threadstorage[0] = staticbufs[0];
    saved_threadstorage[1] = staticbufs[1];
    staticbufs[0] = IPC_Desc_StaticBuffer(6, 0);
    staticbufs[1] = (u32)mac;
    res = svcSendSyncRequest(handle);
    staticbufs[0] = saved_threadstorage[0];
    staticbufs[1] = saved_threadstorage[1];
    if (R_FAILED(res)) return res;
    res = (Result)cmdbuf[1];
    memcpy(mac, (u8*)cmdbuf[3], 6);
    return res;
}
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • ZeroT21 @ ZeroT21:
    it gets hacked/corrupted if i just leave it online for an hour
  • SylverReZ @ SylverReZ:
    @ZeroT21, The Russians are after you lol.
  • K3Nv2 @ K3Nv2:
    Send me your ip I'll remotely fix it
  • ZeroT21 @ ZeroT21:
    @K3Nv2 my head needs fixing if I believe you
  • ZeroT21 @ ZeroT21:
    it's kinda fun watching it happen tho
  • K3Nv2 @ K3Nv2:
    It needs fixing for other things but your pc I can fix
  • ZeroT21 @ ZeroT21:
    over 300+ virus/trojians/worms after scanning, what did I do to deserve this attention lol
  • ZeroT21 @ ZeroT21:
    tho I find it funny when i receive other people's pc/laptops in this state
  • ZeroT21 @ ZeroT21:
    i wont be upgrading unless I cant run the games i want anymore
  • K3Nv2 @ K3Nv2:
    Spill water on it good excuse
  • ZeroT21 @ ZeroT21:
    @K3Nv2 that's like a valid option if someone else is paying for ya
  • K3Nv2 @ K3Nv2:
    Daddy's wallet
  • K3Nv2 @ K3Nv2:
    Ngl hogwarts legacy has good pooping music
  • OctoAori20 @ OctoAori20:
    That's uh-
  • OctoAori20 @ OctoAori20:
    That's certainly a Dairy Queen sign lmao
  • K3Nv2 @ K3Nv2:
    You should see his help wanted signs
  • OctoAori20 @ OctoAori20:
    Ugh, so many sweat-dipwads in Sploon 3 Anarchy mode tonight
  • OctoAori20 @ OctoAori20:
    I didn't know this was "Make Octo never finish Fresh Season 2024 Catalog in Splatoon 3" month, good god
  • Veho @ Veho:
    What's the point of "confirming" games you know will get released. Like Nintendo "confirming" a Zelda sequel. "We can't be sure Nintendo is working on a new Zelda game, or if a new Zelda game will ever be released, until they officially confirm it."
  • Veho @ Veho:
    "There is literally no way to know if they will ever release a new Zelda game, it's wild speculation until they officially confirm it."
  • K3Nv2 @ K3Nv2:
    Black ops was the lesser shitter line in cock a poopoo tbf just a way to let people know it hasn't died or going a different route I guess
  • K3Nv2 @ K3Nv2:
    $70 DLC per 6 months is what it turned into
    K3Nv2 @ K3Nv2: $70 DLC per 6 months is what it turned into