Esempio n. 1
0
hex
rand_hex_range(const hex low, const hex high)
{
  assert(low <= high);
  assert(high <= HEX_RAND_MAX);

  const hex width = high - low + 1; // +1 so we are inclusive
  const hex width_repeats = HEX_RAND_MAX / width;
  const hex retry_if_under = width_repeats * width;

  hex r;
  do {
    r = rand_hex();
  } while (r >= retry_if_under);
  const hex retval = low + r%width;

  assert(retval >= low);
  assert(retval <= high);
  return retval;
}
Esempio n. 2
0
int main(void)
{
 // 1st, let's get the vmx filename into a temp file and then into a variable
  char cmdGetVMX[100];	// create array to store output of dir /b *.vmx command 
  sprintf(cmdGetVMX, "dir /b *.vmx >fff.txt \n");
  system(cmdGetVMX);	// run the system command stored in the array
  
  char cVMX[500];   // read file into char array cVMX 
  FILE *fptr;
  if ((fptr=fopen("fff.txt","r"))==NULL){
      printf("Error opening file! VMX file not found... exiting");
      exit(1);     // Program exits if file pointer returns NULL 
  }
  fscanf(fptr,"%[^\n]",cVMX);
  fclose(fptr);
  printf("VMX file found = %s \n",cVMX);

 // 2nd, Remove lines with ethernet0.generatedAddress, addressOffset, addressType, memsize, and uuid.bios 
  char cmdKillUUID[100];	// create array to store uuid command 
  sprintf(cmdKillUUID, "findstr /v \"uuid.bios\" %s >aaa.txt \n",cVMX);
  system(cmdKillUUID);		// run the system command stored in the array  
  
  char cmdKillEth[100];	// create array to store generatedAddress and generatedAddressOffset command 
  sprintf(cmdKillEth, "findstr /v \"ethernet0.generatedAddress\" aaa.txt >bbb.txt \n");
  system(cmdKillEth);		// run the system command stored in the array
  
  char cmdKillType[100];	// create array to store address and addressType command 
  sprintf(cmdKillType, "findstr /v \"ethernet0.address\" bbb.txt >ccc.txt \n");
  system(cmdKillType);		// run the system command stored in the array 

  char cmdKillMemsize[100];	// create array to store memsize command 
  sprintf(cmdKillMemsize, "findstr /v \"memsize\" ccc.txt >%s \n",cVMX);
  system(cmdKillMemsize);		// run the system command stored in the array 

  // 3rd, add created 32-hex digit bios.uuid and 12-hex digit MAC 
  char aHex[34];			// hex digit random array
  char a0123[10];			// random 0123 array. Need only one digit
  rand_hex(aHex, 34);
  rand_0123(a0123, 10);
  printf("uuid.bios = \"%.2s %.2s %.2s %.2s %.2s %.2s %.2s %.2s-%.2s %.2s %.2s %.2s %.2s %.2s %.2s %.2s\"\n", 
	aHex, &aHex[2], &aHex[4], &aHex[6], &aHex[8], &aHex[10], &aHex[12], &aHex[14], &aHex[16], &aHex[18], &aHex[20], 
	&aHex[22], &aHex[24], &aHex[26], &aHex[28], &aHex[30]);

  printf("ethernet0.address = \"00:50:56:%.1s%.1s:%.2s:%.2s\"\n", &a0123[4], &aHex[29], &aHex[21], &aHex[5]);
  printf("ethernet0.addressType = \"static\"\n");
  	
  char cmdAddUUID[128];	// create array to store add uuid.bios command 
  sprintf(cmdAddUUID, "echo uuid.bios = \"%.2s %.2s %.2s %.2s %.2s %.2s %.2s %.2s-%.2s %.2s %.2s %.2s %.2s %.2s %.2s %.2s\" >>%s \n", 
	aHex, &aHex[2], &aHex[4], &aHex[6], &aHex[8], &aHex[10], &aHex[12], &aHex[14], &aHex[16], &aHex[18], &aHex[20], 
	&aHex[22], &aHex[24], &aHex[26], &aHex[28], &aHex[30], cVMX);
  system(cmdAddUUID);	// run the system command stored in the array
  
  char cmdAddEth0[128];	// create array to store add ethernet0.address command 
  sprintf(cmdAddEth0, "echo ethernet0.address = \"00:50:56:%.1s%.1s:%.2s:%.2s\" >>%s \n", &a0123[4], &aHex[29], &aHex[21], &aHex[5], cVMX);
  system(cmdAddEth0);	// run the system command stored in the array
  
  char cmdAddStatic[100];	// create array to store add ethernet0.addressType = "static" command 
  sprintf(cmdAddStatic, "echo ethernet0.addressType = \"static\" >>%s \n",cVMX);
  system(cmdAddStatic);	// run the system command stored in the array

  // 4th, add memory size between 1808 megs and 2400 megs 
  int w;    // declare w variable
  char cmdAddMem[100];	// create array to store memsize = "####" command 
  sprintf(cmdAddMem, "echo memsize = \"%d\" >>%s \n", randMem(w), cVMX);
  system(cmdAddMem);	// run the system command stored in the array

  // 5th, cleanup temp files  
  char cmdDelTXT[100];	// create array to store del *.txt command 
  sprintf(cmdDelTXT, "del /q *.txt \n");
  system(cmdDelTXT);	// run the system command stored in the array  
  
  return 0;
}