标签:article open author space oid pre false str 日期
VC++ 改动VMware BIOS、uuid_location、ethernet0_address等。主要问题例如以下
(1)随机产生16进制数。
(2)改动vmx相应项。依据规则一般仅仅改动最后三项值;
/************************************************************************/
/*
摘要:产生十六进制随机数串。比如 "0C 8B 9A"或"0C:8B:9A"
返回值:返回生成随机数串。格式如"0C 8B 9A"或"0C:8B:9A"
Author:AboLee
日期:2014年4月6日
*/
/************************************************************************/
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] = ‘"‘;
}
/************************************************************************/
/*
摘要:改动虚拟机*。vmx文件 uuid.bios??uuid.location??ethernet0.address
依据校验规则一般改动后三项值
Author:Abolee
日期:2014年4月6日
*/
/************************************************************************/
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;
}
VC++ 改动VMware BIOS、uuid_location、ethernet0_address等
标签:article open author space oid pre false str 日期
原文地址:http://www.cnblogs.com/cynchanpin/p/7352578.html