1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HOOK_SOCKET_CLIENT 17 #define HOOK_SOCKET_CLIENT 18 19 #include "hook_common.h" 20 #include "service_base.h" 21 #include "stack_writer.h" 22 23 class UnixSocketClient; 24 25 class HookSocketClient : public ServiceBase { 26 public: 27 HookSocketClient(int pid, ClientConfig *config); 28 ~HookSocketClient(); 29 bool Connect(const std::string addrname); 30 bool ProtocolProc(SocketContext &context, uint32_t pnum, const int8_t *buf, const uint32_t size) override; GetSmbFd()31 int GetSmbFd() 32 { 33 return smbFd_; 34 } GetEventFd()35 int GetEventFd() 36 { 37 return eventFd_; 38 } 39 void Flush(); 40 bool SendStack(const void* data, size_t size); 41 bool SendStackWithPayload(const void* data, size_t size, const void* payload, 42 size_t payloadSize); 43 private: 44 std::shared_ptr<UnixSocketClient> unixSocketClient_; 45 int smbFd_; 46 int eventFd_; 47 int pid_; 48 ClientConfig *config_ = nullptr; 49 std::shared_ptr<StackWriter> stackWriter_; 50 }; 51 52 #endif // HOOK_SOCKET_CLIENT