zoukankan      html  css  js  c++  java
  • 有趣的c++代码混淆【python源码】

    有趣的c++代码混淆【python源码】

    import random
    import string
    
    keyword_list = ['cout', '+=', '-=', 'int ', 'goto', 'asm', 'do', 'if', '[', ']',
                    'return', 'typedef', 'auto', 'double', 'inline', '{', '}',
                    'short', 'typeid', 'bool', 'int ', '(', ')',
                    'signed', 'typename', 'break', 'else', '>=', '<=',
                    'sizeof', 'union', 'case', 'enum', 'mutable', ';',
                    'static', 'unsigned', 'catch', 'explicit', 'try',
                    'namespace', 'using', 'char', 'main', 'const',
                    'export', 'new', 'struct', 'class', 'switch',
                    'false', 'private', 'long', '::', 'void', 'endl',
                    'float', 'protected', 'this', 'continue', '++', '--',
                    'for', 'public', 'throw', 'while', 'default', 'friend',
                    'true', '<<', 'cin', 'printf', '==', '>>', '!=', ]
    
    
    def random_char():
        r = chr(random.randint(97, 122))
        char, char_r, list_chr = [], [], []
        for i in range(len(keyword_list)):
            char.append(r + str(i))
            char_r.append(keyword_list[i])
        random.shuffle(char)
        random.shuffle(char_r)
        for i in range(len(char)):
            list_chr.append([char[i], char_r[i]])
        return list_chr
    
    
    def generate_define(list_chr):
        define = []
        for i in range(len(list_chr)):
            define.append('#define ' + list_chr[i][0] + ' ' + list_chr[i][1])
        return define
    
    
    def replace(list_char, str, confusion):
        if confusion == ' /**/ ':
            confusion = ' /*' + ''.join(random.sample(string.hexdigits, 6)) + '*/ '
        for i in list_char:
            if i[1] in str:
                str = str.replace(i[1], confusion + i[0] + confusion)
        return str
    
    
    def open_file(list_char):
        cpp = input('请输入一个C++代码的文件名:')
        confusion = input('请输入混淆注释(可选,不填则随机混淆):')
        confusion = ' /*' + confusion + '*/ '
        filenmae = cpp.split('.')[0] + '混淆.cpp'
        with open(cpp, 'r') as f:
            with open(filenmae, 'w') as m:
                define = generate_define(list_char)
                for i in define:
                    m.write(i + '
    ')
                for i in f.readlines():
                    if '#' in i[0]:
                        m.write(i)
                        continue
                    i = i.strip()
                    i_replace = replace(list_char, i, confusion)
                    m.write(i_replace + '
    ')
                print('混淆代码完成了哦^_^!
    混淆后的文件名为: ' + filenmae + '
    ')
    
    
    if __name__ == '__main__':
        print('-' * 60)
        print('          C++ 代码混淆工具beta版        Author By: Zgao
    ')
        print('                  tips: cpp代码和该软件需在同一目录下
    ')
        print('-' * 60)
        while True:
            open_file(random_char())
    
    ---- suffer now and live the rest of your life as a champion ----
  • 相关阅读:
    在Fragment中保存WebView状态
    Code First下迁移数据库更改
    脚本解决.NET MVC按钮重复提交问题
    1.1C++入门 未完待续。。。
    0.0C语言重点问题回顾
    12F:数字变换
    12G:忍者道具
    12D:迷阵
    12C:未名冰场
    12B:要变多少次
  • 原文地址:https://www.cnblogs.com/popodynasty/p/14527872.html
Copyright © 2011-2022 走看看