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

📄 r2inst.c

📁 这是一个C程序分析工具
💻 C
字号:
/*===================================================================
  FILE   :  @(#)r2inst.c	2.6  -  08/04/99 
  ===================================================================*/
/*===================================================================
   PURPOSE: Instruments C language source code.
                                                                           
   SYSTEM : RECON II                                                                    

   See string array "useage" below for explanation of command line
   requirements.

   HISTORY:                                                                
   VER   DATE         AUTHOR    DESCRIPTION                                
   1.00   6 Feb 93 L. McCallie  Created file.                              
   1.10  20 Feb 93 L. McCallie  Added fileindex argument.                  
   2.00  27 Feb 93 L. McCallie  Parses multiple source files.              
   3.00  28 Jun 93 L. McCallie  Modified code for ANSI compatibility       
   4.00  25 Nov 96 J. Ward      Incorporated DR055 and DR066 per Tisk 15
   5.00  22 Feb 97 R. Jones     Many changes per Tisk 017
   6.00   3 Mar 99 D. Fralish   Added Entry Point Flag as per Tisk 038
  Put under SCCS as version 1.1, 1 Oct 93 by N. Wilde. Use the            
    command "sccs prs ..." for later history                               
  ---------------------------------------------------------------------*/

/*==[ INCLUDES ]=======================================================*/
#include <stdio.h>
#include <stdlib.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"

char useage[MAX_USEAGE_LINES][BUFFERSIZE];


/*==[ GLOBAL VARIABLES ]=============================================*/
	int   gLineNumber = 1;
	char   gHoldChar = EOF;
	FILE   *gSrcFILE = NULL;
	FILE   *gInstFILE = NULL;
	char   gOutputDir[MAXDIR];
        char   gSrcPath[MAXPATH];

/*==[ PRIVATE FUNCTIONS ]============================================*/
int verbose_level(char *);
void display_useage(void);
void display_complete(void);

/*===================================================================
	FUNCTION: main
  ===================================================================
	PURPOSE : Entry to program.  Processes command line arguments.

	HISTORY :
	VER   DATE         AUTHOR    DESCRIPTION
	1.00   6 Feb 93 L. McCallie  Created file.
	2.00  25 Feb 97 R. Jones     removed file index per Tisk 017
        2.10  22 Jan 98 B. Boone     Fixed backslash per Tisk 022
        2.11  25 Nov 98 D. Fralish   Use R2_VERS as per Tisk 033
		2.20   3 Mar 99 D. Fralish   Entry Point Flag as per Tisk 038
  -------------------------------------------------------------------*/
int main(int argc, char *argv[])
	{
	char InstPath[MAXPATH];
	FILE *ProgressFile = stdout;
        char *FixedSrcPath;
	gOutputDir[0] = '\0';


	strcpy(useage[0], "=====================================================================");
	strcpy(useage[1], "   USAGE: r2inst source dest [-v[level]] [-e]");
	strcpy(useage[2], "=====================================================================");
	strcpy(useage[3],"");
	strcpy(useage[4], "");
	strcpy(useage[5], "  source - C language source file to be instrumented.");
	strcpy(useage[6], "");
	strcpy(useage[7], "  dest - destination file for the instrumented source.");
	strcpy(useage[8], "");
	strcpy(useage[9], "  -v (verbose) - write progress messages to the screen.");
	strcpy(useage[10], "  level - {'A'|'F'|'S'|'T'} each level adds info to previous level:");
	strcpy(useage[11], "    A = Admin, writes only high level messages (file names, etc).");
	strcpy(useage[12], "    F = Function names.");
	strcpy(useage[13], "    S = Statements instrumented.");
	strcpy(useage[14], "    T = Tokens recognized.");
	strcpy(useage[15], "  -e (entry) - instruments entry points in functions.  This option");
	strcpy(useage[16], "     enhances C++ reconnaiassance.");
	strcpy(useage[17], "");
	strcpy(useage[18], "    Note: Default Level of Verbosity established in r2inst.h");
	strcpy(useage[19], "");
	strcpy(useage[20], "The verbose arguments are optional. ");
	strcpy(useage[21], "====================================================================");
	
	printf( "\n\nR2Inst: Version %s\n", R2_VERS );

	SetEntryPointFlag(FALSE);

	switch(argc) {
		case 5:
			if (strstr(argv[4], "-v") || strstr(argv[4], "-V"))
			{
				vb_init(verbose_level(argv[4]),ProgressFile);
			}

			if (strstr(argv[4], "-e") || strstr(argv[4], "-E"))
			{
				SetEntryPointFlag(TRUE);
			}

		case 4:
			if (strstr(argv[3], "-v") || strstr(argv[3], "-V"))
			{
				vb_init(verbose_level(argv[3]),ProgressFile);
			}

			if (strstr(argv[3], "-e") || strstr(argv[3], "-E"))
			{
				SetEntryPointFlag(TRUE);
			}

		case 3:
			strcpy(gSrcPath, argv[1]);
			if (NULL != (gSrcFILE = ValidateSourceFile()))
				{
				strcpy(InstPath, argv[2]);
                                if (0 == strcmp(gSrcPath, InstPath))
                                    {
                                    printf("Source and destination files are the same.\n");
                                    printf("Continuing would result in source being overwritten\n");
                                    printf("Program Terminating\n");
                                    exit(1);
                                    }
				if(NULL != (gInstFILE = ValidateDestFile(InstPath)))
					{
					printf("Instrumenting: %s\n", gSrcPath);
                                        FixedSrcPath = FixBackslash(gSrcPath);
                                        strcpy (gSrcPath, FixedSrcPath);
					SendPrototypes();
					while (EOF != ParseFunction());
					fclose(gInstFILE);
					display_complete();
					}
				fclose(gSrcFILE);
				}
			break;
		default:
			display_useage();
			break;
		}
	return(0);
	}

/*===================================================================
	FUNCTION: verbose_level()
  ===================================================================
	PURPOSE : determine verbose level from string containing "-v%"
				 where % -> letter indicating desired level

	CALLS   : none

	USED BY : main()
  -------------------------------------------------------------------*/
int verbose_level(char *vstring)
	{
	char *ptr = strstr(vstring,"-v");
	int level=0;

        if (!ptr)
          ptr = strstr(vstring, "-V");

	if(ptr)
		switch(toupper(*(ptr+2)))
			{
			case 'A':
				level = ADMIN_LEVEL;
				break;
			case 'F':
				level = FUNCTION_LEVEL;
				break;
			case 'S':
				level = STATEMENT_LEVEL;
				break;
			case 'T':
				level = TOKEN_LEVEL;
				break;
			case 'D':
				level = DEBUG_LEVEL;
				break;
			default:
				level = DEFAULT_LEVEL;
				break;
			}
	return(level);
	}

/*===================================================================
	FUNCTION: display_useage()
  ===================================================================
	PURPOSE : display usage instructions

	CALLS   : none

	USED BY : main()
  -------------------------------------------------------------------*/
void display_useage(void)
	{
	int i;

	for(i=0; i < MAX_USEAGE_LINES;i++)
		printf("%s\n",useage[i]);
	}

/*===================================================================
	FUNCTION: display_complete()
  ===================================================================
	PURPOSE : display completion message

	CALLS   : none

	USED BY : main()
  -------------------------------------------------------------------*/
void display_complete(void)
	{
	printf("\n%s\n%s\n%s\n",
		"\t\t\t**************************",
		"\t\t\t*Instrumentation complete*",
		"\t\t\t**************************");
	}
/*=====[ EOF: R2INST.C ]=============================================*/

⌨️ 快捷键说明

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