executeBOFPackCustom executes a BOF with custom packed arguments
(ctx context.Context, client *csclient.Client, beaconID string, action Action)
| 1088 | |
| 1089 | // executeBOFPackCustom executes a BOF with custom packed arguments |
| 1090 | func (e *Executor) executeBOFPackCustom(ctx context.Context, client *csclient.Client, beaconID string, action Action) (string, error) { |
| 1091 | bofPath, ok := action.Parameters["bof"].(string) |
| 1092 | if !ok { |
| 1093 | return "", fmt.Errorf("bof parameter required") |
| 1094 | } |
| 1095 | |
| 1096 | bofData, err := os.ReadFile(bofPath) |
| 1097 | if err != nil { |
| 1098 | return "", fmt.Errorf("failed to read BOF file: %w", err) |
| 1099 | } |
| 1100 | |
| 1101 | bofBase64 := base64.StdEncoding.EncodeToString(bofData) |
| 1102 | |
| 1103 | // Parse arguments array |
| 1104 | var packedArgs []byte |
| 1105 | if argsInterface, ok := action.Parameters["arguments"].([]interface{}); ok { |
| 1106 | var bofArgs []BOFArgument |
| 1107 | for _, arg := range argsInterface { |
| 1108 | argMap, ok := arg.(map[string]interface{}) |
| 1109 | if !ok { |
| 1110 | continue |
| 1111 | } |
| 1112 | |
| 1113 | argType, _ := argMap["type"].(string) |
| 1114 | bofArg := BOFArgument{ |
| 1115 | Type: argType, |
| 1116 | Value: argMap["value"], |
| 1117 | } |
| 1118 | bofArgs = append(bofArgs, bofArg) |
| 1119 | } |
| 1120 | |
| 1121 | // Pack arguments using custom packer |
| 1122 | packedArgs, err = PackBOFArguments(bofArgs) |
| 1123 | if err != nil { |
| 1124 | return "", fmt.Errorf("failed to pack arguments: %w", err) |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | // Encode packed arguments as base64 string |
| 1129 | packedArgsBase64 := base64.StdEncoding.EncodeToString(packedArgs) |
| 1130 | |
| 1131 | req := csclient.InlineExecutePackedDto{ |
| 1132 | BOF: "@files/bof.o", |
| 1133 | Files: map[string]string{"bof.o": bofBase64}, |
| 1134 | Arguments: packedArgsBase64, |
| 1135 | } |
| 1136 | |
| 1137 | if ep, ok := action.Parameters["entrypoint"].(string); ok { |
| 1138 | req.Entrypoint = ep |
| 1139 | } |
| 1140 | |
| 1141 | resp, err := client.ExecuteBOFPacked(ctx, beaconID, req) |
| 1142 | if err != nil { |
| 1143 | return "", err |
| 1144 | } |
| 1145 | |
| 1146 | return e.waitForOutput(ctx, client, resp.TaskID) |
| 1147 | } |
no test coverage detected