当我在我的-s可执行文件中使用标志调用readelf时,我得到:
Num: Value Size Type Bind Vis Ndx Name
43: 00000000004004e7 30 FUNC GLOBAL DEFAULT 13 find_me_func但是,当我在索引43处读取符号表条目时,我有:
st_name: 259
st_info: 18 '\022'
st_other: 0 '\0000'
st_shndx: 13
st_value: 4195559
st_size: 30我的问题是如何使用我必须获得的信息:00000000004004e7?我想这和st_value有某种关系
注意:也许这些宏可以帮上忙?
/*
* Dynamic structure. The ".dynamic" section contains an array of them.
*/
typedef struct {
Elf64_Sxword d_tag; /* Entry type. */
union {
Elf64_Xword d_val; /* Integer value. */
Elf64_Addr d_ptr; /* Address value. */
} d_un;
} Elf64_Dyn;
/*
* Relocation entries.
*/
/* Relocations that don't need an addend field. */
typedef struct {
Elf64_Addr r_offset; /* Location to be relocated. */
Elf64_Xword r_info; /* Relocation type and symbol index. */
} Elf64_Rel;
/* Relocations that need an addend field. */
typedef struct {
Elf64_Addr r_offset; /* Location to be relocated. */
Elf64_Xword r_info; /* Relocation type and symbol index. */
Elf64_Sxword r_addend; /* Addend. */
} Elf64_Rela;
/* Macros for accessing the fields of r_info. */
#define ELF64_R_SYM(info) ((info) >> 32)
#define ELF64_R_TYPE(info) ((info) & 0xffffffffL)
/* Macro for constructing r_info from field values. */
#define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type) & 0xffffffffL))
#define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info)<<32)>>40)
#define ELF64_R_TYPE_ID(info) (((Elf64_Xword)(info)<<56)>>56)
#define ELF64_R_TYPE_INFO(data, type) \
(((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type))发布于 2021-06-21 19:15:09
00000000004004e7是4195559的十六进制表示形式,它是您的st_value。
可以使用%x和printf()以十六进制格式打印值。添加数字,如%016x,以指定数字的数字。
#include <stdio.h>
int main(void) {
int st_value = 4195559;
printf("%016x\n", st_value);
return 0;
}或者如果您想要64位值:
#include <stdio.h>
#include <inttypes.h>
int main(void) {
uint64_t st_value = UINT64_C(4195559);
printf("%016" PRIx64 "\n", st_value);
return 0;
}https://stackoverflow.com/questions/68073447
复制相似问题