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

來源:互聯網
上載者:User

標籤:style   檔案   os   2014   問題   io   

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.