Commit 3e9acb85 authored by George Hotz's avatar George Hotz

a bit simpler

parent eaa6641c
......@@ -49,11 +49,16 @@ func TestCompareUnicornEvm(t *testing.T) {
})
uniram := make(map[uint32](uint32))
go RunUnicorn(fn, uniram, true, false, func(step int, mu uc.Unicorn, ram map[uint32](uint32)) {
ministart := time.Now()
go RunUnicorn(fn, uniram, false, func(step int, mu uc.Unicorn, ram map[uint32](uint32)) {
SyncRegs(mu, ram)
cuni <- RegSerialize(ram)
done.Lock()
done.Unlock()
if step%1000000 == 0 {
steps_per_sec := float64(step) * 1e9 / float64(time.Now().Sub(ministart).Nanoseconds())
fmt.Printf("%10d pc: %x steps per s %f ram entries %d\n", step, ram[0xc0000080], steps_per_sec, len(ram))
}
// halt at steps
if step == steps {
mu.RegWrite(uc.MIPS_REG_PC, 0x5ead0004)
......
......@@ -10,7 +10,7 @@ import (
func TestMinigethUnicorn(t *testing.T) {
uniram := make(map[uint32](uint32))
RunUnicorn("../mipigo/minigeth.bin", uniram, false, true, nil)
RunUnicorn("../mipigo/minigeth.bin", uniram, true, nil)
}
func TestSimpleEVM(t *testing.T) {
......
......@@ -7,7 +7,6 @@ import (
"io/ioutil"
"log"
"os"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/fatih/color"
......@@ -70,7 +69,7 @@ func SyncRegs(mu uc.Unicorn, ram map[uint32](uint32)) {
WriteRam(ram, REG_HEAP, uint32(heap_start))
}
func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callback func(int, uc.Unicorn, map[uint32](uint32))) uc.Unicorn {
func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, uc.Unicorn, map[uint32](uint32))) uc.Unicorn {
mu, err := uc.NewUnicorn(uc.ARCH_MIPS, uc.MODE_32|uc.MODE_BIG_ENDIAN)
check(err)
......@@ -125,7 +124,7 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callb
mu.RegWrite(uc.MIPS_REG_A3, 0)
}, 0, 0)
if slowMode {
if callback != nil {
mu.HookAdd(uc.HOOK_MEM_WRITE, func(mu uc.Unicorn, access int, addr64 uint64, size int, value int64) {
rt := value
rs := addr64 & 3
......@@ -149,15 +148,8 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callb
}, 0, 0x80000000)
ministart := time.Now()
mu.HookAdd(uc.HOOK_CODE, func(mu uc.Unicorn, addr uint64, size uint32) {
if steps%1000000 == 0 && false {
steps_per_sec := float64(steps) * 1e9 / float64(time.Now().Sub(ministart).Nanoseconds())
fmt.Printf("%10d pc: %x steps per s %f ram entries %d\n", steps, addr, steps_per_sec, len(ram))
}
if callback != nil {
callback(steps, mu, ram)
}
steps += 1
}, 0, 0x80000000)
}
......@@ -166,9 +158,9 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callb
}
// reimplement simple.py in go
func RunUnicorn(fn string, ram map[uint32](uint32), slowMode bool, checkIO bool, callback func(int, uc.Unicorn, map[uint32](uint32))) {
func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(int, uc.Unicorn, map[uint32](uint32))) {
root := "/tmp/eth/13284469"
mu := GetHookedUnicorn(root, ram, slowMode, callback)
mu := GetHookedUnicorn(root, ram, callback)
// loop forever to match EVM
//mu.MemMap(0x5ead0000, 0x1000)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment