Decoding/Decrypting Sonic Adventure Ranking Data

Discussion in 'Sega Dreamcast Development and Research' started by TerdFerguson, Feb 13, 2016.

  1. TerdFerguson

    TerdFerguson ls ~/

    Joined:
    Apr 27, 2015
    Messages:
    755
    Likes Received:
    466
    I've been looking into this on and off. I can pretty much restore the rankings to SA1 if I can figure out how to decode this. I've looked around but could not find anything

    Here is the string I am trying to decode http://pastebin.com/yZswPdQM

    It is Base64 encoded. But with another layer of encryption on top of that. That is my issue as of now is the second layer of encryption. I was wondering if anyone here had any suggestions. Here is the string after the Base64 layer has been decoded

    Code:
    øEZ³§Ù×ÃÈÇÆ‚¾†°Em@cÓÝǁ†wŒyI&O(9<´úlðz»&¿MÿJñ£Ï׎Á–ÏQ°Q¾ËëhŠIÖÚ"‚”[\_G?1×íÙã–S›]YZð%þEªä¨š¦]ÛaÕ‰ ‡ßâqž-#aœl’ B.Lã0é>¢æ¨èeUj[$5çÉôǦ¿·±inq`(Ü0Òë‚óŒªp½~m'|),•?›ï[ùU®    ¸qø{ö0®: ó„³õuÏ_ˆe„ûR” !±BO    U4ùUÀÕíہ?sh80nÊ©ÄÄÄ®’Ý.l{:ÿuñûéê¿àC¨y1>“ÄCßM‡1ž?FàYî    VXÈÚ
    ‹Ê¥ÄJ¹d·
    o&aÌÝáӏƒ Nrb| -.Ж옃EJRiù(÷Ô¯•¡—µVÌt²7¼Ø`ñn›Ö°ØZ…s‹K=EÜ9ü7Ÿï¿á^^yP!8àòûü㿺® ^ÓÇˤ”†…×n@tÞ#&    АpvŒB»O=J¯ïµmÈYü"‹‡èJú´‰c×fØý–ÐÛQƒÊx}%Ò/„€™N_Hf:IíÙô@£˜¦kZ¦È%ÃÕ°ä½öa¦`¿×uÞ~‚ ˆÆtâp€:¢4Cýlç_.VÅ
    ã„ü¨ýS¢k¨2ÉÌôȇ´·®K{uu
    .0'ÇŸóžŒM©CO8|2    â?æÑPö^¸Wõ{ü»6µÕdšg›ßGÓWŽ žtÀrß<ƒ+†J[EI5Ï8ÃûŠõœªW¤\ÎÊÞἸ²¡bWmbÑß¡†Ñ‰¥u“y¤;_.cîà&XßVèž ¨üYók£$ÚíÇ¥ÉWÕ”¹uh.*á$ñ˜ –°NbAs=-32ãìíõQ®_´iwö(ø6¤ëªùjµdvãv×{‚7:}ñsý#°-¼‘sœ@=N>6ü8ä¿ê@«~¥8ÂÏûÁå½ú·DlbÒÇÜÆ€†Ž‰v@yH%+ëÂåËYŽW‹MHäê¬É¢Î‹‘ÀJÏP·¹e×kÒ+–%•™Q”THF>Ò0Öìâ™R_]X÷ÙùÚ¥˜«kZ\Ú%Ôˆä†Þ~¦p¡,a#`“ #AâOâ5¬9¥ålèeU.Z'éæɨƨ¾k±hm5c+ÓôÝꁷ¬wq~l&0(/”óšîZ½T±|pÿ?ñ3þ£ò¸µÁ{Ìt°:¾7f„höÔGÛ¹š•xIÀG;?ƒ1úíBà½SR|Ï?ðŽþþ¦I©A ÛÊÕÉ•‡‚WvE. œÑ’ÇB“L†0R?IçéUß[ËžŠÉYÄM¸¶nÚ`ÏÜ¥ÒŽ‚dQq&'á)Ó• ›’[bJU
    -øìö×®¯ –iYÃ(ͱë¿ÛgµišÕtØ]„7ŠJñDß8°6žîsáa]=S ü
    ãñ¿ÿ¢§~®e8$ÄûÊ犺„¦xwi/Ç!(†“ëC@Bª1<màÂî,VŒXïO®ÊÅq¹É·0o‹aóÝJвƒ‚ur×|4 –.÷–Q™¶DKyÒ
    Any input would be a big help
     
  2. Darksecond

    Darksecond Member

    Joined:
    Feb 20, 2016
    Messages:
    6
    Likes Received:
    7
    -
     
    Last edited: Feb 20, 2016
  3. Darksecond

    Darksecond Member

    Joined:
    Feb 20, 2016
    Messages:
    6
    Likes Received:
    7
    Alright, had to do some digging in my code and some testing. First of all it seems your base64 encoded string is incorrect, the leading '1' should not be there.

    I've attached my old perl script that includes the correct decryption function it will output to scree and a test.VMS file. this is a binary file.

     

    Attached Files:

  4. S4pph4rad

    S4pph4rad Site Supporter 2015

    Joined:
    Nov 28, 2014
    Messages:
    140
    Likes Received:
    114
    Thank you so much for posting that. As it turns out, the exact same encryption method is being used for the VMU download events, so I can finally decrypt them now. (Inside you'll find textures and models!)

    Here's a C# port of the decryption code you posted:
    Code:
            public static byte[] DecryptThis(byte[] input)
            {
                //Translated from some perl code someone posted on AssemblerGames
                byte[] output = new byte[input.Length];
    
                byte[] xor_code = new byte[] { 0x41, 0x54, 0x45, 0x5A };
                byte[] plus_val = new byte[] { 0x41, 0x4E, 0x41, 0x4E };
                byte[] tmp_val = new byte[] { 0, 0, 0, 0 };
    
                for (int i = 0; i < input.Length / 4; i++)
                {
                    int tmp_val2 = 0;
                    for (int j = 0; j < 4; j++)
                    {
                        output[i * 4 + j] = (byte)(input[i*4+j] ^  tmp_val[j] ^ xor_code[j]);
                        int next = (tmp_val[j] + plus_val[j] + tmp_val2);
                        tmp_val2 = (next >> 8);
                        tmp_val[j] = (byte)(next & 0xFF);
                    }
                }
                return output;
            }
    
     
    BLUamnEsiac and TerdFerguson like this.
  5. TerdFerguson

    TerdFerguson ls ~/

    Joined:
    Apr 27, 2015
    Messages:
    755
    Likes Received:
    466

    OH MAN
    DID YOU JUST

    WOW
     
  6. Darksecond

    Darksecond Member

    Joined:
    Feb 20, 2016
    Messages:
    6
    Likes Received:
    7
  7. S4pph4rad

    S4pph4rad Site Supporter 2015

    Joined:
    Nov 28, 2014
    Messages:
    140
    Likes Received:
    114
    I provided that backup to GoodCow about 10 to 15 years ago. It was heavily modified to work on a PC, as it includes files that were normally read from disc on the original DC version. The original backup, which I still have somewhere, has static copies of some of the CGI pages like Chao Downloads and minigame rankings. There were a bunch of unused / hidden things as well, like a test copy of one of the designs of the dreamcast.com site.

    The only regret I have is that a few years after the original site was taken down, I discovered there was a commented out link to an unreleased download on the events page. The tool I used to download the entire site didn't pick that up since it wasn't a live link. I have no plans to hack any of the downloads. Not enough free time, and plenty of other projects to work on. I really hope someone else does though. :)

    I'll see if I can find the original backup and upload the .rar of it somewhere if you want it.
     
  8. Darksecond

    Darksecond Member

    Joined:
    Feb 20, 2016
    Messages:
    6
    Likes Received:
    7
    Yeah, having the original site would be amazing
     
  9. TerdFerguson

    TerdFerguson ls ~/

    Joined:
    Apr 27, 2015
    Messages:
    755
    Likes Received:
    466
    I already have the site hosted at sonic.dreampipe.net. The redirect works with DNS and automatically with DreamPi. @Darksecond , would you be interested in teaming up?

    It is slightly edited, but only to make it active again. Rather than just restoring a backup
     
  10. S4pph4rad

    S4pph4rad Site Supporter 2015

    Joined:
    Nov 28, 2014
    Messages:
    140
    Likes Received:
    114
    The oldest backup I could find is here:
    http://www.sappharad.com/junk/sa1site.zip

    Files are dated May 13th 2001. It has some changes from the original data, but it's a backup from before I finished "fixing" it to work correctly on a PC. The version of the site that TurdFerguson is hosting has even more changes, like the background music being replaced with MP3's.

    The actual website loaded a lot of images (and the music) from disc. All of that content I threw into a folder called /sadisk/ when making the site viewable on PC, then did a mass find & replace to point files from disc to the ripped copies of those files. To restore back to the original state, just do a massive find/replace of "sadisk/" with "file:/" to point back at the game disc. This will make it not work well on PC again, but the site will run correctly on DC. Files in the root in ALL CAPS were also ripped from the game disc and aren't needed. I believe that was the only change made at the point that this backup was made.

    Some of the "files" are sort of corrupt in this backup, but not really. They have .bin extensions at the end of them, for example activities.html.bin. To "fix" them, rename back to activities.html and remove the binary garbage before and after the html content. Those are completely unmodified in this backup, other than having extra data in them.

    In the cgi-bin folder, you'll find a few copies of various versions of the minigame pages, and the cart race page. Those were originally CGI scripts of course, these were static backups for specific versions of them. There are some files missing from this backup, like static backups of chao_daycare.cgi and score.cgi. I have copies of those too from a backup dated 2003. That backup was more heavily modified like the version you have. Here is that backup which includes some newer files:
    http://www.sappharad.com/junk/sa1site2003.zip

    Between the two backups, you should have static versions of every single page from the original site. With the information I mentioned above, you should be able to undo the changes made to turn them back into the original HTML. Enjoy, I guess?

    It's more than just a slight edit, for the reasons I mentioned above. The original site wasn't even browsable on a PC since almost all of the images were loaded from the game disc for faster page loads since people had dial-up back then. These older backups can get you back to exactly what the original pages were, excluding the CGI stuff which would need to be re-written.
     
  11. jial

    jial Newly Registered

    Joined:
    Jan 12, 2015
    Messages:
    2
    Likes Received:
    0
    Hi, I try your perl algorithm with a ranking data file, but I get a binary or something similar, and I don´t know how parse it to get the ranking values. Any idea?
     
  12. Darksecond

    Darksecond Member

    Joined:
    Feb 20, 2016
    Messages:
    6
    Likes Received:
    7
    The algorithm purely decrypts the data, it does not parse it in any meaningful way. You have to figure out the data contained within yourself.
     
  13. Redd

    Redd Newly Registered

    Joined:
    Nov 12, 2016
    Messages:
    1
    Likes Received:
    0
    S4pph4rad, do you happen to have the Black Market Chao downloads for either SA1 or SA2?
     
  14. S4pph4rad

    S4pph4rad Site Supporter 2015

    Joined:
    Nov 28, 2014
    Messages:
    140
    Likes Received:
    114
    No, but VMU downloads are floating around on many sites, and there are multiple editors to create whatever you want, including one that runs directly on the VMU.
     
  15. ultramecha

    ultramecha Rising Member

    Joined:
    May 20, 2016
    Messages:
    69
    Likes Received:
    70
    Just wanted to point out that over at dreamcast-talk.com they have reverse engineered the SA 1 ranking data and its back online :) Also they restord the website and I believe they even have the black market chao downloads too :)
     
  16. TerdFerguson

    TerdFerguson ls ~/

    Joined:
    Apr 27, 2015
    Messages:
    755
    Likes Received:
    466
    No black market isn't done yet, it might be done or might not, but there's other things being worked on before that's looked at. For now Black Market chao are awarded as prizes for the ranking events
     

Share This Page