/* $Id: ext2fs.c,v 1.2 2021/11/06 17:35:07 khorben Exp $ */ /* Copyright (c) 2011 khorben of UberWall */ /* This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "plugin.h" /* ext2fs */ /* public */ /* types */ #pragma pack(1) struct ext2fs_super_block { unsigned int e2fs_icount; unsigned int e2fs_bcount; unsigned int e2fs_rbcount; unsigned int e2fs_fbcount; unsigned int e2fs_ficount; unsigned int e2fs_first_dblock; unsigned int e2fs_log_bsize; unsigned int e2fs_fsize; unsigned int e2fs_bpg; unsigned int e2fs_fpg; unsigned int e2fs_ipg; unsigned int e2fs_mtime; unsigned int e2fs_wtime; unsigned short e2fs_mnt_count; unsigned short e2fs_max_mnt_count; unsigned short e2fs_magic; unsigned short e2fs_state; }; #pragma pack() /* prototypes */ static int ext2fs_callback(PluginHelper * ph, int signature, FILE * fp); /* variables */ /* magic */ static unsigned char sig1[] = "\xef\x53"; static unsigned char sig2[] = "\x53\xef"; static PluginMagic ext2fs_magic[] = { { sizeof(struct ext2fs_super_block), offsetof(struct ext2fs_super_block, e2fs_magic), sig1, sizeof(sig1) - 1 }, { sizeof(struct ext2fs_super_block), offsetof(struct ext2fs_super_block, e2fs_magic), sig2, sizeof(sig2) - 1 }, { 0, 0, NULL, 0 } }; /* plugin */ Plugin plugin = { PT_ARCHIVE, "EXT2FS", ext2fs_magic, ext2fs_callback }; /* functions */ /* ext2fs_callback */ static int _callback_time(PluginHelper * ph, char const * what, time_t mtime); static int ext2fs_callback(PluginHelper * ph, int signature, FILE * fp) { int score = 0; struct ext2fs_super_block buf; (void) signature; if(fread(&buf, sizeof(buf), 1, fp) != 1) return -1; ph->printf(ph, "inode count %u, block count %u" ", reserved block count %u", buf.e2fs_icount, buf.e2fs_bcount, buf.e2fs_rbcount); score += _callback_time(ph, "mount time", buf.e2fs_mtime); score += _callback_time(ph, "write time", buf.e2fs_wtime); ph->printf(ph, "\n"); return score / 2; } static int _callback_time(PluginHelper * ph, char const * what, time_t mtime) { struct tm tm; char tmp[22] = ""; if(gmtime_r(&mtime, &tm) == NULL || strftime(tmp, sizeof(tmp), "%d/%m/%Y %H:%M:%S", &tm) == 0) { ph->printf(ph, "%s%s", ", unknown ", what); return 0; } ph->printf(ph, ", %s %s", what, tmp); /* between Wed May 1 00:00:00 CEST 1996 and now */ return mtime > 830901600 && mtime < time(NULL) ? 100 : 0; }