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;
}