Ejemplo n.º 1
0
irecv_error_t irecv_reset_counters(irecv_client_t client) {
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;
	if (client->mode == kDfuMode) {
		irecv_control_transfer(client, 0x21, 4, 0, 0, 0, 0, 1000);
	}
	return IRECV_E_SUCCESS;
}
Ejemplo n.º 2
0
irecv_error_t irecv_set_interface(irecv_client_t client, int interface,
				  int alt_interface)
{
	if (check_context(client) != IRECV_E_SUCCESS)
		return IRECV_E_NO_DEVICE;

#ifndef WIN32
	// pod2g 2011-01-07: we may want to claim multiple interfaces
	//libusb_release_interface(client->handle, client->interface);

	DPRINT("Setting to interface %d:%d\n", interface, alt_interface);
	if (libusb_claim_interface(client->handle, interface) < 0) {
		return IRECV_E_USB_INTERFACE;
	}

	if (libusb_set_interface_alt_setting
	    (client->handle, interface, alt_interface) < 0) {
		return IRECV_E_USB_INTERFACE;
	}

	client->interface = interface;
	client->alt_interface = alt_interface;
#endif

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 3
0
irecv_error_t irecv_send_exploit(irecv_client_t client)
{
	if (check_context(client) != IRECV_E_SUCCESS)
		return IRECV_E_NO_DEVICE;
	irecv_control_transfer(client, 0x21, 2, 0, 0, NULL, 0, 1000);
	return IRECV_E_SUCCESS;
}
Ejemplo n.º 4
0
irecv_error_t irecv_execute_script(irecv_client_t client, const char *filename)
{
	irecv_error_t error = IRECV_E_SUCCESS;
	char *file_data = NULL;
	unsigned int file_size = 0;
	char *line;

	if (check_context(client) != IRECV_E_SUCCESS)
		return IRECV_E_NO_DEVICE;

	if (irecv_read_file(filename, &file_data, &file_size) < 0) {
		return IRECV_E_FILE_NOT_FOUND;
	}

	line = strtok(file_data, "\n");
	while (line != NULL) {
		if (line[0] != '#') {
			error = irecv_send_command(client, line);
			if (error != IRECV_E_SUCCESS) {
				return error;
			}

			error = irecv_receive(client);
			if (error != IRECV_E_SUCCESS) {
				return error;
			}
		}
		line = strtok(NULL, "\n");
	}

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 5
0
irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** value) {
	int ret = 0;
	char command[256];
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;
	*value = NULL;

	if(variable == NULL) {
		return IRECV_E_UNKNOWN_ERROR;
	}

	memset(command, '\0', sizeof(command));
	snprintf(command, sizeof(command)-1, "getenv %s", variable);
	irecv_error_t error = irecv_send_command_raw(client, command);
	if(error == IRECV_E_PIPE) {
		return IRECV_E_SUCCESS;
	}
	if(error != IRECV_E_SUCCESS) {
		return error;
	}

	char* response = (char*) malloc(256);
	if (response == NULL) {
		return IRECV_E_OUT_OF_MEMORY;
	}

	memset(response, '\0', 256);
	ret = irecv_control_transfer(client, 0xC0, 0, 0, 0, (unsigned char*) response, 255, 1000);

	*value = response;
	return IRECV_E_SUCCESS;
}
Ejemplo n.º 6
0
irecv_error_t irecv_send_file(irecv_client_t client, const char* filename, int dfuNotifyFinished) {
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;

	FILE* file = fopen(filename, "rb");
	if (file == NULL) {
		return IRECV_E_FILE_NOT_FOUND;
	}

	fseek(file, 0, SEEK_END);
	long length = ftell(file);
	fseek(file, 0, SEEK_SET);

	char* buffer = (char*) malloc(length);
	if (buffer == NULL) {
		fclose(file);
		return IRECV_E_OUT_OF_MEMORY;
	}

	long bytes = fread(buffer, 1, length, file);
	fclose(file);

	if (bytes != length) {
		free(buffer);
		return IRECV_E_UNKNOWN_ERROR;
	}

	irecv_error_t error = irecv_send_buffer(client, (unsigned char*)buffer, length, dfuNotifyFinished);
	free(buffer);
	return error;
}
Ejemplo n.º 7
0
/*
 * Check satisfiability and get a model
 * - ctx = the context
 * - parameters = heuristic settings (if parameters is NULL, the defaults are used)
 * - var = array of n uninterpreted terms
 * - n = size of array evar and value
 * Output parameters;
 * - value = array of n terms (to receive the value of each var)
 * - model = to export the model (if model is NULL, nothing is exported)
 *
 * The return code is as in check_context:
 * 1) if code = STATUS_SAT then the context is satisfiable
 *    and a model is stored in value[0 ... n-1]
 *    - value[i] = a constant term mapped to evar[i] in the model
 * 2) code = STATUS_UNSAT: not satisfiable
 *
 * 3) other codes report an error of some kind or STATUS_INTERRUPTED
 */
static smt_status_t satisfy_context(context_t *ctx, const param_t *parameters, term_t *var, uint32_t n, term_t *value, model_t **model) {
  smt_status_t stat;
  model_t *mdl;
  int32_t code;

  assert(context_status(ctx) == STATUS_IDLE);

  stat = check_context(ctx, parameters);
  switch (stat) {
  case STATUS_SAT:
  case STATUS_UNKNOWN:
    mdl = yices_get_model(ctx, true);
    code = yices_term_array_value(mdl, n, var, value);
    if (model != NULL) {
      *model = mdl;
    } else {
      yices_free_model(mdl);
    }

    if (code < 0) {
      // can't convert the model to constant terms
      stat = STATUS_ERROR;
    }
    break;

  default:
    // can't build a model
    break;
  }

  return stat;
}
Ejemplo n.º 8
0
irecv_error_t irecv_reset(irecv_client_t client)
{
#ifndef WIN32
	libusb_reset_device(client->handle);
	if (check_context(client) != IRECV_E_SUCCESS)
		return IRECV_E_NO_DEVICE;
#else
	DWORD count;

	if (check_context(client) != IRECV_E_SUCCESS)
		return IRECV_E_NO_DEVICE;

	DeviceIoControl(client->handle, 0x22000C, NULL, 0, NULL, 0, &count,
			    NULL);
#endif

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 9
0
irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid) {
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;

	char* bdid_string = strstr(client->serial, "BDID:");
	if (bdid_string == NULL) {
		*bdid = 0;
		return IRECV_E_UNKNOWN_ERROR;
	}
	sscanf(bdid_string, "BDID:%d", bdid);

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 10
0
irecv_error_t irecv_get_ecid(irecv_client_t client, unsigned long long* ecid) {
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;

	char* ecid_string = strstr(client->serial, "ECID:");
	if (ecid_string == NULL) {
		*ecid = 0;
		return IRECV_E_UNKNOWN_ERROR;
	}
	sscanf(ecid_string, "ECID:%qX", ecid);

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 11
0
irecv_error_t irecv_finish_transfer(irecv_client_t client) {
	int i = 0;
	unsigned int status = 0;

	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;

	irecv_control_transfer(client, 0x21, 1, 0, 0, 0, 0, 1000);

	for(i = 0; i < 3; i++){
		irecv_get_status(client, &status);
	}
	irecv_reset(client);
	return IRECV_E_SUCCESS;
}
Ejemplo n.º 12
0
irecv_error_t irecv_recv_buffer(irecv_client_t client, char *buffer,
				unsigned long length)
{
	int recovery_mode = (client->mode != kDfuMode);
	int packet_size, last, packets;
	int i = 0;
	int bytes = 0;
	unsigned long count = 0;

	if (check_context(client) != IRECV_E_SUCCESS)
		return IRECV_E_NO_DEVICE;

	packet_size = recovery_mode ? 0x2000 : 0x800;
	last = length % packet_size;
	packets = length / packet_size;
	if (last != 0) {
		packets++;
	} else {
		last = packet_size;
	}

	for (i = 0; i < packets; i++) {
		unsigned short size = (i + 1) < packets ? packet_size : last;
		bytes =
		    irecv_control_transfer(client, 0xA1, 2, 0, 0,
					   (unsigned char *)&buffer[i *
								    packet_size],
					   size, 1000);

		if (bytes != size) {
			return IRECV_E_USB_UPLOAD;
		}

		count += size;
		if (client->progress_callback != NULL) {
			irecv_event_t event;
			event.progress =
			    ((double)count / (double)length) * 100.0;
			event.type = IRECV_PROGRESS;
			event.data = "Downloading";
			event.size = count;
			client->progress_callback(client, &event);
		} else {
			DPRINT("Sent: %d bytes - %lu of %lu\n", bytes, count,
			       length);
		}
	}

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 13
0
static OM_uint32	verify_mic
(OM_uint32		*minor_status,
 gss_opaque_t		context_handle,
 gss_buffer_t		message_buffer,
 gss_buffer_t		token_buffer,
 gss_qop_t		*qop_state
     )
{
  OM_uint32 major, minor;

  if ((major = check_context(&minor, context_handle)) != GSS_S_COMPLETE)
    return major;
  return GSS_S_FAILURE;
}
Ejemplo n.º 14
0
/**
 *  Completion callback
 */
void cb_amscatter_done (void *context, void * clientdata, pami_result_t err)
{
  validation_t *v = (validation_t*)clientdata;
  volatile unsigned *active = (volatile unsigned *) v->cookie;
  DEBUG((stderr, "cb_amscatter_done(): cookie= %p value=%u\n", active, *active));
  if(gVerbose)
  {
    check_context((pami_context_t) context);
  }

  int rc_check;
  _gRc |= rc_check = scatter_check_rcvbuf (_g_recv_buffer, v->bytes, my_task_id);
  if (rc_check) fprintf(stderr, "%s FAILED validation\n", gProtocolName);

  (*active)++;
}
Ejemplo n.º 15
0
irecv_error_t irecv_get_status(irecv_client_t client, unsigned int* status) {
	if (check_context(client) != IRECV_E_SUCCESS) {
		*status = 0;
		return IRECV_E_NO_DEVICE;
	}

	unsigned char buffer[6];
	memset(buffer, '\0', 6);
	if (irecv_control_transfer(client, 0xA1, 3, 0, 0, buffer, 6, 1000) != 6) {
		*status = 0;
		return IRECV_E_USB_STATUS;
	}

	*status = (unsigned int) buffer[4];
	return IRECV_E_SUCCESS;
}
Ejemplo n.º 16
0
irecv_error_t irecv_getret(irecv_client_t client, unsigned int* value) {
	int ret = 0;
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;
	*value = 0;

	char* response = (char*) malloc(256);
	if (response == NULL) {
		return IRECV_E_OUT_OF_MEMORY;
	}

	memset(response, '\0', 256);
	ret = irecv_control_transfer(client, 0xC0, 0, 0, 0, (unsigned char*) response, 255, 1000);

	*value = (unsigned int) *response;
	return IRECV_E_SUCCESS;
}
Ejemplo n.º 17
0
irecv_error_t irecv_setenv(irecv_client_t client, const char* variable, const char* value) {
	char command[256];
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;

	if(variable == NULL || value == NULL) {
		return IRECV_E_UNKNOWN_ERROR;
	}

	memset(command, '\0', sizeof(command));
	snprintf(command, sizeof(command)-1, "setenv %s %s", variable, value);
	irecv_error_t error = irecv_send_command_raw(client, command);
	if(error != IRECV_E_SUCCESS) {
		return error;
	}

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 18
0
irecv_error_t irecv_get_srnm(irecv_client_t client, unsigned char* srnm) {
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;

	char* srnmp;
	char* srnm_string = strstr(client->serial, "SRNM:[");
	if(srnm_string == NULL) {
		srnm = NULL;
		return IRECV_E_UNKNOWN_ERROR;
	}

	sscanf(srnm_string, "SRNM:[%s]", srnm);
	srnmp = strrchr(srnm, ']');
	if(srnmp != NULL) {
		*srnmp = '\0';
	}

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 19
0
irecv_error_t irecv_get_imei(irecv_client_t client, unsigned char* imei) {
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;

	char* imeip;
	char* imei_string = strstr(client->serial, "IMEI:[");
	if (imei_string == NULL) {
		*imei = 0;
		return IRECV_E_UNKNOWN_ERROR;
	}


	sscanf(imei_string, "IMEI:[%s]", imei);
	imeip = strrchr(imei, ']');
	if(imeip != NULL) {
		*imeip = '\0';
	}

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 20
0
irecv_error_t irecv_set_configuration(irecv_client_t client, int configuration) {
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;
	
#ifndef WIN32
	debug("Setting to configuration %d\n", configuration);

	int current = 0;
	libusb_get_configuration(client->handle, &current);
	if (current != configuration) {
		if (libusb_set_configuration(client->handle, configuration) < 0) {
			return IRECV_E_USB_CONFIGURATION;
		}
	}

	client->config = configuration;
#endif

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 21
0
/**
 *  Completion callback
 */
void cb_amreduce_done (void *context, void * clientdata, pami_result_t err)
{
  validation_t *v = (validation_t*)clientdata;
  volatile unsigned *active = (volatile unsigned *) v->cookie;
  DEBUG((stderr, "cb_amreduce_done(): cookie= %p value=%u\n", active, *active));
  if(gVerbose)
  {
    check_context((pami_context_t)context);
  }

  if(my_task_id == v->root)
  {
    int rc_check;
    size_t type_sz = get_type_size(dt_array[v->dt]);
    _gRc |= rc_check = reduce_check_rcvbuf (_g_recv_buffer, v->bytes/type_sz, v->op, v->dt, my_task_id, num_tasks);
    if (rc_check) fprintf(stderr, "%s FAILED validation\n", gProtocolName);
  }
  (*active)++;
}
Ejemplo n.º 22
0
static OM_uint32 inquire_context
  (OM_uint32	*minor_status,
   gss_opaque_t context_handle,
   gss_name_t 	*src_name,
   gss_name_t 	*targ_name,
   OM_uint32 	*lifetime_rec,
   OM_uint32 	*ctx_flags,
   int 		*locally_initiated,
   int 		*open)
{
  OM_uint32 major, minor;
  nil_context *context;

  if ((major = check_context(&minor, context_handle)) != GSS_S_COMPLETE)
    return major;

  context = (nil_context *) context_handle;
  if (src_name != NULL)
    {
      if ((*src_name = ilugss_copy_name(context->client)) == NULL)
	return GSS_S_FAILURE;
    }
  if (targ_name != NULL)
    {
      if ((*targ_name = ilugss_copy_name(context->server)) == NULL)
	return GSS_S_FAILURE;
    }
  if (lifetime_rec != NULL)
    {
      if (context->endtime != GSS_C_INDEFINITE)
	*lifetime_rec = context->endtime - time(NULL);
      else
	*lifetime_rec = GSS_C_INDEFINITE;
    }
  if (ctx_flags != NULL)
    *ctx_flags = context->flags;
  if (locally_initiated != NULL)
    *locally_initiated = context->locally_initiated;
  if (open != NULL)
    *open = context->complete;

  return GSS_S_COMPLETE;
}
Ejemplo n.º 23
0
irecv_client_t irecv_reconnect(irecv_client_t client, int initial_pause)
{
	irecv_error_t error = 0;
	irecv_client_t new_client = NULL;
	irecv_event_cb_t progress_callback = client->progress_callback;
#ifdef _WIN32
#ifdef _GUI_ENABLE_
	char buffer[256];
#endif
#endif

	if (check_context(client) == IRECV_E_SUCCESS) {
		irecv_close(client);
	}

#ifdef _WIN32
#ifdef _GUI_ENABLE_
	snprintf(buffer, 256, "Waiting %d seconds for the device...\n", initial_pause);
	SendMessage(hStatus3, WM_SETTEXT, 0, (LPARAM)buffer);
	InvalidateRect(window, NULL, TRUE);
#endif
#endif
	if (initial_pause > 0) {
		DPRINT("Waiting %d seconds for the device to pop up...\n",
		       initial_pause);
		sleep(initial_pause);
	}
#ifdef _WIN32
#ifdef _GUI_ENABLE_
	SendMessage(hStatus3, WM_SETTEXT, 0, (LPARAM) TEXT(" "));
	InvalidateRect(window, NULL, TRUE);
#endif
#endif

	error = irecv_open_attempts(&new_client, 10);
	if (error != IRECV_E_SUCCESS) {
		return NULL;
	}

	new_client->progress_callback = progress_callback;
	return new_client;
}
Ejemplo n.º 24
0
static OM_uint32	unwrap
(OM_uint32		*minor_status,
 gss_opaque_t		context_handle,
 gss_buffer_t		input_message_buffer,
 gss_buffer_t		output_message_buffer,
 int			*conf_state,
 gss_qop_t		*qop_state
     )
{
  OM_uint32 major, minor;

  if ((major = check_context(&minor, context_handle)) != GSS_S_COMPLETE)
    return major;
  output_message_buffer->length=input_message_buffer->length;
  output_message_buffer->value=
    ilugss_malloc(output_message_buffer->length);
  memcpy(output_message_buffer->value,input_message_buffer->value,
	 input_message_buffer->length);
  return GSS_S_COMPLETE;
}
Ejemplo n.º 25
0
irecv_error_t irecv_send_command(irecv_client_t client, char *command)
{
	irecv_error_t error = 0;
	unsigned int length;
	irecv_event_t event;

	if (check_context(client) != IRECV_E_SUCCESS)
		return IRECV_E_NO_DEVICE;

	length = strlen(command);
	if (length >= 0x100) {
		length = 0xFF;
	}

	if (client->precommand_callback != NULL) {
		event.size = length;
		event.data = command;
		event.type = IRECV_PRECOMMAND;
		if (client->precommand_callback(client, &event)) {
			return IRECV_E_SUCCESS;
		}
	}

	error = irecv_send_command_raw(client, command);
	if (error != IRECV_E_SUCCESS) {
		DPRINT("Failed to send command %s\n", command);
		if (error != IRECV_E_PIPE)
			return error;
	}

	if (client->postcommand_callback != NULL) {
		event.size = length;
		event.data = command;
		event.type = IRECV_POSTCOMMAND;
		if (client->postcommand_callback(client, &event)) {
			return IRECV_E_SUCCESS;
		}
	}

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 26
0
/**
 *  User dispatch function
 */
void cb_amreduce_send(pami_context_t         context,      /**< IN:  communication context which invoked the dispatch function */
                      void                 * cookie,       /**< IN:  dispatch cookie */
                      const void           * header_addr,  /**< IN:  header address  */
                      size_t                 header_size,  /**< IN:  header size     */
                      size_t                 data_size,    /**< IN:  data size       */
                      pami_endpoint_t        origin,       /**< IN:  root initiating endpoint */
                      pami_geometry_t        geometry,     /**< IN:  Geometry */
                      pami_data_function   * op,           /**< OUT: PAMI math operation to perform on the datatype */
                      pami_recv_t          * send)         /**< OUT: receive message structure */
{
  user_header_t *hdr;
  hdr = (user_header_t *) header_addr;
  DEBUG((stderr,"cb_amreduce_send(): header_addr=%p  header_size=%zu op=%d dt=%d cookie=%p\n",
         header_addr, header_size, hdr->op, hdr->dt, cookie));
  if(gVerbose)
  {
    check_context(context);
  }

  pami_task_t     task;
  size_t          offset;
  _gRc |= PAMI_Endpoint_query (origin,
                              &task,
                              &offset);

  validation_t *v = _g_val_buffer + task;
  v->cookie = cookie;
  v->bytes  = data_size;
  v->op     = hdr->op;
  v->dt     = hdr->dt;
  v->root = task;

  send->cookie      = (void*)v;
  send->local_fn    = cb_amreduce_done;
  send->addr        = _g_send_buffer;
  send->type        = dt_array[hdr->dt];
  send->offset      = 0;
  send->data_fn     = PAMI_DATA_COPY;
  send->data_cookie = NULL;
  *op = op_array[hdr->op];
}
Ejemplo n.º 27
0
static OM_uint32	context_time
(OM_uint32		*minor_status,
 gss_opaque_t		context_handle,
 OM_uint32		*time_rec
     )
{
  OM_uint32 major, minor;
  nil_context *ctx;

  *time_rec = 0;
  if ((major = check_context(&minor, context_handle)) != GSS_S_COMPLETE)
    return major;
    
  ctx = (nil_context *) context_handle;
  if (ctx->endtime != GSS_C_INDEFINITE)
    {
      nil_time_t now = time(NULL);
      *time_rec = ctx->endtime - now;
    }
  return GSS_S_COMPLETE;
}
Ejemplo n.º 28
0
irecv_error_t irecv_set_interface(irecv_client_t client, int main_interface, int alt_interface) {
	if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;
	
#ifndef _WIN32
	libusb_release_interface(client->handle, client->main_interface);

	debug("Setting to interface %d:%d\n", main_interface, alt_interface);
	if (libusb_claim_interface(client->handle, main_interface) < 0) {
		return IRECV_E_USB_INTERFACE;
	}

	if (libusb_set_interface_alt_setting(client->handle, main_interface, alt_interface) < 0) {
		return IRECV_E_USB_INTERFACE;
	}

	client->main_interface = main_interface;
	client->alt_interface = alt_interface;
#endif

	return IRECV_E_SUCCESS;
}
Ejemplo n.º 29
0
static rc_t compress_main( Args * args )
{
    rc_t rc;
    compress_context ctx;
    
    /* make and fill with default values */
    init_compress_context( &ctx );

    /* extract values from args */
    setup_compress_context( args, &ctx );

    rc = check_context( &ctx );
    DISP_RC( rc, "check_context() failed" );
    if ( rc == 0 )
        rc = perform_compress( &ctx );
    else
        MiniUsage( args );
    
    free_compress_context( &ctx );
    return rc;
}
Ejemplo n.º 30
0
irecv_client_t irecv_reconnect(irecv_client_t client, int initial_pause) {
	irecv_error_t error = 0;
	irecv_client_t new_client = NULL;
	irecv_event_cb_t progress_callback = client->progress_callback;

	if (check_context(client) == IRECV_E_SUCCESS) {
		irecv_close(client);
	}

	if (initial_pause > 0) {
		debug("Waiting %d seconds for the device to pop up...\n", initial_pause);
		sleep(initial_pause);
	}
	
	error = irecv_open_attempts(&new_client, 10);
	if(error != IRECV_E_SUCCESS) {
		return NULL;
	}

	new_client->progress_callback = progress_callback;
	return new_client;
}