- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
// find the start and end of the upload file.
static FILE * _uploadGet(request *wp, unsigned int *startPos, unsigned *endPos) {
FILE *fp=NULL;
struct stat statbuf;
unsigned char c, *buf;
if (wp->method == M_POST)
{
fstat(wp->post_data_fd, &statbuf);
lseek(wp->post_data_fd, SEEK_SET, 0);
printf("file size=%d\n",statbuf.st_size);
fp=fopen(wp->post_file_name,"rb");
if(fp==NULL) goto error;
}
else goto error;
//printf("_uploadGet\n");
do
{
if(feof(fp))
{
printf("Cannot find start of file\n");
goto error;
}
c= fgetc(fp);
if (c!=0xd)
continue;
c= fgetc(fp);
if (c!=0xa)
continue;
c= fgetc(fp);
if (c!=0xd)
continue;
c= fgetc(fp);
if (c!=0xa)
continue;
break;
}while(1);
(*startPos)=ftell(fp);
if(fseek(fp,statbuf.st_size-0x200,SEEK_SET)<0)
goto error;
do
{
if(feof(fp))
{
printf("fmmgmt: Cannot find end of file\n");
goto error;
}
c= fgetc(fp);
if (c!=0xd)
continue;
c= fgetc(fp);
if (c!=0xa)
continue;
c= fgetc(fp);
if (c!='-')
continue;
c= fgetc(fp);
if (c!='-')
continue;
break;
}while(1);
(*endPos)=ftell(fp);
return fp;
error:
return NULL;
}
Вот так вот китайцы парсят MIME при загрузке прошивки в роутер.