|
10 | 10 | #include<stdlib.h>
|
11 | 11 | #include "/usr/include/elf.h"
|
12 | 12 |
|
13 |
| -char buf[10240] = {"00"}; |
| 13 | +int buf[10240] = { 0xffff }; |
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);
|
@@ -62,7 +62,7 @@ int main(int argc,char *argv[])
|
62 | 62 | char *p = (char *)malloc(Section_header.sh_size);
|
63 | 63 | int count = fread(p,sizeof(char),Section_header.sh_size,fp);
|
64 | 64 | int offset =0;
|
65 |
| - //for(offset=32;p[offset]!=0;offset++); |
| 65 | + for(offset=32;p[offset]!=0;offset++); |
66 | 66 |
|
67 | 67 |
|
68 | 68 |
|
@@ -192,16 +192,35 @@ void show(FILE *fp,Elf64_Shdr Section_header)
|
192 | 192 | void m_add(FILE *fp,int offset,char *argv[])
|
193 | 193 | {
|
194 | 194 | int i = 0;
|
| 195 | + int count = 0; |
195 | 196 | PASSWDINFO m_info;
|
196 | 197 | memset(&m_info,0,sizeof(m_info));
|
197 | 198 | memcpy(&m_info.type,argv[1],strlen(argv[1]));
|
198 | 199 | memcpy(&m_info.name,argv[2],strlen(argv[2]));
|
199 | 200 | memcpy(&m_info.passwd,argv[3],strlen(argv[3]));
|
200 |
| - |
201 | 201 | fseek(fp,offset,SEEK_SET);
|
| 202 | + fread(&count,sizeof(count),1,fp); |
| 203 | + if(count == 0xffff) |
| 204 | + { |
| 205 | + count = 0; |
| 206 | + fseek(fp,offset,SEEK_SET); |
| 207 | + fwrite(&count,sizeof(count),1,fp); |
| 208 | + } |
| 209 | + printf("count %d \n",count); |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | + fseek(fp,offset + 4 + count * sizeof(m_info),SEEK_SET); |
202 | 214 |
|
203 | 215 | fwrite(&m_info,sizeof(m_info),1,fp);
|
204 | 216 | printf("1 %ld 2 %ld 3 %ld\n",strlen(argv[1]),strlen(argv[2]),strlen(argv[3]));
|
| 217 | + count ++; |
| 218 | + fseek(fp,offset,SEEK_SET); |
| 219 | + fwrite(&count,sizeof(count),1,fp); |
| 220 | + fseek(fp,offset,SEEK_SET); |
| 221 | + fread(&count,sizeof(count),1,fp); |
| 222 | + printf("count %d \n",count); |
| 223 | + |
205 | 224 | for(i = 0;i<13;i++)
|
206 | 225 | printf("%c",argv[1][i]);
|
207 | 226 | // fwrite(argv[1],strlen(argv[1]),1,fp);
|
|
0 commit comments