ReactOS  0.4.15-dev-506-ga3ec01c
rsym.cmake.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "rsym.h"
Include dependency graph for rsym.cmake.c:

Go to the source code of this file.

Functions

int IsDebugSection (PIMAGE_SECTION_HEADER Section)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ IsDebugSection()

int IsDebugSection ( PIMAGE_SECTION_HEADER  Section)

Definition at line 31 of file rsym.cmake.c.

32 {
33  /* This is a hack, but works for us */
34  return (Section->Name[0] == '/');
35 }
BYTE Name[IMAGE_SIZEOF_SHORT_NAME]
Definition: pedump.c:281

Referenced by main().

◆ main()

int main ( int argc  ,
char argv[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

Definition at line 37 of file rsym.cmake.c.

38 {
39  unsigned int i;
40  PSYMBOLFILE_HEADER SymbolFileHeader;
41  PIMAGE_NT_HEADERS NtHeaders;
42  PIMAGE_DOS_HEADER DosHeader;
43  PIMAGE_FILE_HEADER FileHeader;
44  PIMAGE_OPTIONAL_HEADER OptionalHeader;
45  PIMAGE_SECTION_HEADER SectionHeaders, LastSection;
46  char* path1;
47  char* path2;
48  FILE* out;
49  size_t FileSize;
50  void *FileData;
51  char elfhdr[] = { '\377', 'E', 'L', 'F' };
52 
53  if (argc != 3)
54  {
55  fprintf(stderr, "Usage: rsym <exefile> <symfile>\n");
56  exit(1);
57  }
58 
59  path1 = convert_path(argv[1]);
60  path2 = convert_path(argv[2]);
61 
62  /* Load the input file into memory */
64  if ( !FileData )
65  {
66  fprintf(stderr, "An error occured loading '%s'\n", path1);
67  exit(1);
68  }
69 
70  /* Check if MZ header exists */
71  DosHeader = (PIMAGE_DOS_HEADER) FileData;
72  if (DosHeader->e_magic != IMAGE_DOS_MAGIC || DosHeader->e_lfanew == 0L)
73  {
74  /* Ignore elf */
75  if (!memcmp(DosHeader, elfhdr, sizeof(elfhdr)))
76  exit(0);
77  perror("Input file is not a PE image.\n");
78  free(FileData);
79  exit(1);
80  }
81 
82  /* Locate the headers */
83  NtHeaders = (PIMAGE_NT_HEADERS)((char*)FileData + DosHeader->e_lfanew);
84  FileHeader = &NtHeaders->FileHeader;
85  OptionalHeader = &NtHeaders->OptionalHeader;
86 
87  /* Locate PE section headers */
88  SectionHeaders = (PIMAGE_SECTION_HEADER)((char*)OptionalHeader +
89  FileHeader->SizeOfOptionalHeader);
90 
91  /* Loop all sections */
92  for (i = 0; i < FileHeader->NumberOfSections; i++)
93  {
94  /* Check if this is a debug section */
95  if (IsDebugSection(&SectionHeaders[i]))
96  {
97  /* Make sure we have the correct characteristics */
100  }
101  }
102 
103  /* Get a pointer to the last section header */
104  LastSection = &SectionHeaders[FileHeader->NumberOfSections - 1];
105 
106  /* Set the size of the last section to cover the rest of the PE */
107  LastSection->SizeOfRawData = FileSize - LastSection->PointerToRawData;
108 
109  /* Check if the virtual section size is smaller than the raw data */
110  if (LastSection->Misc.VirtualSize < LastSection->SizeOfRawData)
111  {
112  /* Make sure the virtual size of the section cover the raw data */
113  LastSection->Misc.VirtualSize = ROUND_UP(LastSection->SizeOfRawData,
114  OptionalHeader->SectionAlignment);
115 
116  /* Fix up image size */
117  OptionalHeader->SizeOfImage = LastSection->VirtualAddress +
118  LastSection->Misc.VirtualSize;
119  }
120 
121  /* Open the output file */
122  out = fopen(path2, "wb");
123  if (out == NULL)
124  {
125  perror("Cannot open output file");
126  free(FileData);
127  exit(1);
128  }
129 
130  /* Write the output file */
131  fwrite(FileData, 1, FileSize, out);
132  fclose(out);
133  free(FileData);
134 
135  return 0;
136 }
static const WCHAR path2[]
Definition: path.c:29
static int argc
Definition: ServiceArgs.c:12
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
#define free
Definition: debug_ros.c:5
DWORD PointerToRawData
Definition: pedump.c:290
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define argv
Definition: mplay32.c:18
int IsDebugSection(PIMAGE_SECTION_HEADER Section)
Definition: rsym.cmake.c:31
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
static const WCHAR path1[]
Definition: path.c:28
#define IMAGE_DOS_MAGIC
Definition: pecoff.h:6
#define IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: ntimage.h:231
static FILE * out
Definition: regtests2xml.c:44
static const WCHAR L[]
Definition: oid.c:1250
static UINT load_file(MSIRECORD *row, LPVOID param)
Definition: action.c:1202
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
union _IMAGE_SECTION_HEADER::@1547 Misc
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
#define IMAGE_SCN_MEM_PURGEABLE
Definition: pecoff.h:30
char * convert_path(char *origpath)
Definition: rcopy.c:11
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187
#define IMAGE_SCN_MEM_DISCARDABLE
Definition: ntimage.h:235