📄 ext2fs.c
字号:
EXT2FS_FEATURE_INCOMPAT_JOURNAL_DEV) tsk_fprintf(hFile, "Journal Dev"); tsk_fprintf(hFile, "\n"); } if (tsk_getu32(fs->endian, sb->s_feature_ro_compat)) { tsk_fprintf(hFile, "Read Only Compat Features: "); if (tsk_getu32(fs->endian, sb->s_feature_ro_compat) & EXT2FS_FEATURE_RO_COMPAT_SPARSE_SUPER) tsk_fprintf(hFile, "Sparse Super, "); if (tsk_getu32(fs->endian, sb->s_feature_ro_compat) & EXT2FS_FEATURE_RO_COMPAT_LARGE_FILE) tsk_fprintf(hFile, "Has Large Files, "); if (tsk_getu32(fs->endian, sb->s_feature_ro_compat) & EXT2FS_FEATURE_RO_COMPAT_BTREE_DIR) tsk_fprintf(hFile, "Btree Dir"); tsk_fprintf(hFile, "\n"); } /* Print journal information */ if (tsk_getu32(fs->endian, sb->s_feature_compat) & EXT2FS_FEATURE_COMPAT_HAS_JOURNAL) { tsk_fprintf(hFile, "\nJournal ID: %" PRIx64 "%" PRIx64 "\n", tsk_getu64(fs->endian, &sb->s_journal_uuid[8]), tsk_getu64(fs->endian, &sb->s_journal_uuid[0])); if (tsk_getu32(fs->endian, sb->s_journal_inum) != 0) tsk_fprintf(hFile, "Journal Inode: %" PRIu32 "\n", tsk_getu32(fs->endian, sb->s_journal_inum)); if (tsk_getu32(fs->endian, sb->s_journal_dev) != 0) tsk_fprintf(hFile, "Journal Device: %" PRIu32 "\n", tsk_getu32(fs->endian, sb->s_journal_dev)); } tsk_fprintf(hFile, "\nMETADATA INFORMATION\n"); tsk_fprintf(hFile, "--------------------------------------------\n"); tsk_fprintf(hFile, "Inode Range: %" PRIuINUM " - %" PRIuINUM "\n", fs->first_inum, fs->last_inum); tsk_fprintf(hFile, "Root Directory: %" PRIuINUM "\n", fs->root_inum); tsk_fprintf(hFile, "Free Inodes: %" PRIu32 "\n", tsk_getu32(fs->endian, sb->s_free_inode_count)); if (tsk_getu32(fs->endian, sb->s_last_orphan)) { uint32_t or_in; tsk_fprintf(hFile, "Orphan Inodes: "); or_in = tsk_getu32(fs->endian, sb->s_last_orphan); while (or_in) { TSK_FS_FILE *fs_file; if ((or_in > fs->last_inum) || (or_in < fs->first_inum)) break; tsk_fprintf(hFile, "%" PRIu32 ", ", or_in); if ((fs_file = tsk_fs_file_alloc(fs)) == NULL) { /* Ignore this error */ tsk_error_reset(); break; } /* Get the next one */ if (ext2fs_inode_lookup(fs, fs_file, or_in)) { /* Ignore this error */ tsk_error_reset(); break; } or_in = (uint32_t) fs_file->meta->time2.ext2.dtime; tsk_fs_file_close(fs_file); } tsk_fprintf(hFile, "\n"); } tsk_fprintf(hFile, "\nCONTENT INFORMATION\n"); tsk_fprintf(hFile, "--------------------------------------------\n"); tsk_fprintf(hFile, "Block Range: %" PRIuDADDR " - %" PRIuDADDR "\n", fs->first_block, fs->last_block); if (fs->last_block != fs->last_block_act) tsk_fprintf(hFile, "Total Range in Image: %" PRIuDADDR " - %" PRIuDADDR "\n", fs->first_block, fs->last_block_act); tsk_fprintf(hFile, "Block Size: %u\n", fs->block_size); if (tsk_getu32(fs->endian, sb->s_first_data_block)) tsk_fprintf(hFile, "Reserved Blocks Before Block Groups: %" PRIu32 "\n", tsk_getu32(fs->endian, sb->s_first_data_block)); tsk_fprintf(hFile, "Free Blocks: %" PRIu32 "\n", tsk_getu32(fs->endian, sb->s_free_blocks_count)); tsk_fprintf(hFile, "\nBLOCK GROUP INFORMATION\n"); tsk_fprintf(hFile, "--------------------------------------------\n"); tsk_fprintf(hFile, "Number of Block Groups: %" PRI_EXT2GRP "\n", ext2fs->groups_count); tsk_fprintf(hFile, "Inodes per group: %" PRIu32 "\n", tsk_getu32(fs->endian, sb->s_inodes_per_group)); tsk_fprintf(hFile, "Blocks per group: %" PRIu32 "\n", tsk_getu32(fs->endian, sb->s_blocks_per_group)); /* number of blocks the inodes consume */ ibpg = (tsk_getu32(fs->endian, sb->s_inodes_per_group) * ext2fs->inode_size + fs->block_size - 1) / fs->block_size; for (i = 0; i < ext2fs->groups_count; i++) { TSK_DADDR_T cg_base; TSK_INUM_T inum; if (ext2fs_group_load(ext2fs, i)) { return 1; } tsk_fprintf(hFile, "\nGroup: %d:\n", i); inum = fs->first_inum + tsk_gets32(fs->endian, sb->s_inodes_per_group) * i; tsk_fprintf(hFile, " Inode Range: %" PRIuINUM " - ", inum); if ((inum + tsk_gets32(fs->endian, sb->s_inodes_per_group) - 1) < fs->last_inum) tsk_fprintf(hFile, "%" PRIuINUM "\n", inum + tsk_gets32(fs->endian, sb->s_inodes_per_group) - 1); else tsk_fprintf(hFile, "%" PRIuINUM "\n", fs->last_inum); cg_base = ext2_cgbase_lcl(fs, sb, i); tsk_fprintf(hFile, " Block Range: %" PRIuDADDR " - %" PRIuDADDR "\n", cg_base, ((ext2_cgbase_lcl(fs, sb, i + 1) - 1) < fs->last_block) ? (ext2_cgbase_lcl(fs, sb, i + 1) - 1) : fs->last_block); tsk_fprintf(hFile, " Layout:\n"); /* only print the super block data if we are not in a sparse * group */ if (((tsk_getu32(fs->endian, ext2fs->fs->s_feature_ro_compat) & EXT2FS_FEATURE_RO_COMPAT_SPARSE_SUPER) && (cg_base != tsk_getu32(fs->endian, ext2fs->grp_buf->bg_block_bitmap))) || ((tsk_getu32(fs->endian, ext2fs->fs-> s_feature_ro_compat) & EXT2FS_FEATURE_RO_COMPAT_SPARSE_SUPER) == 0)) { TSK_OFF_T boff; /* the super block is the first 1024 bytes */ tsk_fprintf(hFile, " Super Block: %" PRIuDADDR " - %" PRIuDADDR "\n", cg_base, cg_base + ((sizeof(ext2fs_sb) + fs->block_size - 1) / fs->block_size) - 1); boff = roundup(sizeof(ext2fs_sb), fs->block_size); /* Group Descriptors */ tsk_fprintf(hFile, " Group Descriptor Table: %" PRIuDADDR " - ", (cg_base + (boff + fs->block_size - 1) / fs->block_size)); boff += (ext2fs->groups_count * sizeof(ext2fs_gd)); tsk_fprintf(hFile, "%" PRIuDADDR "\n", ((cg_base + (boff + fs->block_size - 1) / fs->block_size) - 1)); } /* The block bitmap is a full block */ tsk_fprintf(hFile, " Data bitmap: %" PRIu32 " - %" PRIu32 "\n", tsk_getu32(fs->endian, ext2fs->grp_buf->bg_block_bitmap), tsk_getu32(fs->endian, ext2fs->grp_buf->bg_block_bitmap)); /* The inode bitmap is a full block */ tsk_fprintf(hFile, " Inode bitmap: %" PRIu32 " - %" PRIu32 "\n", tsk_getu32(fs->endian, ext2fs->grp_buf->bg_inode_bitmap), tsk_getu32(fs->endian, ext2fs->grp_buf->bg_inode_bitmap)); tsk_fprintf(hFile, " Inode Table: %" PRIu32 " - %" PRIu32 "\n", tsk_getu32(fs->endian, ext2fs->grp_buf->bg_inode_table), tsk_getu32(fs->endian, ext2fs->grp_buf->bg_inode_table) + ibpg - 1); tsk_fprintf(hFile, " Data Blocks: "); /* If we are in a sparse group, display the other addresses */ if ((tsk_getu32(fs->endian, ext2fs->fs->s_feature_ro_compat) & EXT2FS_FEATURE_RO_COMPAT_SPARSE_SUPER) && (cg_base == tsk_getu32(fs->endian, ext2fs->grp_buf->bg_block_bitmap))) { /* it goes from the end of the inode bitmap to before the * table * * This hard coded aspect does not scale ... */ tsk_fprintf(hFile, "%" PRIu32 " - %" PRIu32 ", ", tsk_getu32(fs->endian, ext2fs->grp_buf->bg_inode_bitmap) + 1, tsk_getu32(fs->endian, ext2fs->grp_buf->bg_inode_table) - 1); } tsk_fprintf(hFile, "%" PRIuDADDR " - %" PRIuDADDR "\n", (uint64_t) tsk_getu32(fs->endian, ext2fs->grp_buf->bg_inode_table) + ibpg, ((ext2_cgbase_lcl(fs, sb, i + 1) - 1) < fs->last_block) ? (ext2_cgbase_lcl(fs, sb, i + 1) - 1) : fs->last_block); /* Print the free info */ /* The last group may not have a full number of blocks */ if (i != (ext2fs->groups_count - 1)) { tsk_fprintf(hFile, " Free Inodes: %" PRIu16 " (%" PRIu32 "%%)\n", tsk_getu16(fs->endian, ext2fs->grp_buf->bg_free_inodes_count), (100 * tsk_getu16(fs->endian, ext2fs->grp_buf->bg_free_inodes_count)) / tsk_getu32(fs->endian, sb->s_inodes_per_group)); tsk_fprintf(hFile, " Free Blocks: %" PRIu16 " (%" PRIu32 "%%)\n", tsk_getu16(fs->endian, ext2fs->grp_buf->bg_free_blocks_count), (100 * tsk_getu16(fs->endian, ext2fs->grp_buf->bg_free_blocks_count)) / tsk_getu32(fs->endian, sb->s_blocks_per_group)); } else { TSK_INUM_T inum_left; TSK_DADDR_T blk_left; inum_left = fs->last_inum % tsk_gets32(fs->endian, sb->s_inodes_per_group); if (inum_left == 0) inum_left = tsk_getu32(fs->endian, sb->s_inodes_per_group); tsk_fprintf(hFile, " Free Inodes: %" PRIu16 " (%d%%)\n", tsk_getu16(fs->endian, ext2fs->grp_buf->bg_free_inodes_count), (100 * tsk_getu16(fs->endian, ext2fs->grp_buf->bg_free_inodes_count)) / inum_left); /* Now blocks */ blk_left = fs->block_count % tsk_getu32(fs->endian, sb->s_blocks_per_group); if (blk_left == 0) blk_left = tsk_getu32(fs->endian, sb->s_blocks_per_group); tsk_fprintf(hFile, " Free Blocks: %" PRIu16 " (%d%%)\n", tsk_getu16(fs->endian, ext2fs->grp_buf->bg_free_blocks_count), (100 * tsk_getu16(fs->endian, ext2fs->grp_buf->bg_free_blocks_count)) / blk_left); } tsk_fprintf(hFile, " Total Directories: %" PRIu16 "\n", tsk_getu16(fs->endian, ext2fs->grp_buf->bg_used_dirs_count)); } return 0;}/************************* istat *******************************/static voidext2fs_make_acl_str(char *str, int len, uint16_t perm){ int i = 0; if (perm & EXT2_PACL_PERM_READ) { snprintf(&str[i], len - 1, "Read"); i += 4; } if (perm & EXT2_PACL_PERM_WRITE) { if (i) { snprintf(&str[i], len - 1, ", "); i += 2; } snprintf(&str[i], len - 1, "Write"); i += 5; } if (perm & EXT2_PACL_PERM_EXEC) { if (i) { snprintf(&str[i], len - 1, ", "); i += 2; } snprintf(&str[i], len - 1, "Execute"); i += 7; }}typedef struct { FILE *hFile; int idx;} EXT2FS_PRINT_ADDR;/* Callback for istat to print the block addresses */static TSK_WALK_RET_ENUMprint_addr_act(TSK_FS_FILE * fs_file, TSK_OFF_T a_off, TSK_DADDR_T addr, char *buf, size_t size, TSK_FS_BLOCK_FLAG_ENUM flags, void *a_ptr){ TSK_FS_INFO *fs = fs_file->fs_info; EXT2FS_PRINT_ADDR *print = (EXT2FS_PRINT_ADDR *) a_ptr; if (flags & TSK_FS_BLOCK_FLAG_CONT) { int i, s; /* cycle through the blocks if they exist */ for (i = 0, s = (int) size; s > 0; s -= fs->block_size, i++) { /* sparse file */ if (addr) 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_text2fs_istat(TSK_FS_INFO * fs, FILE * hFile, TSK_INUM_T inum, TSK_DADDR_T numblock, int32_t sec_skew){ EXT2FS_INFO *ext2fs = (EXT2FS_INFO *) fs; TSK_FS_META *fs_meta; TSK_FS_FILE *fs_file; char ls[12]; EXT2FS_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: %" PRIuGID "\n", ext2fs->grp_num); tsk_fprintf(hFile, "Generation Id: %" PRIu32 "\n", tsk_getu32(fs->endian, ext2fs->dino_buf->i_generation));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -