Example #1
0
func addVariableHandlers(mygdb *gdblib.GDB) {
	http.HandleFunc("/handle/variable/create", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.VarCreateParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		result, err := mygdb.VarCreate(parms)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))

	http.HandleFunc("/handle/variable/delete", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.VarDeleteParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		err = mygdb.VarDelete(parms)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
			return
		}

		w.WriteHeader(200)
	}))

	http.HandleFunc("/handle/variable/listchildren", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.VarListChildrenParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		result, err := mygdb.VarListChildren(parms)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))
}
Example #2
0
func addBreakpointHandlers(mygdb *gdblib.GDB) {
	http.HandleFunc("/handle/breakpoint/list", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		result, err := mygdb.BreakList()

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))

	http.HandleFunc("/handle/breakpoint/insert", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.BreakInsertParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		result, err := mygdb.BreakInsert(parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))

	http.HandleFunc("/handle/breakpoint/enable", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.BreakEnableParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		err = mygdb.BreakEnable(parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		w.WriteHeader(200)
	}))

	http.HandleFunc("/handle/breakpoint/disable", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.BreakDisableParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		err = mygdb.BreakDisable(parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		w.WriteHeader(200)
	}))
}
Example #3
0
func addFrameHandlers(mygdb *gdblib.GDB) {
	http.HandleFunc("/handle/frame/stackinfo", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		result, err := mygdb.StackInfoFrame()

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))
	http.HandleFunc("/handle/frame/stacklist", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.StackListFramesParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		result, err := mygdb.StackListFrames(parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))

	http.HandleFunc("/handle/frame/variableslist", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.StackListVariablesParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		result, err := mygdb.StackListVariables(parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))

	http.HandleFunc("/handle/file/get", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := make(map[string]string)

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		path := parms["File"]

		if path == "" {
			w.WriteHeader(400)
			w.Write([]byte("No path provided"))
			return
		}

		if *srcDir != "" {
			path = *srcDir + "/" + strings.Replace(path, "../", "", -1)
		} else {
			path, err = filepath.Abs(path)

			inGopath := false
			for _, p := range gopaths {
				if strings.HasPrefix(path, p) {
					inGopath = true
					break
				}
			}

			// If the path is not under the current directory or in the GOPATH/GOROOT then it is an illegal access
			if !inGopath &&
				!strings.HasPrefix(path, cwd) &&
				!strings.HasPrefix(path, goroot) {

				w.WriteHeader(400)
				w.Write([]byte("Illegal file access"))
				return
			}
		}

		file, err := os.Open(path)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			_, err := io.Copy(w, file)

			if err != nil {
				w.WriteHeader(500)
				w.Write([]byte(err.Error()))
			}
		}
	}))
}
Example #4
0
func addExecHandlers(mygdb *gdblib.GDB) {
	http.HandleFunc("/handle/exec/next", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.ExecNextParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err == nil {
			err = mygdb.ExecNext(parms)
		}

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}
		w.WriteHeader(200)
	}))

	http.HandleFunc("/handle/exec/step", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.ExecStepParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err == nil {
			err = mygdb.ExecStep(parms)
		}

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}
		w.WriteHeader(200)
	}))

	http.HandleFunc("/handle/exec/continue", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.ExecContinueParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err == nil {
			err = mygdb.ExecContinue(parms)
		}

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}
		w.WriteHeader(200)
	}))

	http.HandleFunc("/handle/exec/run", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.ExecRunParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err == nil {
			err = mygdb.ExecRun(parms)
		}

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}
		w.WriteHeader(200)
	}))

	http.HandleFunc("/handle/exec/args", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.ExecArgsParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err == nil {
			err = mygdb.ExecArgs(parms)
		}

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}
		w.WriteHeader(200)
	}))

	http.HandleFunc("/handle/exec/interrupt", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.ExecInterruptParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		mygdb.ExecInterrupt(parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}
		w.WriteHeader(200)
	}))
}
Example #5
0
func addThreadHandlers(mygdb *gdblib.GDB) {
	http.HandleFunc("/handle/thread/listids", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		result, err := mygdb.ThreadListIds()

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))
	http.HandleFunc("/handle/thread/select", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.ThreadSelectParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		result, err := mygdb.ThreadSelect(parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))
	http.HandleFunc("/handle/thread/info", wrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		parms := gdblib.ThreadInfoParms{}

		decoder := json.NewDecoder(r.Body)
		err := decoder.Decode(&parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		result, err := mygdb.ThreadInfo(parms)

		if err != nil {
			w.WriteHeader(400)
			w.Write([]byte(err.Error()))
			return
		}

		resultBytes, err := json.Marshal(result)

		if err != nil {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		} else {
			w.WriteHeader(200)
			w.Write(resultBytes)
		}
	}))
}