]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - vtoygpt/crc32.c
Fix the resolution issue when boot Windows/WinPE in UEFI mode.
[Ventoy.git] / vtoygpt / crc32.c
1 /******************************************************************************
2 * vtoygpt.c ---- ventoy gpt util
3 *
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20 #include <stdio.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <sys/types.h>
28 #include <sys/mman.h>
29 #include <sys/ioctl.h>
30 #include <sys/stat.h>
31 #include <sys/types.h>
32 #include <linux/fs.h>
33 #include <dirent.h>
34
35 #define VOID void
36 #define CHAR char
37 #define UINT64 unsigned long long
38 #define UINT32 unsigned int
39 #define UINT16 unsigned short
40 #define CHAR16 unsigned short
41 #define UINT8 unsigned char
42
43 UINT32 g_crc_table[256] = {
44 0x00000000,
45 0x77073096,
46 0xEE0E612C,
47 0x990951BA,
48 0x076DC419,
49 0x706AF48F,
50 0xE963A535,
51 0x9E6495A3,
52 0x0EDB8832,
53 0x79DCB8A4,
54 0xE0D5E91E,
55 0x97D2D988,
56 0x09B64C2B,
57 0x7EB17CBD,
58 0xE7B82D07,
59 0x90BF1D91,
60 0x1DB71064,
61 0x6AB020F2,
62 0xF3B97148,
63 0x84BE41DE,
64 0x1ADAD47D,
65 0x6DDDE4EB,
66 0xF4D4B551,
67 0x83D385C7,
68 0x136C9856,
69 0x646BA8C0,
70 0xFD62F97A,
71 0x8A65C9EC,
72 0x14015C4F,
73 0x63066CD9,
74 0xFA0F3D63,
75 0x8D080DF5,
76 0x3B6E20C8,
77 0x4C69105E,
78 0xD56041E4,
79 0xA2677172,
80 0x3C03E4D1,
81 0x4B04D447,
82 0xD20D85FD,
83 0xA50AB56B,
84 0x35B5A8FA,
85 0x42B2986C,
86 0xDBBBC9D6,
87 0xACBCF940,
88 0x32D86CE3,
89 0x45DF5C75,
90 0xDCD60DCF,
91 0xABD13D59,
92 0x26D930AC,
93 0x51DE003A,
94 0xC8D75180,
95 0xBFD06116,
96 0x21B4F4B5,
97 0x56B3C423,
98 0xCFBA9599,
99 0xB8BDA50F,
100 0x2802B89E,
101 0x5F058808,
102 0xC60CD9B2,
103 0xB10BE924,
104 0x2F6F7C87,
105 0x58684C11,
106 0xC1611DAB,
107 0xB6662D3D,
108 0x76DC4190,
109 0x01DB7106,
110 0x98D220BC,
111 0xEFD5102A,
112 0x71B18589,
113 0x06B6B51F,
114 0x9FBFE4A5,
115 0xE8B8D433,
116 0x7807C9A2,
117 0x0F00F934,
118 0x9609A88E,
119 0xE10E9818,
120 0x7F6A0DBB,
121 0x086D3D2D,
122 0x91646C97,
123 0xE6635C01,
124 0x6B6B51F4,
125 0x1C6C6162,
126 0x856530D8,
127 0xF262004E,
128 0x6C0695ED,
129 0x1B01A57B,
130 0x8208F4C1,
131 0xF50FC457,
132 0x65B0D9C6,
133 0x12B7E950,
134 0x8BBEB8EA,
135 0xFCB9887C,
136 0x62DD1DDF,
137 0x15DA2D49,
138 0x8CD37CF3,
139 0xFBD44C65,
140 0x4DB26158,
141 0x3AB551CE,
142 0xA3BC0074,
143 0xD4BB30E2,
144 0x4ADFA541,
145 0x3DD895D7,
146 0xA4D1C46D,
147 0xD3D6F4FB,
148 0x4369E96A,
149 0x346ED9FC,
150 0xAD678846,
151 0xDA60B8D0,
152 0x44042D73,
153 0x33031DE5,
154 0xAA0A4C5F,
155 0xDD0D7CC9,
156 0x5005713C,
157 0x270241AA,
158 0xBE0B1010,
159 0xC90C2086,
160 0x5768B525,
161 0x206F85B3,
162 0xB966D409,
163 0xCE61E49F,
164 0x5EDEF90E,
165 0x29D9C998,
166 0xB0D09822,
167 0xC7D7A8B4,
168 0x59B33D17,
169 0x2EB40D81,
170 0xB7BD5C3B,
171 0xC0BA6CAD,
172 0xEDB88320,
173 0x9ABFB3B6,
174 0x03B6E20C,
175 0x74B1D29A,
176 0xEAD54739,
177 0x9DD277AF,
178 0x04DB2615,
179 0x73DC1683,
180 0xE3630B12,
181 0x94643B84,
182 0x0D6D6A3E,
183 0x7A6A5AA8,
184 0xE40ECF0B,
185 0x9309FF9D,
186 0x0A00AE27,
187 0x7D079EB1,
188 0xF00F9344,
189 0x8708A3D2,
190 0x1E01F268,
191 0x6906C2FE,
192 0xF762575D,
193 0x806567CB,
194 0x196C3671,
195 0x6E6B06E7,
196 0xFED41B76,
197 0x89D32BE0,
198 0x10DA7A5A,
199 0x67DD4ACC,
200 0xF9B9DF6F,
201 0x8EBEEFF9,
202 0x17B7BE43,
203 0x60B08ED5,
204 0xD6D6A3E8,
205 0xA1D1937E,
206 0x38D8C2C4,
207 0x4FDFF252,
208 0xD1BB67F1,
209 0xA6BC5767,
210 0x3FB506DD,
211 0x48B2364B,
212 0xD80D2BDA,
213 0xAF0A1B4C,
214 0x36034AF6,
215 0x41047A60,
216 0xDF60EFC3,
217 0xA867DF55,
218 0x316E8EEF,
219 0x4669BE79,
220 0xCB61B38C,
221 0xBC66831A,
222 0x256FD2A0,
223 0x5268E236,
224 0xCC0C7795,
225 0xBB0B4703,
226 0x220216B9,
227 0x5505262F,
228 0xC5BA3BBE,
229 0xB2BD0B28,
230 0x2BB45A92,
231 0x5CB36A04,
232 0xC2D7FFA7,
233 0xB5D0CF31,
234 0x2CD99E8B,
235 0x5BDEAE1D,
236 0x9B64C2B0,
237 0xEC63F226,
238 0x756AA39C,
239 0x026D930A,
240 0x9C0906A9,
241 0xEB0E363F,
242 0x72076785,
243 0x05005713,
244 0x95BF4A82,
245 0xE2B87A14,
246 0x7BB12BAE,
247 0x0CB61B38,
248 0x92D28E9B,
249 0xE5D5BE0D,
250 0x7CDCEFB7,
251 0x0BDBDF21,
252 0x86D3D2D4,
253 0xF1D4E242,
254 0x68DDB3F8,
255 0x1FDA836E,
256 0x81BE16CD,
257 0xF6B9265B,
258 0x6FB077E1,
259 0x18B74777,
260 0x88085AE6,
261 0xFF0F6A70,
262 0x66063BCA,
263 0x11010B5C,
264 0x8F659EFF,
265 0xF862AE69,
266 0x616BFFD3,
267 0x166CCF45,
268 0xA00AE278,
269 0xD70DD2EE,
270 0x4E048354,
271 0x3903B3C2,
272 0xA7672661,
273 0xD06016F7,
274 0x4969474D,
275 0x3E6E77DB,
276 0xAED16A4A,
277 0xD9D65ADC,
278 0x40DF0B66,
279 0x37D83BF0,
280 0xA9BCAE53,
281 0xDEBB9EC5,
282 0x47B2CF7F,
283 0x30B5FFE9,
284 0xBDBDF21C,
285 0xCABAC28A,
286 0x53B39330,
287 0x24B4A3A6,
288 0xBAD03605,
289 0xCDD70693,
290 0x54DE5729,
291 0x23D967BF,
292 0xB3667A2E,
293 0xC4614AB8,
294 0x5D681B02,
295 0x2A6F2B94,
296 0xB40BBE37,
297 0xC30C8EA1,
298 0x5A05DF1B,
299 0x2D02EF8D
300 };
301
302 UINT32 VtoyCrc32(VOID *Buffer, UINT32 Length)
303 {
304 UINT32 i;
305 UINT8 *Ptr = Buffer;
306 UINT32 Crc = 0xFFFFFFFF;
307
308 for (i = 0; i < Length; i++, Ptr++)
309 {
310 Crc = (Crc >> 8) ^ g_crc_table[(UINT8) Crc ^ *Ptr];
311 }
312
313 return Crc ^ 0xffffffff;
314 }
315