source: dev/BasicCompiler_Common/RSrcSection.cpp@ 141

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