zipCryptStream.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _ZIPCRYPTSTREAM_H_
  23. #define _ZIPCRYPTSTREAM_H_
  24. #ifndef _FILTERSTREAM_H_
  25. #include "io/filterStream.h"
  26. #endif
  27. class ZipCryptRStream : public FilterStream
  28. {
  29. typedef FilterStream Parent;
  30. Stream *mStream;
  31. S32 mStreamStartPos;
  32. S32 mFileStartPos;
  33. S32 mFileEndPos;
  34. U32 mKeys[3]; // mKeys and it's usage is very unclear and has a ton of magic numbers -patw
  35. const char *mPassword;
  36. U32 fillBuffer(const U32 in_attemptSize, void *pBuffer);
  37. public:
  38. ZipCryptRStream();
  39. virtual ~ZipCryptRStream();
  40. void setPassword(const char *password);
  41. inline void setFileEndPos(S32 pos) { mFileEndPos = pos; }
  42. // Overrides of FilterStream
  43. bool attachStream(Stream* io_pSlaveStream);
  44. void detachStream();
  45. Stream *getStream() { return mStream; }
  46. U32 getPosition() const;
  47. bool setPosition(const U32 in_newPosition);
  48. protected:
  49. bool _read(const U32 in_numBytes, void* out_pBuffer);
  50. void updateKeys(const U8 c);
  51. U8 decryptByte();
  52. };
  53. #endif // _ZIPCRYPTSTREAM_H_