Subversion Repositories DevTools

Rev

Rev 227 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 227 Rev 4806
Line 3574... Line 3574...
3574
    return EXETYPE_UNIX_NATIVE;
3574
    return EXETYPE_UNIX_NATIVE;
3575
#else
3575
#else
3576
    int                 fd;
3576
    int                 fd;
3577
    unsigned long       res;
3577
    unsigned long       res;
3578
    size_t              len;
3578
    size_t              len;
3579
 
-
 
3580
    if (pathname == NULL)
3579
    if (pathname == NULL)
3581
        res = EXETYPE_BAD_FILE;
3580
        res = EXETYPE_BAD_FILE;
3582
    
3581
    
3583
/* Open the file */
3582
/* Open the file */
3584
 
3583
 
Line 3617... Line 3616...
3617
    struct stat                 fstatus;
3616
    struct stat                 fstatus;
3618
 
3617
 
3619
    if ((read (fd, &OS_Headers, sizeof (struct ExecDosHeader)) !=
3618
    if ((read (fd, &OS_Headers, sizeof (struct ExecDosHeader)) !=
3620
                sizeof (struct ExecDosHeader)) ||
3619
                sizeof (struct ExecDosHeader)) ||
3621
        (OS_Headers.DosHead.e_magic != SIG_DOS))
3620
        (OS_Headers.DosHead.e_magic != SIG_DOS))
-
 
3621
    {
3622
        return EXETYPE_UNKNOWN;
3622
        return EXETYPE_UNKNOWN;
-
 
3623
    }
3623
    
3624
    
3624
/*
3625
/*
3625
 * If the header size in the header is not a new header or the relocation
3626
 * If the header size in the header is not a new header or the relocation
3626
 * section starts before the end of the new header, it must be a DOS program
3627
 * section starts before the end of the new header, it must be a DOS program
3627
 */
3628
 */
3628
 
3629
 
3629
    if ((OS_Headers.DosHead.e_cparhdr * 16 < sizeof (struct ExecDosHeader)) ||
3630
    if ((OS_Headers.DosHead.e_cparhdr * 16 < sizeof (struct ExecDosHeader)) ||
3630
        (OS_Headers.DosHead.e_lfarlc < sizeof (struct ExecDosHeader)))
3631
        (OS_Headers.DosHead.e_lfarlc < sizeof (struct ExecDosHeader)))
-
 
3632
    {
3631
        return EXETYPE_DOS_CUI;
3633
        return EXETYPE_DOS_CUI;
-
 
3634
    }
3632
    
3635
    
3633
    if ((fstat (fd, &fstatus) == -1) ||
3636
    if ((fstat (fd, &fstatus) == -1) ||
3634
        (fstatus.st_size < (off_t) OS_Headers.DosHead.e_lfanew))
3637
        (fstatus.st_size < (off_t) OS_Headers.DosHead.e_lfanew))
-
 
3638
    {
3635
        return EXETYPE_DOS_CUI;
3639
        return EXETYPE_DOS_CUI;
-
 
3640
    }
3636
 
3641
 
3637
    if ((lseek (fd, (off_t) OS_Headers.DosHead.e_lfanew, SEEK_SET) ==
3642
    if ((lseek (fd, (off_t) OS_Headers.DosHead.e_lfanew, SEEK_SET) ==
3638
                (off_t) -1) ||
3643
                (off_t) -1) ||
3639
        (read (fd, &OS_Headers, sizeof (OS_Headers)) != sizeof (OS_Headers)))
3644
        (read (fd, &OS_Headers, sizeof (OS_Headers)) != sizeof (OS_Headers)))
-
 
3645
    {
3640
        return EXETYPE_BAD_IMAGE;
3646
        return EXETYPE_BAD_IMAGE;
-
 
3647
    }
3641
    
3648
    
3642
/* NT */
3649
/* NT */
3643
 
-
 
3644
    if (OS_Headers.NTHead.Signature == SIG_NT)
3650
    if (OS_Headers.NTHead.Signature == SIG_NT)
3645
    {
3651
    {
3646
        if (OS_Headers.NTHead.FileHeader.SizeOfOptionalHeader !=
3652
        // Note: X64 OptionalHeaderSize is longer
3647
            NT_OPTIONAL_HEADER)
3653
        if (OS_Headers.NTHead.FileHeader.SizeOfOptionalHeader < NT_OPTIONAL_HEADER)
3648
            return EXETYPE_UNKNOWN;
3654
            return EXETYPE_UNKNOWN;
3649
 
3655
 
3650
        switch (OS_Headers.NTHead.OptionalHeader.Subsystem)
3656
        switch (OS_Headers.NTHead.OptionalHeader.Subsystem)
3651
        {
3657
        {
3652
            default:
3658
            default: