⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 instrmnt.c

📁 这是一个C程序分析工具
💻 C
📖 第 1 页 / 共 2 页
字号:
/*===================================================================
    FILE   :  @(#)instrmnt.c	2.3  -  08/04/99 
  ===================================================================*/
/*===================================================================
   PURPOSE: Instruments C language source code.
                                                                           
   SYSTEM : RECON II

HISTORY:
VER    DATE     AUTHOR        DESCRIPTION
1.00  22 feb 97 Rich Jones  remove gFileIndex and replace with gScrPath
				per Tisk 017
1.01   9 mar 99 David Fralish added InstrumentEntryPoint, SetEntryPoint,
                              and GetEntryPoint as per Tisk 38
  -------------------------------------------------------------------*/

/*==[ INCLUDES ]=====================================================*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include "r2.h"
#include "r2inst.h"
#include "instpars.h"
#include "instrmnt.h"
#include "instfile.h"
#include "instutil.h"
#include "vb_print.h"

#define IFCONDITIONAL        1
#define WHILECONDITIONAL     2
#define FORCONDITIONAL       3
#define SWITCHCONDITIONAL    4

#define RETURNSTATEMENT      1
#define EXITSTATEMENT        2
#define CONDITIONALSTATEMENT 3

/*==[ PRIVATE FUNCTION DECLARATIONS ]================================*/
void InstrumentReturnStatement(void);
void InstrumentExitStatement(void);
void InstrumentConditionals(char *);
int ConditionalType(char *);
void InstrumentIfWhile(void);
void InstrumentFor(void);
void InstrumentSwitch(void);

static int InstrumentEntryPointFlag = FALSE;

/*==[ PUBLIC FUNCTIONS IMPLEMENTATIONS ]=============================*/


/*===================================================================
   FUNCTION: InstrumentStatements                                          
  ===================================================================
	PURPOSE : Verifies the token as a candidate instruction for
             instrumenting.                                                
                                                                           
   CALLS   : StatementType                                                 
             InstrumentReturnStatement                                     
             InstrumentExitStatement                                       
				 InstrumentConditionals
                                                                           
   USED BY : ParseFunction                                                 
                                                                           
   HISTORY :                                                               
   VER   DATE         AUTHOR    DESCRIPTION                                
   1.00   6 Feb 93 L. McCallie  Created file.                              
  -------------------------------------------------------------------*/
void InstrumentStatements(char *Function,char *Statement)
   {
   int Type = StatementType(Statement);

   if(Type)
      {
      vb_print(STATEMENT_LEVEL,"%d\t\tstatement %s\n",gLineNumber,Statement);
      switch (StatementType(Statement))
         {
         case RETURNSTATEMENT:
				if (0 == strcmp("main", Function))
               InstrumentReturnStatement();
            break;
         case EXITSTATEMENT:
            InstrumentExitStatement();
            break;
			case CONDITIONALSTATEMENT:
            InstrumentConditionals(Statement);
            break;
         }
      }
   }

/*===================================================================
   FUNCTION: InstrumentConditionals                                        
  ===================================================================
   PURPOSE : Verifies the token is a conditional type statement.           
                                                                           
   CALLS   : ConditionalType                                               
             InstrumentIfWhile                                             
             InstrumentFor                                                 
             InstrumentSwitch                                              
                                                                           
   USED BY : InstrumentStatements                                          

   HISTORY :                                                               
   VER   DATE         AUTHOR    DESCRIPTION                                
   1.00   6 Feb 93 L. McCallie  Created file.                              
  -------------------------------------------------------------------*/
void InstrumentConditionals(char *Statement)
	{
   int Type = ConditionalType(Statement);

   if(Type)
      {
      switch(Type)
         {
         case IFCONDITIONAL:
         case WHILECONDITIONAL:
            InstrumentIfWhile();
            break;
         case FORCONDITIONAL:
            InstrumentFor();
            break;
         case SWITCHCONDITIONAL:
            InstrumentSwitch();
            break;
         }
		}
   }


/*===================================================================
   FUNCTION: InstrumentReturnStatement                                     
  ===================================================================
   PURPOSE : Instruments return statements.                                
                                                                           
   CALLS   : FindEndParen                                                  
                                                                           
   USED BY : InstrumentStatements                                          
                                                                           
   HISTORY :                                                               
   VER   DATE         AUTHOR    DESCRIPTION                                
   1.00   6 Feb 93 L. McCallie  Created file.                              
  -------------------------------------------------------------------*/
void InstrumentReturnStatement()
   {
   fputs("R2Close(", gInstFILE);
   FindEndParen();
   fputs(")", gInstFILE);
   }

/*===================================================================
   FUNCTION: InstrumentExitStatement                                       
  ===================================================================
   PURPOSE : Instruments exit statements.                                  
                                                                           
   CALLS   : FindEndParen                                                  

   USED BY : InstrumentStatements                                          
                                                                           
   HISTORY :                                                               
   VER   DATE         AUTHOR    DESCRIPTION                                
   1.00   6 Feb 93 L. McCallie  Created file.                              
  -------------------------------------------------------------------*/
void InstrumentExitStatement(void)
   {
   fputs("R2Close(", gInstFILE);
   FindEndParen();
   fputs(")", gInstFILE);
   }


/*===================================================================
   FUNCTION: InstrumentIfWhile                                             
  ===================================================================
	PURPOSE : Instruments if and while statements.
                                                                           
   CALLS   : FindEndParen                                                  
                                                                           
   USED BY : InstrumentConditionals                                        
                                                                           
	HISTORY :
   VER   DATE         AUTHOR    DESCRIPTION                                
   1.00   6 Feb 93 L. McCallie  Created file. 
   2.00  25 Feb 97 R. Jones     replace file index with R2srcfile_ptr                             
  -------------------------------------------------------------------*/
void InstrumentIfWhile(void)
	{
	int tmpLineNumber = 0;
	tmpLineNumber = gLineNumber;
	fputc('(', gInstFILE);
	FindEndParen();
	fprintf(gInstFILE, "?R2True(R2srcfile_ptr,%d):R2False(R2srcfile_ptr,%d))",
            tmpLineNumber, tmpLineNumber);
        }  
/*===================================================================
	FUNCTION: InstrumentFor
  ===================================================================
	PURPOSE : Instruments for statements
				 Replaces empty conditional phrase with "1"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -