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

修改VMware BIOS与配置参数的随机生成与修改方法
本文介绍了如何使用C语言通过随机生成16进制数来修改VMware虚拟机的BIOS、UUID位置和以太网地址配置。包括了随机数生成函数、关键配置项修改函数及其实现细节。

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

.encoding = "GBK" config.version = "8" virtualHW.version = "18" mks.enable3d = "TRUE" pciBridge0.present = "TRUE" pciBridge4.present = "TRUE" pciBridge4.virtualDev = "pcieRootPort" pciBridge4.functions = "8" pciBridge5.present = "TRUE" pciBridge5.virtualDev = "pcieRootPort" pciBridge5.functions = "8" pciBridge6.present = "TRUE" pciBridge6.virtualDev = "pcieRootPort" pciBridge6.functions = "8" pciBridge7.present = "TRUE" pciBridge7.virtualDev = "pcieRootPort" pciBridge7.functions = "8" vmci0.present = "TRUE" hpet0.present = "TRUE" nvram = "Ubuntu18.04.nvram" virtualHW.productCompatibility = "hosted" powerType.powerOff = "soft" powerType.powerOn = "soft" powerType.suspend = "soft" powerType.reset = "soft" displayName = "Ubuntu18.04" usb.vbluetooth.startConnected = "TRUE" guestOS = "ubuntu-64" tools.syncTime = "FALSE" sound.autoDetect = "TRUE" sound.fileName = "-1" sound.present = "TRUE" numvcpus = "4" vcpu.hotadd = "TRUE" memsize = "8192" mem.hotadd = "TRUE" scsi0.virtualDev = "lsilogic" scsi0.present = "TRUE" sata0.present = "TRUE" scsi0:0.fileName = "Ubuntu18.04.vmdk" scsi0:0.present = "TRUE" sata0:1.deviceType = "cdrom-raw" sata0:1.fileName = "auto detect" sata0:1.present = "TRUE" sata0:0.deviceType = "cdrom-raw" sata0:0.fileName = "auto detect" sata0:0.present = "FALSE" usb.present = "TRUE" ehci.present = "TRUE" svga.graphicsMemoryKB = "8388608" ethernet0.addressType = "generated" ethernet0.virtualDev = "e1000" serial0.fileType = "thinprint" serial0.fileName = "thinprint" floppy0.fileType = "device" floppy0.fileName = "" ethernet0.present = "TRUE" serial0.present = "TRUE" extendedConfigFile = "Ubuntu18.04.vmxf" floppy0.clientDevice = "FALSE" uuid.bios = "56 4d 28 9a c8 33 58 d7-6f 33 f3 d6 5e 3a 62 d8" uuid.location = "56 4d 28 9a c8 33 58 d7-6f 33 f3 d6 5e 3a 62 d8" scsi0:0.redo = "" pciBridge0.pciSlotNumber = "17" pciBridge4.pciSlotNumber = "21" pciBridge5.pciSlotNumber = "22" pciBridge6.pciSlotNumber = "23" pciBridge7.pciSlotNumber = "24" scsi0.pciSlotNumber =
最新发布
09-04
.encoding = "GBK" config.version = "8" virtualHW.version = "21" pciBridge0.present = "TRUE" pciBridge4.present = "TRUE" pciBridge4.virtualDev = "pcieRootPort" pciBridge4.functions = "8" pciBridge5.present = "TRUE" pciBridge5.virtualDev = "pcieRootPort" pciBridge5.functions = "8" pciBridge6.present = "TRUE" pciBridge6.virtualDev = "pcieRootPort" pciBridge6.functions = "8" pciBridge7.present = "TRUE" pciBridge7.virtualDev = "pcieRootPort" pciBridge7.functions = "8" vmci0.present = "TRUE" hpet0.present = "TRUE" nvram = "iosabc 13.nvram" virtualHW.productCompatibility = "hosted" powerType.powerOff = "soft" powerType.powerOn = "soft" powerType.suspend = "soft" powerType.reset = "soft" displayName = "iosabc 13" usb.vbluetooth.startConnected = "TRUE" smc.present = "TRUE" smbios.restrictSerialCharset = "TRUE" guestOS = "windows9-64" board-id.reflectHost = "TRUE" ich7m.present = "TRUE" tools.syncTime = "TRUE" sound.autoDetect = "TRUE" sound.virtualDev = "hdaudio" sound.fileName = "-1" sound.present = "TRUE" numvcpus = "8" cpuid.coresPerSocket = "8" memsize = "8192" sata0.present = "TRUE" sata0:0.fileName = "iosabc 13-000001.vmdk" sata0:0.present = "TRUE" sata0:1.deviceType = "cdrom-image" sata0:1.fileName = "macOS 13.6.5 (22G621)\macOS Ventura 13.6.5 (22G621) MH.iso" sata0:1.present = "TRUE" usb.present = "TRUE" ehci.present = "TRUE" usb_xhci.present = "TRUE" ethernet0.connectionType = "nat" ethernet0.addressType = "generated" ethernet0.virtualDev = "vmxnet3" ethernet0.present = "TRUE" extendedConfigFile = "iosabc 13.vmxf" smc.version = "0" vmxstats.filename = "iosabc 13.scoreboard" numa.autosize.cookie = "80082" numa.autosize.vcpu.maxPerVirtualNode = "8" uuid.bios = "56 4d 8d be 06 3a 3f 52-ac 80 46 8a e9 e3 f3 1d" uuid.location = "56 4d 8d be 06 3a 3f 52-ac 80 46 8a e9 e3 f3 1d" pciBridge0.pciSlotNumber = "17" pciBridge4.pciSlotNumber = "21" pciBridge5.pciSlotNumber = "22" pciBridge6.pciSlotNumber = "23" pciBridge7.pciSlotNumber = "24" usb.pciSlotNumber = "32" ethernet0.pciSlotNumber = "160" sound.pciSlotNumber = "33" ehci.pciSlotNumber = "34" usb_xhci.pciSlotNumber = "192" sata0.pciSlotNumber = "35" sata0:0.redo = "" svga.vramSize = "268435456" vmotion.checkpointFBSize = "134217728" vmotion.checkpointSVGAPrimarySize = "268435456" vmotion.svga.mobMaxSize = "268435456" vmotion.svga.graphicsMemoryKB = "262144" ethernet0.generatedAddress = "00:0c:29:e3:f3:1d" ethernet0.generatedAddressOffset = "0" vmci0.id = "-370937059" monitor.phys_bits_used = "45" cleanShutdown = "FALSE" softPowerOff = "FALSE" usb_xhci:6.speed = "2" usb_xhci:6.present = "TRUE" usb_xhci:6.deviceType = "hub" usb_xhci:6.port = "6" usb_xhci:6.parent = "-1" usb_xhci:7.speed = "4" usb_xhci:7.present = "TRUE" usb_xhci:7.deviceType = "hub" usb_xhci:7.port = "7" usb_xhci:7.parent = "-1" toolsInstallManager.updateCounter = "93" tools.remindInstall = "TRUE" sata0:1.startConnected = "TRUE" toolsInstallManager.lastInstallError = "21004" guestInfo.detailed.data = "architecture='X86' bitness='64' buildNumber='22G621' distroName='macOS' distroVersion='13.6.5' familyName='Darwin' kernelVersion='22.6.0'" isolation.tools.hgfs.disable = "FALSE" sharedFolder0.present = "TRUE" sharedFolder0.enabled = "TRUE" sharedFolder0.readAccess = "TRUE" sharedFolder0.writeAccess = "TRUE" sharedFolder0.hostPath = "E:\ios.xcode" sharedFolder0.guestName = "ios.xcode" sharedFolder0.expiration = "session" sharedFolder.maxNum = "1" floppy0.present = "FALSE" tools.upgrade.policy = "upgradeAtPowerCycle" ulm.disableMitigations = "TRUE" workingDir = "." mks.keyboardFilter = "allow" snapshot.action = "keep" scsi0:0.mode = "persistent" disk.locking = "FALSE" mainMem.prefetchSize = "0" vm.genid = "-605930230881790744" vm.genidX = "-4698855297883241074" usb_xhci:4.present = "TRUE" usb_xhci:4.deviceType = "hid" usb_xhci:4.port = "4" usb_xhci:4.parent = "-1" 我用这个设置直接打开vm的mac想进入BIOS/UEFI界面会有问题吗?‘’
09-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值