]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenFfsFileTask.java
Initial import.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenFfsFileTask.java
1 /** @file
2 GenFfsFileTask class.
3
4 GenFfsFileTaks is to generate ffs file.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16 package org.tianocore.framework.tasks;
17
18 import java.io.DataInputStream;
19 import java.io.DataOutputStream;
20 import java.io.File;
21 import java.io.FileInputStream;
22 import java.io.FileOutputStream;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
26
27 import org.apache.tools.ant.BuildException;
28 import org.apache.tools.ant.Project;
29 import org.apache.tools.ant.Task;
30
31 /**
32 GenFfsFileTask
33
34 GenFfsFileTaks is to generate ffs file.
35
36 **/
37 public class GenFfsFileTask extends Task implements EfiDefine, FfsTypes {
38 /**
39 * GenFfsFile Task Class
40 * class member
41 * -baseName : module baseName
42 * -ffsFileGuid : module Guid.
43 * -ffsFileType : Ffs file type.
44 * -ffsAttributeRecovery : The file is required for recovery.
45 * -ffsAligment : The file data alignment (0 if none required). See FFS
46 * specification for supported alignments (0-7 are only possible
47 * values). *
48 * -ffsAttributeCheckSum : The file data is checksummed. If this is FALSE a
49 * value of 0x5A will be inserted in the file
50 * checksum field of the file header. *
51 * -sectFileDir : specifies the full path to the component build directory.
52 * Required.
53 * -ffsAttrib : Data recorde attribute added result.
54 * -sectionList : List recorded all section elemet in task.
55 */
56 ///
57 /// module baseName
58 ///
59 String baseName = "";
60 ///
61 /// module Guid
62 ///
63 String ffsFileGuid = "";
64 ///
65 /// Ffs file type
66 ///
67 String ffsFileType = "";
68 ///
69 /// ffsAttribHeaderExtension value is used to set the corresponding bit in
70 /// the output FFS file header
71 ///
72 boolean ffsAttribHeaderExtension = false;
73 ///
74 /// ffsAttribTailPresent value is used to set the corresponding bit in the
75 /// output FFS file header
76 ///
77 boolean ffsAttribTailPresent = false;
78 ///
79 /// ffsAttribRecovery value is used to set the corresponding bit in the
80 /// output FFS file header
81 ///
82 boolean ffsAttribRecovery = false;
83 ///
84 /// ffsAligenment value is used to set the corresponding bit in the output
85 /// FFS file header.The specified FFS alignment must be a value between 0
86 /// and 7 inclusive
87 ///
88 int ffsAlignment = 0;
89 ///
90 /// ffsAttribChecksum value is used to set the corresponding bit in the
91 /// output FFS file header
92 ///
93 boolean FfsAttribChecksum = false;
94 ///
95 /// Attribute is used to record the sum of all bit in the output FFS file.
96 ///
97 byte attributes = 0;
98 ///
99 /// The output directory of ffs file.
100 ///
101 String outputDir = "";
102 ///
103 /// List of section.
104 ///
105 List<Object> sectionList = new ArrayList<Object>();
106
107 ///
108 /// The path of Framewor_Tools_Paht.
109 ///
110 static String path = "";
111
112 /**
113 execute
114
115 GenFfsFileTask execute is to generate ffs file according to input section
116 dscriptive information.
117 */
118 public void execute() throws BuildException {
119 Section sect;
120 int fileSize;
121 int fileDataSize;
122 File ffsFile;
123 FfsHeader ffsHeader = new FfsHeader();
124 String ffsSuffix = "";
125 String outputPath = "";
126
127 //
128 // Get Fraemwork_Tools_Path
129 //
130 Project pj = this.getOwningTarget().getProject();
131 path = pj.getProperty("env.Framework_Tools_Path");
132
133 //
134 // Check does the BaseName, Guid, FileType set value.
135 //
136 if (this.baseName.equals("")) {
137 throw new BuildException ("Must set BaseName!\n");
138 }
139
140 if (this.ffsFileGuid.equals("")) {
141 throw new BuildException ("Must set ffsFileGuid!\n");
142 }
143
144 if (this.ffsFileType.equals("")) {
145 throw new BuildException ("Must set ffsFileType!\n");
146 }
147
148 //
149 // Create ffs file. File name = FfsFileGuid + BaseName + ffsSuffix.
150 // If outputDir's value was set, file will output to the outputDir.
151 //
152 ffsSuffix = TypeToSuffix (this.ffsFileType);
153 if (!this.outputDir.equals("")) {
154 String temp;
155 outputPath = this.outputDir;
156 temp = outputPath.replace('\\', File.separatorChar);
157 outputPath = temp.replace('/', File.separatorChar);
158 if (outputPath.charAt(outputPath.length()-1) != File.separatorChar) {
159 outputPath = outputPath + File.separator;
160 }
161
162 }
163
164 ffsFile = new File (outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix);
165 System.out.print("General Ffs file: file name is:\n");
166 System.out.print(outputPath + this.ffsFileGuid + '-' + this.baseName + ffsSuffix);
167 System.out.print("\n");
168
169 //
170 // Create file output stream -- dataBuffer.
171 //
172 try {
173 FileOutputStream dataFs = new FileOutputStream (ffsFile.getAbsolutePath());
174 DataOutputStream dataBuffer = new DataOutputStream (dataFs);
175
176 //
177 // Search SectionList find earch section and call it's
178 // ToBuffer function.
179 //
180 Iterator sectionIter = this.sectionList.iterator();
181 while (sectionIter.hasNext()) {
182 sect = (Section)sectionIter.next();
183
184 try {
185 //
186 // The last section don't need 4 byte ffsAligment.
187 //
188 sect.toBuffer((DataOutputStream)dataBuffer);
189 } catch (Exception e) {
190 throw new BuildException (e.getMessage());
191 }
192 }
193 dataBuffer.close();
194 } catch (Exception e) {
195 throw new BuildException (e.getMessage());
196 }
197
198 //
199 // Creat Ffs file header
200 //
201 try {
202
203 //
204 // create input stream to read file data
205 //
206 byte[] fileBuffer = new byte[(int)ffsFile.length()];
207 FileInputStream fi = new FileInputStream (ffsFile.getAbsolutePath());
208 DataInputStream di = new DataInputStream (fi);
209 di.read(fileBuffer);
210 di.close();
211
212
213 //
214 // Add GUID to header struct
215 //
216 if (this.ffsFileGuid != null) {
217 stringToGuid (this.ffsFileGuid, ffsHeader.name);
218 }
219
220 ffsHeader.ffsAttributes = this.attributes;
221 if ((ffsHeader.fileType = stringToType(this.ffsFileType))== -1) {
222 throw new BuildException ("FFS_FILE_TYPE unknow!\n");
223 }
224
225
226 //
227 // Adjust file size. The function is used to tripe the last
228 // section padding of 4 binary boundary.
229 //
230 //
231 if (ffsHeader.fileType != EFI_FV_FILETYPE_RAW) {
232
233 fileDataSize = adjustFileSize (fileBuffer);
234
235 } else {
236 fileDataSize = fileBuffer.length;
237 }
238
239 //
240 // 1. add header size to file size
241 //
242 fileSize = fileDataSize + ffsHeader.getSize();
243
244 if ((ffsHeader.ffsAttributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {
245 if (ffsHeader.fileType == EFI_FV_FILETYPE_FFS_PAD) {
246
247 throw new BuildException (
248 "FFS_ATTRIB_TAIL_PRESENT=TRUE is " +
249 "invalid for PAD files"
250 );
251 }
252 if (fileSize == ffsHeader.getSize()) {
253 throw new BuildException (
254 "FFS_ATTRIB_TAIL_PRESENT=TRUE is " +
255 "invalid for 0-length files"
256 );
257 }
258 fileSize = fileSize + 2;
259 }
260
261 //
262 // 2. set file size to header struct
263 //
264 ffsHeader.ffsFileSize[0] = (byte)(fileSize & 0x00FF);
265 ffsHeader.ffsFileSize[1] = (byte)((fileSize & 0x00FF00)>>8);
266 ffsHeader.ffsFileSize[2] = (byte)(((int)fileSize & 0xFF0000)>>16);
267
268 //
269 // Fill in checksums and state, these must be zero for checksumming
270 //
271 ffsHeader.integrityCheck.header = calculateChecksum8 (
272 ffsHeader.structToBuffer(),
273 ffsHeader.getSize()
274 );
275
276 if ((this.attributes & FFS_ATTRIB_CHECKSUM) != 0) {
277 if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {
278 ffsHeader.integrityCheck.file = calculateChecksum8 (
279 fileBuffer,
280 fileDataSize
281 );
282 } else {
283 ffsHeader.integrityCheck.file = calculateChecksum8 (
284 fileBuffer,
285 fileDataSize
286 );
287 }
288 } else {
289 ffsHeader.integrityCheck.file = FFS_FIXED_CHECKSUM;
290 }
291
292 //
293 // Set the state now. Spec says the checksum assumes the state is 0.
294 //
295 ffsHeader.ffsState = EFI_FILE_HEADER_CONSTRUCTION |
296 EFI_FILE_HEADER_VALID |
297 EFI_FILE_DATA_VALID;
298
299
300 //
301 // create output stream to first write header data in file, then write sect data in file.
302 //
303 FileOutputStream headerFfs = new FileOutputStream (ffsFile.getAbsolutePath());
304 DataOutputStream ffsBuffer = new DataOutputStream (headerFfs);
305
306 //
307 // Add header struct and file data to FFS file
308 //
309 ffsBuffer.write(ffsHeader.structToBuffer());
310 for (int i = 0; i< fileDataSize; i++) {
311 ffsBuffer.write(fileBuffer[i]);
312 }
313
314 //
315 // If there is a tail, then set it
316 //
317 if ((this.attributes & FFS_ATTRIB_TAIL_PRESENT) != 0) {
318 short tailValue ;
319 byte [] tailByte = new byte[2];
320
321 //
322 // reverse tailvalue , integritycheck.file as hight byte, and
323 // integritycheck.header as low byte.
324 //
325 tailValue = (short)(ffsHeader.integrityCheck.header & 0xff);
326 tailValue = (short)((tailValue) | ((ffsHeader.integrityCheck.file << 8) & 0xff00));
327 tailValue = (short)~tailValue;
328
329 //
330 // Change short to byte[2]
331 //
332 tailByte[0] = (byte)(tailValue & 0xff);
333 tailByte[1] = (byte)((tailValue & 0xff00)>>8);
334 ffsBuffer.write(tailByte[0]);
335 ffsBuffer.write(tailByte[1]);
336 }
337
338 //
339 // close output stream. Note if don't close output stream
340 // the buffer can't be rewritten to file.
341 //
342 ffsBuffer.close();
343 System.out.print ("Successful create ffs file!\n");
344 } catch (Exception e) {
345 throw new BuildException (e.getMessage());
346 }
347 }
348
349 /**
350 addCompress
351
352 This function is to add compress section to section list.
353 @param compress Section of compress
354 **/
355 public void addCompress(CompressSection compress) {
356 this.sectionList.add(compress);
357 }
358
359 /**
360 addTool
361
362 This function is to add tool section to section list.
363 @param tool Section of tool
364 **/
365 public void addTool(Tool tool) {
366 this.sectionList.add(tool);
367 }
368
369 /**
370 addSectionFile
371
372 This function is to add sectFile section to section list.
373 @param sectFile Section of sectFile.
374 **/
375 public void addSectFile (SectFile sectFile) {
376 this.sectionList.add(sectFile);
377 }
378
379 /**
380 getBaseName
381
382 This function is to get basename
383
384 @return String of base name
385 **/
386 public String getBaseName() {
387 return this.baseName;
388 }
389
390 /**
391 setBaseName
392
393 This function is to set base name.
394 @param baseName
395 **/
396 public void setBaseName(String baseName) {
397 this.baseName = baseName.trim();
398 }
399
400 /**
401 getFfsAligment
402
403 This function is to get the ffsAligment
404 @return The value of ffsAligment.
405 **/
406 public int getFfsAligment() {
407 return this.ffsAlignment;
408 }
409
410 /**
411 setFfsAligment
412
413 This function is to set ffsAligment
414 @param ffsAligment The value of ffsAligment.
415 **/
416 public void setFfsAligment(int ffsAligment) {
417 this.ffsAlignment = ffsAligment;
418 if (this.ffsAlignment > 7) {
419 throw new BuildException ("FFS_ALIGMENT Scope is 0-7");
420 } else {
421 attributes |= (((byte)this.ffsAlignment) << 3);
422 }
423 }
424
425 /**
426 getFfsAttribCheckSum
427
428 This function is to get ffsAttribCheckSum
429
430 @return Value of ffsAttribChecksum
431 **/
432 public boolean getFfsAttribChecksum() {
433 return this.FfsAttribChecksum;
434 }
435
436 /**
437 setFfsAttribChecksum
438
439 This function is to set ffsAttribChecksum
440 @param ffsAttributeCheckSum Value of ffsAttribCheckSum
441 **/
442 public void setFfsAttribChecksum(boolean ffsAttributeCheckSum) {
443 this.FfsAttribChecksum = ffsAttributeCheckSum;
444 if (ffsAttributeCheckSum) {
445 attributes |= FFS_ATTRIB_CHECKSUM;
446 }
447 }
448
449 /**
450 getFfsAttribRecovery
451
452 This function is to get ffsAttribRecovery
453 @return Value of ffsAttribRecovery
454 **/
455 public boolean getFfsAttribRecovery() {
456 return this.ffsAttribRecovery;
457 }
458
459 /**
460 setRecovery
461
462 This function is to set ffsAttributeRecovery
463
464 @param ffsAttributeRecovery Value of ffsAttributeRecovery
465 **/
466 public void setRecovery(boolean ffsAttributeRecovery) {
467 this.ffsAttribRecovery = ffsAttributeRecovery;
468 if (ffsAttributeRecovery) {
469 attributes |= FFS_ATTRIB_RECOVERY;
470 }
471 }
472
473 /**
474 getFileGuid
475
476 This function is to get fileGuid
477 @return Guid
478 **/
479 public String getFileGuid() {
480 return this.ffsFileGuid;
481 }
482
483 /**
484 setFileGuid
485
486 This function is to set fileGuid
487 @param ffsFileGuid String of GUID
488 **/
489 public void setFileGuid(String ffsFileGuid) {
490 this.ffsFileGuid = ffsFileGuid.trim();
491 }
492
493 /**
494 getFfsFileType
495
496 This function is to get ffsFileType.
497
498 @return value of ffsFileType
499 **/
500 public String getFfsFileType() {
501 return this.ffsFileType;
502 }
503
504 /**
505 setFfsFileType
506
507 This function is to set ffsFileType.
508
509 @param ffsFileType
510 **/
511 public void setFfsFileType(String ffsFileType) {
512 this.ffsFileType = ffsFileType.trim();
513 }
514
515 /**
516 ffsAttribHeaderExtension
517
518 This function is to get ffsAttribHeaderExtension
519
520 @return Value of ffsAttribHeaderExtension
521 **/
522 public boolean isFfsAttribHeaderExtension() {
523 return this.ffsAttribHeaderExtension;
524 }
525
526 /**
527 setHeaderExension
528
529 This function is to set headerExtension
530 @param headerExtension Value of headerExension
531 **/
532 public void setHeaderExtension(boolean headerExtension) {
533 this.ffsAttribHeaderExtension = headerExtension;
534 if (headerExtension) {
535 attributes |= FFS_ATTRIB_HEADER_EXTENSION;
536 }
537 }
538
539 /**
540 isFfsAttribTailPresent
541
542 This function is to get ffsAttribTailPresent value.
543 @return Value of ffsAttribTailPresent.
544 **/
545 public boolean isFfsAttribTailPresent() {
546 return this.ffsAttribTailPresent;
547 }
548
549 /**
550 setFfsAttribTailPresent
551
552 This function is to set ffsAttribTailPresent.
553 @param tailPresent Value of ffsAttribTailPresent.
554 **/
555 public void setFfsAttribTailPresent(boolean tailPresent) {
556 this.ffsAttribTailPresent = tailPresent;
557 if (tailPresent) {
558 attributes |= FFS_ATTRIB_TAIL_PRESENT;
559 }
560 }
561
562
563 /**
564 stringToGuid
565
566 This function is to convert string to GUID.
567 * @param GuidStr String of GUID.
568 * @param Guid GUID form.
569 */
570 private void stringToGuid (String GuidStr, FfsHeader.FfsGuid Guid){
571
572 int i = 0;
573 int j = 0;
574 int k = 0;
575 char [] charArry;
576 String [] SplitStr;
577
578 byte[] buffer = new byte[16];
579 if (GuidStr.length()!=36) {
580 throw new BuildException ("Guid length is not correct!");
581 }
582
583
584 SplitStr = GuidStr.split("-");
585 if (SplitStr.length != 5) {
586 throw new BuildException ("Guid type is not correct!");
587 }
588
589
590
591 for (i= 0; i < SplitStr.length; i++) {
592 String str = SplitStr[i];
593 charArry = str.toCharArray();
594
595 for (j =0; j < (str.toCharArray().length)/2; j++) {
596
597 buffer[k] = hexCharToByte (charArry[j*2]);
598 buffer[k] = (byte)( buffer[k]& 0x0f);
599 buffer[k] = (byte)((buffer[k]<< 4));
600 buffer[k] = (byte)( buffer[k]& 0xf0);
601 buffer[k] = (byte)( buffer[k]|hexCharToByte(charArry[j*2+1]));
602 k++;
603 }
604 }
605 Guid.bufferToStruct(buffer);
606 }
607
608 /**
609 typeToSuffix
610
611 This function is to get suffix of ffs file according to ffsFileType.
612
613 @param ffsFileType ffsFileType
614 @return The suffix of ffs file
615 **/
616 private String TypeToSuffix (String ffsFileType){
617 if (ffsFileType.equals("EFI_FV_FILETYPE_ALL")) {
618 return "";
619 }
620 if (ffsFileType.equals("EFI_FV_FILETYPE_RAW")) {
621 return EFI_FV_FFS_FILETYPE_STR;
622 }
623 if (ffsFileType.equals("EFI_FV_FILETYPE_FREEFORM")) {
624 return EFI_FV_FFS_FILETYPE_STR;
625 }
626 if (ffsFileType.equals("EFI_FV_FILETYPE_SECURITY_CORE")) {
627 return EFI_FV_SEC_FILETYPE_STR;
628 }
629 if (ffsFileType.equals("EFI_FV_FILETYPE_PEI_CORE")) {
630 return EFI_FV_PEI_FILETYPE_STR;
631 }
632 if (ffsFileType.equals("EFI_FV_FILETYPE_DXE_CORE")) {
633 return EFI_FV_DXE_FILETYPE_STR;
634 }
635 if (ffsFileType.equals("EFI_FV_FILETYPE_PEIM")) {
636 return EFI_FV_PEI_FILETYPE_STR;
637 }
638 if (ffsFileType.equals("EFI_FV_FILETYPE_DRIVER")) {
639 return EFI_FV_DXE_FILETYPE_STR;
640 }
641 if (ffsFileType.equals("EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER")) {
642 return EFI_FV_PEI_FILETYPE_STR;
643 }
644 if (ffsFileType.equals("EFI_FV_FILETYPE_APPLICATION")) {
645 return EFI_FV_APP_FILETYPE_STR;
646 }
647 if (ffsFileType.equals("EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE")) {
648 return EFI_FV_FVI_FILETYPE_STR;
649 }
650 if (ffsFileType.equals("EFI_FV_FILETYPE_FFS_PAD")) {
651 return EFI_FV_FFS_FILETYPE_STR;
652 }
653 return "";
654 }
655
656
657 /**
658 stringToType
659
660 This function is to get ffsFileType integer value according to ffsFileType.
661 @param ffsFileType String value of ffsFileType
662 @return Integer value of ffsFileType.
663 **/
664 private byte stringToType (String ffsFileType){
665
666 if (ffsFileType.equals("EFI_FV_FILETYPE_ALL")) {
667 return(byte)EFI_FV_FILETYPE_ALL;
668 }
669
670 if (ffsFileType.equals("EFI_FV_FILETYPE_RAW")) {
671 return(byte)EFI_FV_FILETYPE_RAW;
672 }
673
674 if (ffsFileType.equals("EFI_FV_FILETYPE_FREEFORM")) {
675 return(byte)EFI_FV_FILETYPE_SECURITY_CORE;
676 }
677
678 if (ffsFileType.equals("EFI_FV_FILETYPE_SECURITY_CORE")) {
679 return(byte)EFI_FV_FILETYPE_SECURITY_CORE;
680 }
681
682 if (ffsFileType.equals("EFI_FV_FILETYPE_PEI_CORE")) {
683 return(byte) EFI_FV_FILETYPE_PEI_CORE;
684 }
685
686 if (ffsFileType.equals("EFI_FV_FILETYPE_DXE_CORE")) {
687 return(byte)EFI_FV_FILETYPE_DXE_CORE;
688 }
689
690 if (ffsFileType.equals("EFI_FV_FILETYPE_PEIM")) {
691 return(byte)EFI_FV_FILETYPE_PEIM;
692 }
693
694 if (ffsFileType.equals("EFI_FV_FILETYPE_DRIVER")) {
695 return(byte) EFI_FV_FILETYPE_DRIVER;
696 }
697
698 if (ffsFileType.equals("EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER")) {
699 return(byte)EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER;
700 }
701
702 if (ffsFileType.equals("EFI_FV_FILETYPE_APPLICATION")) {
703 return(byte)EFI_FV_FILETYPE_APPLICATION;
704 }
705
706 if (ffsFileType.equals("EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE")) {
707 return(byte)EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE;
708 }
709 if (ffsFileType.equals("EFI_FV_FILETYPE_FFS_PAD")) {
710 return(byte) EFI_FV_FILETYPE_FFS_PAD;
711 }
712
713 return -1;
714 }
715
716
717
718 /**
719 calculateCheckSum8
720
721 This function is to calculate the value needed for a valid UINT8 checksum
722 @param buffer Byte buffer containing byte data of component.
723 @param size Size of the buffer.
724 @return The 8 bit checksum value needed.
725 **/
726 private byte calculateChecksum8 (byte[] buffer, int size){
727 return(byte) (0x100 - calculateSum8 (buffer, size));
728 }
729
730
731 /**
732 calculateSum8
733
734 This function is to calculate the UINT8 sum for the requested region.
735 @param buffer Byte buffer containing byte data of component
736 @param size Size of the buffer.
737 @return The 8 bit checksum value needed.
738 **/
739 private short calculateSum8 (byte[] buffer, int size){
740 int Index;
741 byte Sum;
742 Sum = 0;
743
744 //
745 // Perform the word sum for buffer
746 //
747 for (Index = 0; Index < size; Index++) {
748 Sum = (byte) (Sum + buffer[Index]);
749 }
750
751 return(byte) Sum;
752 }
753
754 /**
755 hexCharToByte
756
757 This function is to convert hex character to byte
758
759 @param hexChar hex character
760 @return Byte which corresponding to the character.
761 **/
762 private byte hexCharToByte (char hexChar){
763 switch (hexChar) {
764 case '0':
765 return(byte)0x00;
766 case '1':
767 return(byte)0x01;
768 case '2':
769 return(byte)0x02;
770 case '3':
771 return(byte)0x03;
772 case '4':
773 return(byte)0x04;
774 case '5':
775 return(byte)0x05;
776 case '6':
777 return(byte)0x06;
778 case '7':
779 return(byte)0x07;
780 case '8':
781 return(byte)0x08;
782 case '9':
783 return(byte)0x09;
784 case 'a':
785 case 'A':
786 return(byte)0x0a;
787 case 'b':
788 case 'B':
789 return(byte)0x0b;
790 case 'c':
791 case 'C':
792 return(byte)0x0c;
793
794 case 'd':
795 case 'D':
796 return(byte)0x0d;
797
798 case 'e':
799 case 'E':
800 return(byte)0x0e;
801 case 'f':
802 case 'F':
803 return(byte)0x0f;
804
805 default:
806 return(byte)0xff;
807 }
808 }
809
810 /**
811 adjustFileSize
812
813 This function is used to adjusts file size to insure sectioned file is exactly the right length such
814 that it ends on exactly the last byte of the last section. ProcessScript()
815 may have padded beyond the end of the last section out to a 4 byte boundary.
816 This padding is stripped.
817
818 @param buffer Byte buffer contains a section stream
819 @return Corrected size of file.
820 **/
821 private int adjustFileSize (byte[] buffer){
822
823 int orignalLen = buffer.length;
824 int adjustLen = 0;
825 int sectionPoint = 0;
826 int nextSectionPoint = 0;
827 int sectionLen = 0;
828 int totalLen = 0;
829 int firstSectionHeader = 0;
830
831
832 firstSectionHeader = buffer[0]& 0xff;
833 firstSectionHeader = ((buffer[1]&0xff)<<8) | firstSectionHeader;
834 firstSectionHeader = ((buffer[2]&0xff)<<16)| firstSectionHeader;
835
836
837 while (sectionPoint < buffer.length) {
838 sectionLen = buffer[0 + sectionPoint]& 0xff;
839 sectionLen = ((buffer[1 + sectionPoint]&0xff)<<8)| sectionLen;
840 sectionLen = ((buffer[2 + sectionPoint]&0xff)<<16)| sectionLen;
841 totalLen = totalLen + sectionLen;
842
843 if (totalLen == orignalLen) {
844 return totalLen;
845 }
846
847 sectionPoint = sectionPoint + sectionLen;
848 adjustLen = sectionPoint;
849
850 nextSectionPoint = (sectionPoint + 0x03) & (~0x03);
851 totalLen = totalLen + nextSectionPoint - sectionLen;
852 sectionPoint = nextSectionPoint;
853 }
854 return adjustLen;
855 }
856
857 /**
858 getOutputDir
859
860 This function is to get output directory.
861
862 @return Path of output directory.
863 **/
864 public String getOutputDir() {
865 return outputDir;
866 }
867
868 /**
869 setOutputDir
870
871 This function is to set output directory.
872
873 @param outputDir The output direcotry.
874 **/
875 public void setOutputDir(String outputDir) {
876 this.outputDir = outputDir;
877 }
878 }