How to locate values inside the data of the Sony Tag9400c?

Started by Higamato, November 15, 2021, 04:48:44 PM

Previous topic - Next topic

Higamato

I would like to retrieve the values of the Sony Tag9400c (Sony Makernotes) reading the bytes of the tag directly. But unfortunately I don't understand the documentation. In the chapter "Sony Tag9400c Tags" of the "Sony Tags" page there are numbers listed under "Index1", but they don't seem to point to valid byte positions inside the tag 9400c.

I did a hex dump with a test jpg, listed the tags with exiftool -g -v and inspected the file in a hex editor. All the values were given in the created text file, but could not be located in the hex dump or not exactly at the position indicated by Index1. Some values were missing altogether.

Please enlighten me! Thank you.

Higamato

OK, folks, so I will have to do some self-enlightening.

As I've learned by inspecting Sony.pm, the data in Tag9400c is encrypted, or enciphered, as the term being used is. The job is done here:

#------------------------------------------------------------------------------
# Decipher/encipher Sony tag 0x2010, 0x900b, 0x9050 and 0x940x data (ref PH)
# Inputs: 0) data reference, 1) true to encipher the data
sub Decipher($;$)
{
    my ($dataPt, $encipher) = @_;
    # This is a simple substitution cipher, so use a hardcoded translation table for speed.
    # The formula is: $c = ($b*$b*$b) % 249, where $c is the enciphered data byte
    # (note that bytes with values 249-255 are not translated, and 0-1, 82-84,
    #  165-167 and 248 have the same enciphered value)
    if ($encipher) {    # encipher
        $$dataPt =~ tr/\x02-\xf7/\x08\x1b\x40\x7d\xd8\x5e\x0e\xe7\x04V\xea\xcd\x05\x8ap\xb6i\x88\x200\xbe\xd7\x81\xbb\x92\x0c\x28\xecl\xa0\x95Q\xd3\x2f\x5dj\x5c9\x07\xc5\x87L\x1a\xf0\xe2\xef\x24y\x02\xb7\xac\xe0\x60\x2bG\xba\x91\xcbu\x8e\x233\xc4\xe3\x96\xdc\xc2N\x7fb\xf6OeE\xeet\xcf\x138KRST\x5bn\x93\xd02\xb1aAW\xa9D\x27X\xdd\xc3\x10\xbc\xdbs\x83\x181\xd4\x15\xe5_\x7bF\xbf\xf3\xe8\xa4\x2d\x82\xb0\xbd\xaf\x8cZ\x1f\xda\x9fmJ\x3cIw\xccU\x11\x06\x3a\xb3\x7e\x9a\x14\xe4\x25\xc8\xe1v\x86\x1e\x3d\xe96\x1c\xa1\xd2\xb5P\xa2\xb8\x98H\xc7\x29f\x8b\x9e\xa5\xa6\xa7\xae\xc1\xe6\x2a\x85\x0b\xb4\x94\xaa\x03\x97z\xab7\x1dc\x165\xc6\xd6k\x84\x2eh\x3f\xb2\xce\x99\x19MB\xf7\x80\xd5\x0a\x17\x09\xdf\xadr4\xf2\xc0\x9d\x8f\x9c\xca\x26\xa8dY\x8d\x0d\xd1\xedg\x3ex\x22\x3b\xc9\xd9q\x90C\x89o\xf4\x2c\x0f\xa3\xf5\x12\xeb\x9b\x21\x7c\xb9\xde\xf1/;
    } else {            # decipher
        $$dataPt =~ tr/\x08\x1b\x40\x7d\xd8\x5e\x0e\xe7\x04V\xea\xcd\x05\x8ap\xb6i\x88\x200\xbe\xd7\x81\xbb\x92\x0c\x28\xecl\xa0\x95Q\xd3\x2f\x5dj\x5c9\x07\xc5\x87L\x1a\xf0\xe2\xef\x24y\x02\xb7\xac\xe0\x60\x2bG\xba\x91\xcbu\x8e\x233\xc4\xe3\x96\xdc\xc2N\x7fb\xf6OeE\xeet\xcf\x138KRST\x5bn\x93\xd02\xb1aAW\xa9D\x27X\xdd\xc3\x10\xbc\xdbs\x83\x181\xd4\x15\xe5_\x7bF\xbf\xf3\xe8\xa4\x2d\x82\xb0\xbd\xaf\x8cZ\x1f\xda\x9fmJ\x3cIw\xccU\x11\x06\x3a\xb3\x7e\x9a\x14\xe4\x25\xc8\xe1v\x86\x1e\x3d\xe96\x1c\xa1\xd2\xb5P\xa2\xb8\x98H\xc7\x29f\x8b\x9e\xa5\xa6\xa7\xae\xc1\xe6\x2a\x85\x0b\xb4\x94\xaa\x03\x97z\xab7\x1dc\x165\xc6\xd6k\x84\x2eh\x3f\xb2\xce\x99\x19MB\xf7\x80\xd5\x0a\x17\x09\xdf\xadr4\xf2\xc0\x9d\x8f\x9c\xca\x26\xa8dY\x8d\x0d\xd1\xedg\x3ex\x22\x3b\xc9\xd9q\x90C\x89o\xf4\x2c\x0f\xa3\xf5\x12\xeb\x9b\x21\x7c\xb9\xde\xf1/\x02-\xf7/;
    }
}
#------------------------------------------------------------------------------


I have absolutely no clue about Perl and it took a while before it dawned on me that the operator "%" means modulo. I used Excel to create a lookup table and this did the trick.

Phil Harvey

I'm glad you figured it out.  I would have hoped this would be more obvious in the -v3 (and higher) verbose outputs.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Higamato

-v3? Totally missed that one. But I don't think I would have found the solution faster with it. Highly appreciate your work, Phil. Incredible.

Higamato

Hi Phil, I have 2 more questions.

1) In the case of multiple versions of a tag, e.g. 9050a/b/c, how do you determine which one to use? SonyModelID, Camera model, ModelReleaseYear?

2) Sometimes you give more than one index1 location for the same value, e.g. in "Sony Tag9050c Tags" for "InternalSerialNumber". In the example given they cannot both be valid, since the size is 6 Bytes and the indices 136 and 138 resp. Does that mean that only one of them is valid? How do you determine which one is right?

Thank you.

Phil Harvey

Quote from: Higamato on November 17, 2021, 07:30:32 AM
1) In the case of multiple versions of a tag, e.g. 9050a/b/c, how do you determine which one to use? Camera model, ModelReleaseYear?

Take a look at the code.

Quote2) Sometimes you give more than one index1 location for the same value, e.g. in "Sony Tag9050c Tags" for "InternalSerialNumber".

Again, you will see what is going on by looking at the "Condition" statements in the code.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Higamato

OK, figured it out. Perl is a dark fate.

1) Camera model.

2) Yes, it also depends on the camera model. Plus it might depend on the firmware, too. Nightmare. I noticed that in 9050b none of the three occurences of ShutterCount2 listed the A6500, yet ExifTool reported the count correctly. No, no digging deeper into Perl, please.

To my dismay I stumbled over the comment "number of shutter actuations, does not increase during Silent Shooting, at least for ILCE-7RM2". I had just written a piece of code heavily relying on the shutter count for ensuring the correct sequence of images in time. I can confirm that the count does not increase in the A6500, either; nor does it in the Alpha 1.

I had the A 1 for a short period of time and still have a few dozens of JPGs left. I noticed a peculiar behaviour: At some point the Shutter Count had started reporting 1 shot more than Shutter Count 2. Both had not increased during silent shooting. After I had switched back to the mechanical shutter they had started reporting the same value again. Unfortunately I cannot perform any further tests since I don't have the A 1 anymore. Well, FWIW.