Skip to content

Commit

Permalink
Update GoSDK to: v0.1.45
Browse files Browse the repository at this point in the history
  • Loading branch information
sonariorobot committed Jun 20, 2023
1 parent 264c190 commit 8fa244d
Show file tree
Hide file tree
Showing 169 changed files with 52,789 additions and 642 deletions.
10 changes: 10 additions & 0 deletions pkg/aug_manager/command_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ func NewCommandHandler(agentCom com_ws.AgentCom, augManager AugManager) *Command
handler.augManager.AddAug(augConfig)
})

handler.agentCom.RegisterCallback(common.MessageTypeErrorMessage, func(msg *anypb.Any) {
errMsg := &pb.ErrorMessage{}
err := anypb.UnmarshalTo(msg, errMsg, proto.UnmarshalOptions{})
if err != nil {
logger.Logger().WithError(err).Error("failed to unmarshal envelope to ErrorMessage")
return
}
logger.Logger().Warningf("Received Error Message: %s", errMsg.Message)
})

return &handler
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/augs/breakpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ type Breakpoint struct {
File string `json:"file"`

Line int `json:"line"`


FunctionName string `json:"functionName,omitempty"`


Stacktrace int `json:"stacktrace"`
Expand All @@ -32,10 +29,11 @@ type BreakpointInstance struct {
FailedCounter *uint64
}

func NewBreakpointInstance(addr uint64, breakpoint *Breakpoint) *BreakpointInstance {
func NewBreakpointInstance(addr uint64, breakpoint *Breakpoint, function *Function) *BreakpointInstance {
b := &BreakpointInstance{
Addr: addr,
Breakpoint: breakpoint,
Function: function,
}
return b
}
Expand All @@ -49,6 +47,7 @@ type Function struct {
FinalTrampolinePointer *uint64
PatchedBytes []byte
Hooked bool
Prologue []byte
}

func NewFunction(entry uint64, end uint64, stackFrameSize int32, middleTrampolineAddress unsafe.Pointer, finalTrampolinePointer *uint64) *Function {
Expand Down
4 changes: 3 additions & 1 deletion pkg/com_ws/agent_com_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ func (a *agentComWs) handleIncomingMessage(typeName string, envelope *pb.Envelop
persistentCallbacks = append(persistentCallbacks, messageCB)
}
}
a.callbacks[typeName] = persistentCallbacks
} else {
logger.Logger().Infof("Received unknown command: %s", typeName)
}
a.callbacks[typeName] = persistentCallbacks
}
1 change: 1 addition & 0 deletions pkg/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
MessageTypeRpcRequest = "com.rookout.C2cRpcRequest"
MessageTypeRpcResponse = "com.rookout.C2cRpcResponse"
MessageTypeAssertAgents = "com.rookout.AssertAgents"
MessageTypeErrorMessage = "com.rookout.ErrorMessage"
)

func WrapMsgInEnvelopeWithTime(message proto.Message, t time.Time) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/information/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package information

import pb "github.com/Rookout/GoSDK/pkg/protobuf"

const VERSION = "0.1.44"
const VERSION = "0.1.45"

func collectVersion(info *AgentInformation) error {
info.Version = &pb.VersionInformation{
Expand Down
2 changes: 1 addition & 1 deletion pkg/processor/namespaces/serializer_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func dumpErrorValue(s Serializer, value reflect.Value) {
}

if value.Type() == reflect.TypeOf(rookoutErrors.RookoutErrorImpl{}) {
err := rookoutErrors.RookoutErrorImpl{
err := &rookoutErrors.RookoutErrorImpl{
ExternalError: value.FieldByName("ExternalError").Interface().(error),
Type: value.FieldByName("Type").Interface().(string),
Arguments: value.FieldByName("Arguments").Interface().(map[string]interface{}),
Expand Down
165 changes: 149 additions & 16 deletions pkg/rookoutErrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type RookoutError interface {
GetType() string

GetArguments() map[interface{}]interface{}
AddArgument(key string, value interface{})
}

type RookoutErrorImpl struct {
Expand All @@ -25,7 +26,7 @@ type RookoutErrorImpl struct {
Arguments map[string]interface{}
}

func (r RookoutErrorImpl) Error() string {
func (r *RookoutErrorImpl) Error() string {
errorString := r.Type

if nil != r.ExternalError {
Expand All @@ -36,22 +37,30 @@ func (r RookoutErrorImpl) Error() string {
errorString = fmt.Sprintf(errorString+" | %v", r.Arguments)
}

if nil != r.ExternalError {
errorString += ": " + r.ExternalError.Error()
}

return errorString
}

func (r RookoutErrorImpl) GetType() string {
func (r *RookoutErrorImpl) GetType() string {
return r.Type
}

func (r RookoutErrorImpl) GetArguments() map[interface{}]interface{} {
func (r *RookoutErrorImpl) GetArguments() map[interface{}]interface{} {
outputMap := make(map[interface{}]interface{})
for key, value := range r.Arguments {
outputMap[key] = value
}
return outputMap
}

func (r RookoutErrorImpl) StackFrames() []errors.StackFrame {
func (r *RookoutErrorImpl) AddArgument(key string, value interface{}) {
r.Arguments[key] = value
}

func (r *RookoutErrorImpl) StackFrames() []errors.StackFrame {
switch e := r.ExternalError.(type) {
case *errors.Error:
return e.StackFrames()
Expand All @@ -62,7 +71,7 @@ func (r RookoutErrorImpl) StackFrames() []errors.StackFrame {
}
}

func (r RookoutErrorImpl) Stack() []byte {
func (r *RookoutErrorImpl) Stack() []byte {
switch e := r.ExternalError.(type) {
case *errors.Error:
return e.Stack()
Expand All @@ -74,8 +83,12 @@ func (r RookoutErrorImpl) Stack() []byte {
}

func newRookoutError(errorType string, description string, externalError error, arguments map[string]interface{}) *RookoutErrorImpl {
if externalError == nil {
externalError = errors.Wrap(description, 2)
if _, ok := externalError.(*errors.Error); !ok {
if externalError != nil {
externalError = errors.Wrap(externalError.Error(), 2)
} else {
externalError = errors.Wrap(description, 2)
}
}

return &RookoutErrorImpl{
Expand Down Expand Up @@ -333,27 +346,25 @@ func NewFailedToGetStateEntryAddr(functionEntry uint64, functionEnd uint64, stat
})
}

func NewInvalidBranchDest(hookAddr uintptr, stateAddr uintptr, stateID int) RookoutError {
func NewInvalidBranchDest(src uintptr, dst uintptr) RookoutError {
return newRookoutError(
"InvalidBranchDest",
"Tried to encode an invalid branch instruction - relative distance isn't dividable by 4",
nil,
map[string]interface{}{
"hookAddr": hookAddr,
"stateAddr": stateAddr,
"stateID": stateID,
"src": src,
"dst": dst,
})
}

func NewBranchDestTooFar(hookAddr uintptr, stateAddr uintptr, stateID int) RookoutError {
func NewBranchDestTooFar(src uintptr, dst uintptr) RookoutError {
return newRookoutError(
"BranchDestTooFar",
"Tried to encode an invalid branch instruction - relative distance is too long to be encoded into 26 bit immediate",
nil,
map[string]interface{}{
"hookAddr": hookAddr,
"stateAddr": stateAddr,
"stateID": stateID,
"src": src,
"dst": dst,
})
}

Expand Down Expand Up @@ -705,6 +716,14 @@ func NewFailedToGetAddressMapping(filename string, lineno int, err error) Rookou
})
}

func NewFailedToStartCopyingFunction(err error) RookoutError {
return newRookoutError(
"FailedToStartCopyingFunction",
"Unable to start copying original function",
err,
map[string]interface{}{})
}

func NewCompiledWithoutCGO() RookoutError {
return newRookoutError("CompiledWithoutCGO", "Your project was built with CGO_ENABLED disabled", nil, map[string]interface{}{})
}
Expand All @@ -728,6 +747,24 @@ func NewRookOutputQueueFull() RookoutError {
map[string]interface{}{})
}

func NewInvalidDwarfRegister(dwarfReg uint64) RookoutError {
return newRookoutError("InvalidDwarfRegister",
"Tracked invalid dwarf register while locating variable",
nil,
map[string]interface{}{
"dwarfReg": dwarfReg,
})
}

func NewFailedToLocate(variableName string, externalErr error) RookoutError {
return newRookoutError("FailedToLocate",
"Failed to locate variable",
externalErr,
map[string]interface{}{
"variableName": variableName,
})
}

func NewFailedToAlignFunc(funcAddress, pclntableAddress, funcOffset uintptr) RookoutError {
return newRookoutError(
"FailedToAlignFunc",
Expand Down Expand Up @@ -854,6 +891,31 @@ func NewPCDataVerificationFailed(table uint32, origValue int32, origPC uintptr,
})
}

func NewPCDataAsyncUnsafePointVerificationFailed(newValue int32, newPC uintptr) RookoutError {
return newRookoutError(
"PCDataAsyncUnsafePointVerificationFailed",
"New module has a different value than the unsafe point for PCs within the patched code",
nil,
map[string]interface{}{
"newValue": newValue,
"newPC": newPC,
})
}

func NewPCSPInPatchedVerificationFailed(origValue int32, origPC uintptr, expectedNewValue, newValue int32, newPC uintptr) RookoutError {
return newRookoutError(
"PCSPInPatchedVerificationFailed",
"New module has a different value in pcsp table than the expected generated values",
nil,
map[string]interface{}{
"origValue": origValue,
"origPC": origPC,
"expectedNewValue": expectedNewValue,
"newValue": newValue,
"newPC": newPC,
})
}

func NewPCSPVerificationFailed(origValue int32, origPC uintptr, newValue int32, newPC uintptr) RookoutError {
return newRookoutError(
"PCSPVerificationFailed",
Expand All @@ -867,6 +929,18 @@ func NewPCSPVerificationFailed(origValue int32, origPC uintptr, newValue int32,
})
}

func NewPCSPVerificationFailedMissingEntry(origValue int32, origPC uintptr, newPC uintptr) RookoutError {
return newRookoutError(
"PCSPVerificationFailedMissingEntry",
"New module has doesn't have a PCSP entry for a PC within the patched code",
nil,
map[string]interface{}{
"origValue": origValue,
"origPC": origPC,
"newPC": newPC,
})
}

func NewPCFileVerificationFailed(origFile string, origPC uintptr, newFile string, newPC uintptr) RookoutError {
return newRookoutError(
"PCFileVerificationFailed",
Expand Down Expand Up @@ -926,6 +1000,14 @@ func NewModuleVerificationFailed(recovered interface{}) RookoutError {
})
}

func NewIllegalAddressMappings() RookoutError {
return newRookoutError(
"BadAddressMapping",
"Function address mapping must not contain patched code in the last two mappings",
nil,
nil)
}

func NewVariableCreationFailed(recovered interface{}) RookoutError {
return newRookoutError(
"VariableCreationFailed",
Expand Down Expand Up @@ -956,13 +1038,33 @@ func NewArgIsNotRel(inst interface{}) RookoutError {
})
}

func NewInvalidJumpDest(jumpDest string) RookoutError {
return newRookoutError(
"InvalidJumpDest",
"Created a jump with a nonexistant dest",
nil,
map[string]interface{}{
"jumpDest": jumpDest,
})
}

func NewFailedToAssemble(recovered interface{}) RookoutError {
return newRookoutError(
"FailedToAssemble",
"Failed to assemble instructions",
nil,
map[string]interface{}{
"recovered": recovered,
})
}

func NewFailedToDecode(funcAsm []byte, err error) RookoutError {
return newRookoutError(
"FailedToDecode",
"Failed to decode one instruction",
err,
map[string]interface{}{
"funcAsm": funcAsm,
"inst": fmt.Sprintf("%x", funcAsm),
})
}

Expand Down Expand Up @@ -1030,3 +1132,34 @@ func NewVariableIsNotArray(name string, kind reflect.Kind) RookoutError {
"kind": kind,
})
}

func NewLabelAlreadyExists(label string) RookoutError {
return newRookoutError(
"LabelAlreadyExists",
"Unable to add label to assembly: the label already exists",
nil,
map[string]interface{}{
"label": label,
})
}

func NewInvalidBytes(bytes []byte) RookoutError {
return newRookoutError(
"InvalidBytes",
"Cannot insert bytes: length of bytes is not a multiple of 4",
nil,
map[string]interface{}{
"bytes": bytes,
})
}

func NewUnexpectedInstruction(movGToR12 interface{}, ret interface{}) RookoutError {
return newRookoutError(
"UnexpectedInstruction",
"Unexpected instructions in assembled getg",
nil,
map[string]interface{}{
"movGToR12": movGToR12,
"ret": ret,
})
}
7 changes: 7 additions & 0 deletions pkg/services/assembler/args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package assembler

type Mem struct {
Arg
Base Reg
Disp int64
}
Loading

0 comments on commit 8fa244d

Please sign in to comment.