⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ffs.c

📁 linux下开发的针对所有磁盘的数据恢复的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
                tsk_fprintf(print->hFile, "%" PRIuDADDR " ", addr + i);            else                tsk_fprintf(print->hFile, "0 ");            if (++(print->idx) == 8) {                tsk_fprintf(print->hFile, "\n");                print->idx = 0;            }        }    }    return TSK_WALK_CONT;}/** * Print details on a specific file to a file handle.  * * @param fs File system file is located in * @param hFile File handle to print text to * @param inum Address of file in file system * @param numblock The number of blocks in file to force print (can go beyond file size) * @param sec_skew Clock skew in seconds to also print times in *  * @returns 1 on error and 0 on success */static uint8_tffs_istat(TSK_FS_INFO * fs, FILE * hFile, TSK_INUM_T inum,    TSK_DADDR_T numblock, int32_t sec_skew){    FFS_INFO *ffs = (FFS_INFO *) fs;    TSK_FS_META *fs_meta;    TSK_FS_FILE *fs_file;    char ls[12];    FFS_PRINT_ADDR print;    // clean up any error messages that are lying around    tsk_error_reset();    if ((fs_file = tsk_fs_file_open_meta(fs, NULL, inum)) == NULL) {        return 1;    }    fs_meta = fs_file->meta;    tsk_fprintf(hFile, "inode: %" PRIuINUM "\n", inum);    tsk_fprintf(hFile, "%sAllocated\n",        (fs_meta->flags & TSK_FS_META_FLAG_ALLOC) ? "" : "Not ");    tsk_fprintf(hFile, "Group: %" PRI_FFSGRP "\n", ffs->grp_num);    if (fs_meta->link)        tsk_fprintf(hFile, "symbolic link to: %s\n", fs_meta->link);    tsk_fprintf(hFile, "uid / gid: %" PRIuUID " / %" PRIuGID "\n",        fs_meta->uid, fs_meta->gid);    tsk_fs_make_ls(fs_meta, ls);    tsk_fprintf(hFile, "mode: %s\n", ls);    tsk_fprintf(hFile, "size: %" PRIuOFF "\n", fs_meta->size);    tsk_fprintf(hFile, "num of links: %u\n", fs_meta->nlink);    if (sec_skew != 0) {        tsk_fprintf(hFile, "\nAdjusted Inode Times:\n");        fs_meta->mtime -= sec_skew;        fs_meta->atime -= sec_skew;        fs_meta->ctime -= sec_skew;        tsk_fprintf(hFile, "Accessed:\t%s", ctime(&fs_meta->atime));        tsk_fprintf(hFile, "File Modified:\t%s", ctime(&fs_meta->mtime));        tsk_fprintf(hFile, "Inode Modified:\t%s", ctime(&fs_meta->ctime));        fs_meta->mtime += sec_skew;        fs_meta->atime += sec_skew;        fs_meta->ctime += sec_skew;        tsk_fprintf(hFile, "\nOriginal Inode Times:\n");    }    else {        tsk_fprintf(hFile, "\nInode Times:\n");    }    tsk_fprintf(hFile, "Accessed:\t%s", ctime(&fs_meta->atime));    tsk_fprintf(hFile, "File Modified:\t%s", ctime(&fs_meta->mtime));    tsk_fprintf(hFile, "Inode Modified:\t%s", ctime(&fs_meta->ctime));    if (fs->ftype == TSK_FS_TYPE_FFS2) {        ffs_inode2 *in = (ffs_inode2 *) ffs->dino_buf;        /* Are there extended attributes */        if (tsk_getu32(fs->endian, in->di_extsize) > 0) {            ffs_extattr *ea;            uint32_t size;            char name[257];            char *blk_buf;            if ((blk_buf = tsk_malloc(ffs->ffsbsize_b)) == NULL) {                tsk_fs_file_close(fs_file);                return 1;            }            size = tsk_getu32(fs->endian, in->di_extsize);            tsk_fprintf(hFile, "\nExtended Attributes:\n");            tsk_fprintf(hFile,                "Size: %" PRIu32 " (%" PRIu64 ", %" PRIu64 ")\n", size,                tsk_getu64(fs->endian, in->di_extb[0]),                tsk_getu64(fs->endian, in->di_extb[1]));            /* Process first block */            // @@@ Incorporate values into this as well            if ((tsk_getu64(fs->endian, in->di_extb[0]) >= fs->first_block)                && (tsk_getu64(fs->endian,                        in->di_extb[0]) <= fs->last_block)) {                uintptr_t end;                ssize_t cnt;                cnt =                    tsk_fs_read_block(fs, tsk_getu64(fs->endian,                        in->di_extb[0]), blk_buf, ffs->ffsbsize_b);                if (cnt != ffs->ffsbsize_b) {                    if (cnt >= 0) {                        tsk_error_reset();                        tsk_errno = TSK_ERR_FS_READ;                    }                    snprintf(tsk_errstr2, TSK_ERRSTR_L,                        "ffs_istat: FFS2 extended attribute 0 at %"                        PRIu64, tsk_getu64(fs->endian, in->di_extb[0]));                    tsk_fs_file_close(fs_file);                    free(blk_buf);                    return 1;                }                ea = (ffs_extattr *) blk_buf;                if (size > ffs->ffsbsize_b) {                    end = (uintptr_t) ea + ffs->ffsbsize_b;                    size -= ffs->ffsbsize_b;                }                else {                    end = (uintptr_t) ea + size;                    size = 0;                }                for (; (uintptr_t) ea < end;                    ea =                    (ffs_extattr *) ((uintptr_t) ea +                        tsk_getu32(fs->endian, ea->reclen))) {                    memcpy(name, ea->name, ea->nlen);                    name[ea->nlen] = '\0';                    tsk_fprintf(hFile, "%s\n", name);                }            }            if ((tsk_getu64(fs->endian, in->di_extb[1]) >= fs->first_block)                && (tsk_getu64(fs->endian,                        in->di_extb[1]) <= fs->last_block)) {                uintptr_t end;                ssize_t cnt;                cnt =                    tsk_fs_read_block(fs, tsk_getu64(fs->endian,                        in->di_extb[1]), blk_buf, ffs->ffsbsize_b);                if (cnt != ffs->ffsbsize_b) {                    if (cnt >= 0) {                        tsk_error_reset();                        tsk_errno = TSK_ERR_FS_INODE_COR;                    }                    snprintf(tsk_errstr2, TSK_ERRSTR_L,                        "ffs_istat: FFS2 extended attribute 1 at %"                        PRIu64, tsk_getu64(fs->endian, in->di_extb[1]));                    tsk_fs_file_close(fs_file);                    free(blk_buf);                    return 1;                }                ea = (ffs_extattr *) blk_buf;                if (size > ffs->ffsbsize_b)                    end = (uintptr_t) ea + ffs->ffsbsize_b;                else                    end = (uintptr_t) ea + size;                for (; (uintptr_t) ea < end;                    ea =                    (ffs_extattr *) ((uintptr_t) ea +                        tsk_getu32(fs->endian, ea->reclen))) {                    memcpy(name, ea->name, ea->nlen);                    name[ea->nlen] = '\0';                    tsk_fprintf(hFile, "%s\n", name);                }            }            free(blk_buf);        }    }    /* A bad hack to force a specified number of blocks */    if (numblock > 0)        fs_meta->size = numblock * ffs->ffsbsize_b;    tsk_fprintf(hFile, "\nDirect Blocks:\n");    print.idx = 0;    print.hFile = hFile;    if (tsk_fs_file_walk(fs_file, TSK_FS_FILE_WALK_FLAG_AONLY,            print_addr_act, (void *) &print)) {        tsk_fprintf(hFile, "\nError reading blocks in file\n");        tsk_error_print(hFile);        tsk_fs_file_close(fs_file);        return 1;    }    if (print.idx != 0)        tsk_fprintf(hFile, "\n");    tsk_fs_file_close(fs_file);    return 0;}/* Return 1 on error and 0 on success */uint8_tffs_jopen(TSK_FS_INFO * fs, TSK_INUM_T inum){    tsk_error_reset();    tsk_errno = TSK_ERR_FS_UNSUPFUNC;    snprintf(tsk_errstr, TSK_ERRSTR_L, "UFS does not have a journal");    return 1;}uint8_tffs_jentry_walk(TSK_FS_INFO * fs, int a_flags,    TSK_FS_JENTRY_WALK_CB action, void *ptr){    tsk_error_reset();    tsk_errno = TSK_ERR_FS_UNSUPFUNC;    snprintf(tsk_errstr, TSK_ERRSTR_L, "UFS does not have a journal");    return 1;}uint8_tffs_jblk_walk(TSK_FS_INFO * fs, TSK_DADDR_T start, TSK_DADDR_T end,    int a_flags, TSK_FS_JBLK_WALK_CB action, void *ptr){    tsk_error_reset();    tsk_errno = TSK_ERR_FS_UNSUPFUNC;    snprintf(tsk_errstr, TSK_ERRSTR_L, "UFS does not have a journal");    return 1;}/* ffs_close - close a fast file system */static voidffs_close(TSK_FS_INFO * fs){    FFS_INFO *ffs = (FFS_INFO *) fs;    fs->tag = 0;    if (ffs->grp_buf)        free(ffs->grp_buf);    if (ffs->itbl_buf)        free(ffs->itbl_buf);    if (ffs->dino_buf)        free(ffs->dino_buf);    if (fs->list_inum_named) {        tsk_list_free(fs->list_inum_named);        fs->list_inum_named = NULL;    }    free((char *) ffs->fs.sb1);    free(ffs);}/** * \internal * Open part of a disk image as a FFS/UFS file system.  * * @param img_info Disk image to analyze * @param offset Byte offset where file system starts * @param ftype Specific type of file system * @returns NULL on error or if data is not a FFS file system */TSK_FS_INFO *ffs_open(TSK_IMG_INFO * img_info, TSK_OFF_T offset, TSK_FS_TYPE_ENUM ftype){    char *myname = "ffs_open";    FFS_INFO *ffs;    unsigned int len;    TSK_FS_INFO *fs;    ssize_t cnt;    // clean up any error messages that are lying around    tsk_error_reset();    if (TSK_FS_TYPE_ISFFS(ftype) == 0) {        tsk_error_reset();        tsk_errno = TSK_ERR_FS_ARG;        snprintf(tsk_errstr, TSK_ERRSTR_L, "Invalid FS Type in ffs_open");        return NULL;    }    if ((ffs = (FFS_INFO *) tsk_malloc(sizeof(*ffs))) == NULL)        return NULL;    fs = &(ffs->fs_info);    fs->ftype = ftype;    fs->flags = 0;    fs->duname = "Fragment";    fs->tag = TSK_FS_INFO_TAG;    fs->img_info = img_info;    fs->offset = offset;    /* Both sbs are the same size */    len = roundup(sizeof(ffs_sb1), FFS_DEV_BSIZE);    ffs->fs.sb1 = (ffs_sb1 *) tsk_malloc(len);    if (ffs->fs.sb1 == NULL) {        fs->tag = 0;        free(ffs);        return NULL;    }    /* check the magic and figure out the endian ordering */    /* Try UFS2 first - I read somewhere that some upgrades     * kept the original UFS1 superblock in addition to      * the new one */    cnt = tsk_fs_read        (fs, (TSK_OFF_T) UFS2_SBOFF, (char *) ffs->fs.sb2,        sizeof(ffs_sb2));    if (cnt != sizeof(ffs_sb2)) {        if (cnt >= 0) {            tsk_error_reset();            tsk_errno = TSK_ERR_FS_READ;        }        snprintf(tsk_errstr, TSK_ERRSTR_L,            "%s: Superblock at %" PRIuDADDR, myname,            (TSK_OFF_T) UFS2_SBOFF);        fs->tag = 0;        free(ffs->fs.sb1);        free(ffs);        return NULL;    }    /* If that didn't work, try the 256KB UFS2 location */    if (tsk_fs_guessu32(fs, ffs->fs.sb2->magic, UFS2_FS_MAGIC)) {        cnt = tsk_fs_read            (fs, (TSK_OFF_T) UFS2_SBOFF2, (char *) ffs->fs.sb2,            sizeof(ffs_sb2));        if (cnt != sizeof(ffs_sb2)) {            if (cnt >= 0) {                tsk_error_reset();                tsk_errno = TSK_ERR_FS_READ;            }            snprintf(tsk_errstr2, TSK_ERRSTR_L,                "%s: Superblock at %" PRIuDADDR,                myname, (TSK_OFF_T) UFS2_SBOFF2);            fs->tag = 0;            free(ffs->fs.sb1);            free(ffs);            return NULL;        }        /* Try UFS1 if that did not work */        if (tsk_fs_guessu32(fs, ffs->fs.sb2->magic, UFS2_FS_MAGIC)) {            cnt = tsk_fs_read                (fs, (TSK_OFF_T) UFS1_SBOFF, (char *) ffs->fs.sb1, len);            if (cnt != len) {                if (cnt >= 0) {                    tsk_error_reset();                    tsk_errno = TSK_ERR_FS_READ;                }                snprintf(tsk_errstr2, TSK_ERRSTR_L,                    "%s: Superblock at %" PRIuDADDR,                    myname, (TSK_OFF_T) UFS1_SBOFF);                fs->tag = 0;                free(ffs->fs.sb1);                free(ffs);                return NULL;            }            if (tsk_fs_guessu32(fs, ffs->fs.sb1->magic, UFS1_FS_MAGIC)) {                fs->tag = 0;                free(ffs->fs.sb1);                free(ffs);                tsk_error_reset();                tsk_errno = TSK_ERR_FS_MAGIC;                snprintf(tsk_errstr, TSK_ERRSTR_L, "No UFS Magic Found");                return NULL;            }            else {                // @@@ NEED T

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -