From d7a35829440aa778b5a58bb2df97aedd14114df8 Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 23 Feb 2020 16:40:21 +0100 Subject: place bots + handle errors --- src/init.go | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/init.go b/src/init.go index eadf505..ee6db87 100644 --- a/src/init.go +++ b/src/init.go @@ -186,5 +186,45 @@ func genRandomOffsets(config *Config) { // place the bot in the arena at the given address func placeBot(r2p *r2pipe.Pipe, bot Bot, address int) { - _ = r2cmd(r2p, fmt.Sprintf("wx %s @ %d", bot, address)) + _ = r2cmd(r2p, fmt.Sprintf("wx %s @ %d", bot.Source, address)) +} + +func placeBots(r2p *r2pipe.Pipe, config *Config) { + + logrus.Info("Placing the bots in the arena") + + // place each bot in the arena + for bot := 0; bot < len(config.Bots); bot++ { + + // get the address where the bot should be placed + address := config.RandomOffsets[bot] + + // Place the bot in the arena + logrus.Debugf("[i] Placing bot %d at %d", bot, address) + placeBot(r2p, config.Bots[bot], address) + + logrus.Debugf("\n%s", r2cmd(r2p, fmt.Sprintf("pd 0x8 @ %d", address))) + + // store the initial address of the bot in the according struct field + config.Bots[bot].Addr = address + + // define the instruction point and the stack pointer + _ = r2cmd(r2p, fmt.Sprintf("aer PC=%d", config.Bots[bot].Addr)) + _ = r2cmd(r2p, fmt.Sprintf("aer SP=SP+%d", config.Bots[bot].Addr)) + + // dump the registers of the bot for being able to switch inbetween them + // This is done in order to be able to play one step of each bot at a time, + // but sort of in parallel + initialRegisers := strings.Replace(r2cmd(r2p, "aerR"), "\n", ";", -1) + config.Bots[bot].Regs = initialRegisers + } +} + +func defineErrors(r2p *r2pipe.Pipe) { + // handle errors in esil + _ = r2cmd(r2p, "e cmd.esil.todo=f theend=1") + _ = r2cmd(r2p, "e cmd.esil.trap=f theend=1") + _ = r2cmd(r2p, "e cmd.esil.intr=f theend=1") + _ = r2cmd(r2p, "e cmd.esil.ioer=f theend=1") + _ = r2cmd(r2p, "f theend=0") } -- cgit 1.4.1