[MKHIVE] Remove key name in our custom registry tree; use cell index instead
[reactos.git] / reactos / tools / obj2bin / obj2bin.c
index c5d60a1..07b0767 100644 (file)
@@ -1,7 +1,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "../pecoff.h"
+#include <typedefs.h>
+#include <pecoff.h>
 
 static
 void
@@ -51,8 +52,8 @@ RelocateSection(
                 break;
 
             default:
-                printf("Unknown relocatation type %ld address %ld\n",
-                       pReloc->Type, pReloc->VirtualAddress);
+                printf("Unknown relocation type %u, address 0x%x\n",
+                       pReloc->Type, (unsigned)pReloc->VirtualAddress);
         }
 
         pReloc++;
@@ -63,14 +64,12 @@ int main(int argc, char *argv[])
 {
     char *pszSourceFile;
     char *pszDestFile;
-    unsigned long nFileSize, nBaseAddress, nOffsetSectionHeaders;
+    unsigned long nFileSize, nBaseAddress;
     FILE *pSourceFile, *pDestFile;
     IMAGE_FILE_HEADER *pFileHeader;
     IMAGE_SECTION_HEADER *pSectionHeader;
     unsigned int i;
-    size_t nSize;
     char *pData;
-    PIMAGE_RELOCATION pReloc;
     PIMAGE_SYMBOL pSymbols;
 
     if ((argc != 4) || (strcmp(argv[1], "--help") == 0))
@@ -99,14 +98,17 @@ int main(int argc, char *argv[])
     pData = malloc(nFileSize);
     if (!pData)
     {
-        fprintf(stderr, "Failed to allocate %ld bytes\n", nFileSize);
+        fclose(pSourceFile);
+        fprintf(stderr, "Failed to allocate %lu bytes\n", nFileSize);
         return -3;
     }
 
     /* Read the whole source file */
     if (!fread(pData, nFileSize, 1, pSourceFile))
     {
-        fprintf(stderr, "Failed to read source file: %ld\n", nFileSize);
+        free(pData);
+        fclose(pSourceFile);
+        fprintf(stderr, "Failed to read %lu bytes from source file\n", nFileSize);
         return -4;
     }
 
@@ -115,9 +117,10 @@ int main(int argc, char *argv[])
 
     /* Open the destination file */
     pDestFile = fopen(pszDestFile, "wb");
-    if (!pszDestFile)
+    if (!pDestFile)
     {
-        fprintf(stderr, "Couldn't open dest file '%s'\n", pszDestFile);
+        free(pData);
+        fprintf(stderr, "Couldn't open destination file '%s'\n", pszDestFile);
         return -5;
     }
 
@@ -129,11 +132,9 @@ int main(int argc, char *argv[])
     /* Loop all sections */
     for (i = 0; i < pFileHeader->NumberOfSections; i++)
     {
-        /* Skip empty sections */
-        if (pSectionHeader->SizeOfRawData == 0) continue;
-
         /* 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,
@@ -144,8 +145,10 @@ int main(int argc, char *argv[])
             if (!fwrite(pData + pSectionHeader->PointerToRawData,
                         pSectionHeader->SizeOfRawData, 1, pDestFile))
             {
-                fprintf(stderr, "Failed to write data %ld\n",
-                        pSectionHeader->SizeOfRawData);
+                free(pData);
+                fclose(pDestFile);
+                fprintf(stderr, "Failed to write %u bytes to destination file\n",
+                        (unsigned int)pSectionHeader->SizeOfRawData);
                 return -6;
             }
 
@@ -155,8 +158,8 @@ int main(int argc, char *argv[])
         pSectionHeader++;
     }
 
+    free(pData);
     fclose(pDestFile);
 
     return 0;
 }
-