Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite of unicode scanner and renaming of file #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions usr/bin/grep-find-unicode-wrapper

This file was deleted.

39 changes: 39 additions & 0 deletions usr/bin/scan-text-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
## Copyright (C) 2022 - 2023 ENCRYPTED SUPPORT LP <[email protected]>
## See the file COPYING for copying conditions.

## Search pattern for suspicious characters by negation of allowed characters
SEARCH_PATTERN='[^[:ascii:]]|[\x{061C}\x{200E}\x{200F}\x{202A}\x{202B}\x{202C}\x{202D}\x{202E}\x{2066}\x{2067}\x{2068}\x{2069}]'

found=0
## Loop over input files
while [ "$#" -gt 0 ]; do
current_file="$1"
contains_suspicious_characters=$(LC_ALL=C perl -nle "print \$ARGV if /$SEARCH_PATTERN/" "$current_file")

echo "==================="
echo "File: $current_file"

if [ -n "$contains_suspicious_characters" ]; then
found=1
echo "-- Warning : Suspicious characters were found"
## Printing out suspicious characters in Unicode escape sequence \u... with their line and position
perl -C -ne "while (/$SEARCH_PATTERN/g) {
printf \"Line %d, Position %d: \\\u%04x\n\", \$., \$-[0] + 1, ord(\$&);
}" "$current_file"
else
echo "++ OK : No suspicous characters were found"
fi

## Remove the processed filename from the list of arguments to satisfy while loop
shift
done

if [ $found -ne 0 ]; then
echo -e "-------------------\n-------------------"
echo "NOTE: For safety reasons these characters are shown in their Unicode escape sequence '\u...'. To inspect these characters search a 'Unicode character inspector' online and paste the Unicode escape sequence there"
exit 1
fi

exit 0