ReactOS  r76032
symbols.c File Reference
#include "remods.h"
#include "precomp.h"
#include "stab_gnu.h"
#include <ntdll/ldr.h>
#include <ntdll/rtl.h>
#include <internal/ps.h>
#include <internal/ob.h>
#include <internal/module.h>
#include <debug.h>
Include dependency graph for symbols.c:

Go to the source code of this file.

Classes

struct  _VRET
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _VRET VRET
 
typedef struct _VRETPVRET
 

Functions

BOOLEAN Expression (PVRET pvr)
 
PVOID HEADER_TO_BODY (POBJECT_HEADER obj)
 
POBJECT_HEADER BODY_TO_HEADER (PVOID body)
 
VOID FreeModuleList (PDEBUG_MODULE pm)
 
BOOLEAN InitModuleList (PDEBUG_MODULE *ppmodule, ULONG len)
 
BOOLEAN ListUserModules (PPEB peb)
 
POBJECT FindDriverObjectDirectory (void)
 
BOOLEAN ListDriverModules (void)
 
BOOLEAN BuildModuleList (void)
 
PDEBUG_MODULE IsModuleLoaded (LPSTR p)
 
BOOLEAN ScanExports (const char *pFind, PULONG pValue)
 
BOOLEAN ReadHex (LPSTR p, PULONG pValue)
 
BOOLEAN ScanExportLine (LPSTR p, PULONG ulValue, LPSTR *ppPtrToSymbol)
 
BOOLEAN ValidityCheckSymbols (PICE_SYMBOLFILE_HEADER *pSymbols)
 
PICE_SYMBOLFILE_HEADERFindModuleSymbols (ULONG addr)
 
PDEBUG_MODULE FindModuleFromAddress (ULONG addr)
 
PDEBUG_MODULE FindModuleByName (LPSTR modname)
 
PICE_SYMBOLFILE_HEADERFindModuleSymbolsByModuleName (LPSTR modname)
 
BOOLEAN ScanExportsByAddress (LPSTR *pFind, ULONG ulValue)
 
LPSTR FindFunctionByAddress (ULONG ulValue, PULONG pulstart, PULONG pulend)
 
ULONG FindFunctionInModuleByName (LPSTR szFunctionname, PDEBUG_MODULE pd)
 
ULONG ExtractTypeNumber (LPSTR p)
 
LPSTR FindTypeDefinitionForCombinedTypes (PICE_SYMBOLFILE_HEADER *pSymbols, ULONG ulTypeNumber, ULONG ulFileNumber)
 
LPSTR FindTypeDefinition (PICE_SYMBOLFILE_HEADER *pSymbols, ULONG ulTypeNumber, ULONG ulFileNumber)
 
LPSTR TruncateString (LPSTR p, char c)
 
PLOCAL_VARIABLE FindLocalsByAddress (ULONG addr)
 
LPSTR FindSourceLineForAddress (ULONG addr, PULONG pulLineNumber, LPSTR *ppSrcStart, LPSTR *ppSrcEnd, LPSTR *ppFilename)
 
BOOLEAN FindAddressForSourceLine (ULONG ulLineNumber, LPSTR pFilename, PDEBUG_MODULE pMod, PULONG pValue)
 
ULONG ListSymbolStartingAt (PDEBUG_MODULE pMod, PICE_SYMBOLFILE_HEADER *pSymbols, ULONG index, LPSTR pOutput)
 
BOOLEAN SanityCheckExports (void)
 
BOOLEAN LoadExports (void)
 
void UnloadExports (void)
 
PICE_SYMBOLFILE_HEADERLoadSymbols (LPSTR filename)
 
BOOLEAN ReloadSymbols (void)
 
void UnloadSymbols ()
 
BOOLEAN LoadSymbolsFromConfig (BOOLEAN bIgnoreBootParams)
 
void SkipSpaces (void)
 
BOOLEAN FindGlobalStabSymbol (LPSTR pExpression, PULONG pValue, PULONG pulTypeNumber, PULONG pulFileNumber)
 
void ExtractToken (LPSTR pStringToken)
 
LPSTR ExtractTypeName (LPSTR p)
 
LONG ExtractNumber (LPSTR p)
 
BOOLEAN ExtractArray (PVRET pvr, LPSTR p)
 
PVRET ExtractStructMembers (PVRET pvr, LPSTR p)
 
BOOLEAN EvaluateSymbol (PVRET pvr, LPSTR pToken)
 
BOOLEAN Symbol (PVRET pvr)
 
void Evaluate (PICE_SYMBOLFILE_HEADER *pSymbols, LPSTR p)
 

Variables

PVOID pExports =0
 
ULONG ulExportLen =0
 
LOCAL_VARIABLE local_vars [512]
 
PICE_SYMBOLFILE_HEADERapSymbols [32] ={NULL,}
 
ULONG ulNumSymbolsLoaded =0
 
ULONG kernel_end =0
 
char tempSym [1024]
 
PULONG LocalRegs []
 
ULONG ulIndex
 
LPSTR pExpression
 
VRET vr
 
VRET vrStructMembers [1024]
 
ULONG ulNumStructMembers
 
LIST_ENTRYpModuleListHead = NULL
 
PDIRECTORY_OBJECT * pNameSpaceRoot
 
PDEBUG_MODULE pdebug_module_tail
 
PDEBUG_MODULE pdebug_module_head
 

Macro Definition Documentation

#define NDEBUG

Definition at line 44 of file symbols.c.

Typedef Documentation

typedef struct _VRET* PVRET
typedef struct _VRET VRET

Function Documentation

POBJECT_HEADER BODY_TO_HEADER ( PVOID  body)

Definition at line 111 of file symbols.c.

112 {
113  PCOMMON_BODY_HEADER chdr = (PCOMMON_BODY_HEADER)body;
114  return(CONTAINING_RECORD((&(chdr->Type)),OBJECT_HEADER,Type));
115 }
Type
Definition: Type.h:6
static const void * body(MD5_CTX *ctx, const void *data, unsigned long size)
Definition: md5.c:100
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
BOOLEAN BuildModuleList ( void  )

Definition at line 266 of file symbols.c.

Referenced by COMMAND_PROTOTYPE(), FindModuleByName(), FindModuleFromAddress(), FindModuleSymbols(), IsModuleLoaded(), and ScanExportsByAddress().

267 {
268  PPEB peb;
269  PEPROCESS tsk;
270  ENTER_FUNC();
271 
273  tsk = IoGetCurrentProcess();
274  ASSERT(IsAddressValid((ULONG)tsk));
275  if( tsk ){
276  peb = tsk->Peb;
277  if( peb ){
278  if( !ListUserModules( peb ) ){
279  LEAVE_FUNC();
280  return FALSE;
281  }
282  }
283  }
284  if( !ListDriverModules() ){
285  LEAVE_FUNC();
286  return FALSE;
287  }
288  LEAVE_FUNC();
289  return TRUE;
290 }
#define TRUE
Definition: types.h:120
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define LEAVE_FUNC()
Definition: debug.h:43
BOOLEAN ListDriverModules(void)
Definition: symbols.c:229
#define FALSE
Definition: types.h:117
struct _PEB * Peb
Definition: pstypes.h:1276
PEPROCESS NTAPI IoGetCurrentProcess(VOID)
Definition: util.c:112
PDEBUG_MODULE pdebug_module_head
Definition: init.c:46
BOOLEAN ListUserModules(PPEB peb)
Definition: symbols.c:166
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
PDEBUG_MODULE pdebug_module_tail
Definition: init.c:45
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
void Evaluate ( PICE_SYMBOLFILE_HEADER pSymbols,
LPSTR  p 
)

Definition at line 2918 of file symbols.c.

Referenced by COMMAND_PROTOTYPE().

2919 {
2920  ULONG i;
2921 
2922  PICE_memset(&vr,0,sizeof(vr));
2923  vr.pSymbols = pSymbols;
2924 
2925  pExpression = p;
2926  ulIndex=0;
2928  if(Expression(&vr))
2929  {
2930  DPRINT((1,"\nOK!\n"));
2931  DPRINT((1,"value = %x type = %x\n",vr.value,vr.type));
2932  if(vr.bStructType)
2933  {
2934  PICE_sprintf(tempSym,"struct %s %s @ %x\n",vr.type_name,p,vr.address);
2936  for(i=0;i<ulNumStructMembers;i++)
2937  {
2938  if(vrStructMembers[i].bArrayType)
2939  {
2940  PICE_sprintf(tempSym,"[%.8X %.8X] %s %s[%u]\n",
2942  vrStructMembers[i].size/8,
2943  vrStructMembers[i].type_name,
2944  vrStructMembers[i].name,
2945  vrStructMembers[i].size/8);
2946  }
2947  else if(vrStructMembers[i].bPtrType)
2948  {
2949  PICE_sprintf(tempSym,"[%.8X %.8X] %s* %s -> %x (%u)\n",
2951  vrStructMembers[i].size/8,
2952  vrStructMembers[i].type_name,
2953  vrStructMembers[i].name,
2955  vrStructMembers[i].value);
2956  }
2957  else
2958  {
2959  PICE_sprintf(tempSym,"[%.8X %.8X] %s %s = %x (%u)\n",
2961  vrStructMembers[i].size/8,
2962  vrStructMembers[i].type_name,
2963  vrStructMembers[i].name,
2965  vrStructMembers[i].value);
2966  }
2968  }
2969  }
2970  else if(vr.bArrayType)
2971  {
2972  Print(OUTPUT_WINDOW,"array\n");
2973  }
2974  else
2975  {
2976  PICE_sprintf(tempSym,"%s %s @ %x = %x (%u)\n",vr.type_name,p,vr.address,vr.value,vr.value);
2978  }
2979  }
2980  else
2981  {
2982  DPRINT((1,"\nERROR: code %x\n",vr.error));
2983  }
2984 }
ULONG ulNumStructMembers
Definition: symbols.c:96
Definition: get.c:139
char tempSym[1024]
Definition: symbols.c:58
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:797
VRET vr
Definition: symbols.c:94
GLenum GLclampf GLint i
Definition: glfuncs.h:14
PICE_SYMBOLFILE_HEADER * pSymbols
Definition: symbols.c:89
BOOLEAN bStructType
Definition: symbols.c:87
void DPRINT(...)
Definition: polytest.cpp:61
BOOLEAN bArrayType
Definition: symbols.c:88
GLuint address
Definition: glext.h:9393
ULONG type
Definition: symbols.c:78
char type_name[256]
Definition: symbols.c:85
ULONG error
Definition: symbols.c:80
ULONG value
Definition: symbols.c:77
ULONG ulIndex
Definition: symbols.c:92
ULONG address
Definition: symbols.c:83
LPSTR pExpression
Definition: symbols.c:93
GLsizeiptr size
Definition: glext.h:5919
BOOLEAN Expression(PVRET pvr)
Definition: symbols.c:2906
Definition: name.c:23
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
void PICE_memset(void *p, unsigned char c, int sz)
Definition: utils.c:228
VRET vrStructMembers[1024]
Definition: symbols.c:95
BOOLEAN EvaluateSymbol ( PVRET  pvr,
LPSTR  pToken 
)

Definition at line 2673 of file symbols.c.

Referenced by Symbol().

2674 {
2675  LPSTR pTypeDef,pTypeName,pTypeBase,pSemiColon,pStructMembers;
2676  BOOLEAN bDone = FALSE;
2677  ULONG ulType,ulBits,ulBytes;
2678  LONG lLowerRange,lUpperRange,lDelta;
2679  static char type_def[2048];
2680 
2681  DPRINT((1,"EvaluateSymbol(%s)\n",pToken));
2682 
2683  if(FindGlobalStabSymbol(pToken,&pvr->value,&pvr->type,&pvr->file))
2684  {
2685  DPRINT((1,"EvaluateSymbol(%s) pvr->value = %x pvr->type = %x\n",pToken,pvr->value,pvr->type));
2686  while(!bDone)
2687  {
2688  if(!(pTypeDef = FindTypeDefinition(pvr->pSymbols,pvr->type,pvr->file)))
2689  break;
2690  PICE_strcpy(type_def,pTypeDef);
2691 
2692  pTypeDef = type_def;
2693 
2694  pTypeName = ExtractTypeName(pTypeDef);
2695 
2696  DPRINT((1,"%s %s\n",pTypeName,pToken));
2697 
2698  PICE_strcpy(pvr->type_name,pTypeName);
2699 
2700  pTypeBase = PICE_strchr(pTypeDef,'=');
2701 
2702  if(!pTypeBase)
2703  return FALSE;
2704 
2705  pTypeBase++;
2706 
2707  switch(*pTypeBase)
2708  {
2709  case '(': // type reference
2710  ulType = ExtractTypeNumber(pTypeBase);
2711  DPRINT((1,"%x is a type reference to %x\n",pvr->type,ulType));
2712  pvr->type = ulType;
2713  break;
2714  case 'r': // subrange
2715  pTypeBase++;
2716  ulType = ExtractTypeNumber(pTypeBase);
2717  DPRINT((1,"%x is sub range of %x\n",pvr->type,ulType));
2718  if(pvr->type == ulType)
2719  {
2720  DPRINT((1,"%x is a self reference\n",pvr->type));
2721  pSemiColon = PICE_strchr(pTypeBase,';');
2722  pSemiColon++;
2723  lLowerRange = ExtractNumber(pSemiColon);
2724  pSemiColon = PICE_strchr(pSemiColon,';');
2725  pSemiColon++;
2726  lUpperRange = ExtractNumber(pSemiColon);
2727  lDelta = lUpperRange-lLowerRange;
2728  DPRINT((1,"bounds %x-%x range %x\n",lLowerRange,lUpperRange,lDelta));
2729  ulBits=0;
2730  do
2731  {
2732  ulBits++;
2733  lDelta /= 2;
2734  }while(lDelta);
2735  ulBytes = (ulBits+1)/8;
2736  if(!ulBytes)
2737  ulBytes = 4;
2738  DPRINT((1,"# of bytes = %x\n",ulBytes));
2739  pvr->address = pvr->value;
2740  if(IsRangeValid(pvr->value,ulBytes))
2741  {
2742  switch(ulBytes)
2743  {
2744  case 1:
2745  pvr->value = *(PUCHAR)pvr->value;
2746  break;
2747  case 2:
2748  pvr->value = *(PUSHORT)pvr->value;
2749  break;
2750  case 4:
2751  pvr->value = *(PULONG)pvr->value;
2752  break;
2753  }
2754  }
2755  bDone=TRUE;
2756  }
2757  else
2758  pvr->type = ulType;
2759  break;
2760  case 'a': // array type
2761  DPRINT((1,"%x array\n",pvr->type));
2762  pTypeBase++;
2763  if(!ExtractArray(pvr,pTypeBase))
2764  {
2765  bDone = TRUE;
2766  pvr->error = 1;
2767  }
2768  break;
2769  case '*': // ptr type
2770  DPRINT((1,"%x is ptr to\n",pvr->type));
2771  bDone = TRUE; // meanwhile
2772  break;
2773  case 's': // struct type [name:T(#,#)=s#membername1:(#,#),#,#;membername1:(#,#),#,#;;]
2774  // go past 's'
2775  pTypeBase++;
2776 
2777  // extract the the struct size
2778  lLowerRange = ExtractNumber(pTypeBase);
2779  DPRINT((1,"%x struct size = %x\n",pvr->type,lLowerRange));
2780 
2781  // skip over the digits
2782  while(PICE_isdigit(*pTypeBase))
2783  pTypeBase++;
2784 
2785  // the structs address is is value
2786  pvr->address = pvr->value;
2787  pvr->bStructType = TRUE;
2788 
2789  // decode the struct members. pStructMembers now points to first member name
2790  pStructMembers = pTypeBase;
2791 
2792  while(pStructMembers && *pStructMembers && *pStructMembers!=';' && ulNumStructMembers<DIM(vrStructMembers))
2793  {
2794  DPRINT((1,"EvaluateSymbol(): member #%u\n",ulNumStructMembers));
2795  // put this into our array
2797 
2799  {
2800  ULONG i;
2802 
2803  DPRINT((1,"EvaluateSymbol(): no type name\n"));
2804  for(i=0;i<ulNumStructMembers;i++)
2805  {
2806  DPRINT((1,"EvaluateSymbol(): vr[i].type_name = %s\n",vrStructMembers[i].type_name));
2807  DPRINT((1,"EvaluateSymbol(): vr[i].name = %s\n",vrStructMembers[i].name));
2808  DPRINT((1,"EvaluateSymbol(): vr[i].address = %.8X\n",vrStructMembers[i].address));
2809  DPRINT((1,"EvaluateSymbol(): vr[i].value = %.8X\n",vrStructMembers[i].value));
2810  DPRINT((1,"EvaluateSymbol(): vr[i].size = %.8X\n",vrStructMembers[i].size));
2811  DPRINT((1,"EvaluateSymbol(): vr[i].type = %.8X\n",vrStructMembers[i].type));
2812  if(pvrThis->type == vrStructMembers[i].type)
2813  {
2815  pvrThis->bArrayType = vrStructMembers[i].bArrayType;
2816  pvrThis->bPtrType = vrStructMembers[i].bPtrType;
2818  break;
2819  }
2820  }
2821  }
2822 
2823  DPRINT((1,"EvaluateSymbol(): vr.type_name = %s\n",vrStructMembers[ulNumStructMembers].type_name));
2824  DPRINT((1,"EvaluateSymbol(): vr.name = %s\n",vrStructMembers[ulNumStructMembers].name));
2825  DPRINT((1,"EvaluateSymbol(): vr.address = %.8X\n",vrStructMembers[ulNumStructMembers].address));
2826  DPRINT((1,"EvaluateSymbol(): vr.value = %.8X\n",vrStructMembers[ulNumStructMembers].value));
2827  DPRINT((1,"EvaluateSymbol(): vr.size = %.8X\n",vrStructMembers[ulNumStructMembers].size));
2828  DPRINT((1,"EvaluateSymbol(): vr.type = %.8X\n",vrStructMembers[ulNumStructMembers].type));
2829 
2830  ulNumStructMembers++;
2831 
2832  // skip to next ':'
2833  pStructMembers = PICE_strchr(pStructMembers,';');
2834  pStructMembers = PICE_strchr(pStructMembers,':');
2835  if(pStructMembers)
2836  {
2837  DPRINT((1,"EvaluateSymbol(): ptr is now %s\n",pStructMembers));
2838  // go back to where member name starts
2839  while(*pStructMembers!=';')
2840  pStructMembers--;
2841  // if ';' present, go to next char
2842  if(pStructMembers)
2843  pStructMembers++;
2844  }
2845  }
2846 
2847  bDone = TRUE; // meanwhile
2848  break;
2849  case 'u': // union type
2850  DPRINT((1,"%x union\n",pvr->type));
2851  bDone = TRUE; // meanwhile
2852  break;
2853  case 'e': // enum type
2854  DPRINT((1,"%x enum\n",pvr->type));
2855  bDone = TRUE; // meanwhile
2856  break;
2857  default:
2858  DPRINT((1,"DEFAULT %x, base: %c\n",pvr->type, *pTypeBase));
2859  pvr->address = pvr->value;
2860  if(IsRangeValid(pvr->value,ulBytes))
2861  {
2862  switch(ulBytes)
2863  {
2864  case 1:
2865  pvr->value = *(PUCHAR)pvr->value;
2866  break;
2867  case 2:
2868  pvr->value = *(PUSHORT)pvr->value;
2869  break;
2870  case 4:
2871  pvr->value = *(PULONG)pvr->value;
2872  break;
2873  }
2874  }
2875  bDone = TRUE;
2876  break;
2877  }
2878 
2879  }
2880  return TRUE;
2881  }
2882  return FALSE;
2883 }
ULONG ulNumStructMembers
Definition: symbols.c:96
Definition: get.c:139
#define TRUE
Definition: types.h:120
ULONG ExtractTypeNumber(LPSTR p)
Definition: symbols.c:1030
LONG ExtractNumber(LPSTR p)
Definition: symbols.c:2436
unsigned char * PUCHAR
Definition: retypes.h:3
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
ULONG file
Definition: symbols.c:81
char * PICE_strchr(char *s, char c)
Definition: utils.c:262
Definition: symbols.c:75
char * LPSTR
Definition: xmlstorage.h:182
int PICE_isdigit(int c)
Definition: utils.c:337
PVRET ExtractStructMembers(PVRET pvr, LPSTR p)
Definition: symbols.c:2540
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
GLenum GLclampf GLint i
Definition: glfuncs.h:14
BOOLEAN FindGlobalStabSymbol(LPSTR pExpression, PULONG pValue, PULONG pulTypeNumber, PULONG pulFileNumber)
Definition: symbols.c:2289
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
PICE_SYMBOLFILE_HEADER * pSymbols
Definition: symbols.c:89
BOOLEAN bStructType
Definition: symbols.c:87
void DPRINT(...)
Definition: polytest.cpp:61
BOOLEAN bPtrType
Definition: symbols.c:86
LPSTR ExtractTypeName(LPSTR p)
Definition: symbols.c:2412
LPSTR FindTypeDefinition(PICE_SYMBOLFILE_HEADER *pSymbols, ULONG ulTypeNumber, ULONG ulFileNumber)
Definition: symbols.c:1179
unsigned char BOOLEAN
BOOLEAN IsRangeValid(ULONG Addr, ULONG Length)
Definition: utils.c:735
BOOLEAN bArrayType
Definition: symbols.c:88
unsigned short * PUSHORT
Definition: retypes.h:2
GLuint address
Definition: glext.h:9393
ULONG type
Definition: symbols.c:78
char type_name[256]
Definition: symbols.c:85
_In_z_ PCWSTR _In_ ULONG ulType
Definition: misc.h:62
ULONG error
Definition: symbols.c:80
ULONG value
Definition: symbols.c:77
ULONG address
Definition: symbols.c:83
GLsizeiptr size
Definition: glext.h:5919
unsigned int * PULONG
Definition: retypes.h:1
#define DIM
Definition: s_texfetch.c:44
Definition: name.c:23
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN ExtractArray(PVRET pvr, LPSTR p)
Definition: symbols.c:2491
VRET vrStructMembers[1024]
Definition: symbols.c:95
BOOLEAN Expression ( PVRET  pvr)

Definition at line 2906 of file symbols.c.

Referenced by Evaluate().

2907 {
2908  if(!Symbol(pvr))
2909  return FALSE;
2910 
2911  return TRUE;
2912 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN Symbol(PVRET pvr)
Definition: symbols.c:2890
BOOLEAN ExtractArray ( PVRET  pvr,
LPSTR  p 
)

Definition at line 2491 of file symbols.c.

Referenced by EvaluateSymbol().

2492 {
2493  ULONG index_typenumber,type_number;
2495  LPSTR pTypeDef;
2496 
2497  DPRINT((1,"ExtractArray(%s)\n",p));
2498 
2499  // index-type index-type-number;lower;upper;element-type-number
2500  pvr->bArrayType = TRUE;
2501  p++;
2502  index_typenumber = ExtractTypeNumber(p);
2503  p = PICE_strchr(p,';');
2504  if(p)
2505  {
2506  p++;
2507  lower_bound = ExtractNumber(p);
2508  p = PICE_strchr(p,';');
2509  if(p)
2510  {
2511  p++;
2512 
2513  upper_bound = ExtractNumber(p);
2514  p = PICE_strchr(p,';');
2515  if(p)
2516  {
2517  p++;
2518 
2519  type_number = ExtractTypeNumber(p);
2520 
2521  DPRINT((1,"ExtractArray(): %x %x %x %x\n",index_typenumber,lower_bound,upper_bound,type_number));
2522 
2523  pTypeDef = FindTypeDefinition(pvr->pSymbols,type_number,pvr->file);
2524  if(pTypeDef)
2525  {
2526  PICE_strcpy(pvr->type_name,ExtractTypeName(pTypeDef));
2527  pvr->type = type_number;
2528  return TRUE;
2529  }
2530  }
2531  }
2532  }
2533  return FALSE;
2534 }
#define TRUE
Definition: types.h:120
ULONG ExtractTypeNumber(LPSTR p)
Definition: symbols.c:1030
LONG ExtractNumber(LPSTR p)
Definition: symbols.c:2436
ULONG file
Definition: symbols.c:81
char * PICE_strchr(char *s, char c)
Definition: utils.c:262
char * LPSTR
Definition: xmlstorage.h:182
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
#define FALSE
Definition: types.h:117
PICE_SYMBOLFILE_HEADER * pSymbols
Definition: symbols.c:89
void DPRINT(...)
Definition: polytest.cpp:61
_STLP_MOVE_TO_STD_NAMESPACE _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algo.h:481
LPSTR ExtractTypeName(LPSTR p)
Definition: symbols.c:2412
LPSTR FindTypeDefinition(PICE_SYMBOLFILE_HEADER *pSymbols, ULONG ulTypeNumber, ULONG ulFileNumber)
Definition: symbols.c:1179
BOOLEAN bArrayType
Definition: symbols.c:88
ULONG type
Definition: symbols.c:78
char type_name[256]
Definition: symbols.c:85
_STLP_MOVE_TO_STD_NAMESPACE _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algo.h:507
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
LONG ExtractNumber ( LPSTR  p)

Definition at line 2436 of file symbols.c.

Referenced by ConvertTokenToLineNumber(), EvaluateSymbol(), ExtractArray(), ExtractStructMembers(), and ExtractTypeNumber().

2437 {
2438  LONG lMinus = 1,lBase;
2439  ULONG lNumber = 0;
2440 
2441  DPRINT((0,"ExtractNumber(): %s\n",p));
2442 
2443  if(!IsAddressValid((ULONG)p) )
2444  {
2445  DPRINT((1,"ExtractNumber(): [1] invalid page %x hit!\n",p));
2446  return 0;
2447  }
2448 
2449  if(*p == '-')
2450  {
2451  lMinus = -1;
2452  p++;
2453  }
2454 
2455  if(!IsAddressValid((ULONG)p) )
2456  {
2457  DPRINT((1,"ExtractNumber(): [2] invalid page %x hit!\n",p));
2458  return 0;
2459  }
2460 
2461  if(*p != '0') // non-octal -> decimal number
2462  lBase = 10;
2463  else
2464  lBase = 8;
2465 
2466  if(!IsAddressValid((ULONG)p) )
2467  {
2468  DPRINT((1,"ExtractNumber(): [3] invalid page %x hit!\n",p));
2469  return 0;
2470  }
2471 
2472  while(PICE_isdigit(*p))
2473  {
2474  lNumber *= lBase;
2475  lNumber += *p-'0';
2476  p++;
2477  if(!IsAddressValid((ULONG)p) )
2478  {
2479  DPRINT((1,"ExtractNumber(): [4] invalid page %x hit!\n",p));
2480  return 0;
2481  }
2482  }
2483 
2484  return (lNumber*lMinus);
2485 }
int PICE_isdigit(int c)
Definition: utils.c:337
long LONG
Definition: pedump.c:60
void DPRINT(...)
Definition: polytest.cpp:61
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
PVRET ExtractStructMembers ( PVRET  pvr,
LPSTR  p 
)

Definition at line 2540 of file symbols.c.

Referenced by EvaluateSymbol().

2541 {
2542  ULONG len;
2543  static char member_name[128];
2544  LONG bit_offset,bit_size,type_number,byte_size;
2545  static VRET vr;
2546  LPSTR pTypeDef,pEqual;
2547 
2548  DPRINT((1,"ExtractStructMembers(): %s\n",p));
2549 
2550  PICE_memset(&vr,0,sizeof(vr));
2551 
2552  // name:type-number,bit-offset,bit-size
2553  len=StrLenUpToWhiteChar(p,":");
2554  if(len)
2555  {
2556  // extract member name
2557  PICE_strncpy(member_name,p,len);
2558  member_name[len]=0;
2559  DPRINT((1,"ExtractStructMembers(): member_name = %s\n",member_name));
2560 
2561  // go to char following ':'
2562  p += (len+1);
2563  if(IsAddressValid((ULONG)p) )
2564  {
2565  type_number = ExtractTypeNumber(p);
2566  DPRINT((1,"ExtractStructMembers(): type_number = %x\n",type_number));
2567 
2568  vr.type = type_number;
2569 
2570  pEqual = PICE_strchr(p,')');
2571  // see if it includes type def
2572  if(pEqual)
2573  {
2574  p = pEqual+1;
2575  if(*p == '=')
2576  {
2577  p++;
2578  if(*p == 'a')
2579  {
2580  DPRINT((1,"ExtractStructMembers(): member is array\n"));
2581  vr.bArrayType = TRUE;
2582  p = PICE_strchr(p,';');
2583  p = PICE_strchr(p,';');
2584  p = PICE_strchr(p,';');
2585  if(p)
2586  p++;
2587 
2588  type_number = ExtractTypeNumber(p);
2589  vr.father_type = type_number;
2590  }
2591  else if(*p == '*')
2592  {
2593  DPRINT((1,"ExtractStructMembers(): member is ptr\n"));
2594  vr.bPtrType = TRUE;
2595  type_number = ExtractTypeNumber(p);
2596  DPRINT((1,"ExtractStructMembers(): type_number = %x\n",type_number));
2597  vr.father_type = type_number;
2598  }
2599  else if(*p == 'u')
2600  {
2601  DPRINT((1,"ExtractStructMembers(): member is union\n"));
2602  while(*p!=';' && *(p+1)!=';' && *p!=0)p++;
2603  }
2604  }
2605  }
2606 
2607  p = PICE_strchr(p,',');
2608  if(p)
2609  {
2610  p++;
2611  bit_offset = ExtractNumber(p);
2612  DPRINT((1,"ExtractStructMembers(): bit_offset = %x\n",bit_offset));
2613  p = PICE_strchr(p,',');
2614  if(p)
2615  {
2616  p++;
2617 
2618  bit_size = ExtractNumber(p);
2619  DPRINT((1,"ExtractStructMembers(): bit_size = %x\n",bit_size));
2620 
2621  vr.address = pvr->value + bit_offset/8;
2622  vr.file = pvr->file;
2623  vr.size = bit_size;
2624  PICE_strcpy(vr.name,member_name);
2625  byte_size = (bit_size+1)/8;
2626  if(!byte_size)
2627  byte_size = 4;
2628  pvr->address = pvr->value;
2629  if(IsRangeValid(vr.address,byte_size))
2630  {
2631  switch(byte_size)
2632  {
2633  case 1:
2634  vr.value = *(PUCHAR)vr.address;
2635  break;
2636  case 2:
2637  vr.value = *(PUSHORT)vr.address;
2638  break;
2639  case 4:
2640  vr.value = *(PULONG)vr.address;
2641  break;
2642  }
2643  }
2644 
2645  DPRINT((1,"ExtractStructMembers(): member %s type %x bit_offset %x bit_size%x\n",member_name,type_number,bit_offset,bit_size));
2646 
2647  pTypeDef = FindTypeDefinition(pvr->pSymbols,type_number,pvr->file);
2648  if(pTypeDef)
2649  {
2650  DPRINT((1,"ExtractStructMembers(): pTypedef= %s\n",pTypeDef));
2651  PICE_strcpy(vr.type_name,ExtractTypeName(pTypeDef));
2652  pTypeDef = PICE_strchr(pTypeDef,':');
2653  if(pTypeDef)
2654  {
2655  pTypeDef++;
2656  type_number = ExtractTypeNumber(pTypeDef);
2657  DPRINT((1,"ExtractStructMembers(): type_number = %x\n",type_number));
2658  vr.father_type = type_number;
2659  }
2660  }
2661  }
2662  }
2663  }
2664  }
2665 
2666  return &vr;
2667 }
#define TRUE
Definition: types.h:120
ULONG ExtractTypeNumber(LPSTR p)
Definition: symbols.c:1030
LONG ExtractNumber(LPSTR p)
Definition: symbols.c:2436
ULONG size
Definition: symbols.c:82
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG file
Definition: symbols.c:81
char * PICE_strchr(char *s, char c)
Definition: utils.c:262
Definition: symbols.c:75
char * LPSTR
Definition: xmlstorage.h:182
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
VRET vr
Definition: symbols.c:94
long LONG
Definition: pedump.c:60
PICE_SYMBOLFILE_HEADER * pSymbols
Definition: symbols.c:89
char * PICE_strncpy(char *s1, char *s2, int len)
Definition: utils.c:286
void DPRINT(...)
Definition: polytest.cpp:61
BOOLEAN bPtrType
Definition: symbols.c:86
LPSTR ExtractTypeName(LPSTR p)
Definition: symbols.c:2412
LPSTR FindTypeDefinition(PICE_SYMBOLFILE_HEADER *pSymbols, ULONG ulTypeNumber, ULONG ulFileNumber)
Definition: symbols.c:1179
BOOLEAN IsRangeValid(ULONG Addr, ULONG Length)
Definition: utils.c:735
char name[256]
Definition: symbols.c:84
BOOLEAN bArrayType
Definition: symbols.c:88
unsigned short * PUSHORT
Definition: retypes.h:2
ULONG type
Definition: symbols.c:78
char type_name[256]
Definition: symbols.c:85
GLenum GLsizei len
Definition: glext.h:6722
ULONG value
Definition: symbols.c:77
ULONG address
Definition: symbols.c:83
unsigned int * PULONG
Definition: retypes.h:1
ULONG StrLenUpToWhiteChar(LPSTR p, LPSTR WhiteChars)
Definition: parse.c:3816
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
ULONG father_type
Definition: symbols.c:79
void PICE_memset(void *p, unsigned char c, int sz)
Definition: utils.c:228
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
void ExtractToken ( LPSTR  pStringToken)

Definition at line 2399 of file symbols.c.

Referenced by Symbol().

2400 {
2401  while(PICE_isalpha(pExpression[ulIndex]) || PICE_isdigit(pExpression[ulIndex]) || pExpression[ulIndex]=='_')
2402  {
2403  *pStringToken++=pExpression[ulIndex++];
2404  *pStringToken=0;
2405  }
2406 }
int PICE_isdigit(int c)
Definition: utils.c:337
ULONG ulIndex
Definition: symbols.c:92
LPSTR pExpression
Definition: symbols.c:93
int PICE_isalpha(int c)
Definition: utils.c:352
LPSTR ExtractTypeName ( LPSTR  p)

Definition at line 2412 of file symbols.c.

Referenced by EvaluateSymbol(), ExtractArray(), and ExtractStructMembers().

2413 {
2414  static char temp[1024];
2415  ULONG i;
2416 
2417  DPRINT((1,"ExtractTypeName(%s)\n",p));
2418 
2419  for(i=0;IsAddressValid((ULONG)p) && *p!=0 && *p!=':';i++,p++)
2420  temp[i] = *p;
2421 
2422  if(!IsAddressValid((ULONG)p) )
2423  {
2424  DPRINT((1,"hit invalid page %x!\n",(ULONG)p));
2425  }
2426 
2427  temp[i]=0;
2428 
2429  return temp;
2430 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
void DPRINT(...)
Definition: polytest.cpp:61
static stack_node_t temp
Definition: rpn.c:18
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
ULONG ExtractTypeNumber ( LPSTR  p)

Definition at line 1030 of file symbols.c.

Referenced by EvaluateSymbol(), ExtractArray(), ExtractStructMembers(), FindGlobalStabSymbol(), FindLocalsByAddress(), FindTypeDefinition(), and FindTypeDefinitionForCombinedTypes().

1031 {
1032  LPSTR pTypeNumber;
1033  ULONG ulTypeNumber = 0;
1034 
1035  DPRINT((0,"ExtractTypeNumber(%s)\n",p));
1036 
1037  pTypeNumber = PICE_strchr(p,'(');
1038 
1039  if(pTypeNumber)
1040  {
1041  pTypeNumber++;
1042  ulTypeNumber = ExtractNumber(pTypeNumber);
1043  ulTypeNumber <<= 16;
1044  pTypeNumber = PICE_strchr(p,',');
1045  if(pTypeNumber)
1046  {
1047  pTypeNumber++;
1048  ulTypeNumber += ExtractNumber(pTypeNumber);
1049  }
1050  else
1051  {
1052  ulTypeNumber = 0;
1053  }
1054  }
1055  return ulTypeNumber;
1056 }
LONG ExtractNumber(LPSTR p)
Definition: symbols.c:2436
char * PICE_strchr(char *s, char c)
Definition: utils.c:262
char * LPSTR
Definition: xmlstorage.h:182
void DPRINT(...)
Definition: polytest.cpp:61
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
BOOLEAN FindAddressForSourceLine ( ULONG  ulLineNumber,
LPSTR  pFilename,
PDEBUG_MODULE  pMod,
PULONG  pValue 
)

Definition at line 1689 of file symbols.c.

Referenced by ConvertTokenToLineNumber().

1690 {
1691  ULONG i;
1692  PSTAB_ENTRY pStab;
1693  LPSTR pStr,pName;
1694  int nStabLen;
1695  int nOffset=0,nNextOffset=0;
1696  PICE_SYMBOLFILE_HEADER* pSymbols;
1697  static char szCurrentFunction[256];
1698  static char szCurrentPath[256];
1699  ULONG strLen,addr,ulMinValue=0xFFFFFFFF;
1700  BOOLEAN bFound = FALSE;
1701 
1702  DPRINT((0,"FindAddressForSourceLine(%u,%s,%x)\n",ulLineNumber,pFilename,(ULONG)pMod));
1703 
1704  addr = (ULONG)pMod->BaseAddress;
1705 
1706  pSymbols = FindModuleSymbols(addr);
1707  if(pSymbols)
1708  {
1709  pStab = (PSTAB_ENTRY )((ULONG)pSymbols + pSymbols->ulOffsetToStabs);
1710  nStabLen = pSymbols->ulSizeOfStabs;
1711  pStr = (LPSTR)((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings);
1712 
1713  for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
1714  {
1715  pName = &pStr[pStab->n_strx + nOffset];
1716 
1717  switch(pStab->n_type)
1718  {
1719  case N_UNDF:
1720  nOffset += nNextOffset;
1721  nNextOffset = pStab->n_value;
1722  break;
1723  case N_SO:
1724  if((strLen = PICE_strlen(pName)))
1725  {
1726  if(pName[strLen-1]!='/')
1727  {
1728  if(PICE_strlen(szCurrentPath))
1729  {
1730  PICE_strcat(szCurrentPath,pName);
1731  DPRINT((0,"changing source file %s\n",szCurrentPath));
1732  }
1733  else
1734  {
1735  DPRINT((0,"changing source file %s\n",pName));
1736  PICE_strcpy(szCurrentPath,pName);
1737  }
1738  }
1739  else
1740  PICE_strcpy(szCurrentPath,pName);
1741  }
1742  else
1743  {
1744  szCurrentPath[0]=0;
1745  }
1746  break;
1747  case N_SLINE:
1748  // if we're in the function we're looking for
1749  if(PICE_strcmpi(pFilename,szCurrentPath)==0)
1750  {
1751  if(pStab->n_desc>=ulLineNumber && (pStab->n_desc-ulLineNumber)<=ulMinValue)
1752  {
1753  ulMinValue = pStab->n_desc-ulLineNumber;
1754 
1755  DPRINT((0,"code source line number #%u for offset %x in function @ %s)\n",pStab->n_desc,pStab->n_value,szCurrentFunction));
1756  addr = FindFunctionInModuleByName(szCurrentFunction,pMod);
1757  if(addr)
1758  {
1759  *pValue = addr + pStab->n_value;
1760  bFound = TRUE;
1761  }
1762  }
1763  }
1764  break;
1765  case N_FUN:
1766  if(PICE_strlen(pName))
1767  {
1768  ULONG len;
1769 
1770  len=StrLenUpToWhiteChar(pName,":");
1771  PICE_strncpy(szCurrentFunction,pName,len);
1772  szCurrentFunction[len]=0;
1773  DPRINT((0,"function %s\n",szCurrentFunction));
1774  }
1775  else
1776  {
1777  DPRINT((0,"END of function %s\n",szCurrentFunction));
1778  szCurrentFunction[0]=0;
1779  }
1780  break;
1781  }
1782  pStab++;
1783  }
1784  }
1785  return bFound;
1786 }
#define TRUE
Definition: types.h:120
unsigned short n_desc
Definition: shared.h:97
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
char * LPSTR
Definition: xmlstorage.h:182
unsigned long n_value
Definition: shared.h:98
#define N_FUN
Definition: stabs.c:64
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
GLenum GLclampf GLint i
Definition: glfuncs.h:14
struct _STAB_ENTRY STAB_ENTRY
#define FALSE
Definition: types.h:117
PICE_SYMBOLFILE_HEADER * FindModuleSymbols(ULONG addr)
Definition: symbols.c:463
char * PICE_strncpy(char *s1, char *s2, int len)
Definition: utils.c:286
void DPRINT(...)
Definition: polytest.cpp:61
#define N_UNDF
Definition: stabs.c:57
struct _STAB_ENTRY * PSTAB_ENTRY
unsigned char BOOLEAN
static LPSTR pName
Definition: security.c:78
char * PICE_strcat(char *s1, char *s2)
Definition: utils.c:315
#define N_SLINE
Definition: stabs.c:72
ULONG ulOffsetToStabsStrings
Definition: shared.h:88
GLenum const GLvoid * addr
Definition: glext.h:9621
unsigned long n_strx
Definition: shared.h:94
GLenum GLsizei len
Definition: glext.h:6722
Definition: shared.h:92
#define N_SO
Definition: stabs.c:74
ULONG StrLenUpToWhiteChar(LPSTR p, LPSTR WhiteChars)
Definition: parse.c:3816
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
unsigned char n_type
Definition: shared.h:95
ULONG FindFunctionInModuleByName(LPSTR szFunctionname, PDEBUG_MODULE pd)
Definition: symbols.c:955
ULONG PICE_strcmpi(char *s1, char *s2)
Definition: utils.c:387
POBJECT FindDriverObjectDirectory ( void  )

Definition at line 202 of file symbols.c.

203 {
205  POBJECT_HEADER current_obj;
206  PDIRECTORY_OBJECT pd;
207 
208  ENTER_FUNC();
209 
210  if( pNameSpaceRoot && *pNameSpaceRoot ){
211  current = (*pNameSpaceRoot)->head.Flink;
212  while (current!=(&((*pNameSpaceRoot)->head)))
213  {
214  current_obj = CONTAINING_RECORD(current,OBJECT_HEADER,Entry);
215  DPRINT((0,"Scanning %S\n",current_obj->Name.Buffer));
216  if (_wcsicmp(current_obj->Name.Buffer, L"Modules")==0)
217  {
218  pd=HEADER_TO_BODY(current_obj);
219  DPRINT((0,"Found it %x\n",pd));
220  return pd;
221  }
222  current = current->Flink;
223  }
224  }
225  LEAVE_FUNC();
226  return NULL;
227 }
PDIRECTORY_OBJECT * pNameSpaceRoot
Definition: init.c:44
Definition: bidi.c:75
PVOID HEADER_TO_BODY(POBJECT_HEADER obj)
Definition: symbols.c:106
#define LEAVE_FUNC()
Definition: debug.h:43
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
#define ENTER_FUNC()
Definition: debug.h:42
base of all file and directory entries
Definition: entries.h:82
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
struct task_struct * current
Definition: linux.c:32
LPSTR FindFunctionByAddress ( ULONG  ulValue,
PULONG  pulstart,
PULONG  pulend 
)

Definition at line 767 of file symbols.c.

Referenced by COMMAND_PROTOTYPE(), FindLocalsByAddress(), FindSourceLineForAddress(), IntelStackWalk(), ListSWBreakpoints(), UnassembleOneLineUp(), and UnassembleOnePageUp().

768 {
769  PIMAGE_SYMBOL pSym, pSymEnd, pFoundSym;
770  LPSTR pStr;
771  PIMAGE_SECTION_HEADER pShdr;
772  PDEBUG_MODULE pd;
773  PDEBUG_MODULE pdTemp;
774  PICE_SYMBOLFILE_HEADER* pSymbols;
775  ULONG start,end;
776  static char temp4[256];
777  LPSTR pName;
778 
779  pSymbols = FindModuleSymbols(ulValue);
780  DPRINT((0,"FindFunctionByAddress(): symbols for %S @ %x \n",pSymbols->name,(ULONG)pSymbols));
781  if(pSymbols && pdebug_module_head)
782  {
783  DPRINT((0,"looking up symbol\n"));
784  pd = pdebug_module_head;
785  do
786  {
787  ASSERT(pd->size);
788  pdTemp = pd;
789 
790  //initial values for start and end.
791  start = (ULONG)pdTemp->BaseAddress;
792  end = start+pdTemp->size;
793 
794  DPRINT((0,"FindFunctionByAddress(): ulValue %x\n",ulValue));
795 
796  if(ulValue>=start && ulValue<end)
797  {
798  DPRINT((0,"FindFunctionByAddress(): address matches %S\n",(ULONG)pdTemp->name));
799  if(PICE_wcsicmp(pdTemp->name,pSymbols->name) == 0)
800  {
801  DPRINT((0,"found symbols for module %S\n",pdTemp->name));
802  pSym = (PIMAGE_SYMBOL)((ULONG)pSymbols+pSymbols->ulOffsetToGlobals);
803  pSymEnd = (PIMAGE_SYMBOL)((ULONG)pSym+pSymbols->ulSizeOfGlobals);
804  pStr = (LPSTR)((ULONG)pSymbols+pSymbols->ulOffsetToGlobalsStrings);
805  pShdr = (PIMAGE_SECTION_HEADER)((ULONG)pSymbols+pSymbols->ulOffsetToHeaders);
806 
807  if(!IsRangeValid((ULONG)pSym,sizeof(IMAGE_SYMBOL) ) ) //should we actually check all the symbols here?
808  {
809  DPRINT((0,"FindFunctionByAddress(): pSym = %x is not a valid pointer\n",(ULONG)pSym));
810  return FALSE;
811  }
812  DPRINT((0,"pSym = %x\n",pSym));
813  DPRINT((0,"pStr = %x\n",pStr));
814  DPRINT((0,"pShdr = %x\n",pShdr));
815 
816  while( pSym < pSymEnd )
817  {
818  //symbol is a function is it's type is 0x20, and section>0
819  if(( (pSym->Type == 0x20) &&
820  (pSym->SectionNumber > 0 )))
821  {
822  ULONG ulCurrAddr;
823  PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1);
824 
825  DPRINT((0,"FindFunctionByAddress(): pShdr[%x] = %x\n",pSym->SectionNumber,(ULONG)pShdrThis));
826 
827  if(!IsRangeValid((ULONG)pShdrThis,sizeof(IMAGE_SECTION_HEADER)) )
828  {
829  DPRINT((0,"ScanExportsByAddress(): pElfShdr[%x] = %x is not a valid pointer\n",pSym->SectionNumber,(ULONG)pShdrThis));
830  return FALSE;
831  }
832  //to get address in the memory we base address of the module and
833  //add offset of the section and then add offset of the symbol from
834  //the begining of the section
835  ulCurrAddr = ((ULONG)pdTemp->BaseAddress+pShdrThis->VirtualAddress+pSym->Value);
836  DPRINT((0,"FindFunctionByAddress(): CurrAddr [1] = %x\n",ulCurrAddr));
837  DPRINT((0,"%x ", ulCurrAddr));
838 
839  if(ulCurrAddr<=ulValue && ulCurrAddr>start)
840  {
841  start = ulCurrAddr;
842  pFoundSym = pSym;
843  //DPRINT((0,"FindFunctionByAddress(): CANDIDATE for start %x\n",start));
844  }
845  else if(ulCurrAddr>=ulValue && ulCurrAddr<end)
846  {
847  end = ulCurrAddr;
848  //DPRINT((0,"FindFunctionByAddress(): CANDIDATE for end %x\n",end));
849  }
850  }
851  //skip the auxiliary symbols and get the next symbol
852  pSym += pSym->NumberOfAuxSymbols + 1;
853  }
854  //we went through all the symbols for this module
855  //now start should point to the start of the function and
856  //end to the start of the next (or end of section)
857  if(pulstart)
858  *pulstart = start;
859 
860  if(pulend){
861  //just in case there is more than one code section
862  PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pFoundSym->SectionNumber-1);
863  if( end > (ULONG)pdTemp->BaseAddress+pShdrThis->SizeOfRawData ){
864  DPRINT((0,"Hmm: end=%d, end of section: %d\n", end, (ULONG)pdTemp->BaseAddress+pShdrThis->SizeOfRawData));
865  end = (ULONG)pdTemp->BaseAddress+pShdrThis->SizeOfRawData;
866  }
867  *pulend = end;
868  }
869 
870  if(pFoundSym->N.Name.Short){
871  //name is in the header. it's not zero terminated. have to copy.
872  PICE_sprintf(temp4,"%.8s", pFoundSym->N.ShortName);
873  pName = temp4;
874  DPRINT((0,"Function name: %S!%.8s",pdTemp->name,pName));
875  }
876  else{
877  ASSERT(pFoundSym->N.Name.Long<=pSymbols->ulSizeOfGlobalsStrings); //sanity check
878  pName = pStr+pFoundSym->N.Name.Long;
879  if(!IsAddressValid((ULONG)pName))
880  {
881  DPRINT((0,"FindFunctionByAddress(): pName = %x is not a valid pointer\n",pName));
882  return NULL;
883  }
884  DPRINT((0,"Function name: %S!%s",pdTemp->name,pName));
885  }
886  return pName;
887  }
888  }
889  }while((pd = pd->next) != pdebug_module_tail);
890  }
891  return NULL;
892 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
ULONG PICE_wcsicmp(WCHAR *s1, WCHAR *s2)
Definition: utils.c:504
GLuint GLuint end
Definition: gl.h:1545
char * LPSTR
Definition: xmlstorage.h:182
struct _DEBUG_MODULE_ * next
Definition: symbols.h:49
#define FALSE
Definition: types.h:117
PICE_SYMBOLFILE_HEADER * FindModuleSymbols(ULONG addr)
Definition: symbols.c:463
smooth NULL
Definition: ftsmooth.c:557
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: shared.h:83
ULONG size
Definition: symbols.h:50
void DPRINT(...)
Definition: polytest.cpp:61
struct _IMAGE_SYMBOL IMAGE_SYMBOL
static LPSTR pName
Definition: security.c:78
BOOLEAN IsRangeValid(ULONG Addr, ULONG Length)
Definition: utils.c:735
PDEBUG_MODULE pdebug_module_head
Definition: init.c:46
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
GLuint start
Definition: gl.h:1545
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: symbols.h:53
PDEBUG_MODULE pdebug_module_tail
Definition: init.c:45
ULONG ulSizeOfGlobalsStrings
Definition: shared.h:86
ULONG ulOffsetToGlobalsStrings
Definition: shared.h:86
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
struct _IMAGE_SYMBOL UNALIGNED * PIMAGE_SYMBOL
Definition: pecoff.h:241
ULONG FindFunctionInModuleByName ( LPSTR  szFunctionname,
PDEBUG_MODULE  pd 
)

Definition at line 955 of file symbols.c.

Referenced by ConvertTokenToSymbol(), FindAddressForSourceLine(), FindGlobalStabSymbol(), RevirtualizeBreakpointsForModule(), and TryToInstallVirtualSWBreakpoints().

956 {
957  ULONG i,addr;
958  PICE_SYMBOLFILE_HEADER* pSymbols=NULL;
959  PIMAGE_SYMBOL pSym, pSymEnd;
960  LPSTR pStr;
961  PIMAGE_SECTION_HEADER pShdr;
962 
963  ENTER_FUNC();
964  DPRINT((0,"FindFunctionInModuleByName(%s)\n",szFunctionname));
965  DPRINT((0,"FindFunctionInModuleByName(): mod size = %x\n",pd->size));
966  DPRINT((0,"FindFunctionInModuleByName(): module is %S\n",pd->name));
967 
968  addr = (ULONG)pd->BaseAddress;
969 
970  pSymbols = FindModuleSymbols(addr);
971  if(pSymbols)
972  {
973  DPRINT((0,"FindFunctionInModuleByName(): found symbol table for %S\n",pSymbols->name));
974  pSym = (PIMAGE_SYMBOL)((ULONG)pSymbols+pSymbols->ulOffsetToGlobals);
975  pSymEnd = (PIMAGE_SYMBOL)((ULONG)pSym+pSymbols->ulSizeOfGlobals);
976  pStr = (LPSTR)((ULONG)pSymbols+pSymbols->ulOffsetToGlobalsStrings);
977  pShdr = (PIMAGE_SECTION_HEADER)((ULONG)pSymbols+pSymbols->ulOffsetToHeaders);
978 
979  while( pSym < pSymEnd )
980  {
981  //symbol is a function is it's type is 0x20, storage class is external and section>0
982  //if(( (pSym->Type == 0x20) && (pSym->StorageClass==IMAGE_SYM_CLASS_EXTERNAL) &&
983  // (pSym->SectionNumber > 0 )))
984 
985  if(((pSym->Type == 0x0) || (pSym->Type == 0x20) ) &&
986  ((pSym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) || (pSym->StorageClass==IMAGE_SYM_CLASS_STATIC)) &&
987  (pSym->SectionNumber > 0 ))
988 
989  {
990  ULONG start;
991  LPSTR pName;
992  PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1);
993 
994  start = ((ULONG)pd->BaseAddress+pShdrThis->VirtualAddress+pSym->Value);
995  DPRINT((0,"FindFunctionInModuleByName(): %s @ %x\n",szFunctionname,start));
996 
997  if(pSym->N.Name.Short){ //if name is stored in the structure
998  //name may be not zero terminated but 8 characters max
999  DPRINT((0,"FindFunctionInModuleByName: %.8s\n", pSym->N.ShortName));
1000  pName = pSym->N.ShortName; //name is in the header
1001  if((PICE_fnncmp(pName,szFunctionname, 8) == 0) && start)
1002  {
1003  DPRINT((0,"FindFunctionInModuleByName(): symbol was in symbol table, start: %x\n", start));
1004  LEAVE_FUNC();
1005  return start;
1006  }
1007  }else{
1008  pName = pStr+pSym->N.Name.Long;
1009  DPRINT((0,"FindFunctionInModuleByName: %s\n", pName));
1010  if((PICE_fncmp(pName,szFunctionname) == 0) && start)
1011  {
1012  DPRINT((0,"FindFunctionInModuleByName(): symbol was in string table, start: %x\n", start));
1013  LEAVE_FUNC();
1014  return start;
1015  }
1016  }
1017  }
1018  //skip the auxiliary symbols and get the next symbol
1019  pSym += pSym->NumberOfAuxSymbols + 1;
1020  }
1021  }
1022  LEAVE_FUNC();
1023  return 0;
1024 }
#define LEAVE_FUNC()
Definition: debug.h:43
char * LPSTR
Definition: xmlstorage.h:182
GLenum GLclampf GLint i
Definition: glfuncs.h:14
PICE_SYMBOLFILE_HEADER * FindModuleSymbols(ULONG addr)
Definition: symbols.c:463
smooth NULL
Definition: ftsmooth.c:557
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: shared.h:83
ULONG size
Definition: symbols.h:50
void DPRINT(...)
Definition: polytest.cpp:61
static LPSTR pName
Definition: security.c:78
GLenum const GLvoid * addr
Definition: glext.h:9621
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
GLuint start
Definition: gl.h:1545
ULONG PICE_fnncmp(char *s1, char *s2, ULONG len)
Definition: utils.c:465
ULONG PICE_fncmp(char *s1, char *s2)
Definition: utils.c:434
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: symbols.h:53
#define ENTER_FUNC()
Definition: debug.h:42
ULONG ulOffsetToGlobalsStrings
Definition: shared.h:86
#define IMAGE_SYM_CLASS_STATIC
Definition: winnt_old.h:784
#define IMAGE_SYM_CLASS_EXTERNAL
Definition: compat.h:138
struct _IMAGE_SYMBOL UNALIGNED * PIMAGE_SYMBOL
Definition: pecoff.h:241
BOOLEAN FindGlobalStabSymbol ( LPSTR  pExpression,
PULONG  pValue,
PULONG  pulTypeNumber,
PULONG  pulFileNumber 
)

Definition at line 2289 of file symbols.c.

Referenced by EvaluateSymbol().

2290 {
2291  ULONG i;
2292  PSTAB_ENTRY pStab;
2293  LPSTR pStr,pName;
2294  int nStabLen;
2295  int nOffset=0,nNextOffset=0,nLen,strLen;
2296  PICE_SYMBOLFILE_HEADER* pSymbols;
2297  ULONG ulTypeNumber;
2298  static char SymbolName[1024];
2299  static char szCurrentPath[256];
2300  ULONG ulCurrentFileNumber=0;
2301  LPSTR pTypeDefIncluded;
2302  ULONG addr;
2303 
2304  // must have a current module
2305  if(pCurrentMod)
2306  {
2307  // in case we query for the kernel we need to use the fake kernel module
2308  addr = (ULONG)pCurrentMod->BaseAddress;
2309 
2310  // find the symbols for the module
2311  pSymbols = FindModuleSymbols(addr);
2312  if(pSymbols)
2313  {
2314  // prepare table access
2315  pStab = (PSTAB_ENTRY )((ULONG)pSymbols + pSymbols->ulOffsetToStabs);
2316  nStabLen = pSymbols->ulSizeOfStabs;
2317  pStr = (LPSTR)((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings);
2318  // starting at file 0
2319  *pulFileNumber = 0;
2320 
2321  // go through stabs
2322  for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
2323  {
2324  pName = &pStr[pStab->n_strx + nOffset];
2325 
2326  switch(pStab->n_type)
2327  {
2328  // an N_UNDF symbol marks a change of string table offset
2329  case N_UNDF:
2330  nOffset += nNextOffset;
2331  nNextOffset = pStab->n_value;
2332  break;
2333  // a source file symbol
2334  case N_SO:
2335  if((strLen = PICE_strlen(pName)))
2336  {
2337  if(pName[strLen-1]!='/')
2338  {
2339  ulCurrentFileNumber++;
2340  if(PICE_strlen(szCurrentPath))
2341  {
2342  PICE_strcat(szCurrentPath,pName);
2343  DPRINT((0,"changing source file %s\n",szCurrentPath));
2344  }
2345  else
2346  {
2347  DPRINT((0,"changing source file %s\n",pName));
2348  }
2349  }
2350  else
2351  PICE_strcpy(szCurrentPath,pName);
2352  }
2353  else
2354  {
2355  szCurrentPath[0]=0;
2356  }
2357  break;
2358  case N_GSYM:
2359  case N_LSYM:
2360  case N_PSYM:
2361  // symbol-name:type-identifier type-number =
2362  nLen = StrLenUpToWhiteChar(pName,":");
2363  PICE_strncpy(SymbolName,pName,nLen);
2364  SymbolName[nLen] = 0;
2365  if(PICE_strcmpi(SymbolName,pExpression)==0)
2366  {
2367  DPRINT((0,"global symbol %s\n",pName));
2368  // extract type-number from stab
2369  ulTypeNumber = ExtractTypeNumber(pName);
2370  DPRINT((0,"type number = %x, from %s\n",ulTypeNumber, pName));
2371  *pulTypeNumber = ulTypeNumber;
2372  // look for symbols address in external symbols
2373  if( pStab->n_type == N_LSYM || pStab->n_type == N_PSYM )
2374  *pValue = CurrentEBP + pStab->n_value;
2375  else *pValue = FindFunctionInModuleByName(SymbolName,pCurrentMod);
2376 
2377  DPRINT((0,"value = %x\n",*pValue));
2378  *pulFileNumber = ulCurrentFileNumber;
2379  DPRINT((0,"file = %x\n",ulCurrentFileNumber));
2380  if((pTypeDefIncluded = PICE_strchr(pName,'=')) )
2381  {
2382  DPRINT((0,"symbol includes type definition (%s)\n",pTypeDefIncluded));
2383  }
2384  return TRUE;
2385  }
2386  break;
2387  }
2388  pStab++;
2389  }
2390  }
2391  }
2392  return FALSE;
2393 }
#define TRUE
Definition: types.h:120
ULONG ExtractTypeNumber(LPSTR p)
Definition: symbols.c:1030
PDEBUG_MODULE pCurrentMod
Definition: parse.c:59
#define N_GSYM
Definition: stabs.c:63
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
char * PICE_strchr(char *s, char c)
Definition: utils.c:262
char * LPSTR
Definition: xmlstorage.h:182
unsigned long n_value
Definition: shared.h:98
#define N_PSYM
Definition: stabs.c:79
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
GLenum GLclampf GLint i
Definition: glfuncs.h:14
struct _STAB_ENTRY STAB_ENTRY
#define FALSE
Definition: types.h:117
PICE_SYMBOLFILE_HEADER * FindModuleSymbols(ULONG addr)
Definition: symbols.c:463
char * PICE_strncpy(char *s1, char *s2, int len)
Definition: utils.c:286
void DPRINT(...)
Definition: polytest.cpp:61
#define N_LSYM
Definition: stabs.c:76
#define N_UNDF
Definition: stabs.c:57
struct _STAB_ENTRY * PSTAB_ENTRY
static LPSTR pName
Definition: security.c:78
char * PICE_strcat(char *s1, char *s2)
Definition: utils.c:315
ULONG ulOffsetToStabsStrings
Definition: shared.h:88
GLenum const GLvoid * addr
Definition: glext.h:9621
unsigned long n_strx
Definition: shared.h:94
Definition: shared.h:92
#define N_SO
Definition: stabs.c:74
LPSTR pExpression
Definition: symbols.c:93
ULONG CurrentEBP
Definition: shell.c:115
ULONG StrLenUpToWhiteChar(LPSTR p, LPSTR WhiteChars)
Definition: parse.c:3816
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
unsigned char n_type
Definition: shared.h:95
ULONG FindFunctionInModuleByName(LPSTR szFunctionname, PDEBUG_MODULE pd)
Definition: symbols.c:955
ULONG PICE_strcmpi(char *s1, char *s2)
Definition: utils.c:387
PLOCAL_VARIABLE FindLocalsByAddress ( ULONG  addr)

Definition at line 1317 of file symbols.c.

Referenced by COMMAND_PROTOTYPE().

1318 {
1319  ULONG i;
1320  PSTAB_ENTRY pStab;
1321  LPSTR pStr,pName;
1322  int nStabLen;
1323  int nOffset=0,nNextOffset=0;
1324  PICE_SYMBOLFILE_HEADER* pSymbols;
1325  static char szCurrentFunction[256];
1326  static char szCurrentPath[256];
1327  LPSTR pFunctionName;
1328  ULONG start,end,strLen;
1329  ULONG ulTypeNumber,ulCurrentFileNumber=0;
1330  LPSTR pTypedef;
1331  ULONG ulNumLocalVars=0;
1332 
1333  DPRINT((0,"FindLocalsByAddress()\n"));
1334 
1335  pFunctionName = FindFunctionByAddress(addr,&start,&end);
1336  DPRINT((0,"FindLocalsByAddress(): pFunctionName = %s\n",pFunctionName));
1337  if(pFunctionName)
1338  {
1339  pSymbols = FindModuleSymbols(addr);
1340  if(pSymbols)
1341  {
1342  pStab = (PSTAB_ENTRY )((ULONG)pSymbols + pSymbols->ulOffsetToStabs);
1343  nStabLen = pSymbols->ulSizeOfStabs;
1344  pStr = (LPSTR)((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings);
1345 
1346  for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
1347  {
1348  pName = &pStr[pStab->n_strx + nOffset];
1349 
1350  DPRINT((0,"FindLocalsByAddress(): %x %x %x %x %x\n",
1351  pStab->n_strx,
1352  pStab->n_type,
1353  pStab->n_other,
1354  pStab->n_desc,
1355  pStab->n_value));
1356 
1357  switch(pStab->n_type)
1358  {
1359  case N_UNDF:
1360  nOffset += nNextOffset;
1361  nNextOffset = pStab->n_value;
1362  break;
1363  case N_SO:
1364  if((strLen = PICE_strlen(pName)))
1365  {
1366  if(pName[strLen-1]!='/')
1367  {
1368  ulCurrentFileNumber++;
1369  if(PICE_strlen(szCurrentPath))
1370  {
1371  PICE_strcat(szCurrentPath,pName);
1372  DPRINT((0,"changing source file1 %s, %u\n",szCurrentPath,ulCurrentFileNumber));
1373  }
1374  else
1375  {
1376  DPRINT((0,"changing source file %s, %u\n",pName,ulCurrentFileNumber));
1377  }
1378  }
1379  else
1380  PICE_strcpy(szCurrentPath,pName);
1381  }
1382  else
1383  {
1384  szCurrentPath[0]=0;
1385  }
1386  break;
1387  case N_LSYM:
1388  // if we're in the function we're looking for
1389  if(szCurrentFunction[0] && PICE_fncmp(szCurrentFunction,pFunctionName)==0)
1390  {
1391  DPRINT((0,"local variable1 %.8X %.8X %.8X %.8X %.8X %s\n",pStab->n_strx,pStab->n_type,pStab->n_other,pStab->n_desc,pStab->n_value,pName));
1392  ulTypeNumber = ExtractTypeNumber(pName);
1393  DPRINT((0,"type number = %u\n",ulTypeNumber));
1394  if((pTypedef = FindTypeDefinition(pSymbols,ulTypeNumber,ulCurrentFileNumber)))
1395  {
1396  DPRINT((0,"pTypedef: %x\n", pTypedef));
1397  PICE_strcpy(local_vars[ulNumLocalVars].type_name,TruncateString(pTypedef,':'));
1398  PICE_strcpy(local_vars[ulNumLocalVars].name,TruncateString(pName,':'));
1399  local_vars[ulNumLocalVars].value = (CurrentEBP+pStab->n_value);
1400  local_vars[ulNumLocalVars].offset = pStab->n_value;
1401  local_vars[ulNumLocalVars].line = pStab->n_desc;
1402  local_vars[ulNumLocalVars].bRegister = FALSE;
1403  ulNumLocalVars++;
1404  }
1405  }
1406  break;
1407  case N_PSYM:
1408  // if we're in the function we're looking for
1409  if(szCurrentFunction[0] && PICE_fncmp(szCurrentFunction,pFunctionName)==0)
1410  {
1411  DPRINT((0,"parameter variable %.8X %.8X %.8X %.8X %.8X %s\n",pStab->n_strx,pStab->n_type,pStab->n_other,pStab->n_desc,pStab->n_value,pName));
1412  ulTypeNumber = ExtractTypeNumber(pName);
1413  DPRINT((0,"type number = %x\n",ulTypeNumber));
1414  if((pTypedef = FindTypeDefinition(pSymbols,ulTypeNumber,ulCurrentFileNumber)))
1415  {
1416  PICE_strcpy(local_vars[ulNumLocalVars].type_name,TruncateString(pTypedef,':'));
1417  PICE_strcpy(local_vars[ulNumLocalVars].name,TruncateString(pName,':'));
1418  local_vars[ulNumLocalVars].value = (CurrentEBP+pStab->n_value);
1419  local_vars[ulNumLocalVars].offset = pStab->n_value;
1420  ulNumLocalVars++;
1421  }
1422  }
1423  break;
1424  case N_RSYM:
1425  // if we're in the function we're looking for
1426  if(szCurrentFunction[0] && PICE_fncmp(szCurrentFunction,pFunctionName)==0)
1427  {
1428  DPRINT((0,"local variable2 %.8X %.8X %.8X %.8X %.8X %s\n",pStab->n_strx,pStab->n_type,pStab->n_other,pStab->n_desc,pStab->n_value,pName));
1429  ulTypeNumber = ExtractTypeNumber(pName);
1430  DPRINT((0,"type number = %x\n",ulTypeNumber));
1431  if((pTypedef = FindTypeDefinition(pSymbols,ulTypeNumber,ulCurrentFileNumber)))
1432  {
1433  PICE_strcpy(local_vars[ulNumLocalVars].type_name,TruncateString(pTypedef,':'));
1434  PICE_strcpy(local_vars[ulNumLocalVars].name,TruncateString(pName,':'));
1435  local_vars[ulNumLocalVars].value = (LocalRegs[pStab->n_value]);
1436  local_vars[ulNumLocalVars].offset = pStab->n_value;
1437  local_vars[ulNumLocalVars].line = pStab->n_desc;
1438  local_vars[ulNumLocalVars].bRegister = TRUE;
1439  ulNumLocalVars++;
1440  }
1441  }
1442  break;
1443  case N_FUN:
1444  if(PICE_strlen(pName))
1445  {
1446  ULONG len;
1447 
1448  len=StrLenUpToWhiteChar(pName,":");
1449  PICE_strncpy(szCurrentFunction,pName,len);
1450  szCurrentFunction[len]=0;
1451  DPRINT((0,"function %s\n",szCurrentFunction));
1452  }
1453  else
1454  {
1455  DPRINT((0,"END of function %s\n",szCurrentFunction));
1456  szCurrentFunction[0]=0;
1457  if(ulNumLocalVars)
1458  {
1459  *local_vars[ulNumLocalVars].name = 0;
1460  return local_vars;
1461  }
1462  }
1463  break;
1464  }
1465  pStab++;
1466  }
1467  }
1468  }
1469  return NULL;
1470 }
#define TRUE
Definition: types.h:120
unsigned short n_desc
Definition: shared.h:97
ULONG ExtractTypeNumber(LPSTR p)
Definition: symbols.c:1030
PULONG LocalRegs[]
Definition: symbols.c:61
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
GLuint GLuint end
Definition: gl.h:1545
ULONG offset
Definition: symbols.h:36
char * LPSTR
Definition: xmlstorage.h:182
unsigned long n_value
Definition: shared.h:98
#define N_FUN
Definition: stabs.c:64
#define N_PSYM
Definition: stabs.c:79
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
GLenum GLclampf GLint i
Definition: glfuncs.h:14
LPSTR FindFunctionByAddress(ULONG ulValue, PULONG pulstart, PULONG pulend)
Definition: symbols.c:767
struct _STAB_ENTRY STAB_ENTRY
#define FALSE
Definition: types.h:117
LOCAL_VARIABLE local_vars[512]
Definition: symbols.c:51
PICE_SYMBOLFILE_HEADER * FindModuleSymbols(ULONG addr)
Definition: symbols.c:463
char * PICE_strncpy(char *s1, char *s2, int len)
Definition: utils.c:286
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
#define N_LSYM
Definition: stabs.c:76
#define N_UNDF
Definition: stabs.c:57
struct _STAB_ENTRY * PSTAB_ENTRY
LPSTR FindTypeDefinition(PICE_SYMBOLFILE_HEADER *pSymbols, ULONG ulTypeNumber, ULONG ulFileNumber)
Definition: symbols.c:1179
unsigned char n_other
Definition: shared.h:96
static LPSTR pName
Definition: security.c:78
char * PICE_strcat(char *s1, char *s2)
Definition: utils.c:315
char name[64]
Definition: symbols.h:35
ULONG ulOffsetToStabsStrings
Definition: shared.h:88
ULONG value
Definition: symbols.h:36
GLenum const GLvoid * addr
Definition: glext.h:9621
#define N_RSYM
Definition: stabs.c:71
LPSTR TruncateString(LPSTR p, char c)
Definition: symbols.c:1296
unsigned long n_strx
Definition: shared.h:94
GLenum GLsizei len
Definition: glext.h:6722
BOOLEAN bRegister
Definition: symbols.h:37
Definition: shared.h:92
#define N_SO
Definition: stabs.c:74
GLuint start
Definition: gl.h:1545
ULONG CurrentEBP
Definition: shell.c:115
ULONG PICE_fncmp(char *s1, char *s2)
Definition: utils.c:434
Definition: name.c:23
ULONG StrLenUpToWhiteChar(LPSTR p, LPSTR WhiteChars)
Definition: parse.c:3816
unsigned int ULONG
Definition: retypes.h:1
unsigned char n_type
Definition: shared.h:95
ULONG line
Definition: symbols.h:36
PDEBUG_MODULE FindModuleByName ( LPSTR  modname)

Definition at line 539 of file symbols.c.

540 {
541  PDEBUG_MODULE pd;
542  WCHAR tempstr[DEBUG_MODULE_NAME_LEN];
543 
544  DPRINT((0,"FindModuleFromAddress()\n"));
545  if( !PICE_MultiByteToWideChar(CP_ACP, NULL, modname, -1, tempstr, DEBUG_MODULE_NAME_LEN ) )
546  {
547  DPRINT((0,"Can't convert module name.\n"));
548  return NULL;
549  }
550 
551  if(BuildModuleList())
552  {
553  pd = pdebug_module_head;
554  do
555  {
556  if(pd->size)
557  {
558  if(PICE_wcsicmp(tempstr,pd->name) == 0)
559  {
560  DPRINT((0,"FindModuleByName(): found %S\n",pd->name));
561  return pd;
562  }
563  }
564  }while((pd = pd->next) != pdebug_module_tail);
565  }
566 
567  return NULL;
568 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
ULONG PICE_wcsicmp(WCHAR *s1, WCHAR *s2)
Definition: utils.c:504
struct _DEBUG_MODULE_ * next
Definition: symbols.h:49
INT WINAPI PICE_MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cchMultiByte, LPWSTR lpWideCharStr, int cchWideChar)
Definition: utils.c:2335
#define DEBUG_MODULE_NAME_LEN
Definition: shared.h:79
smooth NULL
Definition: ftsmooth.c:557
ULONG size
Definition: symbols.h:50
void DPRINT(...)
Definition: polytest.cpp:61
PDEBUG_MODULE pdebug_module_head
Definition: init.c:46
BOOLEAN BuildModuleList(void)
Definition: symbols.c:266
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: symbols.h:53
PDEBUG_MODULE pdebug_module_tail
Definition: init.c:45
PDEBUG_MODULE FindModuleFromAddress ( ULONG  addr)

Definition at line 507 of file symbols.c.

Referenced by COMMAND_PROTOTYPE(), and ListSWBreakpoints().

508 {
509  PDEBUG_MODULE pd;
510  ULONG start,end;
511 
512  DPRINT((0,"FindModuleFromAddress()\n"));
513  if(BuildModuleList())
514  {
515  pd = pdebug_module_head;
516  do
517  {
518  if(pd->size)
519  {
520  start = (ULONG)pd->BaseAddress;
521  end = start + pd->size;
522  DPRINT((0,"FindModuleFromAddress(): %S %x-%x\n",pd->name,start,end));
523  if(addr>=start && addr<end)
524  {
525  DPRINT((0,"FindModuleFromAddress(): found %S\n",pd->name));
526  return pd;
527  }
528  }
529  }while((pd = pd->next)!=pdebug_module_tail);
530  }
531 
532  return NULL;
533 }
GLuint GLuint end
Definition: gl.h:1545
struct _DEBUG_MODULE_ * next
Definition: symbols.h:49
smooth NULL
Definition: ftsmooth.c:557
ULONG size
Definition: symbols.h:50
void DPRINT(...)
Definition: polytest.cpp:61
PDEBUG_MODULE pdebug_module_head
Definition: init.c:46
GLenum const GLvoid * addr
Definition: glext.h:9621
BOOLEAN BuildModuleList(void)
Definition: symbols.c:266
GLuint start
Definition: gl.h:1545
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: symbols.h:53
PDEBUG_MODULE pdebug_module_tail
Definition: init.c:45
PICE_SYMBOLFILE_HEADER* FindModuleSymbols ( ULONG  addr)

Definition at line 463 of file symbols.c.

Referenced by COMMAND_PROTOTYPE(), FindAddressForSourceLine(), FindFunctionByAddress(), FindFunctionInModuleByName(), FindGlobalStabSymbol(), FindLocalsByAddress(), FindSourceLineForAddress(), and ScanExportsByAddress().

464 {
465  ULONG start,end,i;
467 
468  DPRINT((0,"FindModuleSymbols(%x)\n",addr));
469  if(BuildModuleList())
470  {
471  i=0;
472  pd = pdebug_module_head;
473  do
474  {
475  DPRINT((0,"pd: %x\n", pd));
476  if(pd->size)
477  {
478  start = (ULONG)pd->BaseAddress;
479  end = start + pd->size;
480  DPRINT((0,"FindModuleSymbols(): %S %x-%x\n",pd->name,start,end));
481  if(addr>=start && addr<end)
482  {
483  DPRINT((0,"FindModuleSymbols(): address matches %S %x-%x\n",pd->name,start,end));
484  for(i=0;i<ulNumSymbolsLoaded;i++)
485  {
486  DPRINT((0,"%S -", apSymbols[i]->name ));
487  if(PICE_wcsicmp(pd->name,apSymbols[i]->name) == 0)
488  {
490  return apSymbols[i];
491  else
492  return NULL;
493  }
494  }
495  }
496  }
497  }while((pd = pd->next) != pdebug_module_tail);
498  }
499 
500  return NULL;
501 }
ULONG ulNumSymbolsLoaded
Definition: symbols.c:54
PICE_SYMBOLFILE_HEADER * apSymbols[32]
Definition: symbols.c:53
ULONG PICE_wcsicmp(WCHAR *s1, WCHAR *s2)
Definition: utils.c:504
BOOLEAN ValidityCheckSymbols(PICE_SYMBOLFILE_HEADER *pSymbols)
Definition: symbols.c:442
GLuint GLuint end
Definition: gl.h:1545
struct _DEBUG_MODULE_ * next
Definition: symbols.h:49
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:557
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: shared.h:83
ULONG size
Definition: symbols.h:50
void DPRINT(...)
Definition: polytest.cpp:61
PDEBUG_MODULE pdebug_module_head
Definition: init.c:46
GLenum const GLvoid * addr
Definition: glext.h:9621
BOOLEAN BuildModuleList(void)
Definition: symbols.c:266
GLuint start
Definition: gl.h:1545
Definition: name.c:23
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: symbols.h:53
PDEBUG_MODULE pdebug_module_tail
Definition: init.c:45
PICE_SYMBOLFILE_HEADER* FindModuleSymbolsByModuleName ( LPSTR  modname)

Definition at line 574 of file symbols.c.

575 {
576  ULONG i;
577  WCHAR tempstr[DEBUG_MODULE_NAME_LEN];
578 
579  DPRINT((0,"FindModuleSymbols()\n"));
580  if( !PICE_MultiByteToWideChar(CP_ACP, NULL, modname, -1, tempstr, DEBUG_MODULE_NAME_LEN ) )
581  {
582  DPRINT((0,"Can't convert module name in FindModuleSymbols.\n"));
583  return NULL;
584  }
585 
586  for(i=0;i<ulNumSymbolsLoaded;i++)
587  {
588  if(PICE_wcsicmp(tempstr,apSymbols[i]->name) == 0)
589  return apSymbols[i];
590  }
591 
592  return NULL;
593 }
ULONG ulNumSymbolsLoaded
Definition: symbols.c:54
PICE_SYMBOLFILE_HEADER * apSymbols[32]
Definition: symbols.c:53
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
ULONG PICE_wcsicmp(WCHAR *s1, WCHAR *s2)
Definition: utils.c:504
INT WINAPI PICE_MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cchMultiByte, LPWSTR lpWideCharStr, int cchWideChar)
Definition: utils.c:2335
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define DEBUG_MODULE_NAME_LEN
Definition: shared.h:79
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
Definition: name.c:23
unsigned int ULONG
Definition: retypes.h:1
LPSTR FindSourceLineForAddress ( ULONG  addr,
PULONG  pulLineNumber,
LPSTR ppSrcStart,
LPSTR ppSrcEnd,
LPSTR ppFilename 
)

Definition at line 1476 of file symbols.c.

Referenced by COMMAND_PROTOTYPE(), and RealIsr().

1477 {
1478  ULONG i; // index for walking through STABS
1479  PSTAB_ENTRY pStab; // pointer to STABS
1480  LPSTR pStr,pName; // pointer to STAB strings and current STAB string
1481  int nStabLen; // length of STAB section in bytes
1482  int nOffset=0,nNextOffset=0; // offset and next offset in string table
1483  PICE_SYMBOLFILE_HEADER* pSymbols; // pointer to module's STAB symbol table
1484  static char szCurrentFunction[256];
1485  static char szCurrentPath[256];
1486  static char szWantedPath[256];
1487  LPSTR pFunctionName; // name of function that brackets the current address
1488  ULONG start,end,strLen,ulMinValue=0xFFFFFFFF;
1489  LPSTR pSrcLine=NULL;
1490  BOOLEAN bFirstOccurence = TRUE;
1491 
1492  // lookup the functions name and start-end (external symbols)
1493  pFunctionName = FindFunctionByAddress(addr,&start,&end);
1494  DPRINT((0,"FindSourceLineForAddress: for function: %s\n", pFunctionName));
1495 
1496  if(pFunctionName)
1497  {
1498  // lookup the modules symbol table (STABS)
1499  pSymbols = FindModuleSymbols(addr);
1500  DPRINT((0,"FindSourceLineForAddress: pSymbols %x\n", pSymbols));
1501  if(pSymbols)
1502  {
1503  DPRINT((0,"FindSourceLineForAddress: pSymbols->ulNumberOfSrcFiles %x\n", pSymbols->ulNumberOfSrcFiles));
1504  // no source files so we don't need to lookup anything
1505  if(!pSymbols->ulNumberOfSrcFiles)
1506  return NULL;
1507 
1508  // prepare STABS access
1509  pStab = (PSTAB_ENTRY )((ULONG)pSymbols + pSymbols->ulOffsetToStabs);
1510  nStabLen = pSymbols->ulSizeOfStabs;
1511  pStr = (LPSTR)((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings);
1512 
1513  // walk over all STABS
1514  for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
1515  {
1516  // the name string corresponding to the STAB
1517  pName = &pStr[pStab->n_strx + nOffset];
1518 
1519  // switch STAB type
1520  switch(pStab->n_type)
1521  {
1522  // change offset of name strings
1523  case N_UNDF:
1524  nOffset += nNextOffset;
1525  nNextOffset = pStab->n_value;
1526  break;
1527  // source file change
1528  case N_SO:
1529  DPRINT((0,"changing source file %s\n",pName));
1530  // if filename has a length record it
1531  if((strLen = PICE_strlen(pName)))
1532  {
1533  PICE_strcpy(szCurrentPath,pName);
1534  }
1535  // else empty filename
1536  else
1537  {
1538  szCurrentPath[0]=0;
1539  }
1540  break;
1541  // sub-source file change
1542  case N_SOL:
1543  DPRINT((0,"changing sub source file %s\n",pName));
1544  // if filename has a length record it
1545  if((strLen = PICE_strlen(pName)))
1546  {
1547  PICE_strcpy(szCurrentPath,pName);
1548  }
1549  // else empty filename
1550  else
1551  {
1552  szCurrentPath[0]=0;
1553  }
1554  break;
1555  // a function symbol
1556  case N_FUN:
1557  if(!PICE_strlen(pName))
1558  {// it's the end of a function
1559  DPRINT((0,"END of function %s\n",szCurrentFunction));
1560 
1561  szCurrentFunction[0]=0;
1562 
1563  // in case we haven't had a zero delta match we return from here
1564  if(pSrcLine)
1565  return pSrcLine;
1566 
1567  break;
1568  }
1569  else
1570  {// if it has a length it's the start of a function
1571  ULONG len;
1572  // extract the name only, the type string is of no use here
1573  len=StrLenUpToWhiteChar(pName,":");
1574  PICE_strncpy(szCurrentFunction,pName,len);
1575  szCurrentFunction[len]=0;
1576 
1577  DPRINT((0,"function %s\n",szCurrentFunction));
1578  }
1579  //intentional fall through
1580 
1581  // line number
1582  case N_SLINE:
1583  // if we're in the function we're looking for
1584  if(szCurrentFunction[0] && PICE_fncmp(szCurrentFunction,pFunctionName)==0)
1585  {
1586  DPRINT((0,"cslnum#%u for addr.%x (fn @ %x) ulMinVal=%x ulDelta=%x\n",pStab->n_desc,start+pStab->n_value,start,ulMinValue,(addr-(start+pStab->n_value))));
1587 
1588  if(bFirstOccurence)
1589  {
1590  PICE_strcpy(szWantedPath,szCurrentPath);
1591  DPRINT((0,"source file must be %s\n",szWantedPath));
1592  bFirstOccurence = FALSE;
1593  }
1594  DPRINT((0,"wanted %s, current: %s\n",szWantedPath, szCurrentPath));
1595  // we might have a match if our address is greater than the one in the STAB
1596  // and we're lower or equal than minimum value
1597  if(addr>=start+pStab->n_value &&
1598  (addr-(start+pStab->n_value))<=ulMinValue &&
1599  PICE_strcmpi(szWantedPath,szCurrentPath)==0 )
1600  {
1601  ULONG j;
1603 
1604  DPRINT((0,"code source line number #%u for addr. %x found!\n",pStab->n_desc,start+pStab->n_value));
1605 
1606  // compute new minimum
1607  ulMinValue = addr-(start+pStab->n_value);
1608 
1609  // if we have a pointer for storage of line number, store it
1610  if(pulLineNumber)
1611  *pulLineNumber = pStab->n_desc;
1612 
1613  // NB: should put this somewhere else so that it's not done all the time
1614  // if we have source files at all
1615  DPRINT((0,"%u source files @ %x\n",pSymbols->ulNumberOfSrcFiles,pSrc));
1616 
1617  // for all source files in this module
1618  for(j=0;j<pSymbols->ulNumberOfSrcFiles;j++)
1619  {
1620  LPSTR pSlash;
1621  ULONG currlen, fnamelen;
1622 
1623  currlen = PICE_strlen( szCurrentPath );
1624  fnamelen = PICE_strlen( pSrc->filename );
1625  pSlash = pSrc->filename + fnamelen - currlen;
1626 
1627  //DPRINT((0,"pSlash: %s, szCurrentPath: %s\n", pSlash, szCurrentPath));
1628  // if base name matches current path we have found the correct source file
1629  if(PICE_strcmpi(pSlash,szCurrentPath)==0)
1630  {
1631  // the linenumber
1632  ULONG k = pStab->n_desc;
1633 
1634  DPRINT((0,"found src file %s @ %x\n",pSrc->filename,pSrc));
1635 
1636  // store the pointer to the filename
1637  if(ppFilename)
1638  *ppFilename = pSrc->filename;
1639 
1640  if(pSrc->ulOffsetToNext > sizeof(PICE_SYMBOLFILE_SOURCE))
1641  {
1642  // get a pointer to the source file (right after the file header)
1643  pSrcLine = (LPSTR)((ULONG)pSrc+sizeof(PICE_SYMBOLFILE_SOURCE));
1644 
1645  // store the source start and end address
1646  if(ppSrcStart)
1647  *ppSrcStart = pSrcLine;
1648  if(ppSrcEnd)
1649  *ppSrcEnd = pSrcLine+pSrc->ulOffsetToNext-sizeof(PICE_SYMBOLFILE_SOURCE);
1650 
1651  // goto to the right line
1652  while(--k)
1653  {
1654  while(*pSrcLine!=0 && *pSrcLine!=0x0a && *pSrcLine!=0x0d)
1655  pSrcLine++;
1656  if(!IsAddressValid((ULONG)pSrcLine))
1657  return NULL;
1658  pSrcLine++;
1659  }
1660 
1661  if(ulMinValue == 0)
1662  return pSrcLine;
1663  }
1664  else
1665  {
1666  DPRINT((0,"src file descriptor found, but contains no source\n"));
1667  }
1668 
1669  break;
1670  }
1671  (ULONG)pSrc += pSrc->ulOffsetToNext;
1672  }
1673  }
1674  }
1675  break;
1676  }
1677  pStab++;
1678  }
1679  }
1680  }
1681  DPRINT((0,"FindSourceLineForAddress: exit 1\n"));
1682  return NULL;
1683 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define TRUE
Definition: types.h:120
unsigned short n_desc
Definition: shared.h:97
ULONG ulOffsetToSrcFiles
Definition: shared.h:89
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
ULONG ulNumberOfSrcFiles
Definition: shared.h:89
GLuint GLuint end
Definition: gl.h:1545
char * LPSTR
Definition: xmlstorage.h:182
unsigned long n_value
Definition: shared.h:98
#define N_FUN
Definition: stabs.c:64
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
#define N_SOL
Definition: stabs.c:78
GLenum GLclampf GLint i
Definition: glfuncs.h:14
LPSTR FindFunctionByAddress(ULONG ulValue, PULONG pulstart, PULONG pulend)
Definition: symbols.c:767
struct _STAB_ENTRY STAB_ENTRY
#define FALSE
Definition: types.h:117
char filename[256]
Definition: shared.h:103
PICE_SYMBOLFILE_HEADER * FindModuleSymbols(ULONG addr)
Definition: symbols.c:463
char * PICE_strncpy(char *s1, char *s2, int len)
Definition: utils.c:286
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
#define N_UNDF
Definition: stabs.c:57
struct _STAB_ENTRY * PSTAB_ENTRY
unsigned char BOOLEAN
static LPSTR pName
Definition: security.c:78
#define N_SLINE
Definition: stabs.c:72
ULONG ulOffsetToStabsStrings
Definition: shared.h:88
GLenum const GLvoid * addr
Definition: glext.h:9621
unsigned long n_strx
Definition: shared.h:94
GLenum GLsizei len
Definition: glext.h:6722
Definition: shared.h:92
#define N_SO
Definition: stabs.c:74
GLuint start
Definition: gl.h:1545
struct _PICE_SYMBOLFILE_SOURCE PICE_SYMBOLFILE_SOURCE
ULONG PICE_fncmp(char *s1, char *s2)
Definition: utils.c:434
ULONG StrLenUpToWhiteChar(LPSTR p, LPSTR WhiteChars)
Definition: parse.c:3816
unsigned int ULONG
Definition: retypes.h:1
LOCAL int currlen
Definition: rock.c:98
unsigned char n_type
Definition: shared.h:95
int k
Definition: mpi.c:3369
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
ULONG PICE_strcmpi(char *s1, char *s2)
Definition: utils.c:387
LPSTR FindTypeDefinition ( PICE_SYMBOLFILE_HEADER pSymbols,
ULONG  ulTypeNumber,
ULONG  ulFileNumber 
)

Definition at line 1179 of file symbols.c.

Referenced by EvaluateSymbol(), ExtractArray(), ExtractStructMembers(), and FindLocalsByAddress().

1180 {
1181  ULONG i;
1182  PSTAB_ENTRY pStab;
1183  LPSTR pStr,pName,pTypeString;
1184  int nStabLen;
1185  int nOffset=0,nNextOffset=0,strLen;
1186  static char szAccumulatedName[2048];
1187  ULONG ulCurrentTypeNumber,ulCurrentFileNumber=0;
1188  LPSTR pTypeSymbol;
1189  static char szCurrentPath[256];
1190 
1191  ENTER_FUNC();
1192  DPRINT((0,"FindTypeDefinition(%u,%u)\n",ulTypeNumber,ulFileNumber));
1193 
1194  *szAccumulatedName = 0;
1195 
1196  pStab = (PSTAB_ENTRY )((ULONG)pSymbols + pSymbols->ulOffsetToStabs);
1197  nStabLen = pSymbols->ulSizeOfStabs;
1198  pStr = (LPSTR)((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings);
1199 
1200  for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
1201  {
1202  pName = &pStr[pStab->n_strx + nOffset];
1203 
1204  switch(pStab->n_type)
1205  {
1206  case N_UNDF:
1207  nOffset += nNextOffset;
1208  nNextOffset = pStab->n_value;
1209  break;
1210  case N_SO:
1211  if((strLen = PICE_strlen(pName)))
1212  {
1213  if(pName[strLen-1]!='/')
1214  {
1215  ulCurrentFileNumber++;
1216  if(PICE_strlen(szCurrentPath))
1217  {
1218  PICE_strcat(szCurrentPath,pName);
1219  DPRINT((0,"FindTypeDefinition()1: cha %s, %u\n",szCurrentPath, ulCurrentFileNumber));
1220  }
1221  else
1222  {
1223  DPRINT((0,"FindTypeDefinition(): cha %s, %u\n",pName, ulCurrentFileNumber));
1224  }
1225  }
1226  else
1227  PICE_strcpy(szCurrentPath,pName);
1228  }
1229  else
1230  {
1231  szCurrentPath[0]=0;
1232  }
1233  break;
1234  case N_LSYM:
1235  // stab has no value -> must be type definition
1236  //ei File number count is not reliable
1237  if(pStab->n_value == 0 /*&& ulCurrentFileNumber==ulFileNumber*/)
1238  {
1239  DPRINT((0,"FindTypeDefinition(): pre type definition %s\n",pName));
1240  // handle multi-line symbols
1241  if(strrchr(pName,'\\'))
1242  {
1243  if(PICE_strlen(szAccumulatedName))
1244  {
1245  PICE_strcat(szAccumulatedName,pName);
1246  DPRINT((0,"FindTypeDefinition(): [1] accum. %s\n",szAccumulatedName));
1247  }
1248  else
1249  {
1250  PICE_strcpy(szAccumulatedName,pName);
1251  DPRINT((0,"FindTypeDefinition(): [2] accum. %s\n",szAccumulatedName));
1252  }
1253  szAccumulatedName[PICE_strlen(szAccumulatedName)-1]=0;
1254  }
1255  else
1256  {
1257  DPRINT((0,"FindTypeDefinition(): [3] accum. %s, pname: %s\n",szAccumulatedName, pName));
1258  if(PICE_strlen(szAccumulatedName)==0)
1259  {
1260  PICE_strcpy(szAccumulatedName,pName);
1261  }
1262  else
1263  {
1264  PICE_strcat(szAccumulatedName,pName);
1265  }
1266  pTypeString = szAccumulatedName;
1267 
1268  pTypeSymbol = PICE_strchr(pTypeString,':');
1269  if(pTypeSymbol && (*(pTypeSymbol+1)=='t' || *(pTypeSymbol+1)=='T'))
1270  {
1271  // parse it
1272  ulCurrentTypeNumber = ExtractTypeNumber(pTypeString);
1273  DPRINT((0,"FindTypeDefinition(): ulCurrType: %u, LSYM is type %s\n",ulCurrentTypeNumber,pName));
1274  if(ulCurrentTypeNumber == ulTypeNumber)
1275  {
1276  DPRINT((0,"FindTypeDefinition(): type definition %s\n",pTypeString));
1277  return pTypeString;
1278  }
1279  }
1280  *szAccumulatedName=0;
1281  }
1282  }
1283  break;
1284  }
1285  pStab++;
1286  }
1287 
1288  return FindTypeDefinitionForCombinedTypes(pSymbols,ulTypeNumber,ulFileNumber);
1289 
1290 }
ULONG ExtractTypeNumber(LPSTR p)
Definition: symbols.c:1030
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
char * PICE_strchr(char *s, char c)
Definition: utils.c:262
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
LPSTR FindTypeDefinitionForCombinedTypes(PICE_SYMBOLFILE_HEADER *pSymbols, ULONG ulTypeNumber, ULONG ulFileNumber)
Definition: symbols.c:1062
char * LPSTR
Definition: xmlstorage.h:182
unsigned long n_value
Definition: shared.h:98
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
GLenum GLclampf GLint i
Definition: glfuncs.h:14
struct _STAB_ENTRY STAB_ENTRY
void DPRINT(...)
Definition: polytest.cpp:61
#define N_LSYM
Definition: stabs.c:76
#define N_UNDF
Definition: stabs.c:57
struct _STAB_ENTRY * PSTAB_ENTRY
static LPSTR pName
Definition: security.c:78
char * PICE_strcat(char *s1, char *s2)
Definition: utils.c:315
ULONG ulOffsetToStabsStrings
Definition: shared.h:88
unsigned long n_strx
Definition: shared.h:94
Definition: shared.h:92
#define N_SO
Definition: stabs.c:74
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
unsigned char n_type
Definition: shared.h:95
LPSTR FindTypeDefinitionForCombinedTypes ( PICE_SYMBOLFILE_HEADER pSymbols,
ULONG  ulTypeNumber,
ULONG  ulFileNumber 
)

Definition at line 1062 of file symbols.c.

Referenced by FindTypeDefinition().

1063 {
1064  ULONG i;
1065  PSTAB_ENTRY pStab;
1066  LPSTR pStr,pName,pTypeNumber,pTypeDefIncluded,pNameTemp;
1067  int nStabLen;
1068  int nOffset=0,nNextOffset=0,nLen;
1069  static char szAccumulatedName[2048];
1070  ULONG ulCurrentTypeNumber,ulCurrentFileNumber=0;
1071  static char szCurrentPath[256];
1072 
1073  ENTER_FUNC();
1074 
1075  *szAccumulatedName = 0;
1076 
1077  pStab = (PSTAB_ENTRY )((ULONG)pSymbols + pSymbols->ulOffsetToStabs);
1078  nStabLen = pSymbols->ulSizeOfStabs;
1079  pStr = (LPSTR)((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings);
1080 
1081  DPRINT((0,"FindTypeDefinitionForCombinedTypes()\n"));
1082 
1083  for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
1084  {
1085  pName = &pStr[pStab->n_strx + nOffset];
1086 
1087  switch(pStab->n_type)
1088  {
1089  case N_UNDF:
1090  nOffset += nNextOffset;
1091  nNextOffset = pStab->n_value;
1092  break;
1093  case N_SO:
1094  if((nLen = PICE_strlen(pName)))
1095  {
1096  if(pName[nLen-1]!='/')
1097  {
1098  ulCurrentFileNumber++;
1099  if(PICE_strlen(szCurrentPath))
1100  {
1101  PICE_strcat(szCurrentPath,pName);
1102  DPRINT((0,"FindTypeDefinitionForCombinedTypes(): changing source file %s\n",szCurrentPath));
1103  }
1104  else
1105  {
1106  DPRINT((0,"FindTypeDefinitionForCombinedTypes(): changing source file %s\n",pName));
1107  }
1108  }
1109  else
1110  PICE_strcpy(szCurrentPath,pName);
1111  }
1112  else
1113  {
1114  szCurrentPath[0]=0;
1115  }
1116  break;
1117  case N_GSYM:
1118  //ei File number count is not reliable
1119  if( 1 /*ulCurrentFileNumber == ulFileNumber*/)
1120  {
1121  DPRINT((0,"FindTypeDefinitionForCombinedTypes(): %s\n",pName));
1122 
1123  // handle multi-line symbols
1124  if(PICE_strchr(pName,'\\'))
1125  {
1126  if(PICE_strlen(szAccumulatedName))
1127  {
1128  PICE_strcat(szAccumulatedName,pName);
1129  }
1130  else
1131  {
1132  PICE_strcpy(szAccumulatedName,pName);
1133  }
1134  szAccumulatedName[PICE_strlen(szAccumulatedName)-1]=0;
1135  //DPRINT((0,"accum. %s\n",szAccumulatedName));
1136  }
1137  else
1138  {
1139  if(PICE_strlen(szAccumulatedName)==0)
1140  {
1141  PICE_strcpy(szAccumulatedName,pName);
1142  }
1143  else
1144  {
1145  PICE_strcat(szAccumulatedName,pName);
1146  }
1147  pNameTemp = szAccumulatedName;
1148 
1149  // symbol-name:type-identifier type-number =
1150  nLen = StrLenUpToWhiteChar(pNameTemp,":");
1151  if((pTypeDefIncluded = PICE_strchr(pNameTemp,'=')) && pNameTemp[nLen+1]=='G')
1152  {
1153  DPRINT((0,"FindTypeDefinitionForCombinedTypes(): symbol includes type definition (%s)\n",pNameTemp));
1154  pTypeNumber = pNameTemp+nLen+1;
1155  if((ulCurrentTypeNumber = ExtractTypeNumber(pTypeNumber)) )
1156  {
1157  DPRINT((0,"FindTypeDefinitionForCombinedTypes(): type-number %x\n",ulCurrentTypeNumber));
1158  if(ulCurrentTypeNumber == ulTypeNumber)
1159  {
1160  DPRINT((0,"FindTypeDefinitionForCombinedTypes(): typenumber %x matches!\n",ulCurrentTypeNumber));
1161  return pNameTemp;
1162  }
1163  }
1164  }
1165  *szAccumulatedName = 0;
1166  }
1167  }
1168  break;
1169  }
1170  pStab++;
1171  }
1172  return NULL;
1173 }
ULONG ExtractTypeNumber(LPSTR p)
Definition: symbols.c:1030
#define N_GSYM
Definition: stabs.c:63
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
char * PICE_strchr(char *s, char c)
Definition: utils.c:262
char * LPSTR
Definition: xmlstorage.h:182
unsigned long n_value
Definition: shared.h:98
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
GLenum GLclampf GLint i
Definition: glfuncs.h:14
struct _STAB_ENTRY STAB_ENTRY
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
#define N_UNDF
Definition: stabs.c:57
struct _STAB_ENTRY * PSTAB_ENTRY
static LPSTR pName
Definition: security.c:78
char * PICE_strcat(char *s1, char *s2)
Definition: utils.c:315
ULONG ulOffsetToStabsStrings
Definition: shared.h:88
unsigned long n_strx
Definition: shared.h:94
Definition: shared.h:92
#define N_SO
Definition: stabs.c:74
ULONG StrLenUpToWhiteChar(LPSTR p, LPSTR WhiteChars)
Definition: parse.c:3816
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
unsigned char n_type
Definition: shared.h:95
VOID FreeModuleList ( PDEBUG_MODULE  pm)

Definition at line 121 of file symbols.c.

Referenced by InitModuleList(), and InitPICE().

122 {
123  PDEBUG_MODULE pNext = pm;
124 
125  ENTER_FUNC();
126 
127  while( pNext ){
128  pNext = pm->next;
129  ExFreePool( pm );
130  }
131  LEAVE_FUNC();
132 }
static LPMONITOREX pm
Definition: localmon.c:42
#define LEAVE_FUNC()
Definition: debug.h:43
struct _DEBUG_MODULE_ * next
Definition: symbols.h:49
#define ENTER_FUNC()
Definition: debug.h:42
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
PVOID HEADER_TO_BODY ( POBJECT_HEADER  obj)

Definition at line 106 of file symbols.c.

Referenced by FindDriverObjectDirectory().

107 {
108  return(((void *)obj)+sizeof(OBJECT_HEADER)-sizeof(COMMON_BODY_HEADER));
109 }
BOOLEAN InitModuleList ( PDEBUG_MODULE ppmodule,
ULONG  len 
)

Definition at line 138 of file symbols.c.

Referenced by InitPICE().

139 {
140  ULONG i;
141  PDEBUG_MODULE pNext = NULL, pm = *ppmodule;
142 
143  ENTER_FUNC();
144 
145  ASSERT(pm==NULL);
146 
147  for(i=1;i<=len;i++){
149  if( !pm ){
150  FreeModuleList(pNext);
151  return FALSE;
152  }
153  pm->next = pNext;
154  pm->size = 0;
155  pm->BaseAddress = NULL;
156  //DbgPrint("len1: %d\n", pm->name.Length);
157  pNext = pm;
158  }
159  *ppmodule = pm;
160 
161  LEAVE_FUNC();
162 
163  return TRUE;
164 }
#define TRUE
Definition: types.h:120
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
static LPMONITOREX pm
Definition: localmon.c:42
#define LEAVE_FUNC()
Definition: debug.h:43
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:557
ULONG size
Definition: symbols.h:50
VOID FreeModuleList(PDEBUG_MODULE pm)
Definition: symbols.c:121
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
GLenum GLsizei len
Definition: glext.h:6722
struct define * next
Definition: wpp.c:35
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
struct _DEBUG_MODULE_ * PDEBUG_MODULE
PDEBUG_MODULE IsModuleLoaded ( LPSTR  p)

Definition at line 296 of file symbols.c.

Referenced by COMMAND_PROTOTYPE(), ConvertTokenToSymbol(), and TryToInstallVirtualSWBreakpoints().

297 {
298  PDEBUG_MODULE pd;
299 
300  ENTER_FUNC();
301  DPRINT((0,"IsModuleLoaded(%s)\n",p));
302 
303  if(BuildModuleList())
304  {
305  pd = pdebug_module_head;
306  do
307  {
309  DPRINT((0,"module (%x) %S\n",pd->size,pd->name));
310  CopyWideToAnsi(temp,pd->name);
311  if(pd->size && PICE_strcmpi(p,temp) == 0)
312  {
313  DPRINT((0,"module %S is loaded!\n",pd->name));
314  LEAVE_FUNC();
315  return pd;
316  }
317  }while((pd = pd->next)!=pdebug_module_tail);
318  }
319  LEAVE_FUNC();
320  return NULL;
321 }
#define LEAVE_FUNC()
Definition: debug.h:43
struct _DEBUG_MODULE_ * next
Definition: symbols.h:49
#define DEBUG_MODULE_NAME_LEN
Definition: shared.h:79
smooth NULL
Definition: ftsmooth.c:557
ULONG size
Definition: symbols.h:50
void DPRINT(...)
Definition: polytest.cpp:61
PDEBUG_MODULE pdebug_module_head
Definition: init.c:46
static stack_node_t temp
Definition: rpn.c:18
void CopyWideToAnsi(LPSTR pAnsi, PWSTR pWide)
Definition: utils.c:591
BOOLEAN BuildModuleList(void)
Definition: symbols.c:266
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: symbols.h:53
#define ENTER_FUNC()
Definition: debug.h:42
PDEBUG_MODULE pdebug_module_tail
Definition: init.c:45
GLfloat GLfloat p
Definition: glext.h:8902
ULONG PICE_strcmpi(char *s1, char *s2)
Definition: utils.c:387
BOOLEAN ListDriverModules ( void  )

Definition at line 229 of file symbols.c.

Referenced by BuildModuleList().

230 {
231  PLIST_ENTRY current_entry;
232  PMODULE_OBJECT current;
233  POBJECT_HEADER current_obj;
234 
235  ENTER_FUNC();
236 
238 
239  current_entry = pModuleListHead->Flink;
240 
241  while (current_entry != (pModuleListHead)){
242 
243  current = CONTAINING_RECORD(current_entry,MODULE_OBJECT,ListEntry);
244 
245  DPRINT((0,"FullName: %S, BaseName: %S, Length: %ld, EntryPoint: %x\n", current->FullName.Buffer,
246  current->BaseName.Buffer, current->Length, current->EntryPoint ));
247 
248  pdebug_module_tail->BaseAddress = current->Base;
249  pdebug_module_tail->size = current->Length;
250  PICE_wcscpy( pdebug_module_tail->name, current->BaseName.Buffer);
251  pdebug_module_tail->EntryPoint = current->EntryPoint;
252 
254 
255  if (current && _wcsicmp(current->BaseName.Buffer, L"ntoskrnl")==0)
256  {
257  kernel_end = (ULONG)current->Base + current->Length;
258  }
259  current_entry = current_entry->Flink;
260  }
261 
262  LEAVE_FUNC();
263  return TRUE;
264 }
#define TRUE
Definition: types.h:120
Definition: bidi.c:75
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define LEAVE_FUNC()
Definition: debug.h:43
struct _DEBUG_MODULE_ * next
Definition: symbols.h:49
PVOID EntryPoint
Definition: symbols.h:52
ULONG size
Definition: symbols.h:50
void DPRINT(...)
Definition: polytest.cpp:61
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
ULONG kernel_end
Definition: symbols.c:56
WCHAR * PICE_wcscpy(WCHAR *str1, const WCHAR *str2)
Definition: utils.c:559
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: symbols.h:53
#define ENTER_FUNC()
Definition: debug.h:42
PDEBUG_MODULE pdebug_module_tail
Definition: init.c:45
LIST_ENTRY * pModuleListHead
Definition: symbols.c:100
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
struct task_struct * current
Definition: linux.c:32
ULONG ListSymbolStartingAt ( PDEBUG_MODULE  pMod,
PICE_SYMBOLFILE_HEADER pSymbols,
ULONG  index,
LPSTR  pOutput 
)

Definition at line 1792 of file symbols.c.

Referenced by COMMAND_PROTOTYPE().

1793 {
1794  PIMAGE_SYMBOL pSym, pSymEnd;
1795  LPSTR pStr;
1796  PIMAGE_SECTION_HEADER pShdr;
1797 
1798  DPRINT((0,"ListSymbolStartingAt(%x,%u)\n",(ULONG)pSymbols,index));
1799  DPRINT((0,"ListSymbolStartingAt(): ulOffsetToGlobals = %x ulSizeofGlobals = %x\n",pSymbols->ulOffsetToGlobals,pSymbols->ulSizeOfGlobals));
1800  pSym = (PIMAGE_SYMBOL)((ULONG)pSymbols+pSymbols->ulOffsetToGlobals);
1801  pSymEnd = (PIMAGE_SYMBOL)((ULONG)pSym+pSymbols->ulSizeOfGlobals);
1802  pStr = (LPSTR)((ULONG)pSymbols+pSymbols->ulOffsetToGlobalsStrings);
1803  pShdr = (PIMAGE_SECTION_HEADER)((ULONG)pSymbols+pSymbols->ulOffsetToHeaders);
1804 
1805  pSym += index;
1806 
1807  while( pSym < pSymEnd )
1808  {
1809  LPSTR pName;
1810 
1811  if(((pSym->Type == 0x0) || (pSym->Type == 0x20) ) &&
1812  ((pSym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) /*|| (pSym->StorageClass==IMAGE_SYM_CLASS_STATIC)*/) &&
1813  (pSym->SectionNumber > 0 ))
1814  {
1815  PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1);
1816  ULONG section_flags;
1817  ULONG start;
1818 
1819  DPRINT((0,"ListSymbolStartingAt(): pShdr[%x] = %x\n",pSym->SectionNumber,(ULONG)pShdrThis));
1820 
1821  if(!IsRangeValid((ULONG)pShdrThis,sizeof(IMAGE_SECTION_HEADER)) )
1822  {
1823  DPRINT((0,"ListSymbolStartingAt(): pShdr[%x] = %x is not a valid pointer\n",pSym->SectionNumber,(ULONG)pShdrThis));
1824  return FALSE;
1825  }
1826  section_flags = pShdrThis->Characteristics;
1827  //to get address in the memory we base address of the module and
1828  //add offset of the section and then add offset of the symbol from
1829  //the begining of the section
1830 
1831  start = ((ULONG)pMod->BaseAddress+pShdrThis->VirtualAddress+pSym->Value);
1832  if(pSym->N.Name.Short){
1833  //name is in the header. it's not zero terminated. have to copy.
1834  PICE_sprintf(pOutput,"%.8X (%s) %.8s\n",start,(section_flags&IMAGE_SCN_CNT_CODE)?"TEXT":"DATA",pSym->N.ShortName);
1835  }
1836  else{
1837  ASSERT(pSym->N.Name.Long<=pSymbols->ulSizeOfGlobalsStrings); //sanity check
1838  pName = pStr+pSym->N.Name.Long;
1839  if(!IsAddressValid((ULONG)pName))
1840  {
1841  DPRINT((0,"ListSymbolStartingAt(): pName = %x is not a valid pointer\n",pName));
1842  return 0;
1843  }
1844  PICE_sprintf(pOutput,"%.8X (%s) %s\n",start,(section_flags&IMAGE_SCN_CNT_CODE)?"TEXT":"DATA",pName);
1845  }
1846 
1847  if((pSym+pSym->NumberOfAuxSymbols+1)<(pSymEnd))
1848  return (index+pSym->NumberOfAuxSymbols+1);
1849  }
1850  index += pSym->NumberOfAuxSymbols + 1;
1851  pSym += pSym->NumberOfAuxSymbols + 1;
1852  }
1853  return 0;
1854 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
char * LPSTR
Definition: xmlstorage.h:182
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
GLuint index
Definition: glext.h:6031
static LPSTR pName
Definition: security.c:78
BOOLEAN IsRangeValid(ULONG Addr, ULONG Length)
Definition: utils.c:735
#define index(s, c)
Definition: various.h:29
#define IMAGE_SCN_CNT_CODE
Definition: ntimage.h:230
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
GLuint start
Definition: gl.h:1545
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
ULONG ulSizeOfGlobalsStrings
Definition: shared.h:86
ULONG ulOffsetToGlobalsStrings
Definition: shared.h:86
#define IMAGE_SYM_CLASS_EXTERNAL
Definition: compat.h:138
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
struct _IMAGE_SYMBOL UNALIGNED * PIMAGE_SYMBOL
Definition: pecoff.h:241
BOOLEAN ListUserModules ( PPEB  peb)

Definition at line 166 of file symbols.c.

Referenced by BuildModuleList().

167 {
168  PLIST_ENTRY UserModuleListHead;
170  PLDR_DATA_TABLE_ENTRY Module;
171  PPEB_LDR_DATA Ldr;
172 
173  ENTER_FUNC();
174 
175  Ldr = peb->Ldr;
176  if( Ldr && IsAddressValid((ULONG)Ldr)){
177  UserModuleListHead = &Ldr->InLoadOrderModuleList;
178  ASSERT(IsAddressValid((ULONG)UserModuleListHead));
179  Entry = UserModuleListHead->Flink;
180  while (Entry != UserModuleListHead)
181  {
182  Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList);
183  //DbgPrint("Module: %x, BaseAddress: %x\n", Module, Module->BaseAddress);
184 
185  DPRINT((0,"FullName: %S, BaseName: %S, Length: %ld, EntryPoint: %x, BaseAddress: %x\n", Module->FullDllName.Buffer,
186  Module->BaseDllName.Buffer, Module->SizeOfImage, Module->EntryPoint, Module->BaseAddress ));
187 
189  pdebug_module_tail->BaseAddress = Module->BaseAddress;
191  ASSERT(Module->BaseDllName.Length<DEBUG_MODULE_NAME_LEN); //name length is limited
194 
195  Entry = Entry->Flink;
196  }
197  }
198  LEAVE_FUNC();
199  return TRUE;
200 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
ULONG SizeOfImage
Definition: ldrtypes.h:141
#define LEAVE_FUNC()
Definition: debug.h:43
struct _DEBUG_MODULE_ * next
Definition: symbols.h:49
PVOID EntryPoint
Definition: symbols.h:52
#define DEBUG_MODULE_NAME_LEN
Definition: shared.h:79
PVOID EntryPoint
Definition: ntddk_ex.h:207
ULONG size
Definition: symbols.h:50
void DPRINT(...)
Definition: polytest.cpp:61
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: btrfs_drv.h:1710
Definition: typedefs.h:117
PPEB_LDR_DATA Ldr
Definition: btrfs_drv.h:1746
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1716
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:143
WCHAR * PICE_wcscpy(WCHAR *str1, const WCHAR *str2)
Definition: utils.c:559
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: symbols.h:53
#define ENTER_FUNC()
Definition: debug.h:42
PDEBUG_MODULE pdebug_module_tail
Definition: init.c:45
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
BOOLEAN LoadExports ( void  )

Definition at line 1909 of file symbols.c.

Referenced by InitPICE().

1910 {
1911  HANDLE hf;
1912  BOOLEAN bResult = TRUE;
1913 
1914  ENTER_FUNC();
1915 
1916  Print(OUTPUT_WINDOW,"pICE: loading exports...\n");
1917  hf = PICE_open(L"\\SystemRoot\\symbols\\ntoskrnl.map",OF_READ);
1918  /*
1919  if(hf)
1920  {
1921  Print(OUTPUT_WINDOW,"pICE: no System.map in /boot\n");
1922  hf = PICE_open("/System.map",OF_READ);
1923  }
1924  */
1925 
1926  if(hf)
1927  {
1928  //mm_segment_t oldfs;
1929  size_t len;
1930 
1931  len = PICE_len(hf);
1932  if(len)
1933  {
1934  DPRINT((0,"file len = %d\n",len));
1935 
1936  pExports = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option
1937 
1938  DPRINT((0,"pExports = %x\n",pExports));
1939 
1940  if(pExports)
1941  {
1942  //oldfs = get_fs(); set_fs(KERNEL_DS);
1943  ulExportLen = len;
1944  ((PUCHAR)pExports)[len]=0;
1945  if(len == PICE_read(hf,pExports,len))
1946  {
1947  DPRINT((0,"success reading system map!\n"));
1948  PICE_sprintf(tempSym,"pICE: ntoskrnl.sym @ %x (size %x)\n",pExports,len);
1950  }
1951  else
1952  DbgPrint("error reading ntoskrnl map!\n");
1953  //set_fs(oldfs);
1954  }
1955  }
1956  PICE_close(hf);
1957  }
1958  else
1959  {
1960  Print(OUTPUT_WINDOW,"pICE: no ntoskrnl.sys \n");
1961  Print(OUTPUT_WINDOW,"pICE: could not load exports...\n");
1962  bResult = FALSE;
1963  }
1964 
1965  LEAVE_FUNC();
1966 
1967  return bResult;
1968 }
int PICE_close(HANDLE hFile)
Definition: utils.c:2300
#define TRUE
Definition: types.h:120
#define OF_READ
Definition: winbase.h:114
#define DbgPrint
Definition: loader.c:26
Definition: bidi.c:75
char tempSym[1024]
Definition: symbols.c:58
unsigned char * PUCHAR
Definition: retypes.h:3
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
#define LEAVE_FUNC()
Definition: debug.h:43
#define NONPAGEDPOOL
Definition: utils.h:306
ULONG ulExportLen
Definition: symbols.c:49
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:797
#define FALSE
Definition: types.h:117
void * PICE_malloc(size_t numBytes, BOOLEAN fromPaged)
Definition: utils.c:2212
void DPRINT(...)
Definition: polytest.cpp:61
unsigned char BOOLEAN
long PICE_read(HANDLE hFile, LPVOID lpBuffer, long lBytes)
Definition: utils.c:2228
PVOID pExports
Definition: symbols.c:48
GLenum GLsizei len
Definition: glext.h:6722
DWORD *typedef HANDLE
Definition: winlogon.h:52
HANDLE PICE_open(LPCWSTR lpPathName, int iReadWrite)
Definition: utils.c:2250
#define ENTER_FUNC()
Definition: debug.h:42
size_t PICE_len(HANDLE hFile)
Definition: utils.c:2310
PICE_SYMBOLFILE_HEADER* LoadSymbols ( LPSTR  filename)

Definition at line 1990 of file symbols.c.

Referenced by LoadSymbolsFromConfig().

1991 {
1992  HANDLE hf;
1993  PICE_SYMBOLFILE_HEADER* pSymbols=NULL;
1994  WCHAR tempstr[256];
1995  int conv;
1996  ENTER_FUNC();
1997 
1998  if( !( conv = PICE_MultiByteToWideChar(CP_ACP, NULL, filename, -1, tempstr, 256 ) ) )
1999  {
2000  DPRINT((0,"Can't convert module name.\n"));
2001  return NULL;
2002  }
2003  DPRINT((0,"LoadSymbols: filename %s, tempstr %S, conv: %d\n", filename, tempstr, conv));
2004 
2006  {
2007  hf = PICE_open(tempstr,OF_READ);
2008  DPRINT((0,"LoadSymbols: hf: %x, file: %S\n",hf, tempstr));
2009  if(hf)
2010  {
2011  //mm_segment_t oldfs;
2012  size_t len;
2013 
2014  DPRINT((0,"hf = %x\n",hf));
2015 
2016  len = PICE_len(hf);
2017  DPRINT((0,"file len = %d\n",len));
2018 
2019  if(len)
2020  {
2021  pSymbols = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option
2022  DPRINT((0,"pSymbols = %x\n",pSymbols));
2023 
2024  if(pSymbols)
2025  {
2026  //oldfs = get_fs(); set_fs(KERNEL_DS);
2027  if(len == PICE_read(hf,(PVOID)pSymbols,len))
2028  {
2029  DPRINT((0,"LoadSymbols(): success reading symbols!\n"));
2030  DPRINT((0,"LoadSymbols(): pSymbols->magic = %X\n",pSymbols->magic));
2031  }
2032  //set_fs(oldfs);
2033 
2034 
2035  if(pSymbols->magic == PICE_MAGIC)
2036  {
2037  DPRINT((0,"magic = %X\n",pSymbols->magic));
2038  DPRINT((0,"name = %S\n",pSymbols->name));
2039  DPRINT((0,"ulOffsetToHeaders,ulSizeOfHeader = %X,%X\n",pSymbols->ulOffsetToHeaders,pSymbols->ulSizeOfHeader));
2040  DPRINT((0,"ulOffsetToGlobals,ulSizeOfGlobals = %X,%X\n",pSymbols->ulOffsetToGlobals,pSymbols->ulSizeOfGlobals));
2041  DPRINT((0,"ulOffsetToGlobalsStrings,ulSizeOfGlobalsStrings = %X,%X\n",pSymbols->ulOffsetToGlobalsStrings,pSymbols->ulSizeOfGlobalsStrings));
2042  DPRINT((0,"ulOffsetToStabs,ulSizeOfStabs = %X,%X\n",pSymbols->ulOffsetToStabs,pSymbols->ulSizeOfStabs));
2043  DPRINT((0,"ulOffsetToStabsStrings,ulSizeOfStabsStrings = %X,%X\n",pSymbols->ulOffsetToStabsStrings,pSymbols->ulSizeOfStabsStrings));
2044  DPRINT((0,"ulOffsetToSrcFiles,ulNumberOfSrcFiles = %X,%X\n",pSymbols->ulOffsetToSrcFiles,pSymbols->ulNumberOfSrcFiles));
2045  DPRINT((0,"pICE: symbols loaded for module \"%S\" @ %x\n",pSymbols->name,pSymbols));
2046  apSymbols[ulNumSymbolsLoaded++]=pSymbols;
2047  }
2048  else
2049  {
2050  DPRINT((0,"LoadSymbols(): freeing %x\n",pSymbols));
2051  DPRINT((0,"pICE: symbols file \"%s\" corrupt\n",filename));
2052  PICE_free(pSymbols);
2053  }
2054  }
2055 
2056  }
2057  PICE_close(hf);
2058  }
2059  else
2060  {
2061  DPRINT((0,"pICE: could not load symbols for %s...\n",filename));
2062  }
2063  }
2064 
2065  LEAVE_FUNC();
2066 
2067  return pSymbols;
2068 }
DWORD *typedef PVOID
Definition: winlogon.h:52
int PICE_close(HANDLE hFile)
Definition: utils.c:2300
#define OF_READ
Definition: winbase.h:114
ULONG ulNumSymbolsLoaded
Definition: symbols.c:54
PICE_SYMBOLFILE_HEADER * apSymbols[32]
Definition: symbols.c:53
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
#define PICE_MAGIC
Definition: shared.h:77
#define LEAVE_FUNC()
Definition: debug.h:43
#define NONPAGEDPOOL
Definition: utils.h:306
INT WINAPI PICE_MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cchMultiByte, LPWSTR lpWideCharStr, int cchWideChar)
Definition: utils.c:2335
LPCSTR filename
Definition: alphablend.c:63
smooth NULL
Definition: ftsmooth.c:557
void * PICE_malloc(size_t numBytes, BOOLEAN fromPaged)
Definition: utils.c:2212
void DPRINT(...)
Definition: polytest.cpp:61
void PICE_free(void *p)
Definition: utils.c:2222
long PICE_read(HANDLE hFile, LPVOID lpBuffer, long lBytes)
Definition: utils.c:2228
GLenum GLsizei len
Definition: glext.h:6722
DWORD *typedef HANDLE
Definition: winlogon.h:52
HANDLE PICE_open(LPCWSTR lpPathName, int iReadWrite)
Definition: utils.c:2250
#define DIM
Definition: s_texfetch.c:44
#define ENTER_FUNC()
Definition: debug.h:42
size_t PICE_len(HANDLE hFile)
Definition: utils.c:2310
BOOLEAN LoadSymbolsFromConfig ( BOOLEAN  bIgnoreBootParams)

Definition at line 2116 of file symbols.c.

Referenced by InitPICE(), and ReloadSymbols().

2117 {
2118  HANDLE hf;
2119  LPSTR pConfig,pConfigEnd,pTemp;
2120  char temp[256];
2121  ULONG line = 1;
2122  BOOLEAN bResult = FALSE;
2123 
2124  ENTER_FUNC();
2125 
2126  hf = PICE_open(L"\\SystemRoot\\symbols\\pice.cfg",OF_READ);
2127  if(hf)
2128  {
2129  //mm_segment_t oldfs;
2130  size_t len;
2131 
2132  DPRINT((0,"hf = %x\n",hf));
2133 
2134  len = PICE_len(hf);
2135  DPRINT((0,"file len = %d\n",len));
2136 
2137  if(len)
2138  {
2139  pConfig = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option
2140  DPRINT((0,"pConfig = %x\n",pConfig));
2141  //oldfs = get_fs(); set_fs(KERNEL_DS);
2142 
2143  if(len == PICE_read(hf,(PVOID)pConfig,len))
2144  {
2145  //set_fs(oldfs);
2146 
2147  pConfigEnd = pConfig + len;
2148 
2149  while(pConfig<pConfigEnd)
2150  {
2151  // skip leading spaces
2152  while(*pConfig==' ' && pConfig<pConfigEnd)
2153  pConfig++;
2154  // get ptr to temporary
2155  pTemp = temp;
2156  // fill in temporary with symbol path
2157  while(*pConfig!=0 && *pConfig!=0x0a && *pConfig!=0x0d && pConfig<pConfigEnd)
2158  *pTemp++ = *pConfig++;
2159  // finish up symbol path string
2160  *pTemp = 0;
2161  // skip any line ends
2162  while((*pConfig==0x0a || *pConfig==0x0d) && pConfig<pConfigEnd)
2163  pConfig++;
2164 
2165  // finally try to load the symbols
2166  if(PICE_strlen(temp))
2167  {
2168  PICE_SYMBOLFILE_HEADER *pSymbols;
2169 
2170  // boot parameter
2171  if(*temp == '!')
2172  {
2173  if(!bIgnoreBootParams)
2174  {
2176  {
2177  PICE_strcpy(szBootParams,temp+1);
2178  DPRINT((0,"pICE: boot params = %s\n",szBootParams));
2179  }
2180  else
2181  {
2182  DPRINT((0,"pICE: boot params already exist! ignoring...\n",szBootParams));
2183  }
2184  }
2185  }
2186  // options
2187  else if(*temp == '+')
2188  {
2189  if(PICE_strlen(temp)>1)
2190  {
2191  if(PICE_strcmpi(temp,"+vga")==0)
2192  {
2194  DPRINT((0,"pICE: eTerminalMode = TERMINAL_MODE_VGA_TEXT\n"));
2195  }
2196  else if(PICE_strcmpi(temp,"+hercules")==0)
2197  {
2199  DPRINT((0,"pICE: eTerminalMode = TERMINAL_MODE_HERCULES_GRAPHICS\n"));
2200  }
2201  else if(PICE_strcmpi(temp,"+serial")==0)
2202  {
2204  DPRINT((0,"pICE: eTerminalMode = TERMINAL_MODE_SERIAL\n"));
2205  }
2206  }
2207  else
2208  {
2209  DPRINT((0,"pICE: found option, but no value\n"));
2210  }
2211  }
2212  // comment
2213  else if(*temp == '#')
2214  {
2215  DPRINT((0,"comment out\n"));
2216  }
2217  // symbol file name/path
2218  else
2219  {
2220  DPRINT((0,"Load symbols from file %s\n", temp));
2221  pSymbols = LoadSymbols(temp);
2222  DPRINT((0,"Load symbols from file %s, pSymbols: %x\n", temp, pSymbols));
2223  if(pSymbols)
2224  {
2225  PICE_SYMBOLFILE_SOURCE* pSrc;
2226  LPSTR p;
2227 
2228  pSrc = (PICE_SYMBOLFILE_SOURCE*)((ULONG)pSymbols + pSymbols->ulOffsetToSrcFiles);
2229  pCurrentSymbols = pSymbols;
2230  p = strrchr(pSrc->filename,'\\');
2231  if(p)
2232  {
2234  }
2235  else
2236  {
2238  }
2239  }
2240  }
2241  }
2242  else
2243  {
2244  DPRINT((0,"invalid line [%u] in config!\n",line));
2245  }
2246  line++;
2247  }
2248  }
2249  else
2250  {
2251  //set_fs(oldfs);
2252  }
2253  }
2254 
2255  PICE_close(hf);
2256  bResult = TRUE;
2257  }
2258  else
2259  {
2260  DPRINT((0,"pICE: config file not found! No symbols loaded.\n"));
2261  DPRINT((0,"pICE: Please make sure to create a file \\systemroot\\symbols\\pice.conf\n"));
2262  DPRINT((0,"pICE: if you want to have symbols for any module loaded.\n"));
2263  }
2264 
2265  LEAVE_FUNC();
2266 
2267  return bResult;
2268 }
DWORD *typedef PVOID
Definition: winlogon.h:52
int PICE_close(HANDLE hFile)
Definition: utils.c:2300
PICE_SYMBOLFILE_HEADER * LoadSymbols(LPSTR filename)
Definition: symbols.c:1990
#define TRUE
Definition: types.h:120
#define OF_READ
Definition: winbase.h:114
Definition: bidi.c:75
ULONG ulOffsetToSrcFiles
Definition: shared.h:89
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
#define LEAVE_FUNC()
Definition: debug.h:43
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
char * LPSTR
Definition: xmlstorage.h:182
#define NONPAGEDPOOL
Definition: utils.h:306
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
#define FALSE
Definition: types.h:117
PICE_SYMBOLFILE_HEADER * pCurrentSymbols
Definition: parse.c:60
char filename[256]
Definition: shared.h:103
void * PICE_malloc(size_t numBytes, BOOLEAN fromPaged)
Definition: utils.c:2212
Definition: parser.c:48
void DPRINT(...)
Definition: polytest.cpp:61
ETERMINALMODE eTerminalMode
Definition: hardware.c:56
TCHAR szCurrentFile[MAX_PATH]
Definition: mplay32.c:23
unsigned char BOOLEAN
long PICE_read(HANDLE hFile, LPVOID lpBuffer, long lBytes)
Definition: utils.c:2228
GLenum GLsizei len
Definition: glext.h:6722
static stack_node_t temp
Definition: rpn.c:18
DWORD *typedef HANDLE
Definition: winlogon.h:52
HANDLE PICE_open(LPCWSTR lpPathName, int iReadWrite)
Definition: utils.c:2250
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
GLfloat GLfloat p
Definition: glext.h:8902
size_t PICE_len(HANDLE hFile)
Definition: utils.c:2310
ULONG PICE_strcmpi(char *s1, char *s2)
Definition: utils.c:387
char szBootParams[1024]
Definition: init.c:41
BOOLEAN ReadHex ( LPSTR  p,
PULONG  pValue 
)

Definition at line 391 of file symbols.c.

Referenced by ScanExportLine().

392 {
393  ULONG result=0,i;
394 
395  for(i=0;i<8 && p[i]!=0 && p[i]!=' ';i++)
396  {
397  if(p[i]>='0' && p[i]<='9')
398  {
399  result<<=4;
400  result|=(ULONG)(UCHAR)(p[i]-'0');
401  }
402  else if(p[i]>='A' && p[i]<='F')
403  {
404  result<<=4;
405  result|=(ULONG)(UCHAR)(p[i]-'A'+10);
406  }
407  else if(p[i]>='a' && p[i]<='f')
408  {
409  result<<=4;
410  result|=(ULONG)(UCHAR)(p[i]-'a'+10);
411  }
412  else
413  return FALSE;
414  }
415 
416  *pValue = result;
417  return TRUE;
418 }
#define TRUE
Definition: types.h:120
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
GLuint64EXT * result
Definition: glext.h:11304
BOOLEAN ReloadSymbols ( void  )

Definition at line 2074 of file symbols.c.

Referenced by pice_ioctl().

2075 {
2076  BOOLEAN bResult;
2077 
2078  ENTER_FUNC();
2079 
2080  UnloadSymbols();
2081 
2082  bResult = LoadSymbolsFromConfig(TRUE);
2083 
2084  LEAVE_FUNC();
2085 
2086  return bResult;
2087 }
#define TRUE
Definition: types.h:120
#define LEAVE_FUNC()
Definition: debug.h:43
BOOLEAN LoadSymbolsFromConfig(BOOLEAN bIgnoreBootParams)
Definition: symbols.c:2116
unsigned char BOOLEAN
#define ENTER_FUNC()
Definition: debug.h:42
void UnloadSymbols()
Definition: symbols.c:2093
BOOLEAN SanityCheckExports ( void  )

Definition at line 1860 of file symbols.c.

Referenced by InitPICE().

1861 {
1862  BOOLEAN bResult = FALSE;
1863  ULONG i,ulValue,incr;
1864 
1865  Print(OUTPUT_WINDOW,"pICE: sanity-checking exports...\n");
1866  return TRUE;
1867  /* fix later!!! do we really need to cross reference two kinds of symbolic info?
1868  if(fake_kernel_module.nsyms && fake_kernel_module.syms)
1869  {
1870  incr = (fake_kernel_module.nsyms/4);
1871  if(!incr)incr = 1;
1872  for(i=0;i<fake_kernel_module.nsyms;i+=incr)
1873  {
1874  if(ScanExports((char*)fake_kernel_module.syms[i].name,&ulValue) )
1875  {
1876  if(!(i%25))
1877  {
1878  ClrLine(wWindow[OUTPUT_WINDOW].y + wWindow[OUTPUT_WINDOW].usCurY);
1879  PICE_sprintf(tempSym,"pICE: sanity-checking exports %u/%u",
1880  i,
1881  fake_kernel_module.nsyms);
1882  PutChar(tempSym,1,wWindow[OUTPUT_WINDOW].y + wWindow[OUTPUT_WINDOW].usCurY);
1883  }
1884 
1885  if(fake_kernel_module.syms[i].value != ulValue)
1886  {
1887  PICE_sprintf(tempSym,"pICE: %s doesn't match (%.8X != %.8X)\n",
1888  fake_kernel_module.syms[i].name,
1889  fake_kernel_module.syms[i].value,
1890  ulValue);
1891  Print(OUTPUT_WINDOW,tempSym);
1892 
1893  return FALSE;
1894  }
1895  }
1896  }
1897 
1898  bResult = TRUE;
1899  }
1900 
1901  return bResult;
1902  */
1903 }
#define TRUE
Definition: types.h:120
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:797
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN ScanExportLine ( LPSTR  p,
PULONG  ulValue,
LPSTR ppPtrToSymbol 
)

Definition at line 424 of file symbols.c.

Referenced by ScanExportsByAddress().

425 {
426  BOOLEAN bResult = FALSE;
427 
428  if(ReadHex(p,ulValue))
429  {
430  p += 11;
431  *ppPtrToSymbol += 11;
432  bResult = TRUE;
433  }
434 
435  return bResult;
436 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN ReadHex(LPSTR p, PULONG pValue)
Definition: symbols.c:391
unsigned char BOOLEAN
GLfloat GLfloat p
Definition: glext.h:8902
BOOLEAN ScanExports ( const char pFind,
PULONG  pValue 
)

Definition at line 327 of file symbols.c.

Referenced by ConvertTokenToSymbol(), InitPICE(), InstallPrintkHook(), and RevirtualizeBreakpointsForModule().

328 {
329  char temp[256];
330  LPSTR pStr=NULL;
331  LPSTR pExp = pExports;
332  BOOLEAN bResult = FALSE;
333 
334  ENTER_FUNC();
335  DPRINT((0,"ScanExports pValue: %x\n", pValue));
336 nomatch:
337  if(pExports)
338  pStr = strstr(pExp,pFind);
339 
340  if(pStr)
341  {
342  LPSTR p;
343  ULONG state;
344  LPSTR pOldStr = pStr;
345 
346  for(;(*pStr!=0x0a && *pStr!=0x0d) && (ULONG)pStr>=(ULONG)pExports;pStr--);
347  pStr++;
348  p = temp;
349  for(;(*pStr!=0x0a && *pStr!=0x0d);)*p++=*pStr++;
350  *p=0;
351  p = (LPSTR) PICE_strtok(temp," ");
352  state=0;
353  while(p)
354  {
355  switch(state)
356  {
357  case 0:
358  ConvertTokenToHex(p,pValue);
359  break;
360  case 1:
361  break;
362  case 2:
363  if(strcmp(p,pFind)!=0)
364  {
365  DPRINT((0,"Not: %s\n", p));
366  pExp = pOldStr+1;
367  goto nomatch;
368  }
369  state = -1;
370  bResult = TRUE;
371  DPRINT((0,"%s @ %x\n",pFind,*pValue));
372  goto exit;
373  break;
374  }
375  state++;
376  p = (char*) PICE_strtok(NULL," ");
377  }
378  }
379 exit:
380  DPRINT((0,"%s %x @ %x\n",pFind,pValue,*pValue));
381 
382  LEAVE_FUNC();
383 
384  return bResult;
385 }
#define TRUE
Definition: types.h:120
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define LEAVE_FUNC()
Definition: debug.h:43
char * LPSTR
Definition: xmlstorage.h:182
char * PICE_strtok(char *szInputString)
Definition: parse.c:3310
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
unsigned char BOOLEAN
BOOLEAN ConvertTokenToHex(LPSTR p, PULONG pValue)
Definition: parse.c:3346
#define exit(n)
Definition: config.h:202
PVOID pExports
Definition: symbols.c:48
static int state
Definition: maze.c:121
static stack_node_t temp
Definition: rpn.c:18
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ENTER_FUNC()
Definition: debug.h:42
GLfloat GLfloat p
Definition: glext.h:8902
BOOLEAN ScanExportsByAddress ( LPSTR pFind,
ULONG  ulValue 
)

Definition at line 599 of file symbols.c.

Referenced by COMMAND_PROTOTYPE(), Disassembler(), ListSWBreakpoints(), OutputIdtEntry(), RealIsr(), and RevirtualizeBreakpointsForModule().

600 {
601  char temp[256];
602  static char temp3[256];
603  LPSTR p,pStartOfLine,pSymbolName=NULL;
604  ULONG ulCurrentValue=0;
605  BOOLEAN bResult = FALSE;
606  PDEBUG_MODULE pd;
607  ULONG ulMinValue = -1;
608  PIMAGE_SYMBOL pSym,pSymEnd; //running pointer to symbols and end of sym talbe
609  PIMAGE_SYMBOL pFoundSym = NULL; //current best symbol match
610  ULONG ulAddr = 0x0; //address of the best match
611  LPSTR pStr;
612  PIMAGE_SECTION_HEADER pShdr;
613  PICE_SYMBOLFILE_HEADER* pSymbols;
614  ULONG ulSectionSize;
615  LPSTR pName;
616 
617  ENTER_FUNC();
618  DPRINT((0,"In ScanExportsByAddress:\n"));
619 
620  pSymbols = FindModuleSymbols(ulValue);
621  DPRINT((0,"pSymbols: %x\n", pSymbols));
622 
623  if(BuildModuleList()){
624  if(pSymbols && pdebug_module_head)
625  {
626  PDEBUG_MODULE pdTemp;
627 
628  DPRINT((0,"looking up symbols\n"));
629  pd = pdebug_module_head;
630  do
631  {
632  if(pd->size){
633  pdTemp = pd;
634 
635  if(ulValue>=((ULONG)pdTemp->BaseAddress) && ulValue<((ULONG)pdTemp+pdTemp->size))
636  {
637  if(PICE_wcsicmp(pdTemp->name,pSymbols->name) == 0)
638  {
639  DPRINT((0,"ScanExportsByAddress(): found symbols for module %S @ %x \n",pdTemp->name,(ULONG)pSymbols));
640 
641  pSym = (PIMAGE_SYMBOL)((ULONG)pSymbols+pSymbols->ulOffsetToGlobals);
642  pSymEnd = (PIMAGE_SYMBOL)((ULONG)pSym+pSymbols->ulSizeOfGlobals);
643  pStr = (LPSTR)((ULONG)pSymbols+pSymbols->ulOffsetToGlobalsStrings);
644  pShdr = (PIMAGE_SECTION_HEADER)((ULONG)pSymbols+pSymbols->ulOffsetToHeaders);
645 
646  if(!IsRangeValid((ULONG)pSym,sizeof(IMAGE_SYMBOL) ) ) //should we actually check all the symbols here?
647  {
648  DPRINT((0,"ScanExportsByAddress(): pSym = %x is not a valid pointer\n",(ULONG)pSym));
649  return FALSE;
650  }
651 
652  DPRINT((0,"ScanExportsByAddress(): pSym = %x\n",pSym));
653  DPRINT((0,"ScanExportsByAddress(): pStr = %x\n",pStr));
654  DPRINT((0,"ScanExportsByAddress(): pShdr = %x\n",pShdr));
655 
656  DPRINT((0,"ScanExportsByAddress(): %S has %u symbols\n",pSymbols->name,pSymbols->ulSizeOfGlobals/sizeof(IMAGE_SYMBOL)));
657 
658  /* go through all the global symbols and find the one with
659  the largest address which is less than ulValue */
660  while(pSym < pSymEnd)
661  { //it seems only 0x0 and 0x20 are used for type and External or Static storage classes
662  if(((pSym->Type == 0x0) || (pSym->Type == 0x20) ) &&
663  ((pSym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) || (pSym->StorageClass==IMAGE_SYM_CLASS_STATIC)) &&
664  (pSym->SectionNumber > 0 ))
665  {
666  ULONG ulCurrAddr;
667  PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1);
668 
669 
670  DPRINT((0,"ScanExportsByAddress(): pShdr[%x] = %x\n",pSym->SectionNumber,(ULONG)pShdrThis));
671 
672  if(!IsRangeValid((ULONG)pShdrThis,sizeof(IMAGE_SECTION_HEADER)) )
673  {
674  DPRINT((0,"ScanExportsByAddress(): pElfShdr[%x] = %x is not a valid pointer\n",pSym->SectionNumber,(ULONG)pShdrThis));
675  return FALSE;
676  }
677  //to get address in the memory we base address of the module and
678  //add offset of the section and then add offset of the symbol from
679  //the begining of the section
680  ulCurrAddr = ((ULONG)pdTemp->BaseAddress+pShdrThis->VirtualAddress+pSym->Value);
681  DPRINT((0,"ScanExportsByAddress(): CurrAddr [1] = %x\n",ulCurrAddr));
682 
683  if(ulCurrAddr<=ulValue && ulCurrAddr>ulAddr)
684  {
685  ulAddr = ulCurrAddr;
686  pFoundSym = pSym;
687  }
688  }
689  //skip the auxiliary symbols and get the next symbol
690  pSym += pSym->NumberOfAuxSymbols + 1;
691  }
692  *pFind = temp3;
693  if( pFoundSym->N.Name.Short ){
694  pName = pFoundSym->N.ShortName; //name is in the header
695  PICE_sprintf(temp3,"%S!%.8s",pdTemp->name,pName); //if name is in the header it may be nonzero terminated
696  }
697  else{
698  ASSERT(pFoundSym->N.Name.Long<=pSymbols->ulSizeOfGlobalsStrings); //sanity check
699  pName = pStr+pFoundSym->N.Name.Long;
700  if(!IsAddressValid((ULONG)pName))
701  {
702  DPRINT((0,"ScanExportsByAddress(): pName = %x is not a valid pointer\n",pName));
703  return FALSE;
704  }
705  PICE_sprintf(temp3,"%S!%s",pdTemp->name,pName);
706  }
707  DPRINT((0,"ScanExportsByAddress(): pName = %x\n",(ULONG)pName));
708  return TRUE;
709  }
710  }
711  }
712  }while((pd = pd->next));
713  }
714  }
715  // if haven't found in the symbols try ntoskrnl exports. (note: check that this is needed since we
716  // already checked ntoskrnl coff symbol table)
717  if(pExports && ulValue >= KERNEL_START && ulValue < kernel_end)
718  {
719  p = pExports;
720  // while we bound in System.map
721  while(p<((LPSTR)pExports+ulExportLen))
722  {
723  // make a temp ptr to the line we can change
724  pStartOfLine = p;
725  // will read the hex value and return a pointer to the symbol name
726  if(ScanExportLine(p,&ulCurrentValue,&pStartOfLine))
727  {
728  if(ulValue>=ulCurrentValue && (ulValue-ulCurrentValue)<ulMinValue)
729  {
730  // save away our info for later
731  ulMinValue = ulValue-ulCurrentValue;
732  pSymbolName = pStartOfLine;
733  bResult = TRUE;
734  *pFind = temp3;
735  if(ulMinValue==0)
736  break;
737  }
738  }
739  // increment pointer to next line
740  p = pStartOfLine;
741  while(*p!=0 && *p!=0x0a && *p!=0x0d)p++;
742  p++;
743  }
744  if(bResult)
745  {
746  int i;
747  // copy symbol name to temp string
748  for(i=0;pSymbolName[i]!=0 && pSymbolName[i]!=0x0a && pSymbolName[i]!=0x0d;i++)
749  temp[i] = pSymbolName[i];
750  temp[i] = 0;
751  // decide if we need to append an offset
752  if(ulMinValue)
753  PICE_sprintf(temp3,"ntoskrnl!%s+%.8X",temp,ulMinValue);
754  else
755  PICE_sprintf(temp3,"ntoskrnl!%s",temp);
756  }
757  }
758 
759  LEAVE_FUNC();
760  return bResult;
761 }
#define TRUE
Definition: types.h:120
#define KERNEL_START
Definition: symbols.h:87
BOOLEAN ScanExportLine(LPSTR p, PULONG ulValue, LPSTR *ppPtrToSymbol)
Definition: symbols.c:424
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
ULONG PICE_wcsicmp(WCHAR *s1, WCHAR *s2)
Definition: utils.c:504
#define LEAVE_FUNC()
Definition: debug.h:43
char * LPSTR
Definition: xmlstorage.h:182
struct _DEBUG_MODULE_ * next
Definition: symbols.h:49
ULONG ulExportLen
Definition: symbols.c:49
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
PICE_SYMBOLFILE_HEADER * FindModuleSymbols(ULONG addr)
Definition: symbols.c:463
smooth NULL
Definition: ftsmooth.c:557
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: shared.h:83
ULONG size
Definition: symbols.h:50
void DPRINT(...)
Definition: polytest.cpp:61
struct _IMAGE_SYMBOL IMAGE_SYMBOL
unsigned char BOOLEAN
static LPSTR pName
Definition: security.c:78
BOOLEAN IsRangeValid(ULONG Addr, ULONG Length)
Definition: utils.c:735
PDEBUG_MODULE pdebug_module_head
Definition: init.c:46
PVOID pExports
Definition: symbols.c:48
static stack_node_t temp
Definition: rpn.c:18
BOOLEAN BuildModuleList(void)
Definition: symbols.c:266
ULONG kernel_end
Definition: symbols.c:56
struct _IMAGE_SECTION_HEADER * PIMAGE_SECTION_HEADER
PVOID BaseAddress
Definition: symbols.h:51
unsigned int ULONG
Definition: retypes.h:1
WCHAR name[DEBUG_MODULE_NAME_LEN]
Definition: symbols.h:53
#define ENTER_FUNC()
Definition: debug.h:42
GLfloat GLfloat p
Definition: glext.h:8902
ULONG ulSizeOfGlobalsStrings
Definition: shared.h:86
ULONG ulOffsetToGlobalsStrings
Definition: shared.h:86
#define IMAGE_SYM_CLASS_STATIC
Definition: winnt_old.h:784
#define IMAGE_SYM_CLASS_EXTERNAL
Definition: compat.h:138
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
struct _IMAGE_SYMBOL UNALIGNED * PIMAGE_SYMBOL
Definition: pecoff.h:241
void SkipSpaces ( void  )

Definition at line 2279 of file symbols.c.

2280 {
2281  while(pExpression[ulIndex]==' ')
2282  ulIndex++;
2283 };
ULONG ulIndex
Definition: symbols.c:92
LPSTR pExpression
Definition: symbols.c:93
BOOLEAN Symbol ( PVRET  pvr)

Definition at line 2890 of file symbols.c.

Referenced by Expression(), main(), MyDrawFrameCaption(), MyDrawFrameScroll(), process_c(), process_preprocessor(), UITOOLS95_DrawFrameCaption(), UITOOLS95_DrawFrameMenu(), UITOOLS95_DrawFrameScroll(), and USBH_ValidateSerialNumberString().

2891 {
2892  char SymbolToken[128];
2893 
2894  ExtractToken(SymbolToken);
2895 
2896  DPRINT((1,"SymbolToken = %s\n",SymbolToken));
2897 
2898  return EvaluateSymbol(pvr,SymbolToken);
2899 }
BOOLEAN EvaluateSymbol(PVRET pvr, LPSTR pToken)
Definition: symbols.c:2673
void ExtractToken(LPSTR pStringToken)
Definition: symbols.c:2399
void DPRINT(...)
Definition: polytest.cpp:61
LPSTR TruncateString ( LPSTR  p,
char  c 
)

Definition at line 1296 of file symbols.c.

Referenced by FindLocalsByAddress().

1297 {
1298  static char temp[1024];
1299  LPSTR pTemp;
1300 
1301  pTemp = temp;
1302 
1303  while(*p!=0 && *p!=c)
1304  *pTemp++ = *p++;
1305 
1306  *pTemp = 0;
1307 
1308  return temp;
1309 }
char * LPSTR
Definition: xmlstorage.h:182
const GLubyte * c
Definition: glext.h:8905
static stack_node_t temp
Definition: rpn.c:18
GLfloat GLfloat p
Definition: glext.h:8902
void UnloadExports ( void  )

Definition at line 1974 of file symbols.c.

Referenced by CleanUpPICE(), and InitPICE().

1975 {
1976  ENTER_FUNC();
1977  if(pExports)
1978  {
1979  DPRINT((0,"freeing %x\n",pExports));
1981  pExports = NULL;
1982  }
1983  LEAVE_FUNC();
1984 }
#define LEAVE_FUNC()
Definition: debug.h:43
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
void PICE_free(void *p)
Definition: utils.c:2222
PVOID pExports
Definition: symbols.c:48
#define ENTER_FUNC()
Definition: debug.h:42
void UnloadSymbols ( void  )

Definition at line 2093 of file symbols.c.

Referenced by CleanUpPICE(), InitPICE(), pice_ioctl(), and ReloadSymbols().

2094 {
2095  ULONG i;
2096 
2097  ENTER_FUNC();
2098 
2099  if(ulNumSymbolsLoaded)
2100  {
2101  for(i=0;i<ulNumSymbolsLoaded;i++)
2102  {
2103  DPRINT((0,"freeing [%u] %x\n",i,apSymbols[i]));
2104  PICE_free(apSymbols[i]);
2105  apSymbols[i] = NULL;
2106  }
2107  ulNumSymbolsLoaded = 0;
2108  }
2109  LEAVE_FUNC();
2110 }
ULONG ulNumSymbolsLoaded
Definition: symbols.c:54
PICE_SYMBOLFILE_HEADER * apSymbols[32]
Definition: symbols.c:53
#define LEAVE_FUNC()
Definition: debug.h:43
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
void PICE_free(void *p)
Definition: utils.c:2222
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
BOOLEAN ValidityCheckSymbols ( PICE_SYMBOLFILE_HEADER pSymbols)

Definition at line 442 of file symbols.c.

Referenced by FindModuleSymbols().

443 {
444  BOOLEAN bRet;
445 
446  DPRINT((0,"ValidityCheckSymbols()\n"));
447 
448  bRet = (IsRangeValid((ULONG)pSymbols + pSymbols->ulOffsetToHeaders,pSymbols->ulSizeOfHeader) &&
449  IsRangeValid((ULONG)pSymbols + pSymbols->ulOffsetToGlobals,pSymbols->ulSizeOfGlobals) &&
450  IsRangeValid((ULONG)pSymbols + pSymbols->ulOffsetToGlobalsStrings,pSymbols->ulSizeOfGlobalsStrings) &&
451  IsRangeValid((ULONG)pSymbols + pSymbols->ulOffsetToStabs,pSymbols->ulSizeOfStabs) &&
452  IsRangeValid((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings,pSymbols->ulSizeOfStabsStrings));
453 
454  DPRINT((0,"ValidityCheckSymbols(): symbols are %s\n",bRet?"VALID":"NOT VALID"));
455 
456  return bRet;
457 }
ULONG ulSizeOfStabsStrings
Definition: shared.h:88
void DPRINT(...)
Definition: polytest.cpp:61
unsigned char BOOLEAN
BOOLEAN IsRangeValid(ULONG Addr, ULONG Length)
Definition: utils.c:735
ULONG ulOffsetToStabsStrings
Definition: shared.h:88
unsigned int ULONG
Definition: retypes.h:1
ULONG ulSizeOfGlobalsStrings
Definition: shared.h:86
ULONG ulOffsetToGlobalsStrings
Definition: shared.h:86

Variable Documentation

PICE_SYMBOLFILE_HEADER* apSymbols[32] ={NULL,}

Definition at line 53 of file symbols.c.

Referenced by COMMAND_PROTOTYPE(), and ConvertTokenToModule().

ULONG kernel_end =0

Definition at line 56 of file symbols.c.

Referenced by ListDriverModules(), and ScanExportsByAddress().

LOCAL_VARIABLE local_vars[512]

Definition at line 51 of file symbols.c.

Referenced by FindLocalsByAddress().

PULONG LocalRegs[]
Initial value:
=
{
}
ULONG CurrentESI
Definition: shell.c:115
ULONG CurrentEDI
Definition: shell.c:115
ULONG CurrentEDX
Definition: shell.c:114
ULONG CurrentECX
Definition: shell.c:114
ULONG CurrentEIP
Definition: shell.c:113
ULONG CurrentEBX
Definition: shell.c:114
ULONG CurrentEBP
Definition: shell.c:115
ULONG CurrentESP
Definition: shell.c:115
ULONG CurrentEFL
Definition: shell.c:113
ULONG CurrentEAX
Definition: shell.c:114

Definition at line 61 of file symbols.c.

Referenced by FindLocalsByAddress().

PDEBUG_MODULE pdebug_module_tail

Definition at line 45 of file init.c.

PVOID pExports =0

Definition at line 48 of file symbols.c.

Referenced by LoadExports(), ScanExports(), ScanExportsByAddress(), and UnloadExports().

LPSTR pExpression

Definition at line 93 of file symbols.c.

Referenced by Evaluate(), ExtractToken(), and SkipSpaces().

LIST_ENTRY* pModuleListHead = NULL

Definition at line 100 of file symbols.c.

PDIRECTORY_OBJECT* pNameSpaceRoot

Definition at line 44 of file init.c.

Referenced by FindDriverObjectDirectory(), and InitPICE().

char tempSym[1024]

Definition at line 58 of file symbols.c.

Referenced by Evaluate(), and LoadExports().

ULONG ulExportLen =0

Definition at line 49 of file symbols.c.

Referenced by LoadExports(), and ScanExportsByAddress().

ULONG ulNumStructMembers

Definition at line 96 of file symbols.c.

Referenced by Evaluate(), and EvaluateSymbol().

ULONG ulNumSymbolsLoaded =0
VRET vr

Definition at line 94 of file symbols.c.

Referenced by ExtractStructMembers().

VRET vrStructMembers[1024]

Definition at line 95 of file symbols.c.