Beispiel #1
0
char	*my_epur_str(char *str)
{
  char	*tmp;
  int	i;
  int	counter;

  counter = 0;
  i = 0;
  if ((tmp = malloc((my_strlen(str) + 1) * sizeof(char))) == NULL)
     return (NULL);
  str = str + (first_step(str));
  while (str[i] != '\0')
    {
      if (str[i] == ' ')
	{
	  while (str[i] == ' ')
	    i++;
	  if (str[i] != '\0')
	    {
	      tmp[counter] = ' ';
	      counter++;
	    }
	}
      tmp[counter++] = str[i++];
    }
  tmp[counter] = '\0';
  return (tmp);
}
Beispiel #2
0
/**
 * (Edit this function to print out the ten "Illinois" lines in mp1-functions.c in order.)
 */
int main()
{

	first_step(81);
	
	int * two= malloc(sizeof(int));
	*two= 132;
	second_step(two);
	free(two);
	
	int ** three= malloc(sizeof(int *));
	three[0]= malloc(sizeof(int));
	*three[0]= 8942;
	double_step(three);
	free(three[0]);
	free(three);

	int * four=0;	
	strange_step(four);

	char * five= calloc(4,sizeof(char));
	empty_step((void*)(five));
	free(five);

	char * s2= calloc(4,sizeof(char));
	s2[3]='u';
	void * s= s2;
	two_step(s, s2);
	free(s2);

	char * first= 0;
	char * second= first+2;
	char * third= second+2;
	three_step(first, second, third);	

	first= calloc(2,sizeof(char));
	first[1]= 0;
	second= malloc(3*sizeof(char));
	second[2]= first[1]+8;
	third= malloc(4*sizeof(char));
	third[3]= second[2]+8;
	step_step_step(first, second, third);
	free(first);
	free(second);
	free(third);

	char * nine= malloc(sizeof(char));
	*nine= 1;
	it_may_be_odd(nine, 1);	
	free(nine);

	int * orange= malloc(sizeof(int));
	*orange= 513;
	int * blue= orange;
	the_end((void *)orange,(void *) blue);	
	//printf("temp= %d\n", (*temp));
	free(orange);
	return 0;
}
Beispiel #3
0
int main(int argc, char **argv) {
    // 0 if first step, 1 if second step.
    int step = argv[1][0] - '0';

    if (step == 0) {
        first_step(argv[2]);
    } else {
        second_step(argv[2]);
    }
    return 0;
}
Beispiel #4
0
/**
 * (Edit this function to print out the ten "Illinois" lines in functions.c in order.)
 */
int main()
{
	first_step(81);
	
	int second_value = 132;
	int *second_p = &second_value;
	second_step(second_p);

	
	int third_value = 8942;
	int *third_p = &third_value;
	int **third_pp = &third_p;
	double_step(third_pp);

	int *forth_value = 0;
	strange_step(forth_value);

	void *fifth_value[] = {0, 0, 0, 0};
	empty_step(fifth_value);
	
	char *s2 = "uuuu";
	void *s = s2;
	two_step(s, s2);
	
	char *first, *second, *third;
	first = 0;
	second = first + 2;
	third = second + 2;
	three_step(first, second, third);
		
	char *arr = malloc(4*sizeof(char));
	arr[1] = 'a';
	arr[2] = arr[1] + 8;
	arr[3] = arr[2] + 8;
	step_step_step(arr, arr, arr);
	free(arr);
	
	int b = 1;
	void *a = &b;
	it_may_be_odd(a, b);	
	
	int end = 1281;
	void *orange, *blue;
	orange = blue = &end;
	the_end(orange, blue);	
	
	return 0;
}
Beispiel #5
0
/**
 * (Edit this function to print out the ten "Illinois" lines in part2-functions.c in order.)
 */
int main()
{
	first_step(81);
	int x = 132;
	int* y = &x;
	second_step(y);
	int *ww[1];
	*y = 8942;
	ww[0] = y;
	
	double_step(ww);
	void* ss = malloc(sizeof(int)*15);

	*(int*)(ss+5) = 15;
	strange_step(ss);
	*(char*)(ss+3) = 0;
	empty_step(ss);
	char a[4];
	a[3] = 'u';
	void* wwww;
	wwww = (void* )a;
	two_step(wwww, a); 
	
	three_step(a,a+2,a+4);
	free(ss);
	char b[4];
	b[1] = 'A';
	b[2] = 'A'+8;
	b[3] = 'A'+16;
	step_step_step(b,b,b);
	int sd = 'A';
	it_may_be_odd(b+(sizeof(char)), sd);
	char i[] = "C,CS241,41";
	tok_step(i);
	
	void* www;	
	x = 4353;
	www = (void*)&x;
	the_end(www,www);
	
	return 0;
}
Beispiel #6
0
int main(int argc, char **argv)
{

    if(argc != 2)
    {
        print_usage( argv );
        return 0;
    }

    if( strstr( argv[1], "1" ) != NULL) {
        if( verify() ) {
            disable_autorotate();
            first_step();                       //create link
        }
        else
        {
            printf("[-] It looks likey is not vulnerable!\n");
        }
    }
    else if( strstr( argv[1], "2") != NULL) {
        second_step();                          //edit ext4(/system) partition(set bit suid)
    }
    else if( strstr( argv[1], "3") != NULL) {
        third_step();                           //get root shell
    }
    else if( strstr( argv[1], "verify") != NULL){
        if( verify() )
            printf("[+] Should be vulnerable!\n");
        else
            printf("[-] Not vulnerable!\n");
    }
    else{
            print_usage( argv );
    }



    return 0;
}
Beispiel #7
0
int			main()
{
  struct timeval	tv;
  struct timezone	tz;
  t_util		*util;
  char			*str;

  gettimeofday(&tv, &tz);
  if (!(util = malloc(sizeof(t_util))))
    return (err_msg(": malloc fail"));
  if ((str = getenv("PWD")) == NULL)
    return (err_msg(": getenv fail"));
  srand(tv.tv_usec);
  if (!(util->key = ftok(str, 0)) == -1)
    return (err_msg(": ftok fail"));
  util->shm_id = shmget(util->key, (sizeof(char) * (MAP_X * MAP_Y)),
			SHM_R | SHM_W);
  if (util->shm_id == -1)
    first_step(util);
  else
    other_player(util);
  return (0);
}
Beispiel #8
0
/**
 * (Edit this function to print out the ten "Illinois" lines in part2-functions.c in order.)
 */
int main()
{
	//1
	first_step(81);

	//2
	int two = 132;
	second_step( &two );

	//3  ????

	int three =8942;
	int * threeP = &three;

	double_step(&threeP);

	//4
	int * four = 0;	
	strange_step(four);

	//5
	char five[4];
	five[3] =0;
	empty_step(five);

	//6
	char * six1, six2[4];
	six2[3] = 'u';
	six1= six2;	
	
	two_step(six1, six2);

	//7

	char * seven1;
	char * seven2;
	char * seven3;
	//seven2 = malloc(sizeof(char));
	seven1 = malloc(sizeof(char));
	//seven3 = malloc(sizeof(char));
	seven2 = seven1 + (char) 2;	
	seven3 = seven2 + (char) 2;

	three_step(seven1, seven2, seven3);
	
	free(seven1);
	
	//8
	char eight1[2];
	eight1[1] = 'b';

	char eight2[3];
	eight2[2] = 'b' + 8;	

	char eight3[4];
	eight3[3] = eight2[2] + 8;
	step_step_step(eight1, eight2, eight3);
	
	//9
	char * nineA = malloc (sizeof(char));
	int    nineB = 1;

	*nineA = (char) 1;

	it_may_be_odd(nineA, nineB);
	free(nineA);

	//10
	char * tenB = malloc(4*sizeof(char));
	int *  tenO = (int*) tenB;
	tenB[0] = (char) 1;
	tenB[1] = 2;
	
	the_end(tenO, tenB);
//((char *)blue)[0] == 1          *((int *)orange) % 3 == 0)


	return 0;

}
Beispiel #9
0
/*! \fn sym_euler_im_with_step_size_control_step
 *
 *   Function does one implicit euler step
 *   and calculates step size for the next step
 *   using the implicit midpoint rule
 *
 */
int sym_euler_im_with_step_size_control_step(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo)
{
  int retVal = 0;
  SIMULATION_DATA *sData = (SIMULATION_DATA*)data->localData[0];
  SIMULATION_DATA *sDataOld = (SIMULATION_DATA*)data->localData[1];
  DATA_SYM_IMP_EULER* userdata = (DATA_SYM_IMP_EULER*)solverInfo->solverData;

  double sc, err, a, b, diff;
  double Atol = data->simulationInfo->tolerance, Rtol = data->simulationInfo->tolerance;
  int i,j;
  double fac = 0.9;
  double facmax = 3.5;
  double facmin = 0.3;
  double saveTime = sDataOld->timeValue;
  double targetTime = sDataOld->timeValue + solverInfo->currentStepSize;


  if (userdata->firstStep  || solverInfo->didEventStep == 1)
  {
    first_step(data, solverInfo);
    userdata->radauStepSizeOld = 0;
  }

  infoStreamPrint(LOG_SOLVER,0, "new step: time=%e", userdata->radauTime);
  while (userdata->radauTime < targetTime)
  {
    do
    {
      /*** do one step with original step size ***/

      infoStreamPrint(LOG_SOLVER,0, "radauStepSize = %e and time = %e", userdata->radauStepSize, userdata->radauTime);

      /* update time */
      sDataOld->timeValue = userdata->radauTime;
      solverInfo->currentTime = userdata->radauTime + userdata->radauStepSize;
      sData->timeValue = solverInfo->currentTime;

      /* update step size */
      data->callback->symEulerUpdate(data, userdata->radauStepSize);

      memcpy(sDataOld->realVars, userdata->radauVars, data->modelData->nStates*sizeof(double));

      infoStreamPrint(LOG_SOLVER,0, "first system time = %e", sData->timeValue);

      /* evaluate function ODE */
      externalInputUpdate(data);
      data->callback->input_function(data, threadData);
      data->callback->functionODE(data,threadData);

      /* save values in y05 */
      memcpy(userdata->y05, sData->realVars, data->modelData->nStates*sizeof(double));

      /* extrapolate values in y1 */
      for (i=0; i<data->modelData->nStates; i++)
      {
        userdata->y1[i] = 2.0 * userdata->y05[i] - userdata->radauVars[i];
      }

      /*** do another step with original step size ***/
      memcpy(sDataOld->realVars, userdata->y05, data->modelData->nStates*sizeof(double));

      /* update time */
      sDataOld->timeValue = userdata->radauTime + userdata->radauStepSize;
      solverInfo->currentTime = userdata->radauTime + 2.0*userdata->radauStepSize;
      sData->timeValue = solverInfo->currentTime;

      infoStreamPrint(LOG_SOLVER,0, "second system time = %e", sData->timeValue);

      /* update step size */
      data->callback->symEulerUpdate(data, userdata->radauStepSize);

      /* evaluate function ODE */
      externalInputUpdate(data);
      data->callback->input_function(data, threadData);
      data->callback->functionODE(data, threadData);

      /* save values in y2 */
      memcpy(userdata->y2, sData->realVars, data->modelData->nStates*sizeof(double));

      /*** calculate error ***/
      for (i=0, err=0.0; i<data->modelData->nStates; i++)
      {
        sc = Atol + fmax(fabs(userdata->y2[i]),fabs(userdata->y1[i]))*Rtol;
        diff = userdata->y2[i]-userdata->y1[i];
        err += (diff*diff)/(sc*sc);
      }

      err /= data->modelData->nStates;
      err = sqrt(err);

      userdata->stepsDone += 1;
      infoStreamPrint(LOG_SOLVER, 0, "err = %e", err);
      infoStreamPrint(LOG_SOLVER, 0, "min(facmax, max(facmin, fac*sqrt(1/err))) = %e",  fmin(facmax, fmax(facmin, fac*sqrt(1.0/err))));


      /* update step size */
      userdata->radauStepSizeOld = 2.0 * userdata->radauStepSize;
      userdata->radauStepSize *=  fmin(facmax, fmax(facmin, fac*sqrt(1.0/err)));

      if (isnan(userdata->radauStepSize))
      {
        userdata->radauStepSize = 1e-6;
      }

    } while  (err > 1.0 );

    userdata->radauTimeOld =  userdata->radauTime;

    userdata->radauTime += userdata->radauStepSizeOld;

    memcpy(userdata->radauVarsOld, userdata->radauVars, data->modelData->nStates*sizeof(double));
    memcpy(userdata->radauVars, userdata->y2, data->modelData->nStates*sizeof(double));
  }

  sDataOld->timeValue = saveTime;
  solverInfo->currentTime = sDataOld->timeValue + solverInfo->currentStepSize;
  sData->timeValue = solverInfo->currentTime;


  /* linear interpolation */
  for (i=0; i<data->modelData->nStates; i++)
  {
    sData->realVars[i] = (userdata->radauVars[i] * (sData->timeValue - userdata->radauTimeOld) + userdata->radauVarsOld[i] * (userdata->radauTime - sData->timeValue))/(userdata->radauTime - userdata->radauTimeOld);

  }

  /* update first derivative  */
  infoStreamPrint(LOG_SOLVER,0, "Time  %e", sData->timeValue);
  for(i=0, j=data->modelData->nStates; i<data->modelData->nStates; ++i, ++j)
  {
    a = 4.0 * (userdata->y2[i] - 2.0 * userdata->y05[i] + userdata->radauVarsOld[i]) / (userdata->radauStepSizeOld * userdata->radauStepSizeOld);
    b = 2.0 * (userdata->y2[i] - userdata->y05[i])/userdata->radauStepSizeOld - userdata->radauTime * a;
    data->localData[0]->realVars[j] = a * sData->timeValue + b;
  }

  /* update step size */
  data->callback->symEulerUpdate(data, 0);
  solverInfo->solverStepSize = userdata->radauStepSizeOld;
  infoStreamPrint(LOG_SOLVER,0, "Step done to %f with step size = %e", sData->timeValue, solverInfo->solverStepSize);

  return retVal;
}
Beispiel #10
0
int main()
{
	/*
	 * [Part 1]:
	 *   Edit the provided part1.c file to print out the tweleve "Illinois" lines
	 *   that are provided in the code inside mp1-functions.c.
	 */
        
        //pass 81 value to print first Illinois.
        first_step(81);
        
        // initialize a varaible with value 132 and pass its pointer as an argument.
        int val = 132;
        second_step(&val);

        // pass a double pointer to string which has value 8942 as its value.
        // int double_val = 8942;
        int** pp = (int **) malloc(sizeof(int*));
        *pp = (int *) malloc(sizeof(int)); 
        *pp[0] = 8942;
        double_step(pp);

        free(*pp);
        free(pp);
        // initialize a pointer value to zero and pass it to strange_step function.
        int* p_val = 0;
        strange_step(p_val);

        // pass a character array whose fourth value is zero.
        int name[4] = {0};
        empty_step(name);

        // create a character array and pointer to that array.
        char s[4];
        char* s1;
        s1 = s;
        s[3] = 'u';
        two_step(s, s1);

        // create a character array and assign other these values.
        char first[10];
        char* second = first + 2;
        char* third = second + 2;
        three_step(first, second, third);

        // use above arrays assign values in such away that they will call this.
        *first = 0;
        *second = *first + 4;
        *third = *second + 4;
        triple_step(first, second, third);
        
        // use the above arrays to call third
        //third = second = first; 
        first[1] = 0;
        second[2] = first[1] + 8;
        third[3] = second[2] + 8;
        step_step_step(first, second, third);         

        // everything is set just call above function.
        triple_three_step_step_step(first, second, third);

        // create an integer which is less than 256
        int b = 10;
        char* a = (char* )&b;
        it_may_be_odd(a, b);

        // create an integer array with initial value 0;
        p_val =(int *) malloc(sizeof(int));
        *p_val = 513;
        the_end(p_val, p_val);
        free(p_val);

	return 0;
}