Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $combined_file = "C:\test\3.jpg"
- $output_location = "C:\test\"
- #Magic string to search for, example is taken from
- #https://en.wikipedia.org/wiki/List_of_file_signatures as jpg example
- $magic_sequence_of_bytes = "FF D8 FF E0 00 10 4A 46 49 46 00 01"
- $ext = "jpg"
- $byte_array_of_combined_file = [System.IO.File]::ReadAllBytes($combined_file)
- $byte_start_offset = @()
- $ar = $magic_sequence_of_bytes.Split(" ")
- $findindex = 0;
- for ($i = 0 ; $i -lt $byte_array_of_combined_file.Length; $i++)
- {
- $v = '{0:X2}' -f $byte_array_of_combined_file[$i]
- if ($v -eq $ar[$findindex])
- {
- if ($findindex -eq $ar.Count-1)
- {
- Write-Host "Found string magic!" -ForegroundColor Green
- $pos = $i - ($ar.Count-1)
- write-host "$magic_sequence_of_bytes starts at offset" $pos
- $byte_start_offset +=$pos
- }
- $findindex=$findindex+1
- }
- else
- {
- $findindex = 0
- }
- }
- for ($f=0; $f -lt $byte_start_offset.Count; $f++)
- {
- $filenameout = "$output_location$f-recreated.$ext"
- if ($f -eq $byte_start_offset.Count -1)
- {
- $s = $byte_start_offset[$f]
- $e = $byte_array_of_combined_file.Length
- }
- else
- {
- $s = $byte_start_offset[$f]
- $e = ($byte_start_offset[$f+1] -1)
- }
- write-host "Creating file:" $filenameout
- [System.IO.File]::WriteAllBytes($filenameout, $byte_array_of_combined_file[$s..$e])
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement