[C#][developers] read sv.t & create a sv.t

04/26/2013 15:17 cyberninjah#1
Here is a little snippet how to read the silkroad version from the sv.t
and create a sv.t in C#.

Thanks to pushedx for the explanation about the file structure.

Code:
        public static void WriteSVTFile(byte[] buffer, int newVersion)
        {
            pk2Reader.Blowfish bf = new pk2Reader.Blowfish(Encoding.ASCII.GetBytes("SILKROADVERSION"), 0, 8);
            Array.Reverse(buffer, 4, 4);
            Array.Reverse(buffer, 8, 4);
            bf.Decrypt(buffer, 4, buffer, 4, 8);
            Array.Reverse(buffer, 4, 4);
            Array.Reverse(buffer, 8, 4);

            int version;
            int.TryParse(Encoding.ASCII.GetString(buffer, 4, 4), out version);

            byte[] tmp = Encoding.ASCII.GetBytes(newVersion.ToString());

            tmp.CopyTo(buffer, 4);

            Array.Reverse(buffer, 8, 4);
            Array.Reverse(buffer, 4, 4);
            bf.Encrypt(buffer, 4, buffer, 4, 8);
            Array.Reverse(buffer, 8, 4);
            Array.Reverse(buffer, 4, 4);

            File.WriteAllBytes("sv.t", buffer);
        }

        public static uint ReadVersion(byte[] buffer)
        {
            pk2Reader.Blowfish bf = new pk2Reader.Blowfish(Encoding.ASCII.GetBytes("SILKROADVERSION"), 0, 8);
            Array.Reverse(buffer, 4, 4);
            Array.Reverse(buffer, 8, 4);
            bf.Decrypt(buffer, 4, buffer, 4, 8);
            Array.Reverse(buffer, 4, 4);
            Array.Reverse(buffer, 8, 4);


            int version;
            int.TryParse(Encoding.ASCII.GetString(buffer, 4, 4), out version);

            if (PatchInfo.lastClientVersion != 0)
            {
                PatchInfo.lastClientVersion = (uint)version;
            }

            return (uint)version;
        }
04/26/2013 17:04 qkuh#2
Can be done more easily.
04/27/2013 19:37 tarek1500#3
I tried your come for ReadVersion , but doesn't read version correctly , when Array.Reverse removed it read well
04/30/2013 22:49 onekyh#4
Quote:
Originally Posted by qkuh View Post
Can be done more easily.
Yeah, but still. It works.


10/10.
11/27/2013 20:06 LemoniscooL#5
i know this is sort of an old thread, but it deserves more thanks
12/15/2013 08:44 Thabo#6
nice source
01/09/2016 18:49 spiele13#7
Hey,

i know its an old thread, but i searched for two days now and i can't find anything.
Could you guys please post the defenition of Blowfish function Decrypt/Encrypt.

Greets, spiele13.
01/09/2016 23:15 DaxterSoul#8
Quote:
Originally Posted by spiele13 View Post
but i searched for two days
I'm sure you did.

Silkroad uses the Blowfish in ECB Mode.
You could either use the Blowfish class which is publicly available for use in various language from it's [Only registered and activated users can see links. Click Here To Register...].
Or you use the one which pushedx included in his [Only registered and activated users can see links. Click Here To Register...].
01/10/2016 22:43 spiele13#9
Quote:
Originally Posted by DaxterSoul View Post
I'm sure you did.

Silkroad uses the Blowfish in ECB Mode.
You could either use the Blowfish class which is publicly available for use in various language from it's [Only registered and activated users can see links. Click Here To Register...].
Or you use the one which pushedx included in his [Only registered and activated users can see links. Click Here To Register...].
I did and i have the SilkroadSecurityApi, but there is no Decrypt/Encrypt function.
The bytes that are important are 4-12, i know that too. I tried to decode them but i failed. Thats why i ask here. :/

Thank you anyway for the answere.
01/11/2016 18:13 DaxterSoul#10
Quote:
Originally Posted by spiele13 View Post
I did and i have the SilkroadSecurityApi, but there is no Decrypt/Encrypt function.
Sometimes you need to think outside the box, because encrypt and decrypt are just names for a function.
[Only registered and activated users can see links. Click Here To Register...], [Only registered and activated users can see links. Click Here To Register...]

[Only registered and activated users can see links. Click Here To Register...]


Quote:
Originally Posted by spiele13 View Post
The bytes that are important are 4-12, i know that too. I tried to decode them but i failed. Thats why i ask here. :/
There is a much simpler way to read them, you don't really need to fuzz with those indices that much.

Have a look at this [Only registered and activated users can see links. Click Here To Register...], it might help you.
01/11/2016 22:05 spiele13#11
Quote:
Originally Posted by DaxterSoul View Post
Sometimes you need to think outside the box, because encrypt and decrypt are just names for a function.
[Only registered and activated users can see links. Click Here To Register...], [Only registered and activated users can see links. Click Here To Register...]

[Only registered and activated users can see links. Click Here To Register...]



There is a much simpler way to read them, you don't really need to fuzz with those indices that much.

Have a look at this [Only registered and activated users can see links. Click Here To Register...], it might help you.
Thank you very much. I did know that i could use Decode/Encode but they have less parameters, so i was not sure. My problem was that i read the file the wrong way and so every function of mine had a wrong buffer.

Thank you again for the helpful answers.
01/11/2016 22:33 DaxterSoul#12
Quote:
Originally Posted by spiele13 View Post
Thank you very much. I did know that i could use Decode/Encode but they have less parameters, so i was not sure.
You might need to read something about [Only registered and activated users can see links. Click Here To Register...] then, because this technique is heavily used everywhere in .NET.

[Only registered and activated users can see links. Click Here To Register...]