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

📄 iso9660.c

📁 linux下开发的针对所有磁盘的数据恢复的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    tsk_fprintf(hFile, "Mode: ");    memset(mode_buf, '-', 11);    mode_buf[10] = '\0';    /* file type */    /* note: socket and symbolic link are multi bit fields */    if ((rr->mode & MODE_IFSOCK) == MODE_IFSOCK)        mode_buf[0] = 's';    else if ((rr->mode & MODE_IFLNK) == MODE_IFLNK)        mode_buf[0] = 'l';    else if (rr->mode & MODE_IFDIR)        mode_buf[0] = 'd';    else if (rr->mode & MODE_IFIFO)        mode_buf[0] = 'p';    else if (rr->mode & MODE_IFBLK)        mode_buf[0] = 'b';    else if (rr->mode & MODE_IFCHR)        mode_buf[0] = 'c';    /* owner permissions */    if (rr->mode & TSK_FS_META_MODE_IRUSR)        mode_buf[1] = 'r';    if (rr->mode & TSK_FS_META_MODE_IWUSR)        mode_buf[2] = 'w';    if ((rr->mode & TSK_FS_META_MODE_IXUSR)        && (rr->mode & TSK_FS_META_MODE_ISUID))        mode_buf[3] = 's';    else if (rr->mode & TSK_FS_META_MODE_IXUSR)        mode_buf[3] = 'x';    else if (rr->mode & TSK_FS_META_MODE_ISUID)        mode_buf[3] = 'S';    /* group permissions */    if (rr->mode & TSK_FS_META_MODE_IRGRP)        mode_buf[4] = 'r';    if (rr->mode & TSK_FS_META_MODE_IWGRP)        mode_buf[5] = 'w';    if ((rr->mode & TSK_FS_META_MODE_IXGRP)        && (rr->mode & TSK_FS_META_MODE_ISGID))        mode_buf[6] = 's';    else if (rr->mode & TSK_FS_META_MODE_IXGRP)        mode_buf[6] = 'x';    else if (rr->mode & TSK_FS_META_MODE_ISGID)        mode_buf[6] = 'S';    /* other permissions */    if (rr->mode & TSK_FS_META_MODE_IROTH)        mode_buf[7] = 'r';    if (rr->mode & TSK_FS_META_MODE_IWOTH)        mode_buf[8] = 'w';    if ((rr->mode & TSK_FS_META_MODE_IXOTH)        && (rr->mode & TSK_FS_META_MODE_ISVTX))        mode_buf[9] = 't';    else if (rr->mode & TSK_FS_META_MODE_IXOTH)        mode_buf[9] = 'x';    else if (rr->mode & TSK_FS_META_MODE_ISVTX)        mode_buf[9] = 'T';    tsk_fprintf(hFile, "%s\n", mode_buf);    tsk_fprintf(hFile, "Number links: %" PRIu32 "\n", rr->nlink);    tsk_fprintf(hFile, "Alternate name: %s\n", rr->fn);    tsk_fprintf(hFile, "\n");}#endif/** * 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_tiso9660_istat(TSK_FS_INFO * fs, FILE * hFile, TSK_INUM_T inum,    TSK_DADDR_T numblock, int32_t sec_skew){    ISO_INFO *iso = (ISO_INFO *) fs;    TSK_FS_FILE *fs_file;    iso9660_dentry dd;    // 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;    tsk_fprintf(hFile, "Entry: %" PRIuINUM "\n", inum);    if (iso9660_dinode_load(iso, inum)) {        snprintf(tsk_errstr2, TSK_ERRSTR_L, "iso9660_istat");        tsk_fs_file_close(fs_file);        return 1;    }    memcpy(&dd, &iso->dinode->dr, sizeof(iso9660_dentry));    tsk_fprintf(hFile, "Type: ");    if (dd.flags & ISO9660_FLAG_DIR)        tsk_fprintf(hFile, "Directory\n");    else        tsk_fprintf(hFile, "File\n");    tsk_fprintf(hFile, "Links: %d\n", fs_file->meta->nlink);    if (dd.gap_sz > 0) {        tsk_fprintf(hFile, "Interleave Gap Size: %d\n", dd.gap_sz);        tsk_fprintf(hFile, "Interleave File Unit Size: %d\n", dd.unit_sz);    }    tsk_fprintf(hFile, "Flags: ");    if (dd.flags & ISO9660_FLAG_HIDE)        tsk_fprintf(hFile, "Hidden, ");    if (dd.flags & ISO9660_FLAG_ASSOC)        tsk_fprintf(hFile, "Associated, ");    if (dd.flags & ISO9660_FLAG_RECORD)        tsk_fprintf(hFile, "Record Format, ");    if (dd.flags & ISO9660_FLAG_PROT)        tsk_fprintf(hFile, "Protected,  ");    /* check if reserved bits are set, be suspicious */    if (dd.flags & ISO9660_FLAG_RES1)        tsk_fprintf(hFile, "Reserved1, ");    if (dd.flags & ISO9660_FLAG_RES2)        tsk_fprintf(hFile, "Reserved2, ");    if (dd.flags & ISO9660_FLAG_MULT)        tsk_fprintf(hFile, "Non-final multi-extent entry");    putchar('\n');    tsk_fprintf(hFile, "Name: %s\n", iso->dinode->fn);    tsk_fprintf(hFile, "Size: %" PRIu32 "\n", tsk_getu32(fs->endian,            iso->dinode->dr.data_len_m));    if (iso->dinode->ea) {        tsk_fprintf(hFile, "\nEXTENDED ATTRIBUTE INFO\n");        tsk_fprintf(hFile, "Owner-ID: %" PRIu32 "\n",            tsk_getu32(fs->endian, iso->dinode->ea->uid));        tsk_fprintf(hFile, "Group-ID: %" PRIu32 "\n",            tsk_getu32(fs->endian, iso->dinode->ea->gid));        tsk_fprintf(hFile, "Mode: %s\n", make_unix_perm(fs, &dd));    }    else if (iso->dinode->susp_off) {        char *buf2 = (char *) tsk_malloc((size_t) iso->dinode->susp_len);        if (buf2 != NULL) {            ssize_t cnt;            fprintf(hFile, "\nRock Ridge Extension Data\n");            cnt =                tsk_fs_read(fs, iso->dinode->susp_off, buf2,                (size_t) iso->dinode->susp_len);            if (cnt == iso->dinode->susp_len) {                parse_susp(fs, buf2, (int) cnt, hFile);            }            else {                fprintf(hFile, "Error reading Rock Ridge Location\n");                if (tsk_verbose) {                    fprintf(stderr,                        "istat: error reading rock ridge entry\n");                    tsk_error_print(stderr);                }                tsk_error_reset();            }            free(buf2);        }        else {            if (tsk_verbose)                fprintf(stderr,                    "istat: error allocating memory to process rock ridge entry\n");            tsk_error_reset();        }    }    //else if (iso->dinode->rr) {    //    iso9660_print_rockridge(hFile, iso->dinode->rr);    //}    else {        tsk_fprintf(hFile, "Owner-ID: 0\n");        tsk_fprintf(hFile, "Group-ID: 0\n");        tsk_fprintf(hFile, "Mode: %s\n", make_unix_perm(fs, &dd));    }    if (sec_skew != 0) {        tsk_fprintf(hFile, "\nAdjusted File Times:\n");        fs_file->meta->mtime -= sec_skew;        fs_file->meta->atime -= sec_skew;        fs_file->meta->crtime -= sec_skew;        tsk_fprintf(hFile, "Written:\t%s", ctime(&fs_file->meta->mtime));        tsk_fprintf(hFile, "Accessed:\t%s", ctime(&fs_file->meta->atime));        tsk_fprintf(hFile, "Created:\t%s", ctime(&fs_file->meta->crtime));        fs_file->meta->mtime += sec_skew;        fs_file->meta->atime += sec_skew;        fs_file->meta->crtime += sec_skew;        tsk_fprintf(hFile, "\nOriginal File Times:\n");    }    else {        tsk_fprintf(hFile, "\nFile Times:\n");    }    tsk_fprintf(hFile, "Created:\t%s", ctime(&fs_file->meta->crtime));    tsk_fprintf(hFile, "File Modified:\t%s", ctime(&fs_file->meta->mtime));    tsk_fprintf(hFile, "Accessed:\t%s", ctime(&fs_file->meta->atime));    tsk_fprintf(hFile, "\nSectors:\n");    /* since blocks are all contiguous, print them here to simplify file_walk */    {        int block = tsk_getu32(fs->endian, iso->dinode->dr.ext_loc_m);        TSK_OFF_T size = fs_file->meta->size;        int rowcount = 0;        while ((int64_t) size > 0) {            tsk_fprintf(hFile, "%d ", block++);            size -= fs->block_size;            rowcount++;            if (rowcount == 8) {                rowcount = 0;                tsk_fprintf(hFile, "\n");            }        }        tsk_fprintf(hFile, "\n");    }    tsk_fs_file_close(fs_file);    return 0;}uint8_tiso9660_jopen(TSK_FS_INFO * fs, TSK_INUM_T inum){    tsk_error_reset();    tsk_errno = TSK_ERR_FS_UNSUPFUNC;    snprintf(tsk_errstr, TSK_ERRSTR_L, "ISO9660 does not have a journal");    return 1;}uint8_tiso9660_jentry_walk(TSK_FS_INFO * fs, int flags,    TSK_FS_JENTRY_WALK_CB action, void *ptr){    tsk_error_reset();    tsk_errno = TSK_ERR_FS_UNSUPFUNC;    snprintf(tsk_errstr, TSK_ERRSTR_L, "ISO9660 does not have a journal");    return 1;}uint8_tiso9660_jblk_walk(TSK_FS_INFO * fs, TSK_DADDR_T start, TSK_DADDR_T end,    int flags, TSK_FS_JBLK_WALK_CB action, void *ptr){    tsk_error_reset();    tsk_errno = TSK_ERR_FS_UNSUPFUNC;    snprintf(tsk_errstr, TSK_ERRSTR_L, "ISO9660 does not have a journal");    return 1;}static TSK_FS_ATTR_TYPE_ENUMiso9660_get_default_attr_type(const TSK_FS_FILE * a_file){    return TSK_FS_ATTR_TYPE_DEFAULT;}static voidiso9660_close(TSK_FS_INFO * fs){    ISO_INFO *iso = (ISO_INFO *) fs;    iso9660_pvd_node *p;    iso9660_svd_node *s;    fs->tag = 0;    while (iso->pvd != NULL) {        p = iso->pvd;        iso->pvd = iso->pvd->next;        free(p);    }    while (iso->svd != NULL) {        s = iso->svd;        iso->svd = iso->svd->next;        free(s);    }    free((char *) iso->dinode);    if (fs->list_inum_named) {        tsk_list_free(fs->list_inum_named);        fs->list_inum_named = NULL;    }    free(fs);}/** Load the volume descriptors into save the raw data structures in * the file system state structure (fs).  Also determines the block size. * * This is useful for discs which may have 2 volumes on them (no, not * multisession CD-R/CD-RW). * Design note: If path table address is the same, then you have the same image. * Only store unique image info. * Uses a linked list even though Ecma-119 says there is only 1 primary vol * desc, consider possibility of more. * * Returns -1 on error and 0 on success */static intload_vol_desc(TSK_FS_INFO * fs){    int count = 0;    ISO_INFO *iso = (ISO_INFO *) fs;    TSK_OFF_T offs;    char *myname = "iso_load_vol_desc";    ssize_t cnt;    iso9660_pvd_node *p;    iso9660_svd_node *s;    iso->pvd = NULL;    iso->svd = NULL;    fs->block_size = 0;    fs->dev_bsize = 512;#if 0    b = (iso_bootrec *) tsk_malloc(sizeof(iso_bootrec));    if (b == NULL) {        return -1;    }#endif    // @@@ Technically, we should seek ahea 16 * sector size    for (offs = ISO9660_SBOFF;; offs += sizeof(iso9660_gvd)) {        iso9660_gvd *vd;        // allocate a buffer the size of the nodes in the linked list        // this will be stored in ISO_INFO, so it is not always freed here        if ((vd =                (iso9660_gvd *) tsk_malloc(sizeof(iso9660_pvd_node))) ==            NULL) {            return -1;        }        // read the full descriptor        cnt = tsk_fs_read(fs, offs, (char *) vd, sizeof(iso9660_gvd));        if (cnt != sizeof(iso9660_gvd)) {            if (cnt >= 0) {                tsk_error_reset();                tsk_errno = TSK_ERR_FS_READ;            }            snprintf(tsk_errstr2, TSK_ERRSTR_L,                "iso_load_vol_desc: Error reading");            free(vd);            return -1;        }        // verify the magic value        if (strncmp(vd->magic, ISO9660_MAGIC, 5)) {            if (tsk_verbose)                tsk_fprintf(stderr, "%s: Bad volume descriptor: \                         Magic number is not CD001\n", myname);            free(vd);            return -1;        }        // see if we are done        if (vd->type == ISO9660_VOL_DESC_SET_TERM)            break;        switch (vd->type) {        case ISO9660_PRIM_VOL_DESC:            p = (iso9660_pvd_node *) vd;            /* list not empty */            if (iso->pvd) {                iso9660_pvd_node *ptmp = iso->pvd;                /* append to list if path table address not found in list */                while ((p->pvd.pt_loc_l != ptmp->pvd.pt_loc_l)                    && (ptmp->next))                    ptmp = ptmp->next;                // we already have it                if (p->pvd.pt_loc_l == ptmp->pvd.pt_loc_l) {                    free(vd);                    p = NULL;                    vd = NULL;                }                else {                    ptmp->next = p;                    p->next = NULL;                    count++;              

⌨️ 快捷键说明

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