diff options
| author | Camille Mougey <commial@gmail.com> | 2018-04-19 15:16:53 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-19 15:16:53 +0200 |
| commit | 145c218af968bea37ecc8a89585686e68566a875 (patch) | |
| tree | b08e09c2dca8b005b1fe874f9de222e7fe7e4bdc | |
| parent | cc6b1ae498d6a4b876c14e274f852be76a7be080 (diff) | |
| parent | c8104588e23cfc53f3d3608b743578a51f279ebf (diff) | |
| download | miasm-145c218af968bea37ecc8a89585686e68566a875.tar.gz miasm-145c218af968bea37ecc8a89585686e68566a875.zip | |
Merge pull request #714 from serpilliere/symb_pool_labels
Asmblock: fix AsmSymbolPool API
| -rw-r--r-- | miasm2/core/asmblock.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/miasm2/core/asmblock.py b/miasm2/core/asmblock.py index 7d18c4f5..07b8ceeb 100644 --- a/miasm2/core/asmblock.py +++ b/miasm2/core/asmblock.py @@ -334,9 +334,20 @@ class asm_block_bad(AsmBlockBad): class AsmSymbolPool(object): + """ + Store symbols. + + A symbol links a name to an (optional) offset + + Rules and limitations: + - two different symbols cannot have the same offset + - two different symbols cannot have the same name + - symbols manipulation (comparison, creation ...) can only be done on + symbols generated by the same symbol pool + """ def __init__(self): - self._labels = [] + self._labels = set() self._name2label = {} self._offset2label = {} self._label_num = 0 @@ -359,7 +370,7 @@ class AsmSymbolPool(object): raise ValueError('symbol %s has same name as %s' % (label, self._name2label[label.name])) - self._labels.append(label) + self._labels.add(label) if label.offset is not None: self._offset2label[label.offset] = label if label.name != "": @@ -427,10 +438,17 @@ class AsmSymbolPool(object): self._offset2label[label.offset] = label @property - def items(self): + def labels(self): """Return all labels""" return self._labels + @property + def items(self): + """Return all labels""" + warnings.warn('DEPRECATION WARNING: use "labels" instead of "items"') + return list(self._labels) + + def __str__(self): return reduce(lambda x, y: x + str(y) + '\n', self._labels, "") @@ -446,7 +464,7 @@ class AsmSymbolPool(object): def merge(self, symbol_pool): """Merge with another @symbol_pool""" - self._labels += symbol_pool._labels + self._labels.update(symbol_pool.labels) self._name2label.update(symbol_pool._name2label) self._offset2label.update(symbol_pool._offset2label) |