Skip to content

Commit

Permalink
add: Implement -q option
Browse files Browse the repository at this point in the history
  • Loading branch information
yamatcha committed Jun 9, 2020
1 parent b816667 commit 4cdf652
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"os"
Expand All @@ -17,26 +18,34 @@ func dumpRegisters(emu *emulator.Emulator) {
}

func main() {
if len(os.Args) < 2 {
quiet := flag.Bool("q", false, "Quiet mode enabled?")
flag.Parse()
argv := flag.Args()
if len(argv) < 1 {
fmt.Println("few arguments")
os.Exit(1)
}
filename := os.Args[1]
filename := argv[0]

emu := emulator.NewEmulator(emulator.MemorySize, 0x7c00, 0x7c00)
if emu == nil {
fmt.Println("Error: Value of eip or esp is invalid")
os.Exit(1)
}

binary, err := os.Open(filename)
if err != nil {
panic(err)
}
defer binary.Close()

mem, err := ioutil.ReadAll(binary)
emu.Memory = append(emu.Memory[:0x7c00], mem...)
for emu.Eip < emulator.MemorySize {
var code byte = emulator.GetCode8(emu, 0)
fmt.Printf("EIP = %X, Code = %02X\n", emu.Eip, code)
if !*quiet {
fmt.Printf("EIP = %X, Code = %02X\n", emu.Eip, code)
}
operator, err := emulator.Instructions(code)
if err != nil {
panic(err)
Expand Down

0 comments on commit 4cdf652

Please sign in to comment.