Created
September 16, 2013 17:35
-
-
Save xcvista/6583906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# IOCCC entry deobfuscator | |
# Copyright (c) 2013 Maxthon Chan <[email protected]> | |
# | |
# This tool tries to deobfuscate code of C programming language using tools from | |
# LLVM project, namely clang and clang-format. | |
# | |
if [ "$1" == "--help" -o "$1" == "-h" -o "$1" == "" ]; then | |
echo IOCCC Entry Deobfuscator, Version 1.0 | |
echo | |
echo USAGE: `basename $0` "<file-names>" ... | |
echo | |
echo Copyright "(c)" 2013 Maxthon T. Chan "<[email protected]>" | |
echo You are free to use, copy, modify and distribute this code. | |
exit 1 | |
fi | |
if [ ! -x "`which clang`" -o ! -x "`which clang-format`" ]; then | |
echo This tool depend on LLVM tools clang and clang-format. | |
exit 1 | |
fi | |
while [ "$1" != "" ]; do | |
SOURCE="$1" | |
EXT="${SOURCE##*.}" | |
NAME="${SOURCE%.*}" | |
# Preserve the headers | |
HEADER="$NAME-preserve.h" | |
cat "$SOURCE" | grep \\#include > "$HEADER" | |
# Remove the include directives | |
DEHEAD="$NAME-nohead.$EXT" | |
cat "$SOURCE" | sed /\\#include/d > "$DEHEAD" | |
# Preprocess the file | |
PREPROCESS="$NAME-preprocessed.$EXT" | |
clang -E "$DEHEAD" -o - | sed /\\#/d > "$PREPROCESS" | |
# Reformat the file | |
REFORMAT="$NAME-reformatted.$EXT" | |
clang-format "$PREPROCESS" > "$REFORMAT" | |
# Rebuild the file | |
RESULT="$NAME-deobfuscated.$EXT" | |
cat "$HEADER" > "$RESULT" | |
cat "$REFORMAT" >> "$RESULT" | |
# Clean up | |
rm "$HEADER" "$DEHEAD" "$PREPROCESS" "$REFORMAT" | |
# Next | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment