Skip to content

Commit 04a37ef

Browse files
add count
1 parent 111ac17 commit 04a37ef

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

main.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include<stdlib.h>
1111
#include "/usr/include/elf.h"
1212

13-
char buf[10240] = {"00"};
13+
int buf[10240] = { 0xffff };
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);
@@ -62,7 +62,7 @@ int main(int argc,char *argv[])
6262
char *p = (char *)malloc(Section_header.sh_size);
6363
int count = fread(p,sizeof(char),Section_header.sh_size,fp);
6464
int offset =0;
65-
//for(offset=32;p[offset]!=0;offset++);
65+
for(offset=32;p[offset]!=0;offset++);
6666

6767

6868

@@ -192,16 +192,35 @@ void show(FILE *fp,Elf64_Shdr Section_header)
192192
void m_add(FILE *fp,int offset,char *argv[])
193193
{
194194
int i = 0;
195+
int count = 0;
195196
PASSWDINFO m_info;
196197
memset(&m_info,0,sizeof(m_info));
197198
memcpy(&m_info.type,argv[1],strlen(argv[1]));
198199
memcpy(&m_info.name,argv[2],strlen(argv[2]));
199200
memcpy(&m_info.passwd,argv[3],strlen(argv[3]));
200-
201201
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);
202214

203215
fwrite(&m_info,sizeof(m_info),1,fp);
204216
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+
205224
for(i = 0;i<13;i++)
206225
printf("%c",argv[1][i]);
207226
// fwrite(argv[1],strlen(argv[1]),1,fp);

0 commit comments

Comments
 (0)