Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

New shell API to get the hash#603

Merged
saurabh95 merged 4 commits intomasterfrom
nethip/GetMachineHash
Jun 15, 2017
Merged

New shell API to get the hash#603
saurabh95 merged 4 commits intomasterfrom
nethip/GetMachineHash

Conversation

@nethip
Copy link
Copy Markdown
Contributor

@nethip nethip commented Jun 5, 2017

This PR is heavily inspired by https://oroboro.com/unique-machine-fingerprint/ in trying to create a hash out of a system based on various parameters like network interfaces, volume, CPU e.t.c.

Relevant PR on Brackets side: adobe/brackets#13419

@nethip
Copy link
Copy Markdown
Contributor Author

nethip commented Jun 5, 2017

abhijit apte, @saurabh95 Please review this.

{
u16 hash = 0;

for ( u32 i = 0; i < 6; i++ )
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Where are these types u16 and u32 defined?

// get MAC address
bool foundMac1 = false;
struct ifreq* ifr;
for ( ifr = conf.ifc_req; (s8*)ifr < (s8*)conf.ifc_req + conf.ifc_len; ifr++ )
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if the machine has multiple of them, what are we doing here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are going to ignore this scenario @abhijitapte.

return id;
}

std::string GetSystemUniqueID()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can we use std::string& as a parameter instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think that is possible as I am returning a local variable here.

// we just need this for purposes of unique machine id. So any one or two
// mac's is fine.

u16 HashMacAddress( u8* mac )
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I assume the mac code changes are the same as the ones mentioned for Linux.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes more or less.


static const int ERR_PID_NOT_FOUND = -9999; // negative int to avoid confusion with real PIDs

typedef uint8_t u8;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nevermind found the type definitions that I was looking for.

Comment thread appshell/appshell_extensions_win.cpp Outdated

void GetMacHash(u16& mac1, u16& mac2)
{
IP_ADAPTER_INFO AdapterInfo[32];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use camel case for adapterInfo

Comment thread appshell/appshell_extensions_win.cpp Outdated
IP_ADAPTER_INFO AdapterInfo[32];
DWORD dwBufLen = sizeof(AdapterInfo);

DWORD dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufLen);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should you consider MIB_IF_TYPE_ETHERNET as listed in the documentation https://msdn.microsoft.com/en-us/library/windows/desktop/aa365917(v=vs.85).aspx

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@abhijitapte Could you elaborate more on this comment?


PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
mac1 = HasMacAddress(pAdapterInfo);
if (pAdapterInfo->Next)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what should you assign mac2 to in case this condition doesn't hold?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually it is better to initialize this all the ids to 0.

return hash;
}

u16 mask[5] = { 0x4e25, 0xf4a1, 0x5437, 0xab41, 0x0000 };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what is this mask for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is used inside Smear method.

@nethip
Copy link
Copy Markdown
Contributor Author

nethip commented Jun 13, 2017

@abhijitapte I will address the review comments. Thanks for reviewing this PR. Appreciate it!

@nethip
Copy link
Copy Markdown
Contributor Author

nethip commented Jun 15, 2017

@abhijitapte I have addressed the review comments. Can you have a look again and tell me if this is OK now?

Note: I will be handling the linux change in a different PR.

@nethip
Copy link
Copy Markdown
Contributor Author

nethip commented Jun 15, 2017

Raised PR for Linux side @ #607

@abhijitapte
Copy link
Copy Markdown

LGTM

@nethip
Copy link
Copy Markdown
Contributor Author

nethip commented Jun 15, 2017

Thanks for reviewing this PR @abhijitapte

@saurabh95 saurabh95 merged commit 63d098b into master Jun 15, 2017
@marcelgerber marcelgerber deleted the nethip/GetMachineHash branch June 16, 2017 09:12
@marcelgerber
Copy link
Copy Markdown
Contributor

For me on Windows, I cannot build brackets-shell due to snprintf: identifier not found.
Which VS version are you building with? I'm using VS 2012 Express.

@nethip
Copy link
Copy Markdown
Contributor Author

nethip commented Jun 16, 2017

@marcelgerber I am using VS 2015. It seems to be building fine on my system. I will try to build this again in the office on Monday. But thanks for building and letting me know. And good to hear from you after a long time 😁

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants