-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathWinFile.pm
More file actions
142 lines (113 loc) · 3.13 KB
/
WinFile.pm
File metadata and controls
142 lines (113 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package WinFile;
#---------------------------------------------------------------------
# WinFile.pm
#
#
# Change history
# 20100922 - created
#
#
# References
#
#
# copyright 2012 ASI
# This software is released under the Perl Artistic License:
# http://dev.perl.org/licenses/artistic.html
#---------------------------------------------------------------------
use strict;
use Exporter;
use Digest::MD5;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 0.1;
@ISA = qw(Exporter);
@EXPORT = ();
@EXPORT_OK = qw(new);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# Global variables
# self reference
my $self = {};
#---------------------------------------------------------------------
# new()
#
#---------------------------------------------------------------------
sub new {
my $class = shift;
return bless($self, $class);
}
#---------------------------------------------------------------------
# getMD5()
# Returns an MD5 hash
#---------------------------------------------------------------------
sub getMD5 {
open(FH, $_[1]) or die "Can't open ".$_[1].": $!";
binmode(FH);
return Digest::MD5->new->addfile(*FH)->hexdigest();
}
#---------------------------------------------------------------------
# getSize()
#
#---------------------------------------------------------------------
sub getSize {return (stat($_[1]))[7];}
#---------------------------------------------------------------------
# getFileExt()
#
#---------------------------------------------------------------------
sub getFileExt {
# strip file name from path
my @list = split(/\\/,$_[1]);
my $i = scalar @list;
my $file = $list[$i - 1];
my @name = split(/\./,$file);
my $sc = scalar @name;
if ($sc == 2) {
return $name[1];
}
elsif ($sc > 2) {
return $name[$sc - 1];
}
else {
# something happened, or there is no file extension
}
}
#---------------------------------------------------------------------
# isMZSig()
# checks first two bytes for 'MZ' (0x5a4d)
#---------------------------------------------------------------------
sub isMZSig {
my $data;
open(FH,$_[1]);
binmode(FH);
seek(FH,0,0);
read(FH,$data,2);
if ($data eq "MZ") {
return 1;
}
else {
return 0;
}
}
#----------------------------------------------------------------
# getError()
# returns the error message for the module
#----------------------------------------------------------------
sub getError {return $self->{error};}
1;
__END__
=head1 NAME
WinFile - Helper module for FSS Scanner
=head1 SYNOPSIS
see example files
=head1 DESCRIPTION
WinFile is a Perl module the provides helper functions for the main
driver component of the Forensic Scanner.
=head1 SEE ALSO
=head1 AUTHOR
Harlan Carvey, E<lt>keydet89@yahoo.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2009 by Harlan Carvey (keydet89@yahoo.com)
This library is free software; you can redistribute it and/or modify
it as you like. However, please be sure to provide proper credit where
it is due.
=cut