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

📄 init.c

📁 一个类似与Windows环境下的softice的源代码
💻 C
字号:
/****************************************************************************** * * Copyright (c) 2003 Gerhard W. Gruber * * PROJECT: pICE * $Source: /cvsroot/pice/pice/module/init.c,v $ * $Revision: 1.5 $ * $Date: 2004/02/17 23:07:36 $ * $Author: lightweave $ * $Name:  $ * * $Log: init.c,v $ * Revision 1.5  2004/02/17 23:07:36  lightweave * * Improved the DEBUG facillity and replaced the configuration handler with a * new code which now can read MS Windows INI style files. See CHANGES.txt for * more details. * Also added a macro which prevents compiling for kernels before 2.4.19. * * Revision 1.4  2003/06/18 22:00:22  lightweave * DEBUG and DEBUG_SERIAL added * * *****************************************************************************/static char *ident = "$Header: /cvsroot/pice/pice/module/init.c,v 1.5 2004/02/17 23:07:36 lightweave Exp $";/*++Copyright (c) 1998-2001 Klaus P. Gerlicher Module Name:      init.c   Abstract:    initialisation and cleanup of debugger kernel module    Environment:         Kernel mode only      Author:            Klaus P. Gerlicher        Revision History:             25-Jan-1999:	created    15-Nov-2000:    general cleanup of source files          Copyright notice:  This file may be distributed under the terms of the GNU Public License.--*/////////////////////////////////////////////////////// INCLUDES////#include "remods.h"#include <linux/fs.h>#include <linux/vmalloc.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/delay.h>#include "precomp.h"#include "config.h"////////////////////////////////////////////////////// GLOBALSULONG ulDoInitialBreak=1;char szBootParams[1024]="";//************************************************************************* // FeatureCheck() // //************************************************************************* void FeatureCheck(void){   DECL_TEMP;   ALLOC_TEMP(256);   PICE_strcpy(TEMP, "ACTIVATE_KEYBOARD_PATCHING ");#ifdef ACTIVATE_KEYBOARD_PATCHING   PICE_strcat(TEMP, "ON\n");#else   PICE_strcat(TEMP, "OFF\n");#endif // ACTIVATE_KEYBOARD_PATCHING   Print(OUTPUT_WINDOW, TEMP);goto Quit;   PICE_strcpy(TEMP, "ACTIVATE_SYSCALL_HOOKING ");#ifdef ACTIVATE_SYSCALL_HOOKING    PICE_strcat(TEMP, "ON\n");#else   PICE_strcat(TEMP, "OFF\n");#endif // ACTIVATE_SYSCALL_HOOKING    Print(OUTPUT_WINDOW, TEMP);   PICE_strcpy(TEMP, "ACTIVATE_TIMER ");#ifdef ACTIVATE_TIMER    PICE_strcat(TEMP, "ON\n");#else   PICE_strcat(TEMP, "OFF\n");#endif // ACTIVATE_TIMER    Print(OUTPUT_WINDOW, TEMP);   PICE_strcpy(TEMP, "ACTIVATE_PRINTK_HOOK ");#ifdef ACTIVATE_PRINTK_HOOK    PICE_strcat(TEMP, "ON\n");#else   PICE_strcat(TEMP, "OFF\n");#endif // ACTIVATE_PRINTK_HOOK    Print(OUTPUT_WINDOW, TEMP);   PICE_strcpy(TEMP, "ACTIVATE_PRINTK_OVERRIDE ");#ifdef ACTIVATE_PRINTK_OVERRIDE    PICE_strcat(TEMP, "ON\n");#else   PICE_strcat(TEMP, "OFF\n");#endif // ACTIVATE_PRINTK_OVERRIDE    Print(OUTPUT_WINDOW, TEMP);   PICE_strcpy(TEMP, "ACTIVATE_GPFAULT_HOOK ");#ifdef ACTIVATE_GPFAULT_HOOK    PICE_strcat(TEMP, "ON\n");#else   PICE_strcat(TEMP, "OFF\n");#endif // ACTIVATE_GPFAULT_HOOK    Print(OUTPUT_WINDOW, TEMP);   PICE_strcpy(TEMP, "ACTIVATE_PAGEFAULT_HOOK ");#ifdef ACTIVATE_PAGEFAULT_HOOK    PICE_strcat(TEMP, "ON\n");#else   PICE_strcat(TEMP, "OFF\n");#endif // ACTIVATE_PAGEFAULT_HOOK    Print(OUTPUT_WINDOW, TEMP);   PICE_strcpy(TEMP, "ACTIVATE_BREAKPOINT_HOOK ");#ifdef ACTIVATE_BREAKPOINT_HOOK   PICE_strcat(TEMP, "ON\n");#else   PICE_strcat(TEMP, "OFF\n");#endif // ACTIVATE_BREAKPOINT_HOOK   Print(OUTPUT_WINDOW, TEMP);   PICE_strcpy(TEMP, "ACTIVATE_DOUBLEFAULT_HOOK ");#ifdef ACTIVATE_DOUBLEFAULT_HOOK   PICE_strcat(TEMP, "ON\n");#else   PICE_strcat(TEMP, "OFF\n");#endif // ACTIVATE_DOUBLEFAULT_HOOK   Print(OUTPUT_WINDOW, TEMP); Quit:   FREE_TEMP();}//************************************************************************* // InitPICE() // //************************************************************************* BOOLEAN InitPICE(void) {	BOOLEAN rc = FALSE;    ULONG ulHandleScancode=0,  ulHandleKbdEvent=0;	BOOLEAN bSymbols = FALSE, bMap = FALSE, bConsole = FALSE;	    ENTER_FUNC();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Loading symbols\n");    // now load all symbol files described in /etc/pice.conf    if(!LoadConfig())    {        DPRINT(PICE_DEBUG, DBT_INIT, DBL_ERROR, "LoadConfig() failed\n");		printk(KERN_ERR "PrivateICE: couldn't load symbols\n");		goto Quit;    }	bSymbols = TRUE;    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Loading system symbols\n");    // load the file /boot/System.map.    // !!! It must be consistent with the current kernel at all cost!!!    if(!LoadSystemMap())    {       DPRINT(KERN_ERR, DBT_INIT, DBL_ERROR, "failed to load System.map\n");	   goto Quit;    }	bMap = TRUE;    // init the output console 	// this might be one of the following depending setup	// a) monochrome card	// b) VGA 	// c) serial terminal (TODO)    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Initializing console\n");    if(!ConsoleInit())     {         DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "ConsoleInit() failed\n");		printk(KERN_ERR "PrivateICE: console couldn't be initialized\n");		goto Quit;    } 	bConsole = TRUE;    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Initial screen template\n");    // print the initial screen template    PrintTemplate(); #if 0    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "trace step %u\n", ulTraceStep++);	// ask the user if he wants to abort the debugger load    if(!CheckLoadAbort())    {       DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "ABORT (abort by user)\n");	   goto Quit;    }#endif     DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Initialize SMP\n");    // initialize SMP functionality    // kernel module is always compiled for non-SMP (CONFIG_SMP not defined)    InitSmp();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Scan kernel map\n");    // end of the kernel    ScanSystemMap("_end", (PULONG)&kernel_end);    if(!kernel_end)    {       DPRINT(KERN_ERR, DBT_INIT, DBL_INFO, "ABORT (kernel size is unknown)\n");	   goto Quit;    }    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Scan module map\n");    // the loaded module list    ScanSystemMap("module_list", (PULONG)&pmodule_list);    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "module_list @ %x\n", (ULONG)pmodule_list);    if(!pmodule_list)    {       DPRINT(KERN_ERR, DBT_INIT, DBL_ERROR, "ABORT (couldn't retreive kernel module list)\n");	   goto Quit;    }    // module_list in kernel is a pointer    pmodule_list = (struct module*)*(PULONG)pmodule_list;    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "pmodule_list = %x\n", (ULONG)pmodule_list);    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Initialize fake kernel module\n");    // setup a fake module struct for use by symbol routines    if(!InitFakeKernelModule())    {       DPRINT(KERN_ERR, DBT_INIT, DBL_ERROR, "ABORT (couldn't initialize kernel module)\n");	   goto Quit;    }    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Check exports\n");    // do a sanity check on exports    if(!SanityCheckSystemMap())    {		 DPRINT(KERN_ERR, DBT_INIT, DBL_ERROR, "ABORT (System.map exports are conflicting with kernel symbols)\n");		 goto Quit;    }    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Scan exception table\n");    // need this to fully decode pagefaults    ScanSystemMap("search_exception_table", (PULONG)&pice_search_exception_table);    // patch the keyboard driver    if(!pice_search_exception_table)    {		 DPRINT(KERN_ERR, DBT_INIT, DBL_ERROR, "ABORT (couldn't find exception fixup function)\n");		 goto Quit;    }    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Scan keyboard hooks\n");    // need these two to hook the keyboard    ScanSystemMap("handle_scancode",  &ulHandleScancode);    ScanSystemMap("handle_kbd_event",  &ulHandleKbdEvent);    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Patch keyboard driver\n");    // patch the keyboard driver    if(!(ulHandleScancode && ulHandleKbdEvent && PatchKeyboardDriver(ulHandleKbdEvent, ulHandleScancode)))    {		 DPRINT(KERN_ERR, DBT_INIT, DBL_ERROR, "ABORT (couldn't patch keyboard driver)\n");		 goto Quit;    }    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Disable Hardware breakpoints\n");    DisableHWBreakpointsAllCpus();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Initalize pICE timer\n");    InitPiceRunningTimer();#ifdef __PICE__DEBUG__    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Feature check\n");    // print list of activated features (defines.h switches)    FeatureCheck();#endif // __PICE__DEBUG__DPRINT(PICE_DEBUG, DBT_INIT, DBL_ERROR, "Premature abort for debugging. Ringbuffer not working!\n");rc = TRUE;goto Quit;	    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Initialize hooks\n");    // install all hooks    InstallBreakpointHook();        DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Breakpointhook installed\n");    InstallTraceHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Tracehook installed\n");    InstallSyscallHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Syscallhook installed\n");    InstallDblFltHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Doublefaulthook installed\n");    InstallPageFaultHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Pagefaulthook installed\n");    InstallGPFaultHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "GPFaulthook installed\n");    InstallStackFaultHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Stackfaulthook installed\n");    InstallInvalidOpcodeHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Invalidopcodehook installed\n");    InstallNmiFaultHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "NMIhook installed\n");    InstallAlignmentHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Alignmenthook installed\n");    InstallPrintkHook();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Printkhook installed\n");    DebuggerBootParams();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Bootparams\n");Quit:	if(rc== FALSE)	{		 if(bSymbols == TRUE)			  UnloadSymbols();		 if(bMap == TRUE)			  UnloadSystemMap();		 if(bConsole == TRUE)			  ConsoleShutdown();	}    LEAVE_FUNC();    return TRUE; } //************************************************************************* // CleanUpPICE() // //************************************************************************* void CleanUpPICE(void) {    ENTER_FUNC();   DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Remove pICE timer\n");   RemovePiceRunningTimer();   DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Uninstall hooks\n");   // de-install all hooks   DeinstallPageFaultHook();   DeInstallSyscallHook();   DeInstallBreakpointHook();   DeInstallPrintkHook();   DeInstallDblFltHook();   DeInstallGPFaultHook();   DeInstallStackFaultHook();   DeInstallInvalidOpcodeHook();   DeInstallNmiFaultHook();   DeInstallTraceHook();   DeInstallAlignmentHook();   DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Unload system map\n");   UnloadSystemMap(); // don't use ScanSystemMap() after this      DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Unload symbols\n");   UnloadSymbols();    DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Restore keyboard driver\n");   // restore patch of keyboard driver   RestoreKeyboardDriver();   Print(OUTPUT_WINDOW, "pICE: shutting down...\n");      DPRINT(PICE_DEBUG, DBT_INIT, DBL_INFO, "Console shutdown\n");   // cleanup the console   ConsoleShutdown();    LEAVE_FUNC();}

⌨️ 快捷键说明

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