import re

def sym2cal(s):
if '>' in s:
return len(s)
else:
return -len(s) def cal(s):
if '+' in s:
return '+= %d'%len(s)
else:
return '-= %d'%len(s) def bf2asm(s,ptr,tab):
p =
l = len(s)
while(p<l):
pattern = re.compile(r'([><]*)\[-([><]*)\[-\]([><]+)\[-\]([><]+)\[-([><]+)\+([><]+)\+([><]+)\]([><]+)\[-([><]+)\+([><]+)\]([><]*)\[-([><]+)\+([><]+)\]([><]*)\]')
match = pattern.match(s[p:])
if match:
p += len(match.group()) groups = match.groups()
ptr1 = ptr + sym2cal(groups[])
ptr2 = ptr1
for i in xrange(,):
ptr2 += sym2cal(groups[i])
ptr3 = ptr2
for i in xrange(,):
ptr3 += sym2cal(groups[i])
print tab+'mem[%d] += mem[%d]*mem[%d]'%(ptr3,ptr2,ptr1) for v in groups:
ptr += sym2cal(v)
continue pattern = re.compile(r'([><]*)\[-\]([><]+)\[-\]([><]+)\[-([><]+)\+([><]+)\+([><]+)\]([><]+)\[-([><]+)\+([><]+)\]([><]*)\[-([><]+)\+([><]+)\]')
match = pattern.match(s[p:])
if match:
p += len(match.group()) groups = match.groups()
ptr1 = ptr
for i in xrange():
ptr1 += sym2cal(groups[i])
ptr2 = ptr1
for i in xrange(,):
ptr2 += sym2cal(groups[i])
print tab+'mem[%d] += mem[%d]'%(ptr2,ptr1) for v in groups:
ptr += sym2cal(v)
continue pattern = re.compile(r'([><]*)\[-\]([><]+)\[-\]([><]+)\[-([><]+)\+([><]+)\+([><]+)\]([><]+)\[-([><]+)\+([><]+)\]([><]+)')
match = pattern.match(s[p:])
if match:
p += len(match.group()) groups = match.groups()
ptr1 = ptr + sym2cal(groups[])
ptr2 = ptr1 + sym2cal(groups[])
ptr3 = ptr2 + sym2cal(groups[])
print tab+'mem[%d] = mem[%d]'%(ptr1,ptr3) for v in groups:
ptr += sym2cal(v)
continue pattern = re.compile(r'\[-\]')
match = pattern.match(s[p:])
if match:
p += len(match.group())
print tab+'mem[%d] = 0'%(ptr)
continue pattern = re.compile(r'>+')
match = pattern.match(s[p:])
if match:
p += len(match.group())
ptr += len(match.group())
continue pattern = re.compile(r'<+')
match = pattern.match(s[p:])
if match:
p += len(match.group())
ptr -= len(match.group())
continue pattern = re.compile(r'\++')
match = pattern.match(s[p:])
if match:
p += len(match.group())
print tab+'mem[%d] %s'%(ptr,cal(match.group()))
continue pattern = re.compile(r'-+')
match = pattern.match(s[p:])
if match:
p += len(match.group())
print tab+'mem[%d] %s'%(ptr,cal(match.group()))
continue c = s[p]
if c == '[':
stk =
for i,v in enumerate(s[p+:]):
if v == '[':
stk +=
elif v == ']':
stk -=
else:
continue
if stk == :
print tab+'while mem[%d]:'%ptr
ptr = bf2asm(s[p+:p++i],ptr,tab+'\t')
p += i+
break
continue elif c == ',':
if input_ptr < :
print tab+'mov mem[%d] input[input_ptr]'%ptr
else:
if bit_add >= :
print tab+'mov mem[%d] 0x30'%ptr
else:
print tab+'mov mem[%d] 1'%ptr
elif c == '.':
print tab+'cmp mem[%d] data[data_ptr]'%ptr
p +=
return ptr s = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[-]<<<<<<<<<<<<<<<<<<<<<<<[-]>>>>>>>>>>>>>>>>>>>>>>[->+<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>]<<<<<<<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>>>>>>>>+<<<<<<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>>>>>>,>>>>>>[-]<<<<<<<<<<<<<<<<<<<<<<<<<<<<[-]>>>>>>>>>>>>>>>>>>>>>>[->>>>>>+<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>]"
input_ptr =
bit_add =
bf2asm(s,,'')

会简化一些代码流程,比如

while mem[]:
mem[] -=
while mem[]:
mem[] -=
while mem[]:
mem[] -=
mem[] +=
mem[] +=
while mem[]:
mem[] -=
mem[] +=

上面这段代码,分析后其实就是

mem[] = mem[]

Brainfuck反汇编-高级版(Python)的更多相关文章

  1. 自定义高级版python线程池

    基于简单版创建类对象过多,现自定义高级版python线程池,代码如下 #高级线程池 import queue import threading import time StopEvent = obje ...

  2. PluginOK中间件高级版-支持在Chrome、Edge、Firefox等浏览器网页中真正内嵌ActiveX等控件运行的版本已获多家上市公司采购

    PluginOK(牛插)中间件(原名:本网通WebRunLocal)是一个实现WEB浏览器(Web Browser)与本地程序(Local Application)之间进行双向调用的低成本.强兼容.安 ...

  3. yii2高级版账号密码问题

    yii2高级版默认后台没有密码,生成账号密码步骤: 1. CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` ...

  4. PHP框架Yii2.0安装(基础版、高级版)

    最近农成也是切入了yiiframework 2.0,就是安装yii2.0就花费了不少的时间,为此做了很多的弯路,特此写一篇博文来给后面学习的同学少走一点的弯路.写的不好的地方欢迎各位学习的同学们能够指 ...

  5. Win7家庭普通版、家庭高级版、专业版、旗舰版版本差别

    刚才我们发了一个大图片:<Windows7.Vista.XP 三大系统功能差异比较一览图>,现在,再发一张对比图片,简要的看看Windows7家庭普通版.家庭高级版.专业版.旗舰版这四个版 ...

  6. 【Win7激活工具2013版下载】适用于旗舰版、家庭高级版等所有版本32/64位 OEM激活

    虽然现在Win8已经发布了,但是身边总是还有一些朋友在用着Win7系统,而近期微软频繁的推送补丁包,导致之前的那些激活都失效了.找了网络上很多工具,之前的那些有的已经不能用了,激活不了,今天就推荐一些 ...

  7. 宣布正式发布 Biz Talk Services、Azure Active Directory 和 Traffic Manager, 同时发布 Azure Active Directory 高级版预览

    除经济优势之外,云计算还在可转化为竞争优势的应用程序开发方面提供了更大的灵活性.我们很高兴看到每天创建的新 Windows Azure 订阅超过 1000 个,更令人兴奋的是,有一半客户使用价值更高的 ...

  8. 希尔排序之C++实现(高级版)

    希尔排序之C++实现(高级版) 一.源代码:ShellSortHigh.cpp /*希尔排序基本思想: 先取一个小于n的整数d1作为第一个增量,把文件的全部记录分组. 所有距离为d1的倍数的记录放在同 ...

  9. 直接插入排序(高级版)之C++实现

    直接插入排序(高级版)之C++实现 一.源代码:InsertSortHigh.cpp /*直接插入排序思想: 假设待排序的记录存放在数组R[1..n]中.初始时,R[1]自成1个有序区,无序区为R[2 ...

随机推荐

  1. vue 百度地图实现标记多个maker,并点击任意一个maker弹出对应的提示框信息, (附: 通过多个地址,标记多个marker 的 方法思路)

    通过点击不同筛选条件,筛选出不同企业所在的地点, 根据每个企业的经纬度 在地图上标记多个maker,点击任意一个maker,会弹出infoWindow 信息窗口: 说明:  因每个人写法不同.需求不同 ...

  2. SQLite中的WHERE子句

    SQLite中的WHERE子句 WHERE子句用于从FROM子句生成的工作表中过滤行.它提供了对每一行进行判断的表达式.当表达式返回的值为false或NULL时,此行就会被丢弃.这种丢弃只是删除记录, ...

  3. C#全能数据库操作类及调用示例

    C#全能数据库操作类及调用示例 using System; using System.Data; using System.Data.Common; using System.Configuratio ...

  4. POJ 2417 Discrete Logging BSGS

    http://poj.org/problem?id=2417 BSGS 大步小步法( baby step giant step ) sqrt( p )的复杂度求出 ( a^x ) % p = b % ...

  5. 潭州课堂25班:Ph201805201 爬虫基础 第四课 Requests (课堂笔记)

    优雅到骨子里的Requests   1528811134432   简介   上一篇文章介绍了Python的网络请求库urllib和urllib3的使用方法,那么,作为同样是网络请求库的Request ...

  6. 基于Python的SQLAlchemy的操作

    安装 在Python使用SQLAlchemy的首要前提是安装相应的模块,当然作为python的优势,可以到python安装目录下的scripts下,同时按住shift+加上鼠标左键,从而在菜单中打开命 ...

  7. Automatic overvoltage protection

    In most cases the voltage that is induced in the coil can not exceed 6V, and it does not have risk t ...

  8. Ubuntu GNOME 13.04将关闭窗口的按钮放在最右边

    转载请注明:转自http://blog.csdn.net/u010811449/article/details/9426187 先上图: 首先打开dconf系统配置编译器. 找到 rog -> ...

  9. Linux C Socket TCP编程介绍及实例

    转自:https://blog.csdn.net/lell3538/article/details/53335231 { printf("向服务器发送数据:%s\n",sendbu ...

  10. Linux 保护文件 不给修改

    chatter +i  file 文件不能删除,不能更改,不能移动 chatter -i  file  恢复 lsattr file 查看 ----i--------e-- file 修改会提示: f ...