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

Fix machine_id on windows to be like the steam client #1167

Closed
wants to merge 2 commits into from

Conversation

LelouBil
Copy link
Contributor

First, the first available physical network interface is found. Using registry keys to differentiate the physical ones.

Then, instead of hashing only the MAC address, we hash 16 bytes where the first 8 are the MAC address.

That is because the steam client on windows hashes the first 16 bytes of a struct containing the mac address at the start and only zeroes afterwards.

First, the first available physical network interface is found. Using registry keys to differentiate the physical ones.

Then, instead of hashing only the MAC address, we hash 16 bytes where the first 8 are the MAC address.

That is because the steam client on windows hashes the first 16 bytes of a struct containing the mac address at the start and only zeroes afterwards.
//Accessing the registry key corresponding to each adapter
string fRegistryKey =
$@"SYSTEM\CurrentControlSet\Control\Network\{{4D36E972-E325-11CE-BFC1-08002BE10318}}\{adapter.Id}\Connection";
RegistryKey? rk = Registry.LocalMachine.OpenSubKey( fRegistryKey, false );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember right, registry opens need to be disposed of.

@LelouBil
Copy link
Contributor Author

Okay, after investigating with a friend, there's a bit more to it. The bytes afterwards are not always zeroes. I'm on it right now, and I'll update the code.

@LelouBil
Copy link
Contributor Author

After investigating, the structure that is hashed is like this :
6 bytes of Mac address of the first physical network interface.
2 bytes of 0s
6 bytes of Mac address of the second physical network interface.
2 bytes of 0s

My computer is a desktop, and I had only one network adapter so the last 8 bytes were always zeroes, after reverse engineering steam a bit more on a friend's laptop we found this. He had Ethernet and wifi as different network adapters, so he had the second part filled.

I'll update the code tomorrow

Copy link
Member

@xPaw xPaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on my machine, I get the same values as the Steam client.

@xPaw xPaw requested a review from psychonic October 18, 2023 12:20
@xPaw
Copy link
Member

xPaw commented Oct 18, 2023

@LelouBil can you add using to the registry opens please so that they get disposed? Then we can merge.

@xPaw
Copy link
Member

xPaw commented Oct 19, 2023

Merged in 74a32bb

@xPaw xPaw closed this Oct 19, 2023
@xPaw xPaw added this to the 2.5.0 milestone Oct 31, 2023
@xPaw
Copy link
Member

xPaw commented Sep 1, 2024

I am currently looking at the linux version, and it feels similar, however I have question:

What happens if you have more than 2 interfaces? Are we sure it blindly takes the first two it finds, or there's a missing sort by the mac address?

Also we might need a fallback to reading non-physical mac addresses if there are no physical ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants