示例#1
0
文件: jit-elf-write.c 项目: 8l/lllm
/*@
 * @deftypefun int jit_writeelf_write_section (jit_writeelf_t @var{writeelf}, const char *@var{name}, jit_int @var{type}, const void *@var{buf}, unsigned int @var{len}, int @var{discardable})
 * Write auxillary data to a section called @var{name}.  If @var{type}
 * is not zero, then it indicates an ELF section type.  This is used
 * by virtual machines to store auxillary data that can be retrieved
 * later using @code{jit_readelf_get_section}.  If the section already
 * contains data, then this will append the new data.  If @var{discardable}
 * is non-zero, then it is OK for this section to be discarded when the
 * ELF binary is stripped.  Returns zero if out of memory or the
 * parameters are invalid.
 * @end deftypefun
@*/
int jit_writeelf_write_section
	(jit_writeelf_t writeelf, const char *name, jit_int type,
	 const void *buf, unsigned int len, int discardable)
{
	jit_section_t section;
	if(!writeelf || !name)
	{
		return 0;
	}
	if(!type)
	{
		/* Application-specific section type, for storing unspecified data */
		type = (jit_int)(SHT_LOUSER + 0x1234);
	}
	if(discardable)
	{
		section = get_section(writeelf, name, type, 0, 1, 1);
	}
	else
	{
		section = get_section(writeelf, name, type, SHF_ALLOC, 1, 1);
	}
	if(!section)
	{
		return 0;
	}
	if(len > 0)
	{
		return add_to_section(section, buf, len);;
	}
	else
	{
		return 1;
	}
}
示例#2
0
void	parse_header(void *buf, char *name, int size)
{
   int		i;
   char		*limit;
   Elf32_Ehdr	*elf;
   Elf32_Shdr	*section;
   Elf32_Shdr	*section_name;

   elf = buf;
   if (check_type_elf(elf, name) == -1)
     return ;
   limit = (char *) ((unsigned int) buf + size);
   if (check_limit_elfheader(elf, limit) == -1)
     return ;
   i = 0;
   if ((section_name = get_section(elf->e_shstrndx, elf, buf, limit)) == NULL)
     return ;
   while (i < elf->e_shstrndx)
     {
       section = get_section(i, elf, buf, limit);
       if ((section->sh_size > 0) && (section->sh_type == SHT_PROGBITS))
	 afsct(section, buf, (char *)elf->e_entry, section_name);
       i++;
     }
}
示例#3
0
/** Convert to a string representation. If this RVA is unbound, then the string representation is the numeric RVA value (in
 * hexadecimal and decimal). Otherwise the string representation contains information about the bound section. */
std::string
rose_rva_t::to_string() const
{
    char s[1024];
    sprintf(s, "0x%08"PRIx64" (%"PRIu64")", get_rva(), get_rva());
    std::string ss = s;

    if (get_section()) {
        sprintf(s, " + 0x%08"PRIx64" (%"PRIu64")", get_rel(), get_rel());
        ss += " <" + get_section()->get_name()->get_string(true) + s + ">";
    }
    return ss;
}
示例#4
0
/* ARGSUSED */
int
fru_get_sections(container_hdl_t container, section_t *section, int maxsec,
    door_cred_t *cred)
{
	int count;
	int num_sec = 0;
	hash_obj_t *cont_object;
	hash_obj_t *sec_hash;

	cont_object = lookup_handle_object(container, CONTAINER_TYPE);
	if (cont_object == NULL) {
		return (-1);
	}

	if (cont_object->u.cont_obj->num_of_section > maxsec) {
		return (-1);
	}

	sec_hash = cont_object->u.cont_obj->sec_obj_list;
	if (sec_hash == NULL) {
		return (-1);
	}

	for (count = 0; count < cont_object->u.cont_obj->num_of_section;
	    count++) {
		section->version = -1;
		/* populate section_t */
		if (get_section(g_raw, sec_hash, section) == 0) {
			section++;
			num_sec++;
		}
		sec_hash = sec_hash->u.sec_obj->next;
	}
	return (num_sec);
}
static void read_triggers(void)
{
  File f = cfg_file;
  String line;
  uint32_t pos = 0;

  Serial.println("reading trigger list");

  if (!f)
    return;

  __log("DBG: %s: f.available=%d\n", __func__, f.available());
  while (f.available()) {
    __log("DBG: read_triggers: position %u\n", pos);
    //Serial.printf("- pos %u\n", pos);

    if (!f.seek(pos, SeekSet)) {
      Serial.println("read_triggers: failed seek\n");
      break;
    }

    line = f.readStringUntil('\n');
    if (!line)
      break;
    // is line null if this fails?
    
    if (line.startsWith("[logic") ||
        line.startsWith("[input") ||
        line.startsWith("[output")) {
      String section = get_section(line);
      read_trigger(section.c_str());
    }
    pos += line.length() + 1;
  }
}
示例#6
0
文件: settings.c 项目: baloo79/uTox
static int config_parser(const char* section, const char* key, const char* value, void* config_v) {
    UTOX_SAVE *config = (UTOX_SAVE*) config_v;

    switch(get_section(section)) {
        case GENERAL_SECTION: {
            parse_general_section(config, key, value);
            break;
        }
        case INTERFACE_SECTION: {
            parse_interface_section(config, key, value);
            break;
        }
        case AV_SECTION: {
            parse_av_section(config, key, value);
            break;
        }
        case NOTIFICATIONS_SECTION: {
            parse_notifications_section(config, key, value);
            break;
        }
        case ADVANCED_SECTION: {
            parse_advanced_section(config, key, value);
            break;
        }
        case UNKNOWN_SECTION: {
            LOG_NOTE("Settings", "Unknown section in config file: %s", section);
            break;
        }
    }

    return 1;
}
示例#7
0
文件: kmp_i18n.c 项目: PRUNER/openmp
char const *
__kmp_i18n_catgets(
    kmp_i18n_id_t  id
) {

    int section = get_section( id );
    int number  = get_number( id );
    char const * message = NULL;

    if ( 1 <= section && section <= __kmp_i18n_default_table.size ) {
        if ( 1 <= number && number <= __kmp_i18n_default_table.sect[ section ].size ) {
            if ( status == KMP_I18N_CLOSED ) {
                __kmp_i18n_catopen();
            }; // if
            if ( status == KMP_I18N_OPENED ) {
                message =
                    catgets(
                        cat,
                        section, number,
                        __kmp_i18n_default_table.sect[ section ].str[ number ]
                    );
            }; // if
            if ( message == NULL ) {
                message = __kmp_i18n_default_table.sect[ section ].str[ number ];
            }; // if
        }; // if
    }; // if
    if ( message == NULL ) {
        message = no_message_available;
    }; // if
    return message;

} // func __kmp_i18n_catgets
示例#8
0
文件: sflbits.c 项目: cookrn/openamq
int
bits_clear (
    BITS *bits,
    long bit)
{
    int
        index,                          /*  Number of index block            */
        section;                        /*  Number of section in index       */
    dbyte
        bit_nbr;                        /*  Number of bit in section         */
    int
        feedback = 0;


    ASSERT (bits);

    if (bit >= 0 && bit < BIT_MAXBITS)
      {
        locate_bit  (bits, bit, &index, &section, &bit_nbr);
        get_section (bits, index, section, section_data, TRUE);
        section_data [bit_nbr / 8] &= 255 - (1 << (bit_nbr % 8));
        put_section (bits, index, section, section_data);
      }
    else
        feedback = -1;
    return (feedback);
}
static void read_depends(void)
{
  File f = cfg_file;
  String line;
  uint32_t pos = 0;

  Serial.println("reading dependency info");

  if (!f)
    return;

  while (true) {
    if (!f.seek(pos, SeekSet)) {
      Serial.println("read_triggers: failed seek\n");
      break;
    }

    if (f.available() <= 0)
      break;
    
    line = f.readStringUntil('\n');
    if (!line)
      break;
 
    if (line.startsWith("[dependency")) {
      String section = get_section(line);
      __log("DBG: found depdency section '%s'\n", section.c_str());
      read_dependency(section.c_str());
    }
    pos += line.length() + 1;
  }
}
示例#10
0
文件: regini.cpp 项目: KrossX/Regini
	void regini_file::write_string(string section, string key, string value)
	{
		section_type *sec = get_section(section);

		entry_type newentry;
		newentry.key = key;
		newentry.value = value;

		if (sec == nullptr)
		{
			section_type newsection;
			newsection.name = section;
			newsection.entry.push_back(newentry);
			this->section.push_back(newsection);
		}
		else
		{
			entry_type *entry = get_entry(section, key);

			if (entry == nullptr)
			{
				sec->entry.push_back(newentry);
			}
			else
			{
				entry->value = newentry.value;
			}
		}
	}
示例#11
0
void get_section_value(const frontend::stache_model &model,
                       const std::string &key,
                       section_range_sink &sink)
{
    auto isubmodel = model.find(key);
    if (isubmodel != model.end()) {
        detail::section_getter_visitor get_section(sink);
        boost::apply_visitor(get_section, isubmodel->second);
    }
}
示例#12
0
void add_entry(char *section_name, char *key, char *value)
{
        section_t *s = get_section(section_name);
        if (s == NULL) {
                s = new_section(section_name);
        }

        s->entry_count++;
        int len = s->entry_count;
        s->entries = realloc(s->entries, sizeof(entry_t) * len);
        s->entries[s->entry_count - 1].key = g_strdup(key);
        s->entries[s->entry_count - 1].value = clean_value(value);
}
示例#13
0
char *get_value(char *section, char *key)
{
        section_t *s = get_section(section);
        if (!s) {
                return NULL;
        }

        for (int i = 0; i < s->entry_count; i++) {
                if (strcmp(s->entries[i].key, key) == 0) {
                        return s->entries[i].value;
                }
        }
        return NULL;
}
示例#14
0
void
go_write_export_data (const char *bytes, unsigned int size)
{
  static section* sec;

  if (sec == NULL)
    {
      gcc_assert (targetm_common.have_named_sections);
      sec = get_section (GO_EXPORT_SECTION_NAME, SECTION_DEBUG, NULL);
    }

  switch_to_section (sec);
  assemble_string (bytes, size);
}
示例#15
0
文件: kmp_i18n.c 项目: PRUNER/openmp
char const *
__kmp_i18n_catgets(
    kmp_i18n_id_t  id
) {

    int section = get_section( id );
    int number  = get_number( id );
    char const * message = NULL;

    if ( 1 <= section && section <= __kmp_i18n_default_table.size ) {
        if ( 1 <= number && number <= __kmp_i18n_default_table.sect[ section ].size ) {
            if ( status == KMP_I18N_CLOSED ) {
                __kmp_i18n_catopen();
            }; // if
            if ( cat != KMP_I18N_NULLCAT ) {
                if ( table.size == 0 ) {
                    table.sect = (kmp_i18n_section_t *)
                        KMP_INTERNAL_CALLOC(
                            ( __kmp_i18n_default_table.size + 2 ),
                            sizeof( kmp_i18n_section_t )
                        );
                    table.size = __kmp_i18n_default_table.size;
                }; // if
                if ( table.sect[ section ].size == 0 ) {
                    table.sect[ section ].str = (const char **)
                        KMP_INTERNAL_CALLOC(
                            __kmp_i18n_default_table.sect[ section ].size + 2,
                            sizeof( char const * )
                        );
                    table.sect[ section ].size = __kmp_i18n_default_table.sect[ section ].size;
                }; // if
                if ( table.sect[ section ].str[ number ] == NULL ) {
                    table.sect[ section ].str[ number ] = ___catgets( id );
                }; // if
                message = table.sect[ section ].str[ number ];
            }; // if
            if ( message == NULL ) {
                // Catalog is not opened or message is not found, return default message.
                message = __kmp_i18n_default_table.sect[ section ].str[ number ];
            }; // if
        }; // if
    }; // if
    if ( message == NULL ) {
        message = no_message_available;
    }; // if
    return message;

} // func __kmp_i18n_catgets
示例#16
0
static int fixup_reloc(void *image, struct nt_header *nt_hdr)
{
	struct section_header *sect_hdr;
	int base = nt_hdr->opt_hdr.opt_nt_hdr.image_base;
	int size;
	struct coffpe_relocs *fixup_block;

	sect_hdr = get_section(nt_hdr, ".reloc");
	if (sect_hdr == NULL)
		return -EINVAL;
	fixup_block = (struct coffpe_relocs *)(image + sect_hdr->rawdata_addr);

	do
	{
		int i;
		uint16_t fixup, offset;

		size = (fixup_block->block_size - (2 * sizeof(uint32_t))) /
			sizeof(uint16_t);
		for (i = 0; i < size; i++)
		{
			uint32_t *loc;
			uint32_t addr;
			fixup = fixup_block->fixup[i];
			offset = fixup & 0xfff;
			loc = RVA2VA(image, fixup_block->page_rva + offset,
				   uint32_t *);

			switch ((fixup >> 12) & 0x0f)
			{
			case COFF_FIXUP_ABSOLUTE:
				break;
			case COFF_FIXUP_HIGHLOW:
				addr = RVA2VA(image, (*loc - base), uint32_t);
				*loc = addr;
				break;
			default:
				ERROR("unknown fixup: %08X", fixup);
				return -EOPNOTSUPP;
				break;
			}
		}
		fixup_block = (struct coffpe_relocs *)
			((size_t)fixup_block + fixup_block->block_size);
	} while (fixup_block->block_size);

	return 0;
}
示例#17
0
文件: symtab.c 项目: lv88h/gcc
void
symtab_node::set_section_for_node (const char *section)
{
  const char *current = get_section ();
  void **slot;

  if (current == section
      || (current && section
	  && !strcmp (current, section)))
    return;

  if (current)
    {
      x_section->ref_count--;
      if (!x_section->ref_count)
	{
	  slot = htab_find_slot_with_hash (symtab->section_hash, x_section->name,
					   htab_hash_string (x_section->name),
					   INSERT);
	  ggc_free (x_section);
	  htab_clear_slot (symtab->section_hash, slot);
	}
      x_section = NULL;
    }
  if (!section)
    {
      implicit_section = false;
      return;
    }
  if (!symtab->section_hash)
    symtab->section_hash = htab_create_ggc (10, hash_section_hash_entry,
				    eq_sections, NULL);
  slot = htab_find_slot_with_hash (symtab->section_hash, section,
				   htab_hash_string (section),
				   INSERT);
  if (*slot)
    x_section = (section_hash_entry *)*slot;
  else
    {
      int len = strlen (section);
      *slot = x_section = ggc_cleared_alloc<section_hash_entry> ();
      x_section->name = ggc_vec_alloc<char> (len + 1);
      memcpy (x_section->name, section, len + 1);
    }
  x_section->ref_count++;
}
示例#18
0
static int parse(struct ini_config *ini, char *buff, unsigned long size)
{
	int curr_section;
	char *curr_pos;
	char *tmp;
	char line[128];
	int section_nr;
	int key_nr;
	int key_cnt;
	int val_cnt;
	int cnt;
	curr_section = 0;

	curr_pos = buff;
	while (size) {
		cnt = get_section_key_nr(curr_pos, size, &section_nr, &key_nr);
		if (cnt == -1)
			return 0;
		tmp = curr_pos;
		ini->section_tbl[curr_section].key_nr = key_nr;
		ini->section_tbl[curr_section].key_tbl = (struct key *)malloc(sizeof(struct key));
		if (!ini->section_tbl[curr_section].key_tbl)
			return 0;
		ini->section_tbl[curr_section].name = (char *)malloc(section_nr);
		tmp = get_line(tmp, line, 128);
		get_section(line, 128, ini->section_tbl[curr_section].name);
		for (int i = 0; i < key_nr; i++) {
			tmp = get_line(tmp, line, 128);
			get_key_val_nr(line, 128, &key_cnt, &val_cnt);
			ini->section_tbl[curr_section].key_tbl[i].key_name = (char *)malloc(key_cnt);
			ini->section_tbl[curr_section].key_tbl[i].key_val = (char *)malloc(val_cnt);
			get_key_val(line, 128, 
				ini->section_tbl[curr_section].key_tbl[i].key_name,
				ini->section_tbl[curr_section].key_tbl[i].key_val);
			printf("section:%s,key_name:%s, key_val%s\n", ini->section_tbl[curr_section].name,
				ini->section_tbl[curr_section].key_tbl[i].key_name,
				ini->section_tbl[curr_section].key_tbl[i].key_val);
		}
		curr_section++;
		curr_pos += cnt;
		size -= cnt;
	}
	return 1;
}
示例#19
0
void
pp::INI::File::write (std::wstring fname)
{
  FILE*   fOut;
  errno_t ret;

  // Strip Read-Only
  /////////AD_SetNormalFileAttribs (fname);

  TRY_FILE_IO (_wfopen_s (&fOut, fname.c_str (), L"w,ccs=UTF-16LE"), fname.c_str (), ret);

  if (ret != 0 || fOut == 0) {
    //AD_MessageBox (L"ERROR: Cannot open INI file for writing. Is it read-only?", fname.c_str (), MB_OK | MB_ICONSTOP);
    return;
  }

  std::vector <std::wstring>::iterator it  = ordered_sections.begin ();
  std::vector <std::wstring>::iterator end = ordered_sections.end   ();

  while (it != end) {
    Section& section = get_section (*it);
    fwprintf (fOut, L"[%s]\n", section.name.c_str ());

    std::vector <std::wstring>::iterator key_it  = section.ordered_keys.begin ();
    std::vector <std::wstring>::iterator key_end = section.ordered_keys.end   ();

    while (key_it != key_end) {
      std::wstring val = section.get_value (*key_it);
      fwprintf (fOut, L"%s=%s\n", key_it->c_str (), val.c_str ());
      ++key_it;
    }

    // Append a newline for everything except the last line...
    if (++it != end)
      fwprintf (fOut, L"\n");
  }

  fflush (fOut);
  fclose (fOut);

  // Make Read-Only
  ////SetFileAttributes (fname.c_str (), FILE_ATTRIBUTE_READONLY);
}
示例#20
0
文件: nwld.c 项目: sequoiar/moxiedev
void
nwld_named_section_asm_out_destructor (rtx symbol, int priority)
{
#if !SUPPORTS_INIT_PRIORITY
  const char section[] = ".dtors"TARGET_SUB_SECTION_SEPARATOR;
#else
  char section[20];

  sprintf (section, ".dtors"TARGET_SUB_SECTION_SEPARATOR"%.5u",
	   /* Invert the numbering so the linker puts us in the proper
	      order; destructors are run from left to right, and the
	      linker sorts in increasing order.  */
	   MAX_INIT_PRIORITY - priority);
#endif

  switch_to_section (get_section (section, 0, NULL));
  assemble_align (POINTER_SIZE);
  assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
}
示例#21
0
文件: regini.cpp 项目: KrossX/Regini
	entry_type* regini_file::get_entry(string section_name, string key_name)
	{
		section_type* sec = get_section(section_name);

		if (sec != nullptr)
		{
			key_name = string_tolower(key_name);

			for (size_t i = 0; i < sec->entry.size(); i++)
			{
				string ekeyname = string_tolower(sec->entry[i].key);

				if (ekeyname.compare(key_name) == 0)
					return &sec->entry[i];
			}
		}

		return nullptr;
	}
示例#22
0
int
bits_test (
    const BITS *bits,
    long bit)
{
    int
        index,                          /*  Number of index block            */
        section;                        /*  Number of section in index       */
    dbyte
        bit_nbr;                        /*  Number of bit in section         */

    ASSERT (bits);

    locate_bit  (bits, bit, &index, &section, &bit_nbr);
    get_section ((BITS *) bits, index, section, section_data, FALSE);
    if ((section_data [bit_nbr / 8]) & (1 << (bit_nbr % 8)))
        return (1);
    else
        return (0);
}
示例#23
0
文件: setup.c 项目: ampotos/CaH
void	load_section(Elf64_Ehdr *header, char *file, char *section_name, t_section *section_ptr)
{
  Elf64_Half nb_entry;
  
  Elf64_Shdr	*section;
  char	*name;
  
  nb_entry = header->e_shnum;
  for (int i = 0; i < nb_entry; i++)
    {
      section = get_section(header, file, i);
      name = get_string(section->sh_name, header, file);
      if (!strcmp(name, section_name))
	{
	  section_ptr->data = map_section(file, section);
	  section_ptr->size = section->sh_size;
	  break;
	}
    }
}
示例#24
0
int
bits_clear (
    BITS *bits,
    long bit)
{
    int
        index,                          /*  Number of index block            */
        section;                        /*  Number of section in index       */
    dbyte
        bit_nbr;                        /*  Number of bit in section         */

    ASSERT (bits);

    locate_bit  (bits, bit, &index, &section, &bit_nbr);
    get_section (bits, index, section, section_data, TRUE);
    section_data [bit_nbr / 8] &= 255 - (1 << (bit_nbr % 8));
    put_section (bits, index, section, section_data);

    return 0;
}
示例#25
0
文件: jit-elf-write.c 项目: 8l/lllm
/*@
 * @deftypefun int jit_writeelf_add_needed (jit_writeelf_t @var{writeelf}, const char *@var{library_name})
 * Add @var{library_name} to the list of dependent libraries that are needed
 * when the ELF binary is reloaded.  If @var{library_name} is already on
 * the list, then this request will be silently ignored.  Returns
 * zero if out of memory or the parameters are invalid.
 * @end deftypefun
@*/
int jit_writeelf_add_needed(jit_writeelf_t writeelf, const char *library_name)
{
	jit_section_t section;
	Elf_Dyn *dyn;
	unsigned int num_dyn;
	Elf_Word name_index;
	if(!writeelf || !library_name)
	{
		return 0;
	}
	section = get_section(writeelf, ".dynamic", SHT_DYNAMIC,
						  SHF_WRITE | SHF_ALLOC,
						  sizeof(Elf_Dyn), sizeof(Elf_Dyn));
	if(!section)
	{
		return 0;
	}
	dyn = (Elf_Dyn *)(section->data);
	num_dyn = section->data_len / sizeof(Elf_Dyn);
	while(num_dyn > 0)
	{
		if(dyn->d_tag == DT_NEEDED &&
		   !jit_strcmp(get_dyn_string(writeelf, (Elf_Word)(dyn->d_un.d_ptr)),
		   			   library_name))
		{
			return 1;
		}
		++dyn;
		--num_dyn;
	}
	name_index = add_dyn_string(writeelf, library_name);
	if(!name_index)
	{
		return 0;
	}
	if(!add_dyn_info(writeelf, DT_NEEDED, (Elf_Addr)name_index, 0))
	{
		return 0;
	}
	return 1;
}
示例#26
0
static int read_exports(void *image, struct nt_header *nt_hdr, char *dll)
{
	struct section_header *export_section;
	struct export_dir_table *export_dir_table;
	cu32 *export_addr_table;
	int i;
	unsigned int *name_table;

	export_section = get_section(nt_hdr, ".edata");
	if (export_section)
		DBGTRACE1("%s", "found exports section");
	else
		return 0;

	export_dir_table = (struct export_dir_table *)
		(image + export_section->rawdata_addr);
	name_table = (unsigned int *)(image + export_dir_table->name_addr_rva);
	export_addr_table = (cu32 *)
		(image + export_dir_table->export_table_rva);

	for (i = 0; i < export_dir_table->num_name_addr; i++)
	{
		if (nt_hdr->opt_hdr.export_tbl.rva <= *export_addr_table ||
		    *export_addr_table >= (nt_hdr->opt_hdr.export_tbl.rva +
					   nt_hdr->opt_hdr.export_tbl.size))
			DBGTRACE1("%s", "forwarder rva");

		DBGTRACE1("export symbol: %s, at %08X",
		     (char *)(image + *name_table),
		     (unsigned int)(image + *export_addr_table));
		     
		exports[num_exports].dll = dll;
		exports[num_exports].name = (char *)(image + *name_table);
		exports[num_exports].addr = (cu32)(image + *export_addr_table);

		num_exports++;
		name_table++;
		export_addr_table++;
	}
	return 0;
}
示例#27
0
/** \brief
 *
 *  \param ctx
 *  \param fp
 *
 *  \return Number of options set
 */
int iniread_file(configctx_t *ctx, FILE *fp)
{
    char        buffer[LIBINI_LINE_MAX];
    char       *start,*ptr;
    int         ret = 0;
    
    while (fgets(buffer,sizeof(buffer),fp) != NULL ) {
        start = skpws(buffer);
        if ( *start == ';' || *start =='#' || *start ==0)
            continue;
        if ( *start == '[' ) {
            get_section(ctx, start);
        } else {        /* Must be an option! */
            ptr = start;
            while ( isoptionchar(*ptr) )
                ptr++;
            if ( *ptr == '=' ) {
                *ptr++ = 0;
            } else {
                *ptr++ = 0;
                /* Search for the '=' now */
                if ( (ptr = strchr(ptr,'=') ) == NULL ) {
                    continue;
                }
                ptr++;
            }

            ptr = skpws(ptr); /* Skip over any white space */
            if ( *ptr == ';' || *ptr =='#' || *ptr ==0 ) {
                continue;
            }
            if ( strlen(start) ) {
                if ( option_set(ctx, start,ptr) >= 0 ) {
                    ret++;
                }
            }
        }
    }
    return ret;
}
示例#28
0
文件: jit-elf-write.c 项目: 8l/lllm
/*
 * Add an entry to the dynamic linking information section.
 */
static int add_dyn_info
	(jit_writeelf_t writeelf, int type, Elf_Addr value, int modify_existing)
{
	jit_section_t section;
	Elf_Dyn dyn;

	/* Get or create the ".dynamic" section */
	section = get_section(writeelf, ".dynamic", SHT_DYNAMIC,
						  SHF_WRITE | SHF_ALLOC,
						  sizeof(Elf_Dyn), sizeof(Elf_Dyn));
	if(!section)
	{
		return 0;
	}

	/* See if we already have this entry, and modify it as appropriate */
	if(modify_existing)
	{
		Elf_Dyn *existing = (Elf_Dyn *)(section->data);
		unsigned int num = section->data_len / sizeof(Elf_Dyn);
		while(num > 0)
		{
			if(existing->d_tag == type)
			{
				existing->d_un.d_ptr = value;
				return 1;
			}
			++existing;
			--num;
		}
	}

	/* Format the dynamic entry */
	jit_memzero(&dyn, sizeof(dyn));
	dyn.d_tag = type;
	dyn.d_un.d_ptr = value;

	/* Add the entry to the section's contents */
	return add_to_section(section, &dyn, sizeof(dyn));
}
示例#29
0
文件: ft_nm_32.c 项目: gmange/ft_nm
char			get_section_symbol_32(char *ptr, uint32_t n)
{
	uint32_t				i;
	struct load_command		*l_cmd;

	i = 0;
	l_cmd = (struct load_command *)(ptr + sizeof(struct mach_header));
	while (i++ < ((struct mach_header *)ptr)->ncmds)
	{
		if (l_cmd->cmd == LC_SEGMENT)
		{
			if (n > ((struct segment_command *)l_cmd)->nsects)
				n -= ((struct segment_command *)l_cmd)->nsects;
			else
				return (get_section((struct section *)
						((char *)l_cmd + sizeof(struct segment_command)), n,
						sizeof(struct section)));
		}
		l_cmd = (struct load_command *)((char *)l_cmd + l_cmd->cmdsize);
	}
	return ('1');
}
示例#30
0
/******************************************************************************
 *                                                                            *
 ******************************************************************************/
int open_namelist(const char *fname)
{
    int nml = -1;
    FILE *f = fopen(fname, "r");
    NML *fl = NULL;

    if ( f == NULL ) {
        fprintf(stderr, "Could not open \"%s\"\n", fname);
        return -1;
    }

    nml = list_count++;
    file_list = realloc(file_list, sizeof(NML)*list_count);
    fl = &file_list[nml];
    fl->count = 0; fl->section = NULL;

    lineno = 0;
    while ( readline(f, buf) ) {
        if (buf[0] != '&') {
            fprintf(stderr, "Error in file \"%s\"\n", fname);
            fprintf(stderr, "\"%s\"\n",buf);
            list_count--;
            file_list = realloc(file_list, sizeof(NML)*list_count);
            nml = -1;
            break;
        }
        fl->count++;
        fl->section = realloc(fl->section, sizeof(NML_Section)*fl->count);
        get_section(f, &fl->section[fl->count-1], &buf[1]);
    }

    fclose(f);
#if DEBUG_NML
    show_namelist(nml);
    exit(0);
#endif

    return nml;
}