source: dev/trunk/abdev/BasicCompiler_Common/RSrcSection.cpp@ 279

Last change on this file since 279 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

File size: 26.0 KB
Line 
1#include "stdafx.h"
2
3#include "../BasicCompiler_Common/common.h"
4
5#ifndef RT_MANIFEST
6#define RT_MANIFEST MAKEINTRESOURCE(24)
7#endif
8
9//リソースアドレススケジュール
10DWORD *lpdwRSrcAddrSchedule;
11int RSrcAddrScheduleNum;
12
13void AddRSrcAddrSchedule(DWORD pos){
14 extern HANDLE hHeap;
15
16 //グローバル変数アドレススケジュールに追加する
17 lpdwRSrcAddrSchedule=(DWORD *)HeapReAlloc(hHeap,0,lpdwRSrcAddrSchedule,(RSrcAddrScheduleNum+1)*sizeof(DWORD));
18 lpdwRSrcAddrSchedule[RSrcAddrScheduleNum]=pos;
19 RSrcAddrScheduleNum++;
20}
21
22char *PermutationString(char *buffer,char *lpszSearch,char *lpszRewrite){
23 //バッファ長
24 int length;
25 length=lstrlen(buffer);
26
27 //サーチ文字列の長さ
28 int search_length;
29 search_length=lstrlen(lpszSearch);
30
31 //置換文字列の長さ
32 int write_length;
33 write_length=lstrlen(lpszRewrite);
34
35 //置換時オフセット
36 int offset;
37 offset=lstrlen(lpszRewrite)-search_length;
38
39 int i;
40 for(i=0;i<length-search_length;i++){
41 if(memcmp(buffer+i,lpszSearch,search_length)==0){
42 if(offset>0){
43 length+=offset;
44 buffer=(char *)HeapReAlloc(hHeap,0,buffer,length+1);
45 }
46
47 SlideString(buffer+i+search_length,offset);
48 memcpy(buffer+i,lpszRewrite,write_length);
49 i+=write_length-1;
50 }
51 }
52
53 return buffer;
54}
55
56char *GetRSrcSectionBuffer(int *pLen){
57 extern HANDLE hHeap;
58 char *buffer,*temporary;
59 int i2,i3,i4,i5,i6,i7,sw,BufSize,TypeNum,NextBase;
60 HANDLE hFile;
61
62 //カーソルリソース
63 extern RESOURCEDATAINFO *pCursorResourceInfo;
64 extern int CursorResourceNum;
65 int CursorNum;
66 CURSORDIR *pCursorDir;
67 CURSORDIRENTRY *pCursorDirEntry;
68 CURSORDIRENTRY_RES CursorDirEntry_Res;
69 CursorNum=0;
70
71 //ビットマップリソース
72 extern RESOURCEDATAINFO *pBitmapResourceInfo;
73 extern int BitmapResourceNum;
74
75 //アイコンリソース
76 extern RESOURCEDATAINFO *pIconResourceInfo;
77 extern int IconResourceNum;
78 int IconNum;
79 ICONDIR *pIconDir;
80 ICONDIRENTRY *pIconDirEntry;
81 ICONDIRENTRY_RES IconDirEntry_Res;
82 IconNum=0;
83
84 //XPManifestリソース
85 extern char szManifestPath[MAX_PATH];
86 extern int XPManiResourceNum;
87
88 BufSize=8192*2;
89 buffer=(char *)HeapAlloc(hHeap,0,BufSize);
90 i2=0;
91 NextBase=0;
92
93 //リソースアドレススケジュール
94 lpdwRSrcAddrSchedule=(DWORD *)HeapAlloc(hHeap,0,1);
95 RSrcAddrScheduleNum=0;
96
97 *pLen=0;
98
99 if(CursorResourceNum==0&&
100 BitmapResourceNum==0&&
101 IconResourceNum==0&&
102 XPManiResourceNum==0) return buffer;
103
104 sw=0;
105
106 //カーソルの枚数を計算(CursorNumに格納)
107 for(i3=0;i3<CursorResourceNum;i3++){
108 hFile=CreateFile(pCursorResourceInfo[i3].FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
109 if(hFile==INVALID_HANDLE_VALUE){
110 SetError(23,pCursorResourceInfo[i3].FileName,-1);
111 sw=1;
112 continue;
113 }
114 i4=GetFileSize(hFile,NULL);
115 temporary=(char *)HeapAlloc(hHeap,0,i4);
116 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
117 CloseHandle(hFile);
118
119 pCursorDir=(CURSORDIR *)temporary;
120 CursorNum+=pCursorDir->idCount;
121
122 HeapDefaultFree(temporary);
123 }
124
125 //ビットマップのファイルの有無を確認
126 for(i3=0;i3<BitmapResourceNum;i3++){
127 hFile=CreateFile(pBitmapResourceInfo[i3].FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
128 if(hFile==INVALID_HANDLE_VALUE){
129 SetError(23,pBitmapResourceInfo[i3].FileName,-1);
130 sw=1;
131 continue;
132 }
133 CloseHandle(hFile);
134 }
135
136 //アイコンの枚数を計算(IconNumに格納)
137 for(i3=0;i3<IconResourceNum;i3++){
138 hFile=CreateFile(pIconResourceInfo[i3].FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
139 if(hFile==INVALID_HANDLE_VALUE){
140 SetError(23,pIconResourceInfo[i3].FileName,-1);
141 sw=1;
142 continue;
143 }
144 i4=GetFileSize(hFile,NULL);
145 temporary=(char *)HeapAlloc(hHeap,0,i4);
146 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
147 CloseHandle(hFile);
148
149 pIconDir=(ICONDIR *)temporary;
150 IconNum+=pIconDir->idCount;
151
152 HeapDefaultFree(temporary);
153 }
154
155 //ファイルの読み込みに失敗した場合
156 if(sw) return buffer;
157
158
159 /////////////////////////
160 // ディレクトリ エントリ
161 /////////////////////////
162 TypeNum=0;
163 if(CursorResourceNum) TypeNum+=2;
164 if(BitmapResourceNum) TypeNum++;
165 if(IconResourceNum) TypeNum+=2;
166 if(XPManiResourceNum) TypeNum++;
167
168 NextBase=sizeof(IMAGE_RESOURCE_DIRECTORY)+
169 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*TypeNum;
170
171 //1階層
172 IMAGE_RESOURCE_DIRECTORY ImgResDir;
173 ImgResDir.Characteristics=0;
174 ImgResDir.TimeDateStamp=0;
175 ImgResDir.MajorVersion=0;
176 ImgResDir.MinorVersion=0;
177 ImgResDir.NumberOfNamedEntries=0;
178 ImgResDir.NumberOfIdEntries=TypeNum;
179 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
180 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
181
182 i6=0;
183 IMAGE_RESOURCE_DIRECTORY_ENTRY ImgDirEntry;
184 if(CursorNum){
185 //RT_CURSOR
186 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_CURSOR;
187 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
188 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
189 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
190
191 //2階層のサイズ
192 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
193 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*CursorNum;
194 }
195 if(BitmapResourceNum){
196 //RT_BITMAP
197 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_BITMAP;
198 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
199 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
200 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
201
202 //2階層のサイズ
203 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
204 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*BitmapResourceNum;
205 }
206 if(IconNum){
207 //RT_ICON
208 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_ICON;
209 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
210 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
211 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
212
213 //2階層のサイズ
214 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
215 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*IconNum;
216 }
217 if(CursorResourceNum){
218 //RT_GROUP_CURSOR
219 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_GROUP_CURSOR;
220 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
221 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
222 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
223
224 //2階層のサイズ
225 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
226 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*CursorNum;
227 }
228 if(IconResourceNum){
229 //RT_GROUP_ICON
230 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_GROUP_ICON;
231 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
232 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
233 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
234
235 //2階層のサイズ
236 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
237 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*IconResourceNum;
238 }
239 if(XPManiResourceNum){
240 //RT_MANIFEST
241 ImgDirEntry.Name=(DWORD)(LONG_PTR)RT_MANIFEST;
242 ImgDirEntry.OffsetToData=(NextBase+i6)|0x80000000;
243 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
244 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
245
246 //2階層のサイズ
247 i6+= sizeof(IMAGE_RESOURCE_DIRECTORY)+
248 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY)*XPManiResourceNum;
249 }
250
251 NextBase+=i6;
252
253 //2階層
254 i6=0;
255 i7=0;
256 if(CursorNum){
257 //RT_CURSOR
258 ImgResDir.Characteristics=0;
259 ImgResDir.TimeDateStamp=0;
260 ImgResDir.MajorVersion=0;
261 ImgResDir.MinorVersion=0;
262 ImgResDir.NumberOfNamedEntries=0;
263 ImgResDir.NumberOfIdEntries=CursorNum;
264 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
265 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
266
267 for(i3=0;i3<CursorNum;i3++,i7++){
268 ImgDirEntry.Name=i7+1;
269 ImgDirEntry.OffsetToData=(NextBase+i6+
270 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
271 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
272 |0x80000000;
273 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
274 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
275 }
276
277 //3階層のサイズ
278 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
279 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*CursorNum;
280 }
281 if(BitmapResourceNum){
282 //RT_BITMAP
283 ImgResDir.Characteristics=0;
284 ImgResDir.TimeDateStamp=0;
285 ImgResDir.MajorVersion=0;
286 ImgResDir.MinorVersion=0;
287 ImgResDir.NumberOfNamedEntries=0;
288 ImgResDir.NumberOfIdEntries=BitmapResourceNum;
289 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
290 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
291
292 for(i3=0;i3<BitmapResourceNum;i3++){
293 ImgDirEntry.Name=pBitmapResourceInfo[i3].dwId;
294 ImgDirEntry.OffsetToData=(NextBase+i6+
295 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
296 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
297 |0x80000000;
298 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
299 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
300 }
301
302 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
303 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*BitmapResourceNum;
304 }
305 if(IconNum){
306 //RT_ICON
307 ImgResDir.Characteristics=0;
308 ImgResDir.TimeDateStamp=0;
309 ImgResDir.MajorVersion=0;
310 ImgResDir.MinorVersion=0;
311 ImgResDir.NumberOfNamedEntries=0;
312 ImgResDir.NumberOfIdEntries=IconNum;
313 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
314 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
315
316 for(i3=0;i3<IconNum;i3++,i7++){
317 ImgDirEntry.Name=i7+1;
318 ImgDirEntry.OffsetToData=(NextBase+i6+
319 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
320 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
321 |0x80000000;
322 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
323 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
324 }
325
326 //3階層のサイズ
327 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
328 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*IconNum;
329 }
330 if(CursorResourceNum){
331 //RT_GROUP_CURSOR
332 ImgResDir.Characteristics=0;
333 ImgResDir.TimeDateStamp=0;
334 ImgResDir.MajorVersion=0;
335 ImgResDir.MinorVersion=0;
336 ImgResDir.NumberOfNamedEntries=0;
337 ImgResDir.NumberOfIdEntries=CursorResourceNum;
338 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
339 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
340
341 for(i3=0;i3<CursorResourceNum;i3++){
342 ImgDirEntry.Name=pCursorResourceInfo[i3].dwId;
343 ImgDirEntry.OffsetToData=(NextBase+i6+
344 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
345 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
346 |0x80000000;
347 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
348 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
349 }
350
351 //3階層のサイズ
352 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
353 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*CursorResourceNum;
354 }
355 if(IconResourceNum){
356 //RT_GROUP_ICON
357 ImgResDir.Characteristics=0;
358 ImgResDir.TimeDateStamp=0;
359 ImgResDir.MajorVersion=0;
360 ImgResDir.MinorVersion=0;
361 ImgResDir.NumberOfNamedEntries=0;
362 ImgResDir.NumberOfIdEntries=IconResourceNum;
363 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
364 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
365
366 for(i3=0;i3<IconResourceNum;i3++){
367 ImgDirEntry.Name=pIconResourceInfo[i3].dwId;
368 ImgDirEntry.OffsetToData=(NextBase+i6+
369 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
370 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
371 |0x80000000;
372 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
373 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
374 }
375
376 //3階層のサイズ
377 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
378 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*IconResourceNum;
379 }
380 if(XPManiResourceNum){
381 //RT_MANIFEST
382 ImgResDir.Characteristics=0;
383 ImgResDir.TimeDateStamp=0;
384 ImgResDir.MajorVersion=0;
385 ImgResDir.MinorVersion=0;
386 ImgResDir.NumberOfNamedEntries=0;
387 ImgResDir.NumberOfIdEntries=XPManiResourceNum;
388 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
389 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
390
391 for(i3=0;i3<XPManiResourceNum;i3++){
392 ImgDirEntry.Name=i3+1;
393 ImgDirEntry.OffsetToData=(NextBase+i6+
394 (sizeof(IMAGE_RESOURCE_DIRECTORY)+
395 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*i3)
396 |0x80000000;
397 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
398 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
399 }
400
401 i6+=(sizeof(IMAGE_RESOURCE_DIRECTORY)+
402 sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY))*XPManiResourceNum;
403 }
404
405
406 NextBase+=i6;
407
408 while(i2+8192>BufSize){
409 BufSize+=8192;
410 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
411 }
412
413 //3階層
414 i6=0;
415 if(CursorNum){
416 //RT_CURSOR
417 for(i3=0;i3<CursorNum;i3++){
418 ImgResDir.Characteristics=0;
419 ImgResDir.TimeDateStamp=0;
420 ImgResDir.MajorVersion=0;
421 ImgResDir.MinorVersion=0;
422 ImgResDir.NumberOfNamedEntries=0;
423 ImgResDir.NumberOfIdEntries=1;
424 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
425 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
426
427 ImgDirEntry.Name=0x411;
428 ImgDirEntry.OffsetToData=NextBase+i6+
429 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
430 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
431 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
432 }
433
434 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY)*CursorNum;
435 }
436 if(BitmapResourceNum){
437 //RT_BITMAP
438 for(i3=0;i3<BitmapResourceNum;i3++){
439 ImgResDir.Characteristics=0;
440 ImgResDir.TimeDateStamp=0;
441 ImgResDir.MajorVersion=0;
442 ImgResDir.MinorVersion=0;
443 ImgResDir.NumberOfNamedEntries=0;
444 ImgResDir.NumberOfIdEntries=1;
445 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
446 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
447
448 ImgDirEntry.Name=0x411;
449 ImgDirEntry.OffsetToData=NextBase+i6+
450 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
451 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
452 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
453 }
454
455 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY)*BitmapResourceNum;
456 }
457 if(IconNum){
458 //RT_ICON
459 for(i3=0;i3<IconNum;i3++){
460 ImgResDir.Characteristics=0;
461 ImgResDir.TimeDateStamp=0;
462 ImgResDir.MajorVersion=0;
463 ImgResDir.MinorVersion=0;
464 ImgResDir.NumberOfNamedEntries=0;
465 ImgResDir.NumberOfIdEntries=1;
466 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
467 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
468
469 ImgDirEntry.Name=0x411;
470 ImgDirEntry.OffsetToData=NextBase+i6+
471 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
472 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
473 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
474 }
475
476 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY)*IconNum;
477 }
478 if(CursorResourceNum){
479 //RT_GROUP_CURSOR
480 for(i3=0;i3<CursorResourceNum;i3++){
481 ImgResDir.Characteristics=0;
482 ImgResDir.TimeDateStamp=0;
483 ImgResDir.MajorVersion=0;
484 ImgResDir.MinorVersion=0;
485 ImgResDir.NumberOfNamedEntries=0;
486 ImgResDir.NumberOfIdEntries=1;
487 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
488 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
489
490 ImgDirEntry.Name=0x411;
491 ImgDirEntry.OffsetToData=NextBase+i6+
492 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
493 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
494 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
495 }
496
497 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY)*CursorResourceNum;
498 }
499 if(IconResourceNum){
500 //RT_GROUP_ICON
501 for(i3=0;i3<IconResourceNum;i3++){
502 ImgResDir.Characteristics=0;
503 ImgResDir.TimeDateStamp=0;
504 ImgResDir.MajorVersion=0;
505 ImgResDir.MinorVersion=0;
506 ImgResDir.NumberOfNamedEntries=0;
507 ImgResDir.NumberOfIdEntries=1;
508 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
509 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
510
511 ImgDirEntry.Name=0x411;
512 ImgDirEntry.OffsetToData=NextBase+i6+
513 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
514 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
515 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
516 }
517
518 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY)*IconResourceNum;
519 }
520 if(XPManiResourceNum){
521 //RT_MANIFEST
522 for(i3=0;i3<XPManiResourceNum;i3++){
523 ImgResDir.Characteristics=0;
524 ImgResDir.TimeDateStamp=0;
525 ImgResDir.MajorVersion=0;
526 ImgResDir.MinorVersion=0;
527 ImgResDir.NumberOfNamedEntries=0;
528 ImgResDir.NumberOfIdEntries=1;
529 memcpy(buffer+i2,&ImgResDir,sizeof(IMAGE_RESOURCE_DIRECTORY));
530 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY);
531
532 ImgDirEntry.Name=0x411;
533 ImgDirEntry.OffsetToData=NextBase+i6+
534 sizeof(IMAGE_RESOURCE_DATA_ENTRY)*i3;
535 memcpy(buffer+i2,&ImgDirEntry,sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
536 i2+=sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY);
537 }
538
539 i6+=sizeof(IMAGE_RESOURCE_DATA_ENTRY)*XPManiResourceNum;
540 }
541
542 NextBase+=i6;
543
544 while(i2+8192>BufSize){
545 BufSize+=8192;
546 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
547 }
548
549
550
551 ////////////////////////////////////////
552 // データ エントリ
553 ////////////////////////////////////////
554
555 DWORD dwDataEntrySchedule[100];
556 int DataEntryScheduleNum;
557 int CursorEntryBase;
558 int CursorGroupEntryBase;
559 int BitmapEntryBase;
560 int IconEntryBase;
561 int IconGroupEntryBase;
562
563 DataEntryScheduleNum=0;
564
565 //空のデータエントリ領域を作成
566
567 //RT_CURSOR
568 CursorEntryBase=DataEntryScheduleNum;
569 for(i3=0;i3<CursorNum;i3++){
570 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
571 DataEntryScheduleNum++;
572 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
573 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
574 }
575
576 //RT_BITMAP
577 BitmapEntryBase=DataEntryScheduleNum;
578 for(i3=0;i3<BitmapResourceNum;i3++){
579 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
580 DataEntryScheduleNum++;
581 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
582 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
583 }
584
585 //RT_ICON
586 IconEntryBase=DataEntryScheduleNum;
587 for(i3=0;i3<IconNum;i3++){
588 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
589 DataEntryScheduleNum++;
590 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
591 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
592 }
593
594 //RT_GROUP_CURSOR
595 CursorGroupEntryBase=DataEntryScheduleNum;
596 for(i3=0;i3<CursorResourceNum;i3++){
597 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
598 DataEntryScheduleNum++;
599 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
600 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
601 }
602
603 //RT_GROUP_ICON
604 IconGroupEntryBase=DataEntryScheduleNum;
605 for(i3=0;i3<IconResourceNum;i3++){
606 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
607 DataEntryScheduleNum++;
608 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
609 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
610 }
611
612 //RT_MANIFEST
613 int XPManiEntryBase;
614 XPManiEntryBase=DataEntryScheduleNum;
615 for(i3=0;i3<XPManiResourceNum;i3++){
616 dwDataEntrySchedule[DataEntryScheduleNum]=i2;
617 DataEntryScheduleNum++;
618 memset(buffer+i2,0,sizeof(IMAGE_RESOURCE_DATA_ENTRY));
619 i2+=sizeof(IMAGE_RESOURCE_DATA_ENTRY);
620 }
621
622 i4=i2%8;
623 if(i4){
624 memset(buffer+i2,0,8-i4);
625 i2+=8-i4;
626 }
627
628 while(i2+8192>BufSize){
629 BufSize+=8192;
630 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
631 }
632
633
634 ///////////////////////////////////////
635 // バイナリ データ
636 // ※データエントリの内容も変更する
637 ///////////////////////////////////////
638
639 IMAGE_RESOURCE_DATA_ENTRY *pImgDataEntry;
640
641 i7=0;
642
643 //カーソルリソース
644 for(i3=0,i6=0;i3<CursorResourceNum;i3++){
645 hFile=CreateFile(pCursorResourceInfo[i3].FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
646 if(hFile==INVALID_HANDLE_VALUE){
647 SetError(23,pCursorResourceInfo[i3].FileName,-1);
648 return buffer;
649 }
650 i4=GetFileSize(hFile,NULL);
651 temporary=(char *)HeapAlloc(hHeap,0,i4);
652 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
653 CloseHandle(hFile);
654
655 pCursorDir=(CURSORDIR *)temporary;
656
657 for(i5=0;i5<pCursorDir->idCount;i5++,i6++){
658 pCursorDirEntry=(CURSORDIRENTRY *)(temporary+sizeof(CURSORDIR)+sizeof(CURSORDIRENTRY)*i5);
659
660 //データエントリ
661 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[CursorEntryBase+i6]);
662 pImgDataEntry->OffsetToData=i2;
663 pImgDataEntry->Size=pCursorDirEntry->dwBytesInRes+sizeof(WORD)*2;
664 AddRSrcAddrSchedule(dwDataEntrySchedule[CursorEntryBase+i6]);
665
666 //RT_CURSOR バイナリ データ
667 *(WORD *)(buffer+i2)=0x001F;
668 i2+=sizeof(WORD);
669 *(WORD *)(buffer+i2)=0x001F;
670 i2+=sizeof(WORD);
671 memcpy(buffer+i2,temporary+pCursorDirEntry->dwImageOffset,pCursorDirEntry->dwBytesInRes);
672 i2+=pCursorDirEntry->dwBytesInRes;
673
674 i4=i2%8;
675 if(i4){
676 memset(buffer+i2,0,8-i4);
677 i2+=8-i4;
678 }
679
680 while(i2+8192>BufSize){
681 BufSize+=8192;
682 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
683 }
684 }
685
686 //データエントリ
687 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[CursorGroupEntryBase+i3]);
688 pImgDataEntry->OffsetToData=i2;
689 pImgDataEntry->Size=sizeof(CURSORDIR)+0xE*pCursorDir->idCount;
690 AddRSrcAddrSchedule(dwDataEntrySchedule[CursorGroupEntryBase+i3]);
691
692 //RT_GROUP_CURSORヘッダデータ(CURSORDIR)
693 memcpy(buffer+i2,temporary,sizeof(CURSORDIR));
694 i2+=sizeof(CURSORDIR);
695
696 for(i5=0;i5<pCursorDir->idCount;i5++,i7++){
697 pCursorDirEntry=(CURSORDIRENTRY *)(temporary+sizeof(CURSORDIR)+sizeof(CURSORDIRENTRY)*i5);
698 CursorDirEntry_Res.wWidth=pCursorDirEntry->bWidth;
699 CursorDirEntry_Res.wHeight=CursorDirEntry_Res.wWidth*2;
700 CursorDirEntry_Res.wXHotspot=pCursorDirEntry->wXHotspot;
701 CursorDirEntry_Res.wYHotspot=pCursorDirEntry->wYHotspot;
702 CursorDirEntry_Res.dwBytesInRes=pCursorDirEntry->dwBytesInRes+sizeof(WORD)*2;
703 CursorDirEntry_Res.wCursorNum=i7+1;
704
705 //RT_GROUP_CURSORヘッダデータ(CURSORDIRENTRY_RES)
706 memcpy(buffer+i2,&CursorDirEntry_Res,0xE);
707 i2+=0xE;
708
709 while(i2+8192>BufSize){
710 BufSize+=8192;
711 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
712 }
713 }
714 i4=i2%8;
715 if(i4){
716 memset(buffer+i2,0,8-i4);
717 i2+=8-i4;
718 }
719
720 HeapDefaultFree(temporary);
721 }
722
723 //ビットマップリソース
724 for(i3=0;i3<BitmapResourceNum;i3++){
725 hFile=CreateFile(pBitmapResourceInfo[i3].FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
726 if(hFile==INVALID_HANDLE_VALUE){
727 SetError(23,pBitmapResourceInfo[i3].FileName,-1);
728 return buffer;
729 }
730 i4=GetFileSize(hFile,NULL);
731 temporary=(char *)HeapAlloc(hHeap,0,i4);
732 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
733 CloseHandle(hFile);
734
735 BufSize+=i4;
736 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
737
738 //データエントリ
739 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[BitmapEntryBase+i3]);
740 pImgDataEntry->OffsetToData=i2;
741 pImgDataEntry->Size=i4-sizeof(BITMAPFILEHEADER);
742 AddRSrcAddrSchedule(dwDataEntrySchedule[BitmapEntryBase+i3]);
743
744 //RT_BITMAP バイナリ データ
745 memcpy(buffer+i2,temporary+sizeof(BITMAPFILEHEADER),i4-sizeof(BITMAPFILEHEADER));
746 i2+=i4-sizeof(BITMAPFILEHEADER);
747
748 HeapDefaultFree(temporary);
749 }
750
751 //アイコンリソース
752 for(i3=0,i6=0;i3<IconResourceNum;i3++){
753 hFile=CreateFile(pIconResourceInfo[i3].FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
754 if(hFile==INVALID_HANDLE_VALUE){
755 SetError(23,pIconResourceInfo[i3].FileName,-1);
756 return buffer;
757 }
758 i4=GetFileSize(hFile,NULL);
759 temporary=(char *)HeapAlloc(hHeap,0,i4);
760 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
761 CloseHandle(hFile);
762
763 pIconDir=(ICONDIR *)temporary;
764
765 for(i5=0;i5<pIconDir->idCount;i5++,i6++){
766 pIconDirEntry=(ICONDIRENTRY *)(temporary+sizeof(ICONDIR)+sizeof(ICONDIRENTRY)*i5);
767
768 //データエントリ
769 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[IconEntryBase+i6]);
770 pImgDataEntry->OffsetToData=i2;
771 pImgDataEntry->Size=pIconDirEntry->dwBytesInRes;
772 AddRSrcAddrSchedule(dwDataEntrySchedule[IconEntryBase+i6]);
773
774 //RT_ICON バイナリ データ
775 memcpy(buffer+i2,temporary+pIconDirEntry->dwImageOffset,pIconDirEntry->dwBytesInRes);
776 i2+=pIconDirEntry->dwBytesInRes;
777
778 i4=i2%8;
779 if(i4){
780 memset(buffer+i2,0,8-i4);
781 i2+=8-i4;
782 }
783
784 while(i2+8192>BufSize){
785 BufSize+=8192;
786 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
787 }
788 }
789
790 //データエントリ
791 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[IconGroupEntryBase+i3]);
792 pImgDataEntry->OffsetToData=i2;
793 pImgDataEntry->Size=sizeof(ICONDIR)+0xE*pIconDir->idCount;
794 AddRSrcAddrSchedule(dwDataEntrySchedule[IconGroupEntryBase+i3]);
795
796 //RT_GROUP_ICONヘッダデータ(ICONDIR)
797 memcpy(buffer+i2,temporary,sizeof(ICONDIR));
798 i2+=sizeof(ICONDIR);
799
800 for(i5=0;i5<pIconDir->idCount;i5++,i7++){
801 pIconDirEntry=(ICONDIRENTRY *)(temporary+sizeof(ICONDIR)+sizeof(ICONDIRENTRY)*i5);
802 IconDirEntry_Res.bWidth=pIconDirEntry->bWidth;
803 IconDirEntry_Res.bHeight=pIconDirEntry->bHeight;
804 IconDirEntry_Res.bColorCount=pIconDirEntry->bColorCount;
805 IconDirEntry_Res.bReserved=0;
806 IconDirEntry_Res.wPlanes=1;
807 if(pIconDirEntry->bColorCount==16)
808 IconDirEntry_Res.wBitCount=4;
809 else if(pIconDirEntry->bColorCount==0)
810 IconDirEntry_Res.wBitCount=8;
811 IconDirEntry_Res.dwBytesInRes=pIconDirEntry->dwBytesInRes;
812 IconDirEntry_Res.wIconNum=i7+1;
813
814 //RT_GROUP_ICONヘッダデータ(ICONDIRENTRY_RES)
815 memcpy(buffer+i2,&IconDirEntry_Res,0xE);
816 i2+=0xE;
817
818 while(i2+8192>BufSize){
819 BufSize+=8192;
820 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
821 }
822 }
823 i4=i2%8;
824 if(i4){
825 memset(buffer+i2,0,8-i4);
826 i2+=8-i4;
827 }
828
829 HeapDefaultFree(temporary);
830 }
831
832 //XPManifestリソース
833 for(i3=0;i3<XPManiResourceNum;i3++){
834 extern char BasicCurDir[MAX_PATH];
835 extern char szManifestPath[MAX_PATH];
836 char temp2[MAX_PATH];
837 lstrcpy(temp2,szManifestPath);
838 GetFullPath(temp2,BasicCurDir);
839 hFile=CreateFile(temp2,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
840 if(hFile==INVALID_HANDLE_VALUE){
841 SetError(59,temp2,-1);
842 return buffer;
843 }
844 i4=GetFileSize(hFile,NULL);
845 temporary=(char *)HeapAlloc(hHeap,0,i4+1);
846 ReadFile(hFile,temporary,i4,(DWORD *)&i5,NULL);
847 temporary[i4]=0;
848 CloseHandle(hFile);
849
850 //プラットフォームをセット
851#ifdef _AMD64_
852 temporary=PermutationString(temporary,"#PLATFORM#","amd64");
853#else
854 temporary=PermutationString(temporary,"#PLATFORM#","x86");
855#endif
856
857 //アプリケーション名をセット
858 extern char OutputFileName[MAX_PATH];
859 char szAppliName[MAX_PATH];
860 _splitpath(OutputFileName,NULL,NULL,szAppliName,temp2);
861 lstrcat(szAppliName,temp2);
862 temporary=PermutationString(temporary,"#APPLI_FILE_NAME#",szAppliName);
863
864 i4=lstrlen(temporary)+1;
865
866 BufSize+=i4;
867 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
868
869 //データエントリ
870 pImgDataEntry=(IMAGE_RESOURCE_DATA_ENTRY *)(buffer+dwDataEntrySchedule[XPManiEntryBase+i3]);
871 pImgDataEntry->OffsetToData=i2;
872 pImgDataEntry->Size=i4-1; //※NULL文字はサイズに含めない
873 AddRSrcAddrSchedule(dwDataEntrySchedule[XPManiEntryBase+i3]);
874
875 //XMLデータ
876 memcpy(buffer+i2,temporary,i4);
877 i2+=i4;
878
879 HeapDefaultFree(temporary);
880 }
881
882 *pLen=i2;
883
884 return buffer;
885}
Note: See TracBrowser for help on using the repository browser.