예제 #1
0
static void
dump_frame(int fd, PyFrameObject *frame)
{
    PyCodeObject *code;
    int lineno;

    code = frame->f_code;
    PUTS(fd, "  File ");
    if (code != NULL && code->co_filename != NULL
        && PyUnicode_Check(code->co_filename))
    {
        write(fd, "\"", 1);
        dump_ascii(fd, code->co_filename);
        write(fd, "\"", 1);
    } else {
        PUTS(fd, "???");
    }

    /* PyFrame_GetLineNumber() was introduced in Python 2.7.0 and 3.2.0 */
    lineno = PyCode_Addr2Line(code, frame->f_lasti);
    PUTS(fd, ", line ");
    dump_decimal(fd, lineno);
    PUTS(fd, " in ");

    if (code != NULL && code->co_name != NULL
        && PyUnicode_Check(code->co_name))
        dump_ascii(fd, code->co_name);
    else
        PUTS(fd, "???");

    write(fd, "\n", 1);
}
예제 #2
0
void query_extension( char *package, char *name, int major, int minor, int revision, char *short_name, char *invocation, char *org_name )
{
  int error;
  char tmp[2048];
  strcpy( tmp, basename( package ) );
  error = chdir( tmp );
  if ( error < 0 )
  {
    print_error( -2, "extension '%s' not accessible: %s\n", package, strerror( *(int*)(__errno_location( )) ) );
  }
  fprintf( stdout, "\nExtension '%s', version %i.%i.%i\n\n", name, major, minor, revision );
  dump_ascii( "description", "Description" );
  dump_ascii( "commands", "Commands provided" );
  dump_ascii( "libs", "Libraries provided" );
  dump_ascii( "headers", "Header files provided" );
  dump_ascii( "depends", "Dependencies" );
  dump_ascii( "bugs", "Bugs" );
  sprintf( tmp, "../%s", package );
  list_binaries( tmp );
  dump_ascii( "authors", "Author(s)" );
  fprintf( stdout, "Type '%s -d %s' to see more detailed information.\n", invocation, org_name );
  fprintf( stdout, "Type '%s -l %s' to see copyright information.\n", invocation, org_name );
  system( "sh post" );
  exit( 0 );
}
예제 #3
0
static int receive_msg(int fd, char *rx, size_t size,
			unsigned int timeout, bool debug)
{
	fd_set fds;
	struct timeval tv;
	int ret;
	unsigned int count;

	/* Initialize structures for select */
	FD_ZERO(&fds);
	FD_SET(fd, &fds);

	/*
	 * Microcontrolle answers very fast,
	 * Timeout is just to take care if no answer is
	 * sent
	 */
	tv.tv_sec = timeout;
	tv.tv_usec = 0; /* Check for not more as 10 mSec */

	ret = select(fd + 1, &fds, NULL, NULL, &tv);
	if (ret == 0) {
		ERROR("Timeout, no answer from microcontroller");
		return -EPROTO;
	}

	ret = read(fd, rx, size);
	if (ret < 3) {
		ERROR("Error in read: %d", ret);
		return -EBADMSG;
	}
	count = ret;

	if (debug)
		dump_ascii(true, rx, count);

	/*
	 * Try some syntax check
	 */
	if (rx[0] != '$') {
		ERROR("First byte is not '$' but '%c'", rx[0]);
		return -EBADMSG;
	}

	if (!verify_chksum(rx, &count)) {
		return -EBADMSG;
	}

	return 0;
}
예제 #4
0
void dump(unsigned char *data, unsigned int datalen, char *margin)
{
    unsigned int i, icols;

    for (i = 0; i < datalen; )
    {
        icols = datalen - i;

        if (icols > DUMP_COLS_PER_ROW)
            icols = DUMP_COLS_PER_ROW;

        dump_hex(&data[i], icols, margin);
        dump_ascii(&data[i], icols, "  ");
        printf("\n");

        i += icols;
    }
} /* dump */
예제 #5
0
void list_extensions( char *gisbase )
{
  char file[2048];
  FILE *f_in;
  fprintf( stdout, "\nExtensions in '%s' (name, version, type, depends):\n", gisbase );
  sprintf( file, "%s/etc/extensions.db", gisbase );
  f_in = (FILE*)fopen( file, "r" );
  if ( f_in == 0 )
  {
    if ( *(int*)(__errno_location( )) == 2 )
    {
      fwrite( "NONE.\n", 1, 6, stderr );
      fclose( f_in );
      exit( 0 );
    }
    fclose( f_in );
    print_error( -29, "checking for file '%s': %s\n", file[0], strerror( *(int*)(__errno_location( )) ) );
  }
  fclose( f_in );
  dump_ascii( file, "" );
  return;
}
예제 #6
0
static int update_fw(void *data, const void *buffer, unsigned int size)
{
	int cnt = 0;
	char c;
	int ret;
	char msg[80];
	struct handler_priv *priv = (struct handler_priv *)data;
	const char *buf = (const char *)buffer;

	while (size > 0) {
		c = buf[cnt++];
		priv->buf[priv->nbytes++] = c;
		size--;
		if (c == '\n') {
			/* Send data */
			if (priv->debug)
				dump_ascii(false, priv->buf, priv->nbytes);
			ret = write_data(priv->fduart, priv->buf, priv->nbytes);
			if (ret < 0)
				return ret;
			priv->buf[priv->nbytes] = '\0';
			msg[0] = '\0';
			ret = receive_msg(priv->fduart, msg, sizeof(msg),
					  priv->timeout, priv->debug);
			priv->nbytes = 0;
			if (ret < 0) {
				return ret;
			}
			if (!strcmp(msg, "$READY;"))
				continue;
			if (!strcmp(msg, "$COMPLETED;"))
				return 0;
		}
	}
	return 0;
}
예제 #7
0
void dump_program(struct state *state)
{
	int i, sect_size;
	uint8_t *ptr;

	state->hdr = next_sect(state, &sect_size);

	printf("######## HEADER: (size %d)\n", sect_size);
	printf("\tsize:       %d\n", state->hdr->size);
	printf("\tattributes: %d\n", state->hdr->num_attribs);
	printf("\tuniforms:   %d\n", state->hdr->num_uniforms);
	printf("\tsamplers:   %d\n", state->hdr->num_samplers);
	printf("\tvaryings:   %d\n", state->hdr->num_varyings);
	if (full_dump)
		dump_hex((void *)state->hdr, sect_size);
	printf("\n");

	/* there seems to be two 0xba5eba11's at the end of the header, possibly
	 * with some other stuff between them:
	 */
	next_sect(state, &sect_size);

	for (i = 0; (i < state->hdr->num_attribs) && (state->sz > 0); i++) {
		state->attribs[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->attribs[i]->type_info))
			state->attribs[i] = next_sect(state, &sect_size);

		clean_ascii(state->attribs[i]->name, sect_size - 28);
		if (full_dump) {
			printf("######## ATTRIBUTE: (size %d)\n", sect_size);
			dump_attribute(state->attribs[i]);
			dump_hex((char *)state->attribs[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_uniforms) && (state->sz > 0); i++) {
		state->uniforms[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->uniforms[i]->type_info))
			state->uniforms[i] = next_sect(state, &sect_size);

		clean_ascii(state->uniforms[i]->name, sect_size - 41);
		if (full_dump) {
			printf("######## UNIFORM: (size %d)\n", sect_size);
			dump_uniform(state->uniforms[i]);
			dump_hex((char *)state->uniforms[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_samplers) && (state->sz > 0); i++) {
		state->samplers[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->samplers[i]->type_info))
			state->samplers[i] = next_sect(state, &sect_size);

		clean_ascii(state->samplers[i]->name, sect_size - 33);
		if (full_dump) {
			printf("######## SAMPLER: (size %d)\n", sect_size);
			dump_sampler(state->samplers[i]);
			dump_hex((char *)state->samplers[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_varyings) && (state->sz > 0); i++) {
		state->varyings[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->varyings[i]->type_info))
			state->varyings[i] = next_sect(state, &sect_size);

		clean_ascii(state->varyings[i]->name, sect_size - 16);
		if (full_dump) {
			printf("######## VARYING: (size %d)\n", sect_size);
			dump_varying(state->varyings[i]);
			dump_hex((char *)state->varyings[i], sect_size);
		}
	}

	if (gpu_id >= 300) {
		dump_shaders_a3xx(state);
	} else {
		dump_shaders_a2xx(state);
	}

	if (!full_dump)
		return;

	/* dump ascii version of shader program: */
	ptr = next_sect(state, &sect_size);
	printf("\n#######################################################\n");
	printf("######## SHADER SRC: (size=%d)\n", sect_size);
	dump_ascii(ptr, sect_size);
	free(ptr);

	/* dump remaining sections (there shouldn't be any): */
	while (state->sz > 0) {
		ptr = next_sect(state, &sect_size);
		printf("######## section (size=%d)\n", sect_size);
		printf("as hex:\n");
		dump_hex(ptr, sect_size);
		printf("as float:\n");
		dump_float(ptr, sect_size);
		printf("as ascii:\n");
		dump_ascii(ptr, sect_size);
		free(ptr);
	}
}
예제 #8
0
void dump_program(struct state *state)
{
	int i, sect_size;
	uint8_t *ptr;

	state->hdr = next_sect(state, &sect_size);

	printf("######## HEADER: (size %d)\n", sect_size);
	printf("\tsize:           %d\n", state->hdr->size);
	printf("\trevision:       %d\n", state->hdr->revision);
	printf("\tattributes:     %d\n", state->hdr->num_attribs);
	printf("\tuniforms:       %d\n", state->hdr->num_uniforms);
	printf("\tsamplers:       %d\n", state->hdr->num_samplers);
	printf("\tvaryings:       %d\n", state->hdr->num_varyings);
	printf("\tuniform blocks: %d\n", state->hdr->num_uniformblocks);
	if (full_dump)
		dump_hex((void *)state->hdr, sect_size);
	printf("\n");

	/* there seems to be two 0xba5eba11's at the end of the header, possibly
	 * with some other stuff between them:
	 */
	ptr = next_sect(state, &sect_size);
	if (full_dump) {
		dump_hex_ascii(ptr, sect_size);
	}

	for (i = 0; (i < state->hdr->num_attribs) && (state->sz > 0); i++) {
		state->attribs[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->attribs[i]->type_info)) {
			dump_hex_ascii(state->attribs[i], sect_size);
			state->attribs[i] = next_sect(state, &sect_size);
		}

		clean_ascii(state->attribs[i]->name, sect_size - 28);
		if (full_dump) {
			printf("######## ATTRIBUTE: (size %d)\n", sect_size);
			dump_attribute(state->attribs[i]);
			dump_hex((char *)state->attribs[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_uniforms) && (state->sz > 0); i++) {
		state->uniforms[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->uniforms[i]->type_info)) {
			dump_hex_ascii(state->uniforms[i], sect_size);
			state->uniforms[i] = next_sect(state, &sect_size);
		}

		if (is_uniform_v2(state->uniforms[i])) {
			clean_ascii(state->uniforms[i]->v2.name, sect_size - 53);
		} else {
			clean_ascii(state->uniforms[i]->v1.name, sect_size - 41);
		}

		if (full_dump) {
			printf("######## UNIFORM: (size %d)\n", sect_size);
			dump_uniform(state->uniforms[i]);
			dump_hex((char *)state->uniforms[i], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_samplers) && (state->sz > 0); i++) {
		state->samplers[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->samplers[i]->type_info)) {
			dump_hex_ascii(state->samplers[i], sect_size);
			state->samplers[i] = next_sect(state, &sect_size);
		}

		clean_ascii(state->samplers[i]->name, sect_size - 33);
		if (full_dump) {
			printf("######## SAMPLER: (size %d)\n", sect_size);
			dump_sampler(state->samplers[i]);
			dump_hex((char *)state->samplers[i], sect_size);
		}

	}

	// These sections show up after all of the other sampler sections
	// Loops through them all since we don't deal with them
	if (state->hdr->revision >= 7) {
		for (i = 0; (i < state->hdr->num_samplers) && (state->sz > 0); i++) {
			ptr = next_sect(state, &sect_size);
			dump_hex_ascii(ptr, sect_size);
		}
	}


	for (i = 0; (i < state->hdr->num_varyings) && (state->sz > 0); i++) {
		state->varyings[i] = next_sect(state, &sect_size);

		/* hmm, for a3xx (or maybe just newer driver version), we have some
		 * extra sections that don't seem useful, so skip these:
		 */
		while (!valid_type(state->varyings[i]->type_info)) {
			dump_hex_ascii(state->varyings[i], sect_size);
			state->varyings[i] = next_sect(state, &sect_size);
		}

		clean_ascii(state->varyings[i]->name, sect_size - 16);
		if (full_dump) {
			printf("######## VARYING: (size %d)\n", sect_size);
			dump_varying(state->varyings[i]);
			dump_hex((char *)state->varyings[i], sect_size);
		}
	}

	/* not sure exactly which revision started this, but seems at least
	 * rev7 and rev8 implicitly include a new section for gl_FragColor:
	 */
	if (state->hdr->revision >= 7) {
		/* I guess only one? */
		state->outputs[0] = next_sect(state, &sect_size);

		clean_ascii(state->outputs[0]->name, sect_size - 32);
		if (full_dump) {
			printf("######## OUTPUT: (size %d)\n", sect_size);
			dump_output(state->outputs[0]);
			dump_hex((char *)state->outputs[0], sect_size);
		}
	}

	for (i = 0; (i < state->hdr->num_uniformblocks) && (state->sz > 0); i++) {
		state->uniformblocks[i].header = next_sect(state, &sect_size);

		clean_ascii(state->uniformblocks[i].header->name, sect_size - 40);
		if (full_dump) {
			printf("######## UNIFORM BLOCK: (size %d)\n", sect_size);
			dump_uniformblock(state->uniformblocks[i].header);
			dump_hex((char *)state->uniformblocks[i].header, sect_size);
		}

		/*
		 * OpenGL ES 3.0 spec mandates a minimum amount of 16K members supported
		 * a330 supports a minimum of 65K
		 */
		state->uniformblocks[i].members = malloc(state->uniformblocks[i].header->num_members * sizeof(void*));

		int member = 0;
		for (member = 0; (member < state->uniformblocks[i].header->num_members) && (state->sz > 0); member++) {
			state->uniformblocks[i].members[member] = next_sect(state, &sect_size);

			clean_ascii(state->uniformblocks[i].members[member]->name, sect_size - 56);
			if (full_dump) {
				printf("######## UNIFORM BLOCK MEMBER: (size %d)\n", sect_size);
				dump_uniformblockmember(state->uniformblocks[i].members[member]);
				dump_hex((char *)state->uniformblocks[i].members[member], sect_size);
			}
		}
		/*
		 * Qualcomm saves the UBO members twice for each UBO
		 * Don't ask me why
		 */
		for (member = 0; (member < state->uniformblocks[i].header->num_members) && (state->sz > 0); member++) {
			state->uniformblocks[i].members[member] = next_sect(state, &sect_size);

			clean_ascii(state->uniformblocks[i].members[member]->name, sect_size - 56);
			if (full_dump) {
				printf("######## UNIFORM BLOCK MEMBER2: (size %d)\n", sect_size);
				dump_uniformblockmember(state->uniformblocks[i].members[member]);
				dump_hex((char *)state->uniformblocks[i].members[member], sect_size);
			}
		}
	}

	if (gpu_id >= 300) {
		dump_shaders_a3xx(state);
	} else {
		dump_shaders_a2xx(state);
	}

	if (!full_dump)
		return;

	/* dump ascii version of shader program: */
	ptr = next_sect(state, &sect_size);
	printf("\n#######################################################\n");
	printf("######## SHADER SRC: (size=%d)\n", sect_size);
	dump_ascii(ptr, sect_size);
	free(ptr);

	/* dump remaining sections (there shouldn't be any): */
	while (state->sz > 0) {
		ptr = next_sect(state, &sect_size);
		printf("######## section (size=%d)\n", sect_size);
		printf("as hex:\n");
		dump_hex(ptr, sect_size);
		printf("as float:\n");
		dump_float(ptr, sect_size);
		printf("as ascii:\n");
		dump_ascii(ptr, sect_size);
		free(ptr);
	}
	/* cleanup the uniform buffer members we allocated */
	if (state->hdr->num_uniformblocks > 0)
		free (state->uniformblocks[i].members);
}
예제 #9
0
int Handle_Packet (char *buffer, int bytes_recieved)
{
    IP_Header     *ip;
    int           from_mask[4], to_mask[4];
    unsigned int  body_offset, body_size;    
       

     #ifdef DEBUG
     #ifdef UNIX

       addr.s_addr = IP_FROM(buffer);
       fprintf (stdout, "\n%s", inet_ntoa(addr));
       if (test_address (from_mask, flags.from_ip_mask) == 0)
       { fprintf (stdout, " (Src OK)"); }
       else
       { fprintf (stdout, " (Src WRONG)"); }

       addr.s_addr = IP_TO(buffer);
       fprintf (stdout, "\n%s", inet_ntoa(addr));
       if (test_address (to_mask, flags.to_ip_mask) == 0)
       { fprintf (stdout, " (Dest OK)"); }
       else
       { fprintf (stdout, " (Dest WRONG)"); }

       fprintf (stdout, "\nProtocol: %d", PROTOCOL(buffer));

     #endif
     #endif

     /********************************************************/
     /*               Dumping ethernet headers ?             */
     /********************************************************/
 
     if (flags.eth_hd == YES)
     { dump_eth_header(ETH_HEADER(buffer), flags.desc); }

     if (ETH_FORMAT(buffer) != ETHERNET_II) { return HANDLER_OK; }

     /********************************************************/
     /*                   Dump *IP* stuff *ONLY*             */
     /********************************************************/

     if (ETH_TYPE(buffer) == IP_ETH)
     {

        /********************************************************/
        /* Set IP masks                                         */
        /********************************************************/

        get_addr (IP_FROM(buffer), from_mask);
        get_addr (IP_TO(buffer), to_mask);

        /*******************************************************/
        /* Checking IP address with mask                       */
        /* Checking port numbers                               */
        /* Checking protocol                                   */
        /* ...                                                 */
        /*******************************************************/

        if
        (
          (test_address (from_mask, flags.from_ip_mask) == 0)
          &&
          (test_address (to_mask, flags.to_ip_mask) == 0)
          && (
               (flags.from_port_num == ALL_PORT)
               ||
               (get_src_port_number(buffer) == flags.from_port_num)
             )
          && (
               (flags.to_port_num == ALL_PORT)
               ||
               (get_dst_port_number(buffer) == flags.to_port_num)
             )
          && (
               (
                 (PROTOCOL(buffer) == UDP_PACKET)
                 &&
                 (flags.proto_udp == YES)
               )
               ||              
               (
                 (PROTOCOL(buffer) == TCP_PACKET)
                 &&
                 (flags.proto_tcp == YES)
               )
               ||              
               (
                 (PROTOCOL(buffer) == IGMP_PACKET)
                 &&
                 (flags.proto_igmp == YES)
               )
             ) /* end test on protocol */
        ) /* end if condition statement */
        {
          /******************************************************************/
          /* Sanity check                                                   */
          /******************************************************************/

          ip = IP_HEADER(buffer);
          if (
                ((ntohs(ip->ip_total_length)+ETH_HD_LEN) > bytes_recieved)
                &&
               (flags.verbose == YES)
             )
          {
             fprintf (stdout, "\nWARNING: received %d bytes", bytes_recieved);
             fprintf (stdout, "\n         total packet size ");
             fprintf (stdout, "%d bytes", ntohs(ip->ip_total_length)+ETH_HD_LEN);
             fprintf (stdout, "\n\nThis may be a network error ... skipping");
             fprintf (stdout, " the packet.\n");
             fflush (stdout);
             return HANDLER_OK;
          }

          /******************************************************************/
          /* Dump the IP header if requested                                */
          /******************************************************************/

          if (flags.ip_hd == YES) { dump_ip_header(ip, flags.desc); }

          /******************************************************************/
          /* Dump the following headers if requested:                       */
          /*    - UDP                                                       */
          /*    - TCP                                                       */
          /*                                                                */
          /* In the case of UDP, it may be a RIP message.                   */
          /******************************************************************/

          if (PROTOCOL(buffer) == UDP_PACKET)
          {
             if (flags.udp_hd == YES)
             { dump_udp_header(UDP_HEADER(buffer), flags.desc); }
             
             switch (UDP_SRC_PORT(buffer))
             {
               case SER_RIP:
                    if (RIP_VERSION(buffer) == 1)
                    { dump_rip1_header (buffer, flags.desc); }
                    else
                    { fprintf (stdout, "\nRIP version 2 !"); };
                    break;
               
               default:;
             }
          }

          if ((PROTOCOL(buffer) == TCP_PACKET) && (flags.tcp_hd == YES))
          { dump_tcp_header(TCP_HEADER(buffer), flags.desc); }

          /********************************************************************/
          /* Dump the packet bopy for the following protocols if requested:   */
          /*    - TCP                                                         */
          /*    - UDP                                                         */
          /*    - IGMP                                                        */
          /*                                                                  */
          /* Note that for IGMP the IGMP header is not separated from the bo- */
          /* -dy.                                                             */
          /********************************************************************/

          if (flags.body_level != BD_NONE)
          {
            /* Get offset and size of the body */
            body_info (buffer, &body_offset, &body_size);

           switch (flags.body_level)
           {
              case BD_HEXA   : dump_hexa (buffer+body_offset, body_size);
                               break;
              case BD_ASCII  : dump_ascii (buffer+body_offset, body_size);
                               break;
              case BD_MIX    : dump (buffer+body_offset, body_size); break;
              default : {
                          if (flags.verbose == YES)
                          { fprintf (stderr, "\nUnknown dump_body option\n"); }
                          else
                          { fprintf (stderr, "\nInternal error\n"); }
                          return HANDLER_ERR;
                        }
            } /* end switch (dump_body) */
          } /* end if for UDP/TCP/dump_body */
        } 

        return HANDLER_OK;       
     } /* end if for *IP* stuff *ONLY* */

     /*****************************************************/
     /* So it is not an IP stuff                          */
     /*****************************************************/

     /******************************************************/
     /*  May be it is ARP ?                                */
     /******************************************************/

     if ((ETH_TYPE(buffer) == ARP_ETH) && (flags.proto_arp == YES))
     {
        dump_ARP_header (ARP_HEADER(buffer), flags.desc);
     }


     return HANDLER_OK;       

}