Skip to content

Commit 111ac17

Browse files
add a new way to save the passwd(using struct)
1 parent 83c5800 commit 111ac17

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

a.out

-384 Bytes
Binary file not shown.

main.c

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ char buf[10240] = {"00"};
1414
void show(FILE *fp,Elf64_Shdr Section_header);
1515
void m_add(FILE *fp,int offset,char *argv[]);
1616
void m_delete(FILE *fp,int offset,char *key,Elf64_Shdr Section_header);
17+
18+
typedef struct passinfo{
19+
char type[20];
20+
char name[20];
21+
char passwd[30];
22+
}PASSWDINFO;
23+
24+
25+
#define STRUCT
26+
1727
int main(int argc,char *argv[])
1828
{
29+
char *a[3];
30+
31+
printf("1 %ld 2 %ld 3 %ld\n",strlen(a[1]),sizeof(a[2]),sizeof(a[3]));
1932
FILE * fp;
2033
int i;
2134
Elf64_Ehdr elfheader;
@@ -34,21 +47,22 @@ int main(int argc,char *argv[])
3447
while(elfheader.e_shnum--)
3548
{
3649
fread(&Section_header,sizeof(Elf64_Shdr),1,fp);
37-
// printf("read sh_type %lu offset %lx size %lx sh_entsize %lx sh_addralign %lx\n",Section_header.sh_type,Section_header.sh_offset,Section_header.sh_size,Section_header.sh_entsize,Section_header.sh_addralign);
50+
printf("read sh_type %lu offset %lx size %lx sh_entsize %lx sh_addralign %lx Section_header.sh_name %lx\n",Section_header.sh_type,Section_header.sh_offset,Section_header.sh_size,Section_header.sh_entsize,Section_header.sh_addralign,Section_header.sh_name);
3851

39-
if(Section_header.sh_type == 1 && Section_header.sh_name == 0xf8)
52+
// if(Section_header.sh_type == 1 && Section_header.sh_name == 0xf8)
53+
if(Section_header.sh_type == 1 && Section_header.sh_name == 0xea)
4054
// size += Section_header.sh_size;
4155
break;
4256
}
43-
// printf("size buf %d %d\n",sizeof(buf),strlen(buf));
57+
printf("size buf %d %d\n",sizeof(buf),strlen(buf));
4458

45-
// printf("read section data offset %lx size %lx sh_entsize %lx sh_addralign %lx\n",Section_header.sh_offset,Section_header.sh_size,Section_header.sh_entsize,Section_header.sh_addralign);
59+
printf("read section data offset %lx size %lx sh_entsize %lx sh_addralign %lx\n",Section_header.sh_offset,Section_header.sh_size,Section_header.sh_entsize,Section_header.sh_addralign);
4660
fseek(fp,Section_header.sh_offset,SEEK_SET);
4761
printf("read section data\n");
4862
char *p = (char *)malloc(Section_header.sh_size);
4963
int count = fread(p,sizeof(char),Section_header.sh_size,fp);
5064
int offset =0;
51-
for(offset=32;p[offset]!=0;offset++);
65+
//for(offset=32;p[offset]!=0;offset++);
5266

5367

5468

@@ -62,7 +76,7 @@ int main(int argc,char *argv[])
6276
switch(select)
6377
{
6478
case 'a':
65-
m_add(fp,Section_header.sh_offset + offset,argv);
79+
m_add(fp,Section_header.sh_offset + Section_header.sh_addralign,argv);
6680
break;
6781
case 'd':
6882

@@ -76,17 +90,17 @@ int main(int argc,char *argv[])
7690

7791
}
7892

79-
for(i=0;i<Section_header.sh_size;i++)
80-
printf("%c",p[i]);
81-
printf("\n");
93+
// for(i=0;i<Section_header.sh_size;i++)
94+
// printf("%c",p[i]);
95+
// printf("\n");
8296
fclose(fp);
8397
system("rm a.out");
8498
system("cp .ab.out a.out");
8599
system("rm .ab.out");
86100
return 0;
87101
}
88102

89-
103+
#ifndef STRUCT
90104
void m_add(FILE *fp,int offset,char *argv[])
91105
{
92106
fseek(fp,offset,SEEK_SET);
@@ -173,3 +187,43 @@ void show(FILE *fp,Elf64_Shdr Section_header)
173187
}
174188

175189
}
190+
#else
191+
192+
void m_add(FILE *fp,int offset,char *argv[])
193+
{
194+
int i = 0;
195+
PASSWDINFO m_info;
196+
memset(&m_info,0,sizeof(m_info));
197+
memcpy(&m_info.type,argv[1],strlen(argv[1]));
198+
memcpy(&m_info.name,argv[2],strlen(argv[2]));
199+
memcpy(&m_info.passwd,argv[3],strlen(argv[3]));
200+
201+
fseek(fp,offset,SEEK_SET);
202+
203+
fwrite(&m_info,sizeof(m_info),1,fp);
204+
printf("1 %ld 2 %ld 3 %ld\n",strlen(argv[1]),strlen(argv[2]),strlen(argv[3]));
205+
for(i = 0;i<13;i++)
206+
printf("%c",argv[1][i]);
207+
// fwrite(argv[1],strlen(argv[1]),1,fp);
208+
209+
}
210+
211+
void m_delete(FILE *fp,int offset,char *key,Elf64_Shdr Section_header)
212+
{
213+
214+
215+
216+
}
217+
218+
219+
void show(FILE *fp,Elf64_Shdr Section_header)
220+
{
221+
PASSWDINFO m_info;
222+
fseek(fp,Section_header.sh_offset + Section_header.sh_addralign,SEEK_SET);
223+
fread(&m_info,sizeof(m_info),1,fp);
224+
225+
printf("m_info.type %s m_info.name %s m_info.passwd %s \n",m_info.type,m_info.name,m_info.passwd);
226+
227+
}
228+
229+
#endif

0 commit comments

Comments
 (0)