예제 #1
0
파일: elf64_shr.c 프로젝트: iu-parfunc/elph
/*
 * Print a section header info. Information is printed on 80 columns and 
 * consists of section index, name, addr, offset in file, size, flags
 * and some others.
 * The print is done on stdout.
 * 
 * @param	shr		Pointer to the section to print info about
 * @param	bin		Binary structure
 * @param	shr_index	Index of the section header in section headers
 *				table
 *
 */
void print_shr_info(Elf64_Shdr *shr, ELF *bin, int shr_index) {
	/* Section index */
	printf("  [%2i] ", shr_index);

	/* Section name */
	print_section_name(get_section_name(bin->file, shr, bin->shr[bin->ehr->e_shstrndx]->sh_offset));

	print_section_type(shr->sh_type);

	/* Section address */
	printf("%08x ", (Elf64_Word) shr->sh_addr);

	/* Section offset */
	printf("%06x ", (Elf64_Word) shr->sh_offset);

	/* Section size */
	printf("%06x ", (Elf64_Word) shr->sh_size);

	/* Entry size */
	printf("%02x ", (unsigned char) shr->sh_entsize);

	/* FLAGS */
	print_section_flags(shr->sh_flags);

	/* Link */
	printf("%2u ", shr->sh_link);

    	/* Info */
	printf("%3u ", shr->sh_info);

 	/* Align */
	printf("%2u", (unsigned char) shr->sh_addralign);

	printf("\n");
}
예제 #2
0
/* This function locate the specified section in the etc file. */
static int etc_LocateSection(FILE* fp, const char* pSection, FILE* bak_fp)
{
    char szBuff[ETC_MAXLINE + 1];
    char *name;

    while (TRUE) {
        if (!fgets(szBuff, ETC_MAXLINE, fp)) {
            if (feof (fp))
                return ETC_SECTIONNOTFOUND;
            else
                return ETC_FILEIOFAILED;
        }
        else if (bak_fp && fputs (szBuff, bak_fp) == EOF)
            return ETC_FILEIOFAILED;
        
        name = get_section_name (szBuff);
        if (!name)
            continue;

        if (strcmp (name, pSection) == 0)
            return ETC_OK; 
    }

    return ETC_SECTIONNOTFOUND;
}
예제 #3
0
파일: elf64_shr.c 프로젝트: iu-parfunc/elph
/*
 * Find section header index from the name
 * 
 * @param	bin	Binary structure
 * @param	s_name	Name of the section to be found
 *
 * @req		The file pointed by bin->file must have been previously opened
 *
 * @ret		The index of the section if found, 0xFFFF otherwise
 *
 */
Elf64_Half get_section_idx(ELF *bin, char *s_name) {
	Elf64_Half idx = 0;
	Elf64_Off stroff = bin->shr[bin->ehr->e_shstrndx]->sh_offset;
	while (idx < bin->ehr->e_shnum) {
    char* sec_name = get_section_name(bin->file, bin->shr[idx], stroff);
		if (strcmp(s_name, sec_name) == 0) {
      free(sec_name);
			return idx;
    }
		idx++;
    free(sec_name);
	}
	return 0xFFFF;
}
예제 #4
0
static tree
section_parsed_coq (tree t) {
  tree r (DOCUMENT);
  int i, n= N(t);
  for (i=0; i<n; i++) {
    if (is_begin_section (t[i])) {
      string name= get_section_name (t[i++]);
      tree body (DOCUMENT);
      while (i<n && !is_end_section (t[i], name)) body << t[i++];
      r << compound ("coq-section", name, section_parsed_coq (body));
    }
    else
      r << t[i];
  }
  return r;
}
예제 #5
0
// Adds a section to the buffer
static int add_section(char *instring, long offset)
{
   int i;
   char section[MAX_SECTION_WIDTH+1];

   // Extract section name
   get_section_name(section,instring);
   // See if section already exists.
   for (i=0;i<NUM_SECTION_BUFFERS;i++)
      if (stricmp(section,section_buffers[i].name)==0)
         return(i);
   // Increment current_section_buffer
   current_section_buffer++;
   if (current_section_buffer>NUM_SECTION_BUFFERS)
      current_section_buffer=0;
   // Delete any field buffers that correspond to this section
   for (i=0;i<NUM_FIELD_BUFFERS;i++)
      if (field_buffers[i].section==current_section_buffer)
         field_buffers[i].name[0]=0;
   // Set buffer information
   strcpy(section_buffers[current_section_buffer].name,section);
   section_buffers[current_section_buffer].offset=offset;
   return(current_section_buffer);
}
예제 #6
0
static bool
is_end_section (tree t, string name) {
  return is_end (t) && get_section_name (t) == name;
}
예제 #7
0
static void analyze_sht(Elf32_Shdr *sh)
{
  int i;

  for(i = 1, sh++; i < e_shnum; i++, sh++)
  {
    if(sh->sh_size==0 && (e_type != ET_REL ||  //skip zero segment's
       (sh->sh_type != SHT_PROGBITS && sh->sh_type != SHT_NOBITS))) continue;

    if ( sh->sh_size == 0 ) continue;
    get_section_name(sh);
    switch(sh->sh_type) {
      case SHT_STRTAB:
        if(!strcmp(name, ".strtab"))
          str_sec = i;
        else if(!strcmp(name, ".dynstr"))
          dst_sec = i;
        break;

      case SHT_DYNAMIC:
      case SHT_DYNSYM:
      case SHT_SYMTAB:
          switch(sh->sh_type)
          {
            case SHT_SYMTAB:
              sym_sec = i;
              symcnt += low(sh->sh_size);
              break;
            case SHT_DYNSYM:
              dsm_sec = i;
              symcnt += low(sh->sh_size);
              break;
            case SHT_DYNAMIC:
              dyn_offset = sh->sh_offset;
              dyn_size   = sh->sh_size;
              dyn_link   = sh->sh_link;
              break;
          }
          break;

      case SHT_PROGBITS:
        if(!strcmp(name, ".interp"))
        {
          int_sec = i;
          break;
        }
        if(!strcmp(name, ".got"))
        {
          got_sec = i;
          break;
        }
        if(!strcmp(name, ".got.plt"))
        {
          gpt_sec = i;
          break;
        }
        // no break
      case SHT_NOBITS:
        if(!strcmp(name, ".plt")) plt_sec = i;
        break;

      // For Kylix (currently - efd only)
      case SHT_LOPROC:
        if(!strcmp(name, "borland.coment")) {
          borext_offset = sh->sh_offset;
          borext_size   = sh->sh_size;
        }
        break;
    }
  }
  if(!gpt_sec) gpt_sec = got_sec; // unification for ABI 2
  else if(!got_sec) gpt_sec = 0;  // unsupported format
}
예제 #8
0
int css_load_ini_file(const char* file_path)
{
	FILE* config_file = NULL;
	int i = 0, secCount = -1, keyCount = 0;
	char* line = NULL;
	int sec_tag = 0;
	css_config_env* m_env;
	CL_INFO("start loading config file : %s \n", file_path);
	if ((config_file = fopen(file_path, "r")) == NULL) {
		CL_ERROR("config file : %s not found!! \n", file_path);
		return -1;
	}

	m_css_config = (css_config*) malloc(MAX_SECMENT_LEN * sizeof(css_config));
	memset(m_css_config, 0, MAX_SECMENT_LEN * sizeof(css_config));
	while (EOF != readLine(config_file, &line)) {
		str_trim(line);
		if (line != NULL && strlen(line) > 0) {
			if (is_annotate_line(line)) {
				//nothing to do,ignore.
			} else if (is_segment_line(line)) {
				if (sec_tag == 1) {
//					printf("%d.%d\n", secCount, keyCount);
//					realloc(m_css_config[secCount].config,
//							keyCount * sizeof(css_config_env));
//					assert(m_css_config[secCount].config!=NULL);
					m_css_config[secCount].keyCount = keyCount;
					sec_tag = 0;
				}
				secCount++;
				get_section_name(line, &(m_css_config[secCount].setctionName));
//				printf("%d.%s\n",secCount,m_css_config[secCount].setctionName);
				m_css_config[secCount].config = (css_config_env*) malloc(
				MAX_KEY_VALUE_OF_SECMENT * sizeof(css_config_env));
				memset(m_css_config[secCount].config, 0,
						MAX_KEY_VALUE_OF_SECMENT * sizeof(css_config_env));
				sec_tag = 1;
				keyCount = 0;
			} else if (is_keyvalue_line(line)) {
				m_env = &(m_css_config[secCount].config[keyCount]);
				get_key_value(line, &(m_env->keyName), &(m_env->value));
//				printf("%d.%d %s:%s\n",secCount,keyCount,m_env->keyName,m_env->value);
				keyCount++;
			} else {
				CL_WARN("read unkown line : %s\n", line);
			}
		}
		FREE(line);
	}
	if (sec_tag == 1) {
//		printf("%d.%d\n", secCount, keyCount);
//		realloc(m_css_config[secCount].config,
//				keyCount * sizeof(css_config_env));
		m_css_config[secCount].keyCount = keyCount;
		sec_tag = 0;
	}
	secCount++;
	css_config_count = secCount;
	CL_DEBUG("total read %d sections of config file : %s.\n", secCount,
			file_path);
	return 0;
}
예제 #9
0
static int etc_ReadSection (FILE* fp, PETCSECTION psect)
{
    char szBuff[ETC_MAXLINE + 1 + 1];
    char* sect_name;
    int max_key_nr = 5;

    psect->name = NULL;
    psect->key_nr = 0;

    while (TRUE) {
        int bufflen;

        if (!fgets(szBuff, ETC_MAXLINE, fp)) {
            if (feof (fp)) {
                if (psect->name)
                    break;
                else
                    return ETC_SECTIONNOTFOUND;
            }
            else
                return ETC_FILEIOFAILED;
        }

        bufflen = strlen (szBuff);
        if (szBuff [bufflen - 1] == '\n')
            szBuff [bufflen - 1] = '\0';

        if (!psect->name) { /* read section name */
            sect_name = get_section_name (szBuff);
            if (!sect_name)
                continue;

            psect->name = strdup (sect_name);
            psect->key_nr = 0;
            psect->keys = malloc (sizeof(char*)*max_key_nr);
            psect->values = malloc (sizeof(char*)*max_key_nr);
        }
        else { /* read key and value */
            int ret;
            char *key, *value;

            if (psect->key_nr == max_key_nr) {
                max_key_nr += 5;
                psect->keys = (char **) realloc (psect->keys, sizeof(char*)*max_key_nr);
                psect->values = (char **) realloc (psect->values, sizeof(char*)*max_key_nr);
            }

            ret = get_key_value (szBuff, &key, &value);
            if (ret < 0)
                continue;
            else if (ret > 0) {  /* another section begins */
                fseek (fp, -bufflen, SEEK_CUR);
                break;
            }

            *(psect->keys + psect->key_nr) = strdup (key);
            *(psect->values + psect->key_nr) = strdup (value);
            psect->key_nr ++;
        }
    }

    return ETC_OK;
}