Skip to content

Commit d351f2a

Browse files
committed
Renamed XorProxyDataIO to FlipBitsProxyDataIO, and added ReadFrom() and WriteTo() overload methods to it
1 parent 629da84 commit d351f2a

5 files changed

Lines changed: 97 additions & 76 deletions

File tree

HISTORY.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ key: - new feature
135135
o Added ByteBufferRefAndIPAddressAndPort and ConstByteBufferRefAndIPAddressAndPort
136136
classes, and changed the ByteBufferPacketDataIO and PacketTunnelIOGateway classes
137137
to use them instead of Hashtable<ByteBufferRef, IPAddressAndPort>.
138+
o Renamed XorProxyDataIO to FlipBitsProxyDataIO, for better accuracy.
139+
* Added ReadFrom() and WriteTo() methods to XorProxyDataIO, for consistency.
138140
* Fixed various compiler-warnings detected by the new build flags.
139141
* Fixed ByteBufferDataIO to handle seeks correctly in >2GB buffers.
140142
* ByteBufferDataIO constructor now offers an option for Read() to

dataio/FlipBitsProxyDataIO.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* This file is Copyright 2000-2026 Meyer Sound Laboratories Inc. See the included LICENSE.txt file for details. */
2+
3+
#ifndef MuscleFlipBitsProxyDataIO_h
4+
#define MuscleFlipBitsProxyDataIO_h
5+
6+
#include "dataio/ProxyDataIO.h"
7+
#include "util/ByteBuffer.h"
8+
9+
namespace muscle {
10+
11+
/** This DataIO is a "wrapper" DataIO that adds a bitwise-NOT operation to any data
12+
* that it reads or writes before passing the call on to the DataIO that it
13+
* holds internally. This can be useful if you want to obfuscate your data
14+
* a little bit before sending it out to disk or over the network.
15+
*/
16+
class FlipBitsProxyDataIO : public ProxyDataIO
17+
{
18+
public:
19+
/** Default Constructor. Be sure to set a child dataIO with SetChildDataIO()
20+
* before using this DataIO, so that this object will do something useful!
21+
*/
22+
FlipBitsProxyDataIO() {/* empty */}
23+
24+
/** Constructor.
25+
* @param childIO Reference to the DataIO to pass calls on through to
26+
* after the data has been NOT'd.
27+
*/
28+
FlipBitsProxyDataIO(const DataIORef & childIO) : ProxyDataIO(childIO) {/* empty */}
29+
30+
/** Virtual destructor, to keep C++ honest. */
31+
virtual ~FlipBitsProxyDataIO() {/* empty */}
32+
33+
/** Implemented to use the child DataIO object to read in some bytes, and then
34+
* un-NOT the read bytes before returning them to the caller.
35+
* @copydoc ProxyDataIO::Read(void *, uint32)
36+
*/
37+
virtual io_status_t Read(void * buffer, uint32 size)
38+
{
39+
const io_status_t ret = ProxyDataIO::Read(buffer, size);
40+
if (ret.GetByteCount() > 0) BitwiseNotMemCpy(buffer, buffer, ret.GetByteCount());
41+
return ret;
42+
}
43+
44+
/** Implemented to make an NOT'd copy of the passed-in bytes, and then use
45+
* the child DataIO object to transmit the NOT'd bytes.
46+
* @copydoc ProxyDataIO::Write(const void *, uint32)
47+
*/
48+
virtual io_status_t Write(const void * buffer, uint32 size)
49+
{
50+
MRETURN_ON_ERROR(_tempBuf.SetNumBytes(size, false));
51+
BitwiseNotMemCpy(_tempBuf.GetBuffer(), buffer, size);
52+
return ProxyDataIO::Write(_tempBuf.GetBuffer(), size);
53+
}
54+
55+
/** Implemented to use the child DataIO object to read in some bytes, and then
56+
* un-NOT the read bytes before returning them to the caller.
57+
* @copydoc ProxyDataIO::ReadFrom(void *, uint32, IPAddressAndPort &)
58+
*/
59+
virtual io_status_t ReadFrom(void * buffer, uint32 size, IPAddressAndPort & retPacketSource)
60+
{
61+
const io_status_t ret = ProxyDataIO::ReadFrom(buffer, size, retPacketSource);
62+
if (ret.GetByteCount() > 0) BitwiseNotMemCpy(buffer, buffer, ret.GetByteCount());
63+
return ret;
64+
}
65+
66+
/** Implemented to make an NOT'd copy of the passed-in bytes, and then use
67+
* the child DataIO object to transmit the NOT'd bytes.
68+
* @copydoc ProxyDataIO::WriteTo(const void *, uint32, const IPAddressAndPort &)
69+
*/
70+
virtual io_status_t WriteTo(const void * buffer, uint32 size, const IPAddressAndPort & packetDest)
71+
{
72+
MRETURN_ON_ERROR(_tempBuf.SetNumBytes(size, false));
73+
BitwiseNotMemCpy(_tempBuf.GetBuffer(), buffer, size);
74+
return ProxyDataIO::WriteTo(_tempBuf.GetBuffer(), size, packetDest);
75+
}
76+
77+
private:
78+
void BitwiseNotMemCpy(void * to, const void * from, uint32 numBytes) const
79+
{
80+
uint8 * cto = (uint8 *) to;
81+
const uint8 * cfrom = (const uint8 *) from;
82+
for (uint32 i=0; i<numBytes; i++) cto[i] = (uint8) (~cfrom[i]);
83+
}
84+
85+
ByteBuffer _tempBuf; // holds the NOT'd bytes temporarily for us
86+
87+
DECLARE_COUNTED_OBJECT(FlipBitsProxyDataIO);
88+
};
89+
DECLARE_REFTYPES(FlipBitsProxyDataIO);
90+
91+
} // end namespace muscle
92+
93+
#endif

dataio/PacketDataIO.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class PacketDataIO : public virtual DataIO
4848
virtual void SetPacketSendDestination(const IPAddressAndPort & iap) = 0;
4949

5050
/** Default implementation of PacketDataIO::Read()
51-
* which just calls ReadFrom(buffer, size, GetSourceOfLastReadPacket()).
51+
* which just calls ReadFrom(buffer, size, GetWritableSourceOfLastReadPacket()).
5252
* @param buffer Buffer to write the bytes into
5353
* @param size Number of bytes in the buffer.
5454
* @return Number of bytes read, or an error code on error.
@@ -71,7 +71,6 @@ class PacketDataIO : public virtual DataIO
7171

7272
/** Tries to read the data from an incoming packet into (buffer). Returns the
7373
* actual number of bytes placed, or an error code if there was an error.
74-
* Default implementation calls Read(), and then calls GetSourceOfLastReadPacket()
7574
* to fill out the (retPacketSource argument).
7675
* @param buffer Buffer to write the bytes into
7776
* @param size Number of bytes in the buffer.

dataio/XorProxyDataIO.h

Lines changed: 0 additions & 73 deletions
This file was deleted.

tools/hexterm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "dataio/RS232DataIO.h"
1111
#include "dataio/SimulatedMulticastDataIO.h"
1212
#include "dataio/UDPSocketDataIO.h"
13-
#include "dataio/XorProxyDataIO.h" // this is here solely so that if any errors creep into it, it will break the build
13+
#include "dataio/FlipBitsProxyDataIO.h" // this is here solely so that if any errors creep into it, it will break the build
1414
#include "iogateway/PlainTextMessageIOGateway.h"
1515
#include "system/SetupSystem.h"
1616
#include "system/SystemInfo.h" // for GetFilePathSeparator()

0 commit comments

Comments
 (0)