VC++ 修改VMware BIOS、uuid_location、ethernet0_address等

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值