---
tags: decompiler
---
# Changing Control flows
List of all changing control flows with different decompylers
# Concise MWES
## `else` in `try/except`:
Python: 3.8
Decompiler: Uncompyle6 - Decompyle3
```python
def nextUid():
try:
pass
except z:
raise "errr"
return x
```
Changes to:
```python
def nextUid():
try:
pass
except z:
raise 'errr'
else:
return x
```
## `else` in `for`:
Python: 3.8
Decompiler: Uncompyle6 - Decompyle3
```python
def copy_original_checksum():
for replaced in l:
x = False
z=z
```
Changes to:
```python
def copy_original_checksum():
for replaced in l:
x = False
else:
z = z
```
## Add nested `try/except` with `except X as Y`
Python: 3.8 - 3.7
Decompiler: Uncompyle6 - Decompyle3
:::info
This only works with `as` added to `except`. Without it, it deocmpiles fine.
:::
```python
def GetProteinData():
try:
pass
except Exception as e:
x = x + 1
```
Changes to:
```python
def GetProteinData():
try:
pass
except Exception as e:
try:
x = x + 1
finally:
e = None
del e
```
## Remove `while` loop inside loop
Python 3.8
Decompiler: Uncompyle6
```pyhton
def GetTargetDiseases():
for id_this in ids:
while a: # must be while loop
z=z
a=a.b() # anything and any number of instructions
z=z # optional
if cond2: break # must have condition
z=z # must have instruction
```
Changes to:
```python
def GetTargetDiseases():
for id_this in ids:
if a: # While loop removed
a = a.b()
z = z
else:
z = z # remaining instructions dumped here
if cond2:
break # HOW???
z = z
```
## Breaking `while` loop conditions:
Python: 3.7-3.8
Decompiler: Uncompyle6-Decompyle3
:::info
Regardless of the number of conditions in while loop, the only one condition remains and the rest are nested inside the loop
:::
```pyhton
def _kafka_main_consumer():
while a or b:
continue
def _kafka_main_consumer():
while a or b or c and d:
continue
```
Changes to =>
```python
def _kafka_main_consumer():
while not a:
if b:
continue
def _kafka_main_consumer():
while not a:
if not b:
if c:
if d:
continue
```
# Anomalies:
## 1. internal decompiler error
The following code throws an internal decompiler error not reported directly in python 3.8 uncompyle6.
```python
def copy_original_checksum():
for replaced in l:
x = False
try:
pass
except:
x = True
if x:
continue
```
Gives the following:
```python
def copy_original_checksum():
for replaced in l:
x = False
try:
pass
except:
x = True
else:
if x:
continue
# NOTE: have internal decompilation grammar errors.
# Use -t option to show full context.
# not in loop:
# continue
# L. 9 38 CONTINUE 4 'to 4'
```
# Original
## MWE 1:
Python 3.8
Original:
```python=
def nextUid():
try:
pass
except z:
raise "errr"
return x
```
Decompiles to:
```python=
def nextUid():
try:
pass
except z:
raise 'errr'
else:
return x
```
## MWE 2:
Python 3.8
Original:
```python=
def copy_original_checksum():
for replaced in l:
x = False
try:
pass
except:
x = True
if x:
continue
```
Decompiles to:
```python=
def copy_original_checksum():
for replaced in l:
x = False
try:
pass
except:
x = True
else:
if x:
continue
```
## ~~MWE 3:~~
Python 3.7
Original:
```python=
def Drug2Targets():
for cid in cids:
try:
pass
except Exception as e:
continue
```
Decompiles to:
```python=
def Drug2Targets():
for cid in cids:
try:
pass
except Exception as e:
try:
continue
finally:
e = None
del e
```
## MWE 4:
Python 3.8:
Original:
```python=
def DrugTargetPaths():
for cid in cids:
for tid in tids:
if odir and graphml.strip():
if not fout_graphml: logging.error('Failed to open output file: %s'%ofile_graphml)
logging.info('%s'%ofile_graphml)
x = x + 1
x = x + 1
x = x + 1
if tid_nmax and n_tid>=tid_skip+tid_nmax: break
```
Decompiles to:
```python=
def DrugTargetPaths():
for cid in cids:
for tid in tids:
if odir:
if graphml.strip():
if not fout_graphml:
logging.error('Failed to open output file: %s' % ofile_graphml)
logging.info('%s' % ofile_graphml)
else:
x = x + 1
x = x + 1
x = x + 1
if tid_nmax:
if n_tid >= tid_skip + tid_nmax:
break
```
## MWE 5:
Python 3.8:
Orginal:
```python=
def GetProteinData():
temp = None
try:
pass
except Exception as e:
x = x + 1
temp = []
if temp != None: return temp
```
Decompiles to:
```python=
def GetProteinData():
temp = None
try:
pass
except Exception as e:
try:
x = x + 1
temp = []
finally:
e = None
del e
else:
if temp != None:
return temp
```
## MWE6:
Python 3.8:
Orginal:
```python=
def ListCompounds():
tmp = False
try:
pass
except Exception as e:
tmp = True
if tmp: return
```
Decompiles to:
```python=
def ListCompounds():
tmp = False
try:
pass
except Exception as e:
try:
tmp = True
finally:
e = None
del e
else:
if tmp:
return
```
## MWE7:
Python 3.8:
Original:
```python=
def GetTargetDiseases():
for id_this in ids:
if conda and condb: continue
while True:
a.b()
if cond1 and cond2: break
x()
```
Decompiles to:
```python=
def GetTargetDiseases():
for id_this in ids:
if conda and condb:
pass
else:
a.b()
else:
if cond1 and cond2:
break
x()
```
## ~~MWE8:~~
Python : 3.8
Original:
```python=
def minify():
for item in token_generator:
tmp = a and b
if tmp:
if c or d or e :
z = z
else:
z = z
```
Decompiled:
```python=
def minify():
for item in token_generator:
tmp = a and b
if not tmp or c or d or e:
z = z
else:
z = z
```
## MWE9:
Python : 3.8
Original:
```python=
def _kafka_main_consumer():
while (a or b or c) and d:
continue
```
Decompiled:
```python=
def _kafka_main_consumer():
while not a:
if b or c:
if d:
continue
```