diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-05 21:55:43 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-05 21:55:43 +0800 |
commit | 2096b3a9edb3289a8f30da81704181dec7b39917 (patch) | |
tree | 1a38e845f32ecfc94a73546ec4cfdb971b740830 /ethchain/asm.go | |
parent | 6a86c517c4f4b372cad0ae1d92e926a482eac5ba (diff) | |
parent | fedd4c906ff9f6139cb2d88e4f1adefbf6ea81a6 (diff) | |
download | dexon-2096b3a9edb3289a8f30da81704181dec7b39917.tar dexon-2096b3a9edb3289a8f30da81704181dec7b39917.tar.gz dexon-2096b3a9edb3289a8f30da81704181dec7b39917.tar.bz2 dexon-2096b3a9edb3289a8f30da81704181dec7b39917.tar.lz dexon-2096b3a9edb3289a8f30da81704181dec7b39917.tar.xz dexon-2096b3a9edb3289a8f30da81704181dec7b39917.tar.zst dexon-2096b3a9edb3289a8f30da81704181dec7b39917.zip |
Merge branch 'release/poc5-rc1'
Diffstat (limited to 'ethchain/asm.go')
-rw-r--r-- | ethchain/asm.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ethchain/asm.go b/ethchain/asm.go new file mode 100644 index 000000000..3194549ba --- /dev/null +++ b/ethchain/asm.go @@ -0,0 +1,59 @@ +package ethchain + +import ( + "fmt" + "github.com/ethereum/eth-go/ethutil" + "math/big" +) + +func Disassemble(script []byte) (asm []string) { + pc := new(big.Int) + for { + if pc.Cmp(big.NewInt(int64(len(script)))) >= 0 { + return + } + + // Get the memory location of pc + val := script[pc.Int64()] + // Get the opcode (it must be an opcode!) + op := OpCode(val) + + asm = append(asm, fmt.Sprintf("%v", op)) + + switch op { + case oPUSH: // Push PC+1 on to the stack + pc.Add(pc, ethutil.Big1) + data := script[pc.Int64() : pc.Int64()+32] + val := ethutil.BigD(data) + + var b []byte + if val.Int64() == 0 { + b = []byte{0} + } else { + b = val.Bytes() + } + + asm = append(asm, fmt.Sprintf("0x%x", b)) + + pc.Add(pc, big.NewInt(31)) + case oPUSH20: + pc.Add(pc, ethutil.Big1) + data := script[pc.Int64() : pc.Int64()+20] + val := ethutil.BigD(data) + var b []byte + if val.Int64() == 0 { + b = []byte{0} + } else { + b = val.Bytes() + } + + asm = append(asm, fmt.Sprintf("0x%x", b)) + + pc.Add(pc, big.NewInt(19)) + } + + pc.Add(pc, ethutil.Big1) + } + + return +} |