1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef TOOLS_IPC_FUZZER_MESSAGE_LIB_MESSAGE_CRACKER_H_ 6 #define TOOLS_IPC_FUZZER_MESSAGE_LIB_MESSAGE_CRACKER_H_ 7 8 #include <string.h> 9 #include "ipc/ipc_message.h" 10 11 // Means for updating protected message fields. 12 class MessageCracker : public IPC::Message { 13 public: CopyMessageID(IPC::Message * dst,IPC::Message * src)14 static void CopyMessageID(IPC::Message* dst, IPC::Message* src) { 15 memcpy(ToCracker(dst)->mutable_payload(), 16 ToCracker(src)->payload(), 17 sizeof(int)); 18 } 19 SetMessageType(IPC::Message * message,uint32 type)20 static void SetMessageType(IPC::Message* message, uint32 type) { 21 ToCracker(message)->header()->type = type; 22 } 23 24 private: ToCracker(IPC::Message * message)25 static MessageCracker* ToCracker(IPC::Message* message) { 26 return reinterpret_cast<MessageCracker*>(message); 27 } 28 29 DISALLOW_COPY_AND_ASSIGN(MessageCracker); 30 }; 31 32 #endif // TOOLS_IPC_FUZZER_MESSAGE_LIB_MESSAGE_CRACKER_H_ 33