当前位置: 首页>>代码示例>>C++>>正文


C++ SymbolTable::InternSymbol方法代码示例

本文整理汇总了C++中SymbolTable::InternSymbol方法的典型用法代码示例。如果您正苦于以下问题:C++ SymbolTable::InternSymbol方法的具体用法?C++ SymbolTable::InternSymbol怎么用?C++ SymbolTable::InternSymbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SymbolTable的用法示例。


在下文中一共展示了SymbolTable::InternSymbol方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if


//.........这里部分代码省略.........
    {
        libtable = new LibSymbolTable();
        libtable->table.Initialize();
        libtable->lib_base = dlmap->l_addr;
        libtable->last_pos = 0;
        table = &libtable->table;
        m_SymTables.AddToTail(libtable);
    }

    /* See if the symbol is already cached in our table */
    symbol_entry = table->FindSymbol(symbol, strlen(symbol));
    if (symbol_entry != NULL)
    {
        return symbol_entry->address;
    }

    /* If symbol isn't in our table, then we have open the actual library */
    dlfile = open(dlmap->l_name, O_RDONLY);
    if (dlfile == -1 || fstat(dlfile, &dlstat) == -1)
    {
        close(dlfile);
        return NULL;
    }

    /* Map library file into memory */
    file_hdr = (Elf32_Ehdr *)mmap(NULL, dlstat.st_size, PROT_READ, MAP_PRIVATE, dlfile, 0);
    map_base = (uintptr_t)file_hdr;
    if (file_hdr == MAP_FAILED)
    {
        close(dlfile);
        return NULL;
    }
    close(dlfile);

    if (file_hdr->e_shoff == 0 || file_hdr->e_shstrndx == SHN_UNDEF)
    {
        munmap(file_hdr, dlstat.st_size);
        return NULL;
    }

    sections = (Elf32_Shdr *)(map_base + file_hdr->e_shoff);
    section_count = file_hdr->e_shnum;
    /* Get ELF section header string table */
    shstrtab_hdr = &sections[file_hdr->e_shstrndx];
    shstrtab = (const char *)(map_base + shstrtab_hdr->sh_offset);

    /* Iterate sections while looking for ELF symbol table and string table */
    for (uint16_t i = 0; i < section_count; i++)
    {
        Elf32_Shdr &hdr = sections[i];
        const char *section_name = shstrtab + hdr.sh_name;

        if (strcmp(section_name, ".symtab") == 0)
        {
            symtab_hdr = &hdr;
        }
        else if (strcmp(section_name, ".strtab") == 0)
        {
            strtab_hdr = &hdr;
        }
    }

    /* Uh oh, we don't have a symbol table or a string table */
    if (symtab_hdr == NULL || strtab_hdr == NULL)
    {
        munmap(file_hdr, dlstat.st_size);
        return NULL;
    }

    symtab = (Elf32_Sym *)(map_base + symtab_hdr->sh_offset);
    strtab = (const char *)(map_base + strtab_hdr->sh_offset);
    symbol_count = symtab_hdr->sh_size / symtab_hdr->sh_entsize;

    /* Iterate symbol table starting from the position we were at last time */
    for (uint32_t i = libtable->last_pos; i < symbol_count; i++)
    {
        Elf32_Sym &sym = symtab[i];
        unsigned char sym_type = ELF32_ST_TYPE(sym.st_info);
        const char *sym_name = strtab + sym.st_name;
        Symbol *cur_sym;

        /* Skip symbols that are undefined or do not refer to functions or objects */
        if (sym.st_shndx == SHN_UNDEF || (sym_type != STT_FUNC && sym_type != STT_OBJECT))
        {
            continue;
        }

        /* Caching symbols as we go along */
        cur_sym = table->InternSymbol(sym_name, strlen(sym_name), (void *)(dlmap->l_addr + sym.st_value));
        if (strcmp(symbol, sym_name) == 0)
        {
            symbol_entry = cur_sym;
            libtable->last_pos = ++i;
            break;
        }
    }

    munmap(file_hdr, dlstat.st_size);
    return symbol_entry ? symbol_entry->address : NULL;
}
开发者ID:kila58,项目名称:sourceop,代码行数:101,代码来源:util.cpp

示例2: GetProcAddress


//.........这里部分代码省略.........
		Symbol* cur_sym;

		/* Skip symbols that are undefined or do not refer to functions or objects */
		if (sym.st_shndx == SHN_UNDEF || (sym_type != STT_FUNC && sym_type != STT_OBJECT))
		{
			continue;
		}

		char *name_demangled = NULL;
		int status;
		size_t length = 0;
		name_demangled = abi::__cxa_demangle(sym_name, NULL, &length, &status);

		if (status != 0) {
			continue;
		}

		//META_CONPRINTF("[MASTERHOOK] Checkpoint: 1\n");
		//META_CONPRINTF("[MASTERHOOK] Checkpoint: 1.1 \"%s\"\n", name_demangled);
		//META_CONPRINTF("[MASTERHOOK] Checkpoint: 1.2\n");

		char* brace_open = NULL;
		if (sym_type == STT_FUNC && strrchr(symbol, '(')  == NULL) { // Is Function and passed symbol doesn't have an arglist

			// Let's strip off the arglist as we don't want to compare with that
			brace_open = strrchr(name_demangled, '(');

			if (brace_open != NULL) {
				brace_open[0] = '\0';
			}
		}

		/* Caching symbols as we go along */
		cur_sym = table->InternSymbol(name_demangled, strlen(name_demangled), (void *)(dlmap->l_addr + sym.st_value));
		if (strcmp(name_demangled, symbol) == 0) {

			if (brace_open != NULL) {
				char* brace_close = strrchr(brace_open+1, ')');

				if (brace_close != NULL) {
					brace_close[0] = '\0';
				}

				if (length > strlen(brace_open+1)) {
					brace_close[len] = '\0';
				}
				//META_CONPRINTF("[MASTERHOOK] Checkpoint: 2 \"%s\" d:%d\n", brace_open+1, len);
				memmove(argsBuffer, brace_open+1, len);
				argsBuffer[len] = '\0';
			}

			symbol_entry = cur_sym;
			libtable->last_pos = ++i;
			type = STT_FUNC;
			free(name_demangled);
			break;
		}

		//META_CONPRINTF("[MASTERHOOK] Checkpoint: 3 \"%s\"\n", name_demangled);
		free(name_demangled);
		//META_CONPRINTF("[MASTERHOOK] Checkpoint: 4\n");
	}
#ifdef DEBUG
	//META_CONPRINTF("[MASTERHOOK] Checkpoint: 5 - End of Symbol Table\n");
#endif
开发者ID:bcserv,项目名称:masterhook.ext,代码行数:66,代码来源:symboltable.cpp

示例3: GetProcAddress


//.........这里部分代码省略.........
		}
		else if (strcmp(section_name, ".strtab") == 0)
		{
			strtab_hdr = &hdr;
		}
	}

	/* Uh oh, we don't have a symbol table or a string table */
	if (symtab_hdr == NULL || strtab_hdr == NULL)
	{
		munmap(file_hdr, dlstat.st_size);
		return NULL;
	}

	symtab = (Elf32_Sym *)(map_base + symtab_hdr->sh_offset);
	strtab = (const char *)(map_base + strtab_hdr->sh_offset);
	symbol_count = symtab_hdr->sh_size / symtab_hdr->sh_entsize;

	/* Iterate symbol table starting from the position we were at last time */
	for (uint32_t i = libtable->last_pos; i < symbol_count; i++)
	{
		Elf32_Sym &sym = symtab[i];
		unsigned char sym_type = ELF32_ST_TYPE(sym.st_info);
		const char *sym_name = strtab + sym.st_name;
		Symbol *cur_sym;

		/* Skip symbols that are undefined or do not refer to functions or objects */
		if (sym.st_shndx == SHN_UNDEF || (sym_type != STT_FUNC && sym_type != STT_OBJECT))
		{
			continue;
		}

		/* Caching symbols as we go along */
		cur_sym = table->InternSymbol(sym_name, strlen(sym_name), (void *)(dlmap->l_addr + sym.st_value));
		if (strcmp(symbol, sym_name) == 0)
		{
			symbol_entry = cur_sym;
			libtable->last_pos = ++i;
			break;
		}
	}

	munmap(file_hdr, dlstat.st_size);
	return symbol_entry ? symbol_entry->address : NULL;

#elif defined(__APPLE__)
	
	uintptr_t dlbase, linkedit_addr;
	uint32_t image_count;
	struct mach_header *file_hdr;
	struct load_command *loadcmds;
	struct segment_command *linkedit_hdr;
	struct symtab_command *symtab_hdr;
	struct nlist *symtab;
	const char *strtab;
	uint32_t loadcmd_count;
	uint32_t symbol_count;
	LibSymbolTable *libtable;
	SymbolTable *table;
	Symbol *symbol_entry;
	
	dlbase = 0;
	image_count = m_ImageList->infoArrayCount;
	linkedit_hdr = NULL;
	symtab_hdr = NULL;
	table = NULL;
开发者ID:Arkshine,项目名称:Okapi,代码行数:67,代码来源:MemoryUtils.cpp


注:本文中的SymbolTable::InternSymbol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。