12#define DPRINT if(DoPrint) printf
34 unsigned long ulResult = 0;
35 unsigned long ulShift = 0;
37 unsigned long ulSize = 0;
43 ulResult |= (
current & 0x7f) << ulShift;
56 unsigned long ulShift = 0;
58 unsigned long ulSize = 0;
64 lResult |= (
current & 0x7f) << ulShift;
70 lResult |= - (1 << (ulShift));
119 unsigned long PrevFramePtr =
State->FramePtr;
153 State->Location += pc[1];
209 State->FramePtr *= 8;
214 unsigned long argsize;
215 printf(
"Warning, DW_CFA_GNU_args_size is unimplemented\n");
222 unsigned long SehType;
230 if (
State->TryLevel >= 20)
232 printf(
"WTF? Trylevel of 20 exceeded...\n");
251 if (
State->TryLevel == 20)
253 printf(
"Ooops, end of SEH with trylevel at 0!\n");
286 printf(
"Found unknow PSEH code 0x%lx\n", SehType);
296 State->FramePtrDiff =
State->FramePtr - PrevFramePtr;
297 DPRINT(
"@%p: code=%x, Loc=%lx, offset=%lx, reg=0x%lx:%s\n",
312 Code[0].CodeOffset =
State->Location - FunctionStart;
320 if (
State->Offset <= 0x7FFF8)
329 Code[1].FrameOffset = (
State->Offset / 8);
330 Code[2].FrameOffset = (
State->Offset / 8) >> 16;
339 AllocSize =
State->FramePtrDiff;
340 if (AllocSize <= 128)
343 Code[0].OpInfo = (AllocSize / 8) - 1;
346 else if (AllocSize <= 0x7FFF8)
350 Code[1].FrameOffset = AllocSize / 8;
358 Code[2].FrameOffset = (
USHORT)(AllocSize >> 16);
367 for (
i =
Info->CountOfCodes - 1;
i >= 0;
i--)
369 Info->UnwindCode[
i + cCodes] =
Info->UnwindCode[
i];
373 for (
i = 0;
i < cCodes;
i++)
378 Info->CountOfCodes += cCodes;
384#define GetxdataSize(cFuncs, cUWOP, cScopes) \
385 ( cFuncs * (sizeof(UNWIND_INFO) + 2 + 4 + 4) \
386 + cUWOP * sizeof(UNWIND_CODE) \
387 + cScopes * sizeof(C_SCOPE_TABLE_ENTRY) )
401 Info->SizeOfProlog = 0;
402 Info->CountOfCodes = 0;
403 Info->FrameRegister = 0;
404 Info->FrameOffset = 0;
410 State.Location = FunctionStart;
417 while (pInst < Cie.
Next)
424 while (pInst < pFde->Next)
432 Info->SizeOfProlog =
State.Location - FunctionStart;
438 if (
State.cScopes > 0)
441 ULONG *pExceptionHandler;
448 pExceptionHandler = (
ULONG*)((
char*)
Info + cbSize);
450 *pExceptionHandler = FunctionStart;
485 p =
File->eh_frame.p;
486 pmax = (
char*)
p +
File->eh_frame.psh->Misc.VirtualSize;
490 if (
p->CiePointer != 0)
496 while (pInst < Fde.
Next)
530 FileAlignment =
File->OptionalHeader->FileAlignment;
533 eh_frame =
File->eh_frame.p;
542 i =
File->pdata.idx =
File->UsedSections;
543 pshp =
File->pdata.psh = &
File->NewSectionHeaders[
i];
547 File->NewSectionHeaders[
i - 1].SizeOfRawData;
550 File->NewSectionHeaders[
i - 1].SizeOfRawData;
568 File->xdata.idx =
File->pdata.idx + 1;
569 pshx =
File->xdata.psh = &
File->NewSectionHeaders[
File->xdata.idx];
589 xdata_p =
File->xdata.p;
590 pmax = (
char*)eh_frame +
File->eh_frame.psh->Misc.VirtualSize - 100;
595 if (
p->CiePointer != 0)
600 pdata[
i].UnwindInfo = xdata_va;
627 for (
i = 0;
i < (cbSize + 1) /
sizeof(
WORD);
i++)
646 File->FileHeader->NumberOfSections =
File->UsedSections + 2;
649 Size =
File->xdata.psh->VirtualAddress
650 +
File->xdata.psh->SizeOfRawData;
651 File->OptionalHeader->SizeOfImage =
Size;
655 for (
i = 0;
i <
File->AllSections;
i++)
657 if (
File->UseSection[
i])
659 Size =
File->SectionHeaders[
i].SizeOfRawData;
663 p =
File->FilePtr +
File->SectionHeaders[
i].PointerToRawData;
668 Size =
File->pdata.psh->Misc.VirtualSize;
670 Size =
File->xdata.psh->Misc.VirtualSize;
672 CheckSum +=
File->HeaderSize;
673 CheckSum +=
File->pdata.psh->Misc.VirtualSize;
674 CheckSum +=
File->xdata.psh->Misc.VirtualSize;
675 File->OptionalHeader->CheckSum = CheckSum;
693 for (
i = 0;
i <
File->AllSections;
i++)
695 if (
File->UseSection[
i])
698 Size =
File->SectionHeaders[
i].SizeOfRawData;
701 p =
File->FilePtr +
File->SectionHeaders[
i].PointerToRawData;
709 Size =
File->pdata.psh->SizeOfRawData;
714 Size =
File->xdata.psh->SizeOfRawData;
724 DWORD OldChecksum, Checksum;
731 (
File->DosHeader->e_lfanew == 0
L))
733 perror(
"Input file is not a PE image.\n");
739 File->DosHeader->e_lfanew +
sizeof(
ULONG));
744 perror(
"Input file is not an x64 image.\n");
752 OldChecksum =
File->OptionalHeader->CheckSum;
753 File->OptionalHeader->CheckSum = 0;
755 Checksum +=
File->cbInFileSize;
756 if ((Checksum & 0xffff) != (OldChecksum & 0xffff))
758 fprintf(
stderr,
"Input file has incorrect PE checksum: 0x%lx (calculated: 0x%lx)\n",
759 OldChecksum, Checksum);
765 +
File->FileHeader->SizeOfOptionalHeader);
767 File->HeaderSize =
File->DosHeader->e_lfanew
770 +
File->FileHeader->SizeOfOptionalHeader;
773 File->ImageBase =
File->OptionalHeader->ImageBase;
774 File->Symbols =
File->FilePtr +
File->FileHeader->PointerToSymbolTable;
775 File->Strings = (
char*)
File->Symbols +
File->FileHeader->NumberOfSymbols * 18;
778 File->AllSections =
File->FileHeader->NumberOfSections;
781 File->UsedSections = 0;
782 File->eh_frame.idx = -1;
787 for (
i = 0;
i <
File->AllSections;
i++)
789 char *
pName = (
char*)
File->SectionHeaders[
i].Name;
790 File->UseSection[
i] = 1;
799 File->UseSection[
i] = 0;
805 File->eh_frame.psh = &
File->SectionHeaders[
i];
806 File->eh_frame.idx =
i;
807 File->eh_frame.p =
File->FilePtr +
File->eh_frame.psh->PointerToRawData;
811 if (
File->UseSection[
i])
812 File->UsedSections =
i+1;
817 File->NewSectionHeaderSize =
821 CurrentPos =
File->HeaderSize +
File->NewSectionHeaderSize;
825 for (
i = 0,
j = 0;
i <
File->UsedSections;
i++)
828 File->NewSectionHeaders[
j] =
File->SectionHeaders[
i];
831 if (
File->UseSection[
i] == 0)
834 File->NewSectionHeaders[
j].PointerToRawData = 0;
835 File->NewSectionHeaders[
j].SizeOfRawData = 0;
836 File->NewSectionHeaders[
j].Characteristics = 0xC0500080;
840 File->NewSectionHeaders[
j].PointerToRawData =
841 File->NewSectionHeaders[
j].PointerToRawData ? CurrentPos : 0;
842 CurrentPos +=
File->NewSectionHeaders[
j].SizeOfRawData;
846 if (
File->eh_frame.idx == -1)
862 int arg, argstate = 0;
863 char *SourcePath =
NULL;
900 fprintf(
stderr,
"Usage: rsym [-s <sources>] <input> <output>\n");
907 fprintf(
stderr,
"An error occured loading '%s'\n", pszInFile);
926 perror(
"Cannot open output file");
int strcmp(const char *String1, const char *String2)
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
ACPI_SIZE strlen(const char *String)
union _UNWIND_CODE UNWIND_CODE
static cab_ULONG checksum(const cab_UBYTE *data, cab_UWORD bytes, cab_ULONG csum)
@ DW_CFA_offset_extended_sf
@ DW_CFA_def_cfa_register
@ DW_CFA_restore_extended
static UINT load_file(MSIRECORD *row, LPVOID param)
#define ROUND_UP(n, align)
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
struct _IMAGE_FILE_HEADER * PIMAGE_FILE_HEADER
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
union Alignment_ Alignment
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
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 GLint GLint j
_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,...)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_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 memcpy(s1, s2, n)
struct task_struct * current
static PROTOCOLDATA * pdata
_In_ ULONG _In_ ULONG Offset
_In_ ULONG _In_ ULONG _In_ ULONG Length
struct _IMAGE_OPTIONAL_HEADER64 * PIMAGE_OPTIONAL_HEADER64
#define IMAGE_SCN_MEM_NOT_PAGED
#define IMAGE_SCN_CNT_INITIALIZED_DATA
#define IMAGE_FILE_MACHINE_AMD64
#define IMAGE_SCN_MEM_READ
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
#define IMAGE_DIRECTORY_ENTRY_EXCEPTION
struct _IMAGE_SECTION_HEADER IMAGE_SECTION_HEADER
char * convert_path(char *origpath)
ULONG StoreUnwindInfo(PUNWIND_INFO Info, PDW2FDE pFde, ULONG FunctionStart)
void WriteOutFile(FILE *handle, PFILE_INFO File)
int ParsePEHeaders(PFILE_INFO File)
void GeneratePData(PFILE_INFO File)
unsigned long DwExecIntruction(PDW2CFSTATE State, char *pc)
unsigned long DwDecodeFde(PDW2FDE Fde, char *pc)
unsigned long DwDecodeSleb128(long *pResult, char *pc)
ULONG StoreUnwindCodes(PUNWIND_INFO Info, PDW2CFSTATE State, ULONG FunctionStart)
void CountUnwindData(PFILE_INFO File)
unsigned long DwDecodeCie(PDW2CIE Cie, char *pc)
unsigned long DwDecodeUleb128(unsigned long *pResult, char *pc)
#define GetxdataSize(cFuncs, cUWOP, cScopes)
int CompFunc(const void *p1, const void *p2)
WORD CalculateChecksum(DWORD Start, void *pFile, ULONG cbSize)
struct _C_SCOPE_TABLE * PC_SCOPE_TABLE
struct _C_SCOPE_TABLE_ENTRY C_SCOPE_TABLE_ENTRY
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))
ULONG ReturnAddressRegister
C_SCOPE_TABLE_ENTRY Entry[1]
#define UWOP_SAVE_NONVOL_FAR
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_In_ UCHAR _In_ UCHAR _In_ ULONG Code