コード例 #1
0
ファイル: process_linux.go プロジェクト: ZhuHangpeng/mig
func openFromPid(pid uint) (p Process, harderror error, softerrors []error) {
	// Check if we have premissions to read the process memory
	memPath := common.MemFilePathFromPid(pid)
	memFile, err := os.Open(memPath)
	if err != nil {
		harderror = fmt.Errorf("Permission denied to access memory of process %v", pid)
		return
	}
	defer memFile.Close()

	return proc(pid), nil, nil
}
コード例 #2
0
ファイル: memaccess_linux.go プロジェクト: ZhuHangpeng/mig
func copyMemory(p process.Process, address uintptr, buffer []byte) (harderror error, softerrors []error) {
	mem, harderror := os.Open(common.MemFilePathFromPid(p.Pid()))

	if harderror != nil {
		harderror := fmt.Errorf("Error while reading %d bytes starting at %x: %s", len(buffer), address, harderror)
		return harderror, softerrors
	}
	defer mem.Close()

	bytes_read, harderror := mem.ReadAt(buffer, int64(address))
	if harderror != nil {
		harderror := fmt.Errorf("Error while reading %d bytes starting at %x: %s", len(buffer), address, harderror)
		return harderror, softerrors
	}

	if bytes_read != len(buffer) {
		return fmt.Errorf("Could not read the entire buffer"), softerrors
	}

	return nil, softerrors
}