Skip to content

Commit

Permalink
Fixed writing the tag thanks to @boardhead explaining encipher/decipher.
Browse files Browse the repository at this point in the history
Sadly, ArrayCfg/crpyt does not know if he's encrypting/decrypting.  I've added a sniff in TiffEncoder::visitBinaryArrayEnd to avoid changing the API.  Let's change the API in v0.28 (but not yet on master).
  • Loading branch information
clanmills committed Jun 21, 2019
1 parent 23f1aa9 commit c89dc37
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
17 changes: 15 additions & 2 deletions src/sonymn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,14 +811,18 @@ namespace Exiv2 {
return tagInfoFp_;
}

DataBuf sonyTagDecipher(uint16_t /* tag */, const byte* bytes, uint32_t size, TiffComponent* const /*object*/)
DataBuf sonyTagCipher(uint16_t /* tag */, const byte* bytes, uint32_t size, TiffComponent* const /*object*/, bool bDecipher)
{
DataBuf b(bytes,size); // copy the data

// initialize the code table
byte code[256];
for ( uint32_t i = 0 ; i < 249 ; i++ ) {
code[(i * i * i) % 249] = i ;
if ( bDecipher ) {
code[(i * i * i) % 249] = i ;
} else {
code[i] = (i * i * i) % 249 ;
}
}
for ( uint32_t i = 249 ; i < 256 ; i++ ) {
code[i] = i;
Expand All @@ -832,4 +836,13 @@ namespace Exiv2 {
return b;
}

DataBuf sonyTagDecipher(uint16_t tag, const byte* bytes, uint32_t size, TiffComponent* const object)
{
return sonyTagCipher(tag,bytes,size,object,true);
}
DataBuf sonyTagEncipher(uint16_t tag, const byte* bytes, uint32_t size, TiffComponent* const object)
{
return sonyTagCipher(tag,bytes,size,object,false);
}

}} // namespace Internal, Exiv2
2 changes: 2 additions & 0 deletions src/sonymn_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ namespace Exiv2 {

}; // class SonyMakerNote

DataBuf sonyTagCipher (uint16_t, const byte*, uint32_t, TiffComponent* const, bool bCipher);
DataBuf sonyTagDecipher(uint16_t, const byte*, uint32_t, TiffComponent* const);
DataBuf sonyTagEncipher(uint16_t, const byte*, uint32_t, TiffComponent* const);

}} // namespace Internal, Exiv2

Expand Down
6 changes: 5 additions & 1 deletion src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "value.hpp"
#include "image.hpp"
#include "jpgimage.hpp"
#include "sonymn_int.hpp"
#include "i18n.h" // NLS support.

// + standard includes
Expand Down Expand Up @@ -780,7 +781,10 @@ namespace Exiv2 {
if (!object->initialize(pRoot_)) return;

// Re-encrypt buffer if necessary
const CryptFct cryptFct = object->cfg()->cryptFct_;
CryptFct cryptFct = object->cfg()->cryptFct_;
if ( cryptFct == sonyTagDecipher ) {
cryptFct = sonyTagEncipher;
}
if (cryptFct != 0) {
const byte* pData = object->pData();
DataBuf buf = cryptFct(object->tag(), pData, size, pRoot_);
Expand Down
Binary file modified test/data/exiv2-pr906.exv
Binary file not shown.
8 changes: 4 additions & 4 deletions tests/bugfixes/github/test_pr_906.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Sony2FpTest(metaclass=CaseMeta):
filename = path("$data_path/exiv2-pr906.exv")
commands = ["$exiv2 -pa --grep Sony2Fp $filename"]

stdout = ["""Exif.Sony2Fp.AmbientTemperature SByte 1 73
Exif.Sony2Fp.FocusMode Byte 1 42
Exif.Sony2Fp.AFAreaMode Byte 1 3
Exif.Sony2Fp.FocusPosition2 Byte 1 179
stdout = ["""Exif.Sony2Fp.AmbientTemperature SByte 1 19
Exif.Sony2Fp.FocusMode Byte 1 6
Exif.Sony2Fp.AFAreaMode Byte 1 12
Exif.Sony2Fp.FocusPosition2 Byte 1 140
"""
]
stderr = [""]
Expand Down

0 comments on commit c89dc37

Please sign in to comment.