版本比较
【工程】代码混淆
正文
增加 54 行删除 54 行
24 行未改动252627282929303132335 行未改动3940414243434445464647484950515253545455565758595960616263646566676869697071727374757576777879808081828384858686878889909192929394959596979899991001011021031031041051061071081081091101111111121131141151161171171181191201201211221231241251251261271281291291301311321339 行未改动14314414514614714714814914915015115215364 行未改动2182192202212222222232242252262272282282292302312322332342352352362372382399 行未改动2492502512522532532542552562562572582592603 行未改动2642652662672682682692702712722 行未改动2752762772782792792802812822833 行未改动2872882892902912912922932942955 行未改动30130230330430530530630730830931031131231331331431531631731831831932032132224 行未改动34734834935035135135235335435549 行未改动40540640740840940941041141241241341441541621 行未改动4384394404414424424434444454468 行未改动4554564574584594594604614624638 行未改动47247347447547647647747847948026 行未改动50750850951051151151251351451551651751751851952052114 行未改动5365375385395405405415425435447 行未改动5525535545555565565575585595605605615625625635645655665675685695695705715725732 行未改动57657757857958058058158258358410 行未改动59559659759859959960060160260310 行未改动61461561661761861861962062162225 行未改动6486496506516526526536546556566576586596606606616626636647 行未改动6726736746756766766776786796806 行未改动68768868969069169169269369469469569669769869869970070170270324 行未改动// 保留标识符集合(关键字 + 常用标准库名称 + 宏)// 可根据需要自行扩充// ----------------------------------------------------------------------static const std::unordered_set<std::string> keywords = {
"alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char8_t", "char16_t", "char32_t", "class", "compl", "concept", "const", "consteval", "constexpr", "constinit", "const_cast", "continue", "contract_assert",5 行未改动 "requires", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "synchronized", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq",
// ========== 标准库命名空间 ========== "std",
// ========== 核心容器 ========== "array", "vector", "deque", "list", "forward_list", "set", "map", "multiset", "multimap", "unordered_set", "unordered_map", "unordered_multiset", "unordered_multimap", "stack", "queue", "priority_queue", "pair", "tuple", "optional", "variant", "any", "bitset", "valarray",
// ========== 迭代器 ========== "iterator", "back_inserter", "front_inserter", "inserter", "reverse_iterator", "istream_iterator", "ostream_iterator", "begin", "end", "advance", "next", "prev", "distance",
// ========== 算法(常用) ========== "for_each", "count", "find", "search", "copy", "move", "transform", "replace", "remove", "reverse", "rotate", "fill", "partition", "sort", "stable_sort", "partial_sort", "nth_element", "lower_bound", "upper_bound", "binary_search", "merge", "includes", "set_union", "set_intersection", "set_difference", "make_heap", "push_heap", "pop_heap", "sort_heap", "min", "max", "minmax", "min_element", "max_element", "equal", "lexicographical_compare", "is_permutation", "next_permutation", "prev_permutation", "all_of", "any_of", "none_of",
// ========== 字符串与字符处理 ========== "string", "wstring", "u16string", "u32string", "string_view", "to_string", "stoi", "stol", "stod", "isalnum", "isalpha", "isdigit", "isspace", "toupper", "tolower", "strcpy", "strncpy", "strcat", "strncat", "strcmp", "strlen", "strstr", "strchr",
// ========== 数学与数值 ========== "abs", "sqrt", "pow", "sin", "cos", "log", "ceil", "floor", "round", "complex", "numeric_limits", "ratio", "random_device", "mt19937", "uniform_int_distribution", "uniform_real_distribution", "normal_distribution",
// ========== 输入/输出流 ========== "cin", "cout", "cerr", "clog", "wcin", "wcout", "wcerr", "wclog", "ifstream", "ofstream", "fstream", "istringstream", "ostringstream", "stringstream", "endl", "flush", "boolalpha", "hex", "setprecision", "setw", "setfill", "istream", "ostream", "iostream",
// ========== 函数对象与工具 ========== "function", "bind", "ref", "cref", "plus", "minus", "multiplies", "divides", "modulus", "negate", "less", "greater", "less_equal", "greater_equal", "equal_to", "not_equal_to", "logical_and", "logical_or", "logical_not", "bit_and", "bit_or", "bit_xor",
// ========== 内存管理 ========== "shared_ptr", "unique_ptr", "weak_ptr", "allocator", "addressof",
// ========== 时间与日期 ========== "chrono", "system_clock", "steady_clock", "high_resolution_clock", "duration", "time_point", "time", "localtime", "strftime",
// ========== 错误与异常处理 ========== "exception", "runtime_error", "logic_error", "bad_alloc", "out_of_range", "error_code", "error_condition", "system_error", "assert",
// ========== 并发支持 ========== "thread", "this_thread", "mutex", "recursive_mutex", "timed_mutex", "lock_guard", "unique_lock", "condition_variable", "atomic", "future", "promise", "async", "packaged_task",
// ========== 正则表达式 ========== "regex", "smatch", "regex_match", "regex_search", "regex_replace",
// ========== 元编程与类型支持 ========== "is_integral", "is_floating_point", "is_same", "remove_const", "remove_pointer", "enable_if", "conditional", "decay", "declval", "int8_t", "int16_t", "int32_t", "int64_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t", "type_index", "type_info",
// ========== 范围库 (C++20) ========== "ranges", "views", "filter", "transform", "take", "drop",
// ========== C 库函数(常见) ========== "malloc", "free", "calloc", "realloc", "exit", "abort", "system", "printf", "scanf", "fprintf", "fscanf", "sprintf", "sscanf", "fopen", "fclose", "fread", "fwrite", "fgetc", "fputc", "fgets", "fputs",
"static", "const", "std", "unordered_set", "unordered_map", "string", "vector", "size_t", "substr", "push_back", "reserve", "begin", "end", "find", "sync_with_stdio", "tie", "istreambuf_iterator", "cout", "cin",
// 类型与命名空间 "ios", // 成员函数 "size", "second", "find_if", "istreambuf_iterator",9 行未改动 "open", "close", "is_open", "precision", "width", "fill", "setf", "unsetf", "join", "detach", "lock", "unlock", "try_lock", "get", "reset", "release", "use_count", "unique",
"main",
// 常用标准库函数 "getchar", "putchar", "getc", "putc", "ungetc", // 标准库类型别名 "size_t", "ptrdiff_t", "nullptr_t",64 行未改动 "set_difference", "set_symmetric_difference", "make_heap", "push_heap", "pop_heap", "sort_heap", "min", "max", "minmax", "min_element", "max_element", "minmax_element", "equal", "lexicographical_compare", "is_permutation", "next_permutation", "prev_permutation", "all_of", "any_of", "none_of",
// 标准宏(通常在预处理阶段已展开,但为避免替换,加入保留集) "EOF", "NULL", "BUFSIZ", "FILENAME_MAX", "FOPEN_MAX", "TMP_MAX", "L_tmpnam", "SEEK_CUR", "SEEK_END", "SEEK_SET", "EXIT_SUCCESS", "EXIT_FAILURE", "RAND_MAX", "CLOCKS_PER_SEC", "EDOM", "ERANGE", "EILSEQ",
// 流操作符(iomanip) "fixed", "scientific", "hexfloat", "defaultfloat", "setprecision", "setw", "setfill", "setbase", "left", "right", "internal", "showbase", "noshowbase", "showpoint", "noshowpoint", "showpos", "noshowpos", "uppercase", "nouppercase", "unitbuf", "nounitbuf",
// 其他常用标准库名称 "endl", "ends", "flush", "boolalpha", "noboolalpha", "hex", "dec", "oct", "ws", "skipws", "noskipws", // C++ 关键字9 行未改动 "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq",
// 标准库命名空间 "std",
// 常用类型 "string", "vector", "unordered_set", "unordered_map", "array", "list", "deque", "forward_list", "set", "map", "multiset", "multimap", "pair", "tuple", "optional", "variant", "any", "bitset", "valarray", "complex",3 行未改动 "mt19937", "uniform_int_distribution", "uniform_real_distribution", "chrono", "duration", "time_point", "system_clock", "steady_clock", "regex", "smatch", "thread", "mutex", "condition_variable", "atomic", "future", "promise", "async", "packaged_task",
// 常用函数 "getchar", "putchar", "getc", "putc", "ungetc", "getchar", "putchar", "printf", "scanf", "fprintf", "fscanf", "sprintf", "sscanf", "fopen", "fclose", "fread", "fwrite", "fgetc", "fputc", "fgets", "fputs",2 行未改动 "asin", "acos", "atan", "atan2", "exp", "log", "log10", "ceil", "floor", "round", "isalnum", "isalpha", "isdigit", "isspace", "toupper", "tolower", "strcpy", "strncpy", "strcat", "strncat", "strcmp", "strncmp", "strlen", "strchr", "strstr", "memcpy", "memmove", "memset",
// 常用成员函数 "size", "length", "empty", "clear", "reserve", "capacity", "substr", "find", "rfind", "find_first_of", "find_last_of", "c_str", "data", "copy", "compare", "replace", "insert", "erase", "push_back", "pop_back",3 行未改动 "lock", "unlock", "try_lock", "wait", "notify_one", "notify_all", "load", "store", "exchange", "compare_exchange_weak", "open", "close", "is_open", "rdbuf", "sync_with_stdio", "tie", "good", "fail", "bad", "eof", "precision", "width", "fill", "setf", "unsetf",
// 算法函数 "for_each", "count", "count_if", "find", "find_if", "find_end", "find_first_of", "search", "search_n", "copy", "copy_if", "copy_n", "move", "transform", "replace", "replace_if", "remove", "remove_if",5 行未改动 "pop_heap", "sort_heap", "min", "max", "minmax", "min_element", "max_element", "minmax_element", "equal", "lexicographical_compare", "is_permutation", "next_permutation", "prev_permutation", "all_of", "any_of", "none_of",
// 流操作符 "fixed", "scientific", "hexfloat", "defaultfloat", "setprecision", "setw", "setfill", "setbase", "left", "right", "internal", "showbase", "noshowbase", "showpoint", "noshowpoint", "showpos", "noshowpos", "uppercase", "nouppercase", "unitbuf", "nounitbuf", "endl", "ends", "flush", "boolalpha", "noboolalpha", "hex", "dec", "oct", "ws", "skipws", "noskipws",
// 宏 "EOF", "NULL", "BUFSIZ", "FILENAME_MAX", "FOPEN_MAX", "TMP_MAX", "L_tmpnam", "SEEK_CUR", "SEEK_END", "SEEK_SET", "EXIT_SUCCESS", "EXIT_FAILURE", "RAND_MAX", "CLOCKS_PER_SEC", "EDOM", "ERANGE", "EILSEQ",
// 其他常用 "main", "size_t", "ptrdiff_t", "nullptr_t", "int8_t", "int16_t", "int32_t", "int64_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t", "first", "second"24 行未改动std::string removeComments(const std::string& code) { std::string result; size_t i = 0; const size_t n = code.size();
while (i < n) { if (code[i] == '"') { result += code[i++]; while (i < n) {49 行未改动 std::string result; size_t i = 0; const size_t n = code.size(); std::unordered_map<std::string, std::string> idMap;
// 辅助函数:判断字符是否为空白(非换行) auto isSpace = [](char ch) { return std::isspace(static_cast<unsigned char>(ch)) && ch != '\n'; };
while (i < n) { // 预处理指令检测:跳过行首空白,判断是否为 '#' size_t line_start = i; while (line_start < n && isSpace(code[line_start])) ++line_start;21 行未改动 } i = line_end; continue; }
// 字符串字面量 if (code[i] == '"') { result += code[i++]; while (i < n) {8 行未改动 } } continue; }
// 字符常量 if (code[i] == '\'') { result += code[i++]; while (i < n) {8 行未改动 } } continue; }
// 数字字面量 if (std::isdigit(static_cast<unsigned char>(code[i])) || (code[i] == '.' && i+1 < n && std::isdigit(static_cast<unsigned char>(code[i+1])))) { size_t start = i;26 行未改动 (code[i] == 'l' || code[i] == 'L'))) ++i; result += code.substr(start, i - start); continue; }
// 标识符 if (std::isalpha(static_cast<unsigned char>(code[i])) || code[i] == '_') { size_t start = i; while (i < n && (std::isalnum(static_cast<unsigned char>(code[i])) || code[i] == '_')) ++i; std::string ident = code.substr(start, i - start);
// 先查 idMap(包含宏名和已映射的用户标识符) auto it = idMap.find(ident); if (it != idMap.end()) { result += it->second;14 行未改动 idMap[ident] = newName; result += newName; continue; }
// 其他字符 result += code[i++]; } return result;7 行未改动 ">>=", "<<=", "->*", ".*", "::", "++", "--", "->", "&&", "||", "<<", ">>", "<=", ">=", "==", "!=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "##" };
std::vector<std::string> tokens; size_t i = 0; const size_t n = code.size();
auto isSpace = [](char ch) { return std::isspace(static_cast<unsigned char>(ch)); };
while (i < n) { // 跳过空白 if (isSpace(code[i])) { ++i; continue; }
// 预处理指令整行作为一个 token size_t line_start = i; while (line_start < n && isSpace(code[line_start]) && code[line_start] != '\n') ++line_start; if (line_start < n && code[line_start] == '#') {2 行未改动 tokens.push_back(code.substr(line_start, line_end - line_start)); i = line_end; continue; }
// 字符串字面量 if (code[i] == '"') { size_t start = i; ++i;10 行未改动 } tokens.push_back(code.substr(start, i - start)); continue; }
// 字符常量 if (code[i] == '\'') { size_t start = i; ++i;10 行未改动 } tokens.push_back(code.substr(start, i - start)); continue; }
// 数字字面量 if (std::isdigit(static_cast<unsigned char>(code[i])) || (code[i] == '.' && i+1 < n && std::isdigit(static_cast<unsigned char>(code[i+1])))) { size_t start = i;25 行未改动 (code[i] == 'l' || code[i] == 'L'))) ++i; tokens.push_back(code.substr(start, i - start)); continue; }
// 标识符 if (std::isalpha(static_cast<unsigned char>(code[i])) || code[i] == '_') { size_t start = i; while (i < n && (std::isalnum(static_cast<unsigned char>(code[i])) || code[i] == '_')) ++i; tokens.push_back(code.substr(start, i - start)); continue; }
// 多字符操作符 bool matched = false; for (const auto& op : multiOps) { if (i + op.size() <= n && code.substr(i, op.size()) == op) {7 行未改动 tokens.push_back(std::string(1, code[i])); ++i; } }
std::string result; for (const auto& tok : tokens) { result += tok; result += '\n';6 行未改动// ----------------------------------------------------------------------int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
std::string code((std::istreambuf_iterator<char>(std::cin)), std::istreambuf_iterator<char>());
code = removeComments(code); code = replaceIdentifiers(code); code = tokenizeAndInsertNewlines(code);
std::cout << code; return 0;}``:::