comparison Plugins/Input/modplug/modplugbmp.cpp @ 910:a540829b188a trunk

[svn] Detection of modules by magic bytes instead of by extension. Please let me know of false positives, if any. I would appreciate examples for any of the extensions still listed in the fallback that are not archives.
author chainsaw
date Sun, 02 Apr 2006 11:32:31 -0700
parents 073d2f46a490
children 5ef13028e42d
comparison
equal deleted inserted replaced
909:46960fb15ba0 910:a540829b188a
12 #include <libmodplug/stdafx.h> 12 #include <libmodplug/stdafx.h>
13 #include <libmodplug/sndfile.h> 13 #include <libmodplug/sndfile.h>
14 #include "stddefs.h" 14 #include "stddefs.h"
15 #include "archive/open.h" 15 #include "archive/open.h"
16 #include "libaudacious/configdb.h" 16 #include "libaudacious/configdb.h"
17 #include "libaudacious/vfs.h"
17 extern "C" { 18 extern "C" {
18 #include "audacious/output.h" 19 #include "audacious/output.h"
19 } 20 }
20 21
21 // ModplugXMMS member functions =============================== 22 // ModplugXMMS member functions ===============================
93 bool ModplugXMMS::CanPlayFile(const string& aFilename) 94 bool ModplugXMMS::CanPlayFile(const string& aFilename)
94 { 95 {
95 string lExt; 96 string lExt;
96 uint32 lPos; 97 uint32 lPos;
97 98
99 VFSFile *file;
100 gchar magic[4];
101
102 if ((file = vfs_fopen(aFilename.c_str(), "rb"))) {
103 vfs_fread(magic, 1, 4, file);
104 if (!memcmp(magic, UMX_MAGIC, 4)) {
105 vfs_fclose(file);
106 return 1;
107 }
108 if (!memcmp(magic, XM_MAGIC, 4)) {
109 vfs_fclose(file);
110 return 1;
111 }
112 if (!memcmp(magic, M669_MAGIC, 4)) {
113 vfs_fclose(file);
114 return 1;
115 }
116 if (!memcmp(magic, IT_MAGIC, 4)) {
117 vfs_fclose(file);
118 return 1;
119 }
120 if (!memcmp(magic, MTM_MAGIC, 4)) {
121 vfs_fclose(file);
122 return 1;
123 }
124 if (!memcmp(magic, PSM_MAGIC, 4)) {
125 vfs_fclose(file);
126 return 1;
127 }
128 vfs_fseek(file, 44, SEEK_SET);
129 vfs_fread(magic, 1, 4, file);
130 if (!memcmp(magic, S3M_MAGIC, 4)) {
131 vfs_fclose(file);
132 return 1;
133 }
134 vfs_fseek(file, 1080, SEEK_SET);
135 vfs_fread(magic, 1, 4, file);
136 if (!memcmp(magic, MOD_MAGIC_PROTRACKER4, 4)) {
137 vfs_fclose(file);
138 return 1;
139 }
140 if (!memcmp(magic, MOD_MAGIC_PROTRACKER4X, 4)) {
141 vfs_fclose(file);
142 return 1;
143 }
144 if (!memcmp(magic, MOD_MAGIC_STARTRACKER4, 4)) {
145 vfs_fclose(file);
146 return 1;
147 }
148 if (!memcmp(magic, MOD_MAGIC_STARTRACKER8, 4)) {
149 vfs_fclose(file);
150 return 1;
151 }
152 if (!memcmp(magic, MOD_MAGIC_FASTTRACKER4, 4)) {
153 vfs_fclose(file);
154 return 1;
155 }
156 if (!memcmp(magic, MOD_MAGIC_FASTTRACKER6, 4)) {
157 vfs_fclose(file);
158 return 1;
159 }
160 if (!memcmp(magic, MOD_MAGIC_FASTTRACKER8, 4)) {
161 vfs_fclose(file);
162 return 1;
163 }
164 if (!memcmp(magic, MOD_MAGIC_OKTALYZER8, 4)) {
165 vfs_fclose(file);
166 return 1;
167 }
168 if (!memcmp(magic, MOD_MAGIC_OKTALYZER8X, 4)) {
169 vfs_fclose(file);
170 return 1;
171 }
172 if (!memcmp(magic, MOD_MAGIC_TAKETRACKER16, 4)) {
173 vfs_fclose(file);
174 return 1;
175 }
176 if (!memcmp(magic, MOD_MAGIC_TAKETRACKER32, 4)) {
177 vfs_fclose(file);
178 return 1;
179 }
180 if (!memcmp(magic, MOD_MAGIC_15INSTRUMENT, 4)) {
181 vfs_fclose(file);
182 return 1;
183 }
184
185 /* We didn't find the magic bytes, fall back to extension check */
186 vfs_fclose(file);
187 } /* end of vfs_open main if statement */
188
98 lPos = aFilename.find_last_of('.'); 189 lPos = aFilename.find_last_of('.');
99 if((int)lPos == -1) 190 if((int)lPos == -1)
100 return false; 191 return false;
101 lExt = aFilename.substr(lPos); 192 lExt = aFilename.substr(lPos);
102 for(uint32 i = 0; i < lExt.length(); i++) 193 for(uint32 i = 0; i < lExt.length(); i++)
103 lExt[i] = tolower(lExt[i]); 194 lExt[i] = tolower(lExt[i]);
104 195
105 if (lExt == ".669")
106 return true;
107 if (lExt == ".amf") 196 if (lExt == ".amf")
108 return true; 197 return true;
109 if (lExt == ".ams") 198 if (lExt == ".ams")
110 return true; 199 return true;
111 if (lExt == ".dbm") 200 if (lExt == ".dbm")
114 return true; 203 return true;
115 if (lExt == ".dsm") 204 if (lExt == ".dsm")
116 return true; 205 return true;
117 if (lExt == ".far") 206 if (lExt == ".far")
118 return true; 207 return true;
119 if (lExt == ".it")
120 return true;
121 if (lExt == ".mdl") 208 if (lExt == ".mdl")
122 return true; 209 return true;
123 if (lExt == ".med") 210 if (lExt == ".med")
124 return true; 211 return true;
125 if (lExt == ".mod")
126 return true;
127 if (lExt == ".mtm")
128 return true;
129 if (lExt == ".okt")
130 return true;
131 if (lExt == ".ptm")
132 return true;
133 if (lExt == ".s3m")
134 return true;
135 if (lExt == ".stm") 212 if (lExt == ".stm")
136 return true; 213 return true;
137 if (lExt == ".ult") 214 if (lExt == ".ult")
138 return true; 215 return true;
139 if (lExt == ".umx") //Unreal rocks!
140 return true;
141 if (lExt == ".xm")
142 return true;
143 if (lExt == ".j2b") 216 if (lExt == ".j2b")
144 return true; 217 return true;
145 if (lExt == ".mt2") 218 if (lExt == ".mt2")
146 return true;
147 if (lExt == ".psm")
148 return true; 219 return true;
149 220
150 if (lExt == ".mdz") 221 if (lExt == ".mdz")
151 return true; 222 return true;
152 if (lExt == ".mdr") 223 if (lExt == ".mdr")