开发者

How to get laptop Serial in C

Hi I'm trying to make a security feature for 开发者_StackOverflowmy C Project, so that if someone steals it, it becomes useless. It works as following: The main function only runs if the comparison of my macbook's Serial to an encrypted one is 1.

The Problem is that I cannot get the system info in the program.

When I do:

int main ()
{ i=0;  

if (strcmp(system("system_profiler SPHardwareDataType | grep \"Serial Number\""), 
                  "Serial Number (system): W80314GJATP"));

{
 bla
 bla 
 bla
}

else {for(i=0;i<100;i++)
         {printf("Unauthorized Computer");
     }

 return 1;
}

It only prints info to stdout. Is there a way to do that comparison?


Best Regards


Not an answer to your question, but keep in mind that these tricks are never really secure.

See for example this post at lifehacker (this is about OS X, but it doesn't really matter).


system() does not return a char pointer, it returns the exit code (an int) from command that was run. You could use popen() to run a command. popen() will return a FILE* that you can read from (it is from the program's stdout). You can then read and parse the program output accordingly.


system returns an int not a const char * of what would show up on the command interrupter. If you want the output of the program you will need to get that programs stdout.


Take a look at this question on how to get the output from a pipe.


If you honestly want to make it secure, use (for example) a BIOS serial number (or hard disk serial number) as a key to encrypt the executable. Write a small wrapper that reads the same data, uses it to decrypt the executable, and then runs the result. At least without access to the original hardware, this can be fairly difficult to work around (unlike the comparison you're doing). OTOH, with access to the original hardware, this is pretty easy to break as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜