VC + + modified VMware BIOS, uuid_location, ethernet0_address, etc.

Source: Internet
Author: User

VC + + modified VMware BIOS, uuid_location, ethernet0_address, etc., the main problems are as follows

(1) Randomly generate 16 binary numbers;

(2) Modify the VMX counterpart, generally only modify the last three values according to the rules;

/************************************************************************/
/*
Summary: Generate hexadecimal random string, e.g. "0C 8B 9A" or "0c:8b:9a"
Return value: Returns the generated random number string, formatted as "0C 8B 9A" or "0c:8b:9a"
Author:abolee
Date: April 6, 2014
*/
/************************************************************************/
void Random (char *szrand,bool ismacaddr)
{
Srand ((unsigned) time (NULL));
if (!ISMACADDR)
sprintf (Szrand, "%02x%02x%02x", Rand () & 0xFF, Rand () & 0xFF, Rand () & 0xFF);
Else
sprintf (Szrand, "%02x:%02x:%02x", Rand () & 0xFF, Rand () & 0xFF, Rand () & 0xFF);


SZRAND[8] = ' "';
}


/************************************************************************/
/*
Summary: Modify the virtual machine *. VMX file Uuid.bios?? Uuid.location?? Ethernet0.address
Generally modified after three values according to the validation rules
Author:abolee
Date: April 6, 2014
*/
/************************************************************************/
const char *uuid_bios = "Uuid.bios = \" ";
const char *uuid_location = "uuid.location = \" ";
const char *ethernet0_address = "ethernet0.address = \" ";
int modifyvmbiosandaddress (wchar_t *szvmwarepath)
{
Char buffer[8 * 1024];


CFile file;
File. Open (Szvmwarepath,cfile::modereadwrite);
int fileSize = file. Read (Buffer, 8 * 1024);


Char *p = strstr (Buffer, Uuid_bios);
if (p = = NULL) return-1;
p + = 52;
Random (P,false);
Char *p2 = strstr (Buffer, uuid_location);
P2 + = 56;
memcpy (P2, p2, 8);


Char *p3 = strstr (Buffer, ethernet0_address);
if (P3 = = NULL) return-1;
P3 + = 30;
Random (p3,true);

File. Seektobegin ();
File. Write (buffer,filesize);
File. Close ();

return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.