60 int sectionHeadersSize,
72 int nOffset=0,nNextOffset=0;
74 char*
pName,szCurrentPath[2048];
78 char* pCopyExeName =
temp;
85 memset((
void*)&SymbolFileHeader,0,
sizeof(SymbolFileHeader));
96 pCopyExeName = pSlash+1;
100 printf(
"Cannot convert string to multibyte: %s\n", pCopyExeName );
101 wcscpy(SymbolFileHeader.name,tempstr);
120 nOffset += nNextOffset;
121 nNextOffset = pStabCopy->
n_value;
127 if(
pName[strLen-1]!=
'/')
217 SymbolFileHeader.ulSizeOfHeader = sectionHeadersSize;
219 SymbolFileHeader.ulSizeOfGlobals = nGlobalLen;
221 SymbolFileHeader.ulSizeOfGlobalsStrings = nGlobalStrLen;
222 SymbolFileHeader.ulOffsetToStabs =
sizeof(
PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen+nGlobalStrLen;
223 SymbolFileHeader.ulSizeOfStabs = nStabLen;
224 SymbolFileHeader.ulOffsetToStabsStrings =
sizeof(
PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen+nGlobalStrLen+nStabLen;
225 SymbolFileHeader.ulSizeOfStabsStrings = nStrLen;
226 SymbolFileHeader.ulOffsetToSrcFiles =
sizeof(
PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen+nGlobalStrLen+nStabLen+nStrLen;
229 printf(
"sectionHeaderSize: %ld, nGlobalLen: %ld, nGlobalStrLen: %ld, nStabLen: %ld, " 230 "nStrLen: %ld, ulCurrentSrcFile: %ld, ulOffsetToStabs: %ld\n",
231 sectionHeadersSize, nGlobalLen, nGlobalStrLen,
257 *(srctmp) = *(srctmp+2);
263 printf(
"Can't open file: %s\n", srctmp );
304 PSTAB_ENTRY* ppStab,
int* pLen,
char** ppStr,
int* pnStabStrLen)
317 *pLen =
section->SizeOfRawData;
318 printf(
"LOADER: .stab @ %x (offset %x) len = %x\n",*ppStab,
section->PointerToRawData,
section->SizeOfRawData);
322 *ppStr = (
char*)((
int)
p +
section->PointerToRawData);
323 *pnStabStrLen =
section->SizeOfRawData;
324 printf(
"LOADER: .stabstr @ %x (offset %x) len = %x\n",*ppStab,
section->PointerToRawData,
section->SizeOfRawData);
347 char szSymName[2048];
349 int nSymStrLen,nStabStrLen;
366 nSymStrLen = *((
DWORD*)pStrTab);
368 &pStab,&nStabLen,&pStr,&nStabStrLen);
370 if(pStab && nStabLen && pStr && nStabStrLen)
376 if((pDot =
strchr(szSymName,
'.')))
386 printf(
"LOADER: creating symbol file %s for %s\n",szSymName,
filename);
417 printf(
"LOADER: creation of symbol file %s failed\n",szSymName);
424 printf(
"LOADER: file %s has no data inside symbol tables\n",
filename);
427 if( !pStab || !nStabLen )
428 printf(
"LOADER: - symbol table is empty or not present\n");
429 if( !pStr || !nStabStrLen )
430 printf(
"LOADER: - string table is empty or not present\n");
436 printf(
"LOADER: file %s does not have a symbol table\n",
filename);
543 printf(
"#########################################################\n");
544 printf(
"#### Symbols LOADER/TRANSLATOR for PICE ####\n");
545 printf(
"#########################################################\n");
548 #define ACTION_NONE 0 549 #define ACTION_LOAD 1 550 #define ACTION_UNLOAD 2 551 #define ACTION_TRANS 3 552 #define ACTION_RELOAD 4 553 #define ACTION_INSTALL 5 554 #define ACTION_UNINSTALL 6 555 #define ACTION_STATUS 7 556 #define ACTION_BREAK 8 557 #define ACTION_TERMINAL 9 573 printf(
"LOADER: loading symbols from %s\n",pfilename);
581 printf(
"LOADER: unloading symbols from %s\n",pfilename);
589 printf(
"LOADER: reloading all symbols\n");
594 printf(
"LOADER: reloading DONE!\n");
598 printf(
"LOADER: an internal error has occurred at change_symbols\n");
604 printf(
"LOADER: debugger return value = -EINVAL, operation has failed\n");
610 printf(
"LOADER: debugger return value = %i, operation possibly failed\n",iRetVal);
622 char *
argv[]={
"/sbin/insmod",
"pice.o",
NULL};
627 printf(
"LOADER: trying to install debugger...\n");
631 printf(
"LOADER: debugger already installed...\n");
643 printf(
"LOADER: fork failed for execution of '%s' (errno = %u).\n",
argv[0],
err);
654 printf(
"LOADER: waiting for debugger to load...\n");
657 printf(
"LOADER: debugger loaded!\n");
660 printf(
"LOADER: Error on loading debugger! (waitpid() = %i)\n",
pid);
663 else if( !WIFEXITED(
status) )
665 printf(
"LOADER: Error on loading debugger! (ifexited = %i)\n",WIFEXITED(
status));
670 printf(
"LOADER: Error on loading debugger! (exitstatus = %u)\n",WEXITSTATUS(
status));
683 int tryuninstall(
void)
685 char *
argv[]={
"/sbin/rmmod",
"pice",
NULL};
690 printf(
"LOADER: trying to remove debugger...\n");
707 printf(
"LOADER: fork failed for execution of '%s' (errno=%u).\n",
argv[0],
err);
718 printf(
"LOADER: waiting for debugger to unload...\n");
722 printf(
"LOADER: debugger removed!\n");
725 printf(
"LOADER: Error on removing debugger! (waitpid() = %i)\n",
pid);
728 else if( !WIFEXITED(
status) )
730 printf(
"LOADER: Error on removing debugger! (ifexited = %i)\n",WIFEXITED(
status));
735 printf(
"LOADER: Error on removing debugger! (exitstatus = %u)\n",WEXITSTATUS(
status));
782 void doterminal(
void)
801 char* parg,*pfilename =
NULL;
818 else if(
strcmp(parg,
"unload")==0 ||
strcmp(parg,
"u")==0)
826 else if(
strcmp(parg,
"reload")==0 ||
strcmp(parg,
"r")==0)
830 else if(
strcmp(parg,
"verbose")==0 ||
strcmp(parg,
"v")==0)
835 else if(
strcmp(parg,
"install")==0 ||
strcmp(parg,
"i")==0)
839 else if(
strcmp(parg,
"uninstall")==0 ||
strcmp(parg,
"x")==0)
843 else if(
strcmp(parg,
"status")==0 ||
strcmp(parg,
"s")==0)
851 else if(
strcmp(parg,
"serial")==0 ||
strcmp(parg,
"ser")==0)
857 printf(
"LOADER: error: unknown switch %s",
argv[
i]);
866 if(
action == new_action )
872 printf(
"LOADER: error: conflicting switch %s",
argv[
i]);
881 printf(
"LOADER: error: additional filename %s", parg);
896 printf(
"LOADER: error: missing filename\n");
924 printf(
"LOADER: no action specified specifed on commandline\n");
929 printf(
"LOADER: an internal error has occurred at commandline parsing\n");
938 printf(
"LOADER: trying to translate file %s...\n",pfilename);
940 printf(
"LOADER: file %s has been translated\n",pfilename);
942 printf(
"LOADER: error while translating file %s\n",pfilename);
963 printf(
"LOADER: Syntax:\n");
964 printf(
"LOADER: loader [switches] [executable/object file path]\n");
965 printf(
"LOADER: Switches:\n");
966 printf(
"LOADER: -trans (-t): translate from exe to sym\n");
967 printf(
"LOADER: -load (-l): load symbols\n");
968 printf(
"LOADER: -unload (-u): unload symbols\n");
969 printf(
"LOADER: -reload (-r): reload some/all symbols\n");
970 printf(
"LOADER: -verbose (-v): be a bit more verbose\n");
971 printf(
"LOADER: -install (-i): install pICE debugger\n");
972 printf(
"LOADER: -uninstall (-x): uninstall pICE debugger\n");
973 printf(
"LOADER: -break (-b): break into debugger\n");
974 printf(
"LOADER: -serial (-ser): start serial line terminal\n");
984 printf(
"LOADER: You must be superuser!\n");
#define PICE_IOCTL_UNLOAD
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
#define PICE_IOCTL_RELOAD
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
char * strcat(char *DstString, const char *SrcString)
ACPI_SIZE strlen(const char *String)
void find_stab_sections(void *p, PIMAGE_SECTION_HEADER section, unsigned cSections, PSTAB_ENTRY *ppStab, int *pLen, char **ppStr, int *pnStabStrLen)
GLuint GLuint GLsizei count
#define INVALID_HANDLE_VALUE
DWORD WINAPI GetLastError(VOID)
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define IMAGE_DOS_SIGNATURE
_CRTIMP intptr_t __cdecl execve(_In_z_ const char *_Filename, _In_z_ char *const _ArgList[], _In_opt_z_ char *const _Env[])
char SrcFileNames[2048][2048]
struct _STAB_ENTRY STAB_ENTRY
#define IMAGE_FIRST_SECTION(NtHeader)
void process_stabs(char *pExeName, HANDLE fileout, PIMAGE_SECTION_HEADER section, int sectionHeadersSize, void *p, PSTAB_ENTRY pStab, int nStabLen, char *pStr, int nStrLen, char *pGlobals, int nGlobalLen, char *pGlobalsStr, int nGlobalStrLen)
HANDLE open_debugger(void)
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
void showpermission(void)
int process_file(char *filename)
struct _STAB_ENTRY * PSTAB_ENTRY
_Check_return_opt_ _CRTIMP int __cdecl _close(_In_ int _FileHandle)
#define IMAGE_NT_SIGNATURE
_Check_return_ _CRTIMP int __cdecl _read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)
struct _PICE_SYMBOLFILE_HEADER PICE_SYMBOLFILE_HEADER
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
int main(int argc, const char *argv[])
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
BOOLEAN SetupSerial(ULONG port, ULONG baudrate)
#define memcpy(s1, s2, n)
int ioctl(HANDLE device, DWORD ioctrlcode, PDEBUGGER_STATUS_BLOCK psb)
void close_debugger(void)
PFX_DRIVER_GLOBALS pGlobals
#define PICE_IOCTL_STATUS
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
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
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
_CRTIMP int __cdecl _open(const char *_Filename, int _OpenFlag,...)
struct _PICE_SYMBOLFILE_SOURCE PICE_SYMBOLFILE_SOURCE
#define ReadFile(a, b, c, d, e)
#define MultiByteToWideChar
char * strchr(const char *String, int ch)
char * strcpy(char *DstString, const char *SrcString)
int strcmp(const char *String1, const char *String2)
_Check_return_opt_ _CRTIMP long __cdecl _lseek(_In_ int _FileHandle, _In_ long _Offset, _In_ int _Origin)
int process_pe(char *filename, int file, void *p, int len)
static SERVICE_STATUS status
int process_switches(int argc, char *argv[])
void change_symbols(int action, char *pfilename)
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
struct _IMAGE_SYMBOL UNALIGNED * PIMAGE_SYMBOL