@@ -14,8 +14,21 @@ char buf[10240] = {"00"};
14
14
void show (FILE * fp ,Elf64_Shdr Section_header );
15
15
void m_add (FILE * fp ,int offset ,char * argv []);
16
16
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
+
17
27
int main (int argc ,char * argv [])
18
28
{
29
+ char * a [3 ];
30
+
31
+ printf ("1 %ld 2 %ld 3 %ld\n" ,strlen (a [1 ]),sizeof (a [2 ]),sizeof (a [3 ]));
19
32
FILE * fp ;
20
33
int i ;
21
34
Elf64_Ehdr elfheader ;
@@ -34,21 +47,22 @@ int main(int argc,char *argv[])
34
47
while (elfheader .e_shnum -- )
35
48
{
36
49
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 );
38
51
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 )
40
54
// size += Section_header.sh_size;
41
55
break ;
42
56
}
43
- // printf("size buf %d %d\n",sizeof(buf),strlen(buf));
57
+ printf ("size buf %d %d\n" ,sizeof (buf ),strlen (buf ));
44
58
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 );
46
60
fseek (fp ,Section_header .sh_offset ,SEEK_SET );
47
61
printf ("read section data\n" );
48
62
char * p = (char * )malloc (Section_header .sh_size );
49
63
int count = fread (p ,sizeof (char ),Section_header .sh_size ,fp );
50
64
int offset = 0 ;
51
- for (offset = 32 ;p [offset ]!= 0 ;offset ++ );
65
+ // for(offset=32;p[offset]!=0;offset++);
52
66
53
67
54
68
@@ -62,7 +76,7 @@ int main(int argc,char *argv[])
62
76
switch (select )
63
77
{
64
78
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 );
66
80
break ;
67
81
case 'd' :
68
82
@@ -76,17 +90,17 @@ int main(int argc,char *argv[])
76
90
77
91
}
78
92
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");
82
96
fclose (fp );
83
97
system ("rm a.out" );
84
98
system ("cp .ab.out a.out" );
85
99
system ("rm .ab.out" );
86
100
return 0 ;
87
101
}
88
102
89
-
103
+ #ifndef STRUCT
90
104
void m_add (FILE * fp ,int offset ,char * argv [])
91
105
{
92
106
fseek (fp ,offset ,SEEK_SET );
@@ -173,3 +187,43 @@ void show(FILE *fp,Elf64_Shdr Section_header)
173
187
}
174
188
175
189
}
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