📄 ext2fs.c
字号:
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); /* Print the device ids */ if ((fs_meta->type == TSK_FS_META_TYPE_BLK) || (fs_meta->type == TSK_FS_META_TYPE_CHR)) { tsk_fprintf(hFile, "Device Major: %" PRIu8 " Minor: %" PRIu8 "\n", ext2fs->dino_buf->i_block[0][1], ext2fs->dino_buf->i_block[0][0]); } if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_flags)) { tsk_fprintf(hFile, "Flags: "); if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_flags) & EXT2_IN_SECDEL) tsk_fprintf(hFile, "Secure Delete, "); if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_flags) & EXT2_IN_UNRM) tsk_fprintf(hFile, "Undelete, "); if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_flags) & EXT2_IN_COMP) tsk_fprintf(hFile, "Compressed, "); if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_flags) & EXT2_IN_SYNC) tsk_fprintf(hFile, "Sync Updates, "); if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_flags) & EXT2_IN_IMM) tsk_fprintf(hFile, "Immutable, "); if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_flags) & EXT2_IN_APPEND) tsk_fprintf(hFile, "Append Only, "); if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_flags) & EXT2_IN_NODUMP) tsk_fprintf(hFile, "Do Not Dump, "); if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_flags) & EXT2_IN_NOA) tsk_fprintf(hFile, "No A-Time, "); tsk_fprintf(hFile, "\n"); } tsk_fprintf(hFile, "size: %" PRIuOFF "\n", fs_meta->size); tsk_fprintf(hFile, "num of links: %d\n", fs_meta->nlink); /* Ext attribute are stored in a block with a header and a list * of entries that are aligned to 4-byte boundaries. The attr * value is stored at the end of the block. There are 4 null bytes * in between the headers and values */ if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_file_acl) != 0) { char *buf; ext2fs_ea_header *ea_head; ext2fs_ea_entry *ea_entry; ssize_t cnt; if ((buf = tsk_malloc(fs->block_size)) == NULL) { tsk_fs_file_close(fs_file); return 1; } tsk_fprintf(hFile, "\nExtended Attributes (Block: %" PRIu32 ")\n", tsk_getu32(fs->endian, ext2fs->dino_buf->i_file_acl)); /* Is the value too big? */ if (tsk_getu32(fs->endian, ext2fs->dino_buf->i_file_acl) > fs->last_block) { tsk_fprintf(hFile, "Extended Attributes block is larger than file system\n"); goto egress_ea; } cnt = tsk_fs_read(fs, (TSK_DADDR_T) tsk_getu32(fs->endian, ext2fs->dino_buf->i_file_acl) * fs->block_size, buf, fs->block_size); if (cnt != fs->block_size) { if (cnt >= 0) { tsk_error_reset(); tsk_errno = TSK_ERR_FS_READ; } snprintf(tsk_errstr2, TSK_ERRSTR_L, "ext2fs_istat: ACL block %" PRIu32, tsk_getu32(fs->endian, ext2fs->dino_buf->i_file_acl)); tsk_fs_file_close(fs_file); free(buf); return 1; } /* Check the header */ ea_head = (ext2fs_ea_header *) buf; if (tsk_getu32(fs->endian, ea_head->magic) != EXT2_EA_MAGIC) { tsk_fprintf(hFile, "Incorrect extended attribute header: %" PRIx32 "\n", tsk_getu32(fs->endian, ea_head->magic)); } /* Cycle through each entry - at the top of the block */ for (ea_entry = (ext2fs_ea_entry *) & ea_head->entry; ((uintptr_t) ea_entry < ((uintptr_t) buf + fs->block_size - sizeof(ext2fs_ea_entry))); ea_entry = (ext2fs_ea_entry *) ((uintptr_t) ea_entry + EXT2_EA_LEN(ea_entry->nlen))) { char name[256]; /* Stop if the first four bytes are NULL */ if ((ea_entry->nlen == 0) && (ea_entry->nidx == 0) && (tsk_getu16(fs->endian, ea_entry->val_off) == 0)) break; /* The Linux src does not allow this */ if (tsk_getu32(fs->endian, ea_entry->val_blk) != 0) { tsk_fprintf(hFile, "Attribute has non-zero value block - skipping\n"); continue; } /* Is the value location and size valid? */ if ((tsk_getu32(fs->endian, ea_entry->val_off) > fs->block_size) || ((tsk_getu16(fs->endian, ea_entry->val_off) + tsk_getu32(fs->endian, ea_entry->val_size)) > fs->block_size)) { continue; } /* Copy the name into a buffer - not NULL term */ strncpy(name, (char *) &ea_entry->name, ea_entry->nlen); name[ea_entry->nlen] = '\0'; /* User assigned attributes - setfattr / getfattr */ if ((ea_entry->nidx == EXT2_EA_IDX_USER) || (ea_entry->nidx == EXT2_EA_IDX_TRUSTED) || (ea_entry->nidx == EXT2_EA_IDX_SECURITY)) { char val[256]; strncpy(val, &buf[tsk_getu16(fs->endian, ea_entry->val_off)], tsk_getu32(fs->endian, ea_entry->val_size) > 256 ? 256 : tsk_getu32(fs->endian, ea_entry->val_size)); val[tsk_getu32(fs->endian, ea_entry->val_size) > 256 ? 256 : tsk_getu32(fs->endian, ea_entry->val_size)] = '\0'; if (ea_entry->nidx == EXT2_EA_IDX_USER) tsk_fprintf(hFile, "user.%s=%s\n", name, val); else if (ea_entry->nidx == EXT2_EA_IDX_TRUSTED) tsk_fprintf(hFile, "trust.%s=%s\n", name, val); else if (ea_entry->nidx == EXT2_EA_IDX_SECURITY) tsk_fprintf(hFile, "security.%s=%s\n", name, val); } /* POSIX ACL - setfacl / getfacl stuff */ else if ((ea_entry->nidx == EXT2_EA_IDX_POSIX_ACL_ACCESS) || (ea_entry->nidx == EXT2_EA_IDX_POSIX_ACL_DEFAULT)) { ext2fs_pos_acl_entry_lo *acl_lo; ext2fs_pos_acl_head *acl_head; if (ea_entry->nidx == EXT2_EA_IDX_POSIX_ACL_ACCESS) tsk_fprintf(hFile, "POSIX Access Control List Entries:\n"); else if (ea_entry->nidx == EXT2_EA_IDX_POSIX_ACL_DEFAULT) tsk_fprintf(hFile, "POSIX Default Access Control List Entries:\n"); /* examine the header */ acl_head = (ext2fs_pos_acl_head *) & buf[tsk_getu16(fs->endian, ea_entry->val_off)]; if (tsk_getu32(fs->endian, acl_head->ver) != 1) { tsk_fprintf(hFile, "Invalid ACL Header Version: %" PRIu32 "\n", tsk_getu32(fs->endian, acl_head->ver)); continue; } /* The first entry starts after the header */ acl_lo = (ext2fs_pos_acl_entry_lo *) ((uintptr_t) acl_head + sizeof(ext2fs_pos_acl_head)); /* Cycle through the values */ while ((uintptr_t) acl_lo < ((uintptr_t) buf + tsk_getu16(fs->endian, ea_entry->val_off) + tsk_getu32(fs->endian, ea_entry->val_size))) { char perm[64]; int len; /* Make a string from the permissions */ ext2fs_make_acl_str(perm, 64, tsk_getu16(fs->endian, acl_lo->perm)); switch (tsk_getu16(fs->endian, acl_lo->tag)) { case EXT2_PACL_TAG_USERO: tsk_fprintf(hFile, " uid: %" PRIuUID ": %s\n", fs_meta->uid, perm); len = sizeof(ext2fs_pos_acl_entry_sh); break; case EXT2_PACL_TAG_GRPO: tsk_fprintf(hFile, " gid: %" PRIuGID ": %s\n", fs_meta->gid, perm); len = sizeof(ext2fs_pos_acl_entry_sh); break; case EXT2_PACL_TAG_OTHER: tsk_fprintf(hFile, " other: %s\n", perm); len = sizeof(ext2fs_pos_acl_entry_sh); break; case EXT2_PACL_TAG_MASK: tsk_fprintf(hFile, " mask: %s\n", perm); len = sizeof(ext2fs_pos_acl_entry_sh); break; case EXT2_PACL_TAG_GRP: tsk_fprintf(hFile, " gid: %" PRIu32 ": %s\n", tsk_getu32(fs->endian, acl_lo->id), perm); len = sizeof(ext2fs_pos_acl_entry_lo); break; case EXT2_PACL_TAG_USER: tsk_fprintf(hFile, " uid: %" PRIu32 ": %s\n", tsk_getu32(fs->endian, acl_lo->id), perm); len = sizeof(ext2fs_pos_acl_entry_lo); break; default: tsk_fprintf(hFile, "Unknown ACL tag: %d\n", tsk_getu16(fs->endian, acl_lo->tag)); len = sizeof(ext2fs_pos_acl_entry_sh); break; } acl_lo = (ext2fs_pos_acl_entry_lo *) ((uintptr_t) acl_lo + len); } } else { tsk_fprintf(hFile, "Unsupported Extended Attr Type: %d\n", ea_entry->nidx); } } egress_ea: free(buf); } 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)); if (fs_meta->time2.ext2.dtime) { fs_meta->time2.ext2.dtime -= sec_skew; tsk_fprintf(hFile, "Deleted:\t%s", ctime(&fs_meta->time2.ext2.dtime)); fs_meta->time2.ext2.dtime += sec_skew; } 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_meta->time2.ext2.dtime) tsk_fprintf(hFile, "Deleted:\t%s", ctime(&fs_meta->time2.ext2.dtime)); if (numblock > 0) fs_meta->size = numblock * fs->block_size; 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 file: "); tsk_error_print(hFile); tsk_error_reset(); } else if (print.idx != 0) { tsk_fprintf(hFile, "\n"); } tsk_fs_file_close(fs_file); return 0;}/* ext2fs_close - close an ext2fs file system */static voidext2fs_close(TSK_FS_INFO * fs){ EXT2FS_INFO *ext2fs = (EXT2FS_INFO *) fs; fs->tag = 0; free((char *) ext2fs->fs); if (ext2fs->dino_buf != NULL) free((char *) ext2fs->dino_buf); if (ext2fs->grp_buf != NULL) free((char *) ext2fs->grp_buf); if (ext2fs->bmap_buf != NULL) free((char *) ext2fs->bmap_buf); if (ext2fs->imap_buf != NULL) free((char *) ext2fs->imap_buf); if (fs->list_inum_named) { tsk_list_free(fs->list_inum_named); fs->list_inum_named = NULL; } free(ext2fs);}/** * \internal * Open part of a disk image as a Ext2/3 file system. * * @param img_info Disk image to analyze * @param offset Byte offset where file system starts * @param ftype Specific type of file system * @param test NOT USED * @returns NULL on error or if data is not an Ext2/3 file system */TSK_FS_INFO *ext2fs_open(TSK_IMG_INFO * img_info, TSK_OFF_T offset, TSK_FS_TYPE_ENUM ftype, uint8_t test){ EXT2FS_INFO *ext2fs; 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_ISEXT(ftype) == 0) { tsk_error_reset(); tsk_errno = TSK_ERR_FS_ARG; snprintf(tsk_errstr, TSK_ERRSTR_L, "Invalid FS Type in ext2fs_open"); return NULL; } if ((ext2fs = (EXT2FS_INFO *) tsk_malloc(sizeof(*ext2fs))) == NULL) return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -