Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sleuthkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IRT
Sleuthkit
Commits
48da2032
Commit
48da2032
authored
4 years ago
by
apriestman
Browse files
Options
Downloads
Patches
Plain Diff
Stop hashing if EOF is found.
Keep track of how many bytes are written to the EncodedFileOutputStream.
parent
6f2d2818
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bindings/java/src/org/sleuthkit/datamodel/EncodedFileOutputStream.java
+18
-2
18 additions, 2 deletions
.../src/org/sleuthkit/datamodel/EncodedFileOutputStream.java
bindings/java/src/org/sleuthkit/datamodel/HashUtility.java
+6
-1
6 additions, 1 deletion
bindings/java/src/org/sleuthkit/datamodel/HashUtility.java
with
24 additions
and
3 deletions
bindings/java/src/org/sleuthkit/datamodel/EncodedFileOutputStream.java
+
18
−
2
View file @
48da2032
...
@@ -30,7 +30,8 @@
...
@@ -30,7 +30,8 @@
*/
*/
public
class
EncodedFileOutputStream
extends
BufferedOutputStream
{
public
class
EncodedFileOutputStream
extends
BufferedOutputStream
{
private
TskData
.
EncodingType
type
;
private
final
TskData
.
EncodingType
type
;
private
long
encodedDataLength
;
/**
/**
* Create an encoded output stream using the specified encoding.
* Create an encoded output stream using the specified encoding.
...
@@ -43,6 +44,7 @@ public class EncodedFileOutputStream extends BufferedOutputStream {
...
@@ -43,6 +44,7 @@ public class EncodedFileOutputStream extends BufferedOutputStream {
public
EncodedFileOutputStream
(
OutputStream
out
,
TskData
.
EncodingType
type
)
throws
IOException
{
public
EncodedFileOutputStream
(
OutputStream
out
,
TskData
.
EncodingType
type
)
throws
IOException
{
super
(
out
);
super
(
out
);
this
.
type
=
type
;
this
.
type
=
type
;
encodedDataLength
=
0
;
writeHeader
();
writeHeader
();
}
}
...
@@ -65,11 +67,13 @@ public EncodedFileOutputStream(OutputStream out, int size, TskData.EncodingType
...
@@ -65,11 +67,13 @@ public EncodedFileOutputStream(OutputStream out, int size, TskData.EncodingType
private
void
writeHeader
()
throws
IOException
{
private
void
writeHeader
()
throws
IOException
{
// We get the encoded header here so it will be in plaintext after encoding
// We get the encoded header here so it will be in plaintext after encoding
write
(
EncodedFileUtil
.
getEncodedHeader
(
type
),
0
,
EncodedFileUtil
.
getHeaderLength
());
write
(
EncodedFileUtil
.
getEncodedHeader
(
type
),
0
,
EncodedFileUtil
.
getHeaderLength
());
encodedDataLength
-=
EncodedFileUtil
.
getHeaderLength
();
}
}
@Override
@Override
public
void
write
(
int
b
)
throws
IOException
{
public
void
write
(
int
b
)
throws
IOException
{
super
.
write
((
int
)
EncodedFileUtil
.
encodeByte
((
byte
)
b
,
type
));
super
.
write
((
int
)
EncodedFileUtil
.
encodeByte
((
byte
)
b
,
type
));
encodedDataLength
++;
}
}
@Override
@Override
...
@@ -83,5 +87,17 @@ public void write(byte[] b,
...
@@ -83,5 +87,17 @@ public void write(byte[] b,
}
}
super
.
write
(
encodedData
,
off
,
len
);
super
.
write
(
encodedData
,
off
,
len
);
encodedDataLength
+=
len
;
}
}
}
/**
* Get the number of bytes written to the file, excluding header bytes.
* This is needed for storing the original length of the file in the
* tsk_files table in cases where we don't know the size in advance.
*
* @return the number of bytes written to the stream, excluding the header.
*/
public
long
getBytesWritten
()
{
return
encodedDataLength
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
bindings/java/src/org/sleuthkit/datamodel/HashUtility.java
+
6
−
1
View file @
48da2032
...
@@ -68,6 +68,11 @@ static public List<HashResult> calculateHashes(Content content, Collection<HashT
...
@@ -68,6 +68,11 @@ static public List<HashResult> calculateHashes(Content content, Collection<HashT
}
catch
(
TskCoreException
ex
)
{
}
catch
(
TskCoreException
ex
)
{
throw
new
TskCoreException
(
"Error reading data at address "
+
i
*
BUFFER_SIZE
+
" from content with ID: "
+
content
.
getId
(),
ex
);
throw
new
TskCoreException
(
"Error reading data at address "
+
i
*
BUFFER_SIZE
+
" from content with ID: "
+
content
.
getId
(),
ex
);
}
}
// Check for EOF
if
(
read
==
-
1
)
{
break
;
}
// Only update with the read bytes.
// Only update with the read bytes.
if
(
read
==
BUFFER_SIZE
)
{
if
(
read
==
BUFFER_SIZE
)
{
...
@@ -228,4 +233,4 @@ static public String calculateMd5Hash(Content content) throws IOException {
...
@@ -228,4 +233,4 @@ static public String calculateMd5Hash(Content content) throws IOException {
throw
new
IOException
(
ex
);
throw
new
IOException
(
ex
);
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment