annotate unrarlib.c @ 15888:da752f91c5f2

Check for WAVEFORMAT.wFormatTag overflows and allow user to override the tag with -fafmttag
author ranma
date Sat, 02 Jul 2005 19:00:13 +0000
parents 775330fe3889
children 0783dd397f74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1 /* ***************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
3 ** This file is part of the UniquE RAR File Library.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
4 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
5 ** Copyright (C) 2000-2002 by Christian Scheurer (www.ChristianScheurer.ch)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
6 ** UNIX port copyright (c) 2000-2002 by Johannes Winkelmann (jw@tks6.net)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
7 **
15165
775330fe3889 Mark unrarlib imported files as changed to comply with GPL ¡ø2a.
diego
parents: 11013
diff changeset
8 ** Modified for use with MPlayer, detailed CVS changelog at
775330fe3889 Mark unrarlib imported files as changed to comply with GPL ¡ø2a.
diego
parents: 11013
diff changeset
9 ** http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
775330fe3889 Mark unrarlib imported files as changed to comply with GPL ¡ø2a.
diego
parents: 11013
diff changeset
10 ** $Id$
775330fe3889 Mark unrarlib imported files as changed to comply with GPL ¡ø2a.
diego
parents: 11013
diff changeset
11 **
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
12 ** The contents of this file are subject to the UniquE RAR File Library
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
13 ** License (the "unrarlib-license.txt"). You may not use this file except
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
14 ** in compliance with the License. You may obtain a copy of the License
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
15 ** at http://www.unrarlib.org/license.html.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
16 ** Software distributed under the License is distributed on an "AS IS"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
17 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied warranty.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
18 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
19 ** Alternatively, the contents of this file may be used under the terms
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
20 ** of the GNU General Public License Version 2 or later (the "GPL"), in
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
21 ** which case the provisions of the GPL are applicable instead of those
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
22 ** above. If you wish to allow use of your version of this file only
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
23 ** under the terms of the GPL and not to allow others to use your version
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
24 ** of this file under the terms of the UniquE RAR File Library License,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
25 ** indicate your decision by deleting the provisions above and replace
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
26 ** them with the notice and other provisions required by the GPL. If you
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
27 ** do not delete the provisions above, a recipient may use your version
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
28 ** of this file under the terms of the GPL or the UniquE RAR File Library
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
29 ** License.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
30 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
31 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
32
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
33 /* ***************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
34 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
35 ** UniquE RAR File Library
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
36 ** The free file lib for the demoscene
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
37 ** multi-OS version (Win32, Linux and SunOS)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
38 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
39 *****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
40 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
41 ** ==> Please configure the program in "unrarlib.h". <==
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
42 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
43 ** RAR decompression code:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
44 ** (C) Eugene Roshal
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
45 ** Modifications to a FileLib:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
46 ** (C) 2000-2002 Christian Scheurer aka. UniquE/Vantage (cs@unrarlib.org)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
47 ** Linux port:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
48 ** (C) 2000-2002 Johannes Winkelmann (jw@tks6.net)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
49 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
50 ** The UniquE RAR File Library gives you the ability to access RAR archives
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
51 ** (any compression method supported in RAR v2.0 including Multimedia
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
52 ** Compression and encryption) directly from your program with ease an by
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
53 ** adding only 12kB (6kB UPX-compressed) additional code to your program.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
54 ** Both solid and normal (recommended for fast random access to the files!)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
55 ** archives are supported. This FileLib is made for the Demo scene, so it's
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
56 ** designed for easy use within your demos and intros.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
57 ** Please read "licence.txt" to learn more about how you may use URARFileLib
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
58 ** in your productions.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
59 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
60 *****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
61 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
62 ** ==> see the "CHANGES" file to see what's new
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
63 **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
64 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
65
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
66 /* -- include files ------------------------------------------------------- */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
67 #include "unrarlib.h" /* include global configuration */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
68 /* ------------------------------------------------------------------------ */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
69
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
70
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
71
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
72 /* -- global stuff -------------------------------------------------------- */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
73 #ifdef _WIN_32
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
74
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
75 #include <windows.h> /* WIN32 definitions */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
76 #include <stdio.h>
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
77 #include <string.h>
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
78
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
79
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
80 #define ENABLE_ACCESS
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
81
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
82 #define HOST_OS WIN_32
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
83
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
84 #define FM_NORMAL 0x00
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
85 #define FM_RDONLY 0x01
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
86 #define FM_HIDDEN 0x02
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
87 #define FM_SYSTEM 0x04
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
88 #define FM_LABEL 0x08
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
89 #define FM_DIREC 0x10
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
90 #define FM_ARCH 0x20
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
91
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
92 #define PATHDIVIDER "\\"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
93 #define CPATHDIVIDER '\\'
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
94 #define MASKALL "*.*"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
95
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
96 #define READBINARY "rb"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
97 #define READTEXT "rt"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
98 #define UPDATEBINARY "r+b"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
99 #define CREATEBINARY "w+b"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
100 #define CREATETEXT "w"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
101 #define APPENDTEXT "at"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
102
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
103 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
104
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
105 #ifdef _UNIX
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
106
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
107 #include <stdio.h> /* LINUX/UNIX definitions */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
108 #include <stdlib.h>
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
109 #include <ctype.h>
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
110 #include <string.h>
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
111
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
112 #define ENABLE_ACCESS
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
113
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
114 #define HOST_OS UNIX
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
115
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
116 #define FM_LABEL 0x0000
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
117 #define FM_DIREC 0x4000
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
118
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
119 #define PATHDIVIDER "/"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
120 #define CPATHDIVIDER '/'
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
121 #define MASKALL "*.*"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
122
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
123 #define READBINARY "r"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
124 #define READTEXT "r"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
125 #define UPDATEBINARY "r+"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
126 #define CREATEBINARY "w+"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
127 #define CREATETEXT "w"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
128 #define APPENDTEXT "a"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
129
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
130
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
131 /* emulation of the windows API and data types */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
132 /* 20-08-2000 Johannes Winkelmann, jw@tks6.net */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
133
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
134 typedef long DWORD;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
135 typedef short BOOL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
136 #define TRUE 1
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
137 #define FALSE 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
138
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
139
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
140 #ifdef _DEBUG_LOG /* define macros for debugging */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
141 #include <unistd.h>
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
142 #include <sys/time.h>
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
143
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
144 DWORD GetTickCount()
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
145 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
146 struct timeval tv;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
147 gettimeofday( &tv, 0 );
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
148 return (tv.tv_usec / 1000);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
149 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
150 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
151
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
152 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
153
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
154
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
155
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
156
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
157
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
158 #ifdef _DEBUG_LOG /* define macros for debugging */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
159
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
160 BOOL debug_log_first_start = TRUE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
161
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
162 #define debug_log(a); debug_log_proc(a, __FILE__, __LINE__);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
163 #define debug_init(a); debug_init_proc(a);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
164
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
165 void debug_log_proc(char *text, char *sourcefile, int sourceline);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
166 void debug_init_proc(char *file_name);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
167
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
168 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
169 #define debug_log(a); /* no debug this time */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
170 #define debug_init(a); /* no debug this time */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
171 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
172
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
173
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
174
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
175
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
176
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
177 #define MAXWINSIZE 0x100000
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
178 #define MAXWINMASK (MAXWINSIZE-1)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
179 #define UNP_MEMORY MAXWINSIZE
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
180 #define Min(x,y) (((x)<(y)) ? (x):(y))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
181 #define Max(x,y) (((x)>(y)) ? (x):(y))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
182 #define NM 260
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
183
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
184 #define SIZEOF_MARKHEAD 7
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
185 #define SIZEOF_OLDMHD 7
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
186 #define SIZEOF_NEWMHD 13
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
187 #define SIZEOF_OLDLHD 21
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
188 #define SIZEOF_NEWLHD 32
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
189 #define SIZEOF_SHORTBLOCKHEAD 7
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
190 #define SIZEOF_LONGBLOCKHEAD 11
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
191 #define SIZEOF_COMMHEAD 13
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
192 #define SIZEOF_PROTECTHEAD 26
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
193
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
194
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
195 #define PACK_VER 20 /* version of decompression code*/
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
196 #define UNP_VER 20
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
197 #define PROTECT_VER 20
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
198
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
199
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
200 enum { M_DENYREAD,M_DENYWRITE,M_DENYNONE,M_DENYALL };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
201 enum { FILE_EMPTY,FILE_ADD,FILE_UPDATE,FILE_COPYOLD,FILE_COPYBLOCK };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
202 enum { SUCCESS,WARNING,FATAL_ERROR,CRC_ERROR,LOCK_ERROR,WRITE_ERROR,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
203 OPEN_ERROR,USER_ERROR,MEMORY_ERROR,USER_BREAK=255,IMM_ABORT=0x8000 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
204 enum { EN_LOCK=1,EN_VOL=2 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
205 enum { SD_MEMORY=1,SD_FILES=2 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
206 enum { NAMES_DONTCHANGE };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
207 enum { LOG_ARC=1,LOG_FILE=2 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
208 enum { OLD_DECODE=0,OLD_ENCODE=1,NEW_CRYPT=2 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
209 enum { OLD_UNPACK,NEW_UNPACK };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
210
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
211
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
212 #define MHD_COMMENT 2
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
213 #define MHD_LOCK 4
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
214 #define MHD_PACK_COMMENT 16
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
215 #define MHD_AV 32
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
216 #define MHD_PROTECT 64
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
217
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
218 #define LHD_SPLIT_BEFORE 1
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
219 #define LHD_SPLIT_AFTER 2
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
220 #define LHD_PASSWORD 4
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
221 #define LHD_COMMENT 8
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
222 #define LHD_SOLID 16
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
223
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
224 #define LHD_WINDOWMASK 0x00e0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
225 #define LHD_WINDOW64 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
226 #define LHD_WINDOW128 32
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
227 #define LHD_WINDOW256 64
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
228 #define LHD_WINDOW512 96
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
229 #define LHD_WINDOW1024 128
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
230 #define LHD_DIRECTORY 0x00e0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
231
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
232 #define LONG_BLOCK 0x8000
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
233 #define READSUBBLOCK 0x8000
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
234
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
235 enum { ALL_HEAD=0,MARK_HEAD=0x72,MAIN_HEAD=0x73,FILE_HEAD=0x74,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
236 COMM_HEAD=0x75,AV_HEAD=0x76,SUB_HEAD=0x77,PROTECT_HEAD=0x78};
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
237 enum { EA_HEAD=0x100 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
238 enum { MS_DOS=0,OS2=1,WIN_32=2,UNIX=3 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
239
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
240
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
241 struct MarkHeader
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
242 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
243 UBYTE Mark[7];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
244 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
245
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
246
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
247 struct NewMainArchiveHeader
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
248 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
249 UWORD HeadCRC;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
250 UBYTE HeadType;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
251 UWORD Flags;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
252 UWORD HeadSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
253 UWORD Reserved;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
254 UDWORD Reserved1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
255 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
256
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
257
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
258 struct NewFileHeader
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
259 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
260 UWORD HeadCRC;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
261 UBYTE HeadType;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
262 UWORD Flags;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
263 UWORD HeadSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
264 UDWORD PackSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
265 UDWORD UnpSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
266 UBYTE HostOS;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
267 UDWORD FileCRC;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
268 UDWORD FileTime;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
269 UBYTE UnpVer;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
270 UBYTE Method;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
271 UWORD NameSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
272 UDWORD FileAttr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
273 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
274
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
275
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
276 struct BlockHeader
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
277 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
278 UWORD HeadCRC;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
279 UBYTE HeadType;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
280 UWORD Flags;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
281 UWORD HeadSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
282 UDWORD DataSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
283 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
284
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
285
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
286 struct Decode
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
287 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
288 unsigned int MaxNum;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
289 unsigned int DecodeLen[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
290 unsigned int DecodePos[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
291 unsigned int DecodeNum[2];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
292 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
293
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
294
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
295 struct MarkHeader MarkHead;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
296 struct NewMainArchiveHeader NewMhd;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
297 struct NewFileHeader NewLhd;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
298 struct BlockHeader BlockHead;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
299
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
300 static UBYTE *TempMemory = NULL; /* temporary unpack-buffer */
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
301 static char *CommMemory = NULL;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
302
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
303
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
304 static UBYTE *UnpMemory = NULL;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
305 static char* ArgName = NULL; /* current file in rar archive */
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
306 static char* ArcFileName = NULL; /* file to decompress */
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
307
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
308 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION /* mem-to-mem decompression */
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
309 static MemoryFile *MemRARFile; /* pointer to RAR file in memory*/
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
310 #else
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
311 static char* ArcName = NULL; /* RAR archive name */
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
312 static FILE *ArcPtr; /* input RAR file handler */
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
313 #endif
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
314 static char *Password = NULL; /* password to decrypt files */
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
315
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
316 static unsigned char *temp_output_buffer; /* extract files to this pointer*/
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
317 static unsigned long *temp_output_buffer_offset; /* size of temp. extract buffer */
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
318
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
319 static BOOL FileFound; /* TRUE=use current extracted */
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
320 /* data FALSE=throw data away, */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
321 /* wrong file */
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
322 static int MainHeadSize;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
323 static long CurBlockPos,NextBlockPos;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
324
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
325 static unsigned long CurUnpRead, CurUnpWrite;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
326 static long UnpPackedSize;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
327 static long DestUnpSize;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
328
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
329 static UDWORD HeaderCRC;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
330 static int Encryption;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
331
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
332 //static unsigned int UnpWrSize;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
333 //static unsigned char *UnpWrAddr;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
334 static unsigned int UnpPtr,WrPtr;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
335
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
336 static unsigned char PN1,PN2,PN3;
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
337 static unsigned short OldKey[4];
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
338
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
339
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
340
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
341 /* function header definitions */
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
342 static int ReadHeader(int BlockType);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
343 static BOOL ExtrFile(void);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
344 //BOOL ListFile(void);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
345 static int tread(void *stream,void *buf,unsigned len);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
346 static int tseek(void *stream,long offset,int fromwhere);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
347 static BOOL UnstoreFile(void);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
348 static int IsArchive(void);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
349 static int ReadBlock(int BlockType);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
350 static unsigned int UnpRead(unsigned char *Addr,unsigned int Count);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
351 static void UnpInitData(void);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
352 static void Unpack(unsigned char *UnpAddr);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
353 static UBYTE DecodeAudio(int Delta);
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
354 static void DecodeNumber(struct Decode *Dec);
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
355 static void UpdKeys(UBYTE *Buf);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
356 static void SetCryptKeys(char *Password);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
357 static void SetOldKeys(char *Password);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
358 static void DecryptBlock(unsigned char *Buf);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
359 static void InitCRC(void);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
360 static UDWORD CalcCRC32(UDWORD StartCRC,UBYTE *Addr,UDWORD Size);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
361 static void UnpReadBuf(int FirstBuf);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
362 static void ReadTables(void);
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
363 static void ReadLastTables(void);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
364 static void MakeDecodeTables(unsigned char *LenTab,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
365 struct Decode *Dec,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
366 int Size);
10127
228a767a51fd avoid symbol clash with never samba versions (btw, unrarlib.c is full of global variables, with common names :( and it's a bit bloated, I think)
alex
parents: 9584
diff changeset
367 static int my_stricomp(char *Str1,char *Str2);
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
368 /* ------------------------------------------------------------------------ */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
369
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
370
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
371 /* -- global functions ---------------------------------------------------- */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
372
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
373 int urarlib_get(void *output,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
374 unsigned long *size,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
375 char *filename,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
376 void *rarfile,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
377 char *libpassword)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
378 /* Get a file from a RAR file to the "output" buffer. The UniquE RAR FileLib
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
379 * does everything from allocating memory, decrypting and unpacking the file
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
380 * from the archive. TRUE is returned if the file could be successfully
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
381 * extracted, else a FALSE indicates a failure.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
382 */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
383 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
384 BOOL retcode = FALSE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
385
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
386 #ifdef _DEBUG_LOG
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
387 int str_offs; /* used for debug-strings */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
388 char DebugMsg[500]; /* used to compose debug msg */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
389
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
390 if(debug_log_first_start)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
391 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
392 debug_log_first_start=FALSE; /* only create a new log file */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
393 debug_init(_DEBUG_LOG_FILE); /* on startup */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
394 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
395
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
396 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
397
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
398 InitCRC(); /* init some vars */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
399
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
400 if(ArgName) free(ArgName);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
401 ArgName = strdup(filename); /* set file(s) to extract */
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
402 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
403 MemRARFile = rarfile; /* set pointer to mem-RAR file */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
404 #else
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
405 if(ArcName) free(ArcName);
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
406 ArcName = strdup(rarfile); /* set RAR file name */
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
407 #endif
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
408 if(Password) free(Password);
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
409 if(libpassword != NULL)
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
410 Password = strdup(libpassword); /* init password */
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
411 else
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
412 Password = strdup("");
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
413
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
414 temp_output_buffer = NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
415 temp_output_buffer_offset=size; /* set size of the temp buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
416
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
417 #ifdef _DEBUG_LOG
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
418 sprintf(DebugMsg, "Extracting >%s< from >%s< (password is >%s<)...",
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
419 filename, (char*)rarfile, libpassword);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
420 debug_log(DebugMsg);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
421 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
422
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
423 retcode = ExtrFile(); /* unpack file now! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
424
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
425 //memset(Password,0,sizeof(Password)); /* clear password */
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
426
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
427 #ifndef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
428 if (ArcPtr!=NULL){
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
429 fclose(ArcPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
430 ArcPtr = NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
431 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
432 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
433
9584
31126ea5cd36 Some free(NULL) found with njamd
albeu
parents: 8451
diff changeset
434 if(UnpMemory) free(UnpMemory); /* free memory */
31126ea5cd36 Some free(NULL) found with njamd
albeu
parents: 8451
diff changeset
435 if(TempMemory) free(TempMemory);
31126ea5cd36 Some free(NULL) found with njamd
albeu
parents: 8451
diff changeset
436 if(CommMemory) free(CommMemory);
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
437 UnpMemory=NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
438 TempMemory=NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
439 CommMemory=NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
440
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
441
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
442 if(retcode == FALSE)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
443 {
9584
31126ea5cd36 Some free(NULL) found with njamd
albeu
parents: 8451
diff changeset
444 if(temp_output_buffer) /* free memory and return NULL */
31126ea5cd36 Some free(NULL) found with njamd
albeu
parents: 8451
diff changeset
445 free(temp_output_buffer);
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
446 temp_output_buffer=NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
447 *(DWORD*)output=0; /* pointer on errors */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
448 *size=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
449 #ifdef _DEBUG_LOG
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
450
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
451
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
452 /* sorry for this ugly code, but older SunOS gcc compilers don't support */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
453 /* white spaces within strings */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
454 str_offs = sprintf(DebugMsg, "Error - couldn't extract ");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
455 str_offs += sprintf(DebugMsg + str_offs, ">%s<", filename);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
456 str_offs += sprintf(DebugMsg + str_offs, " and allocated ");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
457 str_offs += sprintf(DebugMsg + str_offs, "%u Bytes", (unsigned int)*size);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
458 str_offs += sprintf(DebugMsg + str_offs, " of unused memory!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
459
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
460 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
461 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
462 sprintf(DebugMsg, "Extracted %u Bytes.", (unsigned int)*size);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
463 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
464 debug_log(DebugMsg);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
465 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
466 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
467 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
468 *(DWORD*)output=(DWORD)temp_output_buffer;/* return pointer for unpacked*/
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
469 /* data */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
470
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
471 return retcode;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
472 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
473
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
474
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
475 int urarlib_list(void *rarfile, ArchiveList_struct *list)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
476 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
477 ArchiveList_struct *tmp_List = NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
478 int NoOfFilesInArchive = 0; /* number of files in archive */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
479
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
480 #ifdef _DEBUG_LOG
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
481 if(debug_log_first_start)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
482 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
483 debug_log_first_start=FALSE; /* only create a new log file */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
484 debug_init(_DEBUG_LOG_FILE); /* on startup */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
485 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
486 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
487
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
488 InitCRC(); /* init some vars */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
489
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
490 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
491 MemRARFile = rarfile; /* assign pointer to RAR file */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
492 MemRARFile->offset = 0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
493 if (!IsArchive())
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
494 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
495 debug_log("Not a RAR file");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
496 return NoOfFilesInArchive; /* error => exit! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
497 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
498 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
499 /* open and identify archive */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
500 if ((ArcPtr=fopen(rarfile,READBINARY))!=NULL)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
501 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
502 if (!IsArchive())
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
503 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
504 debug_log("Not a RAR file");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
505 fclose(ArcPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
506 ArcPtr = NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
507 return NoOfFilesInArchive; /* error => exit! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
508 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
509 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
510 else {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
511 debug_log("Error opening file.");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
512 return NoOfFilesInArchive;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
513 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
514 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
515
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
516 if ((UnpMemory=malloc(UNP_MEMORY))==NULL)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
517 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
518 debug_log("Can't allocate memory for decompression!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
519 return NoOfFilesInArchive;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
520 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
521
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
522 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
523 MemRARFile->offset+=NewMhd.HeadSize-MainHeadSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
524 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
525 tseek(ArcPtr,NewMhd.HeadSize-MainHeadSize,SEEK_CUR);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
526 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
527 (*(DWORD*)list) = (DWORD)NULL; /* init file list */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
528 /* do while file is not extracted and there's no error */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
529 while (TRUE)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
530 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
531 if (ReadBlock(FILE_HEAD | READSUBBLOCK) <= 0) /* read name of the next */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
532 { /* file within the RAR archive */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
533 debug_log("Couldn't read next filename from archive (I/O error).");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
534 break; /* error, file not found in */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
535 } /* archive or I/O error */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
536 if (BlockHead.HeadType==SUB_HEAD)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
537 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
538 debug_log("Sorry, sub-headers not supported.");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
539 break; /* error => exit */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
540 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
541
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
542 if((void*)(*(DWORD*)list) == NULL) /* first entry */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
543 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
544 tmp_List = malloc(sizeof(ArchiveList_struct));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
545 tmp_List->next = NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
546
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
547 (*(DWORD*)list) = (DWORD)tmp_List;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
548
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
549 } else /* add entry */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
550 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
551 tmp_List->next = malloc(sizeof(ArchiveList_struct));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
552 tmp_List = (ArchiveList_struct*) tmp_List->next;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
553 tmp_List->next = NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
554 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
555
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
556 tmp_List->item.Name = malloc(NewLhd.NameSize + 1);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
557 strcpy(tmp_List->item.Name, ArcFileName);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
558 tmp_List->item.NameSize = NewLhd.NameSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
559 tmp_List->item.PackSize = NewLhd.PackSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
560 tmp_List->item.UnpSize = NewLhd.UnpSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
561 tmp_List->item.HostOS = NewLhd.HostOS;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
562 tmp_List->item.FileCRC = NewLhd.FileCRC;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
563 tmp_List->item.FileTime = NewLhd.FileTime;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
564 tmp_List->item.UnpVer = NewLhd.UnpVer;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
565 tmp_List->item.Method = NewLhd.Method;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
566 tmp_List->item.FileAttr = NewLhd.FileAttr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
567
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
568 NoOfFilesInArchive++; /* count files */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
569
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
570 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
571 MemRARFile->offset = NextBlockPos;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
572 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
573 if (ArcPtr!=NULL) tseek(ArcPtr,NextBlockPos,SEEK_SET);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
574 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
575
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
576 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
577
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
578 /* free memory, clear password and close archive */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
579 memset(Password,0,sizeof(Password)); /* clear password */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
580 #ifndef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
581 if (ArcPtr!=NULL){
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
582 fclose(ArcPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
583 ArcPtr = NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
584 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
585 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
586
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
587 free(UnpMemory); /* free memory */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
588 free(TempMemory);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
589 free(CommMemory);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
590 UnpMemory=NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
591 TempMemory=NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
592 CommMemory=NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
593
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
594 return NoOfFilesInArchive;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
595 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
596
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
597
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
598
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
599 /* urarlib_freelist:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
600 * (after the suggestion and code of Duy Nguyen, Sean O'Blarney
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
601 * and Johannes Winkelmann who independently wrote a patch)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
602 * free the memory of a ArchiveList_struct created by urarlib_list.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
603 *
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
604 * input: *list pointer to an ArchiveList_struct
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
605 * output: -
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
606 */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
607
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
608 void urarlib_freelist(ArchiveList_struct *list)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
609 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
610 ArchiveList_struct* tmp = list;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
611
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
612 while ( list ) {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
613 tmp = list->next;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
614 free( list->item.Name );
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
615 free( list );
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
616 list = tmp;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
617 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
618 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
619
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
620
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
621 /* ------------------------------------------------------------------------ */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
622
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
623
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
624
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
625
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
626
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
627
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
628
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
629
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
630
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
631
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
632
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
633
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
634
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
635
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
636
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
637
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
638
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
639 /****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
640 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
641 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
642 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
643 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
644 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
645 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
646 ******* B L O C K I / O *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
647 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
648 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
649 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
650 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
651 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
652 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
653 ****************************************************************************/
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
654
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
655
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
656
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
657 #define GetHeaderByte(N) Header[N]
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
658
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
659 #define GetHeaderWord(N) (Header[N]+((UWORD)Header[N+1]<<8))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
660
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
661 #define GetHeaderDword(N) (Header[N]+((UWORD)Header[N+1]<<8)+\
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
662 ((UDWORD)Header[N+2]<<16)+\
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
663 ((UDWORD)Header[N+3]<<24))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
664
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
665
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
666 int ReadBlock(int BlockType)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
667 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
668 struct NewFileHeader SaveFileHead;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
669 int Size=0,ReadSubBlock=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
670 static int LastBlock;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
671 memcpy(&SaveFileHead,&NewLhd,sizeof(SaveFileHead));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
672 if (BlockType & READSUBBLOCK)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
673 ReadSubBlock=1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
674 BlockType &= 0xff;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
675 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
676 while (1)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
677 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
678 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
679 CurBlockPos=MemRARFile->offset; /* get offset of mem-file */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
680 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
681 CurBlockPos=ftell(ArcPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
682 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
683 Size=ReadHeader(FILE_HEAD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
684 if (Size!=0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
685 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
686 if (NewLhd.HeadSize<SIZEOF_SHORTBLOCKHEAD)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
687 return(0);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
688 NextBlockPos=CurBlockPos+NewLhd.HeadSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
689 if (NewLhd.Flags & LONG_BLOCK)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
690 NextBlockPos+=NewLhd.PackSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
691 if (NextBlockPos<=CurBlockPos)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
692 return(0);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
693 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
694
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
695 if (Size > 0 && BlockType!=SUB_HEAD)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
696 LastBlock=BlockType;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
697 if (Size==0 || BlockType==ALL_HEAD || NewLhd.HeadType==BlockType ||
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
698 (NewLhd.HeadType==SUB_HEAD && ReadSubBlock && LastBlock==BlockType))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
699 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
700 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
701 MemRARFile->offset = NextBlockPos;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
702 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
703 tseek(ArcPtr, NextBlockPos, SEEK_SET);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
704 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
705 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
706 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
707
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
708 BlockHead.HeadCRC=NewLhd.HeadCRC;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
709 BlockHead.HeadType=NewLhd.HeadType;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
710 BlockHead.Flags=NewLhd.Flags;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
711 BlockHead.HeadSize=NewLhd.HeadSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
712 BlockHead.DataSize=NewLhd.PackSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
713
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
714 if (BlockType!=NewLhd.HeadType) BlockType=ALL_HEAD;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
715
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
716 if((FILE_HEAD == BlockType) && (Size>0))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
717 {
11013
49818f04efb9 100L fix the bug added by last commit
albeu
parents: 10815
diff changeset
718 ArcFileName=realloc(ArcFileName,NewLhd.NameSize+1);
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
719 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
720 tread(MemRARFile, ArcFileName, NewLhd.NameSize);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
721 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
722 tread(ArcPtr,ArcFileName,NewLhd.NameSize);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
723 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
724 ArcFileName[NewLhd.NameSize]=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
725 #ifdef _DEBUG_LOG
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
726 if (NewLhd.HeadCRC!=(UWORD)~CalcCRC32(HeaderCRC,(UBYTE*)&ArcFileName[0],
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
727 NewLhd.NameSize))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
728 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
729 debug_log("file header broken");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
730 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
731 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
732 Size+=NewLhd.NameSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
733 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
734 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
735 memcpy(&NewLhd,&SaveFileHead,sizeof(NewLhd));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
736 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
737 MemRARFile->offset = CurBlockPos;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
738 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
739 tseek(ArcPtr,CurBlockPos,SEEK_SET);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
740 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
741 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
742
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
743
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
744 return(Size);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
745 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
746
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
747
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
748 int ReadHeader(int BlockType)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
749 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
750 int Size = 0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
751 unsigned char Header[64];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
752 switch(BlockType)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
753 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
754 case MAIN_HEAD:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
755 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
756 Size=tread(MemRARFile, Header, SIZEOF_NEWMHD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
757 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
758 Size=tread(ArcPtr,Header,SIZEOF_NEWMHD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
759 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
760 NewMhd.HeadCRC=(unsigned short)GetHeaderWord(0);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
761 NewMhd.HeadType=GetHeaderByte(2);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
762 NewMhd.Flags=(unsigned short)GetHeaderWord(3);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
763 NewMhd.HeadSize=(unsigned short)GetHeaderWord(5);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
764 NewMhd.Reserved=(unsigned short)GetHeaderWord(7);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
765 NewMhd.Reserved1=GetHeaderDword(9);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
766 HeaderCRC=CalcCRC32(0xFFFFFFFFL,&Header[2],SIZEOF_NEWMHD-2);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
767 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
768 case FILE_HEAD:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
769 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
770 Size=tread(MemRARFile, Header, SIZEOF_NEWLHD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
771 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
772 Size=tread(ArcPtr,Header,SIZEOF_NEWLHD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
773 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
774 NewLhd.HeadCRC=(unsigned short)GetHeaderWord(0);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
775 NewLhd.HeadType=GetHeaderByte(2);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
776 NewLhd.Flags=(unsigned short)GetHeaderWord(3);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
777 NewLhd.HeadSize=(unsigned short)GetHeaderWord(5);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
778 NewLhd.PackSize=GetHeaderDword(7);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
779 NewLhd.UnpSize=GetHeaderDword(11);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
780 NewLhd.HostOS=GetHeaderByte(15);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
781 NewLhd.FileCRC=GetHeaderDword(16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
782 NewLhd.FileTime=GetHeaderDword(20);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
783 NewLhd.UnpVer=GetHeaderByte(24);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
784 NewLhd.Method=GetHeaderByte(25);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
785 NewLhd.NameSize=(unsigned short)GetHeaderWord(26);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
786 NewLhd.FileAttr=GetHeaderDword(28);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
787 HeaderCRC=CalcCRC32(0xFFFFFFFFL,&Header[2],SIZEOF_NEWLHD-2);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
788 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
789
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
790 #ifdef _DEBUG_LOG
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
791 case COMM_HEAD: /* log errors in case of debug */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
792 debug_log("Comment headers not supported! "\
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
793 "Please create archives without comments.");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
794 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
795 case PROTECT_HEAD:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
796 debug_log("Protected headers not supported!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
797 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
798 case ALL_HEAD:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
799 debug_log("ShortBlockHeader not supported!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
800 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
801 default:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
802 debug_log("Unknown//unsupported !");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
803 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
804 default: /* else do nothing */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
805 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
806 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
807 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
808 return(Size);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
809 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
810
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
811 /* **************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
812 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
813 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
814 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
815
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
816
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
817
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
818
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
819
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
820
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
821
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
822
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
823
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
824
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
825
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
826
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
827
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
828
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
829
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
830
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
831
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
832 /* **************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
833 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
834 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
835 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
836 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
837 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
838 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
839 ******* E X T R A C T L O O P *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
840 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
841 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
842 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
843 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
844 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
845 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
846 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
847
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
848
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
849 int IsArchive(void)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
850 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
851 #ifdef _DEBUG_LOG
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
852 int str_offs; /* used for debug-strings */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
853 char DebugMsg[500]; /* used to compose debug msg */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
854 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
855
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
856 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
857 if (tread(MemRARFile, MarkHead.Mark, SIZEOF_MARKHEAD) != SIZEOF_MARKHEAD)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
858 return(FALSE);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
859 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
860 if (tread(ArcPtr,MarkHead.Mark,SIZEOF_MARKHEAD)!=SIZEOF_MARKHEAD)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
861 return(FALSE);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
862 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
863 /* Old archive => error */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
864 if (MarkHead.Mark[0]==0x52 && MarkHead.Mark[1]==0x45 &&
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
865 MarkHead.Mark[2]==0x7e && MarkHead.Mark[3]==0x5e)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
866 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
867 debug_log("Attention: format as OLD detected! Can't handel archive!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
868 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
869 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
870 /* original RAR v2.0 */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
871 if ((MarkHead.Mark[0]==0x52 && MarkHead.Mark[1]==0x61 && /* original */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
872 MarkHead.Mark[2]==0x72 && MarkHead.Mark[3]==0x21 && /* RAR header*/
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
873 MarkHead.Mark[4]==0x1a && MarkHead.Mark[5]==0x07 &&
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
874 MarkHead.Mark[6]==0x00) ||
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
875 /* "UniquE!" - header */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
876 (MarkHead.Mark[0]=='U' && MarkHead.Mark[1]=='n' && /* "UniquE!" */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
877 MarkHead.Mark[2]=='i' && MarkHead.Mark[3]=='q' && /* header */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
878 MarkHead.Mark[4]=='u' && MarkHead.Mark[5]=='E' &&
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
879 MarkHead.Mark[6]=='!'))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
880
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
881 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
882 if (ReadHeader(MAIN_HEAD)!=SIZEOF_NEWMHD)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
883 return(FALSE);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
884 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
885 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
886
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
887 #ifdef _DEBUG_LOG
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
888 /* sorry for this ugly code, but older SunOS gcc compilers don't */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
889 /* support white spaces within strings */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
890 str_offs = sprintf(DebugMsg, "unknown archive type (only plain RAR ");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
891 str_offs += sprintf(DebugMsg + str_offs, "supported (normal and solid ");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
892 str_offs += sprintf(DebugMsg + str_offs, "archives), SFX and Volumes ");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
893 str_offs += sprintf(DebugMsg + str_offs, "are NOT supported!)");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
894
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
895 debug_log(DebugMsg);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
896 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
897
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
898 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
899
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
900
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
901 MainHeadSize=SIZEOF_NEWMHD;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
902
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
903 return(TRUE);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
904 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
905
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
906
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
907 BOOL ExtrFile(void)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
908 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
909 BOOL ReturnCode=TRUE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
910 FileFound=FALSE; /* no file found by default */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
911
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
912 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
913 MemRARFile->offset = 0; /* start reading from offset 0 */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
914 if (!IsArchive())
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
915 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
916 debug_log("Not a RAR file");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
917 return FALSE; /* error => exit! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
918 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
919
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
920 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
921 /* open and identify archive */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
922 if ((ArcPtr=fopen(ArcName,READBINARY))!=NULL)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
923 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
924 if (!IsArchive())
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
925 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
926 debug_log("Not a RAR file");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
927 fclose(ArcPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
928 ArcPtr = NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
929 return FALSE; /* error => exit! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
930 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
931 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
932 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
933 debug_log("Error opening file.");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
934 return FALSE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
935 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
936 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
937
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
938
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
939 if ((UnpMemory=malloc(UNP_MEMORY))==NULL)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
940 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
941 debug_log("Can't allocate memory for decompression!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
942 return FALSE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
943 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
944
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
945 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
946 MemRARFile->offset+=NewMhd.HeadSize-MainHeadSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
947 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
948 tseek(ArcPtr,NewMhd.HeadSize-MainHeadSize,SEEK_CUR);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
949 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
950
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
951 /* do while file is not extracted and there's no error */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
952 do
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
953 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
954
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
955 if (ReadBlock(FILE_HEAD | READSUBBLOCK) <= 0) /* read name of the next */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
956 { /* file within the RAR archive */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
957 /*
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
958 *
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
959 * 21.11.2000 UnQ There's a problem with some linux distros when a file
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
960 * can not be found in an archive.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
961 *
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
962 * debug_log("Couldn't read next filename from archive (I/O error).");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
963 *
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
964 */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
965 ReturnCode=FALSE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
966 break; /* error, file not found in */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
967 } /* archive or I/O error */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
968 if (BlockHead.HeadType==SUB_HEAD)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
969 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
970 debug_log("Sorry, sub-headers not supported.");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
971 ReturnCode=FALSE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
972 break; /* error => exit */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
973 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
974
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
975
10127
228a767a51fd avoid symbol clash with never samba versions (btw, unrarlib.c is full of global variables, with common names :( and it's a bit bloated, I think)
alex
parents: 9584
diff changeset
976 if(TRUE == (FileFound=(my_stricomp(ArgName, ArcFileName) == 0)))
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
977 /* *** file found! *** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
978 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
979 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
980 temp_output_buffer=malloc(NewLhd.UnpSize);/* allocate memory for the*/
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
981 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
982 *temp_output_buffer_offset=0; /* file. The default offset */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
983 /* within the buffer is 0 */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
984
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
985 if(temp_output_buffer == NULL)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
986 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
987 debug_log("can't allocate memory for the file decompression");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
988 ReturnCode=FALSE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
989 break; /* error, can't extract file! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
990 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
991
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
992
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
993 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
994
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
995 /* in case of a solid archive, we need to decompress any single file till
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
996 * we have found the one we are looking for. In case of normal archives
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
997 * (recommended!!), we skip the files until we are sure that it is the
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
998 * one we want.
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
999 */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1000 if((NewMhd.Flags & 0x08) || FileFound)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1001 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1002 if (NewLhd.UnpVer<13 || NewLhd.UnpVer>UNP_VER)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1003 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1004 debug_log("unknown compression method");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1005 ReturnCode=FALSE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1006 break; /* error, can't extract file! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1007 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1008
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1009 CurUnpRead=CurUnpWrite=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1010 if ((*Password!=0) && (NewLhd.Flags & LHD_PASSWORD))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1011 Encryption=NewLhd.UnpVer;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1012 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1013 Encryption=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1014 if (Encryption) SetCryptKeys(Password);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1015
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1016 UnpPackedSize=NewLhd.PackSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1017 DestUnpSize=NewLhd.UnpSize;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1018
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1019 if (NewLhd.Method==0x30)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1020 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1021 UnstoreFile();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1022 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1023 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1024 Unpack(UnpMemory);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1025 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1026
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1027
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1028
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1029 #ifdef _DO_CRC32_CHECK /* calculate CRC32 */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1030 if((UBYTE*)temp_output_buffer != NULL)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1031 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1032 if(NewLhd.FileCRC!=~CalcCRC32(0xFFFFFFFFL,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1033 (UBYTE*)temp_output_buffer,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1034 NewLhd.UnpSize))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1035 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1036 debug_log("CRC32 error - file couldn't be decompressed correctly!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1037 ReturnCode=FALSE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1038 break; /* error, can't extract file! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1039 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1040 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1041 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1042
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1043 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1044
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1045 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1046 MemRARFile->offset = NextBlockPos;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1047 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1048 if (ArcPtr!=NULL) tseek(ArcPtr,NextBlockPos,SEEK_SET);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1049 #endif
10127
228a767a51fd avoid symbol clash with never samba versions (btw, unrarlib.c is full of global variables, with common names :( and it's a bit bloated, I think)
alex
parents: 9584
diff changeset
1050 } while(my_stricomp(ArgName, ArcFileName) != 0);/* exit if file is extracted */
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1051
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1052 /* free memory, clear password and close archive */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1053 free(UnpMemory);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1054 UnpMemory=NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1055 #ifndef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1056 if (ArcPtr!=NULL){
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1057 fclose(ArcPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1058 ArcPtr = NULL;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1059 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1060 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1061
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1062 return ReturnCode; /* file extracted successful! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1063 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1064
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1065 /* **************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1066 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1067 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1068 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1069
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1070
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1071
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1072
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1073
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1074
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1075
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1076
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1077
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1078
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1079
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1080
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1081
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1082
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1083
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1084
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1085
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1086
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1087 /* **************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1088 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1089 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1090 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1091 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1092 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1093 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1094 ******* G L O B A L F U N C T I O N S *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1095 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1096 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1097 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1098 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1099 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1100 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1101 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1102
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1103
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1104 int tread(void *stream,void *buf,unsigned len)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1105 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1106 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1107
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1108 if(((MemRARFile->offset + len) > MemRARFile->size) || (len == 0))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1109 return 0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1110
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1111 memcpy(buf,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1112 (BYTE*)(((MemoryFile*)stream)->data)+((MemoryFile*)stream)->offset,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1113 len % ((((MemoryFile*)stream)->size) - 1));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1114
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1115 MemRARFile->offset+=len; /* update read pointer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1116 return len % ((((MemoryFile*)stream)->size) - 1);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1117 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1118 return(fread(buf,1,len,(FILE*)stream));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1119 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1120 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1121
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1122
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1123 #ifndef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1124 int tseek(void *stream,long offset,int fromwhere)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1125 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1126 return(fseek((FILE*)stream,offset,fromwhere));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1127 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1128 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1129
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1130
10127
228a767a51fd avoid symbol clash with never samba versions (btw, unrarlib.c is full of global variables, with common names :( and it's a bit bloated, I think)
alex
parents: 9584
diff changeset
1131 static char* my_strupper(char *Str)
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1132 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1133 char *ChPtr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1134 for (ChPtr=Str;*ChPtr;ChPtr++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1135 *ChPtr=(char)toupper(*ChPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1136 return(Str);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1137 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1138
10127
228a767a51fd avoid symbol clash with never samba versions (btw, unrarlib.c is full of global variables, with common names :( and it's a bit bloated, I think)
alex
parents: 9584
diff changeset
1139
228a767a51fd avoid symbol clash with never samba versions (btw, unrarlib.c is full of global variables, with common names :( and it's a bit bloated, I think)
alex
parents: 9584
diff changeset
1140 static int my_stricomp(char *Str1,char *Str2)
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1141 /* compare strings without regard of '\' and '/' */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1142 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1143 char S1[512],S2[512];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1144 char *chptr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1145
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1146 strncpy(S1,Str1,sizeof(S1));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1147 strncpy(S2,Str2,sizeof(S2));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1148
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1149 while((chptr = strchr(S1, '\\')) != NULL) /* ignore backslash */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1150 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1151 *chptr = '_';
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1152 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1153
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1154 while((chptr = strchr(S2, '\\')) != NULL) /* ignore backslash */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1155 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1156 *chptr = '_';
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1157 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1158
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1159 while((chptr = strchr(S1, '/')) != NULL) /* ignore slash */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1160 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1161 *chptr = '_';
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1162 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1163
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1164 while((chptr = strchr(S2, '/')) != NULL) /* ignore slash */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1165 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1166 *chptr = '_';
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1167 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1168
10127
228a767a51fd avoid symbol clash with never samba versions (btw, unrarlib.c is full of global variables, with common names :( and it's a bit bloated, I think)
alex
parents: 9584
diff changeset
1169 return(strcmp(my_strupper(S1),my_strupper(S2)));
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1170 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1171
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1172
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1173 /* **************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1174 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1175 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1176 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1177
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1178
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1179
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1180
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1181
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1182
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1183
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1184
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1185
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1186
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1187
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1188
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1189
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1190
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1191
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1192
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1193
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1194
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1195 /* **************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1196 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1197 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1198 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1199 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1200 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1201 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1202 ******* U N P A C K C O D E *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1203 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1204 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1205 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1206 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1207 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1208 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1209 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1210
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1211
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1212 /* *****************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1213 * ** unpack stored RAR files **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1214 * *****************************/
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1215
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1216 BOOL UnstoreFile(void)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1217 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1218 if ((long)(*temp_output_buffer_offset=UnpRead(temp_output_buffer,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1219 NewLhd.UnpSize))==-1)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1220 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1221 debug_log("Read error of stored file!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1222 return FALSE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1223 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1224 return TRUE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1225 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1226
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1227
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1228
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1229
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1230 /* ****************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1231 * ** RAR decompression code starts here **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1232 * ****************************************/
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1233
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1234 #define NC 298 /* alphabet = {0,1,2, .,NC - 1} */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1235 #define DC 48
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1236 #define RC 28
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1237 #define BC 19
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1238 #define MC 257
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1239
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1240 enum {CODE_HUFFMAN=0,CODE_LZ=1,CODE_LZ2=2,CODE_REPEATLZ=3,CODE_CACHELZ=4,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1241 CODE_STARTFILE=5,CODE_ENDFILE=6,CODE_STARTMM=8,CODE_ENDMM=7,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1242 CODE_MMDELTA=9};
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1243
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1244 struct AudioVariables
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1245 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1246 int K1,K2,K3,K4,K5;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1247 int D1,D2,D3,D4;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1248 int LastDelta;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1249 unsigned int Dif[11];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1250 unsigned int ByteCount;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1251 int LastChar;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1252 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1253
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1254
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1255 #define NC 298 /* alphabet = {0, 1, 2, ..., NC - 1} */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1256 #define DC 48
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1257 #define RC 28
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1258 #define BC 19
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1259 #define MC 257
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1260
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1261
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1262 struct AudioVariables AudV[4];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1263
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1264 #define GetBits() \
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1265 BitField = ( ( ( (UDWORD)InBuf[InAddr] << 16 ) | \
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1266 ( (UWORD) InBuf[InAddr+1] << 8 ) | \
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1267 ( InBuf[InAddr+2] ) ) \
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1268 >> (8-InBit) ) & 0xffff;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1269
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1270
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1271 #define AddBits(Bits) \
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1272 InAddr += ( InBit + (Bits) ) >> 3; \
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1273 InBit = ( InBit + (Bits) ) & 7;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1274
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1275 static unsigned char *UnpBuf;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1276 static unsigned int BitField;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1277 static unsigned int Number;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1278
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1279 unsigned char InBuf[8192]; /* input read buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1280
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1281 unsigned char UnpOldTable[MC*4];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1282
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1283 unsigned int InAddr,InBit,ReadTop;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1284
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1285 unsigned int LastDist,LastLength;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1286 static unsigned int Length,Distance;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1287
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1288 unsigned int OldDist[4],OldDistPtr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1289
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1290
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1291 struct LitDecode
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1292 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1293 unsigned int MaxNum;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1294 unsigned int DecodeLen[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1295 unsigned int DecodePos[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1296 unsigned int DecodeNum[NC];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1297 } LD;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1298
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1299 struct DistDecode
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1300 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1301 unsigned int MaxNum;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1302 unsigned int DecodeLen[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1303 unsigned int DecodePos[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1304 unsigned int DecodeNum[DC];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1305 } DD;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1306
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1307 struct RepDecode
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1308 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1309 unsigned int MaxNum;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1310 unsigned int DecodeLen[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1311 unsigned int DecodePos[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1312 unsigned int DecodeNum[RC];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1313 } RD;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1314
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1315 struct MultDecode
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1316 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1317 unsigned int MaxNum;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1318 unsigned int DecodeLen[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1319 unsigned int DecodePos[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1320 unsigned int DecodeNum[MC];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1321 } MD[4];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1322
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1323 struct BitDecode
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1324 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1325 unsigned int MaxNum;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1326 unsigned int DecodeLen[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1327 unsigned int DecodePos[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1328 unsigned int DecodeNum[BC];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1329 } BD;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1330
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1331 static struct MultDecode *MDPtr[4]={&MD[0],&MD[1],&MD[2],&MD[3]};
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1332
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1333 int UnpAudioBlock,UnpChannels,CurChannel,ChannelDelta;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1334
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1335
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1336 void Unpack(unsigned char *UnpAddr)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1337 /* *** 38.3% of all CPU time is spent within this function!!! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1338 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1339 static unsigned char LDecode[]={0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1340 40,48,56,64,80,96,112,128,160,192,224};
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1341 static unsigned char LBits[]= {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1342 3,3,3,4,4,4,4,5,5,5,5};
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1343 static int DDecode[]={0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1344 512,768,1024,1536,2048,3072,4096,6144,8192,12288,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1345 16384,24576,32768U,49152U,65536,98304,131072,196608,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1346 262144,327680,393216,458752,524288,589824,655360,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1347 720896,786432,851968,917504,983040};
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1348 static unsigned char DBits[]= {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1349 9,10,10,11,11,12,12,13,13,14,14,15,15,16,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1350 16,16,16,16,16,16,16,16,16,16,16,16,16};
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1351 static unsigned char SDDecode[]={0,4,8,16,32,64,128,192};
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1352 static unsigned char SDBits[]={2,2,3, 4, 5, 6, 6, 6};
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1353 unsigned int Bits;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1354
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1355
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1356 UnpBuf=UnpAddr; /* UnpAddr is a pointer to the */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1357 UnpInitData(); /* unpack buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1358 UnpReadBuf(1);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1359 if (!(NewLhd.Flags & LHD_SOLID))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1360 ReadTables();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1361 DestUnpSize--;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1362
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1363 while (DestUnpSize>=0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1364 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1365 UnpPtr&=MAXWINMASK;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1366
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1367 if (InAddr>sizeof(InBuf)-30)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1368 UnpReadBuf(0);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1369 if (((WrPtr-UnpPtr) & MAXWINMASK)<270 && WrPtr!=UnpPtr)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1370 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1371
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1372
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1373 if (FileFound)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1374 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1375
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1376 if (UnpPtr<WrPtr)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1377 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1378 if((*temp_output_buffer_offset + UnpPtr) > NewLhd.UnpSize)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1379 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1380 debug_log("Fatal! Buffer overrun during decompression!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1381 DestUnpSize=-1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1382
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1383 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1384 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1385 /* copy extracted data to output buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1386 memcpy(temp_output_buffer + *temp_output_buffer_offset,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1387 &UnpBuf[WrPtr], (0-WrPtr) & MAXWINMASK);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1388 /* update offset within buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1389 *temp_output_buffer_offset+= (0-WrPtr) & MAXWINMASK;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1390 /* copy extracted data to output buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1391 memcpy(temp_output_buffer + *temp_output_buffer_offset, UnpBuf,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1392 UnpPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1393 /* update offset within buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1394 *temp_output_buffer_offset+=UnpPtr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1395 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1396 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1397 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1398 if((*temp_output_buffer_offset + (UnpPtr-WrPtr)) > NewLhd.UnpSize)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1399 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1400 debug_log("Fatal! Buffer overrun during decompression!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1401 DestUnpSize=-1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1402 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1403 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1404 /* copy extracted data to output buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1405 memcpy(temp_output_buffer + *temp_output_buffer_offset,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1406 &UnpBuf[WrPtr], UnpPtr-WrPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1407 *temp_output_buffer_offset+=UnpPtr-WrPtr; /* update offset within buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1408 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1409
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1410 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1411 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1412
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1413 WrPtr=UnpPtr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1414 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1415
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1416 if (UnpAudioBlock)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1417 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1418 DecodeNumber((struct Decode *)MDPtr[CurChannel]);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1419 if (Number==256)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1420 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1421 ReadTables();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1422 continue;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1423 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1424 UnpBuf[UnpPtr++]=DecodeAudio(Number);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1425 if (++CurChannel==UnpChannels)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1426 CurChannel=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1427 DestUnpSize--;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1428 continue;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1429 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1430
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1431 DecodeNumber((struct Decode *)&LD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1432 if (Number<256)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1433 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1434 UnpBuf[UnpPtr++]=(UBYTE)Number;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1435 DestUnpSize--;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1436 continue;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1437 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1438 if (Number>269)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1439 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1440 Length=LDecode[Number-=270]+3;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1441 if ((Bits=LBits[Number])>0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1442 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1443 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1444 Length+=BitField>>(16-Bits);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1445 AddBits(Bits);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1446 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1447
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1448 DecodeNumber((struct Decode *)&DD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1449 Distance=DDecode[Number]+1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1450 if ((Bits=DBits[Number])>0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1451 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1452 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1453 Distance+=BitField>>(16-Bits);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1454 AddBits(Bits);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1455 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1456
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1457 if (Distance>=0x40000L)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1458 Length++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1459
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1460 if (Distance>=0x2000)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1461 Length++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1462
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1463 LastDist=OldDist[OldDistPtr++ & 3]=Distance;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1464 DestUnpSize-=(LastLength=Length);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1465 while (Length--)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1466 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1467 UnpBuf[UnpPtr]=UnpBuf[(UnpPtr-Distance) & MAXWINMASK];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1468 UnpPtr=(UnpPtr+1) & MAXWINMASK;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1469 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1470
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1471 continue;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1472 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1473 if (Number==269)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1474 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1475 ReadTables();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1476 continue;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1477 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1478 if (Number==256)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1479 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1480 Length=LastLength;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1481 Distance=LastDist;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1482 LastDist=OldDist[OldDistPtr++ & 3]=Distance;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1483 DestUnpSize-=(LastLength=Length);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1484 while (Length--)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1485 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1486 UnpBuf[UnpPtr]=UnpBuf[(UnpPtr-Distance) & MAXWINMASK];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1487 UnpPtr=(UnpPtr+1) & MAXWINMASK;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1488 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1489 continue;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1490 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1491 if (Number<261)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1492 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1493 Distance=OldDist[(OldDistPtr-(Number-256)) & 3];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1494 DecodeNumber((struct Decode *)&RD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1495 Length=LDecode[Number]+2;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1496 if ((Bits=LBits[Number])>0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1497 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1498 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1499 Length+=BitField>>(16-Bits);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1500 AddBits(Bits);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1501 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1502 if (Distance>=0x40000)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1503 Length++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1504 if (Distance>=0x2000)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1505 Length++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1506 if (Distance>=0x101)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1507 Length++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1508 LastDist=OldDist[OldDistPtr++ & 3]=Distance;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1509 DestUnpSize-=(LastLength=Length);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1510 while (Length--)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1511 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1512 UnpBuf[UnpPtr]=UnpBuf[(UnpPtr-Distance) & MAXWINMASK];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1513 UnpPtr=(UnpPtr+1) & MAXWINMASK;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1514 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1515 continue;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1516 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1517 if (Number<270)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1518 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1519 Distance=SDDecode[Number-=261]+1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1520 if ((Bits=SDBits[Number])>0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1521 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1522 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1523 Distance+=BitField>>(16-Bits);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1524 AddBits(Bits);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1525 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1526 Length=2;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1527 LastDist=OldDist[OldDistPtr++ & 3]=Distance;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1528 DestUnpSize-=(LastLength=Length);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1529 while (Length--)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1530 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1531 UnpBuf[UnpPtr]=UnpBuf[(UnpPtr-Distance) & MAXWINMASK];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1532 UnpPtr=(UnpPtr+1) & MAXWINMASK;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1533 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1534 continue;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1535 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1536 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1537 ReadLastTables();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1538
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1539 if (FileFound) /* flush buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1540 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1541
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1542 if (UnpPtr<WrPtr)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1543 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1544 if((*temp_output_buffer_offset + UnpPtr) > NewLhd.UnpSize)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1545 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1546 debug_log("Fatal! Buffer overrun during decompression!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1547 DestUnpSize=-1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1548 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1549 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1550 /* copy extracted data to output buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1551 memcpy(temp_output_buffer + *temp_output_buffer_offset, &UnpBuf[WrPtr],
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1552 (0-WrPtr) & MAXWINMASK);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1553 /* update offset within buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1554 *temp_output_buffer_offset+= (0-WrPtr) & MAXWINMASK;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1555 /* copy extracted data to output buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1556 memcpy(temp_output_buffer + *temp_output_buffer_offset, UnpBuf, UnpPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1557 /* update offset within buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1558 *temp_output_buffer_offset+=UnpPtr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1559 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1560 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1561 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1562 if((*temp_output_buffer_offset + (UnpPtr-WrPtr)) > NewLhd.UnpSize)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1563 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1564 debug_log("Fatal! Buffer overrun during decompression!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1565 DestUnpSize=-1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1566 } else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1567 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1568 /* copy extracted data to output buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1569 memcpy(temp_output_buffer + *temp_output_buffer_offset, &UnpBuf[WrPtr],
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1570 UnpPtr-WrPtr);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1571 /* update offset within buffer */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1572 *temp_output_buffer_offset+=UnpPtr-WrPtr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1573 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1574 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1575 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1576
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1577 WrPtr=UnpPtr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1578 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1579
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1580
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1581 unsigned int UnpRead(unsigned char *Addr,unsigned int Count)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1582 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1583 int RetCode=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1584 unsigned int I,ReadSize,TotalRead=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1585 unsigned char *ReadAddr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1586 ReadAddr=Addr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1587 while (Count > 0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1588 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1589 ReadSize=(unsigned int)((Count>(unsigned long)UnpPackedSize) ?
10815
58c6f2998afa Fix the segfault with long filenames. Also prevent some other buffer
albeu
parents: 10127
diff changeset
1590 (unsigned int)UnpPackedSize : Count);
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1591 #ifdef _USE_MEMORY_TO_MEMORY_DECOMPRESSION
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1592 if(MemRARFile->data == NULL)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1593 return(0);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1594 RetCode=tread(MemRARFile, ReadAddr, ReadSize);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1595 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1596 if (ArcPtr==NULL)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1597 return(0);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1598 RetCode=tread(ArcPtr,ReadAddr,ReadSize);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1599 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1600 CurUnpRead+=RetCode;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1601 ReadAddr+=RetCode;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1602 TotalRead+=RetCode;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1603 Count-=RetCode;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1604 UnpPackedSize-=RetCode;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1605 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1606 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1607 if (RetCode!= -1)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1608 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1609 RetCode=TotalRead;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1610 if (Encryption)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1611 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1612 if (Encryption<20)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1613 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1614 debug_log("Old Crypt() not supported!");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1615 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1616 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1617 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1618 for (I=0;I<(unsigned int)RetCode;I+=16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1619 DecryptBlock(&Addr[I]);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1620 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1621 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1622 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1623 return(RetCode);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1624 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1625
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1626
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1627 void UnpReadBuf(int FirstBuf)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1628 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1629 int RetCode;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1630 if (FirstBuf)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1631 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1632 ReadTop=UnpRead(InBuf,sizeof(InBuf));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1633 InAddr=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1634 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1635 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1636 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1637 memcpy(InBuf,&InBuf[sizeof(InBuf)-32],32);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1638 InAddr&=0x1f;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1639 RetCode=UnpRead(&InBuf[32],sizeof(InBuf)-32);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1640 if (RetCode>0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1641 ReadTop=RetCode+32;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1642 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1643 ReadTop=InAddr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1644 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1645 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1646
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1647
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1648 void ReadTables(void)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1649 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1650 UBYTE BitLength[BC];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1651 unsigned char Table[MC*4];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1652 int TableSize,N,I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1653 if (InAddr>sizeof(InBuf)-25)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1654 UnpReadBuf(0);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1655 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1656 UnpAudioBlock=(BitField & 0x8000);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1657
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1658 if (!(BitField & 0x4000))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1659 memset(UnpOldTable,0,sizeof(UnpOldTable));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1660 AddBits(2);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1661
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1662
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1663 if (UnpAudioBlock)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1664 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1665 UnpChannels=((BitField>>12) & 3)+1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1666 if (CurChannel>=UnpChannels)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1667 CurChannel=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1668 AddBits(2);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1669 TableSize=MC*UnpChannels;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1670 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1671 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1672 TableSize=NC+DC+RC;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1673
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1674
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1675 for (I=0;I<BC;I++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1676 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1677 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1678 BitLength[I]=(UBYTE)(BitField >> 12);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1679 AddBits(4);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1680 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1681 MakeDecodeTables(BitLength,(struct Decode *)&BD,BC);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1682 I=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1683 while (I<TableSize)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1684 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1685 if (InAddr>sizeof(InBuf)-5)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1686 UnpReadBuf(0);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1687 DecodeNumber((struct Decode *)&BD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1688 if (Number<16)
8451
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7446
diff changeset
1689 {
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7446
diff changeset
1690 Table[I]=(Number+UnpOldTable[I]) & 0xf;
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7446
diff changeset
1691 I++;
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7446
diff changeset
1692 }
7446
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1693 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1694 if (Number==16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1695 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1696 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1697 N=(BitField >> 14)+3;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1698 AddBits(2);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1699 while (N-- > 0 && I<TableSize)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1700 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1701 Table[I]=Table[I-1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1702 I++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1703 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1704 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1705 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1706 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1707 if (Number==17)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1708 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1709 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1710 N=(BitField >> 13)+3;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1711 AddBits(3);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1712 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1713 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1714 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1715 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1716 N=(BitField >> 9)+11;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1717 AddBits(7);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1718 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1719 while (N-- > 0 && I<TableSize)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1720 Table[I++]=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1721 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1722 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1723 if (UnpAudioBlock)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1724 for (I=0;I<UnpChannels;I++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1725 MakeDecodeTables(&Table[I*MC],(struct Decode *)MDPtr[I],MC);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1726 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1727 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1728 MakeDecodeTables(&Table[0],(struct Decode *)&LD,NC);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1729 MakeDecodeTables(&Table[NC],(struct Decode *)&DD,DC);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1730 MakeDecodeTables(&Table[NC+DC],(struct Decode *)&RD,RC);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1731 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1732 memcpy(UnpOldTable,Table,sizeof(UnpOldTable));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1733 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1734
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1735
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1736 static void ReadLastTables(void)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1737 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1738 if (ReadTop>=InAddr+5)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1739 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1740 if (UnpAudioBlock)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1741 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1742 DecodeNumber((struct Decode *)MDPtr[CurChannel]);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1743 if (Number==256)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1744 ReadTables();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1745 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1746 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1747 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1748 DecodeNumber((struct Decode *)&LD);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1749 if (Number==269)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1750 ReadTables();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1751 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1752 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1753 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1754
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1755
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1756 static void MakeDecodeTables(unsigned char *LenTab,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1757 struct Decode *Dec,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1758 int Size)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1759 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1760 int LenCount[16],TmpPos[16],I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1761 long M,N;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1762 memset(LenCount,0,sizeof(LenCount));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1763 for (I=0;I<Size;I++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1764 LenCount[LenTab[I] & 0xF]++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1765
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1766 LenCount[0]=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1767 for (TmpPos[0]=Dec->DecodePos[0]=Dec->DecodeLen[0]=0,N=0,I=1;I<16;I++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1768 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1769 N=2*(N+LenCount[I]);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1770 M=N<<(15-I);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1771 if (M>0xFFFF)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1772 M=0xFFFF;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1773 Dec->DecodeLen[I]=(unsigned int)M;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1774 TmpPos[I]=Dec->DecodePos[I]=Dec->DecodePos[I-1]+LenCount[I-1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1775 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1776
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1777 for (I=0;I<Size;I++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1778 if (LenTab[I]!=0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1779 Dec->DecodeNum[TmpPos[LenTab[I] & 0xF]++]=I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1780 Dec->MaxNum=Size;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1781 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1782
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1783
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1784 static void DecodeNumber(struct Decode *Deco)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1785 /* *** 52.6% of all CPU time is spent within this function!!! */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1786 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1787 unsigned int I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1788 register unsigned int N;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1789 GetBits();
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1790
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1791 #ifdef _USE_ASM
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1792
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1793 #ifdef _WIN_32
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1794 __asm {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1795
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1796 xor eax, eax
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1797 mov eax, BitField // N=BitField & 0xFFFE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1798 and eax, 0xFFFFFFFE
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1799 mov [N], eax
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1800 mov edx, [Deco] // EAX=N, EDX=Deco
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1801
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1802 cmp eax, dword ptr[edx + 8*4 + 4]// if (N<Dec->DecodeLen[8])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1803 jae else_G
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1804
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1805 cmp eax, dword ptr[edx + 4*4 + 4]// if (N<Dec->DecodeLen[4])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1806 jae else_F
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1807
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1808
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1809 cmp eax, dword ptr[edx + 2*4 + 4]// if (N<Dec->DecodeLen[2])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1810 jae else_C
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1811
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1812 cmp eax, dword ptr[edx + 1*4 + 4]// if (N<Dec->DecodeLen[1])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1813 jae else_1
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1814 mov I, 1 // I=1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1815 jmp next_1
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1816 else_1: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1817 mov I, 2 // I=2;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1818 next_1:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1819
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1820 jmp next_C
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1821 else_C: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1822
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1823 cmp eax, dword ptr[edx + 3*4 + 4]// if (N<Dec->DecodeLen[3])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1824 jae else_2
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1825 mov I, 3 // I=3;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1826 jmp next_2
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1827 else_2: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1828 mov I, 4 // I=4;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1829 next_2:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1830
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1831 next_C: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1832
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1833 jmp next_F
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1834 else_F:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1835
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1836
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1837 cmp eax, dword ptr[edx + 6*4 + 4]// if (N<Dec->DecodeLen[6])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1838 jae else_E
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1839
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1840 cmp eax, dword ptr[edx + 5*4 + 4]// if (N<Dec->DecodeLen[5])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1841 jae else_3
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1842 mov I, 5 // I=5;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1843 jmp next_3
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1844 else_3: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1845 mov I, 6 // I=6;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1846 next_3:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1847
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1848 jmp next_E
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1849 else_E: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1850
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1851 cmp eax, dword ptr[edx + 7*4 + 4]// if (N<Dec->DecodeLen[7])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1852 jae else_4
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1853 mov I, 7 // I=7;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1854 jmp next_4
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1855 else_4: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1856 mov I, 8 // I=8;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1857 next_4:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1858
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1859 next_E:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1860
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1861 next_F:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1862
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1863 jmp next_G
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1864 else_G:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1865
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1866 cmp eax, dword ptr[edx + 12*4 + 4] // if (N<Dec->DecodeLen[12])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1867 jae else_D
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1868
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1869 cmp eax, dword ptr[edx + 10*4 + 4]// if (N<Dec->DecodeLen[10])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1870 jae else_B
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1871
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1872 cmp eax, dword ptr[edx + 9*4 + 4]// if (N<Dec->DecodeLen[9])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1873 jae else_5
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1874 mov I, 9 // I=9;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1875 jmp next_5
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1876 else_5: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1877 mov I, 10 // I=10;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1878 next_5:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1879
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1880 jmp next_B
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1881 else_B: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1882
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1883 cmp eax, dword ptr[edx + 11*4 + 4]// if (N<Dec->DecodeLen[11])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1884 jae else_6
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1885 mov I, 11 // I=11;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1886 jmp next_6
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1887 else_6: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1888 mov I, 12 // I=12;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1889 next_6:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1890
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1891 next_B:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1892
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1893
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1894 jmp next_D
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1895 else_D: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1896
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1897 cmp eax, dword ptr[edx + 14*4 + 4]// if (N<Dec->DecodeLen[14])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1898 jae else_A
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1899
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1900 cmp eax, dword ptr[edx + 13*4 + 4]// if (N<Dec->DecodeLen[13])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1901 jae else_7
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1902 mov I, 13 // I=13;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1903 jmp next_7
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1904 else_7: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1905 mov I, 14 // I=14;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1906 next_7:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1907
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1908 jmp next_A
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1909 else_A: // else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1910 mov I, 15 // I=15;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1911 next_A:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1912
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1913 next_D:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1914 next_G:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1915 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1916 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1917 __asm__ __volatile__ (
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1918 "andl $0xFFFFFFFE, %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1919 " movl %%eax, %1"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1920 " cmpl 8*4(%%edx), %%eax /* 5379 */"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1921 " jae else_G"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1922 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1923 " cmpl 4*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1924 " jae else_F"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1925 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1926 " cmpl 2*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1927 " jae else_C"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1928 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1929 " cmpl 1*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1930 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1931 " jae else_1"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1932 " movl $1, %0"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1933 " jmp next_1"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1934 " else_1: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1935 " movl $2, %0"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1936 " next_1:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1937 " "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1938 " jmp next_C"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1939 " else_C: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1940 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1941 " cmpl 3*4(%%edx), %%eax "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1942 " jae else_2"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1943 " movl $3, %0"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1944 " jmp next_2"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1945 " else_2: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1946 " movl $4, %0"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1947 " next_2:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1948 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1949 " next_C: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1950 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1951 " jmp next_F"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1952 " else_F:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1953 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1954 " cmpl 6*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1955 " jae else_E"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1956 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1957 " cmpl 5*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1958 " jae else_3"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1959 " movl $5, %0 "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1960 " jmp next_3"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1961 " else_3: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1962 " movl $6, %0 "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1963 " next_3:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1964 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1965 " jmp next_E"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1966 " else_E: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1967 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1968 " cmpl 7*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1969 " jae else_4"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1970 " movl $7, %0 "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1971 " jmp next_4"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1972 " else_4: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1973 " movl $8, %0 "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1974 " next_4:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1975 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1976 " next_E:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1977 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1978 " next_F:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1979 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1980 " jmp next_G"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1981 " else_G:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1982 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1983 " cmpl 12*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1984 " jae else_D"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1985 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1986 " cmpl 10*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1987 " jae else_B"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1988 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1989 " cmpl 9*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1990 " jae else_5"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1991 " movl $9, %0 "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1992 " jmp next_5"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1993 " else_5: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1994 " movl $10, %0 "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1995 " next_5:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1996 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1997 " jmp next_B"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1998 " else_B: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
1999 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2000 " cmpl 11*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2001 " "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2002 " jae else_6"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2003 " movl $11, %0 "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2004 " jmp next_6"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2005 " else_6: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2006 " movl $12, %0 "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2007 " next_6:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2008 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2009 " next_B:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2010 " "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2011 " "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2012 " jmp next_D"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2013 " else_D: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2014 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2015 " cmpl 14*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2016 " jae else_A"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2017 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2018 " cmpl 13*4(%%edx), %%eax"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2019 " jae else_7"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2020 " movl $13, %0"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2021 " jmp next_7"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2022 " else_7: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2023 " movl $14, %0"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2024 " next_7:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2025 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2026 " jmp next_A"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2027 " else_A: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2028 " movl $15, %0 "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2029 " next_A:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2030 " "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2031 " next_D: "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2032 " next_G:"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2033 : "=g" (I), "=r"(N)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2034 : "eax" ((long)BitField), "edx"((long)Deco->DecodeLen)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2035 : "memory"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2036 );
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2037 #endif /* #ifdef _WIN_32 ... #elif defined _X86_ASM_ */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2038
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2039 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2040 N=BitField & 0xFFFE;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2041 if (N<Deco->DecodeLen[8]) {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2042 if (N<Deco->DecodeLen[4]) {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2043 if (N<Deco->DecodeLen[2]) {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2044 if (N<Deco->DecodeLen[1])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2045 I=1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2046 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2047 I=2;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2048 } else {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2049 if (N<Deco->DecodeLen[3])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2050 I=3;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2051 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2052 I=4;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2053 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2054 } else {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2055 if (N<Deco->DecodeLen[6]) {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2056 if (N<Deco->DecodeLen[5])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2057 I=5;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2058 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2059 I=6;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2060 } else {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2061 if (N<Deco->DecodeLen[7])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2062 I=7;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2063 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2064 I=8;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2065 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2066 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2067 } else {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2068 if (N<Deco->DecodeLen[12]) {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2069 if (N<Deco->DecodeLen[10]) {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2070 if (N<Deco->DecodeLen[9])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2071 I=9;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2072 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2073 I=10;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2074 } else {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2075 if (N<Deco->DecodeLen[11])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2076 I=11;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2077 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2078 I=12;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2079 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2080 } else {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2081 if (N<Deco->DecodeLen[14]) {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2082 if (N<Deco->DecodeLen[13])
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2083 I=13;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2084 else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2085 I=14;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2086
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2087 } else {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2088 I=15;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2089 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2090 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2091
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2092 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2093 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2094
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2095 AddBits(I);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2096 if ((N=Deco->DecodePos[I]+((N-Deco->DecodeLen[I-1])>>(16-I)))>=Deco->MaxNum)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2097 N=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2098 Number=Deco->DecodeNum[N];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2099 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2100
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2101
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2102 void UnpInitData()
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2103 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2104 InAddr=InBit=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2105 if (!(NewLhd.Flags & LHD_SOLID))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2106 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2107 ChannelDelta=CurChannel=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2108
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2109 #ifdef _USE_ASM
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2110
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2111 #ifdef _WIN_32 /* Win32 with VisualC */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2112
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2113 __asm {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2114 push edi
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2115 push eax
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2116 push ecx
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2117
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2118 cld /* increment EDI and ESI */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2119 mov al, 0x00
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2120 mov ecx, SIZE AudV
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2121 mov edi, Offset AudV
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2122 rep stosb /* clear memory */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2123
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2124 mov ecx, SIZE OldDist
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2125 mov edi, Offset OldDist
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2126 rep stosb /* clear memory */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2127
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2128 mov ecx, SIZE UnpOldTable
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2129 mov edi, Offset UnpOldTable
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2130 rep stosb /* clear memory */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2131
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2132 pop ecx
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2133 pop eax
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2134 pop edi
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2135
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2136
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2137 mov [OldDistPtr], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2138 mov [LastDist], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2139 mov [LastLength], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2140 mov [UnpPtr], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2141 mov [WrPtr], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2142 mov [OldDistPtr], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2143 mov [LastLength], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2144 mov [LastDist], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2145 mov [UnpPtr], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2146 mov [WrPtr], 0
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2147
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2148 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2149 memset(UnpBuf,0,MAXWINSIZE);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2150
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2151
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2152 #else /* unix/linux on i386 cpus */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2153 __asm__ __volatile (
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2154 " cld /* increment EDI and ESI */"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2155 " movb $0x00, %%al"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2156 " movl %0, %%ecx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2157 " movl %1, %%edi"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2158 " rep "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2159 " stosb /* clear memory */"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2160 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2161 " movl %2, %%ecx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2162 " mov %3, %%edi"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2163 " rep "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2164 " stosb /* clear memory */"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2165 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2166 " movl %4, %%ecx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2167 " movl %5, %%edi"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2168 " rep "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2169 " stosb /* clear memory */"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2170 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2171 " movl $0, (OldDistPtr)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2172 " movl $0, (LastDist)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2173 " movl $0, (LastLength)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2174 " movl $0, (UnpPtr)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2175 " movl $0, (WrPtr)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2176 " movl $0, (OldDistPtr)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2177 " movl $0, (LastLength)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2178 " movl $0, (LastDist)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2179 " movl $0, (UnpPtr)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2180 " movl $0, (WrPtr)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2181 :
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2182 : "m" ((long)sizeof(AudV)),
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2183 "m" ((long)AudV),
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2184 "m" ((long)sizeof(OldDist)),
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2185 "m" ((long)OldDist),
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2186 "m" ((long)sizeof(UnpOldTable)),
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2187 "m" ((long)UnpOldTable)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2188 : "memory", "edi", "eax", "ecx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2189 );
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2190 memset(UnpBuf,0,MAXWINSIZE);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2191 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2192
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2193 #else /* unix/linux on non-i386 cpu */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2194 memset(AudV,0,sizeof(AudV));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2195 memset(OldDist,0,sizeof(OldDist));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2196 OldDistPtr=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2197 LastDist=LastLength=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2198 memset(UnpBuf,0,MAXWINSIZE);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2199 memset(UnpOldTable,0,sizeof(UnpOldTable));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2200 UnpPtr=WrPtr=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2201 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2202
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2203 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2204 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2205
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2206
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2207 UBYTE DecodeAudio(int Delta)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2208 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2209 struct AudioVariables *V;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2210 unsigned int Ch;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2211 unsigned int NumMinDif,MinDif;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2212 int PCh,I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2213
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2214 V=&AudV[CurChannel];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2215 V->ByteCount++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2216 V->D4=V->D3;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2217 V->D3=V->D2;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2218 V->D2=V->LastDelta-V->D1;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2219 V->D1=V->LastDelta;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2220 PCh=8*V->LastChar+V->K1*V->D1+V->K2*V->D2+
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2221 V->K3*V->D3+V->K4*V->D4+V->K5*ChannelDelta;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2222 PCh=(PCh>>3) & 0xFF;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2223
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2224 Ch=PCh-Delta;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2225
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2226 I=((signed char)Delta)<<3;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2227
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2228 V->Dif[0]+=abs(I);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2229 V->Dif[1]+=abs(I-V->D1);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2230 V->Dif[2]+=abs(I+V->D1);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2231 V->Dif[3]+=abs(I-V->D2);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2232 V->Dif[4]+=abs(I+V->D2);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2233 V->Dif[5]+=abs(I-V->D3);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2234 V->Dif[6]+=abs(I+V->D3);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2235 V->Dif[7]+=abs(I-V->D4);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2236 V->Dif[8]+=abs(I+V->D4);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2237 V->Dif[9]+=abs(I-ChannelDelta);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2238 V->Dif[10]+=abs(I+ChannelDelta);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2239
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2240 ChannelDelta=V->LastDelta=(signed char)(Ch-V->LastChar);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2241 V->LastChar=Ch;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2242
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2243 if ((V->ByteCount & 0x1F)==0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2244 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2245 MinDif=V->Dif[0];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2246 NumMinDif=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2247 V->Dif[0]=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2248 for (I=1;(unsigned int)I<sizeof(V->Dif)/sizeof(V->Dif[0]);I++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2249 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2250 if (V->Dif[I]<MinDif)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2251 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2252 MinDif=V->Dif[I];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2253 NumMinDif=I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2254 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2255 V->Dif[I]=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2256 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2257 switch(NumMinDif)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2258 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2259 case 1:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2260 if (V->K1>=-16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2261 V->K1--;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2262 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2263 case 2:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2264 if (V->K1<16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2265 V->K1++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2266 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2267 case 3:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2268 if (V->K2>=-16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2269 V->K2--;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2270 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2271 case 4:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2272 if (V->K2<16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2273 V->K2++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2274 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2275 case 5:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2276 if (V->K3>=-16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2277 V->K3--;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2278 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2279 case 6:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2280 if (V->K3<16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2281 V->K3++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2282 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2283 case 7:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2284 if (V->K4>=-16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2285 V->K4--;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2286 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2287 case 8:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2288 if (V->K4<16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2289 V->K4++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2290 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2291 case 9:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2292 if (V->K5>=-16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2293 V->K5--;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2294 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2295 case 10:
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2296 if (V->K5<16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2297 V->K5++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2298 break;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2299 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2300 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2301 return((UBYTE)Ch);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2302 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2303
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2304
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2305
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2306
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2307
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2308
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2309
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2310 /* ***************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2311 * ** CRCCrypt Code - decryption engine starts here **
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2312 * ***************************************************/
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2313
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2314
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2315 #define NROUNDS 32
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2316
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2317 #define rol(x,n) (((x)<<(n)) | ((x)>>(8*sizeof(x)-(n))))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2318 #define ror(x,n) (((x)>>(n)) | ((x)<<(8*sizeof(x)-(n))))
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2319
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2320 #define substLong(t) ( (UDWORD)SubstTable[(int)t&255] | \
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2321 ((UDWORD)SubstTable[(int)(t>> 8)&255]<< 8) | \
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2322 ((UDWORD)SubstTable[(int)(t>>16)&255]<<16) | \
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2323 ((UDWORD)SubstTable[(int)(t>>24)&255]<<24) )
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2324
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2325
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2326 UDWORD CRCTab[256];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2327
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2328 UBYTE SubstTable[256];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2329 UBYTE InitSubstTable[256]={
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2330 215, 19,149, 35, 73,197,192,205,249, 28, 16,119, 48,221, 2, 42,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2331 232, 1,177,233, 14, 88,219, 25,223,195,244, 90, 87,239,153,137,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2332 255,199,147, 70, 92, 66,246, 13,216, 40, 62, 29,217,230, 86, 6,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2333 71, 24,171,196,101,113,218,123, 93, 91,163,178,202, 67, 44,235,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2334 107,250, 75,234, 49,167,125,211, 83,114,157,144, 32,193,143, 36,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2335 158,124,247,187, 89,214,141, 47,121,228, 61,130,213,194,174,251,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2336 97,110, 54,229,115, 57,152, 94,105,243,212, 55,209,245, 63, 11,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2337 164,200, 31,156, 81,176,227, 21, 76, 99,139,188,127, 17,248, 51,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2338 207,120,189,210, 8,226, 41, 72,183,203,135,165,166, 60, 98, 7,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2339 122, 38,155,170, 69,172,252,238, 39,134, 59,128,236, 27,240, 80,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2340 131, 3, 85,206,145, 79,154,142,159,220,201,133, 74, 64, 20,129,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2341 224,185,138,103,173,182, 43, 34,254, 82,198,151,231,180, 58, 10,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2342 118, 26,102, 12, 50,132, 22,191,136,111,162,179, 45, 4,148,108,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2343 161, 56, 78,126,242,222, 15,175,146, 23, 33,241,181,190, 77,225,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2344 0, 46,169,186, 68, 95,237, 65, 53,208,253,168, 9, 18,100, 52,
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2345 116,184,160, 96,109, 37, 30,106,140,104,150, 5,204,117,112, 84
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2346 };
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2347
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2348 UDWORD Key[4];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2349
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2350
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2351 void EncryptBlock(UBYTE *Buf)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2352 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2353 int I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2354
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2355 UDWORD A,B,C,D,T,TA,TB;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2356 #ifdef NON_INTEL_BYTE_ORDER
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2357 A=((UDWORD)Buf[0]|((UDWORD)Buf[1]<<8)|((UDWORD)Buf[2]<<16)|
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2358 ((UDWORD)Buf[3]<<24))^Key[0];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2359 B=((UDWORD)Buf[4]|((UDWORD)Buf[5]<<8)|((UDWORD)Buf[6]<<16)|
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2360 ((UDWORD)Buf[7]<<24))^Key[1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2361 C=((UDWORD)Buf[8]|((UDWORD)Buf[9]<<8)|((UDWORD)Buf[10]<<16)|
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2362 ((UDWORD)Buf[11]<<24))^Key[2];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2363 D=((UDWORD)Buf[12]|((UDWORD)Buf[13]<<8)|((UDWORD)Buf[14]<<16)|
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2364 ((UDWORD)Buf[15]<<24))^Key[3];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2365 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2366 UDWORD *BufPtr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2367 BufPtr=(UDWORD *)Buf;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2368 A=BufPtr[0]^Key[0];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2369 B=BufPtr[1]^Key[1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2370 C=BufPtr[2]^Key[2];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2371 D=BufPtr[3]^Key[3];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2372 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2373 for(I=0;I<NROUNDS;I++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2374 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2375 T=((C+rol(D,11))^Key[I&3]);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2376 TA=A^substLong(T);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2377 T=((D^rol(C,17))+Key[I&3]);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2378 TB=B^substLong(T);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2379 A=C;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2380 B=D;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2381 C=TA;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2382 D=TB;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2383 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2384 #ifdef NON_INTEL_BYTE_ORDER
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2385 C^=Key[0];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2386 Buf[0]=(UBYTE)C;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2387 Buf[1]=(UBYTE)(C>>8);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2388 Buf[2]=(UBYTE)(C>>16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2389 Buf[3]=(UBYTE)(C>>24);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2390 D^=Key[1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2391 Buf[4]=(UBYTE)D;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2392 Buf[5]=(UBYTE)(D>>8);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2393 Buf[6]=(UBYTE)(D>>16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2394 Buf[7]=(UBYTE)(D>>24);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2395 A^=Key[2];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2396 Buf[8]=(UBYTE)A;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2397 Buf[9]=(UBYTE)(A>>8);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2398 Buf[10]=(UBYTE)(A>>16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2399 Buf[11]=(UBYTE)(A>>24);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2400 B^=Key[3];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2401 Buf[12]=(UBYTE)B;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2402 Buf[13]=(UBYTE)(B>>8);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2403 Buf[14]=(UBYTE)(B>>16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2404 Buf[15]=(UBYTE)(B>>24);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2405 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2406 BufPtr[0]=C^Key[0];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2407 BufPtr[1]=D^Key[1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2408 BufPtr[2]=A^Key[2];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2409 BufPtr[3]=B^Key[3];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2410 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2411 UpdKeys(Buf);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2412 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2413
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2414
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2415 void DecryptBlock(UBYTE *Buf)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2416 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2417 int I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2418 UBYTE InBuf[16];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2419 UDWORD A,B,C,D,T,TA,TB;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2420 #ifdef NON_INTEL_BYTE_ORDER
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2421 A=((UDWORD)Buf[0]|((UDWORD)Buf[1]<<8)|((UDWORD)Buf[2]<<16)|
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2422 ((UDWORD)Buf[3]<<24))^Key[0];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2423 B=((UDWORD)Buf[4]|((UDWORD)Buf[5]<<8)|((UDWORD)Buf[6]<<16)|
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2424 ((UDWORD)Buf[7]<<24))^Key[1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2425 C=((UDWORD)Buf[8]|((UDWORD)Buf[9]<<8)|((UDWORD)Buf[10]<<16)|
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2426 ((UDWORD)Buf[11]<<24))^Key[2];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2427 D=((UDWORD)Buf[12]|((UDWORD)Buf[13]<<8)|((UDWORD)Buf[14]<<16)|
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2428 ((UDWORD)Buf[15]<<24))^Key[3];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2429 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2430 UDWORD *BufPtr;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2431 BufPtr=(UDWORD *)Buf;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2432 A=BufPtr[0]^Key[0]; /* xxx may be this can be */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2433 B=BufPtr[1]^Key[1]; /* optimized in assembler */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2434 C=BufPtr[2]^Key[2];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2435 D=BufPtr[3]^Key[3];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2436 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2437 memcpy(InBuf,Buf,sizeof(InBuf));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2438 for(I=NROUNDS-1;I>=0;I--)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2439 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2440 T=((C+rol(D,11))^Key[I&3]);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2441 TA=A^substLong(T);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2442 T=((D^rol(C,17))+Key[I&3]);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2443 TB=B^substLong(T);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2444 A=C;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2445 B=D;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2446 C=TA;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2447 D=TB;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2448 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2449 #ifdef NON_INTEL_BYTE_ORDER
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2450 C^=Key[0];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2451 Buf[0]=(UBYTE)C;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2452 Buf[1]=(UBYTE)(C>>8);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2453 Buf[2]=(UBYTE)(C>>16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2454 Buf[3]=(UBYTE)(C>>24);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2455 D^=Key[1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2456 Buf[4]=(UBYTE)D;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2457 Buf[5]=(UBYTE)(D>>8);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2458 Buf[6]=(UBYTE)(D>>16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2459 Buf[7]=(UBYTE)(D>>24);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2460 A^=Key[2];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2461 Buf[8]=(UBYTE)A;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2462 Buf[9]=(UBYTE)(A>>8);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2463 Buf[10]=(UBYTE)(A>>16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2464 Buf[11]=(UBYTE)(A>>24);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2465 B^=Key[3];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2466 Buf[12]=(UBYTE)B;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2467 Buf[13]=(UBYTE)(B>>8);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2468 Buf[14]=(UBYTE)(B>>16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2469 Buf[15]=(UBYTE)(B>>24);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2470 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2471 BufPtr[0]=C^Key[0];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2472 BufPtr[1]=D^Key[1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2473 BufPtr[2]=A^Key[2];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2474 BufPtr[3]=B^Key[3];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2475 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2476 UpdKeys(InBuf);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2477 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2478
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2479
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2480 void UpdKeys(UBYTE *Buf)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2481 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2482 int I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2483 for (I=0;I<16;I+=4)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2484 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2485 Key[0]^=CRCTab[Buf[I]]; /* xxx may be I'll rewrite this */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2486 Key[1]^=CRCTab[Buf[I+1]]; /* in asm for speedup */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2487 Key[2]^=CRCTab[Buf[I+2]];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2488 Key[3]^=CRCTab[Buf[I+3]];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2489 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2490 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2491
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2492 void SetCryptKeys(char *Password)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2493 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2494 unsigned int I,J,K,PswLength;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2495 unsigned char N1,N2;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2496 unsigned char Psw[256];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2497
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2498 #if !defined _USE_ASM
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2499 UBYTE Ch;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2500 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2501
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2502 SetOldKeys(Password);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2503
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2504 Key[0]=0xD3A3B879L;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2505 Key[1]=0x3F6D12F7L;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2506 Key[2]=0x7515A235L;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2507 Key[3]=0xA4E7F123L;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2508 memset(Psw,0,sizeof(Psw));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2509 strcpy((char *)Psw,Password);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2510 PswLength=strlen(Password);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2511 memcpy(SubstTable,InitSubstTable,sizeof(SubstTable));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2512
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2513 for (J=0;J<256;J++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2514 for (I=0;I<PswLength;I+=2)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2515 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2516 N2=(unsigned char)CRCTab[(Psw[I+1]+J)&0xFF];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2517 for (K=1, N1=(unsigned char)CRCTab[(Psw[I]-J)&0xFF];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2518 (N1!=N2) && (N1 < 256); /* I had to add "&& (N1 < 256)", */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2519 N1++, K++) /* because the system crashed with */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2520 { /* encrypted RARs */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2521 #ifdef _USE_ASM
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2522
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2523 #ifdef _WIN_32
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2524 __asm {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2525
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2526 mov ebx, Offset SubstTable
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2527 mov edx, ebx
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2528
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2529 xor ecx, ecx // read SubstTable[N1]...
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2530 mov cl, N1
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2531 add ebx, ecx
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2532 mov al, byte ptr[ebx]
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2533
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2534 mov cl, N1 // read SubstTable[(N1+I+K)&0xFF]...
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2535 add ecx, I
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2536 add ecx, K
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2537 and ecx, 0xFF
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2538 add edx, ecx
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2539 mov ah, byte ptr[edx]
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2540
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2541 mov byte ptr[ebx], ah // and write back
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2542 mov byte ptr[edx], al
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2543
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2544 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2545 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2546 __asm__ __volatile__ (
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2547 " xorl %%ecx, %%ecx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2548 " movl %2, %%ecx /* ecx = N1 */"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2549 " mov %%ebx, %%edx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2550 " addl %%ecx, %%ebx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2551 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2552 " addl %0, %%ecx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2553 " addl %1, %%ecx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2554 " andl $0x000000FF, %%ecx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2555 " addl %%ecx, %%edx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2556 " "
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2557 " movb (%%ebx), %%al"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2558 " movb (%%edx), %%ah"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2559 ""
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2560 " movb %%ah, (%%ebx) /* and write back */"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2561 " movb %%al, (%%edx)"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2562 : : "g" ((long)I),
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2563 "g" ((long)K),
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2564 "g" ((long)N1),
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2565 "ebx"((long)SubstTable)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2566 : "ecx", "edx"
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2567
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2568 );
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2569 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2570
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2571 #else
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2572 /* Swap(&SubstTable[N1],&SubstTable[(N1+I+K)&0xFF]); */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2573 Ch=SubstTable[N1];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2574 SubstTable[N1]=SubstTable[(N1+I+K)&0xFF];
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2575 SubstTable[(N1+I+K)&0xFF]=Ch;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2576 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2577 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2578 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2579 for (I=0;I<PswLength;I+=16)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2580 EncryptBlock(&Psw[I]);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2581 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2582
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2583
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2584 void SetOldKeys(char *Password)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2585 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2586 UDWORD PswCRC;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2587 UBYTE Ch;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2588 PswCRC=CalcCRC32(0xFFFFFFFFL,(UBYTE*)Password,strlen(Password));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2589 OldKey[0]=(UWORD)PswCRC;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2590 OldKey[1]=(UWORD)(PswCRC>>16);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2591 OldKey[2]=OldKey[3]=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2592 PN1=PN2=PN3=0;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2593 while ((Ch=*Password)!=0)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2594 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2595 PN1+=Ch;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2596 PN2^=Ch;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2597 PN3+=Ch;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2598 PN3=(UBYTE)rol(PN3,1);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2599 OldKey[2]^=((UWORD)(Ch^CRCTab[Ch]));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2600 OldKey[3]+=((UWORD)(Ch+(CRCTab[Ch]>>16)));
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2601 Password++;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2602 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2603 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2604
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2605 void InitCRC(void)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2606 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2607 int I, J;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2608 UDWORD C;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2609 for (I=0;I<256;I++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2610 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2611 for (C=I,J=0;J<8;J++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2612 C=(C & 1) ? (C>>1)^0xEDB88320L : (C>>1);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2613 CRCTab[I]=C;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2614 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2615 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2616
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2617
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2618 UDWORD CalcCRC32(UDWORD StartCRC,UBYTE *Addr,UDWORD Size)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2619 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2620 unsigned int I;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2621 for (I=0; I<Size; I++)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2622 StartCRC = CRCTab[(UBYTE)StartCRC ^ Addr[I]] ^ (StartCRC >> 8);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2623 return(StartCRC);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2624 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2625
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2626
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2627 /* **************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2628 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2629 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2630 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2631
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2632
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2633
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2634
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2635
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2636
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2637
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2638
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2639
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2640
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2641
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2642
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2643
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2644
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2645
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2646
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2647
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2648
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2649
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2650
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2651
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2652
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2653
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2654
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2655
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2656 /* **************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2657 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2658 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2659 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2660 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2661 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2662 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2663 ******* D E B U G F U N C T I O N S *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2664 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2665 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2666 ******* *******
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2667 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2668 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2669 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2670 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2671 #ifdef _DEBUG_LOG
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2672
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2673
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2674 /* -- global stuff -------------------------------------------------------- */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2675 char log_file_name[256]; /* file name for the log file */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2676 DWORD debug_start_time; /* starttime of debug */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2677 BOOL debug_started = FALSE; /* debug_log writes only if */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2678 /* this is TRUE */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2679 /* ------------------------------------------------------------------------ */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2680
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2681
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2682 /* -- global functions ---------------------------------------------------- */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2683 void debug_init_proc(char *file_name)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2684 /* Create/Rewrite a log file */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2685 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2686 FILE *fp;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2687 char date[] = __DATE__;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2688 char time[] = __TIME__;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2689
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2690 debug_start_time = GetTickCount(); /* get start time */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2691 strcpy(log_file_name, file_name); /* save file name */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2692
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2693 if((fp = fopen(log_file_name, CREATETEXT)) != NULL)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2694 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2695 debug_started = TRUE; /* enable debug */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2696 fprintf(fp, "Debug log of UniquE's RARFileLib\n"\
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2697 "~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~\n");
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2698 fprintf(fp, "(executable compiled on %s at %s)\n\n", date, time);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2699 fclose(fp);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2700 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2701 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2702
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2703
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2704 void debug_log_proc(char *text, char *sourcefile, int sourceline)
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2705 /* add a line to the log file */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2706 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2707 FILE *fp;
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2708
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2709 if(debug_started == FALSE) return; /* exit if not initialized */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2710
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2711 if((fp = fopen(log_file_name, APPENDTEXT)) != NULL) /* append to logfile */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2712
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2713 {
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2714 fprintf(fp, " %8u ms (line %u in %s):\n - %s\n",
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2715 (unsigned int)(GetTickCount() - debug_start_time),
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2716 sourceline, sourcefile, text);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2717 fclose(fp);
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2718 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2719 }
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2720
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2721 /* ------------------------------------------------------------------------ */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2722 #endif
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2723 /* **************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2724 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2725 ****************************************************************************
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2726 ************************************************************************** */
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2727
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2728
ad00ad5f25a9 Automatic unrar of vobsub. Does not work with rar v3
kmkaplan
parents:
diff changeset
2729 /* end of file urarlib.c */