From: <in...@us...> - 2002-05-26 10:14:05
|
Update of /cvsroot/mingw/utils/res2coff In directory usw-pr-cvs1:/tmp/cvs-serv2405/res2coff Modified Files: objimage.c protos.h readme.1st res2coff.c res2coff.h resimage.c Log Message: Convert some text files to Unix format Index: objimage.c =================================================================== RCS file: /cvsroot/mingw/utils/res2coff/objimage.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** objimage.c 14 May 2002 20:38:30 -0000 1.1 --- objimage.c 26 May 2002 10:13:58 -0000 1.2 *************** *** 1,385 **** ! /* ********************************************* ! * ! * res2coff : Functions dealing with the creation ! * of a .o file image in memory before ! * writing it out ! * ! */ ! ! #include "res2coff.h" ! #include <stdlib.h> ! ! ! /* ! * return the offset of the string we just added ! * into the string table or -1 if error ! * strings are DWORD aligned ! */ ! ! int Add2StringTable(wchar_t *NewString) ! { ! int result = Strings.Size; ! int strlen = lstrlenW(NewString); ! int i,addsize; ! wchar_t *p1,*p2; ! ! addsize = (strlen+2) * sizeof(wchar_t); ! if (addsize % sizeof(DWORD)) ! addsize += sizeof(wchar_t); ! ! Strings.Image = realloc(Strings.Image,result+addsize); ! if (Strings.Image == NULL) ! AppExit(1,"Out of memory for the string table\n",NULL); ! ! p1 = NewString; ! p2 = (wchar_t *)((BYTE *)Strings.Image+result); ! *p2++ = (wchar_t)strlen; ! ! for (i=0;i < strlen;i++) ! *p2++ = *p1++; ! *p2 = L'\0'; ! Strings.Size +=addsize; ! return result; ! } ! ! // Append a MemImage to another MemImage ! int AppendMemImage(MemImage *membase,MemImage *memappend) ! { ! char *p1,*p2; ! int i; ! ! membase->Image = realloc(membase->Image,membase->Size+memappend->Size); ! ! if (membase->Image == NULL) ! AppExit(1,"Error reallocating MemImage!\n",NULL); ! ! p1 = (char *)memappend->Image; ! p2 = (char *)(membase->Image)+membase->Size; ! ! for(i=0;i<memappend->Size;i++) ! *p2++ = *p1++; ! ! membase->Size += memappend->Size; ! return TRUE; ! } ! ! // Add an entry to the relocation table ! int AddRelocation(int RVA) ! { ! int last,newsize,*pReloc; ! ! last = RelocTable.nElems++; ! newsize = RelocTable.nElems * sizeof(int); ! pReloc = RelocTable.pElems = realloc(RelocTable.pElems,newsize); ! if (pReloc == NULL) ! AppExit(1,"Out of memory for relocations\n",NULL); ! pReloc[last] = RVA ; ! return TRUE; ! } ! ! // Create the directory tree and other related chunks ! ! int MakeDirectoryTree(void) ! { ! PIMAGE_RESOURCE_DIRECTORY RD; ! PIMAGE_RESOURCE_DIRECTORY_ENTRY RDE; ! PIMAGE_RESOURCE_DATA_ENTRY RPR; ! ! int i,j,ThisOffset,ResSize; ! ! int types = 0; ! int ResPointOffs = 0; ! int ResourceOffs = 0; ! int PhantomID = 100; ! ! // we start by calculating the amount of memory we are ! // going to need in the directory image and the resource pointers ! ! ResourceHeads.Size = 0; ! Directory.Size = sizeof(IMAGE_RESOURCE_DIRECTORY); // in the root ! for (i=1;i<17;i++) ! if (ResInfo[i].count) { ! types++; ! Directory.Size += sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); // in the root ! // resource types ! Directory.Size += sizeof(IMAGE_RESOURCE_DIRECTORY); ! Directory.Size += ResInfo[i].count * ! sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); ! // individual resources ! Directory.Size += ResInfo[i].count * ! sizeof(IMAGE_RESOURCE_DIRECTORY); ! Directory.Size += ResInfo[i].count * ! sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); ! // ! // reserve also for the Resource Pointer Records ! // ! ResourceHeads.Size += ResInfo[i].count * ! sizeof(IMAGE_RESOURCE_DATA_ENTRY); ! } ! ! if (types == 0) ! AppExit(1,"ERROR: no resources in RES file ?!?!\n",NULL); ! ! Directory.Image = malloc(Directory.Size); ! if (Directory.Image == NULL) ! AppExit(1,"Out of memory for the directory\n",NULL); ! ! ResourceHeads.Image = malloc(ResourceHeads.Size); ! if (ResourceHeads.Image == NULL) ! AppExit(1,"Out of memory for the resource headers\n",NULL); ! ! RPR = (PIMAGE_RESOURCE_DATA_ENTRY)ResourceHeads.Image; ! ! // Root Directory ! ! RD = (PIMAGE_RESOURCE_DIRECTORY)Directory.Image; ! RD -> Characteristics = 0; ! RD -> TimeStamp = ResourceTime; ! RD -> MajorVersion = DECLARED_MAV; ! RD -> MinorVersion = DECLARED_MIV; ! RD -> NumberOfNamedEntries = 0; ! RD -> NumberOfIdEntries = types; ! ! RD++; ! RDE = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) RD; ! ThisOffset = sizeof(IMAGE_RESOURCE_DIRECTORY) + ! types * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); ! ! // Root directory entries are pointers to directories ! // of types ! ! for (i=1;i<17;i++) ! if (ResInfo[i].count) { ! RDE->Name = i; ! RDE->OffsetToData = ThisOffset | IMAGE_RESOURCE_DATA_IS_DIRECTORY ; ! RDE++; ! ThisOffset += sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY) * ResInfo[i].count + ! sizeof(IMAGE_RESOURCE_DIRECTORY); ! } ! ! // Now the directories of types ! // ThisOffset is pointing at the storage area for the last directory level ! // each Directory there will point to one and only one resource ! ! RD = (PIMAGE_RESOURCE_DIRECTORY)Directory.Image; ! RD++; ! RDE = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)RD; ! for (i=0;i<types;i++) { ! int RDNum = RDE->Name & 0x7fffffff; ! int RDOfs = RDE->OffsetToData & 0x7fffffff; ! PIMAGE_RESOURCE_DIRECTORY_ENTRY RDENext; ! ! RD = (PIMAGE_RESOURCE_DIRECTORY)((BYTE *)Directory.Image + RDOfs); ! ! RD -> Characteristics = 0; ! RD -> TimeStamp = ResourceTime; ! RD -> MajorVersion = DECLARED_MAV; ! RD -> MinorVersion = DECLARED_MIV; ! RD -> NumberOfNamedEntries = ResInfo[RDNum].named; ! RD -> NumberOfIdEntries = ResInfo[RDNum].unnamed; ! RD++; ! ! RDENext = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)RD; ! for (j=0;j<ResInfo[RDNum].count;j++) { ! PIMAGE_RESOURCE_DIRECTORY RDLast; ! PIMAGE_RESOURCE_DIRECTORY_ENTRY RDELast; ! PRESOURCEHEAD *pThisResource; ! ! if (j==0) ! pThisResource = ResInfo[RDNum].RName; ! if (j == ResInfo[RDNum].named) ! pThisResource = ResInfo[RDNum].RID; ! ! if (j < ResInfo[RDNum].named) { ! wchar_t *NameInRES; ! int NameOfs; ! ! NameInRES = ResName(*pThisResource); ! NameOfs = Add2StringTable(NameInRES); ! NameOfs += Directory.Size+ResourceHeads.Size; ! RDENext->Name = NameOfs | IMAGE_RESOURCE_NAME_IS_STRING; ! } else { ! wchar_t *NameID = ResName(*pThisResource); ! if (*NameID == 0xffff) { ! PhantomID = (int)*(++NameID); ! RDENext->Name = PhantomID++; ! } else { ! AppExit(1,"Unnamed resource has no ID field",NULL); ! } ! } ! ! RDENext->OffsetToData = ThisOffset | IMAGE_RESOURCE_DATA_IS_DIRECTORY; ! ! RDLast = (PIMAGE_RESOURCE_DIRECTORY) ! ((BYTE *)Directory.Image+ThisOffset); ! ! ThisOffset += sizeof(IMAGE_RESOURCE_DIRECTORY); ! ! RDLast -> Characteristics = 0; ! RDLast -> TimeStamp = ResourceTime; ! RDLast -> MajorVersion = DECLARED_MAV; ! RDLast -> MinorVersion = DECLARED_MIV; ! RDLast -> NumberOfNamedEntries = 0; ! RDLast -> NumberOfIdEntries = 1; ! ! RDELast = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) ! ((BYTE *)Directory.Image+ThisOffset); ! ! ThisOffset += sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); ! RDELast->Name = PhantomID++; ! RDELast->OffsetToData = Directory.Size+ResPointOffs; ! ResSize = (*pThisResource)->DataSize; ! ! RPR -> OffsetToData = ResourceOffs; ! RPR -> Size = ResSize; ! RPR -> CodePage = LanguageID(*pThisResource); ! RPR -> Reserved = 0; ! ! RPR++; ! RDENext++; ! ResPointOffs += sizeof(IMAGE_RESOURCE_DATA_ENTRY); ! ResourceOffs += ResSize; ! pThisResource++; ! } ! RDE++; ! } ! ! ResourceSize = ResourceOffs; ! ! RPR = (PIMAGE_RESOURCE_DATA_ENTRY)ResourceHeads.Image; ! for (i=0;i<17;i++) { ! for( j=0;j<ResInfo[i].count;j++) { ! LPVOID RelocPos; ! ! /* ! * The data is situated after the directory, the resourceheads ! * and the strings ! */ ! RPR->OffsetToData += Directory.Size+ResourceHeads.Size+Strings.Size; ! /* ! * the resource heads, where the relocations have to take place, ! * are just after the directory ! */ ! RelocPos = (LPVOID)(&RPR->OffsetToData); ! AddRelocation((int)((BYTE *)Directory.Size - ! (BYTE *)ResourceHeads.Image + ! (BYTE *)RelocPos)); ! ! RPR++; ! } ! } ! ! // Finally we put all 'subsections' or chunks together ! ! if (AppendMemImage(&Directory,&ResourceHeads) == FALSE) ! return FALSE; ! ! if (AppendMemImage(&Directory,&Strings) == FALSE) ! return FALSE; ! ! return TRUE; ! } ! ! void DumpResource(HANDLE ofile,PRESOURCEHEAD this) ! { ! BYTE *buffer = (BYTE *)this; ! ! buffer += this->HeaderSize; ! CheckedWrite(ofile,buffer,this->DataSize,"resources"); ! } ! ! void DumpResources(HANDLE ofile) ! { ! int i,j; ! ! for (i=1;i<17;i++) { ! for (j=0;j < ResInfo[i].named;j++) ! DumpResource(ofile,ResInfo[i].RName[j]); ! ! for (j=0;j < ResInfo[i].unnamed;j++) ! DumpResource(ofile,ResInfo[i].RID[j]); ! } ! } ! ! void DumpDirectoryImage(HANDLE ofile) ! { ! CheckedWrite(ofile,Directory.Image,Directory.Size,"resource directory"); ! } ! ! /* Dump all relocations */ ! ! void DumpRelocations(HANDLE ofile) ! { ! ! /* ! * The relocation type is 32 bits absolute without ! * base reference. The smbols referenced is the ! * section start, which is the first element of ! * the symbols table. ! */ ! ! IMAGE_RELOCATION RelocBuffer = { 0,0,IMAGE_REL_I386_DIR32NB}; ! int i,*relocs; ! ! relocs = (int *)RelocTable.pElems; ! for (i=0;i<RelocTable.nElems;i++) { ! RelocBuffer.VirtualAddress = relocs[i]; ! CheckedWrite(ofile,(LPVOID)(&RelocBuffer),10,"relocations"); ! } ! } ! ! void DumpSymbols(HANDLE ofile) ! { ! IMAGE_SYMBOL NewSym; ! IMAGE_AUX_SYMBOL SecSym; ! ! memset(&NewSym,0,IMAGE_SIZEOF_SYMBOL); ! memset(&SecSym,0,IMAGE_SIZEOF_SYMBOL); ! ! lstrcpyA(NewSym.N.ShortName,".rsrc"); ! NewSym.Value = 0; ! NewSym.SectionNumber = 1; ! NewSym.Type = 0; ! NewSym.StorageClass = 3; ! NewSym.NumberOfAuxSymbols = 1; ! ! SecSym.Section.Length = ResourceSize+Directory.Size; ! SecSym.Section.NumberOfRelocations = RelocTable.nElems; ! ! CheckedWrite(ofile,&NewSym,IMAGE_SIZEOF_SYMBOL,"symbols"); ! CheckedWrite(ofile,&SecSym,IMAGE_SIZEOF_SYMBOL,"symbols"); ! } ! ! void MakeCOFFSections(HANDLE ofile) ! { ! IMAGE_FILE_HEADER fileheader; ! IMAGE_SECTION_HEADER RSRChdr; ! ! lstrcpyA(RSRChdr.Name,".rsrc"); ! RSRChdr.Misc.PhysicalAddress = 0; ! RSRChdr.VirtualAddress = 0; ! RSRChdr.SizeOfRawData = ResourceSize+Directory.Size; ! RSRChdr.PointerToRawData = IMAGE_SIZEOF_FILE_HEADER + ! IMAGE_SIZEOF_SECTION_HEADER; ! RSRChdr.PointerToRelocations = RSRChdr.SizeOfRawData + ! RSRChdr.PointerToRawData; ! RSRChdr.PointerToLinenumbers = 0; ! RSRChdr.NumberOfRelocations = RelocTable.nElems; ! RSRChdr.NumberOfLinenumbers = 0; ! RSRChdr.Characteristics = IMAGE_SCN_MEM_READ ! /* | IMAGE_SCN_MEM_WRITE */; ! ! fileheader.Machine = IMAGE_FILE_MACHINE_I386; ! fileheader.NumberOfSections = 1; ! fileheader.TimeDateStamp = ResourceTime; ! fileheader.PointerToSymbolTable = RSRChdr.PointerToRelocations+ ! RelocTable.nElems * 10; ! fileheader.NumberOfSymbols = 2; ! fileheader.SizeOfOptionalHeader = 0; ! fileheader.Characteristics = IMAGE_FILE_LINE_NUMS_STRIPPED | ! IMAGE_FILE_32BIT_MACHINE; ! ! CheckedWrite(ofile,&fileheader,IMAGE_SIZEOF_FILE_HEADER,"COFF file header"); ! CheckedWrite(ofile,&RSRChdr,IMAGE_SIZEOF_SECTION_HEADER,".rsrc section header"); ! } ! --- 1,385 ---- ! /* ********************************************* ! * ! * res2coff : Functions dealing with the creation ! * of a .o file image in memory before ! * writing it out ! * ! */ ! ! #include "res2coff.h" ! #include <stdlib.h> ! ! ! /* ! * return the offset of the string we just added ! * into the string table or -1 if error ! * strings are DWORD aligned ! */ ! ! int Add2StringTable(wchar_t *NewString) ! { ! int result = Strings.Size; ! int strlen = lstrlenW(NewString); ! int i,addsize; ! wchar_t *p1,*p2; ! ! addsize = (strlen+2) * sizeof(wchar_t); ! if (addsize % sizeof(DWORD)) ! addsize += sizeof(wchar_t); ! ! Strings.Image = realloc(Strings.Image,result+addsize); ! if (Strings.Image == NULL) ! AppExit(1,"Out of memory for the string table\n",NULL); ! ! p1 = NewString; ! p2 = (wchar_t *)((BYTE *)Strings.Image+result); ! *p2++ = (wchar_t)strlen; ! ! for (i=0;i < strlen;i++) ! *p2++ = *p1++; ! *p2 = L'\0'; ! Strings.Size +=addsize; ! return result; ! } ! ! // Append a MemImage to another MemImage ! int AppendMemImage(MemImage *membase,MemImage *memappend) ! { ! char *p1,*p2; ! int i; ! ! membase->Image = realloc(membase->Image,membase->Size+memappend->Size); ! ! if (membase->Image == NULL) ! AppExit(1,"Error reallocating MemImage!\n",NULL); ! ! p1 = (char *)memappend->Image; ! p2 = (char *)(membase->Image)+membase->Size; ! ! for(i=0;i<memappend->Size;i++) ! *p2++ = *p1++; ! ! membase->Size += memappend->Size; ! return TRUE; ! } ! ! // Add an entry to the relocation table ! int AddRelocation(int RVA) ! { ! int last,newsize,*pReloc; ! ! last = RelocTable.nElems++; ! newsize = RelocTable.nElems * sizeof(int); ! pReloc = RelocTable.pElems = realloc(RelocTable.pElems,newsize); ! if (pReloc == NULL) ! AppExit(1,"Out of memory for relocations\n",NULL); ! pReloc[last] = RVA ; ! return TRUE; ! } ! ! // Create the directory tree and other related chunks ! ! int MakeDirectoryTree(void) ! { ! PIMAGE_RESOURCE_DIRECTORY RD; ! PIMAGE_RESOURCE_DIRECTORY_ENTRY RDE; ! PIMAGE_RESOURCE_DATA_ENTRY RPR; ! ! int i,j,ThisOffset,ResSize; ! ! int types = 0; ! int ResPointOffs = 0; ! int ResourceOffs = 0; ! int PhantomID = 100; ! ! // we start by calculating the amount of memory we are ! // going to need in the directory image and the resource pointers ! ! ResourceHeads.Size = 0; ! Directory.Size = sizeof(IMAGE_RESOURCE_DIRECTORY); // in the root ! for (i=1;i<17;i++) ! if (ResInfo[i].count) { ! types++; ! Directory.Size += sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); // in the root ! // resource types ! Directory.Size += sizeof(IMAGE_RESOURCE_DIRECTORY); ! Directory.Size += ResInfo[i].count * ! sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); ! // individual resources ! Directory.Size += ResInfo[i].count * ! sizeof(IMAGE_RESOURCE_DIRECTORY); ! Directory.Size += ResInfo[i].count * ! sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); ! // ! // reserve also for the Resource Pointer Records ! // ! ResourceHeads.Size += ResInfo[i].count * ! sizeof(IMAGE_RESOURCE_DATA_ENTRY); ! } ! ! if (types == 0) ! AppExit(1,"ERROR: no resources in RES file ?!?!\n",NULL); ! ! Directory.Image = malloc(Directory.Size); ! if (Directory.Image == NULL) ! AppExit(1,"Out of memory for the directory\n",NULL); ! ! ResourceHeads.Image = malloc(ResourceHeads.Size); ! if (ResourceHeads.Image == NULL) ! AppExit(1,"Out of memory for the resource headers\n",NULL); ! ! RPR = (PIMAGE_RESOURCE_DATA_ENTRY)ResourceHeads.Image; ! ! // Root Directory ! ! RD = (PIMAGE_RESOURCE_DIRECTORY)Directory.Image; ! RD -> Characteristics = 0; ! RD -> TimeStamp = ResourceTime; ! RD -> MajorVersion = DECLARED_MAV; ! RD -> MinorVersion = DECLARED_MIV; ! RD -> NumberOfNamedEntries = 0; ! RD -> NumberOfIdEntries = types; ! ! RD++; ! RDE = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) RD; ! ThisOffset = sizeof(IMAGE_RESOURCE_DIRECTORY) + ! types * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); ! ! // Root directory entries are pointers to directories ! // of types ! ! for (i=1;i<17;i++) ! if (ResInfo[i].count) { ! RDE->Name = i; ! RDE->OffsetToData = ThisOffset | IMAGE_RESOURCE_DATA_IS_DIRECTORY ; ! RDE++; ! ThisOffset += sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY) * ResInfo[i].count + ! sizeof(IMAGE_RESOURCE_DIRECTORY); ! } ! ! // Now the directories of types ! // ThisOffset is pointing at the storage area for the last directory level ! // each Directory there will point to one and only one resource ! ! RD = (PIMAGE_RESOURCE_DIRECTORY)Directory.Image; ! RD++; ! RDE = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)RD; ! for (i=0;i<types;i++) { ! int RDNum = RDE->Name & 0x7fffffff; ! int RDOfs = RDE->OffsetToData & 0x7fffffff; ! PIMAGE_RESOURCE_DIRECTORY_ENTRY RDENext; ! ! RD = (PIMAGE_RESOURCE_DIRECTORY)((BYTE *)Directory.Image + RDOfs); ! ! RD -> Characteristics = 0; ! RD -> TimeStamp = ResourceTime; ! RD -> MajorVersion = DECLARED_MAV; ! RD -> MinorVersion = DECLARED_MIV; ! RD -> NumberOfNamedEntries = ResInfo[RDNum].named; ! RD -> NumberOfIdEntries = ResInfo[RDNum].unnamed; ! RD++; ! ! RDENext = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)RD; ! for (j=0;j<ResInfo[RDNum].count;j++) { ! PIMAGE_RESOURCE_DIRECTORY RDLast; ! PIMAGE_RESOURCE_DIRECTORY_ENTRY RDELast; ! PRESOURCEHEAD *pThisResource; ! ! if (j==0) ! pThisResource = ResInfo[RDNum].RName; ! if (j == ResInfo[RDNum].named) ! pThisResource = ResInfo[RDNum].RID; ! ! if (j < ResInfo[RDNum].named) { ! wchar_t *NameInRES; ! int NameOfs; ! ! NameInRES = ResName(*pThisResource); ! NameOfs = Add2StringTable(NameInRES); ! NameOfs += Directory.Size+ResourceHeads.Size; ! RDENext->Name = NameOfs | IMAGE_RESOURCE_NAME_IS_STRING; ! } else { ! wchar_t *NameID = ResName(*pThisResource); ! if (*NameID == 0xffff) { ! PhantomID = (int)*(++NameID); ! RDENext->Name = PhantomID++; ! } else { ! AppExit(1,"Unnamed resource has no ID field",NULL); ! } ! } ! ! RDENext->OffsetToData = ThisOffset | IMAGE_RESOURCE_DATA_IS_DIRECTORY; ! ! RDLast = (PIMAGE_RESOURCE_DIRECTORY) ! ((BYTE *)Directory.Image+ThisOffset); ! ! ThisOffset += sizeof(IMAGE_RESOURCE_DIRECTORY); ! ! RDLast -> Characteristics = 0; ! RDLast -> TimeStamp = ResourceTime; ! RDLast -> MajorVersion = DECLARED_MAV; ! RDLast -> MinorVersion = DECLARED_MIV; ! RDLast -> NumberOfNamedEntries = 0; ! RDLast -> NumberOfIdEntries = 1; ! ! RDELast = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) ! ((BYTE *)Directory.Image+ThisOffset); ! ! ThisOffset += sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY); ! RDELast->Name = PhantomID++; ! RDELast->OffsetToData = Directory.Size+ResPointOffs; ! ResSize = (*pThisResource)->DataSize; ! ! RPR -> OffsetToData = ResourceOffs; ! RPR -> Size = ResSize; ! RPR -> CodePage = LanguageID(*pThisResource); ! RPR -> Reserved = 0; ! ! RPR++; ! RDENext++; ! ResPointOffs += sizeof(IMAGE_RESOURCE_DATA_ENTRY); ! ResourceOffs += ResSize; ! pThisResource++; ! } ! RDE++; ! } ! ! ResourceSize = ResourceOffs; ! ! RPR = (PIMAGE_RESOURCE_DATA_ENTRY)ResourceHeads.Image; ! for (i=0;i<17;i++) { ! for( j=0;j<ResInfo[i].count;j++) { ! LPVOID RelocPos; ! ! /* ! * The data is situated after the directory, the resourceheads ! * and the strings ! */ ! RPR->OffsetToData += Directory.Size+ResourceHeads.Size+Strings.Size; ! /* ! * the resource heads, where the relocations have to take place, ! * are just after the directory ! */ ! RelocPos = (LPVOID)(&RPR->OffsetToData); ! AddRelocation((int)((BYTE *)Directory.Size - ! (BYTE *)ResourceHeads.Image + ! (BYTE *)RelocPos)); ! ! RPR++; ! } ! } ! ! // Finally we put all 'subsections' or chunks together ! ! if (AppendMemImage(&Directory,&ResourceHeads) == FALSE) ! return FALSE; ! ! if (AppendMemImage(&Directory,&Strings) == FALSE) ! return FALSE; ! ! return TRUE; ! } ! ! void DumpResource(HANDLE ofile,PRESOURCEHEAD this) ! { ! BYTE *buffer = (BYTE *)this; ! ! buffer += this->HeaderSize; ! CheckedWrite(ofile,buffer,this->DataSize,"resources"); ! } ! ! void DumpResources(HANDLE ofile) ! { ! int i,j; ! ! for (i=1;i<17;i++) { ! for (j=0;j < ResInfo[i].named;j++) ! DumpResource(ofile,ResInfo[i].RName[j]); ! ! for (j=0;j < ResInfo[i].unnamed;j++) ! DumpResource(ofile,ResInfo[i].RID[j]); ! } ! } ! ! void DumpDirectoryImage(HANDLE ofile) ! { ! CheckedWrite(ofile,Directory.Image,Directory.Size,"resource directory"); ! } ! ! /* Dump all relocations */ ! ! void DumpRelocations(HANDLE ofile) ! { ! ! /* ! * The relocation type is 32 bits absolute without ! * base reference. The smbols referenced is the ! * section start, which is the first element of ! * the symbols table. ! */ ! ! IMAGE_RELOCATION RelocBuffer = { 0,0,IMAGE_REL_I386_DIR32NB}; ! int i,*relocs; ! ! relocs = (int *)RelocTable.pElems; ! for (i=0;i<RelocTable.nElems;i++) { ! RelocBuffer.VirtualAddress = relocs[i]; ! CheckedWrite(ofile,(LPVOID)(&RelocBuffer),10,"relocations"); ! } ! } ! ! void DumpSymbols(HANDLE ofile) ! { ! IMAGE_SYMBOL NewSym; ! IMAGE_AUX_SYMBOL SecSym; ! ! memset(&NewSym,0,IMAGE_SIZEOF_SYMBOL); ! memset(&SecSym,0,IMAGE_SIZEOF_SYMBOL); ! ! lstrcpyA(NewSym.N.ShortName,".rsrc"); ! NewSym.Value = 0; ! NewSym.SectionNumber = 1; ! NewSym.Type = 0; ! NewSym.StorageClass = 3; ! NewSym.NumberOfAuxSymbols = 1; ! ! SecSym.Section.Length = ResourceSize+Directory.Size; ! SecSym.Section.NumberOfRelocations = RelocTable.nElems; ! ! CheckedWrite(ofile,&NewSym,IMAGE_SIZEOF_SYMBOL,"symbols"); ! CheckedWrite(ofile,&SecSym,IMAGE_SIZEOF_SYMBOL,"symbols"); ! } ! ! void MakeCOFFSections(HANDLE ofile) ! { ! IMAGE_FILE_HEADER fileheader; ! IMAGE_SECTION_HEADER RSRChdr; ! ! lstrcpyA(RSRChdr.Name,".rsrc"); ! RSRChdr.Misc.PhysicalAddress = 0; ! RSRChdr.VirtualAddress = 0; ! RSRChdr.SizeOfRawData = ResourceSize+Directory.Size; ! RSRChdr.PointerToRawData = IMAGE_SIZEOF_FILE_HEADER + ! IMAGE_SIZEOF_SECTION_HEADER; ! RSRChdr.PointerToRelocations = RSRChdr.SizeOfRawData + ! RSRChdr.PointerToRawData; ! RSRChdr.PointerToLinenumbers = 0; ! RSRChdr.NumberOfRelocations = RelocTable.nElems; ! RSRChdr.NumberOfLinenumbers = 0; ! RSRChdr.Characteristics = IMAGE_SCN_MEM_READ ! /* | IMAGE_SCN_MEM_WRITE */; ! ! fileheader.Machine = IMAGE_FILE_MACHINE_I386; ! fileheader.NumberOfSections = 1; ! fileheader.TimeDateStamp = ResourceTime; ! fileheader.PointerToSymbolTable = RSRChdr.PointerToRelocations+ ! RelocTable.nElems * 10; ! fileheader.NumberOfSymbols = 2; ! fileheader.SizeOfOptionalHeader = 0; ! fileheader.Characteristics = IMAGE_FILE_LINE_NUMS_STRIPPED | ! IMAGE_FILE_32BIT_MACHINE; ! ! CheckedWrite(ofile,&fileheader,IMAGE_SIZEOF_FILE_HEADER,"COFF file header"); ! CheckedWrite(ofile,&RSRChdr,IMAGE_SIZEOF_SECTION_HEADER,".rsrc section header"); ! } ! Index: protos.h =================================================================== RCS file: /cvsroot/mingw/utils/res2coff/protos.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** protos.h 14 May 2002 20:38:30 -0000 1.1 --- protos.h 26 May 2002 10:13:58 -0000 1.2 *************** *** 1,37 **** ! // res2coff.c ! ! void WriteError(LPCSTR); ! void AppExit(int,char *,...); ! void CleanUp(void); ! void CheckedWrite(HANDLE,LPVOID,DWORD,char *); ! void usage(char); ! ! // OBJimage.c ! ! int Add2StringTable(wchar_t *); ! int AppendMemImage(MemImage *,MemImage *); ! int AddRelocation(int); ! int MakeDirectoryTree(void); ! int MakeSymbols(char *); ! ! void DumpResources(HANDLE); ! void DumpDirectoryImage(HANDLE); ! void DumpRelocations(HANDLE); ! void DumpSymbols(HANDLE); ! void MakeCOFFSections(HANDLE); ! ! // RESimage.c ! ! void InitResourceInfo(void); ! void FreeResourceInfo(void); ! int AddNamedResource(int,PRESOURCEHEAD); ! int AddIDResource(int,PRESOURCEHEAD); ! int IsTypeCoded(PRESOURCEHEAD); ! int TypeCode(PRESOURCEHEAD); ! int IsNameCoded(PRESOURCEHEAD); ! int IDCode(PRESOURCEHEAD); ! wchar_t *ResName(PRESOURCEHEAD); ! WORD LanguageID(PRESOURCEHEAD); ! PRESOURCEHEAD ParseResource(PRESOURCEHEAD); ! int Check32bitResourceFile(PRESOURCEHEAD); ! void SortUnnamedResources(void); --- 1,37 ---- ! // res2coff.c ! ! void WriteError(LPCSTR); ! void AppExit(int,char *,...); ! void CleanUp(void); ! void CheckedWrite(HANDLE,LPVOID,DWORD,char *); ! void usage(char); ! ! // OBJimage.c ! ! int Add2StringTable(wchar_t *); ! int AppendMemImage(MemImage *,MemImage *); ! int AddRelocation(int); ! int MakeDirectoryTree(void); ! int MakeSymbols(char *); ! ! void DumpResources(HANDLE); ! void DumpDirectoryImage(HANDLE); ! void DumpRelocations(HANDLE); ! void DumpSymbols(HANDLE); ! void MakeCOFFSections(HANDLE); ! ! // RESimage.c ! ! void InitResourceInfo(void); ! void FreeResourceInfo(void); ! int AddNamedResource(int,PRESOURCEHEAD); ! int AddIDResource(int,PRESOURCEHEAD); ! int IsTypeCoded(PRESOURCEHEAD); ! int TypeCode(PRESOURCEHEAD); ! int IsNameCoded(PRESOURCEHEAD); ! int IDCode(PRESOURCEHEAD); ! wchar_t *ResName(PRESOURCEHEAD); ! WORD LanguageID(PRESOURCEHEAD); ! PRESOURCEHEAD ParseResource(PRESOURCEHEAD); ! int Check32bitResourceFile(PRESOURCEHEAD); ! void SortUnnamedResources(void); Index: readme.1st =================================================================== RCS file: /cvsroot/mingw/utils/res2coff/readme.1st,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** readme.1st 14 May 2002 20:38:30 -0000 1.1 --- readme.1st 26 May 2002 10:13:58 -0000 1.2 *************** *** 1,40 **** ! RES2COFF : a binary resource to COFF object format converter ! ! First of all understand this : ! ! * THIS SOFTWARE IS NOT COPYRIGHTED ! * ! * This source code is offered for use in the public domain. You may ! * use, modify or distribute it freely. ! * ! * This code is distributed in the hope that it will be useful but ! * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY ! * DISCLAMED. This includes but is not limited to warrenties of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! ! Second, should you reuse it, I'd really appretiate a reference to this ! software. Blessings (if the program is useful to you), why not. Blamings, ! none. ! ! Now how to use it: ! ! res2coff [-v] -i <resource file> -o <object file> ! ! Both the resource and the object file have to be fully qualified and include ! the extension. I never assume anything about files. ! ! the -v flag will turn on a verbose mode which will show you a ! short recap of all resources found in the resource file. ! ! Revision history: ! ! v1.00 First 'working' version using Jacob Navia's lccwin32 ! v1.10 Ported to the Minimalist GNUWIN32 with the win32 headers ! from lccwin32, modified to pack system structures under GCC ! v1.20 Sorts the string tables found and now passes the tests ! in RCL 1.6.3 ! ! Enjoy ! ! Pedro A. Aranda ! pa...@ti... --- 1,40 ---- ! RES2COFF : a binary resource to COFF object format converter ! ! First of all understand this : ! ! * THIS SOFTWARE IS NOT COPYRIGHTED ! * ! * This source code is offered for use in the public domain. You may ! * use, modify or distribute it freely. ! * ! * This code is distributed in the hope that it will be useful but ! * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY ! * DISCLAMED. This includes but is not limited to warrenties of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! ! Second, should you reuse it, I'd really appretiate a reference to this ! software. Blessings (if the program is useful to you), why not. Blamings, ! none. ! ! Now how to use it: ! ! res2coff [-v] -i <resource file> -o <object file> ! ! Both the resource and the object file have to be fully qualified and include ! the extension. I never assume anything about files. ! ! the -v flag will turn on a verbose mode which will show you a ! short recap of all resources found in the resource file. ! ! Revision history: ! ! v1.00 First 'working' version using Jacob Navia's lccwin32 ! v1.10 Ported to the Minimalist GNUWIN32 with the win32 headers ! from lccwin32, modified to pack system structures under GCC ! v1.20 Sorts the string tables found and now passes the tests ! in RCL 1.6.3 ! ! Enjoy ! ! Pedro A. Aranda ! pa...@ti... Index: res2coff.c =================================================================== RCS file: /cvsroot/mingw/utils/res2coff/res2coff.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** res2coff.c 14 May 2002 20:38:30 -0000 1.1 --- res2coff.c 26 May 2002 10:13:58 -0000 1.2 *************** *** 1,237 **** ! #define __main__ ! #include "res2coff.h" ! ! /* ! res2coff.c ! ! Convert a 32 bit resource file into a COFF file ! to integrate the resources into an application ! at link time ! ! v1.00 : First official release, seems to be quite ! debugged ! ! v1.01 : stdargs for AppExit() ! standalone CleanUp() ! Compilable with mingw32 and Jacob Navia's WIN32 headers ! ! Most of the credit for getting me doing this thing is ! for Matt Pietrek's and his Windows95 Programming Secrets. ! I got the book before I even thought of doing this, but ! without it, I wouldn't have even dared to start. ! ! * Contributors: ! * Created by Pedro A. Aranda <pa...@ti...> ! * ! * THIS SOFTWARE IS NOT COPYRIGHTED ! * ! * This source code is offered for use in the public domain. You may ! * use, modify or distribute it freely. ! * ! * This code is distributed in the hope that it will be useful but ! * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY ! * DISCLAMED. This includes but is not limited to warrenties of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! ! Madrid, 06-06-96 ! ! */ ! ! /* ! * Exit the program in an orderly way ! * Any open handles are closed, ! * All dynamic memory is freed ! * Error messages are printed out through stderr ! */ ! ! void CleanUp(void) ! { ! ! if (Directory.Image) ! free(Directory.Image); ! ! if (Strings.Image) ! free(Strings.Image); ! ! if (ResourceHeads.Image) ! free(ResourceHeads.Image); ! ! if (RelocTable.pElems) ! free(RelocTable.pElems); ! ! FreeResourceInfo(); ! ! if (RESview) ! UnmapViewOfFile(RESview); ! if (RESmapping) ! CloseHandle(RESmapping); ! if ((RESfile) && (RESfile != (HANDLE)INVALID_HANDLE_VALUE)) ! CloseHandle(RESfile); ! if ((OBJFile) && (OBJFile != (HANDLE)INVALID_HANDLE_VALUE)) ! CloseHandle(OBJFile); ! } ! ! void AppExit(int ErrorLevel,char *msg,...) ! { ! va_list args; ! ! va_start(args,msg); ! if ((ErrorLevel) && (msg)) ! { ! fprintf(stderr,"%s :",ProgName); ! vfprintf(stderr,msg,args); ! } ! va_end(args); ! ! CleanUp(); ! exit(ErrorLevel); ! } ! ! void CheckedWrite(HANDLE of,LPVOID buffer,DWORD size,char *sectmsg) ! { ! DWORD written; ! ! WriteFile(of,buffer,size,&written,NULL); ! if (written == size) ! return; ! else ! AppExit(1,"Error writing %s , disk full(?)\n",sectmsg); ! } ! ! void usage(char wrong) ! { ! printf("\nUsage: %s [-v] -i infile -o outfile\n\n" ! " -v verbose mode\n" ! " -i <file>.res RES32 file (input)\n" ! " -o <file>.o COFF object file (output)\n",ProgName); ! ! if (wrong) ! printf("\n -%c is not defined as a valid option \n",wrong); ! ! exit(-1); ! } ! ! int main(int argc,char **argv) ! { ! int arg,result; ! char *src,*dst; ! DWORD cbFileSize; ! ! ProgName = argv[0]; ! ! if (argc == 1) { ! usage(0); ! exit(-1); ! } ! ! ResourceTime = (unsigned long)time(NULL); ! ! verbose = 0; ! src = dst = NULL; ! ! InitResourceInfo(); ! ! for (arg = 1;arg < argc;arg++) { ! if (argv[arg][0] == '-') ! switch(argv[arg][1]) { ! case 'v': ! case 'V': verbose = 1; ! break; ! ! case 'i': ! case 'I': if (argv[arg][2]) ! src = &argv[arg][2]; ! else ! src = argv[++arg]; ! break; ! case 'o': ! case 'O': if (argv[arg][2]) ! dst = &argv[arg][2]; ! else ! dst = argv[++arg]; ! break; ! ! default : usage(argv[arg][1]); ! break; ! } else ! usage(0); ! } ! ! if (src == NULL) { ! usage(0); ! printf("No input file\n"); ! } ! ! if (dst == NULL) { ! usage(0); ! printf("No output file\n"); ! } ! ! if (verbose) ! printf("%s version %x.%02x\n\n",ProgName,__MAVERSION__,__MIVERSION__); ! ! /* ! * Now we enter a very orderly procedure: ! * 1.- Open the resource file ! * 2.- Create a maping for it ! * 3.- Map it into virtual memory ! * 4.- Check it is indeed a RES32 file ! * 5.- Sort the unnamed resources (v1.2) ! * 6.- Create the COFF object file ! * ! * Should any of these steps fail, the application is ! * exited in an orderly way ! */ ! ! RESfile = CreateFileA(src, GENERIC_READ, ! FILE_SHARE_READ, NULL, OPEN_EXISTING, ! FILE_FLAG_SEQUENTIAL_SCAN, NULL); ! ! if ((!RESfile) || (RESfile == (HANDLE)INVALID_HANDLE_VALUE)) ! AppExit(1,"Couldn't open '%s'\n",src); ! ! RESmapping = CreateFileMappingA(RESfile,NULL,PAGE_READONLY,0,0,NULL); ! ! if (RESmapping == NULL) ! AppExit(1,"Couldn't create file mapping for '%s'\n",src); ! ! RESview = MapViewOfFile(RESmapping, FILE_MAP_READ, 0, 0, 0); ! ! if (RESview == NULL) ! AppExit(1,"Couldn't map view of '%s'\n",src); ! ! cbFileSize = GetFileSize(RESfile, NULL); ! ! if ((cbFileSize == -1) && (GetLastError() != NO_ERROR)) ! AppExit(1,"Error getting size of '%s'",src); ! ! RESviewEnd = (void *)((BYTE *)RESview + cbFileSize); ! ! if (!Check32bitResourceFile((PRESOURCEHEAD)RESview)) ! AppExit(1,"Error in RES32 file format in '%s'\n",src); ! ! SortUnnamedResources(); ! ! OBJFile = CreateFileA(dst,GENERIC_WRITE,0,NULL, ! CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); ! ! if ((!OBJFile) || (OBJFile == (HANDLE)INVALID_HANDLE_VALUE)) ! AppExit(1,"Couldn't create '%s'\n",dst); ! ! /* ! * Now we do the real processing. All functions have ! * autodocumenting names, just follow the code. ! * When all is done, we exit in an ordely way, ! * cleaning up any kind off mess we could have ! * stored in memory and flagging success (error level = 0) ! */ ! MakeDirectoryTree(); ! MakeCOFFSections(OBJFile); ! DumpDirectoryImage(OBJFile); ! DumpResources(OBJFile); ! DumpRelocations(OBJFile); ! DumpSymbols(OBJFile); ! CleanUp(); ! return 0; ! } ! --- 1,237 ---- ! #define __main__ ! #include "res2coff.h" ! ! /* ! res2coff.c ! ! Convert a 32 bit resource file into a COFF file ! to integrate the resources into an application ! at link time ! ! v1.00 : First official release, seems to be quite ! debugged ! ! v1.01 : stdargs for AppExit() ! standalone CleanUp() ! Compilable with mingw32 and Jacob Navia's WIN32 headers ! ! Most of the credit for getting me doing this thing is ! for Matt Pietrek's and his Windows95 Programming Secrets. ! I got the book before I even thought of doing this, but ! without it, I wouldn't have even dared to start. ! ! * Contributors: ! * Created by Pedro A. Aranda <pa...@ti...> ! * ! * THIS SOFTWARE IS NOT COPYRIGHTED ! * ! * This source code is offered for use in the public domain. You may ! * use, modify or distribute it freely. ! * ! * This code is distributed in the hope that it will be useful but ! * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY ! * DISCLAMED. This includes but is not limited to warrenties of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! ! Madrid, 06-06-96 ! ! */ ! ! /* ! * Exit the program in an orderly way ! * Any open handles are closed, ! * All dynamic memory is freed ! * Error messages are printed out through stderr ! */ ! ! void CleanUp(void) ! { ! ! if (Directory.Image) ! free(Directory.Image); ! ! if (Strings.Image) ! free(Strings.Image); ! ! if (ResourceHeads.Image) ! free(ResourceHeads.Image); ! ! if (RelocTable.pElems) ! free(RelocTable.pElems); ! ! FreeResourceInfo(); ! ! if (RESview) ! UnmapViewOfFile(RESview); ! if (RESmapping) ! CloseHandle(RESmapping); ! if ((RESfile) && (RESfile != (HANDLE)INVALID_HANDLE_VALUE)) ! CloseHandle(RESfile); ! if ((OBJFile) && (OBJFile != (HANDLE)INVALID_HANDLE_VALUE)) ! CloseHandle(OBJFile); ! } ! ! void AppExit(int ErrorLevel,char *msg,...) ! { ! va_list args; ! ! va_start(args,msg); ! if ((ErrorLevel) && (msg)) ! { ! fprintf(stderr,"%s :",ProgName); ! vfprintf(stderr,msg,args); ! } ! va_end(args); ! ! CleanUp(); ! exit(ErrorLevel); ! } ! ! void CheckedWrite(HANDLE of,LPVOID buffer,DWORD size,char *sectmsg) ! { ! DWORD written; ! ! WriteFile(of,buffer,size,&written,NULL); ! if (written == size) ! return; ! else ! AppExit(1,"Error writing %s , disk full(?)\n",sectmsg); ! } ! ! void usage(char wrong) ! { ! printf("\nUsage: %s [-v] -i infile -o outfile\n\n" ! " -v verbose mode\n" ! " -i <file>.res RES32 file (input)\n" ! " -o <file>.o COFF object file (output)\n",ProgName); ! ! if (wrong) ! printf("\n -%c is not defined as a valid option \n",wrong); ! ! exit(-1); ! } ! ! int main(int argc,char **argv) ! { ! int arg,result; ! char *src,*dst; ! DWORD cbFileSize; ! ! ProgName = argv[0]; ! ! if (argc == 1) { ! usage(0); ! exit(-1); ! } ! ! ResourceTime = (unsigned long)time(NULL); ! ! verbose = 0; ! src = dst = NULL; ! ! InitResourceInfo(); ! ! for (arg = 1;arg < argc;arg++) { ! if (argv[arg][0] == '-') ! switch(argv[arg][1]) { ! case 'v': ! case 'V': verbose = 1; ! break; ! ! case 'i': ! case 'I': if (argv[arg][2]) ! src = &argv[arg][2]; ! else ! src = argv[++arg]; ! break; ! case 'o': ! case 'O': if (argv[arg][2]) ! dst = &argv[arg][2]; ! else ! dst = argv[++arg]; ! break; ! ! default : usage(argv[arg][1]); ! break; ! } else ! usage(0); ! } ! ! if (src == NULL) { ! usage(0); ! printf("No input file\n"); ! } ! ! if (dst == NULL) { ! usage(0); ! printf("No output file\n"); ! } ! ! if (verbose) ! printf("%s version %x.%02x\n\n",ProgName,__MAVERSION__,__MIVERSION__); ! ! /* ! * Now we enter a very orderly procedure: ! * 1.- Open the resource file ! * 2.- Create a maping for it ! * 3.- Map it into virtual memory ! * 4.- Check it is indeed a RES32 file ! * 5.- Sort the unnamed resources (v1.2) ! * 6.- Create the COFF object file ! * ! * Should any of these steps fail, the application is ! * exited in an orderly way ! */ ! ! RESfile = CreateFileA(src, GENERIC_READ, ! FILE_SHARE_READ, NULL, OPEN_EXISTING, ! FILE_FLAG_SEQUENTIAL_SCAN, NULL); ! ! if ((!RESfile) || (RESfile == (HANDLE)INVALID_HANDLE_VALUE)) ! AppExit(1,"Couldn't open '%s'\n",src); ! ! RESmapping = CreateFileMappingA(RESfile,NULL,PAGE_READONLY,0,0,NULL); ! ! if (RESmapping == NULL) ! AppExit(1,"Couldn't create file mapping for '%s'\n",src); ! ! RESview = MapViewOfFile(RESmapping, FILE_MAP_READ, 0, 0, 0); ! ! if (RESview == NULL) ! AppExit(1,"Couldn't map view of '%s'\n",src); ! ! cbFileSize = GetFileSize(RESfile, NULL); ! ! if ((cbFileSize == -1) && (GetLastError() != NO_ERROR)) ! AppExit(1,"Error getting size of '%s'",src); ! ! RESviewEnd = (void *)((BYTE *)RESview + cbFileSize); ! ! if (!Check32bitResourceFile((PRESOURCEHEAD)RESview)) ! AppExit(1,"Error in RES32 file format in '%s'\n",src); ! ! SortUnnamedResources(); ! ! OBJFile = CreateFileA(dst,GENERIC_WRITE,0,NULL, ! CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); ! ! if ((!OBJFile) || (OBJFile == (HANDLE)INVALID_HANDLE_VALUE)) ! AppExit(1,"Couldn't create '%s'\n",dst); ! ! /* ! * Now we do the real processing. All functions have ! * autodocumenting names, just follow the code. ! * When all is done, we exit in an ordely way, ! * cleaning up any kind off mess we could have ! * stored in memory and flagging success (error level = 0) ! */ ! MakeDirectoryTree(); ! MakeCOFFSections(OBJFile); ! DumpDirectoryImage(OBJFile); ! DumpResources(OBJFile); ! DumpRelocations(OBJFile); ! DumpSymbols(OBJFile); ! CleanUp(); ! return 0; ! } ! Index: res2coff.h =================================================================== RCS file: /cvsroot/mingw/utils/res2coff/res2coff.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** res2coff.h 14 May 2002 20:38:30 -0000 1.1 --- res2coff.h 26 May 2002 10:13:58 -0000 1.2 *************** *** 1,363 **** ! // RES2COFF.h ! ! #ifndef __RES2COFF_H__ ! # define __RES2COFF_H__ ! ! # define WIN32 ! ! # include <windows.h> ! # include <stdio.h> ! # include <stdarg.h> ! # include <stdlib.h> ! # include <time.h> ! ! // This is an easy and clean way to define variables ! // accessible from all source files. One of them ! // defines __main__ and there's where they are ! // placed. The rest of the source files see them ! // as extern variables ! ! # ifdef __main__ ! # define PUBVAR ! # else ! # define PUBVAR extern ! # endif ! ! /* ***************************************************************** ! * ! * All structure definitions from this point on (paag) ! * ! * A 32 bit resource file header structure ! * ! */ ! ! typedef struct { ! DWORD DataSize ; ! DWORD HeaderSize ; ! DWORD Type ; ! DWORD Name ; ! DWORD DataVersion ; ! WORD MemoryFlag ; ! WORD LanguageID ; ! WORD Version ; ! DWORD Characteristics ; ! } RESOURCEHEAD,*PRESOURCEHEAD; ! ! ! /* ! * This code added by Colin Peters <co...@bi...>. ! * November 15, 1996. You should ifdef this out if you have complete ! * Windows 32 API files which include these structure definitions. ! */ ! struct _IMAGE_RESOURCE_DIRECTORY ! { ! DWORD Characteristics; ! DWORD TimeStamp; ! WORD MajorVersion; ! WORD MinorVersion; ! WORD NumberOfNamedEntries; ! WORD NumberOfIdEntries; ! }; ! ! typedef struct _IMAGE_RESOURCE_DIRECTORY IMAGE_RESOURCE_DIRECTORY; ! typedef struct _IMAGE_RESOURCE_DIRECTORY* PIMAGE_RESOURCE_DIRECTORY; ! ! struct _IMAGE_RESOURCE_DIRECTORY_ENTRY ! { ! DWORD Name; ! DWORD OffsetToData; ! }; ! ! typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY ! IMAGE_RESOURCE_DIRECTORY_ENTRY; ! typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY* ! PIMAGE_RESOURCE_DIRECTORY_ENTRY; ! ! struct _IMAGE_RESOURCE_DATA_ENTRY ! { ! DWORD OffsetToData; ! DWORD Size; ! DWORD CodePage; ! DWORD Reserved; ! }; ! ! typedef struct _IMAGE_RESOURCE_DATA_ENTRY IMAGE_RESOURCE_DATA_ENTRY; ! typedef struct _IMAGE_RESOURCE_DATA_ENTRY* PIMAGE_RESOURCE_DATA_ENTRY; ! ! #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000 ! #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000 ! ! struct _IMAGE_RELOCATION ! { ! DWORD VirtualAddress; ! DWORD SymbolTableIndex; ! WORD Type; ! }; ! ! typedef struct _IMAGE_RELOCATION IMAGE_RELOCATION; ! typedef struct _IMAGE_RELOCATION* PIMAGE_RELOCATION; ! ! /* Image relocation types (i386) */ ! #define IMAGE_REL_I386_ABSOLUTE 0 ! #define IMAGE_REL_I386_DIR16 1 ! #define IMAGE_REL_I386_REL16 2 ! #define IMAGE_REL_I386_DIR32 6 ! #define IMAGE_REL_I386_DIR32NB 7 ! #define IMAGE_REL_I386_SEG12 9 ! #define IMAGE_REL_I386_SECTION 10 ! #define IMAGE_REL_I386_SECREL 11 ! #define IMAGE_REL_I386_REL32 14 ! ! #define IMAGE_SIZEOF_RELOCATION 10; ! ! struct _IMAGE_SYMBOL ! { ! union ! { ! BYTE ShortName[8]; ! struct ! { ! DWORD Short; ! DWORD Long; ! } Name; ! PBYTE LongName[2]; ! } N; ! DWORD Value; ! SHORT SectionNumber; ! WORD Type; ! BYTE StorageClass; ! BYTE NumberOfAuxSymbols; ! }; ! ! typedef struct _IMAGE_SYMBOL IMAGE_SYMBOL; ! typedef struct _IMAGE_SYMBOL* PIMAGE_SYMBOL; ! ! #define IMAGE_SIZEOF_SYMBOL 18 ! ! ! typedef union _IMAGE_AUX_SYMBOL ! { ! struct /* Sym */ ! { ! DWORD TagIndex; ! ! union /* Misc */ ! { ! struct ! { ! WORD Linenumber; ! WORD Size; ! } LnSz; ! DWORD TotalSize; ! } Misc; ! ! union /* FcnAry */ ! { ! struct ! { ! DWORD PointerToLinenumber; ! DWORD PointerToNextFunction; ! } Function; ! ! struct ! { ! WORD Dimension[4]; ! } Array; ! ! } FcnAry; ! ! WORD TvIndex; ! ! } Sym; ! ! struct /* File */ ! { ! BYTE Name[IMAGE_SIZEOF_SYMBOL]; ! } File; ! ! struct /* Section */ ! { ! DWORD Length; ! WORD NumberOfRelocations; ! WORD NumberOfLinenumbers; ! DWORD CheckSum; ! SHORT Number; ! BYTE Selection; ! } Section; ! ! } IMAGE_AUX_SYMBOL; ! ! ! struct _IMAGE_FILE_HEADER ! { ! WORD Machine; ! WORD NumberOfSections; ! DWORD TimeDateStamp; ! DWORD PointerToSymbolTable; ! DWORD NumberOfSymbols; ! WORD SizeOfOptionalHeader; ! WORD Characteristics; ! }; ! ! typedef struct _IMAGE_FILE_HEADER IMAGE_FILE_HEADER; ! typedef struct _IMAGE_FILE_HEADER* PIMAGE_FILE_HEADER; ! ! #define IMAGE_SIZEOF_FILE_HEADER 20 ! ! #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 ! #define IMAGE_FILE_32BIT_MACHINE 0x0100 ! ! #define IMAGE_FILE_MACHINE_I386 0x014c ! ! ! #define IMAGE_SIZEOF_SHORT_NAME 8 ! ! struct _IMAGE_SECTION_HEADER ! { ! BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; ! union ! { ! DWORD PhysicalAddress; ! DWORD VirtualSize; ! } Misc; ! DWORD VirtualAddress; ! DWORD SizeOfRawData; ! DWORD PointerToRawData; ! DWORD PointerToRelocations; ! DWORD PointerToLinenumbers; ! WORD NumberOfRelocations; ! WORD NumberOfLinenumbers; ! DWORD Characteristics; ! }; ! ! typedef struct _IMAGE_SECTION_HEADER IMAGE_SECTION_HEADER; ! typedef struct _IMAGE_SECTION_HEADER* PIMAGE_SECTION_HEADER; ! ! #define IMAGE_SIZEOF_SECTION_HEADER 40 ! ! #define IMAGE_SCN_MEM_READ 0x40000000 ! #define IMAGE_SCN_MEM_WRITE 0x80000000 ! ! /* ! * End of modification by Colin Peters. ! */ ! ! ! // This is the storage for the COFF image chunks ! // before they are transfered to the disk ! ! typedef struct { ! int Size ; ! void *Image ; ! } MemImage; ! ! // This holds the relocation and symbol tables ! ! typedef struct { ! int nElems; ! LPVOID pElems; ! } Table ; ! ! // Make a similar tree to the original one, but ! // taking into account that data are already in ! // memory. ! ! ! typedef struct { ! int count,named,unnamed; ! PRESOURCEHEAD *RName,*RID; ! } RESOURCEINFO; ! ! ! // ******************************************************** ! ! #define MAX_TYPES 17 ! #define CCHMAXPATH 260 ! ! // Program version ! ! #define __MAVERSION__ 1 ! #define __MIVERSION__ 0x20 ! ! // Declared version in the resources ! ! #define DECLARED_MAV 4 ! #define DECLARED_MIV 0 ! ! ! /* ************************************************** ! * ! * Function prototypes ! */ ! ! # include "protos.h" ! ! ! /* ************************************************** ! * ! * Variables ! */ ! ! PUBVAR RESOURCEINFO ResInfo[MAX_TYPES]; ! ! /* Option flags */ ! ! PUBVAR int verbose; ! ! PUBVAR int ResourceTime; ! PUBVAR int ResourceSize; ! PUBVAR char *ProgName; ! // ! ! PUBVAR HANDLE OBJFile; ! PUBVAR HANDLE RESfile; ! PUBVAR HANDLE RESmapping; ! PUBVAR LPVOID RESview; ! PUBVAR LPVOID RESviewEnd; ! ! // ******************************************* ! // Initialised variables ! // ! ! PUBVAR MemImage Directory ! #ifdef __main__ ! = { 0,NULL } ! #endif ! ; ! ! PUBVAR MemImage Strings ! #ifdef __main__ ! = { 0,NULL } ! #endif ! ; ! ! PUBVAR MemImage ResourceHeads ! #ifdef __main__ ! = { 0,NULL } ! #endif ! ; ! ! PUBVAR Table RelocTable ! #ifdef __main__ ! = { 0,NULL } ! #endif ! ; ! ! // Constants : ! // The predefined resource types ! ! PUBVAR char *szResourceTypes[] ! # ifdef __main__ ! = { ! "???_0", "CURSOR", "BITMAP", "ICON", ! "MENU", "DIALOG", "STRING", "FONTDIR", ! "FONT", "ACCELERATORS", "RCDATA", "MESSAGETABLE", ! "GROUP_CURSOR", "???_13", "GROUP_ICON", "???_15", ! "VERSION" ! } ! # endif ! ; ! ! #endif // defined(__RES2COFF_H__) ! ! --- 1,363 ---- ! // RES2COFF.h ! ! #ifndef __RES2COFF_H__ ! # define __RES2COFF_H__ ! ! # define WIN32 ! ! # include <windows.h> ! # include <stdio.h> ! # include <stdarg.h> ! # include <stdlib.h> ! # include <time.h> ! ! // This is an easy and clean way to define variables ! // accessible from all source files. One of them ! // defines __main__ and there's where they are ! // placed. The rest of the source files see them ! // as extern variables ! ! # ifdef __main__ ! # define PUBVAR ! # else ! # define PUBVAR extern ! # endif ! ! /* ***************************************************************** ! * ! * All structure definitions from this point on (paag) ! * ! * A 32 bit resource file header structure ! * ! */ ! ! typedef struct { ! DWORD DataSize ; ! DWORD HeaderSize ; ! DWORD Type ; ! DWORD Name ; ! DWORD DataVersion ; ! WORD MemoryFlag ; ! WORD LanguageID ; ! WORD Version ; ! DWORD Characteristics ; ! } RESOURCEHEAD,*PRESOURCEHEAD; ! ! ! /* ! * This code added by Colin Peters <co...@bi...>. ! * November 15, 1996. You should ifdef this out if you have complete ! * Windows 32 API files which include these structure definitions. ! */ ! struct _IMAGE_RESOURCE_DIRECTORY ! { ! DWORD Characteristics; ! DWORD TimeStamp; ! WORD MajorVersion; ! WORD MinorVersion; ! WORD NumberOfNamedEntries; ! WORD NumberOfIdEntries; ! }; ! ! typedef struct _IMAGE_RESOURCE_DIRECTORY IMAGE_RESOURCE_DIRECTORY; ! typedef struct _IMAGE_RESOURCE_DIRECTORY* PIMAGE_RESOURCE_DIRECTORY; ! ! struct _IMAGE_RESOURCE_DIRECTORY_ENTRY ! { ! DWORD Name; ! DWORD OffsetToData; ! }; ! ! typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY ! IMAGE_RESOURCE_DIRECTORY_ENTRY; ! typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY* ! PIMAGE_RESOURCE_DIRECTORY_ENTRY; ! ! struct _IMAGE_RESOURCE_DATA_ENTRY ! { ! DWORD OffsetToData; ! DWORD Size; ! DWORD CodePage; ! DWORD Reserved; ! }; ! ! typedef struct _IMAGE_RESOURCE_DATA_ENTRY IMAGE_RESOURCE_DATA_ENTRY; ! typedef struct _IMAGE_RESOURCE_DATA_ENTRY* PIMAGE_RESOURCE_DATA_ENTRY; ! ! #define IMAGE_RESOURCE_NAME_IS_STRING 0x80000000 ! #define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x80000000 ! ! struct _IMAGE_RELOCATION ! { ! DWORD VirtualAddress; ! DWORD SymbolTableIndex; ! WORD Type; ! }; ! ! typedef struct _IMAGE_RELOCATION IMAGE_RELOCATION; ! typedef struct _IMAGE_RELOCATION* PIMAGE_RELOCATION; ! ! /* Image relocation types (i386) */ ! #define IMAGE_REL_I386_ABSOLUTE 0 ! #define IMAGE_REL_I386_DIR16 1 ! #define IMAGE_REL_I386_REL16 2 ! #define IMAGE_REL_I386_DIR32 6 ! #define IMAGE_REL_I386_DIR32NB 7 ! #define IMAGE_REL_I386_SEG12 9 ! #define IMAGE_REL_I386_SECTION 10 ! #define IMAGE_REL_I386_SECREL 11 ! #define IMAGE_REL_I386_REL32 14 ! ! #define IMAGE_SIZEOF_RELOCATION 10; ! ! struct _IMAGE_SYMBOL ! { ! union ! { ! BYTE ShortName[8]; ! struct ! { ! DWORD Short; ! DWORD Long; ! } Name; ! PBYTE LongName[2]; ! } N; ! DWORD Value; ! SHORT SectionNumber; ! WORD Type; ! BYTE StorageClass; ! BYTE NumberOfAuxSymbols; ! }; ! ! typedef struct _IMAGE_SYMBOL IMAGE_SYMBOL; ! typedef struct _IMAGE_SYMBOL* PIMAGE_SYMBOL; ! ! #define IMAGE_SIZEOF_SYMBOL 18 ! ! ! typedef union _IMAGE_AUX_SYMBOL ! { ! struct /* Sym */ ! { ! DWORD TagIndex; ! ! union /* Misc */ ! { ! struct ! { ! WORD Linenumber; ! WORD Size; ! } LnSz; ! DWORD TotalSize; ! } Misc; ! ! union /* FcnAry */ ! { ! struct ! { ! DWORD PointerToLinenumber; ! DWORD PointerToNextFunction; ! } Function; ! ! struct ! { ! WORD Dimension[4]; ! } Array; ! ! } FcnAry; ! ! WORD TvIndex; ! ! } Sym; ! ! struct /* File */ ! { ! BYTE Name[IMAGE_SIZEOF_SYMBOL]; ! } File; ! ! struct /* Section */ ! { ! DWORD Length; ! WORD NumberOfRelocations; ! WORD NumberOfLinenumbers; ! DWORD CheckSum; ! SHORT Number; ! BYTE Selection; ! } Section; ! ! } IMAGE_AUX_SYMBOL; ! ! ! struct _IMAGE_FILE_HEADER ! { ! WORD Machine; ! WORD NumberOfSections; ! DWORD TimeDateStamp; ! DWORD PointerToSymbolTable; ! DWORD NumberOfSymbols; ! WORD SizeOfOptionalHeader; ! WORD Characteristics; ! }; ! ! typedef struct _IMAGE_FILE_HEADER IMAGE_FILE_HEADER; ! typedef struct _IMAGE_FILE_HEADER* PIMAGE_FILE_HEADER; ! ! #define IMAGE_SIZEOF_FILE_HEADER 20 ! ! #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 ! #define IMAGE_FILE_32BIT_MACHINE 0x0100 ! ! #define IMAGE_FILE_MACHINE_I386 0x014c ! ! ! #define IMAGE_SIZEOF_SHORT_NAME 8 ! ! struct _IMAGE_SECTION_HEADER ! { ! BYTE Name[IMAGE_SIZEOF_SHORT_NAME]; ! union ! { ! DWORD PhysicalAddress; ! DWORD VirtualSize; ! } Misc; ! DWORD VirtualAddress; ! DWORD SizeOfRawData; ! DWORD PointerToRawData; ! DWORD PointerToRelocations; ! DWORD PointerToLinenumbers; ! WORD NumberOfRelocations; ! WORD NumberOfLinenumbers; ! DWORD Characteristics; ! }; ! ! typedef struct _IMAGE_SECTION_HEADER IMAGE_SECTION_HEADER; ! typedef struct _IMAGE_SECTION_HEADER* PIMAGE_SECTION_HEADER; ! ! #define IMAGE_SIZEOF_SECTION_HEADER 40 ! ! #define IMAGE_SCN_MEM_READ 0x40000000 ! #define IMAGE_SCN_MEM_WRITE 0x80000000 ! ! /* ! * End of modification by Colin Peters. ! */ ! ! ! // This is the storage for the COFF image chunks ! // before they are transfered to the disk ! ! typedef struct { ! int Size ; ! void *Image ; ! } MemImage; ! ! // This holds the relocation and symbol tables ! ! typedef struct { ! int nElems; ! LPVOID pElems; ! } Table ; ! ! // Make a similar tree to the original one, but ! // taking into account that data are already in ! // memory. ! ! ! typedef struct { ! int count,named,unnamed; ! PRESOURCEHEAD *RName,*RID; ! } RESOURCEINFO; ! ! ! // ******************************************************** ! ! #define MAX_TYPES 17 ! #define CCHMAXPATH 260 ! ! // Program version ! ! #define __MAVERSION__ 1 ! #define __MIVERSION__ 0x20 ! ! // Declared version in the resources ! ! #define DECLARED_MAV 4 ! #define DECLARED_MIV 0 ! ! ! /* ************************************************** ! * ! * Function prototypes ! */ ! ! # include "protos.h" ! ! ! /* ************************************************** ! * ! * Variables ! */ ! ! PUBVAR RESOURCEINFO ResInfo[MAX_TYPES]; ! ! /* Option flags */ ! ! PUBVAR int verbose; ! ! PUBVAR int ResourceTime; ! PUBVAR int ResourceSize; ! PUBVAR char *ProgName; ! // ! ! PUBVAR HANDLE OBJFile; ! PUBVAR HANDLE RESfile; ! PUBVAR HANDLE RESmapping; ! PUBVAR LPVOID RESview; ! PUBVAR LPVOID RESviewEnd; ! ! // ******************************************* ! // Initialised variables ! // ! ! PUBVAR MemImage Directory ! #ifdef __main__ ! = { 0,NULL } ! #endif ! ; ! ! PUBVAR MemImage Strings ! #ifdef __main__ ! = { 0,NULL } ! #endif ! ; ! ! PUBVAR MemImage ResourceHeads ! #ifdef __main__ ! = { 0,NULL } ! #endif ! ; ! ! PUBVAR Table RelocTable ! #ifdef __main__ ! = { 0,NULL } ! #endif ! ; ! ! // Constants : ! // The predefined resource types ! ! PUBVAR char *szResourceTypes[] ! # ifdef __main__ ! = { ! "???_0", "CURSOR", "BITMAP", "ICON", ! "MENU", "DIALOG", "STRING", "FONTDIR", ! "FONT", "ACCELERATORS", "RCDATA", "MESSAGETABLE", ! "GROUP_CURSOR", "???_13", "GROUP_ICON", "???_15", ! "VERSION" ! } ! # endif ! ; ! ! #endif // defined(__RES2COFF_H__) ! ! Index: resimage.c =================================================================== RCS file: /cvsroot/mingw/utils/res2coff/resimage.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** resimage.c 14 May 2002 20:38:30 -0000 1.1 --- resimage.c 26 May 2002 10:13:58 -0000 1.2 *************** *** 1,334 **** ! /* ! * RESimage.c ! * ! * This module is devoted to treating the .RES files ! */ ! ! #include "res2coff.h" ! ! // Initialise the Resource Information Tree ! ! void InitResourceInfo(void) ! { ! int i; ! ! for (i=0;i<MAX_TYPES;i++) { ! ResInfo[i].count = ResInfo[i].named = ResInfo[i].unnamed = 0; ! ResInfo[i].RName = ResInfo[i].RID = NULL; ! } ! } ! ! // Free the Resource Information Tree ! ! void FreeResourceInfo(void) ! { ! int i; ! ! #ifdef NDEBUG ! if (verbose) ! printf("Resources found in file\n Named Unnamed Type\n"); ! #endif ! ! for (i=0;i<MAX_TYPES;i++) ! { ! #ifdef NDEBUG ! if ((verbose) && (ResInfo[i].count)) ! printf(" %4d %6d %s\n", ! ResInfo[i].named, ! ResInfo[i].unnamed, ! szResourceTypes[i]); ! #endif ! if (ResInfo[i].RName) ! free(ResInfo[i].RName); ! if (ResInfo[i].RID) ! free(ResInfo[i].RID); ! } ! } ! ! // Add a named resource of a given type to the Resource Information Tree ! ! int AddNamedResource(int type,PRESOURCEHEAD pNewResource) ! { ! PRESOURCEHEAD *pTemp; ! int result; ! int last = ResInfo[type].named; ! ! pTemp = (PRESOURCEHEAD *)realloc(ResInfo[type].RName, ! sizeof(PRESOURCEHEAD)*(last+1)); ! ResInfo[type].RName = pTemp; ! if (result = (pTemp) ? TRUE : FALSE) ! { ! ResInfo[type].RName = pTemp; ! ResInfo[type].count++; ! ResInfo[type].named++; ! pTemp[last] = pNewResource; ! } ! ! return result; ! } ! ! // Add a numbered resource of a given type to the Resource Information Tree ! ! int AddIDResource(int type,PRESOURCEHEAD pNewResource) ! { ! PRESOURCEHEAD *pTemp; ! int result; ! int ... [truncated message content] |