File: decode.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,940 kB
  • sloc: cs: 160,836; java: 42,449; javascript: 7,966; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 234; php: 142; xml: 117; sh: 21
file content (126 lines) | stat: -rw-r--r-- 3,540 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * SingerConfig.cs
 * Copyright (c) 2008-2009 kbinani
 *
 * This file is part of Boare.Lib.Vsq.
 *
 * Boare.Lib.Vsq is free software; you can redistribute it and/or
 * modify it under the terms of the BSD License.
 *
 * Boare.Lib.Vsq is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
using System;
using System.IO;
using System.Collections.Generic;

public class decode {
    public static void Main( string[] args ){
        if( args.Length <= 1 ){
            return;
        }
        string file = args[0];
        string result = args[1];
        FileStream fs = new FileStream( file, FileMode.Open, FileAccess.Read );
        byte[] buf = new byte[fs.Length];
        fs.Read( buf, 0, buf.Length );
        fs.Close();
        decode_vvd_bytes( ref buf );
        for ( int i = 0; i < buf.Length - 1; i++ ) {
            if ( buf[i] == 0x17 && buf[i + 1] == 0x10 ) {
                buf[i] = 0x0d;
                buf[i + 1] = 0x0a;
            }
        }
        FileStream fsout = new FileStream( result, FileMode.Create );
        fsout.Write( buf, 0, buf.Length );
        fsout.Close();
    }

    public static void decode_vvd_bytes( ref byte[] dat ) {
        for ( int i = 0; i < dat.Length; i++ ) {
            byte M = (byte)(dat[i] >> 4);
            byte L = (byte)(dat[i] - (M << 4));
            byte newM = endecode_vvd_m( M );
            byte newL = endecode_vvd_l( L );
            dat[i] = (byte)((newM << 4) | newL);
        }
    }

    static byte endecode_vvd_l( byte value ) {
        switch ( value ) {
            case 0x0:
                return 0xa;
            case 0x1:
                return 0xb;
            case 0x2:
                return 0x8;
            case 0x3:
                return 0x9;
            case 0x4:
                return 0xe;
            case 0x5:
                return 0xf;
            case 0x6:
                return 0xc;
            case 0x7:
                return 0xd;
            case 0x8:
                return 0x2;
            case 0x9:
                return 0x3;
            case 0xa:
                return 0x0;
            case 0xb:
                return 0x1;
            case 0xc:
                return 0x6;
            case 0xd:
                return 0x7;
            case 0xe:
                return 0x4;
            case 0xf:
                return 0x5;
        }
        return 0x0;
    }

    static byte endecode_vvd_m( byte value ) {
        switch ( value ) {
            case 0x0:
                return 0x1;
            case 0x1:
                return 0x0;
            case 0x2:
                return 0x3;
            case 0x3:
                return 0x2;
            case 0x4:
                return 0x5;
            case 0x5:
                return 0x4;
            case 0x6:
                return 0x7;
            case 0x7:
                return 0x6;
            case 0x8:
                return 0x9;
            case 0x9:
                return 0x8;
            case 0xa:
                return 0xb;
            case 0xb:
                return 0xa;
            case 0xc:
                return 0xd;
            case 0xd:
                return 0xc;
            case 0xe:
                return 0xf;
            case 0xf:
                return 0xe;
        }
        return 0x0;
    }
}