检查打开的文件是不是ELF格式的文件,如果是就输出节头字符串表的地址,并依次输出各节的名称,字符串
来源:互联网 发布:布丁软件官网 编辑:程序博客网 时间:2024/05/20 13:17
#include "elf.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp;
int i = 0;
int fd = 0;
Elf64_Ehdr ehdr;
if ((fp=fopen(argv[1],"r"))==NULL)
{
perror("open");
return -1;
}
else
{
printf("%s\n",argv[1] );
fd=fread(&ehdr,1,sizeof(Elf64_Ehdr),fp);
if (fd==sizeof(Elf64_Ehdr))
{
if (ehdr.e_ident[EI_MAG0] != ELFMAG0 ||
ehdr.e_ident[EI_MAG1] != ELFMAG1 ||
ehdr.e_ident[EI_MAG2] != ELFMAG2 ||
ehdr.e_ident[EI_MAG3] != ELFMAG3) {
perror("the file is not a valid ELF file");
return -1;
}
else{
printf("section header table中表项的数目%ld\n",(long int)ehdr.e_shnum);//节表头数量
}
Elf64_Shdr shdr[ehdr.e_shnum];
fseek(fp,ehdr.e_shoff,0);
for(i=0;i<ehdr.e_shnum;i++)
{
fread(&shdr[i],ehdr.e_shentsize,1,fp);
}
printf("节头字符串表的地址:\n");
fseek(fp,ehdr.e_shoff,0);
fread(shdr,sizeof(Elf64_Shdr),ehdr.e_shnum,fp);//指向节头表
long shstraddr = shdr[ehdr.e_shstrndx].sh_offset;
printf("%p\n",shdr[ehdr.e_shstrndx].sh_offset);//节头字符串表的地址
fseek(fp,shstraddr,0);
char buf[1024] = {0};
fread(buf,1,sizeof(buf),fp);//指向节头字符串表
printf("各节名称字符串:\n");
for(i=0;i<ehdr.e_shnum;i++)
printf("%s\n",&buf[shdr[i].sh_name]);
}
fclose(fp);
}
return 0;
}
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp;
int i = 0;
int fd = 0;
Elf64_Ehdr ehdr;
if ((fp=fopen(argv[1],"r"))==NULL)
{
perror("open");
return -1;
}
else
{
printf("%s\n",argv[1] );
fd=fread(&ehdr,1,sizeof(Elf64_Ehdr),fp);
if (fd==sizeof(Elf64_Ehdr))
{
if (ehdr.e_ident[EI_MAG0] != ELFMAG0 ||
ehdr.e_ident[EI_MAG1] != ELFMAG1 ||
ehdr.e_ident[EI_MAG2] != ELFMAG2 ||
ehdr.e_ident[EI_MAG3] != ELFMAG3) {
perror("the file is not a valid ELF file");
return -1;
}
else{
printf("section header table中表项的数目%ld\n",(long int)ehdr.e_shnum);//节表头数量
}
Elf64_Shdr shdr[ehdr.e_shnum];
fseek(fp,ehdr.e_shoff,0);
for(i=0;i<ehdr.e_shnum;i++)
{
fread(&shdr[i],ehdr.e_shentsize,1,fp);
}
printf("节头字符串表的地址:\n");
fseek(fp,ehdr.e_shoff,0);
fread(shdr,sizeof(Elf64_Shdr),ehdr.e_shnum,fp);//指向节头表
long shstraddr = shdr[ehdr.e_shstrndx].sh_offset;
printf("%p\n",shdr[ehdr.e_shstrndx].sh_offset);//节头字符串表的地址
fseek(fp,shstraddr,0);
char buf[1024] = {0};
fread(buf,1,sizeof(buf),fp);//指向节头字符串表
printf("各节名称字符串:\n");
for(i=0;i<ehdr.e_shnum;i++)
printf("%s\n",&buf[shdr[i].sh_name]);
}
fclose(fp);
}
return 0;
}
0 0
- 检查打开的文件是不是ELF格式的文件,如果是就输出节头字符串表的地址,并依次输出各节的名称,字符串
- 检查打开的文件是不是ELF格式的文件,如果是就输出节头表表項的数目,各表項指向的节的地址
- 检查打开的文件是不是ELF格式的文件,如果是就输出节头表的文件偏移
- 检查打开的文件是不是ELF格式的文件,提取“特别”的节中的信息
- 文件的打开并输出
- 动态生成的字符串输出xml文件并下载
- 格式化字符串的输出格式
- 字符串输出的格式控制
- 如何将xml格式的字符串结合xsl文件转换为html 格式字符串输出
- ELF 文件的格式
- MATLAB中字符串数组的文件输出
- 判断质因数的个数并依次输出
- 编写一个类,其中包含一个排序的方法Sort(),当传入的是一串整数,就按照从小到大的顺序输出,如果传入的是一个字符串,就将字符串反序输出。
- 查找当前目录以下重复的头文件并输出
- 判断两各字符串相等的部分并将其输出(文件输入输出)
- 如果是小写字符就输出对应的大写字符,如果接收的是大写字符,就输出对应的小写字符,如果是数字不输出。
- c语言实现,如果是小写字符就输出对应的大写字符,如果是大写,就输出对应的小写字符,是数字就不输出
- 如何输出字符串指针所指的地址
- 18 Android编译系统
- Visual Studio2010 快捷键 集锦
- MATLAB学习资料合集下载
- Step2-500(刷题计划2)
- org.apache.log4j.Logger详解
- 检查打开的文件是不是ELF格式的文件,如果是就输出节头字符串表的地址,并依次输出各节的名称,字符串
- matlab经典教程分享
- MySQL C++接口封装
- 回话session和cookie的区别
- 检查打开的文件是不是ELF格式的文件,提取“特别”的节中的信息
- Android探秘:SimpleAdapter与Bitmap的结合
- int* (*a)[10]
- MATLAB中常用到的绘图函数
- Objective-C语法快速参考