Fix some compiler warnings, improve formatting, diagnostic messages.
svn path=/trunk/; revision=58591
+/*
+ * Generates assembly definitions from the target headers.
+ */
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
/* Verify the PE signature */
if (signature != 0x4550)
{
/* Verify the PE signature */
if (signature != 0x4550)
{
- fprintf(stderr, "Invalid signature: 0x%lx.\n", signature);
+ fprintf(stderr, "Invalid signature: 0x%x.\n", signature);
- if (InfHostGetIntField (Context, 4, &Flags) != 0)
+ if (InfHostGetIntField (Context, 4, (INT *)&Flags) != 0)
rc = RegQueryValueExW(hKey, lpValueNameW, lpReserved, lpType, lpData, lpcbData);
if (lpValueNameW)
free(lpValueNameW);
rc = RegQueryValueExW(hKey, lpValueNameW, lpReserved, lpType, lpData, lpcbData);
if (lpValueNameW)
free(lpValueNameW);
+ if (rc != ERROR_SUCCESS)
+ return rc;
return ERROR_UNSUCCESSFUL;
}
return ERROR_UNSUCCESSFUL;
}
#include <string.h>
#include <ctype.h>
#ifndef _MSC_VER
#include <string.h>
#include <ctype.h>
#ifndef _MSC_VER
#define SW_SHOWNORMAL 1
#define SW_SHOWMINNOACTIVE 7
#define SW_SHOWNORMAL 1
#define SW_SHOWMINNOACTIVE 7
uint32_t Data1;
uint16_t Data2;
uint16_t Data3;
uint32_t Data1;
uint16_t Data2;
uint16_t Data3;
LNK_HEADER Header;
uint16_t uhTmp;
uint32_t dwTmp;
LNK_HEADER Header;
uint16_t uhTmp;
uint32_t dwTmp;
for (i = 1; i < argc; ++i)
{
if (argv[i][0] != '-' && argv[i][0] != '/')
for (i = 1; i < argc; ++i)
{
if (argv[i][0] != '-' && argv[i][0] != '/')
else if (!strcmp(argv[i] + 1, "g") && i + 1 < argc)
{
unsigned Data4Tmp[8], j;
else if (!strcmp(argv[i] + 1, "g") && i + 1 < argc)
{
unsigned Data4Tmp[8], j;
-
- sscanf(argv[++i], "{%8lx-%4hx-%4hx-%2x%2x-%2x%2x%2x%2x%2x%2x}",
+
+ sscanf(argv[++i], "{%8x-%4hx-%4hx-%2x%2x-%2x%2x%2x%2x%2x%2x}",
&Guid.Data1, &Guid.Data2, &Guid.Data3,
&Data4Tmp[0], &Data4Tmp[1], &Data4Tmp[2], &Data4Tmp[3],
&Data4Tmp[4], &Data4Tmp[5], &Data4Tmp[6], &Data4Tmp[7]);
&Guid.Data1, &Guid.Data2, &Guid.Data3,
&Data4Tmp[0], &Data4Tmp[1], &Data4Tmp[2], &Data4Tmp[3],
&Data4Tmp[4], &Data4Tmp[5], &Data4Tmp[6], &Data4Tmp[7]);
else
printf("Invalid option: %s\n", argv[i]);
}
else
printf("Invalid option: %s\n", argv[i]);
}
if (!pszTarget || bHelp)
{
printf("Usage: %s [-o path][-d descr][-w path][-c cmd_line_args][-i icon_path [nr]][-h][-g guid] target\n"
if (!pszTarget || bHelp)
{
printf("Usage: %s [-o path][-d descr][-w path][-c cmd_line_args][-i icon_path [nr]][-h][-g guid] target\n"
"target\tAbsolute or relative to guid specified with -g option path\n", argv[0]);
return 0;
}
"target\tAbsolute or relative to guid specified with -g option path\n", argv[0]);
return 0;
}
pFile = fopen(pszOutputPath, "wb");
if (!pFile)
{
printf("Failed to open %s\n", pszOutputPath);
return -1;
}
pFile = fopen(pszOutputPath, "wb");
if (!pFile)
{
printf("Failed to open %s\n", pszOutputPath);
return -1;
}
// Header
memset(&Header, 0, sizeof(Header));
Header.Signature = (uint32_t)'L';
// Header
memset(&Header, 0, sizeof(Header));
Header.Signature = (uint32_t)'L';
Header.IconNr = IconNr;
Header.Show = bMinimized ? SW_SHOWMINNOACTIVE : SW_SHOWNORMAL;
fwrite(&Header, sizeof(Header), 1, pFile);
Header.IconNr = IconNr;
Header.Show = bMinimized ? SW_SHOWMINNOACTIVE : SW_SHOWNORMAL;
fwrite(&Header, sizeof(Header), 1, pFile);
if (Header.Flags & LINK_ID_LIST)
{
ID_LIST_FILE IdListFile;
if (Header.Flags & LINK_ID_LIST)
{
ID_LIST_FILE IdListFile;
ID_LIST_DRIVE IdListDrive;
unsigned cbListSize = sizeof(IdListGuid) + sizeof(uint16_t), cchName;
const char *pszName = pszTarget;
ID_LIST_DRIVE IdListDrive;
unsigned cbListSize = sizeof(IdListGuid) + sizeof(uint16_t), cchName;
const char *pszName = pszTarget;
// ID list
// It seems explorer does not accept links without id list. List is relative to desktop.
// ID list
// It seems explorer does not accept links without id list. List is relative to desktop.
if (pszName[0] && pszName[1] == ':')
{
cbListSize += sizeof(IdListDrive);
if (pszName[0] && pszName[1] == ':')
{
cbListSize += sizeof(IdListDrive);
while (*pszName == '\\' || *pszName == '/')
++pszName;
}
while (*pszName == '\\' || *pszName == '/')
++pszName;
}
while (*pszName)
{
cchName = 0;
while (pszName[cchName] && pszName[cchName] != '\\' && pszName[cchName] != '/')
++cchName;
while (*pszName)
{
cchName = 0;
while (pszName[cchName] && pszName[cchName] != '\\' && pszName[cchName] != '/')
++cchName;
if (cchName != 1 || pszName[0] != '.')
cbListSize += sizeof(IdListFile) + 2 * (cchName + 1);
if (cchName != 1 || pszName[0] != '.')
cbListSize += sizeof(IdListFile) + 2 * (cchName + 1);
pszName += cchName;
while (*pszName == '\\' || *pszName == '/')
++pszName;
}
pszName += cchName;
while (*pszName == '\\' || *pszName == '/')
++pszName;
}
uhTmp = cbListSize;
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile); // size
uhTmp = cbListSize;
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile); // size
IdListGuid.Size = sizeof(IdListGuid);
IdListGuid.Type = PT_GUID;
IdListGuid.dummy = 0x50;
IdListGuid.guid = Guid;
fwrite(&IdListGuid, sizeof(IdListGuid), 1, pFile);
IdListGuid.Size = sizeof(IdListGuid);
IdListGuid.Type = PT_GUID;
IdListGuid.dummy = 0x50;
IdListGuid.guid = Guid;
fwrite(&IdListGuid, sizeof(IdListGuid), 1, pFile);
if (isalpha(pszName[0]) && pszName[1] == ':')
{
memset(&IdListDrive, 0, sizeof(IdListDrive));
if (isalpha(pszName[0]) && pszName[1] == ':')
{
memset(&IdListDrive, 0, sizeof(IdListDrive));
while(*pszName == '\\' || *pszName == '/')
++pszName;
}
while(*pszName == '\\' || *pszName == '/')
++pszName;
}
while (*pszName)
{
cchName = 0;
while (pszName[cchName] && pszName[cchName] != '\\' && pszName[cchName] != '/')
++cchName;
while (*pszName)
{
cchName = 0;
while (pszName[cchName] && pszName[cchName] != '\\' && pszName[cchName] != '/')
++cchName;
if (cchName != 1 || pszName[0] != '.')
{
memset(&IdListFile, 0, sizeof(IdListFile));
if (cchName != 1 || pszName[0] != '.')
{
memset(&IdListFile, 0, sizeof(IdListFile));
fwrite(pszName, cchName, 1, pFile);
fputc(0, pFile);
}
fwrite(pszName, cchName, 1, pFile);
fputc(0, pFile);
}
pszName += cchName;
while (*pszName == '\\' || *pszName == '/')
++pszName;
}
pszName += cchName;
while (*pszName == '\\' || *pszName == '/')
++pszName;
}
uhTmp = 0; // list end
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
}
uhTmp = 0; // list end
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
}
if (Header.Flags & LINK_DESCRIPTION)
{
// Dscription
if (Header.Flags & LINK_DESCRIPTION)
{
// Dscription
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszDescription, pFile);
}
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszDescription, pFile);
}
if (Header.Flags & LINK_RELATIVE_PATH)
{
// Relative Path
if (Header.Flags & LINK_RELATIVE_PATH)
{
// Relative Path
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszTarget, pFile);
}
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszTarget, pFile);
}
if (Header.Flags & LINK_WORKING_DIR)
{
// Working Dir
if (Header.Flags & LINK_WORKING_DIR)
{
// Working Dir
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszWorkingDir, pFile);
}
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszWorkingDir, pFile);
}
if (Header.Flags & LINK_CMD_LINE_ARGS)
{
// Command line arguments
if (Header.Flags & LINK_CMD_LINE_ARGS)
{
// Command line arguments
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszCmdLineArgs, pFile);
}
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszCmdLineArgs, pFile);
}
if (Header.Flags & LINK_ICON)
{
// Command line arguments
if (Header.Flags & LINK_ICON)
{
// Command line arguments
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszIcon, pFile);
}
fwrite(&uhTmp, sizeof(uhTmp), 1, pFile);
fputs(pszIcon, pFile);
}
// Extra stuff
dwTmp = 0;
fwrite(&dwTmp, sizeof(dwTmp), 1, pFile);
// Extra stuff
dwTmp = 0;
fwrite(&dwTmp, sizeof(dwTmp), 1, pFile);
- printf("Unknown relocatation type %ld address %ld\n",
+ printf("Unknown relocatation type %d, address 0x%lx\n",
pReloc->Type, pReloc->VirtualAddress);
}
pReloc->Type, pReloc->VirtualAddress);
}
{
free(pData);
fclose(pSourceFile);
{
free(pData);
fclose(pSourceFile);
- fprintf(stderr, "Failed to read source file: %ld\n", nFileSize);
+ fprintf(stderr, "Failed to read %ld bytes from source file\n", nFileSize);
if (!pDestFile)
{
free(pData);
if (!pDestFile)
{
free(pData);
- fprintf(stderr, "Couldn't open dest file '%s'\n", pszDestFile);
+ fprintf(stderr, "Couldn't open destination file '%s'\n", pszDestFile);
for (i = 0; i < pFileHeader->NumberOfSections; i++)
{
/* Check if this is '.text' section */
for (i = 0; i < pFileHeader->NumberOfSections; i++)
{
/* Check if this is '.text' section */
- if ((strcmp(pSectionHeader->Name, ".text") == 0) &&
+ if ((strcmp((char*)pSectionHeader->Name, ".text") == 0) &&
(pSectionHeader->SizeOfRawData != 0))
{
RelocateSection(pData,
(pSectionHeader->SizeOfRawData != 0))
{
RelocateSection(pData,
{
free(pData);
fclose(pDestFile);
{
free(pData);
fclose(pDestFile);
- fprintf(stderr, "Failed to write data %ld\n",
+ fprintf(stderr, "Failed to write %ld bytes to destination file\n",
pSectionHeader->SizeOfRawData);
return -6;
}
pSectionHeader->SizeOfRawData);
return -6;
}
for (Idx = 0; Idx < PEFileHeader->NumberOfSections; Idx++)
{
/* printf("section: '%.08s'\n", PESectionHeaders[Idx].Name); */
for (Idx = 0; Idx < PEFileHeader->NumberOfSections; Idx++)
{
/* printf("section: '%.08s'\n", PESectionHeaders[Idx].Name); */
- if ((strncmp((char*)PESectionHeaders[Idx].Name, ".stab", 5) == 0)
+ if ((strncmp((char *) PESectionHeaders[Idx].Name, ".stab", 5) == 0)
&& (PESectionHeaders[Idx].Name[5] == 0))
{
/* printf(".stab section found. Size %d\n",
&& (PESectionHeaders[Idx].Name[5] == 0))
{
/* printf(".stab section found. Size %d\n",
*StabSymbolsBase = (void *)((char *) FileData + PESectionHeaders[Idx].PointerToRawData);
}
*StabSymbolsBase = (void *)((char *) FileData + PESectionHeaders[Idx].PointerToRawData);
}
- if (strncmp((char*)PESectionHeaders[Idx].Name, ".stabstr", 8) == 0)
+ if (strncmp((char *) PESectionHeaders[Idx].Name, ".stabstr", 8) == 0)
{
/* printf(".stabstr section found. Size %d\n",
PESectionHeaders[Idx].SizeOfRawData); */
{
/* printf(".stabstr section found. Size %d\n",
PESectionHeaders[Idx].SizeOfRawData); */
if ((0 == StartOfRawData
|| InSectionHeaders[Section].PointerToRawData < StartOfRawData)
&& 0 != InSectionHeaders[Section].PointerToRawData
if ((0 == StartOfRawData
|| InSectionHeaders[Section].PointerToRawData < StartOfRawData)
&& 0 != InSectionHeaders[Section].PointerToRawData
- && 0 != (strncmp(InSectionHeaders[Section].Name, ".stab", 5)))
+ && 0 != (strncmp((char *) InSectionHeaders[Section].Name, ".stab", 5)))
{
StartOfRawData = InSectionHeaders[Section].PointerToRawData;
}
{
StartOfRawData = InSectionHeaders[Section].PointerToRawData;
}
OutRelocSection = NULL;
for (Section = 0; Section < InFileHeader->NumberOfSections; Section++)
{
OutRelocSection = NULL;
for (Section = 0; Section < InFileHeader->NumberOfSections; Section++)
{
- if (0 != (strncmp(InSectionHeaders[Section].Name, ".stab", 5)))
+ if (0 != (strncmp((char *) InSectionHeaders[Section].Name, ".stab", 5)))
{
*CurrentSectionHeader = InSectionHeaders[Section];
CurrentSectionHeader->PointerToLinenumbers = 0;
{
*CurrentSectionHeader = InSectionHeaders[Section];
CurrentSectionHeader->PointerToLinenumbers = 0;