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 "service_base.h" 20 #include "stack_writer.h" 21 22 extern uint32_t g_filterSize; 23 24 class UnixSocketClient; 25 26 class HookSocketClient : public ServiceBase { 27 public: 28 HookSocketClient(int pid); 29 ~HookSocketClient(); 30 bool Connect(const std::string addrname); 31 bool ProtocolProc(SocketContext &context, uint32_t pnum, const int8_t *buf, const uint32_t size) override; GetSmbFd()32 int GetSmbFd() 33 { 34 return smbFd_; 35 } GetEventFd()36 int GetEventFd() 37 { 38 return eventFd_; 39 } 40 bool SendStack(const void* data, size_t size); 41 private: 42 std::shared_ptr<UnixSocketClient> unixSocketClient_; 43 int smbFd_; 44 int eventFd_; 45 int pid_; 46 std::shared_ptr<StackWriter> stackWriter_; 47 }; 48 49 #endif // HOOK_SOCKET_CLIENT