コード例 #1
0
ファイル: URI.c プロジェクト: PrioKim/AlgoSpot
void decode_percent_encoding(char * out, char * in)
{
	int j = 0; // j is out str's index
	char * ch = in;
	char decoded_char;
	int hex_code;

	while (*ch != '\0')
	{
		if (*ch == '%')
		{
			hex_code = (*(++ch) - '0') * 16;
			if (*(++ch) == 'a')
				hex_code += 10;
			else
				hex_code += (*ch - '0');

			decoded_char = search_table(hex_code);
			if (decoded_char == -1){
				fprintf(stdout, "search failed\n");
				return;
			}

			out[j] = decoded_char;
		}
		else
			out[j] = *ch;

		j++;
		ch++;
	}

	out[j] = '\0';
}
コード例 #2
0
ファイル: strlib.c プロジェクト: yongpitt/MiniJavaCompiler
int put_in_table(char *rs,Token_Type type,int len)
   {
     int exist;
     if(last_in_table == LIMIT1-1)
     {
       printf("string_table overflow!!! \n");
       return(-1);
     }
     

     
     exist = search_table(rs,len);
     if(exist == -1)
     {       
       strncpy(current,rs,len);
       last_in_table++;  
       string_table[last_in_table].real_string = current;
       string_table[last_in_table].tist = type;
       string_table[last_in_table].length = len;
       
       current += len;
       current[0] = '\0';
       current++ ;
       
       return(last_in_table);
     }
     else
     return(exist);  
   }
コード例 #3
0
ファイル: catalog.cpp プロジェクト: rn2dy/DBEngine525
/**
 * Return 1 if successfully delete, 0 otherwise
**/
int Catalog::del_rec(char *table_name)
{
	if(search_table(table_name))
	{
		tables.erase(tables.find(table_name));		
		numOfTables--;
		return 1;
	}
	else
		return 0;
}
コード例 #4
0
void load_edge(char* filename)
{
	FILE* fread = fopen(filename,"r");
	
	char line[MAX_LINE_LEN];
	while(1)
	{
		fgets(line, MAX_LINE_LEN, fread);
		if (feof(fread))
			break;
		
		char* tab1, *tab2;
		
		char ip1[32];
		char ip2[32];
		
		double delay;
		
		int i=0;
		while(line[i]!='\t')
		{
			ip1[i] = line[i];
			i++;
		}
		ip1[i]='\0';
		
		int j=0;
		i++;
		while (line[i]!='\t')
		{
			ip2[j] = line[i];
			j++;
			i++;
		}
		ip2[j]='\0';
		
		delay =  strtod(line+i, NULL);
		
		
		
		//printf("%s\t%s\t%f\n", ip1,ip2,delay);
		
		search_table(ip1,ip2,delay);
		
	}
	
	
	fclose(fread);
}
コード例 #5
0
ファイル: bus_cheker.c プロジェクト: ryuz/jelly
int read_table(unsigned long addr, unsigned long data, unsigned long sel)
{
	int      index;
	
	index = search_table(addr);
	if ( index >= 0 )
	{
		if ( data != table_data[index] )
		{
			printf("exp:%08lx\n", table_data[index]);
			return 0;
		}
		return 1;
	}
	else
	{
		printf("read error\n");
		return 0;
	}
}
コード例 #6
0
ファイル: bus_cheker.c プロジェクト: ryuz/jelly
void write_table(unsigned long addr, unsigned long data, unsigned long sel)
{
	int index;

	index = search_table(addr);
	if ( index < 0 )
	{
		if ( table_num + 1 >= TABLE_SIZE )
		{
			return;
		}
		index = table_num++;
	}
	
	table_valid[index] |= sel;
	table_addr[index]   = addr;
	if ( sel & 0x1 ) { table_data[index] = ((table_data[index] & 0xffffff00) | (data & 0x000000ff)); }
	if ( sel & 0x2 ) { table_data[index] = ((table_data[index] & 0xffff00ff) | (data & 0x0000ff00)); }
	if ( sel & 0x4 ) { table_data[index] = ((table_data[index] & 0xff00ffff) | (data & 0x00ff0000)); }
	if ( sel & 0x8 ) { table_data[index] = ((table_data[index] & 0x00ffffff) | (data & 0xff000000)); }
}
コード例 #7
0
int search_node_func_def_2(Node *node){
	if(DEBUG_SYMBOL_TABLE){
		printf("#ST: search_node_func_def_2: ");
	}

	int errorcount = 0;

	/* get the function name */
	char *function_name = node->first_child->value;

	if(DEBUG_SYMBOL_TABLE){
		printf("f_name: %s\n", function_name);
	}

	Table *function_table = search_table(function_name);

	/* handle node NODE_VAR_PART */

	errorcount += search_node_var_part_function(node->first_child->brother, function_table);

	return errorcount;
}
コード例 #8
0
const char *
dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
		     GElf_Sym *closest_sym, GElf_Word *shndxp)
{
  int syments = INTUSE(dwfl_module_getsymtab) (mod);
  if (syments < 0)
    return NULL;

  /* Return true iff we consider ADDR to lie in the same section as SYM.  */
  GElf_Word addr_shndx = SHN_UNDEF;
  inline bool same_section (const GElf_Sym *sym, GElf_Word shndx)
    {
      /* For absolute symbols and the like, only match exactly.  */
      if (shndx >= SHN_LORESERVE)
	return sym->st_value == addr;

      /* Figure out what section ADDR lies in.  */
      if (addr_shndx == SHN_UNDEF)
	{
	  GElf_Addr mod_addr = dwfl_deadjust_st_value (mod, addr);
	  Elf_Scn *scn = NULL;
	  addr_shndx = SHN_ABS;
	  while ((scn = elf_nextscn (mod->symfile->elf, scn)) != NULL)
	    {
	      GElf_Shdr shdr_mem;
	      GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
	      if (likely (shdr != NULL)
		  && mod_addr >= shdr->sh_addr
		  && mod_addr < shdr->sh_addr + shdr->sh_size)
		{
		  addr_shndx = elf_ndxscn (scn);
		  break;
		}
	    }
	}

      return shndx == addr_shndx;
    }

  /* Keep track of the closest symbol we have seen so far.
     Here we store only symbols with nonzero st_size.  */
  const char *closest_name = NULL;
  GElf_Word closest_shndx = SHN_UNDEF;

  /* Keep track of an eligible symbol with st_size == 0 as a fallback.  */
  const char *sizeless_name = NULL;
  GElf_Sym sizeless_sym = { 0, 0, 0, 0, 0, SHN_UNDEF };
  GElf_Word sizeless_shndx = SHN_UNDEF;

  /* Keep track of the lowest address a relevant sizeless symbol could have.  */
  GElf_Addr min_label = 0;

  /* Look through the symbol table for a matching symbol.  */
  inline void search_table (int start, int end)
    {
      for (int i = start; i < end; ++i)
	{
	  GElf_Sym sym;
	  GElf_Word shndx;
	  const char *name = INTUSE(dwfl_module_getsym) (mod, i, &sym, &shndx);
	  if (name != NULL && name[0] != '\0'
	      && sym.st_shndx != SHN_UNDEF
	      && sym.st_value <= addr
	      && GELF_ST_TYPE (sym.st_info) != STT_SECTION
	      && GELF_ST_TYPE (sym.st_info) != STT_FILE
	      && GELF_ST_TYPE (sym.st_info) != STT_TLS)
	    {
	      /* Even if we don't choose this symbol, its existence excludes
		 any sizeless symbol (assembly label) that is below its upper
		 bound.  */
	      if (sym.st_value + sym.st_size > min_label)
		min_label = sym.st_value + sym.st_size;

	      if (sym.st_size == 0 || addr - sym.st_value < sym.st_size)
		{
		  /* This symbol is a better candidate than the current one
		     if it's closer to ADDR or is global when it was local.  */
		  if (closest_name == NULL
		      || closest_sym->st_value < sym.st_value
		      || (GELF_ST_BIND (closest_sym->st_info)
			  < GELF_ST_BIND (sym.st_info)))
		    {
		      if (sym.st_size != 0)
			{
			  *closest_sym = sym;
			  closest_shndx = shndx;
			  closest_name = name;
			}
		      else if (closest_name == NULL
			       && sym.st_value >= min_label
			       && same_section (&sym, shndx))
			{
			  /* Handwritten assembly symbols sometimes have no
			     st_size.  If no symbol with proper size includes
			     the address, we'll use the closest one that is in
			     the same section as ADDR.  */
			  sizeless_sym = sym;
			  sizeless_shndx = shndx;
			  sizeless_name = name;
			}
		    }
		  /* When the beginning of its range is no closer,
		     the end of its range might be.  But do not
		     replace a global symbol with a local!  */
		  else if (sym.st_size != 0
			   && closest_sym->st_value == sym.st_value
			   && closest_sym->st_size > sym.st_size
			   && (GELF_ST_BIND (closest_sym->st_info)
			       <= GELF_ST_BIND (sym.st_info)))
		    {
		      *closest_sym = sym;
		      closest_shndx = shndx;
		      closest_name = name;
		    }
		}
	    }
	}
    }

  /* First go through global symbols.  mod->first_global is setup by
     dwfl_module_getsymtab to the index of the first global symbol in
     the module's symbol table, or -1 when unknown.  All symbols with
     local binding come first in the symbol table, then all globals.  */
  search_table (mod->first_global < 0 ? 1 : mod->first_global, syments);

  /* If we found nothing searching the global symbols, then try the locals.
     Unless we have a global sizeless symbol that matches exactly.  */
  if (closest_name == NULL && mod->first_global > 1
      && (sizeless_name == NULL || sizeless_sym.st_value != addr))
    search_table (1, mod->first_global);

  /* If we found no proper sized symbol to use, fall back to the best
     candidate sizeless symbol we found, if any.  */
  if (closest_name == NULL
      && sizeless_name != NULL && sizeless_sym.st_value >= min_label)
    {
      *closest_sym = sizeless_sym;
      closest_shndx = sizeless_shndx;
      closest_name = sizeless_name;
    }

  if (shndxp != NULL)
    *shndxp = closest_shndx;
  return closest_name;
}
コード例 #9
0
ファイル: mkg3states.c プロジェクト: narenas/nx-libs
short black_run_length (unsigned long prefix)
{
    return (search_table(prefix, TIFFFaxBlackCodes, NCODES(TIFFFaxBlackCodes)));
}
コード例 #10
0
ファイル: mkg3states.c プロジェクト: narenas/nx-libs
short white_run_length (unsigned long prefix)
{
    return (search_table(prefix, TIFFFaxWhiteCodes, NCODES(TIFFFaxWhiteCodes)));
}
コード例 #11
0
/*****************************************************************************
Gets called by picl_walk_tree_by_class.  Then it cycles through the properties
until we find what we are looking for.  Once we are done, we return
PICL_WALK_TERMINATE to stop picl_walk_tree_by_class from traversing the tree.

Note that PICL_PTYPE_UNSIGNED_INT and PICL_PTYPE_INT can either be 4-bytes
or 8-bytes.
*****************************************************************************/
static int probe_cpu(picl_nodehdl_t node_hdl, void* dummy_arg) {

  picl_prophdl_t  p_hdl;
  picl_prophdl_t  table_hdl;
  picl_propinfo_t p_info;
  long long       long_long_val;
  unsigned int    uint_val;
  int             index;
  int             int_val;
  int             val;
  char            string_val[PICL_PROPNAMELEN_MAX];

  val = picl_get_first_prop(node_hdl, &p_hdl);
  while (val == PICL_SUCCESS) {
    called_cpu_probe = 1;
    val = picl_get_propinfo(p_hdl, &p_info);
    if (val == PICL_SUCCESS) {
      for (index = 0; index < NUM_ITEMS; index++) {
        if (strcasecmp(p_info.name, items[index]) == 0) {
          if (p_info.type == PICL_PTYPE_UNSIGNED_INT) {
            if (p_info.size == sizeof(uint_val)) {
              val = picl_get_propval(p_hdl, &uint_val, sizeof(uint_val));
              if (val == PICL_SUCCESS) {
                long_long_val = uint_val;
                assign_value(index, long_long_val);
              }
            }
            else if (p_info.size == sizeof(long_long_val)) {
              val = picl_get_propval(p_hdl, &long_long_val,
                                     sizeof(long_long_val));
              if (val == PICL_SUCCESS) {
                assign_value(index, long_long_val);
              }
            }
          }
          else if (p_info.type == PICL_PTYPE_INT) {
            if (p_info.size == sizeof(int_val)) {
              val = picl_get_propval(p_hdl, &int_val, sizeof(int_val));
              if (val == PICL_SUCCESS) {
                long_long_val = int_val;
                assign_value(index, long_long_val);
              }
            }
            else if (p_info.size == sizeof(long_long_val)) {
              val = picl_get_propval(p_hdl, &long_long_val,
                                     sizeof(long_long_val));
              if (val == PICL_SUCCESS) {
                assign_value(index, long_long_val);
              }
            }
          }
          else if (p_info.type == PICL_PTYPE_CHARSTRING) {
            val = picl_get_propval(p_hdl, &string_val, sizeof(string_val));
            if (val == PICL_SUCCESS) {
              assign_string_value(index, string_val);
            }
          }
          else if (p_info.type == PICL_PTYPE_TABLE) {
            val = picl_get_propval(p_hdl, &table_hdl, p_info.size);
            if (val == PICL_SUCCESS) {
              search_table(index, table_hdl);
            }
          }
          break;
        } else if (index == NUM_ITEMS-1) {
	  if (p_info.type == PICL_PTYPE_CHARSTRING) {
            val = picl_get_propval(p_hdl, &string_val, sizeof(string_val));
            if (val == PICL_SUCCESS) {
            }	  
	  }
	} 
      }
    }

    val = picl_get_next_prop(p_hdl, &p_hdl);
  }
  return PICL_WALK_TERMINATE;
}
コード例 #12
0
ファイル: dnshijacker.c プロジェクト: keyeMyria/Attack
/******************************************************************************
 *  parse_dns                                                                 *
 *                                                                            *
 *  take a packet and print it (verbose or not)                               *
 *  store relevant information in our cc struct                               *
 *  arg1: (char *) pointer to packet                                          *
 *  arg2: (int)    captured packet length                                     *
 *  ret:  none                                                                *
 ******************************************************************************/
void parse_dns (char *packet, int caplen)   {
    struct   ip      *ip;           /* ip header                   */
    struct   udphdr  *udp;          /* udp header                  */
    struct   dnshdr  *dns;          /* dns header                  */
    char     *data,                 /* pointer to dns payload      */
             *data_backup,          /* we modify data so keep orig */
             name[128];             /* storage for lookup name     */
    u_long   rdata;                 /* rdata in network byte order */
    int      datalen,               /* length of dns payload       */
             c = 1,                 /* used in name extraction     */
             i;                     /* loop counter                */

    ip   = (struct ip     *) (packet + offset);
    udp  = (struct udphdr *) (packet + offset + LIBNET_IP_H);
    dns  = (struct dnshdr *) (packet + offset + LIBNET_IP_H + LIBNET_UDP_H);
    data = (packet + offset + LIBNET_IP_H + LIBNET_UDP_H + LIBNET_DNS_H);

    /*
     *  we modify the data pointer, so save the original position
     */

    data_backup = data;

    /*
     *  print dns packet source_address:port > destination_address:port
     */

    printf("\ndns activity:        %s:%d > ", inet_ntoa(ip->ip_src), ntohs(udp->uh_sport));
    printf("%s:%d",                           inet_ntoa(ip->ip_dst), ntohs(udp->uh_dport));

    /*
     *  clean out our name array and grab length of name to convert
     */

    memset(name, '\0', sizeof(name));
    datalen = strlen(data);

    #if defined DEBUG
            printf("\nDEBUG> datalen: %d", datalen);
    #endif

    /*
     *  convert name...
     *  dns names are of the form 3www7redhive3com
     *  we need to convert it to the more friendly www.redhive.com
     */

    if (dn_expand((u_char *)dns, packet + caplen, data, name, sizeof(name)) < 0)
        return;

    /*
     *  restore the data pointer
     */

    data = data_backup;

    /* kill the trailing '.' */
    name[datalen-1] = '\0';

    /*
     *  are we looking at a question or an answer?
     */

    if (htons(dns->qdcount) > 0 && htons(dns->ancount) == 0)
        printf("\t[%s = ?]", name);
    else if (htons(dns->ancount) > 0)
        printf("\t[%s = real answer]", name);

    /*
     *  what type of question is it?
     */

    #if defined DEBUG
        printf("\nDEBUG> data: %#x", *(data+datalen+2));
        if ( ((int)*(data+datalen+2)) == T_A)
            printf("\nDEBUG> type: A");

        if ( ((int)*(data+datalen+2)) == T_PTR)
            printf("\nDEBUG> type: PTR");
    #endif

    /*
     *  print more verbose packet information
     */

    if (vflag)   {
        printf("\ndns id:              %d", ntohs(dns->id));
        printf("\nrecursion desired:   %d", dns->rd);
        printf("\ntruncated message:   %d", dns->tc);
        printf("\nauthoritive answer:  %d", dns->aa);
        printf("\nopcode:              %d", dns->opcode);
        printf("\nresponse flag:       %d", dns->qr);
        printf("\nresponse code:       %d", dns->rcode);
        printf("\nrecursion available: %d", dns->ra);
        printf("\nnumber questions:    %d", htons(dns->qdcount));
        printf("\nnumber answers:      %d", htons(dns->ancount));
        printf("\nnumber authority:    %d", htons(dns->nscount));
    }

    /* print seperator */
    printf("\n--");

    /*
     *  bake the chewycenter
     */

    chewycenter.src_address = ip->ip_src.s_addr;
    chewycenter.dst_address = ip->ip_dst.s_addr;
    chewycenter.src_port    = udp->uh_sport;
    chewycenter.dst_port    = udp->uh_dport;
    chewycenter.dns_id      = dns->id;

    /*
     *  we only spoof packets from nameservers
     *  if the source of the question is not a client
     *  we don't waste any time building a packet, simply return
     */

    if (ntohs(chewycenter.dst_port) != 53) {
        return;
    }

    /*
     *  check the question type
     *  the question type is stored in the 2 bytes after the variables length name
     *  if the question is not of type A we return since we are only spoofing those type answers
     */

    if ( ((int)*(data+datalen+2)) == T_A)
        chewycenter.is_a = 1;
    else    {
        chewycenter.is_a = 0;
        return;
    }

    /*
     *  we start clean withno answer, also we set the current question
     */

    chewycenter.current_answer   = NULL;
    strncpy(chewycenter.current_question, name, 128);

    /*
     *  if there is a fabrication table search the list for an appropriate entry
     */

    if (fflag)
        chewycenter.current_answer = search_table(name);

    /*
     *  if an entry was not found and a default address is specified use it
     */

    if (!chewycenter.current_answer && dflag)    {
        chewycenter.current_answer = chewycenter.default_answer;
    }

    /*
     *  if an entry was not found and a default address is not specified then we ignore packet
     */

    if (!chewycenter.current_answer && !dflag)   {
        chewycenter.have_answer = 0;
        return;
    }

    /*
     *  if we've gotten this far it means that we have an answer to write
     */

    chewycenter.have_answer = 1;

    /*
     *  convert rdata from char * to something useable (unsigned long in network byte order)
     */

    rdata = libnet_name_resolve(chewycenter.current_answer, 0);

    /*
     *  build the payload
     *
     *  payload format: (very rudimentary ascii diagram)
     *  +-------------------------------|----------------------|--------------+
     *  | variable length question name | 2 byte question type | 2 byte class |
     *  |-------------------------------|----------------------|--------------|
     *  | variable length answer name   | 2 byte question type | 2 byte class |
     *  |-------------------------------|----------------------|--------------|
     *  | 4 byte time to live           | 2 byte rdata length  | 4 byte rdata |
     *  +-------------------------------|----------------------|--------------+
     *
     *  good lord is this ugly, but it works
     *  00 00 00 00 00 04 = 4 byte ttl + 2 byte rdata length
     *  rdata length is always 4, this is because we are only dealing with T_A
     *  hence rdata will always be a dotted quad
     */

    memcpy(chewycenter.payload, data, datalen + 5);

    memcpy(chewycenter.payload + datalen + 5, data, datalen + 5);

    memcpy(chewycenter.payload + 2 * (datalen + 5), "\x00\x00\x00\x00\x00\x04", 6);

    *((u_long *)(chewycenter.payload + 2 * (datalen + 5) + 6 + 0)) = rdata;

    chewycenter.payload_size = 2 * (datalen + 5) + 10;

    #if defined DEBUG
        printf("\nDEBUG>\ndata [%d]: ", datalen);
            for (i = 0; i < datalen+5; i++)
                printf("%x ", data[i]);
        printf("\n");

        printf("\nDEBUG>\nchewycenter [%d]: ", chewycenter.payload_size);
            for (i = 0; i < chewycenter.payload_size; i++)
                printf("%x ", chewycenter.payload[i]);
        printf("\n");
    #endif
}