message_cracker.h 1016 B

12345678910111213141516171819202122232425262728293031323334
  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. #ifndef TOOLS_IPC_FUZZER_MESSAGE_LIB_MESSAGE_CRACKER_H_
  5. #define TOOLS_IPC_FUZZER_MESSAGE_LIB_MESSAGE_CRACKER_H_
  6. #include <stdint.h>
  7. #include <string.h>
  8. #include "base/macros.h"
  9. #include "ipc/ipc_message.h"
  10. // Means for updating protected message fields.
  11. class MessageCracker : public IPC::Message {
  12. public:
  13. static void CopyMessageID(IPC::Message* dst, IPC::Message* src) {
  14. memcpy(ToCracker(dst)->mutable_payload(),
  15. ToCracker(src)->payload(),
  16. sizeof(int));
  17. }
  18. static void SetMessageType(IPC::Message* message, uint32_t type) {
  19. ToCracker(message)->header()->type = type;
  20. }
  21. private:
  22. static MessageCracker* ToCracker(IPC::Message* message) {
  23. return reinterpret_cast<MessageCracker*>(message);
  24. }
  25. DISALLOW_COPY_AND_ASSIGN(MessageCracker);
  26. };
  27. #endif // TOOLS_IPC_FUZZER_MESSAGE_LIB_MESSAGE_CRACKER_H_