#! /bin/sh
-# deblob-check version 2009-03-17
+# deblob-check version 2009-03-18
# Inspired in gNewSense's find-firmware script.
# Written by Alexandre Oliva <lxoliva@fsfla.org>
# context around the blobs.
# -X --print-all-matches: print all blobs, be they known false
-# positives or blobs.
+# positives or actual blobs.
# -x --list-all-matches: list files that contain sequences that appear
# to be blobs, be they known false positives or not.
# -p --mark-false-positives: print the processed input, replacing
-# sequences that match the blob detector test, but that
-# are known to be false positives, with /*(DEBLOBBED)*/.
+# sequences that match the blob detector test, even those
+# known to be false positives, with /*(DEBLOBBED)*/.
# -P --list-false-positives: list files that contain false positives.
# Regular expression that matches one or more blobs without
# intervening line breaks.
- sblobctx="\\([^\\n]*$bloblong\\)\\+"
+ sblobctx="\\(\([^\\n]\|[/][*](DEBLOB-\\nBED)[*][/]\)*$bloblong\\)\\+"
# Regular expression that matches the context for a long blob match.
lblobctx="\\($initblob\\|$defineblob\\|$asmblob\\|$sblobctx\\)"
# This is tricky. We don't want to print the false positive.
/^$falsepos[^\\n]*$blobfast/ {
$v:delete false positive immediately followed by blob
+ s/^\\($falsepos\\)/\\1\/*(DEBLOB-\\nBED)*\//;
h;
s/^\\($falsepos\\).*/\\1/;
$v:matched false positive
G;
b print_blobs_delete_to_eol;
}
- s/^$falsepos//;
- b print_blobs_delete_to_eol;
+ /^$falsepos[/][*](DEBLOB-\\nBED)[*][/]/! {
+ s/^$falsepos//;
+ b print_blobs_delete_to_eol;
+ }
}
-/^[^\\n]*$blobfast/! {
+/^\([^\\n]\|[/][*](DEBLOB-\\nBED)[*][/]\)*$blobfast/! {
$v:delete non-blob header
h;
s/[\\n]\\($falsepos\\|[^\\n]*$blobfast\\).*//;
x;
b print_blobs_delete_to_eol;
}
-h;
i\\
::: $file :::
+: print_blobs_output_false_positive;
+/[^\\n]*[/][*](DEBLOB-[\\n]BED)[*][/]/ {
+ P;
+ s,^[^\\n]*[\\n],,
+ b print_blobs_output_false_positive;
+}
+h;
s/^\\([^\\n]*\\($bloblong[^\\n]*\\)\\+\\)\\([\\n].*\\)\\?$/\\1/;
$v:narrowed to blob
p;
# This is tricky. We don't want to print the false positive.
/^$falsepos[^\\n]*$blobfast/ {
$v:delete false positive immediately followed by blob
+ s/^\\($falsepos\\)/\\1\/*(DEBLOB-\\nBED)*\//;
h;
s/^\\($falsepos\\).*/\\1/;
$v:matched false positive
G;
b print_marked_blobs_delete_to_eol;
}
- s/^falsepos//;
- b print_marked_blobs_delete_to_eol;
+ /^$falsepos[/][*](DEBLOB-\\nBED)[*][/]/! {
+ s/^falsepos//;
+ b print_marked_blobs_delete_to_eol;
+ }
}
-/^[^\\n]*$blobfast/! {
+/^\([^\\n]\|[/][*](DEBLOB-\\nBED)[*][/]\)*$blobfast/! {
$v:delete non-blob header
h;
s/[\\n]\\($falsepos\\|[^\\n]*$blobfast\\).*//;
x;
b print_marked_blobs_delete_to_eol;
}
-h;
i\\
::: $file :::
+: print_marked_blobs_output_false_positive;
+/[^\\n]*[/][*](DEBLOB-[\\n]BED)[*][/]/ {
+ P;
+ s,^[^\\n]*[\\n],,
+ b print_marked_blobs_output_false_positive;
+}
+h;
s/^\\([^\\n]*\\($bloblong[^\\n]*\\)\\+\\)\\([\\n].*\\)\\?$/\\1/;
$v:narrowed to blob
s/{\\($sepx\\)\\?$blobfseq\\($sepx\\)\\?}[ ]*;/{\/*(DEBLOBBED)*\/};/g;
# This is tricky. We don't want to print the false positive.
/^$falsepos[^\\n]*$blobfast/ {
$v:delete false positive immediately followed by blob
+ s/^\\($falsepos\\)/\\1\/*(DEBLOB-\\nBED)*\//;
h;
s/^\\($falsepos\\).*/\\1/;
$v:matched false positive
G;
b print_cblobs_delete_to_eol;
}
- s/^$falsepos//;
- b print_cblobs_delete_to_eol;
+ /^$falsepos[/][*](DEBLOB-\\nBED)[*][/]/! {
+ s/^$falsepos//;
+ b print_cblobs_delete_to_eol;
+ }
}
/^$lblobctx/! {
$v:delete non-blob header
x;
b print_cblobs_delete_to_eol;
}
-h;
i\\
::: $file :::
+: print_cblobs_output_false_positive;
+/[^\\n]*[/][*](DEBLOB-[\\n]BED)[*][/]/ {
+ P;
+ s,^[^\\n]*[\\n],,
+ b print_cblobs_output_false_positive;
+}
+h;
s/^\\($lblobctx[^\\n]*\\($bloblong[^\\n]*\\)*\\)\\([\\n].*\\)\\?$/\\1/;
$v:narrowed to blob
p;
# This is tricky. We don't want to print the false positive.
/^$falsepos[^\\n]*$blobfast/ {
$v:delete false positive immediately followed by blob
+ s/^\\($falsepos\\)/\\1\/*(DEBLOB-\\nBED)*\//;
h;
s/^\\($falsepos\\).*/\\1/;
$v:matched false positive
G;
b print_marked_cblobs_delete_to_eol;
}
- s/^$falsepos//;
- b print_marked_cblobs_delete_to_eol;
+ /^$falsepos[/][*](DEBLOB-\\nBED)[*][/]/! {
+ s/^$falsepos//;
+ b print_marked_cblobs_delete_to_eol;
+ }
}
/^$lblobctx/! {
$v:delete non-blob header
x;
b print_marked_cblobs_delete_to_eol;
}
-h;
i\\
::: $file :::
+: print_marked_cblobs_output_false_positive;
+/[^\\n]*[/][*](DEBLOB-[\\n]BED)[*][/]/ {
+ P;
+ s,^[^\\n]*[\\n],,
+ b print_marked_cblobs_output_false_positive;
+}
+h;
s/^\\($lblobctx[^\\n]*\\($bloblong[^\\n]*\\)*\\)\\([\\n].*\\)\\?$/\\1/;
$v:narrowed to blob
s/{\\($sepx\\)\\?$blobfseq\\($sepx\\)\\?}[ ]*;/{\/*(DEBLOBBED)*\/};/g;
# This is tricky. We don't want to deblob the false positive.
/^$falsepos[^\\n]*$blobfast/ {
$v:print false positive immediately followed by blob
+ s/^\\($falsepos\\)/\\1\/*(DEBLOB-\\nBED)*\//;
h;
- s/^\\($falsepos\\)[^\\n]*$blobfast.*/\\1/;
+ s/^\\($falsepos\\).*/\\1/;
: list_blobs_match_loop
/[\\n]/ {
P;
fi
set "$@" "$cmd"
- test $# != 1 || set "$@" "cat"
+ sedunbreak='
+: restart;
+/[/][*](DEBLOB-$/ {
+ N;
+ s,[/][*](DEBLOB-[\n]BED)[*][/],,
+ b restart;
+}'
+ cmd='sed "$sedunbreak"'
+ set "$@" "$cmd"
+
+ # test $# = 1 || set "$@" "cat"
shift # fnord goes out here