---
# System prepended metadata

title: Perturbing Rules
tags: [comp-decomp]

---

---
tags: comp-decomp
title: Perturbing Rules
---

# Rule 1: Extending Variable

## 1a. Adding methods

Change:
```
foo
```
to 
```
foo.bar()
```

disassmebly:
```
0    LOAD_NAME
2    LOAD_METHOD
4    CALL_METHOD
6    POP_TOP
```

### 1a-(i). Adding methods args

Change:
```
foo.bar()
```
to 
```
foo.bar(arg)
```

disassmebly:
```
0    LOAD_NAME
2    LOAD_METHOD
4    LOAD_NAME
6    CALL_METHOD
8    POP_TOP
```

## 1b. Adding attribute

Change:
```
foo
```
to 
```
foo.bar
```

disassmebly:
```
0 LOAD_NAME               27 (sys)
2 LOAD_ATTR               28 (platform)
```

## 1c. Storing variable

Change:
```
foo
```
to 
```
bar = foo
```

disassmebly:
```
0 LOAD_NAME               
2 STORE_NAME             
```

## 1d. Converting to function
Change:
```
foo
```
to 
```
foo()
```

disassmebly:
```
0 LOAD_NAME               
2 CALL_FUNCTION
4 POP_TOP
```
### 1d-(i). Adding arguments

Change:
```
foo()
```
to 
```
foo(arg)
```

disassmebly:
```
0 LOAD_NAME 
2 LOAD_NAME 
4 CALL_FUNCTION
6 POP_TOP
```
### 1d-(ii). Removing arguments

Change:
```
foo(arg)
```
to 
```
foo()
```

disassmebly:
```
2 LOAD_NAME 
4 CALL_FUNCTION
6 POP_TOP
```

## 1e. Removing methods

Change:
```
foo.bar()
```
to 
```
foo
```

disassmebly:
```
0    LOAD_NAME
2    POP_TOP
```

# Rule 2: Extending Tuple

## 2a. Adding to tuple
Change:
```
(foo)
```
to 
```
(foo, bar)
```

disassmebly:
```
0 LOAD_NAME   
2 LOAD_NAME
4 BUILD_TUPLE             
```

# Rule 3: Exception blocks

## 3a. Creating Exception block:
Change:
```
```
to
```
try:
    pass
except:
    pass
```

## 3b. Changing Exception type:
Change
```
except:
```
to
```
except TypeError:
```
disassembly:
```
 68 DUP_TOP
 70 LOAD_NAME               14 (Exception)
 72 COMPARE_OP              10 (exception match)
 74 POP_JUMP_IF_FALSE       94
 76 POP_TOP
 78 POP_TOP
 80 POP_TOP
```

# Rule 4: Converting imports

## 4a. Adding `import *`
Change
```
import ctypes
```
to 
```
from ctypes import *
```
disassembly:
```
0 LOAD_CONST               0 (0)
2 LOAD_CONST               1 (('*',))
4 IMPORT_NAME              0 (ctypes)
6 IMPORT_STAR
```
