├── 0.3 ├── TODO ├── README ├── idt.c ├── page.c ├── LISEZMOI ├── command.c ├── font.bmp ├── video.c ├── core_rr0d.c ├── foo_vxd.rc ├── keyboard.c ├── pci_data.h ├── breakpoint.c ├── doc_tech.tex ├── x_mode │ ├── compil │ └── x_ice.c ├── fig │ ├── pagination.dia │ ├── install_RR0D.dia │ └── pose_breakpoint.dia ├── Makefile-WINXP ├── module_win.rc ├── fb_pci_agp.h ├── command.h ├── Makefile-netbsd ├── Makefile-openbsd ├── Resource.h ├── Makefile-freebsd ├── core_rr0d.h ├── types.h ├── disasm.h ├── foo_vxd.dsw ├── fb_pci_agp.c ├── foo_vxd.h ├── import_symb.h ├── Makefile-linux ├── sources ├── module_nux.c ├── symbols.sh ├── buffering.h ├── Makefile-26 ├── module_freebsd.c ├── page.h ├── keyboard.h ├── var_globale.h ├── config.h.sample ├── Spy.def ├── import_symb.c ├── breakpoint.h ├── utils.h ├── SpyAsm.asm ├── idt.h ├── SpyExec.c ├── exporter │ └── main.c ├── Mylocal.inc ├── insns.h ├── Makefile-win ├── winver.h ├── names.c ├── foo_vxd.dsp ├── video.h ├── buffering.c ├── vars.h ├── module_win.c ├── pci.c ├── driver_loader.c ├── pci.h ├── utils.c ├── disasmbak.c └── nasm.h ├── tests-freebsd ├── titi.c └── lkm │ ├── Makefile │ └── toto.c ├── tests-openbsd └── lkm │ ├── Makefile │ └── toto.c └── tests-linux ├── Makefile └── find_fb.c /0.3/TODO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/TODO -------------------------------------------------------------------------------- /0.3/README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/README -------------------------------------------------------------------------------- /0.3/idt.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/idt.c -------------------------------------------------------------------------------- /0.3/page.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/page.c -------------------------------------------------------------------------------- /0.3/LISEZMOI: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/LISEZMOI -------------------------------------------------------------------------------- /0.3/command.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/command.c -------------------------------------------------------------------------------- /0.3/font.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/font.bmp -------------------------------------------------------------------------------- /0.3/video.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/video.c -------------------------------------------------------------------------------- /0.3/core_rr0d.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/core_rr0d.c -------------------------------------------------------------------------------- /0.3/foo_vxd.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/foo_vxd.rc -------------------------------------------------------------------------------- /0.3/keyboard.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/keyboard.c -------------------------------------------------------------------------------- /0.3/pci_data.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/pci_data.h -------------------------------------------------------------------------------- /0.3/breakpoint.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/breakpoint.c -------------------------------------------------------------------------------- /0.3/doc_tech.tex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/doc_tech.tex -------------------------------------------------------------------------------- /0.3/x_mode/compil: -------------------------------------------------------------------------------- 1 | gcc -L/usr/X11R6/lib -lX11 -lXxf86dga -lXext x_ice.c -Wall 2 | -------------------------------------------------------------------------------- /0.3/fig/pagination.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/fig/pagination.dia -------------------------------------------------------------------------------- /0.3/fig/install_RR0D.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/fig/install_RR0D.dia -------------------------------------------------------------------------------- /0.3/fig/pose_breakpoint.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice799/rr0d/HEAD/0.3/fig/pose_breakpoint.dia -------------------------------------------------------------------------------- /tests-freebsd/titi.c: -------------------------------------------------------------------------------- 1 | int main () { 2 | __asm("\ 3 | int $0x3;\ 4 | "); 5 | getchar(); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests-openbsd/lkm/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.2 2004-10-03 12:33:49 lalet Exp $ 2 | 3 | SRCS = toto.c 4 | LKM = toto 5 | BSDSRCDIR = /usr/src 6 | 7 | .include 8 | -------------------------------------------------------------------------------- /tests-freebsd/lkm/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 1.1 2004-10-02 14:31:24 lalet Exp $ 2 | 3 | SRCS = toto.c 4 | KMOD = toto 5 | KO = ${KMOD}.ko 6 | KLDMOD = t 7 | 8 | .include 9 | -------------------------------------------------------------------------------- /tests-linux/Makefile: -------------------------------------------------------------------------------- 1 | obj-m += find_fb.o 2 | 3 | all: 4 | make -C /lib/modules/$(shell uname -r)/build M=`pwd` modules 5 | 6 | clean: 7 | make -C /lib/modules/$(shell uname -r)/build M=`pwd` clean 8 | -------------------------------------------------------------------------------- /0.3/Makefile-WINXP: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | !INCLUDE $(NTMAKEENV)\makefile.def 8 | -------------------------------------------------------------------------------- /0.3/module_win.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #define VER_FILETYPE VFT_DRV 6 | #define VER_FILESUBTYPE VFT2_DRV_SYSTEM 7 | #define VER_FILEDESCRIPTION_STR "Sample Cancel Driver" 8 | #define VER_INTERNALNAME_STR "cancel.sys" 9 | 10 | #include "common.ver" 11 | -------------------------------------------------------------------------------- /0.3/fb_pci_agp.h: -------------------------------------------------------------------------------- 1 | #ifndef FB_PCI_AGP 2 | #define FB_PCI_AGP 3 | 4 | 5 | 6 | extern unsigned char fb_hw_padding_var1[0x1000]; 7 | extern unsigned char fb_hw_flying_page1[1024*0x1000]; 8 | extern unsigned char fb_hw_padding_var2[0x1000]; 9 | 10 | 11 | extern unsigned int fb_hw_flying_page1_sav; 12 | extern unsigned int fb_hw_flying_page1_level; 13 | 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /0.3/command.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMAND_H 2 | #define COMMAND_H 3 | 4 | extern char cmd_result[80]; 5 | extern unsigned int adresse_ret_1; 6 | extern unsigned int adresse_ret_2; 7 | 8 | 9 | 10 | extern unsigned int edit_mode; 11 | 12 | int chose_command(char* command); 13 | int chose_reg(char* reg); 14 | 15 | unsigned int chose_symb(char* symb); 16 | 17 | 18 | int parse_command(char* ); 19 | 20 | #endif /* COMMAND_H */ 21 | -------------------------------------------------------------------------------- /0.3/Makefile-netbsd: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the Rasta Ring 0 debug 3 | # 4 | # Copyright (C) 2004 Droids Corporation 5 | # http://www.droids-corp.org/ 6 | # 7 | # $Id: Makefile-netbsd,v 1.3 2006-07-12 13:09:25 serpilliere Exp $ 8 | # 9 | 10 | SRCS = utils.c breakpoint.c buffering.c command.c disasmbak.c idt.c keyboard.c page.c video.c Spy.c pci.c 11 | KMOD = rr0d 12 | KO = ${KMOD}.ko 13 | KLDMOD = t 14 | 15 | .include 16 | -------------------------------------------------------------------------------- /0.3/Makefile-openbsd: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the Rasta Ring 0 debug 3 | # 4 | # Copyright (C) 2004 Droids Corporation 5 | # http://www.droids-corp.org/ 6 | # 7 | # $Id: Makefile-openbsd,v 1.6 2006-07-12 13:09:25 serpilliere Exp $ 8 | # 9 | 10 | NOMAN = 11 | SRCS = utils.c breakpoint.c buffering.c command.c disasmbak.c idt.c keyboard.c page.c video.c Spy.c pci.c 12 | #OBJS=$(SRCS:.c=.o) 13 | LKM = rr0d 14 | BSDSRCDIR = /usr/src 15 | 16 | .include 17 | -------------------------------------------------------------------------------- /0.3/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by foo_vxd.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NEXT_RESOURCE_VALUE 101 11 | #define _APS_NEXT_COMMAND_VALUE 40001 12 | #define _APS_NEXT_CONTROL_VALUE 1000 13 | #define _APS_NEXT_SYMED_VALUE 101 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /0.3/Makefile-freebsd: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the Rasta Ring 0 debug 3 | # 4 | # Copyright (C) 2004 Droids Corporation 5 | # http://www.droids-corp.org/ 6 | # 7 | # $Id: Makefile-freebsd,v 1.6 2006-07-12 13:09:25 serpilliere Exp $ 8 | # 9 | 10 | SRCS = breakpoint.c buffering.c command.c disasmbak.c idt.c keyboard.c page.c video.c import_symb.c utils.c module_freebsd.c core_rr0d.c pci.c 11 | KMOD = rr0d 12 | KO = ${KMOD}.ko 13 | KLDMOD = t 14 | 15 | .include 16 | -------------------------------------------------------------------------------- /0.3/core_rr0d.h: -------------------------------------------------------------------------------- 1 | void _kbdhandle (void); 2 | void _int0_handle (void); 3 | void _int1_handle (void); 4 | void _int3_handle (void); 5 | void _int6_handle (void); 6 | void _int13_handle (void); 7 | void _int14_handle (void); 8 | void _int128_handle (void); 9 | int init_rr0d(void); 10 | void cleanup_rr0d(void); 11 | void kbdhandle(void); 12 | void int0_handle (void); 13 | void int1_handle (void); 14 | void int3_handle (void); 15 | void int6_handle (void); 16 | void int13_handle (void); 17 | void int14_handle (void); 18 | void int128_handle (void); 19 | -------------------------------------------------------------------------------- /0.3/types.h: -------------------------------------------------------------------------------- 1 | #if !defined(__TYPES_H__) 2 | #define __TYPES_H__ 3 | typedef unsigned char u8; // 8 bit type 4 | typedef unsigned short u16; // 16 bit type 5 | typedef unsigned long u32; // 32 bit type 6 | typedef unsigned long long u64; // 64 bit type 7 | 8 | typedef char i8; // 8 bit signed type 9 | typedef short i16; // 16 bit signed type 10 | typedef long i32; // 32 bit signed type 11 | typedef long long i64; // 64 bit signed type 12 | 13 | #endif /* !defined(__TYPES_H__) */ 14 | -------------------------------------------------------------------------------- /0.3/disasm.h: -------------------------------------------------------------------------------- 1 | /* disasm.h header file for disasm.c 2 | * 3 | * The Netwide Assembler is copyright (C) 1996 Simon Tatham and 4 | * Julian Hall. All rights reserved. The software is 5 | * redistributable under the licence given in the file "Licence" 6 | * distributed in the NASM archive. 7 | */ 8 | 9 | #ifndef NASM_DISASM_H 10 | #define NASM_DISASM_H 11 | 12 | #define INSN_MAX 32 /* one instruction can't be longer than this */ 13 | 14 | //long disasm (unsigned char *, char *, int , long , int ); 15 | long disasm (unsigned char *, char *, int , long,int, insn *); 16 | long eatbyte (unsigned char *, char *); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /0.3/foo_vxd.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "foo_vxd"=.\foo_vxd.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | -------------------------------------------------------------------------------- /0.3/fb_pci_agp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Rasta Ring 0 debug 3 | * 4 | * Copyright (C) 2004 Droids Corporation. 5 | * based on Deblin debuger 6 | * 7 | * $Id: fb_pci_agp.c,v 1.1 2006-06-29 08:37:30 serpilliere Exp $ 8 | * 9 | */ 10 | 11 | #include "vars.h" 12 | 13 | #include "page.h" 14 | 15 | #include "utils.h" 16 | #include "buffering.h" 17 | 18 | #include "fb_pci_agp.h" 19 | 20 | unsigned char fb_hw_padding_var1[0x1000]; 21 | unsigned char fb_hw_flying_page1[1024*0x1000]; 22 | unsigned char fb_hw_padding_var2[0x1000]; 23 | 24 | 25 | unsigned int fb_hw_flying_page1_sav = 0; 26 | unsigned int fb_hw_flying_page1_level = 0; 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /0.3/foo_vxd.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FOO_VXD_H 3 | #define _FOO_VXD_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #define FOO_VXD_MAJOR_VER 1 // Major version number 10 | #define FOO_VXD_MINOR_VER 0 // Minor version number 11 | #define FOO_VXD_DEVICE_ID UNDEFINED_DEVICE_ID // Device ID for this VxD 12 | #define FOO_VXD_INIT_ORDER UNDEFINED_INIT_ORDER // Initialization order 13 | 14 | /////////////////// 15 | // Define Win32 DeviceIoControl codes 16 | // 17 | #define FOO_VXD_CTL_CODE(IoctlIndex) CTL_CODE(FILE_DEVICE_UNKNOWN,(IoctlIndex|0x800),METHOD_BUFFERED,FILE_ANY_ACCESS) 18 | 19 | #define IOCTL_FOO_VXD_GET_VERSION FOO_VXD_CTL_CODE(1) 20 | 21 | 22 | #endif -------------------------------------------------------------------------------- /0.3/import_symb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Rasta Ring 0 debug 3 | * 4 | * Copyright (C) 2004 Droids Corporation. 5 | * 6 | * $Id 7 | * 8 | */ 9 | 10 | #ifndef IMPORT_SYMB_H 11 | #define IMPORT_SYMB_H 12 | 13 | 14 | 15 | #define MAX_SYMBOL 2000 16 | #define SYMBOL_NAME_LEN 16 17 | 18 | 19 | typedef struct symb_struct { 20 | unsigned int address; 21 | char name[SYMBOL_NAME_LEN]; 22 | } Symbol; 23 | 24 | extern Symbol tab_import_symb[MAX_SYMBOL]; 25 | 26 | 27 | void init_symb(void); 28 | char * is_symbol_address(unsigned int); 29 | int load_symbol(Symbol* address_symbol, unsigned int num_symb); 30 | 31 | void list_symbol(void); 32 | 33 | #endif //IMPORT_SYMB_H 34 | -------------------------------------------------------------------------------- /0.3/Makefile-linux: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the Rasta Ring 0 debug 3 | # 4 | # Copyright (C) 2004 Droids Corporation 5 | # http://www.droids-corp.org/ 6 | # 7 | # $Id: Makefile-linux,v 1.7 2007-01-06 17:49:09 serpilliere Exp $ 8 | # 9 | 10 | 11 | CC = gcc 12 | LD = ld 13 | CFLAGS = -c -I /usr/src/linux/include -I . -Wall 14 | LFLAGS = -r 15 | OBJ = utils.o breakpoint.o buffering.o command.o disasmbak.o idt.o keyboard.o page.o video.o core_rr0d.o import_symb.o module_nux.o pci.o 16 | MODULE = rr0d.o 17 | 18 | all: $(MODULE) 19 | 20 | 21 | 22 | $(MODULE): $(OBJ) 23 | $(LD) $(LFLAGS) -o $@ $(OBJ) 24 | 25 | %.o: %.c 26 | $(CC) $(CFLAGS) $< 27 | 28 | clean: 29 | rm -f *.o *~ Makefile-depend 30 | -------------------------------------------------------------------------------- /0.3/sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=cancel 2 | TARGETPATH=obj 3 | TARGETTYPE=DRIVER 4 | 5 | # 6 | # The WinXP DDK has introduced the DDK_TARGET_OS environemnt variable 7 | # for conditional compilation. The test here is designed to make this 8 | # sources file portable to the standalone Win 2K DDK environment. Note, 9 | # however, that the required csq.h and csq.lib are not present in that 10 | # environment. 11 | # 12 | !if "$(DDK_TARGET_OS)"!="WinXP" 13 | C_DEFINES=$(C_DEFINES) -DW2K=1 14 | TARGETLIBS=$(DDK_LIB_PATH)\csq.lib 15 | !endif 16 | 17 | SOURCES=breakpoint.c buffering.c command.c disasmbak.c idt.c keyboard.c page.c video.c utils.c import_symb.c core_rr0d.c module_win.c pci.c module_win.rc 18 | 19 | -------------------------------------------------------------------------------- /0.3/module_nux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2004 Droids Corporation 3 | * http://www.droids-corp.org/ 4 | * 5 | * important parts of this code were taken from the Linux source code, 6 | * Copyright (C) 1996 Linus Torvalds (file linux/mm/remap.c). See 7 | * http://www.kernel.org/ 8 | * 9 | * $Id: module_nux.c,v 1.3 2006-06-30 12:25:35 serpilliere Exp $ 10 | * 11 | */ 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | extern int init_rr0d(void); 20 | extern void cleanup_rr0d(void); 21 | 22 | int init_module() 23 | { 24 | MODULE_LICENSE("GPL"); 25 | 26 | init_rr0d(); 27 | return 0; 28 | } 29 | 30 | void cleanup_module() 31 | { 32 | cleanup_rr0d(); 33 | } 34 | -------------------------------------------------------------------------------- /0.3/symbols.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Quand il marchera, ce prog fournira les adresses des symboles des 4 | # librairies. Mais il ne marche pas. 5 | # 6 | # $Id: symbols.sh,v 1.1 2004-09-08 23:16:49 lalet Exp $ 7 | 8 | # usage 9 | LIBRARY=$1 10 | BINARY=$2 11 | 12 | offset=`ldd $BINARY | grep $LIBRARY | sed 's/.*(// ; s/).*//'` 13 | 14 | i=0 15 | #for ligne in `objdump -T $LIBRARY | awk '{print $1":"$7}' | grep -v '^:$'` 16 | for ligne in `nm -D $LIBRARY | awk '{print $1":"$3}'` 17 | do 18 | address=`echo $ligne | cut -d ':' -f 1` 19 | symbol=`echo $ligne | cut -d ':' -f 2` 20 | if [ "X$symbol" != "X" -a "$address" != "00000000" ]; then 21 | echo "address[$i]=0x$address + $offset;" 22 | echo "symbol[$((i++))]=\"$symbol\";" 23 | fi 24 | done 25 | -------------------------------------------------------------------------------- /0.3/buffering.h: -------------------------------------------------------------------------------- 1 | #ifndef BUFFERING_H 2 | #define BUFFERING_H 3 | 4 | 5 | 6 | extern int bufferindex; 7 | extern int insertbufferindex; 8 | 9 | 10 | void cleaningbuffer(void); 11 | void insert_cmd(char *); 12 | void recall_oldcmd(int ); 13 | 14 | void insertinbuffer(char *); 15 | void displaybuffer(void); 16 | void bufferdown(void); 17 | 18 | void bufferup(void); 19 | 20 | 21 | void bufferbigdown(void); 22 | 23 | void bufferbigup(void); 24 | 25 | void startbuffer(void); 26 | 27 | void endbuffer(void); 28 | 29 | void restorebuffer(void); 30 | 31 | 32 | void log_line_in_buffer(char *ptr); 33 | 34 | #define BUFFERMAXCMD 40 35 | extern char buff_cmd[BUFFERMAXCMD][80]; 36 | extern int insertcmdindex; 37 | extern int cmdindex; 38 | 39 | #endif /* BUFFERING_H */ 40 | -------------------------------------------------------------------------------- /0.3/Makefile-26: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the Rasta Ring 0 debug 3 | # 4 | # Copyright (C) 2004 Droids Corporation 5 | # http://www.droids-corp.org/ 6 | # 7 | # $Id: Makefile-26,v 1.9 2006-07-12 13:09:25 serpilliere Exp $ 8 | # 9 | 10 | EXTRA_CFLAGS += -O2 -Wall -DLINUX_26 11 | 12 | OBJ := module_nux.o breakpoint.o buffering.o command.o disasmbak.o idt.o 13 | OBJ += keyboard.o page.o video.o utils.o import_symb.o core_rr0d.o pci.o 14 | MODULE := rr0d.o 15 | 16 | obj-m := $(MODULE) 17 | rr0d-objs := $(OBJ) 18 | 19 | default: 20 | make -C /lib/modules/`uname -r`/build/ SUBDIRS=`pwd` modules 21 | 22 | clean: 23 | rm -f *.o .*.o.cmd .*.ko.cmd *.mod.c *~ 24 | rm -rf .tmp_versions 25 | 26 | mrproper: 27 | make clean 28 | rm -f *.ko 29 | -------------------------------------------------------------------------------- /0.3/module_freebsd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | extern int init_rr0d(void); 11 | extern void cleanup_rr0d(void); 12 | 13 | 14 | static int handler (struct module *module, int cmd, void *arg) { 15 | int error = 0; 16 | 17 | switch (cmd) { 18 | case MOD_LOAD : 19 | init_rr0d(); 20 | break; 21 | case MOD_UNLOAD: 22 | cleanup_rr0d(); 23 | break; 24 | default : 25 | error = EINVAL; 26 | break; 27 | } 28 | 29 | return error; 30 | } 31 | 32 | static moduledata_t rr0d_mod = { 33 | "rr0d", 34 | handler, 35 | NULL 36 | }; 37 | 38 | DECLARE_MODULE(rr0d, rr0d_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); 39 | -------------------------------------------------------------------------------- /0.3/page.h: -------------------------------------------------------------------------------- 1 | #ifndef PAGE_H 2 | #define PAGE_H 3 | 4 | 5 | extern unsigned int pagedir; 6 | 7 | 8 | unsigned int* basetp(void); 9 | unsigned int get_page_info(unsigned int adresse, unsigned int *tab_page, unsigned int *tab_page_entry, unsigned int *level ); 10 | int page_exist(unsigned int ); 11 | unsigned int set_page_info(unsigned int adresse, unsigned int data, unsigned int level); 12 | 13 | int write_save_dirty(unsigned char* ptr, unsigned char o); 14 | void display_page(unsigned int page_ad); 15 | 16 | unsigned int get_page_phys(unsigned int ad); 17 | 18 | unsigned int linear2physical(unsigned int ptr); 19 | 20 | 21 | void poked(unsigned int ptr, unsigned int v); 22 | 23 | void poked1(unsigned int ptr, unsigned int v); 24 | 25 | void poked_cache(unsigned int ptr, unsigned int v); 26 | 27 | 28 | extern unsigned int saved_wp_bit; 29 | 30 | 31 | 32 | void clear_wp_bit(void); 33 | void restore_wp_bit(void); 34 | 35 | 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /0.3/keyboard.h: -------------------------------------------------------------------------------- 1 | #ifndef KEYBOARD_H 2 | #define KEYBOARD_H 3 | 4 | #define KBENTER -1 5 | #define KBF11 -2 6 | #define KBF12 -3 7 | #define KBDEL -4 8 | #define KBCURSORUP -5 9 | #define KBCURSORDOWN -6 10 | #define KBLEFTALT -7 11 | #define KBRIGHTSHIFT -8 12 | #define KBPAGEUP -9 13 | #define KBPAGEDOWN -10 14 | 15 | #define KBLEFTSHIFT -11 16 | 17 | #define KBCURSORLEFT -12 18 | #define KBCURSORRIGHT -13 19 | 20 | #define KBESC -14 21 | 22 | 23 | #define KBUP -128 24 | 25 | 26 | 27 | 28 | 29 | 30 | unsigned int read_scancode(void); 31 | 32 | void handle_scancode(unsigned char ); 33 | 34 | char scan_to_ascii(int ); 35 | 36 | 37 | 38 | 39 | unsigned int WaitForKeyboard(void); 40 | void DrainOutputBuffer(void); 41 | unsigned int SendKeyboardCommand(unsigned char); 42 | unsigned char print_keystroke(void); 43 | unsigned int myWaitForKeyboard(unsigned char*); 44 | 45 | unsigned int _read_scancode(void); 46 | 47 | 48 | 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /tests-linux/find_fb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2004 Droids Corporation 3 | * http://www.droids-corp.org/ 4 | * 5 | * important parts of this code were taken from the Linux source code, 6 | * Copyright (C) 1996 Linus Torvalds (file linux/mm/remap.c). See 7 | * http://www.kernel.org/ 8 | * 9 | * $Id: find_fb.c,v 1.3 2004-06-21 18:05:12 lalet Exp $ 10 | * 11 | */ 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | int init_module() 19 | { 20 | 21 | /* 0 est le mineur de /dev/fb0 */ 22 | struct fb_info *info = registered_fb[0]; 23 | #if 0 24 | int i; 25 | #endif 26 | 27 | if (info == NULL) { 28 | printk("No registered framebuffers!\n"); 29 | return 0; 30 | } 31 | 32 | printk("fb is at 0x%X\n", (unsigned int) info->screen_base); 33 | 34 | #if 0 35 | for (i=0; i<1024*3; i+=2) { 36 | * ((unsigned char *) info->disp->screen_base + i) = 0xff; 37 | * ((unsigned char *) info->disp->screen_base + i + 1) = 0; 38 | } 39 | #endif 40 | 41 | return 0; 42 | } 43 | 44 | void cleanup_module() 45 | { 46 | return ; 47 | } 48 | -------------------------------------------------------------------------------- /0.3/var_globale.h: -------------------------------------------------------------------------------- 1 | #ifndef VAR_GLOBALE_H 2 | #define VAR_GLOBALE_H 3 | 4 | extern int fired; 5 | extern unsigned int gdt_limit; 6 | 7 | 8 | extern unsigned long idt_[2]; 9 | 10 | extern unsigned long gdt_[2]; 11 | extern unsigned long ldt_[1]; 12 | 13 | 14 | extern unsigned int data_ptr; 15 | extern unsigned int old_data_ptr; 16 | 17 | extern unsigned int code_ptr; 18 | extern unsigned int old_code_ptr; 19 | 20 | extern char debug__[80]; 21 | 22 | typedef struct reg_struct { 23 | 24 | unsigned int reg_EDI; 25 | unsigned int reg_ESI; 26 | unsigned int reg_EBP; 27 | unsigned int reg_ESP_; 28 | unsigned int reg_EBX; 29 | unsigned int reg_EDX; 30 | unsigned int reg_ECX; 31 | unsigned int reg_EAX; 32 | 33 | unsigned int reg_ES; 34 | unsigned int reg_FS; 35 | unsigned int reg_GS; 36 | unsigned int reg_DS; 37 | 38 | unsigned int reg_dummy_ret; 39 | 40 | unsigned int reg_ERROR; 41 | 42 | unsigned int reg_EIP; 43 | unsigned int reg_CS; 44 | unsigned int reg_EFLAG; 45 | unsigned int reg_ESP; 46 | unsigned int reg_SS; 47 | } Reg_struct; 48 | 49 | 50 | 51 | extern Reg_struct *reg_stack; 52 | 53 | extern Reg_struct current_reg_stack; 54 | /* BUG /!\ pour nux, 0x18 */ 55 | 56 | void printf_disasm(unsigned int , unsigned char* ); 57 | 58 | #endif /* VAR_GLOBALE_H */ 59 | -------------------------------------------------------------------------------- /tests-openbsd/lkm/toto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ATTENTION : tel quel, le module crashe le kernel, c'est normal 3 | * 4 | * $Id: toto.c,v 1.9 2004-10-03 18:04:51 lalet Exp $ 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | MOD_MISC( "toto" ) 16 | 17 | unsigned int tarace; 18 | unsigned char *ptr; 19 | 20 | static int handler (struct lkm_table *lkmtp, int cmd) { 21 | int s; 22 | int error = 0; 23 | int i; 24 | 25 | switch (cmd) { 26 | case LKM_E_LOAD : 27 | 28 | #if 0 29 | __asm__ __volatile__ ( "\t" 30 | "call pouetpouet\n" 31 | "pouetpouet:\n\t" 32 | "pop %eax\n\t" 33 | "mov %eax, tarace\n\t" 34 | ); 35 | printf("tarace : 0x%.8X\n", tarace); 36 | ptr=tarace; 37 | #endif 38 | 39 | ptr = (unsigned int) 0xCD000000; 40 | while (1) { 41 | printf("0x%.8X : 0x%X\n", ptr, ptr[0]); 42 | ptr-=0x01000000; 43 | } 44 | /* la, on est morts, de toute facon */ 45 | 46 | break; 47 | case LKM_E_UNLOAD: 48 | break; 49 | default : 50 | error = EINVAL; 51 | break; 52 | } 53 | 54 | return error; 55 | } 56 | 57 | toto(struct lkm_table *lkmtp, int cmd, int ver) { 58 | DISPATCH(lkmtp, cmd, ver, handler, handler, lkm_nofunc) 59 | } 60 | -------------------------------------------------------------------------------- /0.3/config.h.sample: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Rasta Ring 0 debug 3 | * 4 | * Copyright (C) 2004 Droids Corporation. 5 | * based on Deblin debuger 6 | * 7 | * $Id: config.h.sample,v 1.13 2006-07-11 07:09:29 serpilliere Exp $ 8 | * 9 | */ 10 | 11 | #ifndef CONFIG_H 12 | #define CONFIG_H 13 | 14 | /* _________________________ OS definitions ____________________ */ 15 | 16 | /* FOR WINDOWS */ 17 | /* #define WIN32 */ 18 | /* #define KEYB_INTER 0x51 */ 19 | 20 | /* OR LINUX */ 21 | #define LINUX 22 | #define KEYB_INTER 0x21 23 | 24 | /* OR FREEBSD */ 25 | /* #define FREEBSD */ 26 | /* le reste viendra plus tard... */ 27 | 28 | 29 | /* ________________________ video definitions __________________ */ 30 | 31 | /* CONSOLE MODE */ 32 | /* #define VIDEO_AA */ 33 | 34 | /* OR GRAPHIC MODE */ 35 | /* we want a graphic mode */ 36 | #define VIDEO_FB 37 | /* we want direct hardware writtng */ 38 | #define HW_FB 39 | /* we want rr0d to find automatically the address of the video hardware */ 40 | #define AUTO_HW_FB 41 | /* we set a default value... */ 42 | #define SCREEN_ADRESSE 0xF0000000 43 | 44 | 45 | /* screen dimension (internal hardware dimensions) */ 46 | #define SCREEN_MAX_X 2048 47 | #define SCREEN_MAX_Y 768 48 | 49 | /* screen bytes per pixel (internal hardware dimensions) */ 50 | /* #define BYTE_PER_PIXEL_HALF */ 51 | /* #define BYTE_PER_PIXEL_ONE */ 52 | /* #define BYTE_PER_PIXEL_TWO */ 53 | /* #define BYTE_PER_PIXEL_THREE */ 54 | #define BYTE_PER_PIXEL_FOUR 55 | 56 | 57 | /* ____________________________ custom _________________________ */ 58 | 59 | #define DONT_HOOK_KBD 60 | 61 | #endif /* CONFIG_H */ 62 | -------------------------------------------------------------------------------- /0.3/Spy.def: -------------------------------------------------------------------------------- 1 | ;**************************************************************************** 2 | ; * 3 | ; THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY * 4 | ; KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * 5 | ; IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR * 6 | ; PURPOSE. * 7 | ; * 8 | ; Copyright 1993-95 Microsoft Corporation. All Rights Reserved. * 9 | ; * 10 | ;**************************************************************************** 11 | 12 | VXD SPY DYNAMIC 13 | 14 | DESCRIPTION 'SPY to monitor File i/o' 15 | 16 | SEGMENTS 17 | _LPTEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE 18 | _LTEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE 19 | _LDATA CLASS 'LCODE' PRELOAD NONDISCARDABLE 20 | _TEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE 21 | _DATA CLASS 'LCODE' PRELOAD NONDISCARDABLE 22 | CONST CLASS 'LCODE' PRELOAD NONDISCARDABLE 23 | _TLS CLASS 'LCODE' PRELOAD NONDISCARDABLE 24 | _BSS CLASS 'LCODE' PRELOAD NONDISCARDABLE 25 | _ITEXT CLASS 'ICODE' DISCARDABLE 26 | _IDATA CLASS 'ICODE' DISCARDABLE 27 | _PTEXT CLASS 'PCODE' NONDISCARDABLE 28 | _PDATA CLASS 'PDATA' NONDISCARDABLE SHARED 29 | _STEXT CLASS 'SCODE' RESIDENT 30 | _SDATA CLASS 'SCODE' RESIDENT 31 | _DBOSTART CLASS 'DBOCODE' PRELOAD NONDISCARDABLE CONFORMING 32 | _DBOCODE CLASS 'DBOCODE' PRELOAD NONDISCARDABLE CONFORMING 33 | _DBODATA CLASS 'DBOCODE' PRELOAD NONDISCARDABLE CONFORMING 34 | _16ICODE CLASS '16ICODE' PRELOAD DISCARDABLE 35 | _RCODE CLASS 'RCODE' 36 | EXPORTS 37 | SPY_DDB @1 38 | 39 | -------------------------------------------------------------------------------- /0.3/import_symb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Rasta Ring 0 debug 3 | * 4 | * Copyright (C) 2004 Droids Corporation. 5 | * based on Deblin debuger 6 | * 7 | * $Id 8 | * 9 | */ 10 | 11 | #include "import_symb.h" 12 | #include "utils.h" 13 | #include "buffering.h" 14 | 15 | 16 | Symbol tab_import_symb[MAX_SYMBOL]; 17 | 18 | 19 | void init_symb(void) 20 | { 21 | int i; 22 | for (i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | typedef uint64_t pd_entry_t; 7 | extern pd_entry_t PTD[]; 8 | 9 | extern pd_entry_t PTmap[]; 10 | 11 | unsigned int * my_ptd; 12 | unsigned int my_cr3; 13 | 14 | int tototiti; 15 | 16 | //extern u_int KERNELBASEPDE; 17 | 18 | 19 | unsigned int gdt[2]; 20 | unsigned int * ad_gdt; 21 | unsigned int cs_val=0; 22 | unsigned int ds_val=0; 23 | unsigned int fs_val=0; 24 | unsigned int gs_val=0; 25 | unsigned int es_val=0; 26 | 27 | unsigned int ss_val=0; 28 | static int handler (struct module *module, int cmd, void *arg) { 29 | int s; 30 | int error = 0; 31 | int i; 32 | 33 | switch (cmd) { 34 | case MOD_LOAD : 35 | // printf("%.8X\n", KERNELBASEPDE); 36 | 37 | printf("PTmap: %.8X\n", PTmap); 38 | printf("PTD: 0x%.8x\n", PTD); 39 | __asm__("mov %cr3, %eax"); 40 | __asm__("mov %eax, my_cr3"); 41 | printf("CR3: 0x%.8x\n", my_cr3); 42 | 43 | my_ptd = my_cr3;//(unsigned int *) PTD; 44 | 45 | my_ptd+=(0xc00>>2); 46 | printf("ptd: %.8X\n", my_ptd); 47 | 48 | 49 | printf("page info 0 %.8X\n", my_ptd[0]); 50 | 51 | /* 52 | for (i=0;i<1024;i++) 53 | { 54 | if (my_ptd[i]&1) 55 | printf("info :%.8X\n", my_ptd[i]); 56 | } 57 | */ 58 | 59 | // printf("KERN_BASE: %.8X\n", PTD-my_cr3); 60 | __asm__("mov %cs, %ax\n mov %eax, cs_val"); 61 | __asm__("mov %ds, %ax\n mov %eax, ds_val"); 62 | __asm__("mov %gs, %ax\n mov %eax, fs_val"); 63 | __asm__("mov %fs, %ax\n mov %eax, gs_val"); 64 | __asm__("mov %es, %ax\n mov %eax, es_val"); 65 | __asm__("mov %ss, %ax\n mov %eax, ss_val"); 66 | printf("cs: 0x%x\n", cs_val); 67 | printf("ds: 0x%x\n", ds_val); 68 | printf("fs: 0x%x\n", fs_val); 69 | printf("gs: 0x%x\n", gs_val); 70 | printf("es: 0x%x\n", es_val); 71 | printf("ss: 0x%x\n", ss_val); 72 | 73 | 74 | 75 | break; 76 | case MOD_UNLOAD: 77 | break; 78 | default : 79 | error = EINVAL; 80 | break; 81 | } 82 | 83 | return error; 84 | } 85 | 86 | static moduledata_t toto_mod = { 87 | "toto", 88 | handler, 89 | NULL 90 | }; 91 | 92 | DECLARE_MODULE(toto, toto_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); 93 | -------------------------------------------------------------------------------- /0.3/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Rasta Ring 0 debug 3 | * 4 | * Copyright (C) 2004 Droids Corporation. 5 | * based on Deblin debuger 6 | * 7 | * $Id $ 8 | * 9 | */ 10 | 11 | 12 | /*tout est dit (ou pas) */ 13 | /* */ 14 | 15 | #define size_t unsigned int 16 | 17 | unsigned char rr0d_inb (unsigned int Port); 18 | unsigned short rr0d_inw (unsigned int Port); 19 | unsigned int rr0d_inl (unsigned int Port); 20 | void rr0d_outb (unsigned char Value , unsigned int Port); 21 | void rr0d_outw (unsigned short Value, unsigned int Port); 22 | void rr0d_outl (unsigned int Value , unsigned int Port); 23 | 24 | 25 | 26 | int Sprintf (char *outbuf, char *fmt, ...); 27 | 28 | 29 | 30 | 31 | int rr0d_isalpha(register int ); 32 | int rr0d_isupper(register int ); 33 | int rr0d_islower(register int ); 34 | int rr0d_isdigit(register int ); 35 | int rr0d_isxdigit(register int ); 36 | int rr0d_isspace(register int ); 37 | int rr0d_ispunct(register int ); 38 | int rr0d_isalnum(register int ); 39 | int rr0d_isprint(register int ); 40 | int rr0d_isgraph(register int ); 41 | int rr0d_iscntrl(register int ); 42 | int rr0d_isascii(register int ); 43 | int rr0d_toascii(register int ); 44 | 45 | #define rr0d_toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z'))) 46 | #define rr0d_tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z'))) 47 | 48 | int rr0d_atoi( char *); 49 | char * rr0d_strchr( char *, int ); 50 | int rr0d_strcmp( char *, char *); 51 | //#if 0 52 | size_t rr0d_strlen( char *); 53 | int rr0d_strnicmp ( char *, char *,size_t ); 54 | //#endif 55 | int rr0d_stricmp (char *, char *); 56 | char * rr0d_strcpy(char *, char *); 57 | unsigned rr0d_strcspn( char *, char *); 58 | char *rr0d_strcat(char *, char *); 59 | char *rr0d_strncat(char *, char *, unsigned int ); 60 | int rr0d_strncmp( char *, char *, unsigned int ); 61 | char * rr0d_strncpy(char *, char *, unsigned int ); 62 | char * rr0d_strpbrk( char *, char *); 63 | char * rr0d_strrchr( char *, int ); 64 | unsigned int rr0d_strspn( char *, char *); 65 | char * rr0d_strstr( char *, char *); 66 | char * rr0d_strtok_r(char *, char *, char **); 67 | 68 | 69 | 70 | void* rr0d_memset(void* , int , unsigned int ); 71 | void* rr0d_memcpy(void* , void* , unsigned int ); 72 | 73 | -------------------------------------------------------------------------------- /0.3/SpyAsm.asm: -------------------------------------------------------------------------------- 1 | ;****************************************************************************** 2 | TITLE CONTROL - ControlDispatch for VxD in C 3 | ;****************************************************************************** 4 | ; 5 | 6 | .386p 7 | 8 | ;****************************************************************************** 9 | ; I N C L U D E S 10 | ;****************************************************************************** 11 | IFSFN_DELETE Equ 31 12 | IFSFN_OPEN Equ 36 13 | IFSFN_READ Equ 0 14 | .xlist 15 | include vmm.inc 16 | include debug.inc 17 | include ifsmgr.inc 18 | 19 | public _Sprintf1 20 | 21 | ; the following equate makes the VXD dynamically loadable. 22 | SPY_DYNAMIC EQU 1 23 | 24 | ;============================================================================ 25 | ; V I R T U A L D E V I C E D E C L A R A T I O N 26 | ;============================================================================ 27 | 28 | DECLARE_VIRTUAL_DEVICE SPY, 1, 0, SPY_Control, UNDEFINED_DEVICE_ID, \ 29 | UNDEFINED_INIT_ORDER 30 | 31 | VxD_LOCKED_CODE_SEG 32 | 33 | ;=========================================================================== 34 | ; 35 | ; PROCEDURE: SPY_Control 36 | ; 37 | ; DESCRIPTION: 38 | ; Device control procedure for the SPY VxD 39 | ; 40 | ; ENTRY: 41 | ; EAX = Control call ID 42 | ; 43 | ; EXIT: 44 | ; If carry clear then 45 | ; Successful 46 | ; else 47 | ; Control call failed 48 | ; 49 | ; USES: 50 | ; EAX, EBX, ECX, EDX, ESI, EDI, Flags 51 | ; 52 | ;============================================================================ 53 | 54 | BeginProc SPY_Control 55 | Control_Dispatch SYS_DYNAMIC_DEVICE_INIT, SPY_Dynamic_Init, sCall 56 | Control_Dispatch SYS_DYNAMIC_DEVICE_EXIT, SPY_Dynamic_Exit, sCall 57 | Control_Dispatch W32_DEVICEIOCONTROL, SPY_W32_DeviceIOControl, sCall, 58 | clc 59 | ret 60 | EndProc SPY_Control 61 | 62 | VxD_LOCKED_CODE_ENDS 63 | 64 | ; ************************************************************************* 65 | VxD_LOCKED_DATA_SEG 66 | PrevFunc Dd 0 67 | VxD_LOCKED_DATA_ENDS 68 | ; ************************************************************************* 69 | 70 | VxD_CODE_SEG 71 | BeginProc _Sprintf1 72 | PUSH EBP 73 | MOV EBP, ESP 74 | VMMCall _Sprintf, <[EBP+8h], [EBP+0Ch], [EBP+10h], [EBP+14h]> 75 | POP EBP 76 | RET 77 | EndProc _Sprintf1 78 | VxD_CODE_ENDS 79 | END 80 | -------------------------------------------------------------------------------- /0.3/idt.h: -------------------------------------------------------------------------------- 1 | #ifndef IDH_H 2 | #define IDT_H 3 | 4 | #include 5 | 6 | unsigned int* getbaseidt(void); 7 | unsigned int* getbasegdt(void); 8 | unsigned int getbaseldt(void); 9 | unsigned int translate_logic_to_linear(unsigned int , unsigned int ); 10 | void visualise_idt(unsigned long *); 11 | unsigned long modifie_idt(unsigned int ,unsigned int *); 12 | unsigned long read_idt_entry(unsigned int *); 13 | 14 | struct segment_descriptor { 15 | unsigned limit0:16; 16 | unsigned base0:24; 17 | unsigned type:5; 18 | unsigned dpl:2; 19 | unsigned present:1; 20 | unsigned limit1:4; 21 | unsigned reserved:2; 22 | unsigned def32:1; 23 | unsigned gran:1; 24 | unsigned base:8; 25 | }; 26 | 27 | static inline u32 sd_offset(struct segment_descriptor *sd) { 28 | return (sd->base0 | sd->base >> 24); 29 | } 30 | 31 | static inline u32 sd_limit(struct segment_descriptor *sd) { 32 | return (sd->limit0 | sd->limit1 >> 16); 33 | } 34 | 35 | static inline u32 sd_present(struct segment_descriptor *sd) { 36 | return (sd->present); 37 | } 38 | 39 | static inline u32 sd_dpl(struct segment_descriptor *sd) { 40 | return (sd->dpl); 41 | } 42 | 43 | struct gate_descriptor { 44 | unsigned offset0:16; 45 | unsigned selector:16; 46 | unsigned stkcpy:5; 47 | unsigned reserved:3; 48 | unsigned type:5; 49 | unsigned dpl:2; 50 | unsigned present:1; 51 | unsigned offset1:16; 52 | }; 53 | 54 | static inline u32 gd_offset(struct gate_descriptor *gd) { 55 | return (gd->offset0 | gd->offset1 >> 16); 56 | } 57 | 58 | static inline u32 gd_present(struct gate_descriptor *gd) { 59 | return (gd->present); 60 | } 61 | 62 | static inline u32 gd_dpl(struct gate_descriptor *gd) { 63 | return (gd->dpl); 64 | } 65 | 66 | static inline u32 gd_type(struct gate_descriptor *gd) { 67 | return (gd->type); 68 | } 69 | 70 | static inline u32 gd_selector(struct gate_descriptor *gd) { 71 | return (gd->selector); 72 | } 73 | 74 | union descriptor { 75 | struct gate_descriptor gd; 76 | struct segment_descriptor sd; 77 | }; 78 | 79 | typedef struct { 80 | u16 limit; 81 | u32 base; 82 | } IDTR; 83 | 84 | typedef struct { 85 | u16 limit; 86 | u32 base; 87 | } GDTR; 88 | 89 | typedef struct { 90 | u16 limit; 91 | u32 base; 92 | } LDTR; 93 | 94 | #define IDT_MAX (0xFF) 95 | 96 | #define DT_TSS 0x9 97 | #define DT_NULL 0xA 98 | #define DT_TSSBUSY 0xB 99 | #define DT_CALL 0xC 100 | #define DT_GATE 0xE 101 | #define DT_TRAP 0xF 102 | 103 | #endif /* IDT_H */ 104 | -------------------------------------------------------------------------------- /0.3/SpyExec.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * PROGRAM: CON_SAMP.C 4 | * 5 | * PURPOSE: Simple console application for calling CVXDSAMP (C VxD Sample) VxD 6 | * 7 | * FUNCTIONS: 8 | * main() - Console application calls VMM and VKD through CVXDSAMP which 9 | * supports DeviceIoControl. CVXDSAMP will return values to this 10 | * application through this same DeviceIoControl interface. 11 | * 12 | * SPECIAL INSTRUCTIONS: 13 | * 14 | ****************************************************************************/ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define SPY_APIFUNC_1 1 22 | #define SPY_APIFUNC_2 2 23 | #define SPY_APIFUNC_3 3 24 | 25 | int main() 26 | { 27 | HANDLE hCVxD = 0; 28 | DWORD cbBytesReturned; 29 | DWORD dwErrorCode; 30 | DWORD RetInfo[1]; 31 | #if 0 32 | DWORD ErrorCode; 33 | #endif 34 | 35 | /* 36 | * Dynamically load and prepare to call CVXDSAMP 37 | * The CREATE_NEW flag is not necessary 38 | */ 39 | 40 | hCVxD = CreateFile("\\\\.\\SPY.VXD", 0,0,0, 41 | CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0); 42 | 43 | if ( hCVxD == INVALID_HANDLE_VALUE ) 44 | { 45 | dwErrorCode = GetLastError(); 46 | if ( dwErrorCode == ERROR_NOT_SUPPORTED ) 47 | { 48 | printf("Unable to open VxD, \n device does not support DeviceIOCTL\n"); 49 | } 50 | else 51 | { 52 | printf("Unable to open VxD, Error code: %lx\n", dwErrorCode); 53 | } 54 | } 55 | else 56 | { 57 | if(!DeviceIoControl(hCVxD, SPY_APIFUNC_3, 58 | (LPVOID)NULL, 0, 59 | (LPVOID)RetInfo, sizeof(RetInfo), 60 | &cbBytesReturned, NULL)){ 61 | printf("Unable to create C:\\FileCall.Spy file! Aborting!"); 62 | CloseHandle(hCVxD); 63 | exit(1); 64 | } 65 | DeviceIoControl(hCVxD, SPY_APIFUNC_1, 66 | (LPVOID)NULL, 0, 67 | (LPVOID)RetInfo, sizeof(RetInfo), 68 | &cbBytesReturned, NULL); 69 | MessageBox(NULL, "Press OK to unhook spy\nLogging to C:\\FileCall.Spy", "SPY HOOKED", MB_OK); 70 | 71 | system("pause"); 72 | 73 | DeviceIoControl(hCVxD, SPY_APIFUNC_2, 74 | (LPVOID)NULL, 0, 75 | (LPVOID)RetInfo, sizeof(RetInfo), 76 | &cbBytesReturned, NULL); 77 | /* Dynamically unload SPY */ 78 | if(!CloseHandle(hCVxD)) 79 | printf("Unable to close\n"); 80 | 81 | } 82 | return(0); 83 | } 84 | -------------------------------------------------------------------------------- /0.3/exporter/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | 7 | 8 | 9 | 10 | #define SYMBOL_NAME_LEN 16 11 | 12 | 13 | typedef struct symb_struct { 14 | unsigned int adress; 15 | char name[SYMBOL_NAME_LEN]; 16 | } Symbol; 17 | 18 | Symbol *buffer_export; 19 | unsigned int export_num=0; 20 | 21 | 22 | 23 | void add_export(char* name, unsigned int ad) 24 | { 25 | 26 | buffer_export = realloc(buffer_export, (export_num+1)*sizeof(Symbol)); 27 | if (!buffer_export) 28 | { 29 | fprintf(stderr, "err malloc\n"); 30 | exit(0); 31 | } 32 | 33 | strncpy(buffer_export[export_num].name, name, SYMBOL_NAME_LEN-1); 34 | buffer_export[export_num].adress = ad; 35 | export_num++; 36 | 37 | } 38 | 39 | 40 | int main(int argc, char** argv) 41 | { 42 | 43 | void* handle; 44 | unsigned int (*my_strlen)(char*); 45 | char* error; 46 | FILE* f_list; 47 | char name_export[1024]; 48 | unsigned int ad_export; 49 | int filtre=1; 50 | unsigned int a, b; 51 | 52 | 53 | 54 | 55 | buffer_export = malloc(1*sizeof(Symbol)); 56 | if (!buffer_export) 57 | { 58 | fprintf(stderr, "err malloc\n"); 59 | exit(0); 60 | } 61 | 62 | 63 | f_list = fopen("lib_list_libc", "r"); 64 | 65 | if (!f_list) 66 | { 67 | fprintf(stderr, "open lib list failed\n"); 68 | exit(1); 69 | } 70 | #ifdef FREEBSD 71 | handle = dlopen("/lib/libc.so.5", RTLD_LAZY); 72 | #else 73 | handle = dlopen("/lib/libc.so.6", RTLD_LAZY); 74 | #endif 75 | 76 | 77 | 78 | if (!handle) 79 | { 80 | fputs(dlerror(), stderr); 81 | exit(1); 82 | } 83 | 84 | while(fscanf(f_list, "%s", name_export)!=-1) 85 | { 86 | if (filtre) 87 | { 88 | if ( (name_export[0]=='_')|| 89 | (name_export[0]=='.')) 90 | continue; 91 | } 92 | ad_export = dlsym(handle, name_export); 93 | if ( (error = dlerror())!=NULL) 94 | { 95 | fprintf(stderr, "%s\n", error); 96 | //exit(1); 97 | continue; 98 | } 99 | 100 | printf("%s\t %.8X\n",name_export, ad_export); 101 | add_export(name_export, ad_export); 102 | 103 | } 104 | 105 | printf("total export: %d\n", export_num); 106 | /* 107 | a = (unsigned int) buffer_export; 108 | b = 0; 109 | a = a/b; 110 | */ 111 | __asm("mov buffer_export, %eax"); 112 | __asm("mov export_num, %ebx"); 113 | 114 | __asm("mov $0, %edx"); 115 | __asm("mov $0x1337beef, %ecx"); 116 | // __asm("div %edx"); 117 | __asm("int $0x3"); 118 | 119 | 120 | 121 | 122 | a = strlen(argv[0]); 123 | 124 | __asm("int $0x3"); 125 | 126 | a+= strlen(argv[0]); 127 | 128 | 129 | 130 | return a; 131 | } 132 | 133 | -------------------------------------------------------------------------------- /0.3/Mylocal.inc: -------------------------------------------------------------------------------- 1 | ;**************************************************************************** 2 | ; * 3 | ; THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY * 4 | ; KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * 5 | ; IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR * 6 | ; PURPOSE. * 7 | ; * 8 | ; Copyright 1993-95 Microsoft Corporation. All Rights Reserved. * 9 | ; * 10 | ;**************************************************************************** 11 | 12 | .386p 13 | 14 | include basedef.inc 15 | include vmm.inc 16 | include debug.inc 17 | ;include ifsmgr.inc 18 | 19 | .errndef SEGNUM 20 | 21 | IFE SEGNUM-1 22 | 23 | SEGB TEXTEQU 24 | SEGE TEXTEQU 25 | 26 | ELSEIFE SEGNUM-2 27 | 28 | SEGB TEXTEQU 29 | SEGE TEXTEQU 30 | 31 | ELSEIFE SEGNUM-3 32 | 33 | SEGB TEXTEQU 34 | SEGE TEXTEQU 35 | 36 | ELSEIFE SEGNUM-4 37 | 38 | SEGB TEXTEQU 39 | SEGE TEXTEQU 40 | 41 | ELSEIFE SEGNUM-5 42 | 43 | SEGB TEXTEQU 44 | SEGE TEXTEQU 45 | 46 | ELSEIFE SEGNUM-6 47 | 48 | SEGB TEXTEQU 49 | SEGE TEXTEQU 50 | 51 | ELSE 52 | %OUT Wrong SEGNUM 53 | .err 54 | 55 | ENDIF 56 | 57 | BEGSEG MACRO 58 | SEGB 59 | ENDM 60 | 61 | ENDSEG MACRO 62 | SEGE 63 | ENDM 64 | 65 | @RETNAME MACRO Name 66 | LOCAL txt 67 | IFE SEGNUM-1 68 | 69 | txt TEXTEQU @CATSTR(_LCODE_,Name) 70 | 71 | ELSEIFE SEGNUM-2 72 | 73 | txt TEXTEQU @CATSTR(_ICODE_,Name) 74 | 75 | ELSEIFE SEGNUM-3 76 | 77 | txt TEXTEQU @CATSTR(_PCODE_,Name) 78 | 79 | ELSEIFE SEGNUM-4 80 | 81 | txt TEXTEQU @CATSTR(_SCODE_,Name) 82 | 83 | ELSEIFE SEGNUM-5 84 | 85 | txt TEXTEQU @CATSTR(_DCODE_,Name) 86 | 87 | ELSE 88 | 89 | txt TEXTEQU @CATSTR(_CCODE_,Name) 90 | 91 | ENDIF 92 | 93 | EXITM txt 94 | ENDM 95 | 96 | 97 | StartCDecl MACRO Name 98 | PUBLIC @RETNAME(Name) 99 | BEGSEG 100 | @RETNAME(Name) PROC NEAR 101 | ENDM 102 | 103 | EndCDecl MACRO Name 104 | @RETNAME(Name) ENDP 105 | ENDSEG 106 | ENDM 107 | 108 | MakeCDecl MACRO Name 109 | StartCDecl Name 110 | VxDJmp Name 111 | EndCDecl Name 112 | ENDM 113 | 114 | MakeStdCall MACRO Name, Param 115 | StartCDecl Name&@&Param 116 | VxDJmp Name 117 | EndCDecl Name&@&Param 118 | ENDM 119 | 120 | -------------------------------------------------------------------------------- /0.3/insns.h: -------------------------------------------------------------------------------- 1 | /* insns.h header file for insns.c 2 | * 3 | * The Netwide Assembler is copyright (C) 1996 Simon Tatham and 4 | * Julian Hall. All rights reserved. The software is 5 | * redistributable under the licence given in the file "Licence" 6 | * distributed in the NASM archive. 7 | */ 8 | 9 | #ifndef NASM_INSNS_H 10 | #define NASM_INSNS_H 11 | 12 | struct itemplate { 13 | int opcode; /* the token, passed from "parser.c" */ 14 | int operands; /* number of operands */ 15 | long opd[3]; /* bit flags for operand types */ 16 | char *code; /* the code it assembles to */ 17 | int flags; /* some flags */ 18 | }; 19 | 20 | /* 21 | * Instruction template flags. These specify which processor 22 | * targets the instruction is eligible for, whether it is 23 | * privileged or undocumented, and also specify extra error 24 | * checking on the matching of the instruction. 25 | * 26 | * IF_SM stands for Size Match: any operand whose size is not 27 | * explicitly specified by the template is `really' intended to be 28 | * the same size as the first size-specified operand. 29 | * Non-specification is tolerated in the input instruction, but 30 | * _wrong_ specification is not. 31 | * 32 | * IF_SM2 invokes Size Match on only the first _two_ operands, for 33 | * three-operand instructions such as SHLD: it implies that the 34 | * first two operands must match in size, but that the third is 35 | * required to be _unspecified_. 36 | * 37 | * IF_SB invokes Size Byte: operands with unspecified size in the 38 | * template are really bytes, and so no non-byte specification in 39 | * the input instruction will be tolerated. IF_SW similarly invokes 40 | * Size Word, and IF_SD invokes Size Doubleword. 41 | * 42 | * (The default state if neither IF_SM nor IF_SM2 is specified is 43 | * that any operand with unspecified size in the template is 44 | * required to have unspecified size in the instruction too...) 45 | */ 46 | 47 | #define IF_SM 0x0001 /* size match */ 48 | #define IF_SM2 0x0002 /* size match first two operands */ 49 | #define IF_SB 0x0004 /* unsized operands can't be non-byte */ 50 | #define IF_SW 0x0008 /* unsized operands can't be non-word */ 51 | #define IF_SD 0x0010 /* unsized operands can't be nondword */ 52 | #define IF_8086 0x0000 /* 8086 instruction */ 53 | #define IF_186 0x0100 /* 186+ instruction */ 54 | #define IF_286 0x0200 /* 286+ instruction */ 55 | #define IF_386 0x0300 /* 386+ instruction */ 56 | #define IF_486 0x0400 /* 486+ instruction */ 57 | #define IF_PENT 0x0500 /* Pentium instruction */ 58 | #define IF_P6 0x0600 /* P6 instruction */ 59 | #define IF_CYRIX 0x0800 /* Cyrix-specific instruction */ 60 | #define IF_PMASK 0x0F00 /* the mask for processor types */ 61 | #define IF_PRIV 0x1000 /* it's a privileged instruction */ 62 | #define IF_UNDOC 0x2000 /* it's an undocumented instruction */ 63 | #define IF_FPU 0x4000 /* it's an FPU instruction */ 64 | #define IF_MMX 0x8000 /* it's an MMX instruction */ 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /0.3/Makefile-win: -------------------------------------------------------------------------------- 1 | #**************************************************************************** 2 | # * 3 | # THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY * 4 | # KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * 5 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR * 6 | # PURPOSE. * 7 | # * 8 | # Copyright 1993-95 Microsoft Corporation. All Rights Reserved. * 9 | # * 10 | #**************************************************************************** 11 | 12 | !ifdef MASTER_MAKE 13 | BUILD_BITS=32 14 | BUILD_TYPE=base 15 | !INCLUDE $(DDKROOT)\master.mk 16 | !endif 17 | 18 | CFLAGS = -DWIN32 -DCON -Di386 -D_X86_ -D_NTWIN -W3 -Gs -D_DEBUG -Zi 19 | CVXDFLAGS = -Zdp -Gs -c -DIS_32 -Zl -DDEBLEVEL=1 -DDEBUG 20 | LFLAGS = -machine:i386 -debug:full -debugtype:cv /PDB:BIN\SPY.PDB -subsystem:console kernel32.lib user32.lib shell32.lib libc.lib 21 | AFLAGS = -coff -DBLD_COFF -DIS_32 -W2 -Zd -c -Cx -DMASM6 -DDEBLEVEL=1 -DDEBUG 22 | 23 | all: direxist bin\SpyExec.exe bin\Spy.vxd 24 | 25 | direxist: 26 | if not exist bin\nul md bin 27 | 28 | bin\Spy.obj: Spy.c 29 | cl $(CVXDFLAGS) -Fo$@ %s 30 | 31 | bin\video.obj: video.c 32 | cl -c -Fo$@ %s 33 | 34 | bin\idt.obj: idt.c 35 | cl -c -Fo$@ %s 36 | 37 | bin\keyboard.obj: keyboard.c 38 | cl -c -Fo$@ %s 39 | 40 | bin\buffering.obj: buffering.c 41 | cl -c -Fo$@ %s 42 | 43 | bin\disasmbak.obj: disasmbak.c 44 | cl -c -Fo$@ %s 45 | 46 | bin\page.obj: page.c 47 | cl -c -Fo$@ %s 48 | 49 | bin\command.obj: command.c 50 | cl -c -Fo$@ %s 51 | 52 | bin\breakpoint.obj: breakpoint.c 53 | cl -c -Fo$@ %s 54 | 55 | bin\pci.obj: pci.c 56 | cl -c -Fo$@ %s 57 | 58 | bin\SpyAsm.obj: SpyAsm.asm 59 | F:\masm32\BIN\ml $(AFLAGS) -Fo$@ %s 60 | 61 | bin\Spy.vxd: bin\Spy.obj bin\video.obj bin\idt.obj bin\keyboard.obj bin\buffering.obj bin\disasmbak.obj bin\page.obj bin\command.obj bin\breakpoint.obj bin\SpyAsm.obj Spy.def 62 | echo >NUL @<NUL @< 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | 15 | 16 | 17 | typedef struct 18 | { 19 | char *ptr; // Pointer to the DGA framebuffer 20 | int width; // Width of the screen 21 | int banksize; // 22 | int memsize; // 23 | 24 | } TMYWIN; 25 | 26 | void CollectDisplayInfo(char *sDisplay, unsigned int fQuery) 27 | { 28 | //static TXINITPACKET Init; // Init packet sent to the debugger 29 | 30 | Display *display; // Display name to connect to 31 | XWindowAttributes windowattr; // Window attributes structure 32 | int screen_num; // Screen number 33 | Screen *screen_ptr; // Pointer to screen structure 34 | TMYWIN mywin; // Structure holding window information 35 | 36 | int event_base, error_base; 37 | 38 | unsigned int display_width, display_height; 39 | unsigned char* tmp; 40 | unsigned int* tmp_i; 41 | int a; 42 | 43 | int i; 44 | 45 | display = XOpenDisplay(sDisplay); 46 | 47 | if( !display ) 48 | { 49 | fprintf(stderr, "FAILED: Cannot connect to server %s\n", XDisplayName(sDisplay)); 50 | return; 51 | } 52 | 53 | // Get the screen number and pointers 54 | screen_num = DefaultScreen(display); 55 | screen_ptr = DefaultScreenOfDisplay(display); 56 | 57 | 58 | // Get the root window attributes 59 | if( !XGetWindowAttributes(display, RootWindow(display, screen_num), &windowattr) ) 60 | { 61 | fprintf(stderr, "FAILED: Unable to get root window attributes\n"); 62 | return; 63 | } 64 | 65 | display_width = windowattr.width; 66 | display_height = windowattr.height; 67 | 68 | printf("%d %d\n", display_width, display_height); 69 | 70 | // Query the DGA extension - this is specific to XFree86 71 | if(! XF86DGAQueryExtension(display, &event_base, &error_base) ) 72 | { 73 | fprintf(stderr, "FAILED: Unable to query the DGA extension\n"); 74 | fprintf(stderr, "Your display does not support DGA extensions!\n"); 75 | return; 76 | } 77 | printf("%d %d\n", event_base, error_base& XF86DGADirectPresent); 78 | 79 | if(! XF86DGAGetVideo(display, screen_num, &mywin.ptr, &mywin.width, &mywin.banksize, &mywin.memsize) ) 80 | { 81 | fprintf(stderr, "FAILED: XF86DGAGetVideo\n"); 82 | return; 83 | } 84 | tmp = (unsigned char*)mywin.ptr; 85 | tmp_i = (unsigned int*)mywin.ptr; 86 | printf("bank: %X\n", mywin.banksize); 87 | printf("%p %X %X %X \n", 88 | mywin.ptr, 89 | mywin.width, 90 | mywin.memsize, 91 | mywin.memsize/ mywin.width); 92 | printf("%d\n", windowattr.depth); 93 | 94 | for (i=0;i=3 4 | #pragma GCC system_header 5 | #endif 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #define VS_FILE_INFO RT_VERSION 11 | #define VS_VERSION_INFO 1 12 | #define VS_USER_DEFINED 100 13 | #define VS_FFI_SIGNATURE 0xFEEF04BD 14 | #define VS_FFI_STRUCVERSION 0x10000 15 | #define VS_FFI_FILEFLAGSMASK 0x3F 16 | #define VS_FF_DEBUG 1 17 | #define VS_FF_PRERELEASE 2 18 | #define VS_FF_PATCHED 4 19 | #define VS_FF_PRIVATEBUILD 8 20 | #define VS_FF_INFOINFERRED 16 21 | #define VS_FF_SPECIALBUILD 32 22 | #define VOS_UNKNOWN 0 23 | #define VOS_DOS 0x10000 24 | #define VOS_OS216 0x20000 25 | #define VOS_OS232 0x30000 26 | #define VOS_NT 0x40000 27 | #define VOS__BASE 0 28 | #define VOS__WINDOWS16 1 29 | #define VOS__PM16 2 30 | #define VOS__PM32 3 31 | #define VOS__WINDOWS32 4 32 | #define VOS_DOS_WINDOWS16 0x10001 33 | #define VOS_DOS_WINDOWS32 0x10004 34 | #define VOS_OS216_PM16 0x20002 35 | #define VOS_OS232_PM32 0x30003 36 | #define VOS_NT_WINDOWS32 0x40004 37 | #define VFT_UNKNOWN 0 38 | #define VFT_APP 1 39 | #define VFT_DLL 2 40 | #define VFT_DRV 3 41 | #define VFT_FONT 4 42 | #define VFT_VXD 5 43 | #define VFT_STATIC_LIB 7 44 | #define VFT2_UNKNOWN 0 45 | #define VFT2_DRV_PRINTER 1 46 | #define VFT2_DRV_KEYBOARD 2 47 | #define VFT2_DRV_LANGUAGE 3 48 | #define VFT2_DRV_DISPLAY 4 49 | #define VFT2_DRV_MOUSE 5 50 | #define VFT2_DRV_NETWORK 6 51 | #define VFT2_DRV_SYSTEM 7 52 | #define VFT2_DRV_INSTALLABLE 8 53 | #define VFT2_DRV_SOUND 9 54 | #define VFT2_DRV_COMM 10 55 | #define VFT2_DRV_INPUTMETHOD 11 56 | #define VFT2_FONT_RASTER 1 57 | #define VFT2_FONT_VECTOR 2 58 | #define VFT2_FONT_TRUETYPE 3 59 | #define VFFF_ISSHAREDFILE 1 60 | #define VFF_CURNEDEST 1 61 | #define VFF_FILEINUSE 2 62 | #define VFF_BUFFTOOSMALL 4 63 | #define VIFF_FORCEINSTALL 1 64 | #define VIFF_DONTDELETEOLD 2 65 | #define VIF_TEMPFILE 1 66 | #define VIF_MISMATCH 2 67 | #define VIF_SRCOLD 4 68 | #define VIF_DIFFLANG 8 69 | #define VIF_DIFFCODEPG 16 70 | #define VIF_DIFFTYPE 32 71 | #define VIF_WRITEPROT 64 72 | #define VIF_FILEINUSE 128 73 | #define VIF_OUTOFSPACE 256 74 | #define VIF_ACCESSVIOLATION 512 75 | #define VIF_SHARINGVIOLATION 1024 76 | #define VIF_CANNOTCREATE 2048 77 | #define VIF_CANNOTDELETE 4096 78 | #define VIF_CANNOTRENAME 8192 79 | #define VIF_CANNOTDELETECUR 16384 80 | #define VIF_OUTOFMEMORY 32768 81 | #define VIF_CANNOTREADSRC 65536 82 | #define VIF_CANNOTREADDST 0x20000 83 | #define VIF_BUFFTOOSMALL 0x40000 84 | #ifndef RC_INVOKED 85 | typedef struct tagVS_FIXEDFILEINFO { 86 | DWORD dwSignature; 87 | DWORD dwStrucVersion; 88 | DWORD dwFileVersionMS; 89 | DWORD dwFileVersionLS; 90 | DWORD dwProductVersionMS; 91 | DWORD dwProductVersionLS; 92 | DWORD dwFileFlagsMask; 93 | DWORD dwFileFlags; 94 | DWORD dwFileOS; 95 | DWORD dwFileType; 96 | DWORD dwFileSubtype; 97 | DWORD dwFileDateMS; 98 | DWORD dwFileDateLS; 99 | } VS_FIXEDFILEINFO; 100 | DWORD WINAPI VerFindFileA(DWORD,LPSTR,LPSTR,LPSTR,LPSTR,PUINT,LPSTR,PUINT); 101 | DWORD WINAPI VerFindFileW(DWORD,LPWSTR,LPWSTR,LPWSTR,LPWSTR,PUINT,LPWSTR,PUINT); 102 | DWORD WINAPI VerInstallFileA(DWORD,LPSTR,LPSTR,LPSTR,LPSTR,LPSTR,LPSTR,PUINT); 103 | DWORD WINAPI VerInstallFileW(DWORD,LPWSTR,LPWSTR,LPWSTR,LPWSTR,LPWSTR,LPWSTR,PUINT); 104 | DWORD WINAPI GetFileVersionInfoSizeA(LPSTR,PDWORD); 105 | DWORD WINAPI GetFileVersionInfoSizeW(LPWSTR,PDWORD); 106 | BOOL WINAPI GetFileVersionInfoA(LPSTR,DWORD,DWORD,PVOID); 107 | BOOL WINAPI GetFileVersionInfoW(LPWSTR,DWORD,DWORD,PVOID); 108 | DWORD WINAPI VerLanguageNameA(DWORD,LPSTR,DWORD); 109 | DWORD WINAPI VerLanguageNameW(DWORD,LPWSTR,DWORD); 110 | BOOL WINAPI VerQueryValueA(PCVOID,LPSTR,PVOID*,PUINT); 111 | BOOL WINAPI VerQueryValueW(PCVOID,LPWSTR,PVOID*,PUINT); 112 | #ifdef UNICODE 113 | #define VerFindFile VerFindFileW 114 | #define VerQueryValue VerQueryValueW 115 | #define VerInstallFile VerInstallFileW 116 | #define GetFileVersionInfoSize GetFileVersionInfoSizeW 117 | #define GetFileVersionInfo GetFileVersionInfoW 118 | #define VerLanguageName VerLanguageNameW 119 | #define VerQueryValue VerQueryValueW 120 | #else 121 | #define VerQueryValue VerQueryValueA 122 | #define VerFindFile VerFindFileA 123 | #define VerInstallFile VerInstallFileA 124 | #define GetFileVersionInfoSize GetFileVersionInfoSizeA 125 | #define GetFileVersionInfo GetFileVersionInfoA 126 | #define VerLanguageName VerLanguageNameA 127 | #define VerQueryValue VerQueryValueA 128 | #endif 129 | #endif 130 | #ifdef __cplusplus 131 | } 132 | #endif 133 | #endif 134 | -------------------------------------------------------------------------------- /0.3/names.c: -------------------------------------------------------------------------------- 1 | /* names.c included source file defining instruction and register 2 | * names for the Netwide [Dis]Assembler 3 | * 4 | * The Netwide Assembler is copyright (C) 1996 Simon Tatham and 5 | * Julian Hall. All rights reserved. The software is 6 | * redistributable under the licence given in the file "Licence" 7 | * distributed in the NASM archive. 8 | */ 9 | 10 | static char *reg_names[] = { /* register names, as strings */ 11 | "ah", "al", "ax", "bh", "bl", "bp", "bx", "ch", "cl", 12 | "cr0", "cr2", "cr3", "cr4", "cs", "cx", "dh", "di", "dl", "dr0", 13 | "dr1", "dr2", "dr3", "dr6", "dr7", "ds", "dx", "eax", "ebp", 14 | "ebx", "ecx", "edi", "edx", "es", "esi", "esp", "fs", "gs", 15 | "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", "si", 16 | "sp", "ss", "st0", "st1", "st2", "st3", "st4", "st5", "st6", 17 | "st7", "tr3", "tr4", "tr5", "tr6", "tr7" 18 | }; 19 | 20 | static char *insn_names[] = { /* instruction names, as strings */ 21 | "aaa", "aad", "aam", "aas", "adc", "add", "and", "arpl", 22 | "bound", "bsf", "bsr", "bswap", "bt", "btc", "btr", "bts", 23 | "call", "cbw", "cdq", "clc", "cld", "cli", "clts", "cmc", "cmp", 24 | "cmpsb", "cmpsd", "cmpsw", "cmpxchg", "cmpxchg486", "cmpxchg8b", 25 | "cpuid", "cwd", "cwde", "daa", "das", "db", "dd", "dec", "div", 26 | "dq", "dt", "dw", "emms", "enter", "equ", "f2xm1", "fabs", 27 | "fadd", "faddp", "fbld", "fbstp", "fchs", "fclex", "fcmovb", 28 | "fcmovbe", "fcmove", "fcmovnb", "fcmovnbe", "fcmovne", 29 | "fcmovnu", "fcmovu", "fcom", "fcomi", "fcomip", "fcomp", 30 | "fcompp", "fcos", "fdecstp", "fdisi", "fdiv", "fdivp", "fdivr", 31 | "fdivrp", "feni", "ffree", "fiadd", "ficom", "ficomp", "fidiv", 32 | "fidivr", "fild", "fimul", "fincstp", "finit", "fist", "fistp", 33 | "fisub", "fisubr", "fld", "fld1", "fldcw", "fldenv", "fldl2e", 34 | "fldl2t", "fldlg2", "fldln2", "fldpi", "fldz", "fmul", "fmulp", 35 | "fnclex", "fndisi", "fneni", "fninit", "fnop", "fnsave", 36 | "fnstcw", "fnstenv", "fnstsw", "fpatan", "fprem", "fprem1", 37 | "fptan", "frndint", "frstor", "fsave", "fscale", "fsetpm", 38 | "fsin", "fsincos", "fsqrt", "fst", "fstcw", "fstenv", "fstp", 39 | "fstsw", "fsub", "fsubp", "fsubr", "fsubrp", "ftst", "fucom", 40 | "fucomi", "fucomip", "fucomp", "fucompp", "fxam", "fxch", 41 | "fxtract", "fyl2x", "fyl2xp1", "hlt", "ibts", "icebp", "idiv", 42 | "imul", "in", "inc", "incbin", "insb", "insd", "insw", "int", 43 | "int1", "int01", "int3", "into", "invd", "invlpg", "iret", 44 | "iretd", "iretw", "jcxz", "jecxz", "jmp", "lahf", "lar", "lds", 45 | "lea", "leave", "les", "lfs", "lgdt", "lgs", "lidt", "lldt", 46 | "lmsw", "loadall", "loadall286", "lodsb", "lodsd", "lodsw", 47 | "loop", "loope", "loopne", "loopnz", "loopz", "lsl", "lss", 48 | "ltr", "mov", "movd", "movq", "movsb", "movsd", "movsw", 49 | "movsx", "movzx", "mul", "neg", "nop", "not", "or", "out", 50 | "outsb", "outsd", "outsw", "packssdw", "packsswb", "packuswb", 51 | "paddb", "paddd", "paddsb", "paddsiw", "paddsw", "paddusb", 52 | "paddusw", "paddw", "pand", "pandn", "paveb", "pcmpeqb", 53 | "pcmpeqd", "pcmpeqw", "pcmpgtb", "pcmpgtd", "pcmpgtw", 54 | "pdistib", "pmachriw", "pmaddwd", "pmagw", "pmulhrw", 55 | "pmulhriw", "pmulhw", "pmullw", "pmvgezb", "pmvlzb", "pmvnzb", 56 | "pmvzb", "pop", "popa", "popad", "popaw", "popf", "popfd", 57 | "popfw", "por", "pslld", "psllq", "psllw", "psrad", "psraw", 58 | "psrld", "psrlq", "psrlw", "psubb", "psubd", "psubsb", 59 | "psubsiw", "psubsw", "psubusb", "psubusw", "psubw", "punpckhbw", 60 | "punpckhdq", "punpckhwd", "punpcklbw", "punpckldq", "punpcklwd", 61 | "push", "pusha", "pushad", "pushaw", "pushf", "pushfd", 62 | "pushfw", "pxor", "rcl", "rcr", "rdmsr", "rdpmc", "rdtsc", 63 | "resb", "resd", "resq", "rest", "resw", "ret", "retf", "retn", 64 | "rol", "ror", "rsm", "sahf", "sal", "salc", "sar", "sbb", 65 | "scasb", "scasd", "scasw", "sgdt", "shl", "shld", "shr", "shrd", 66 | "sidt", "sldt", "smi", "smsw", "stc", "std", "sti", "stosb", 67 | "stosd", "stosw", "str", "sub", "test", "umov", "verr", "verw", 68 | "wait", "wbinvd", "wrmsr", "xadd", "xbts", "xchg", "xlatb", 69 | "xor" 70 | }; 71 | 72 | static char *icn[] = { /* conditional instructions */ 73 | "cmov", "j", "set" 74 | }; 75 | 76 | static int ico[] = { /* and the corresponding opcodes */ 77 | I_CMOVcc, I_Jcc, I_SETcc 78 | }; 79 | 80 | static char *conditions[] = { /* condition code names */ 81 | "a", "ae", "b", "be", "c", "e", "g", "ge", "l", "le", "na", "nae", 82 | "nb", "nbe", "nc", "ne", "ng", "nge", "nl", "nle", "no", "np", 83 | "ns", "nz", "o", "p", "pe", "po", "s", "z" 84 | }; 85 | -------------------------------------------------------------------------------- /0.3/foo_vxd.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="foo_vxd" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) External Target" 0x0106 6 | 7 | CFG=foo_vxd - Win32 Release 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "foo_vxd.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "foo_vxd.mak" CFG="foo_vxd - Win32 Release" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "foo_vxd - Win32 Release" (based on "Win32 (x86) External Target") 21 | !MESSAGE "foo_vxd - Win32 Debug" (based on "Win32 (x86) External Target") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | 29 | !IF "$(CFG)" == "foo_vxd - Win32 Release" 30 | 31 | # PROP BASE Use_Debug_Libraries 0 32 | # PROP BASE Output_Dir "Release" 33 | # PROP BASE Intermediate_Dir "Release" 34 | # PROP BASE Cmd_Line "NMAKE /nologo CFG="Release"" 35 | # PROP BASE Rebuild_Opt "/a" 36 | # PROP BASE Target_File "Release\foo_vxd.VxD" 37 | # PROP BASE Bsc_Name "Release\foo_vxd.bsc" 38 | # PROP BASE Target_Dir "" 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Cmd_Line "NMAKE /nologo CFG="Release"" 43 | # PROP Rebuild_Opt "/a" 44 | # PROP Target_File "Release\foo_vxd.VxD" 45 | # PROP Bsc_Name "Release\foo_vxd.bsc" 46 | # PROP Target_Dir "" 47 | 48 | !ELSEIF "$(CFG)" == "foo_vxd - Win32 Debug" 49 | 50 | # PROP BASE Use_Debug_Libraries 1 51 | # PROP BASE Output_Dir "Debug" 52 | # PROP BASE Intermediate_Dir "Debug" 53 | # PROP BASE Cmd_Line "NMAKE /nologo /k" 54 | # PROP BASE Rebuild_Opt "/a" 55 | # PROP BASE Target_File "Debug\foo_vxd.vxd" 56 | # PROP BASE Bsc_Name "Debug\foo_vxd.bsc" 57 | # PROP BASE Target_Dir "" 58 | # PROP Use_Debug_Libraries 1 59 | # PROP Output_Dir "Debug" 60 | # PROP Intermediate_Dir "Debug" 61 | # PROP Cmd_Line "NMAKE /nologo /k CFG="Debug"" 62 | # PROP Rebuild_Opt "/a" 63 | # PROP Target_File "Debug\foo_vxd.VxD" 64 | # PROP Bsc_Name "Debug\foo_vxd.bsc" 65 | # PROP Target_Dir "" 66 | 67 | !ENDIF 68 | 69 | # Begin Target 70 | 71 | # Name "foo_vxd - Win32 Release" 72 | # Name "foo_vxd - Win32 Debug" 73 | 74 | !IF "$(CFG)" == "foo_vxd - Win32 Release" 75 | 76 | !ELSEIF "$(CFG)" == "foo_vxd - Win32 Debug" 77 | 78 | !ENDIF 79 | 80 | # Begin Group "Header Files" 81 | 82 | # PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd" 83 | # Begin Source File 84 | 85 | SOURCE=.\breakpoint.h 86 | # End Source File 87 | # Begin Source File 88 | 89 | SOURCE=.\buffering.h 90 | # End Source File 91 | # Begin Source File 92 | 93 | SOURCE=.\command.h 94 | # End Source File 95 | # Begin Source File 96 | 97 | SOURCE=.\config.h 98 | # End Source File 99 | # Begin Source File 100 | 101 | SOURCE=.\disasm.h 102 | # End Source File 103 | # Begin Source File 104 | 105 | SOURCE=.\font_256.h 106 | # End Source File 107 | # Begin Source File 108 | 109 | SOURCE=.\foo_vxd.h 110 | # End Source File 111 | # Begin Source File 112 | 113 | SOURCE=.\idt.h 114 | # End Source File 115 | # Begin Source File 116 | 117 | SOURCE=.\keyboard.h 118 | # End Source File 119 | # Begin Source File 120 | 121 | SOURCE=.\page.h 122 | # End Source File 123 | # Begin Source File 124 | 125 | SOURCE=.\var_globale.h 126 | # End Source File 127 | # Begin Source File 128 | 129 | SOURCE=.\video.h 130 | # End Source File 131 | # End Group 132 | # Begin Group "Resource Files" 133 | 134 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" 135 | # Begin Source File 136 | 137 | SOURCE=.\foo_vxd.rc 138 | # End Source File 139 | # End Group 140 | # Begin Group "Source Files" 141 | 142 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90" 143 | # Begin Source File 144 | 145 | SOURCE=.\breakpoint.c 146 | # End Source File 147 | # Begin Source File 148 | 149 | SOURCE=.\buffering.c 150 | # End Source File 151 | # Begin Source File 152 | 153 | SOURCE=.\command.c 154 | # End Source File 155 | # Begin Source File 156 | 157 | SOURCE=.\disasmbak.c 158 | # End Source File 159 | # Begin Source File 160 | 161 | SOURCE=.\idt.c 162 | # End Source File 163 | # Begin Source File 164 | 165 | SOURCE=.\keyboard.c 166 | # End Source File 167 | # Begin Source File 168 | 169 | SOURCE=.\page.c 170 | # End Source File 171 | # Begin Source File 172 | 173 | SOURCE=.\Spy.c 174 | # End Source File 175 | # Begin Source File 176 | 177 | SOURCE=.\SpyAsm.asm 178 | # End Source File 179 | # Begin Source File 180 | 181 | SOURCE=.\video.c 182 | # End Source File 183 | # End Group 184 | # Begin Source File 185 | 186 | SOURCE=.\makefile 187 | # End Source File 188 | # End Target 189 | # End Project 190 | -------------------------------------------------------------------------------- /0.3/video.h: -------------------------------------------------------------------------------- 1 | #ifndef VIDEO_H 2 | #define VIDEO_H 3 | 4 | #define dump_screen_size (80*25*2) 5 | 6 | extern char *table[]; 7 | extern char screen_line0[]; 8 | extern char screen_line1[]; 9 | extern char screen_line2[]; 10 | extern char screen_line3[]; 11 | extern char screen_line4[]; 12 | extern char screen_line5[]; 13 | extern char screen_line6[]; 14 | extern char screen_line7[]; 15 | extern char screen_line8[]; 16 | extern char screen_line9[]; 17 | 18 | extern char screen_line10[]; 19 | extern char screen_line11[]; 20 | extern char screen_line12[]; 21 | extern char screen_line13[]; 22 | extern char screen_line14[]; 23 | extern char screen_line15[]; 24 | extern char screen_line16[]; 25 | extern char screen_line17[]; 26 | extern char screen_line18[]; 27 | extern char screen_line19[]; 28 | 29 | extern char screen_line20[]; 30 | extern char screen_line21[]; 31 | extern char screen_line22[]; 32 | extern char screen_line23[]; 33 | extern char screen_line24[]; 34 | extern char screen_line25[]; 35 | extern char screen_line26[]; 36 | extern char screen_line27[]; 37 | extern char screen_line28[]; 38 | extern char screen_line29[]; 39 | 40 | extern char screen_line30[]; 41 | extern char screen_line31[]; 42 | extern char screen_line32[]; 43 | extern char screen_line33[]; 44 | extern char screen_line34[]; 45 | extern char screen_line35[]; 46 | extern char screen_line36[]; 47 | extern char screen_line37[]; 48 | extern char screen_line38[]; 49 | extern char screen_line39[]; 50 | 51 | extern char *table_color[]; 52 | 53 | extern unsigned int data_win_y; 54 | extern unsigned int data_win_dim; 55 | 56 | extern unsigned int code_win_y; 57 | extern unsigned int code_win_dim; 58 | 59 | extern unsigned int buff_win_y; 60 | extern unsigned int buff_win_dim; 61 | 62 | extern unsigned int cmd_win_y; 63 | extern unsigned int cmd_win_dim; 64 | 65 | extern unsigned int screen_offset_x; 66 | extern unsigned int screen_offset_y; 67 | 68 | extern unsigned int screen_bpp; 69 | 70 | extern unsigned int code_dim_line[10]; 71 | 72 | #define SCREEN_LINE 40 73 | 74 | typedef struct tagBITMAPFILEHEADER { /* bmfh */ 75 | unsigned int bfSize; 76 | short bfReserved1; 77 | short bfReserved2; 78 | unsigned int bfOffBits; 79 | } BITMAPFILEHEADER; 80 | 81 | 82 | typedef struct tagBITMAPINFOHEADER{ /* bmih */ 83 | unsigned int biSize; 84 | unsigned int biWidth; 85 | unsigned int biHeight; 86 | short int biPlanes; 87 | short int biBitCount ; 88 | int biCompression; 89 | int biSizeImage; 90 | unsigned int biXPelsPerMeter; 91 | unsigned int biYPelsPerMeter; 92 | int biClrUsed; 93 | int biClrImportant; 94 | } BITMAPINFOHEADER; 95 | 96 | #define BITMAP_ID 0x4d42 97 | 98 | extern unsigned int font_width; 99 | extern unsigned int font_height; 100 | 101 | extern unsigned int font_x; 102 | extern unsigned int font_y; 103 | extern unsigned int font_bpp; 104 | 105 | extern unsigned int screen_adresse ; 106 | 107 | extern unsigned char font_data[]; 108 | 109 | int test(void); 110 | void prepare_screen(void); 111 | 112 | 113 | int LoadBMP(char* , unsigned int* , unsigned int* , unsigned int *, unsigned char *); 114 | 115 | void my_outb(unsigned short port, unsigned char value); 116 | void read_mem_base(void); 117 | void restore_mem_base(void) ; 118 | void reset_mem_to_0(void); 119 | 120 | void put_XY_char(int x, int y, unsigned char a); 121 | 122 | void print_char(unsigned char , unsigned int , unsigned int ); 123 | void Put_String(char* , unsigned int , unsigned int ); 124 | void PutString(unsigned long ,unsigned long ,char *,char ); 125 | 126 | void dump_screen(void); 127 | void restore_screen(int); 128 | 129 | 130 | 131 | void displaymessage(char *); 132 | 133 | void WriteVCon(unsigned int ,unsigned ,char *); 134 | 135 | void delline(int ); 136 | 137 | void ClearAW(void); 138 | void ClearDW(void); 139 | void ClearCW(void); 140 | void cls(void); 141 | 142 | 143 | void DisplayText(int ,int ,char *); 144 | 145 | void Refresh_AW(void); 146 | void Refresh_DW(void); 147 | void Refresh_CW(void); 148 | void Refresh_ALL(void); 149 | void cursor_top_right(void); 150 | void Refresh_Display(void); 151 | 152 | #ifdef VIDEO_AA 153 | void Start_Display(void); 154 | void End_Display(void); 155 | #endif /* VIDEO_AA */ 156 | 157 | void InsertCommandKey(char ); 158 | void ClearCommand(void); 159 | 160 | void DeleteCommandKey(void); 161 | 162 | void deblin_change_color(char *,char *); 163 | void deblin_console_off(void); 164 | void deblin_console_on(void); 165 | void test_scr(void); 166 | 167 | void print_AW(char* ptr, int ligne); 168 | void print_DW(char* ptr, int ligne); 169 | void print_CW(char* ptr, int ligne); 170 | 171 | void update_cursor(unsigned int x, unsigned int y); 172 | void erase_cursor(void); 173 | 174 | extern unsigned int cursor_X; 175 | extern unsigned int cursor_Y; 176 | extern unsigned int cursor_old_color; 177 | extern unsigned int cursor_color; 178 | 179 | 180 | 181 | #endif /* VIDEO_H */ 182 | -------------------------------------------------------------------------------- /0.3/buffering.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Rasta Ring 0 debug 3 | * 4 | * Copyright (C) 2004 Droids Corporation. 5 | * based on Deblin debuger 6 | * 7 | * $Id: buffering.c,v 1.22 2006-06-29 08:37:30 serpilliere Exp $ 8 | * 9 | */ 10 | 11 | #include "vars.h" 12 | #include "buffering.h" 13 | #include "utils.h" 14 | #include "video.h" 15 | 16 | #define BUFFERMAXLINES 80 17 | 18 | 19 | 20 | int infobuffer; /* =DESACTIVADO; */ 21 | int bufferindex=0; 22 | int insertbufferindex=0; 23 | 24 | char buff_cmd[BUFFERMAXCMD][80]; 25 | int insertcmdindex; 26 | int cmdindex; 27 | 28 | 29 | char buffering[BUFFERMAXLINES][80]; /* 200 lines and 80 chars */ 30 | 31 | 32 | /*nettoie le buffer de log */ 33 | /* */ 34 | /* */ 35 | void cleaningbuffer(void) 36 | { 37 | int x,y=0; 38 | char *ptr; 39 | for (x=0;x50?50:len; 72 | 73 | for (i=0;i=BUFFERMAXLINES) 89 | { 90 | for (i=0;i0) bufferindex--; 141 | 142 | } 143 | 144 | /*descend de 10 ligne dans le buffer de log */ 145 | /* */ 146 | /* */ 147 | void bufferbigdown(void) 148 | { 149 | int i; 150 | for (i=0;i<10;i++) 151 | bufferdown(); 152 | } 153 | 154 | /*remonte de 10 ligne dans le buffer de log */ 155 | /* */ 156 | /* */ 157 | void bufferbigup(void) 158 | { 159 | int i; 160 | for (i=0;i<10;i++) 161 | bufferup(); 162 | } 163 | 164 | 165 | void startbuffer(void) 166 | { 167 | ClearAW(); 168 | cleaningbuffer(); 169 | 170 | bufferindex=0; 171 | insertbufferindex=0; 172 | } 173 | 174 | void endbuffer(void) 175 | { 176 | 177 | } 178 | 179 | void restorebuffer(void) 180 | { 181 | 182 | } 183 | 184 | 185 | /*insere une ligne dans la file du buffer de log */ 186 | /* */ 187 | /* */ 188 | void log_line_in_buffer(char *ptr) 189 | { 190 | insertinbuffer(ptr); 191 | displaybuffer(); 192 | Refresh_Display(); 193 | } 194 | 195 | 196 | -------------------------------------------------------------------------------- /0.3/vars.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Rasta Ring 0 debug 3 | * 4 | * Copyright (C) 2004 Droids Corporation. 5 | * 6 | * $Id: vars.h,v 1.30 2006-07-11 07:09:30 serpilliere Exp $ 7 | * 8 | */ 9 | 10 | #ifndef VARS_H 11 | #define VARS_H 12 | 13 | #include "config.h" 14 | 15 | #ifndef NULL 16 | #define NULL 0 17 | #endif 18 | 19 | 20 | 21 | /* We check whether an ASM style has been chosen */ 22 | #if defined(_MSC_VER) && defined(__GNUC__) 23 | #error Your config.h is wrong : you cannot use MSC_VER *and* GNUC 24 | #endif /* both MSC_VER and GNUC */ 25 | #if ! defined(_MSC_VER) && ! defined(__GNUC__) 26 | #error Your config.h is wrong : you must choose either MSC_VER or GNUC 27 | #endif /* neither MSC_VER nor GNUC */ 28 | 29 | /* 30 | * We check wether a video mode has been chosen. If VIDEO_FB has been 31 | * chosen, a value for SCREEN_ADRESSE needs to be set. 32 | */ 33 | #if defined VIDEO_FB && defined VIDEO_AA 34 | #error Your config.h is wrong : you cannot use VIDEO_FB *and* VIDEO_AA 35 | #endif /* both VIDEO_FB and VIDEO_AA */ 36 | #if ! defined VIDEO_FB && ! defined VIDEO_AA 37 | #error Your config.h is wrong : you must choose either VIDEO_FB or VIDEO_AA 38 | #endif /* neither VIDEO_FB nor VIDEO_AA */ 39 | #if defined VIDEO_FB && ! defined SCREEN_ADRESSE 40 | #error Your config.h is wrong : if you want to use VIDEO_FB, you must define SCREEN_ADRESSE 41 | #endif /* VIDEO_FB without SCREEN_ADRESSE */ 42 | 43 | /* We check that an OS has been chosen */ 44 | 45 | #if defined LINUX_26 && ! defined LINUX 46 | #define LINUX 47 | #warning I set LINUX macro because you have set LINUX_26 48 | #endif /* LINUX_26 without LINUX */ 49 | 50 | #if defined FREEBSD || defined OPENBSD || defined NETBSD 51 | #define XBSD 52 | #endif 53 | 54 | #if ! defined LINUX && ! defined XBSD && ! defined WIN32 55 | #error Set your OS in config.h ! (and RTFM) 56 | #endif /* no OS set */ 57 | 58 | #if (defined LINUX && (defined XBSD || defined WIN32)) || (defined XBSD && defined WIN32) 59 | #error You must chose only *one* OS in config.h 60 | #endif 61 | 62 | #if (defined FREEBSD && (defined OPENBSD || defined NETBSD)) || (defined OPENBSD && defined NETBSD) 63 | #error You must chose only *one* OS in config.h 64 | #endif 65 | 66 | #if defined(__GNUC__) 67 | #define _asm_ __asm__ __volatile__ 68 | #endif /* GNUC */ 69 | 70 | #ifdef LINUX 71 | 72 | #define KERNEL_B 0xC0000000 73 | 74 | #ifndef __KERNEL__ 75 | #define __KERNEL__ 76 | #endif /* __KERNEL__ */ 77 | 78 | #ifndef MODULE 79 | #define MODULE 80 | #endif /* MODULE */ 81 | 82 | #include 83 | #include 84 | #include 85 | 86 | #define Out_Debug_String(a) printk(a) 87 | #define __declspec_naked __attribute__((cdecl)) 88 | 89 | #ifdef LINUX_26 90 | 91 | #define fake_naked 92 | 93 | #if defined(__GNUC__) 94 | #define RING_HOOO_SEGMENT "$0x7b" 95 | //#define RING_HOOO_SEGMENT "$0x60" 96 | #elif defined(_MSC_VER) 97 | #define RING_HOOO_SEGMENT 0x7b 98 | #endif 99 | 100 | #define RING_HOOO_SEGMENT_VALUE 0x7b 101 | //#define RING_HOOO_SEGMENT_VALUE 0x60 102 | 103 | #else /* LINUX_24 */ 104 | 105 | #define fake_naked _asm_("\t" \ 106 | "add $0x08, %esp\n\t" \ 107 | "popl %ebp\n" \ 108 | ); 109 | 110 | #if defined(__GNUC__) 111 | #define RING_HOOO_SEGMENT "$0x18" 112 | #elif defined(_MSC_VER) 113 | #define RING_HOOO_SEGMENT 0x18 114 | #endif 115 | 116 | #define RING_HOOO_SEGMENT_VALUE 0x18 117 | 118 | #endif /* LINUX_26 */ 119 | 120 | #endif /* LINUX */ 121 | 122 | #ifdef XBSD /* Generic stuffs for *BSD */ 123 | 124 | #if defined(__GNUC__) 125 | #define RING_HOOO_SEGMENT "$0x10" 126 | #elif defined(_MSC_VER) 127 | #define RING_HOOO_SEGMENT 0x10 128 | #endif 129 | 130 | #define RING_HOOO_SEGMENT_VALUE 0x10 131 | 132 | #include 133 | #include 134 | 135 | #ifdef FREEBSD 136 | #include 137 | #include 138 | 139 | #define KERNEL_B 0xC0000000 140 | #endif /* FREEBSD */ 141 | 142 | #ifdef OPENBSD 143 | #include 144 | #include 145 | #include 146 | #include 147 | 148 | #define KERNEL_B 0xD0000000 149 | #endif /* OPENBSD */ 150 | 151 | #ifdef NETBSD 152 | #include 153 | #include 154 | #include 155 | #include 156 | 157 | #define KERNEL_B 0xC0000000 158 | #endif /* NETBSD */ 159 | 160 | #define __declspec_naked __attribute__((cdecl)) 161 | #define fake_naked _asm_("\t" \ 162 | "popl %ebp\n" \ 163 | ); 164 | #define Out_Debug_String(a) printf(a) 165 | #endif /* XBSD */ 166 | 167 | #ifdef WIN32 168 | #define KERNEL_B 0xC2690000 169 | 170 | //#include 171 | 172 | extern unsigned int DbgPrint(char* Format,...); 173 | #define Out_Debug_String(_X_) \ 174 | DbgPrint("CANCEL.SYS: ");\ 175 | DbgPrint(_X_); 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | #if defined(__GNUC__) 184 | #define RING_HOOO_SEGMENT "$0x30" 185 | #elif defined(_MSC_VER) 186 | #define RING_HOOO_SEGMENT 0x30 187 | #endif 188 | 189 | 190 | #define RING_HOOO_SEGMENT_VALUE 0x30 191 | /* 192 | #include 193 | #include 194 | extern void Out_Debug_String(char* psz); 195 | */ 196 | #define fake_naked 197 | #define __declspec_naked __declspec(naked) 198 | 199 | #endif /* WIN32 */ 200 | 201 | 202 | #define MAX_INT 255 203 | 204 | #endif /* VARS_H */ 205 | -------------------------------------------------------------------------------- /0.3/module_win.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define TRIVIAL_DEVICE_NAME_U L"\\Device\\CANCELSAMP" 4 | #define TRIVIAL_DOS_DEVICE_NAME_U L"\\DosDevices\\CancelSamp" 5 | 6 | 7 | #define CSAMP_KDPRINT(_x_) \ 8 | DbgPrint("CANCEL.SYS: ");\ 9 | DbgPrint _x_; 10 | 11 | typedef struct _DEVICE_EXTENSION{ 12 | 13 | BOOLEAN Spare; 14 | 15 | } DEVICE_EXTENSION, *PDEVICE_EXTENSION; 16 | 17 | NTSTATUS 18 | DriverEntry( 19 | IN PDRIVER_OBJECT DriverObject, 20 | IN PUNICODE_STRING registryPath 21 | ); 22 | 23 | NTSTATUS 24 | TrivialCreateClose ( 25 | IN PDEVICE_OBJECT DeviceObject, 26 | IN PIRP Irp 27 | ); 28 | 29 | VOID 30 | TrivialUnload( 31 | IN PDRIVER_OBJECT DriverObject 32 | ); 33 | 34 | NTSTATUS 35 | TrivialCleanup( 36 | IN PDEVICE_OBJECT DeviceObject, 37 | IN PIRP Irp 38 | ); 39 | 40 | 41 | #ifdef ALLOC_PRAGMA 42 | #pragma alloc_text( INIT, DriverEntry ) 43 | #pragma alloc_text( PAGE, TrivialCreateClose) 44 | #pragma alloc_text( PAGE, TrivialUnload) 45 | #endif // ALLOC_PRAGMA 46 | 47 | 48 | extern int init_rr0d(void); 49 | extern void cleanup_rr0d(void); 50 | 51 | NTSTATUS 52 | DriverEntry( 53 | IN PDRIVER_OBJECT DriverObject, 54 | IN PUNICODE_STRING RegistryPath 55 | ) 56 | { 57 | NTSTATUS status = STATUS_SUCCESS; 58 | UNICODE_STRING unicodeDeviceName; 59 | UNICODE_STRING unicodeDosDeviceName; 60 | PDEVICE_OBJECT deviceObject; 61 | PDEVICE_EXTENSION devExtension; 62 | HANDLE threadHandle; 63 | 64 | UNREFERENCED_PARAMETER (RegistryPath); 65 | 66 | CSAMP_KDPRINT(("--DriverEntry Enter \n")); 67 | 68 | // 69 | // Initialize UNICODE_STRING structures with NT and DOS device names 70 | // 71 | (void) RtlInitUnicodeString( &unicodeDeviceName, TRIVIAL_DEVICE_NAME_U); 72 | (void) RtlInitUnicodeString( &unicodeDosDeviceName, TRIVIAL_DOS_DEVICE_NAME_U ); 73 | 74 | 75 | 76 | // 77 | // Create DOS device 78 | // 79 | status = IoCreateDevice( 80 | DriverObject, 81 | sizeof(DEVICE_EXTENSION), 82 | &unicodeDeviceName, 83 | FILE_DEVICE_UNKNOWN, 84 | 0, 85 | (BOOLEAN) FALSE, 86 | &deviceObject 87 | ); 88 | 89 | if (!NT_SUCCESS(status)) 90 | { 91 | return status; 92 | } 93 | 94 | // 95 | // Create the DOS name for the device 96 | // 97 | status = IoCreateSymbolicLink( 98 | (PUNICODE_STRING) &unicodeDosDeviceName, 99 | (PUNICODE_STRING) &unicodeDeviceName 100 | ); 101 | 102 | if (!NT_SUCCESS(status)) 103 | { 104 | IoDeleteDevice(deviceObject); 105 | return status; 106 | } 107 | 108 | // Nothing in our device extension 109 | //devExtension = deviceObject->DeviceExtension; 110 | 111 | // 112 | // Initialize our IRP handling and unload functions 113 | // 114 | DriverObject->MajorFunction[IRP_MJ_CREATE] = TrivialCreateClose; 115 | DriverObject->MajorFunction[IRP_MJ_CLOSE] = TrivialCreateClose; 116 | DriverObject->MajorFunction[IRP_MJ_CLEANUP] = TrivialCleanup; 117 | 118 | DriverObject->DriverUnload = TrivialUnload; 119 | 120 | 121 | init_rr0d(); 122 | 123 | // Nothing to set in our flags, since we don't do any actual I/O 124 | //deviceObject->Flags |= DO_BUFFERED_IO; 125 | 126 | return status; 127 | } 128 | 129 | 130 | 131 | NTSTATUS 132 | TrivialCreateClose( 133 | IN PDEVICE_OBJECT DeviceObject, 134 | IN PIRP Irp 135 | ) 136 | { 137 | PIO_STACK_LOCATION irpStack; 138 | NTSTATUS status = STATUS_SUCCESS; 139 | 140 | PAGED_CODE (); 141 | 142 | // 143 | // Get a pointer to the current location in the Irp. 144 | // 145 | CSAMP_KDPRINT(("TrivialCreateClose \n")); 146 | 147 | irpStack = IoGetCurrentIrpStackLocation(Irp); 148 | 149 | switch(irpStack->MajorFunction) 150 | { 151 | case IRP_MJ_CREATE: 152 | Irp->IoStatus.Information = 0; 153 | break; 154 | 155 | case IRP_MJ_CLOSE: 156 | Irp->IoStatus.Information = 0; 157 | break; 158 | 159 | default: 160 | status = STATUS_INVALID_PARAMETER; 161 | break; 162 | } 163 | 164 | // 165 | // Save Status for return and complete Irp 166 | // 167 | Irp->IoStatus.Status = status; 168 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 169 | 170 | return status; 171 | } 172 | 173 | NTSTATUS 174 | TrivialCleanup( 175 | IN PDEVICE_OBJECT DeviceObject, 176 | IN PIRP Irp 177 | ) 178 | { 179 | 180 | PDEVICE_EXTENSION devExtension; 181 | LIST_ENTRY tempQueue; 182 | PLIST_ENTRY thisEntry; 183 | PIRP pendingIrp; 184 | PIO_STACK_LOCATION pendingIrpStack, irpStack; 185 | 186 | 187 | CSAMP_KDPRINT(("TrivialCleanup \n")); 188 | 189 | //devExtension = DeviceObject->DeviceExtension; 190 | //irpStack = IoGetCurrentIrpStackLocation(Irp); 191 | 192 | // 193 | // Finally complete the cleanup IRP 194 | // 195 | Irp->IoStatus.Information = 0; 196 | Irp->IoStatus.Status = STATUS_SUCCESS; 197 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 198 | 199 | return STATUS_SUCCESS; 200 | } 201 | 202 | VOID 203 | TrivialUnload( 204 | IN PDRIVER_OBJECT DriverObject 205 | ) 206 | { 207 | PDEVICE_OBJECT deviceObject = DriverObject->DeviceObject; 208 | UNICODE_STRING uniWin32NameString; 209 | PDEVICE_EXTENSION devExtension = deviceObject->DeviceExtension; 210 | 211 | PAGED_CODE(); 212 | 213 | CSAMP_KDPRINT(("TrivialUnload \n")); 214 | 215 | 216 | cleanup_rr0d(); 217 | 218 | // 219 | // Delete our DOS link and then our device 220 | // 221 | RtlInitUnicodeString( &uniWin32NameString, TRIVIAL_DOS_DEVICE_NAME_U ); 222 | IoDeleteSymbolicLink( &uniWin32NameString ); 223 | 224 | IoDeleteDevice( deviceObject ); 225 | 226 | return; 227 | } 228 | 229 | 230 | -------------------------------------------------------------------------------- /0.3/pci.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Rasta Ring 0 debug 3 | * 4 | * Copyright (C) 2004 Droids Corporation. 5 | * 6 | * 7 | * $Id: pci.c,v 1.2 2006-07-12 14:11:31 serpilliere Exp $ 8 | * 9 | */ 10 | 11 | 12 | #include "vars.h" 13 | #include "pci.h" 14 | 15 | #include "utils.h" 16 | 17 | 18 | #include "pci_data.h" 19 | 20 | /* 21 | #define rr0d_outb outb 22 | #define rr0d_outw outw 23 | #define rr0d_outl outl 24 | 25 | #define rr0d_inb inb 26 | #define rr0d_inw inw 27 | #define rr0d_inl inl 28 | */ 29 | 30 | /*******************************/ 31 | #define PCI_CONF_TYPE_NONE 0 32 | #define PCI_CONF_TYPE_1 1 33 | #define PCI_CONF_TYPE_2 2 34 | 35 | static unsigned char pci_conf_type = PCI_CONF_TYPE_1;//PCI_CONF_TYPE_NONE; 36 | 37 | 38 | #define PCI_CONF1_ADDRESS(bus, dev, fn, reg) \ 39 | (0x80000000 | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3)) 40 | 41 | #define PCI_CONF2_ADDRESS(dev, reg) (unsigned short)(0xC000 | (dev << 8) | reg) 42 | 43 | int pci_conf_read(unsigned bus, unsigned dev, unsigned fn, unsigned reg, unsigned len, unsigned int *value) 44 | { 45 | int result; 46 | 47 | if (!value || (bus > 255) || (dev > 31) || (fn > 7) || (reg > 255)) 48 | return -1; 49 | 50 | result = -1; 51 | switch(pci_conf_type) { 52 | case PCI_CONF_TYPE_1: 53 | rr0d_outl(PCI_CONF1_ADDRESS(bus, dev, fn, reg), 0xCF8); 54 | switch(len) { 55 | case 1: *value = rr0d_inb(0xCFC + (reg & 3)); result = 0; break; 56 | case 2: *value = rr0d_inw(0xCFC + (reg & 2)); result = 0; break; 57 | case 4: *value = rr0d_inl(0xCFC); result = 0; break; 58 | } 59 | break; 60 | case PCI_CONF_TYPE_2: 61 | rr0d_outb(0xF0 | (fn << 1), 0xCF8); 62 | rr0d_outb((unsigned char)bus, 0xCFA); 63 | 64 | switch(len) { 65 | case 1: *value = rr0d_inb(PCI_CONF2_ADDRESS(dev, reg)); result = 0; break; 66 | case 2: *value = rr0d_inw(PCI_CONF2_ADDRESS(dev, reg)); result = 0; break; 67 | case 4: *value = rr0d_inl(PCI_CONF2_ADDRESS(dev, reg)); result = 0; break; 68 | } 69 | rr0d_outb(0, 0xCF8); 70 | break; 71 | } 72 | return result; 73 | } 74 | 75 | int pci_conf_write(unsigned bus, unsigned dev, unsigned fn, unsigned reg, unsigned len, unsigned int value) 76 | { 77 | int result; 78 | 79 | if ((bus > 255) || (dev > 31) || (fn > 7) || (reg > 255)) 80 | return -1; 81 | 82 | result = -1; 83 | switch(pci_conf_type) { 84 | case PCI_CONF_TYPE_1: 85 | rr0d_outl(PCI_CONF1_ADDRESS(bus, dev, fn, reg), 0xCF8); 86 | switch(len) { 87 | case 1: rr0d_outb((unsigned char)value, 0xCFC + (reg & 3)); result = 0; break; 88 | case 2: rr0d_outw((unsigned short)value, 0xCFC + (reg & 2)); result = 0; break; 89 | case 4: rr0d_outl(value, 0xCFC); result = 0; break; 90 | } 91 | break; 92 | case PCI_CONF_TYPE_2: 93 | rr0d_outb(0xF0 | (fn << 1), 0xCF8); 94 | rr0d_outb((unsigned char)bus, 0xCFA); 95 | 96 | switch(len) { 97 | case 1: rr0d_outb((unsigned char)value, PCI_CONF2_ADDRESS(dev, reg)); result = 0; break; 98 | case 2: rr0d_outw((unsigned short)value, PCI_CONF2_ADDRESS(dev, reg)); result = 0; break; 99 | case 4: rr0d_outl(value, PCI_CONF2_ADDRESS(dev, reg)); result = 0; break; 100 | } 101 | rr0d_outb(0, 0xCF8); 102 | break; 103 | } 104 | return result; 105 | } 106 | 107 | 108 | 109 | 110 | unsigned int pci_get_name(unsigned int v, unsigned int d, unsigned char *out_char) 111 | { 112 | unsigned int i, ii; 113 | pci_desc* vendor; 114 | pci_desc* device; 115 | unsigned int precision = 0; 116 | 117 | 118 | 119 | for(i=0;i< sizeof(tab_vendor)/sizeof(pci_desc);i++) 120 | { 121 | vendor=&tab_vendor[i]; 122 | if (vendor->id != v) 123 | continue; 124 | 125 | //printf("%s\n", vendor->name); 126 | strcpy(out_char, vendor->name); 127 | strcat(out_char, " "); 128 | precision=1; 129 | if (vendor->list == NULL) 130 | continue; 131 | 132 | for(ii=0;;ii++) 133 | { 134 | device = &(vendor->list[ii]); 135 | if (device->id == 0) 136 | break; 137 | 138 | 139 | if (device->id == d) 140 | //printf("%s\n", device->name); 141 | strcat(out_char, device->name); 142 | } 143 | 144 | 145 | precision=2; 146 | return precision; 147 | } 148 | 149 | 150 | return precision; 151 | } 152 | 153 | void list_controller(void) 154 | { 155 | 156 | 157 | int i; 158 | unsigned int ctrl_bus; 159 | unsigned int ctrl_dev; 160 | unsigned int ctrl_fn; 161 | 162 | int result; 163 | unsigned int tmp; 164 | unsigned int vendor; 165 | unsigned int device; 166 | unsigned char pci_data[0x40]; 167 | unsigned char debug[256]; 168 | 169 | 170 | for (ctrl_bus = 0;ctrl_bus<255;ctrl_bus++) 171 | for (ctrl_dev = 0;ctrl_dev<31;ctrl_dev++) 172 | for (ctrl_fn = 0;ctrl_fn<7;ctrl_fn++) 173 | { 174 | result = pci_conf_read(ctrl_bus, ctrl_dev, ctrl_fn, PCI_vendor_id ,2, &vendor ); 175 | result = pci_conf_read(ctrl_bus, ctrl_dev, ctrl_fn, PCI_device_id ,2, &device ); 176 | 177 | if ((vendor == 0xFFFF || device == 0xFFFF ) || 178 | (vendor == 0x0 && device == 0x0)) 179 | continue; 180 | Sprintf(debug, "%.4X %.4X\n", vendor, device); 181 | Out_Debug_String(debug); 182 | pci_get_name(vendor, device, debug); 183 | strcat(debug, "\n"); 184 | Out_Debug_String(debug); 185 | 186 | for (i=0;i<0x40;i++) 187 | { 188 | result = pci_conf_read(ctrl_bus, ctrl_dev, ctrl_fn, i,1, &tmp); 189 | pci_data[i] = (unsigned char)(tmp&0xff); 190 | #ifdef PCI_DEBUG 191 | Sprintf(debug, "%.2X ", tmp&0xFF); 192 | Out_Debug_String(debug); 193 | if (i%16==15) 194 | Out_Debug_String("\n"); 195 | #endif 196 | 197 | } 198 | 199 | 200 | 201 | } 202 | 203 | 204 | 205 | } 206 | 207 | /*If a display is found, give back its reg adress*/ 208 | unsigned int pci_detect_display(void) 209 | { 210 | 211 | 212 | int i; 213 | unsigned int ctrl_bus; 214 | unsigned int ctrl_dev; 215 | unsigned int ctrl_fn; 216 | 217 | unsigned int header_type_tmp; 218 | 219 | int result; 220 | unsigned int tmp; 221 | unsigned int vendor; 222 | unsigned int device; 223 | unsigned char pci_data[0x40]; 224 | pci_info* p_pci_info; 225 | 226 | unsigned char debug[256]; 227 | unsigned int reg1_address; 228 | 229 | Out_Debug_String("Start pci scan\n"); 230 | 231 | 232 | for (ctrl_bus = 0;ctrl_bus<255;ctrl_bus++) 233 | for (ctrl_dev = 0;ctrl_dev<31;ctrl_dev++) 234 | for (ctrl_fn = 0;ctrl_fn<7;ctrl_fn++) 235 | { 236 | result = pci_conf_read(ctrl_bus, ctrl_dev, ctrl_fn, PCI_vendor_id ,2, &vendor ); 237 | result = pci_conf_read(ctrl_bus, ctrl_dev, ctrl_fn, PCI_device_id ,2, &device ); 238 | 239 | if ((vendor == 0xFFFF || device == 0xFFFF ) || 240 | (vendor == 0x0 && device == 0x0)) 241 | continue; 242 | 243 | Sprintf(debug, "%.4X %.4X\n", vendor, device); 244 | Out_Debug_String(debug); 245 | 246 | 247 | result = pci_conf_read(ctrl_bus, ctrl_dev, ctrl_fn, PCI_header_type,1, &header_type_tmp); 248 | 249 | header_type_tmp&=0x7F; 250 | 251 | Sprintf(debug, "Header type %.2X\n", header_type_tmp); 252 | Out_Debug_String(debug); 253 | 254 | for (i=0;i<0x40;i++) 255 | { 256 | result = pci_conf_read(ctrl_bus, ctrl_dev, ctrl_fn, i,1, &tmp); 257 | pci_data[i] = (unsigned char)(tmp&0xff); 258 | #ifdef PCI_DEBUG 259 | Sprintf(debug, "%.2X ", tmp&0xFF); 260 | Out_Debug_String(debug); 261 | if (i%16==15) 262 | Out_Debug_String("\n"); 263 | #endif 264 | } 265 | 266 | p_pci_info = (pci_info*)pci_data; 267 | 268 | 269 | //If its not a display device 270 | if (p_pci_info->class_base != 3) 271 | continue; 272 | 273 | if (header_type_tmp == 0) 274 | { 275 | reg1_address = p_pci_info->u.h0.base_registers[1]; 276 | } 277 | else if (header_type_tmp == 1) 278 | { 279 | reg1_address = p_pci_info->u.h1.base_registers[1]; 280 | } 281 | else 282 | { 283 | Out_Debug_String("Strange Header...\n"); 284 | continue; 285 | } 286 | 287 | 288 | if (reg1_address & PCI_BASE_ADDRESS_SPACE) 289 | { 290 | Out_Debug_String("Device with io...\n"); 291 | continue; 292 | } 293 | 294 | reg1_address &= ~PCI_BASE_ADDRESS_SPACE_IO; 295 | reg1_address &= PCI_BASE_ADDRESS_MEM_MASK; 296 | 297 | pci_get_name(vendor, device, debug); 298 | 299 | Out_Debug_String("____________\n"); 300 | Out_Debug_String(debug); 301 | Out_Debug_String("\n____________\n"); 302 | 303 | Sprintf(debug, "Good one, returning %.8X\n", reg1_address); 304 | Out_Debug_String(debug); 305 | 306 | return reg1_address; 307 | 308 | } 309 | 310 | Out_Debug_String("Pci scan: failed\n"); 311 | 312 | return 0; 313 | 314 | } 315 | 316 | -------------------------------------------------------------------------------- /0.3/driver_loader.c: -------------------------------------------------------------------------------- 1 | //tx to Eliyas Yakub 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define DRIVER_FUNC_INSTALL 0x01 10 | #define DRIVER_FUNC_REMOVE 0x02 11 | #define DRIVER_NAME "cancel" 12 | 13 | // 14 | // function prototypes 15 | // 16 | BOOLEAN 17 | SetupDriverName( 18 | PUCHAR DriverLocation 19 | ); 20 | 21 | BOOLEAN 22 | ManageDriver( 23 | IN LPCTSTR DriverName, 24 | IN LPCTSTR ServiceName, 25 | IN USHORT Function 26 | ); 27 | 28 | // 29 | // Main function 30 | // 31 | 32 | VOID _cdecl main( ULONG argc, PCHAR argv[] ) 33 | { 34 | UCHAR driverLocation[8*MAX_PATH]; // Just make it long. Doesn't have to be "safe" 35 | HANDLE hDevice; 36 | BOOLEAN r; 37 | DWORD d; 38 | 39 | char * devicePath = "\\\\.\\Cancel"; 40 | 41 | // 42 | // Get driver directory 43 | // 44 | if (argc > 1) { 45 | strcpy(driverLocation, argv[1]); 46 | } else { 47 | strcpy(driverLocation, "."); 48 | d = GetCurrentDirectory(MAX_PATH, driverLocation); 49 | if (d <= 0) { 50 | printf("Could not get current directory.\n"); 51 | getchar(); 52 | return; 53 | } 54 | } 55 | 56 | 57 | 58 | // 59 | // Setup full path to driver name. 60 | // 61 | if (!SetupDriverName(driverLocation)) { 62 | printf("cannot setup driver name\n"); 63 | getchar(); 64 | return; 65 | } 66 | 67 | // 68 | // Be sure driver (and service) are unloaded/removed. 69 | // 70 | printf("Be sure driver (and service) are unloaded/removed.\n"); 71 | (void) ManageDriver (DRIVER_NAME, driverLocation, DRIVER_FUNC_REMOVE); 72 | 73 | 74 | // 75 | // Install driver. 76 | // 77 | printf("Install service and driver.\n"); 78 | r = ManageDriver(DRIVER_NAME, driverLocation, DRIVER_FUNC_INSTALL); 79 | if (!r) { 80 | printf("Unable to install driver: %s\n", driverLocation); 81 | return; 82 | } 83 | 84 | printf("Driver loaded: enter to remove it\n"); 85 | getchar(); 86 | printf("remove driver\n"); 87 | (void) ManageDriver (DRIVER_NAME, driverLocation, DRIVER_FUNC_REMOVE); 88 | 89 | 90 | return ; 91 | 92 | } 93 | 94 | BOOLEAN 95 | SetupDriverName( 96 | PUCHAR DriverLocation 97 | ) 98 | { 99 | HANDLE fileHandle; 100 | 101 | // 102 | // Setup path name to driver file. 103 | // 104 | strcat(DriverLocation, "\\"); 105 | strcat(DriverLocation, DRIVER_NAME); 106 | strcat(DriverLocation, ".sys"); 107 | 108 | // 109 | // Insure driver file is in the specified directory. 110 | // 111 | fileHandle = CreateFile (DriverLocation, 112 | GENERIC_READ, 113 | 0, 114 | NULL, 115 | OPEN_EXISTING, 116 | FILE_ATTRIBUTE_NORMAL, 117 | NULL 118 | ); 119 | if (fileHandle == INVALID_HANDLE_VALUE) { 120 | printf("Driver: %s.SYS is not in the system directory. \n", DRIVER_NAME); 121 | return FALSE; 122 | } 123 | 124 | if (fileHandle) { 125 | CloseHandle(fileHandle); 126 | } 127 | 128 | return TRUE; 129 | } 130 | 131 | ///////////////////////////////////////////////////////////////////////////////////// 132 | // 133 | // Manage Windows drivers via the Service Control Manager APIs 134 | // 135 | ///////////////////////////////////////////////////////////////////////////////////// 136 | BOOLEAN 137 | InstallDriver( 138 | IN SC_HANDLE SchSCManager, 139 | IN LPCTSTR DriverName, 140 | IN LPCTSTR ServiceExe 141 | ); 142 | 143 | 144 | BOOLEAN 145 | RemoveDriver( 146 | IN SC_HANDLE SchSCManager, 147 | IN LPCTSTR DriverName 148 | ); 149 | 150 | BOOLEAN 151 | StartDriver( 152 | IN SC_HANDLE SchSCManager, 153 | IN LPCTSTR DriverName 154 | ); 155 | 156 | BOOLEAN 157 | StopDriver( 158 | IN SC_HANDLE SchSCManager, 159 | IN LPCTSTR DriverName 160 | ); 161 | 162 | 163 | 164 | BOOLEAN 165 | InstallDriver( 166 | IN SC_HANDLE SchSCManager, 167 | IN LPCTSTR DriverName, 168 | IN LPCTSTR ServiceExe 169 | ) 170 | { 171 | SC_HANDLE schService; 172 | DWORD err; 173 | 174 | // 175 | // NOTE: This creates an entry for a standalone driver. If this 176 | // is modified for use with a driver that requires a Tag, 177 | // Group, and/or Dependencies, it may be necessary to 178 | // query the registry for existing driver information 179 | // (in order to determine a unique Tag, etc.). 180 | // 181 | 182 | // 183 | // Create a new a service object. 184 | // 185 | 186 | schService = CreateService(SchSCManager, // handle of service control manager database 187 | DriverName, // address of name of service to start 188 | DriverName, // address of display name 189 | SERVICE_ALL_ACCESS, // type of access to service 190 | SERVICE_KERNEL_DRIVER, // type of service 191 | SERVICE_DEMAND_START, // when to start service 192 | SERVICE_ERROR_NORMAL, // severity if service fails to start 193 | ServiceExe, // address of name of binary file 194 | NULL, // service does not belong to a group 195 | NULL, // no tag requested 196 | NULL, // no dependency names 197 | NULL, // use LocalSystem account 198 | NULL // no password for service account 199 | ); 200 | 201 | if (schService == NULL) { 202 | err = GetLastError(); 203 | if (err == ERROR_SERVICE_EXISTS) { 204 | return TRUE; // Ignore. 205 | } else { 206 | printf("CreateService failed! Error = %d \n", err ); 207 | return FALSE; // Failure. 208 | } 209 | } 210 | 211 | // 212 | // Close the service object. 213 | // 214 | if (schService) { 215 | CloseServiceHandle(schService); 216 | } 217 | 218 | return TRUE; // Success. 219 | } 220 | 221 | BOOLEAN 222 | ManageDriver( 223 | IN LPCTSTR DriverName, 224 | IN LPCTSTR ServiceName, 225 | IN USHORT Function 226 | ) 227 | { 228 | 229 | SC_HANDLE schSCManager; 230 | 231 | BOOLEAN rCode = TRUE; 232 | 233 | // 234 | // Insure (somewhat) that the driver and service names are valid. 235 | // 236 | if (!DriverName || !ServiceName) { 237 | printf("Invalid Driver or Service provided to ManageDriver() \n"); 238 | return FALSE; 239 | } 240 | 241 | // 242 | // Connect to the Service Control Manager and open the Services database. 243 | // 244 | schSCManager = OpenSCManager(NULL, // local machine 245 | NULL, // local database 246 | SC_MANAGER_ALL_ACCESS // access required 247 | ); 248 | 249 | if (!schSCManager) { 250 | printf("Open SC Manager failed! Error = %d \n", GetLastError()); 251 | return FALSE; 252 | } 253 | 254 | // 255 | // Do the requested function. 256 | // 257 | switch( Function ) { 258 | 259 | case DRIVER_FUNC_INSTALL: 260 | // 261 | // Install the driver service. 262 | // 263 | if (InstallDriver(schSCManager, DriverName, ServiceName)) { 264 | // 265 | // Start the driver service (i.e. start the driver). 266 | // 267 | rCode = StartDriver(schSCManager, DriverName); 268 | 269 | } else { 270 | rCode = FALSE; // Indicate an error. 271 | } 272 | break; 273 | 274 | case DRIVER_FUNC_REMOVE: 275 | // 276 | // Stop the driver and remove the driver service. 277 | // 278 | StopDriver(schSCManager, DriverName); 279 | RemoveDriver(schSCManager, DriverName); 280 | 281 | rCode = TRUE; // Ignore all errors. 282 | break; 283 | 284 | default: 285 | printf("Unknown ManageDriver() function. \n"); 286 | rCode = FALSE; 287 | break; 288 | } 289 | 290 | // 291 | // Close handle to service control manager. 292 | // 293 | if (schSCManager) { 294 | CloseServiceHandle(schSCManager); 295 | } 296 | return rCode; 297 | } 298 | 299 | BOOLEAN 300 | RemoveDriver( 301 | IN SC_HANDLE SchSCManager, 302 | IN LPCTSTR DriverName 303 | ) 304 | { 305 | SC_HANDLE schService; 306 | BOOLEAN rCode; 307 | DWORD err; 308 | 309 | // 310 | // Open the handle to the existing service. 311 | // 312 | schService = OpenService(SchSCManager, DriverName, SERVICE_ALL_ACCESS); 313 | if (schService == NULL) { 314 | err = GetLastError(); 315 | if (err != ERROR_SERVICE_DOES_NOT_EXIST && err != ERROR_SERVICE_NOT_ACTIVE) 316 | { 317 | printf("OpenService failed! Error = %d \n", err); 318 | } 319 | return FALSE; // Failure. 320 | } 321 | 322 | // 323 | // Mark the service for deletion from the service control manager database. 324 | // 325 | if (DeleteService(schService)) { 326 | rCode = TRUE; // Success. 327 | } else { 328 | err = GetLastError(); 329 | if (err != ERROR_SERVICE_DOES_NOT_EXIST && err != ERROR_SERVICE_NOT_ACTIVE) 330 | { 331 | printf("DeleteService failed! Error = %d \n", err); 332 | } 333 | rCode = FALSE; // Failure. 334 | } 335 | 336 | // 337 | // Close the service object. 338 | // 339 | if (schService) { 340 | CloseServiceHandle(schService); 341 | } 342 | 343 | return rCode; 344 | } 345 | 346 | BOOLEAN 347 | StartDriver( 348 | IN SC_HANDLE SchSCManager, 349 | IN LPCTSTR DriverName 350 | ) 351 | { 352 | SC_HANDLE schService; 353 | DWORD err; 354 | 355 | // 356 | // Open the handle to the existing service. 357 | // 358 | schService = OpenService(SchSCManager, DriverName, SERVICE_ALL_ACCESS); 359 | if (schService == NULL) { 360 | printf("OpenService failed! Error = %d \n", GetLastError()); 361 | return FALSE; // Failure. 362 | } 363 | 364 | // 365 | // Start the execution of the service (i.e. start the driver). 366 | // 367 | if (!StartService(schService, 0, NULL)) { 368 | 369 | err = GetLastError(); 370 | if (err == ERROR_SERVICE_ALREADY_RUNNING) { 371 | return TRUE; // Ignore. 372 | } else { 373 | printf("StartService failure! Error = %d \n", err ); 374 | return FALSE; // Failure. 375 | } 376 | 377 | } 378 | 379 | // 380 | // Close the service object. 381 | // 382 | if (schService) { 383 | CloseServiceHandle(schService); 384 | } 385 | 386 | return TRUE; 387 | } 388 | 389 | BOOLEAN 390 | StopDriver( 391 | IN SC_HANDLE SchSCManager, 392 | IN LPCTSTR DriverName 393 | ) 394 | { 395 | BOOLEAN rCode = TRUE; 396 | SC_HANDLE schService; 397 | SERVICE_STATUS serviceStatus; 398 | DWORD err; 399 | 400 | // 401 | // Open the handle to the existing service. 402 | // 403 | schService = OpenService(SchSCManager, DriverName, SERVICE_ALL_ACCESS); 404 | if (schService == NULL) { 405 | err = GetLastError(); 406 | if (err != ERROR_SERVICE_DOES_NOT_EXIST && err != ERROR_SERVICE_NOT_ACTIVE) 407 | { 408 | printf("OpenService failed! Error = %d \n", err); 409 | } 410 | return FALSE; 411 | } 412 | 413 | // 414 | // Request that the service stop. 415 | // 416 | if (ControlService(schService, SERVICE_CONTROL_STOP, &serviceStatus)) { 417 | rCode = TRUE; // Success. 418 | } else { 419 | err = GetLastError(); 420 | if (err != ERROR_SERVICE_DOES_NOT_EXIST && err != ERROR_SERVICE_NOT_ACTIVE) 421 | { 422 | printf("ControlService failed! Error = %d \n", err); 423 | } 424 | rCode = FALSE; // Failure. 425 | } 426 | 427 | // 428 | // Close the service object. 429 | // 430 | if (schService) { 431 | CloseServiceHandle (schService); 432 | } 433 | 434 | return rCode; 435 | } 436 | 437 | 438 | -------------------------------------------------------------------------------- /0.3/pci.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMTEST_PCI_H 2 | #define MEMTEST_PCI_H 3 | 4 | int pci_conf_read(unsigned bus, unsigned dev, unsigned fn, unsigned reg, 5 | unsigned len, unsigned int *value); 6 | int pci_conf_write(unsigned bus, unsigned dev, unsigned fn, unsigned reg, 7 | unsigned len, unsigned int value); 8 | int pci_init(void); 9 | 10 | /* 11 | * Under PCI, each device has 256 bytes of configuration address space, 12 | * of which the first 64 bytes are standardized as follows: 13 | */ 14 | #define PCI_VENDOR_ID 0x00 /* 16 bits */ 15 | #define PCI_DEVICE_ID 0x02 /* 16 bits */ 16 | #define PCI_COMMAND 0x04 /* 16 bits */ 17 | #define PCI_COMMAND_IO 0x1 /* Enable response in I/O space */ 18 | #define PCI_COMMAND_MEMORY 0x2 /* Enable response in Memory space */ 19 | #define PCI_COMMAND_MASTER 0x4 /* Enable bus mastering */ 20 | #define PCI_COMMAND_SPECIAL 0x8 /* Enable response to special cycles */ 21 | #define PCI_COMMAND_INVALIDATE 0x10 /* Use memory write and invalidate */ 22 | #define PCI_COMMAND_VGA_PALETTE 0x20 /* Enable palette snooping */ 23 | #define PCI_COMMAND_PARITY 0x40 /* Enable parity checking */ 24 | #define PCI_COMMAND_WAIT 0x80 /* Enable address/data stepping */ 25 | #define PCI_COMMAND_SERR 0x100 /* Enable SERR */ 26 | #define PCI_COMMAND_FAST_BACK 0x200 /* Enable back-to-back writes */ 27 | 28 | #define PCI_STATUS 0x06 /* 16 bits */ 29 | #define PCI_STATUS_CAP_LIST 0x10 /* Support Capability List */ 30 | #define PCI_STATUS_66MHZ 0x20 /* Support 66 Mhz PCI 2.1 bus */ 31 | #define PCI_STATUS_UDF 0x40 /* Support User Definable Features [obsolete] */ 32 | #define PCI_STATUS_FAST_BACK 0x80 /* Accept fast-back to back */ 33 | #define PCI_STATUS_PARITY 0x100 /* Detected parity error */ 34 | #define PCI_STATUS_DEVSEL_MASK 0x600 /* DEVSEL timing */ 35 | #define PCI_STATUS_DEVSEL_FAST 0x000 36 | #define PCI_STATUS_DEVSEL_MEDIUM 0x200 37 | #define PCI_STATUS_DEVSEL_SLOW 0x400 38 | #define PCI_STATUS_SIG_TARGET_ABORT 0x800 /* Set on target abort */ 39 | #define PCI_STATUS_REC_TARGET_ABORT 0x1000 /* Master ack of " */ 40 | #define PCI_STATUS_REC_MASTER_ABORT 0x2000 /* Set on master abort */ 41 | #define PCI_STATUS_SIG_SYSTEM_ERROR 0x4000 /* Set when we drive SERR */ 42 | #define PCI_STATUS_DETECTED_PARITY 0x8000 /* Set on parity error */ 43 | 44 | #define PCI_CLASS_REVISION 0x08 /* High 24 bits are class, low 8 45 | revision */ 46 | #define PCI_REVISION_ID 0x08 /* Revision ID */ 47 | #define PCI_CLASS_PROG 0x09 /* Reg. Level Programming Interface */ 48 | #define PCI_CLASS_DEVICE 0x0a /* Device class */ 49 | 50 | #define PCI_CACHE_LINE_SIZE 0x0c /* 8 bits */ 51 | #define PCI_LATENCY_TIMER 0x0d /* 8 bits */ 52 | #define PCI_HEADER_TYPE 0x0e /* 8 bits */ 53 | #define PCI_HEADER_TYPE_NORMAL 0 54 | #define PCI_HEADER_TYPE_BRIDGE 1 55 | #define PCI_HEADER_TYPE_CARDBUS 2 56 | 57 | #define PCI_BIST 0x0f /* 8 bits */ 58 | #define PCI_BIST_CODE_MASK 0x0f /* Return result */ 59 | #define PCI_BIST_START 0x40 /* 1 to start BIST, 2 secs or less */ 60 | #define PCI_BIST_CAPABLE 0x80 /* 1 if BIST capable */ 61 | 62 | /* 63 | * Base addresses specify locations in memory or I/O space. 64 | * Decoded size can be determined by writing a value of 65 | * 0xffffffff to the register, and reading it back. Only 66 | * 1 bits are decoded. 67 | */ 68 | #define PCI_BASE_ADDRESS_0 0x10 /* 32 bits */ 69 | #define PCI_BASE_ADDRESS_1 0x14 /* 32 bits [htype 0,1 only] */ 70 | #define PCI_BASE_ADDRESS_2 0x18 /* 32 bits [htype 0 only] */ 71 | #define PCI_BASE_ADDRESS_3 0x1c /* 32 bits */ 72 | #define PCI_BASE_ADDRESS_4 0x20 /* 32 bits */ 73 | #define PCI_BASE_ADDRESS_5 0x24 /* 32 bits */ 74 | #define PCI_BASE_ADDRESS_SPACE 0x01 /* 0 = memory, 1 = I/O */ 75 | #define PCI_BASE_ADDRESS_SPACE_IO 0x01 76 | #define PCI_BASE_ADDRESS_SPACE_MEMORY 0x00 77 | #define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06 78 | #define PCI_BASE_ADDRESS_MEM_TYPE_32 0x00 /* 32 bit address */ 79 | #define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02 /* Below 1M [obsolete] */ 80 | #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04 /* 64 bit address */ 81 | #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08 /* prefetchable? */ 82 | #define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) 83 | #define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) 84 | /* bit 1 is reserved if address_space = 1 */ 85 | 86 | 87 | /* Device classes and subclasses */ 88 | #define PCI_CLASS_NOT_DEFINED 0x0000 89 | #define PCI_CLASS_NOT_DEFINED_VGA 0x0001 90 | 91 | #define PCI_BASE_CLASS_BRIDGE 0x06 92 | #define PCI_CLASS_BRIDGE_HOST 0x0600 93 | 94 | #endif /* MEMTEST_PCI_H */ 95 | 96 | #ifndef uchar 97 | #define uchar unsigned char 98 | #endif 99 | #ifndef ushort 100 | #define ushort unsigned short 101 | #endif 102 | #ifndef ulong 103 | #define ulong unsigned int 104 | #endif 105 | 106 | 107 | /*MOI MOI*/ 108 | typedef struct pci_info { 109 | ushort vendor_id; /* vendor id */ 110 | ushort device_id; /* device id */ 111 | ushort command; /* bus number */ 112 | ushort status; /* device number on bus */ 113 | uchar revision; /* revision id */ 114 | uchar class_api; /* specific register interface type */ 115 | uchar class_sub; /* specific device function */ 116 | uchar class_base; /* device type (display vs network, etc) */ 117 | uchar line_size; /* cache line size in 32 bit words */ 118 | uchar latency; /* latency timer */ 119 | uchar header_type; /* header type */ 120 | uchar bist; /* built-in self-test */ 121 | 122 | 123 | union { 124 | struct { 125 | //0x10 126 | ulong base_registers[6]; /* base registers, viewed from host */ 127 | ulong cardbus_cis; /* CardBus CIS pointer */ 128 | 129 | 130 | ushort subsystem_vendor_id; /* subsystem (add-in card) vendor id */ 131 | ushort subsystem_id; /* subsystem (add-in card) id */ 132 | //0x30 133 | ulong rom_base; /* rom base address, viewed from host */ 134 | ulong rom_base_pci; /* rom base addr, viewed from pci */ 135 | ulong rom_size; /* rom size */ 136 | 137 | //0x3c 138 | uchar interrupt_line; /* interrupt line */ 139 | uchar interrupt_pin; /* interrupt pin */ 140 | 141 | //0x3e 142 | uchar min_grant; /* burst period @ 33 Mhz */ 143 | uchar max_latency; /* how often PCI access needed */ 144 | 145 | 146 | } h0; 147 | struct { 148 | //0x10 149 | ulong base_registers[2]; /* base registers, viewed from host */ 150 | 151 | ulong base_registers_pci[2]; /* base registers, viewed from pci */ 152 | ulong base_register_sizes[2]; /* size of what base regs point to */ 153 | uchar base_register_flags[2]; /* flags from base address fields */ 154 | 155 | uchar primary_bus; 156 | uchar secondary_bus; 157 | uchar subordinate_bus; 158 | uchar secondary_latency; 159 | uchar io_base; 160 | uchar io_limit; 161 | ushort secondary_status; 162 | ushort memory_base; 163 | ushort memory_limit; 164 | ushort prefetchable_memory_base; 165 | ushort prefetchable_memory_limit; 166 | ulong prefetchable_memory_base_upper32; 167 | ulong prefetchable_memory_limit_upper32; 168 | //0x30 169 | ushort io_base_upper16; 170 | ushort io_limit_upper16; 171 | ulong rom_base; /* rom base address, viewed from host */ 172 | ulong rom_base_pci; /* rom base addr, viewed from pci */ 173 | 174 | //0x3c 175 | uchar interrupt_line; /* interrupt line */ 176 | uchar interrupt_pin; /* interrupt pin */ 177 | ushort bridge_control; 178 | } h1; 179 | } u; 180 | } pci_info; 181 | 182 | 183 | 184 | typedef struct _pci_info { 185 | ushort vendor_id; /* vendor id */ 186 | ushort device_id; /* device id */ 187 | uchar bus; /* bus number */ 188 | uchar device; /* device number on bus */ 189 | uchar function; /* function number in device */ 190 | uchar revision; /* revision id */ 191 | uchar class_api; /* specific register interface type */ 192 | uchar class_sub; /* specific device function */ 193 | uchar class_base; /* device type (display vs network, etc) */ 194 | uchar line_size; /* cache line size in 32 bit words */ 195 | uchar latency; /* latency timer */ 196 | uchar header_type; /* header type */ 197 | uchar bist; /* built-in self-test */ 198 | uchar reserved; /* filler, for alignment */ 199 | union { 200 | struct { 201 | ulong cardbus_cis; /* CardBus CIS pointer */ 202 | ushort subsystem_id; /* subsystem (add-in card) id */ 203 | ushort subsystem_vendor_id; /* subsystem (add-in card) vendor id */ 204 | ulong rom_base; /* rom base address, viewed from host */ 205 | ulong rom_base_pci; /* rom base addr, viewed from pci */ 206 | ulong rom_size; /* rom size */ 207 | ulong base_registers[6]; /* base registers, viewed from host */ 208 | ulong base_registers_pci[6]; /* base registers, viewed from pci */ 209 | ulong base_register_sizes[6]; /* size of what base regs point to */ 210 | uchar base_register_flags[6]; /* flags from base address fields */ 211 | uchar interrupt_line; /* interrupt line */ 212 | uchar interrupt_pin; /* interrupt pin */ 213 | uchar min_grant; /* burst period @ 33 Mhz */ 214 | uchar max_latency; /* how often PCI access needed */ 215 | } _h0; 216 | struct { 217 | ulong base_registers[2]; /* base registers, viewed from host */ 218 | ulong base_registers_pci[2]; /* base registers, viewed from pci */ 219 | ulong base_register_sizes[2]; /* size of what base regs point to */ 220 | uchar base_register_flags[2]; /* flags from base address fields */ 221 | uchar primary_bus; 222 | uchar secondary_bus; 223 | uchar subordinate_bus; 224 | uchar secondary_latency; 225 | uchar io_base; 226 | uchar io_limit; 227 | ushort secondary_status; 228 | ushort memory_base; 229 | ushort memory_limit; 230 | ushort prefetchable_memory_base; 231 | ushort prefetchable_memory_limit; 232 | ulong prefetchable_memory_base_upper32; 233 | ulong prefetchable_memory_limit_upper32; 234 | ushort io_base_upper16; 235 | ushort io_limit_upper16; 236 | ulong rom_base; /* rom base address, viewed from host */ 237 | ulong rom_base_pci; /* rom base addr, viewed from pci */ 238 | uchar interrupt_line; /* interrupt line */ 239 | uchar interrupt_pin; /* interrupt pin */ 240 | ushort bridge_control; 241 | } _h1; 242 | } _u; 243 | } _pci_info; 244 | 245 | 246 | 247 | 248 | /* --- 249 | offsets in PCI configuration space to the elements of the predefined 250 | header common to all header types 251 | --- */ 252 | 253 | #define PCI_vendor_id 0x00 /* (2 byte) vendor id */ 254 | #define PCI_device_id 0x02 /* (2 byte) device id */ 255 | #define PCI_command 0x04 /* (2 byte) command */ 256 | #define PCI_status 0x06 /* (2 byte) status */ 257 | #define PCI_revision 0x08 /* (1 byte) revision id */ 258 | #define PCI_class_api 0x09 /* (1 byte) specific register interface type */ 259 | #define PCI_class_sub 0x0a /* (1 byte) specific device function */ 260 | #define PCI_class_base 0x0b /* (1 byte) device type (display vs network, etc) */ 261 | #define PCI_line_size 0x0c /* (1 byte) cache line size in 32 bit words */ 262 | #define PCI_latency 0x0d /* (1 byte) latency timer */ 263 | #define PCI_header_type 0x0e /* (1 byte) header type */ 264 | #define PCI_bist 0x0f /* (1 byte) built-in self-test */ 265 | 266 | 267 | 268 | /* --- 269 | offsets in PCI configuration space to the elements of the predefined 270 | header common to header types 0x00 and 0x01 271 | --- */ 272 | #define PCI_base_registers 0x10 /* base registers (size varies) */ 273 | #define PCI_interrupt_line 0x3c /* (1 byte) interrupt line */ 274 | #define PCI_interrupt_pin 0x3d /* (1 byte) interrupt pin */ 275 | 276 | 277 | 278 | 279 | /* --- 280 | offsets in PCI configuration space to the elements of header type 0x00 281 | --- */ 282 | 283 | #define PCI_cardbus_cis 0x28 /* (4 bytes) CardBus CIS (Card Information Structure) pointer (see PCMCIA v2.10) */ 284 | #define PCI_subsystem_vendor_id 0x2c /* (2 bytes) subsystem (add-in card) vendor id */ 285 | #define PCI_subsystem_id 0x2e /* (2 bytes) subsystem (add-in card) id */ 286 | #define PCI_rom_base 0x30 /* (4 bytes) expansion rom base address */ 287 | #define PCI_min_grant 0x3e /* (1 byte) burst period @ 33 Mhz */ 288 | #define PCI_max_latency 0x3f /* (1 byte) how often PCI access needed */ 289 | 290 | 291 | /* --- 292 | offsets in PCI configuration space to the elements of header type 0x01 (PCI-to-PCI bridge) 293 | --- */ 294 | 295 | #define PCI_primary_bus 0x18 296 | #define PCI_secondary_bus 0x19 297 | #define PCI_subordinate_bus 0x1A 298 | #define PCI_secondary_latency 0x1B 299 | #define PCI_io_base 0x1C 300 | #define PCI_io_limit 0x1D 301 | #define PCI_secondary_status 0x1E 302 | #define PCI_memory_base 0x20 303 | #define PCI_memory_limit 0x22 304 | #define PCI_prefetchable_memory_base 0x24 305 | #define PCI_prefetchable_memory_limit 0x26 306 | #define PCI_prefetchable_memory_base_upper32 0x28 307 | #define PCI_prefetchable_memory_limit_upper32 0x2C 308 | #define PCI_io_base_upper16 0x30 309 | #define PCI_io_limit_upper16 0x32 310 | #define PCI_bridge_rom_base 0x38 311 | #define PCI_bridge_control 0x3E 312 | 313 | 314 | 315 | /* --- 316 | values for the class_base field in the common header 317 | --- */ 318 | 319 | #define PCI_early 0x00 /* built before class codes defined */ 320 | #define PCI_mass_storage 0x01 /* mass storage_controller */ 321 | #define PCI_network 0x02 /* network controller */ 322 | #define PCI_display 0x03 /* display controller */ 323 | #define PCI_multimedia 0x04 /* multimedia device */ 324 | #define PCI_memory 0x05 /* memory controller */ 325 | #define PCI_bridge 0x06 /* bridge controller */ 326 | #define PCI_simple_communications 0x07 /* simple communications controller */ 327 | #define PCI_base_peripheral 0x08 /* base system peripherals */ 328 | #define PCI_input 0x09 /* input devices */ 329 | #define PCI_docking_station 0x0a /* docking stations */ 330 | #define PCI_processor 0x0b /* processors */ 331 | #define PCI_serial_bus 0x0c /* serial_bus_controller */ 332 | 333 | #define PCI_undefined 0xFF /* not in any defined class */ 334 | 335 | 336 | 337 | struct pci_desc 338 | { 339 | unsigned int id; 340 | unsigned char name[130]; 341 | struct pci_desc* list; 342 | }; 343 | 344 | typedef struct pci_desc pci_desc; 345 | 346 | 347 | 348 | void list_controller(void); 349 | unsigned int pci_detect_display(void); 350 | 351 | 352 | -------------------------------------------------------------------------------- /0.3/utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Rasta Ring 0 debug 3 | * 4 | * Copyright (C) 2004 Droids Corporation. 5 | * based on Deblin debuger 6 | * 7 | * $Id $ 8 | * 9 | */ 10 | 11 | 12 | #include "utils.h" 13 | 14 | 15 | 16 | 17 | 18 | 19 | #include 20 | 21 | 22 | 23 | /*TEST TEST*/ 24 | 25 | unsigned char rr0d_inb (unsigned int Port) 26 | { 27 | unsigned char Value; 28 | #if defined(__GNUC__) 29 | __asm__("inb %w1, %0;\n\t" 30 | : "=a" (Value) 31 | : "d" (Port)); 32 | 33 | #elif defined(_MSC_VER) 34 | __asm 35 | { 36 | push edx 37 | xor edx, edx 38 | mov edx, Port 39 | in al, dx 40 | mov Value, al 41 | pop edx 42 | } 43 | #endif 44 | return(Value); 45 | } 46 | 47 | 48 | unsigned short rr0d_inw (unsigned int Port) 49 | { 50 | unsigned short Value; 51 | #if defined(__GNUC__) 52 | __asm__("inw %w1, %0;\n\t" 53 | : "=a" (Value) 54 | : "d" (Port)); 55 | 56 | #elif defined(_MSC_VER) 57 | __asm 58 | { 59 | push edx 60 | xor edx, edx 61 | mov edx, Port 62 | in ax, dx 63 | mov Value, ax 64 | pop edx 65 | } 66 | #endif 67 | return(Value); 68 | } 69 | 70 | 71 | unsigned int rr0d_inl (unsigned int Port) 72 | { 73 | unsigned int Value; 74 | #if defined(__GNUC__) 75 | __asm__("inl %w1, %0;\n\t" 76 | : "=a" (Value) 77 | : "d" (Port)); 78 | 79 | #elif defined(_MSC_VER) 80 | __asm 81 | { 82 | push edx 83 | xor edx, edx 84 | mov edx, Port 85 | in eax, dx 86 | mov Value, eax 87 | pop edx 88 | } 89 | #endif 90 | return(Value); 91 | } 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | void rr0d_outb (unsigned char Value, unsigned int Port) 100 | { 101 | #if defined(__GNUC__) 102 | __asm__("outb %0, %w1\n\t" 103 | : 104 | : "a" (Value), 105 | "d" (Port)); 106 | #elif defined(_MSC_VER) 107 | __asm 108 | { 109 | push edx 110 | xor edx, edx 111 | mov edx, Port 112 | mov al, Value 113 | out dx,al 114 | pop edx 115 | } 116 | #endif 117 | } 118 | 119 | 120 | void rr0d_outw (unsigned short Value, unsigned int Port) 121 | { 122 | #if defined(__GNUC__) 123 | __asm__("outw %0, %w1\n\t" 124 | : 125 | : "a" (Value), 126 | "d" (Port)); 127 | #elif defined(_MSC_VER) 128 | __asm 129 | { 130 | push edx 131 | xor edx, edx 132 | mov edx, Port 133 | mov ax, Value 134 | out dx,ax 135 | pop edx 136 | } 137 | #endif 138 | } 139 | 140 | 141 | void rr0d_outl (unsigned int Value, unsigned int Port) 142 | { 143 | #if defined(__GNUC__) 144 | __asm__("outl %0, %w1\n\t" 145 | : 146 | : "a" (Value), 147 | "d" (Port)); 148 | #elif defined(_MSC_VER) 149 | __asm 150 | { 151 | push edx 152 | xor edx, edx 153 | mov edx, Port 154 | mov eax, Value 155 | out dx,eax 156 | pop edx 157 | } 158 | #endif 159 | } 160 | 161 | 162 | static void bad ( char *fmt) 163 | { 164 | //printf("bad fmt in Sprintf, starting with \"%s\"\n", fmt); 165 | //exit(1); 166 | } 167 | 168 | #define put(x) *outbuf++ = (char)x 169 | 170 | 171 | 172 | unsigned char hexabuf_M[] = "0123456789ABCDEF"; 173 | unsigned char hexabuf_L[] = "0123456789abcdef"; 174 | 175 | 176 | int Sprintf( char *outbuf, char *fmt, ...) 177 | { 178 | char *ob0, *s; 179 | char buf[32]; 180 | va_list ap; 181 | //long i/*, j*/; 182 | unsigned int i, j; 183 | int signed_entry; 184 | char* hexabuf = (unsigned char)0; 185 | int fixed_len; 186 | unsigned char c; 187 | 188 | va_start(ap, fmt); 189 | ob0 = outbuf; 190 | for(;;) { 191 | for(;;) { 192 | switch(i = *fmt++) { 193 | case 0: 194 | goto done; 195 | case '%': 196 | break; 197 | default: 198 | put(i); 199 | continue; 200 | } 201 | break; 202 | } 203 | fixed_len=0; 204 | special_char: 205 | switch(*fmt++) { 206 | 207 | case '.': 208 | for(i=0;i<8;i++) 209 | { 210 | c = *fmt++; 211 | if (c>='0' && c <='9') 212 | { 213 | fixed_len*=10; 214 | fixed_len+=c-'0'; 215 | } 216 | else 217 | break; 218 | } 219 | fmt--; 220 | goto special_char; 221 | continue; 222 | case 'c': 223 | i = va_arg(ap, int); 224 | put(i); 225 | continue; 226 | case 'l': 227 | if ((*fmt != 'd')&& (*fmt != 'x') && (*fmt != 'X')) 228 | bad(fmt); 229 | if ((*fmt == 'x') || (*fmt == 'X')) 230 | goto special_char; 231 | 232 | fmt++; 233 | //i = va_arg(ap, long); 234 | signed_entry = va_arg(ap, long); 235 | goto have_i; 236 | case 'd': 237 | //i = va_arg(ap, int); 238 | signed_entry = va_arg(ap, int); 239 | have_i: 240 | if (signed_entry < 0) { 241 | put('-'); 242 | signed_entry = -signed_entry; 243 | } 244 | s = buf; 245 | i = signed_entry; 246 | do { 247 | j = i / 10; 248 | *s++ = i - 10*j + '0'; 249 | fixed_len--; 250 | } 251 | while((i = j)); 252 | while(fixed_len-->0) put('0'); 253 | do { 254 | i = *--s; 255 | put(i); 256 | } 257 | while(s > buf); 258 | continue; 259 | case 'x': 260 | hexabuf = hexabuf_L; 261 | goto have_hexa; 262 | case 'X': 263 | hexabuf = hexabuf_M; 264 | have_hexa: 265 | i = va_arg(ap, int); 266 | s = buf; 267 | do { 268 | j = i / 16; 269 | *s++ = hexabuf[i - 16*j]; 270 | fixed_len--; 271 | } 272 | while((i = j)); 273 | while(fixed_len-->0) put('0'); 274 | do { 275 | i = *--s; 276 | put(i); 277 | } 278 | while(s > buf); 279 | continue; 280 | 281 | 282 | case 's': 283 | s = va_arg(ap, char*); 284 | while((i = *s++)) 285 | { put(i); } 286 | continue; 287 | default: 288 | bad(fmt); 289 | } 290 | } 291 | done: 292 | *outbuf = 0; 293 | return outbuf - ob0; 294 | } 295 | /* 296 | #ifdef __cplusplus 297 | } 298 | #endif 299 | */ 300 | 301 | 302 | 303 | 304 | 305 | /*TRUE STDLIB*/ 306 | #ifndef NULL 307 | #define NULL ((unsigned char*)0) 308 | #endif 309 | #define _U 0x00000001 /* Upper case */ 310 | #define _L 0x00000002 /* Lower case */ 311 | #define _N 0x00000004 /* Numeral (digit) */ 312 | #define _S 0x00000008 /* Spacing character */ 313 | #define _P 0x00000010 /* Punctuation */ 314 | #define _C 0x00000020 /* Control character */ 315 | #define _B 0x00000040 /* Blank */ 316 | #define _X 0x00000080 /* heXadecimal digit */ 317 | 318 | 319 | 320 | char _ctype_[] = { 0, 321 | 322 | /* 0 1 2 3 4 5 6 7 */ 323 | 324 | /* 0*/ _C, _C, _C, _C, _C, _C, _C, _C, 325 | /* 10*/ _C, _S|_C, _S|_C, _S|_C, _S|_C, _S|_C, _C, _C, 326 | /* 20*/ _C, _C, _C, _C, _C, _C, _C, _C, 327 | /* 30*/ _C, _C, _C, _C, _C, _C, _C, _C, 328 | /* 40*/ (char)(_S|_B), _P, _P, _P, _P, _P, _P, _P, 329 | /* 50*/ _P, _P, _P, _P, _P, _P, _P, _P, 330 | /* 60*/ _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, 331 | /* 70*/ _N|_X, _N|_X, _P, _P, _P, _P, _P, _P, 332 | /*100*/ _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, 333 | /*110*/ _U, _U, _U, _U, _U, _U, _U, _U, 334 | /*120*/ _U, _U, _U, _U, _U, _U, _U, _U, 335 | /*130*/ _U, _U, _U, _P, _P, _P, _P, _P, 336 | /*140*/ _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, 337 | /*150*/ _L, _L, _L, _L, _L, _L, _L, _L, 338 | /*160*/ _L, _L, _L, _L, _L, _L, _L, _L, 339 | /*170*/ _L, _L, _L, _P, _P, _P, _P, _C, 340 | /*200*/ 0, 0, 0, 0, 0, 0, 0, 0, 341 | 0, 0, 0, 0, 0, 0, 0, 0, 342 | 0, 0, 0, 0, 0, 0, 0, 0, 343 | 0, 0, 0, 0, 0, 0, 0, 0, 344 | 0, 0, 0, 0, 0, 0, 0, 0, 345 | 0, 0, 0, 0, 0, 0, 0, 0, 346 | 0, 0, 0, 0, 0, 0, 0, 0, 347 | 0, 0, 0, 0, 0, 0, 0, 0, 348 | 0, 0, 0, 0, 0, 0, 0, 0, 349 | 0, 0, 0, 0, 0, 0, 0, 0, 350 | 0, 0, 0, 0, 0, 0, 0, 0, 351 | 0, 0, 0, 0, 0, 0, 0, 0, 352 | 0, 0, 0, 0, 0, 0, 0, 0, 353 | 0, 0, 0, 0, 0, 0, 0, 0, 354 | 0, 0, 0, 0, 0, 0, 0, 0, 355 | 0, 0, 0, 0, 0, 0, 0, 0 356 | }; 357 | 358 | unsigned int _mb_cur_max; 359 | 360 | 361 | int rr0d_isalpha(register int c) 362 | { 363 | return((_ctype_+1)[c]&(_U|_L)); 364 | } 365 | 366 | int rr0d_isupper(register int c) 367 | { 368 | return((_ctype_+1)[c]&_U); 369 | } 370 | 371 | int rr0d_islower(register int c) 372 | { 373 | return((_ctype_+1)[c]&_L); 374 | } 375 | 376 | int rr0d_isdigit(register int c) 377 | { 378 | return((_ctype_+1)[c]&_N); 379 | } 380 | 381 | int rr0d_isxdigit(register int c) 382 | { 383 | return((_ctype_+1)[c]&_X); 384 | } 385 | 386 | 387 | int rr0d_isspace(register int c) 388 | { 389 | return((_ctype_+1)[c]&_S); 390 | } 391 | 392 | 393 | int rr0d_ispunct(register int c) 394 | { 395 | return((_ctype_+1)[c]&_P); 396 | } 397 | 398 | 399 | int rr0d_isalnum(register int c) 400 | { 401 | return((_ctype_+1)[c]&(_U|_L|_N)); 402 | } 403 | 404 | 405 | int rr0d_isprint(register int c) 406 | { 407 | return((_ctype_+1)[c]&(_P|_U|_L|_N|_B)); 408 | } 409 | 410 | 411 | int rr0d_isgraph(register int c) 412 | { 413 | return((_ctype_+1)[c]&(_P|_U|_L|_N)); 414 | } 415 | 416 | 417 | int rr0d_iscntrl(register int c) 418 | { 419 | return((_ctype_+1)[c]&_C); 420 | } 421 | 422 | int rr0d_isascii(register int c) 423 | { 424 | return((unsigned)(c)<=0177); 425 | } 426 | 427 | int rr0d_toascii(register int c) 428 | { 429 | return((c)&0177); 430 | } 431 | 432 | 433 | 434 | 435 | 436 | int rr0d_atoi( char *p) 437 | { 438 | int n; 439 | int c, neg = 0; 440 | unsigned char *up = (unsigned char *)p; 441 | 442 | if (!rr0d_isdigit(c = *up)) { 443 | while (rr0d_isspace(c)) 444 | c = *++up; 445 | switch (c) { 446 | case '-': 447 | neg++; 448 | /* FALLTHROUGH */ 449 | case '+': 450 | c = *++up; 451 | } 452 | if (!rr0d_isdigit(c)) 453 | return (0); 454 | } 455 | for (n = '0' - c; rr0d_isdigit(c = *++up); ) { 456 | n *= 10; /* two steps to avoid unnecessary overflow */ 457 | n += '0' - c; /* accum neg to avoid surprises at MAX */ 458 | } 459 | return (neg ? n : -n); 460 | } 461 | 462 | char * rr0d_strchr( char *sp, int c) 463 | { 464 | do { 465 | if (*sp == (char)c) 466 | return ((char *)sp); 467 | } while (*sp++); 468 | return (NULL); 469 | } 470 | int rr0d_strcmp( char *s1, char *s2) 471 | { 472 | if (s1 == s2) 473 | return (0); 474 | while (*s1 == *s2++) 475 | if (*s1++ == '\0') 476 | return (0); 477 | return (*(unsigned char *)s1 - *(unsigned char *)--s2); 478 | } 479 | 480 | unsigned int rr0d_strlen( char *s) 481 | { 482 | char *s0 = s + 1; 483 | 484 | while (*s++ != '\0') 485 | ; 486 | return (s - s0); 487 | } 488 | int rr0d_strnicmp ( char *s1, char *s2,size_t n) 489 | { 490 | char c1,c2; 491 | 492 | if(n==0) return 0; 493 | 494 | do { 495 | c1 = *s1++; if(rr0d_islower(c1)) c1=rr0d_toupper(c1); 496 | c2 = *s2++; if(rr0d_islower(c2)) c2=rr0d_toupper(c2); 497 | } while(c1==c2 && c1 && c2 && --n>0); 498 | 499 | if(n==0 || c1==c2) return 0; 500 | if(c1=='\0' || c1> 6) & 03; 127 | rm = modrm & 07; 128 | 129 | if (mod == 3) { /* pure register version */ 130 | op->basereg = rm; 131 | op->segment |= SEG_RMREG; 132 | return data; 133 | } 134 | 135 | op->addr_size = 0; 136 | 137 | if (asize == 16) { 138 | /* 139 | * specifies the displacement size (none, byte or 140 | * word), and specifies the register combination. 141 | * Exception: mod=0,rm=6 does not specify [BP] as one might 142 | * expect, but instead specifies [disp16]. 143 | */ 144 | op->indexreg = op->basereg = -1; 145 | op->scale = 1; /* always, in 16 bits */ 146 | switch (rm) { 147 | case 0: op->basereg = R_BX; op->indexreg = R_SI; break; 148 | case 1: op->basereg = R_BX; op->indexreg = R_DI; break; 149 | case 2: op->basereg = R_BP; op->indexreg = R_SI; break; 150 | case 3: op->basereg = R_BP; op->indexreg = R_DI; break; 151 | case 4: op->basereg = R_SI; break; 152 | case 5: op->basereg = R_DI; break; 153 | case 6: op->basereg = R_BP; break; 154 | case 7: op->basereg = R_BX; break; 155 | } 156 | if (rm == 6 && mod == 0) { /* special case */ 157 | op->basereg = -1; 158 | if (segsize != 16) 159 | op->addr_size = 16; 160 | mod = 2; /* fake disp16 */ 161 | } 162 | switch (mod) { 163 | case 0: 164 | op->segment |= SEG_NODISP; 165 | break; 166 | case 1: 167 | op->segment |= SEG_DISP8; 168 | op->offset = (signed char) *data++; 169 | break; 170 | case 2: 171 | op->segment |= SEG_DISP16; 172 | op->offset = *data++; 173 | op->offset |= (*data++) << 8; 174 | break; 175 | } 176 | return data; 177 | } else { 178 | /* 179 | * Once again, specifies displacement size (this time 180 | * none, byte or *dword*), while specifies the base 181 | * register. Again, [EBP] is missing, replaced by a pure 182 | * disp32 (this time that's mod=0,rm=*5*). However, rm=4 183 | * indicates not a single base register, but instead the 184 | * presence of a SIB byte... 185 | */ 186 | op->indexreg = -1; 187 | switch (rm) { 188 | case 0: op->basereg = R_EAX; break; 189 | case 1: op->basereg = R_ECX; break; 190 | case 2: op->basereg = R_EDX; break; 191 | case 3: op->basereg = R_EBX; break; 192 | case 5: op->basereg = R_EBP; break; 193 | case 6: op->basereg = R_ESI; break; 194 | case 7: op->basereg = R_EDI; break; 195 | } 196 | if (rm == 5 && mod == 0) { 197 | op->basereg = -1; 198 | if (segsize != 32) 199 | op->addr_size = 32; 200 | mod = 2; /* fake disp32 */ 201 | } 202 | if (rm == 4) { /* process SIB */ 203 | scale = (*data >> 6) & 03; 204 | index = (*data >> 3) & 07; 205 | base = *data & 07; 206 | data++; 207 | 208 | op->scale = 1 << scale; 209 | switch (index) { 210 | case 0: op->indexreg = R_EAX; break; 211 | case 1: op->indexreg = R_ECX; break; 212 | case 2: op->indexreg = R_EDX; break; 213 | case 3: op->indexreg = R_EBX; break; 214 | case 4: op->indexreg = -1; break; 215 | case 5: op->indexreg = R_EBP; break; 216 | case 6: op->indexreg = R_ESI; break; 217 | case 7: op->indexreg = R_EDI; break; 218 | } 219 | 220 | switch (base) { 221 | case 0: op->basereg = R_EAX; break; 222 | case 1: op->basereg = R_ECX; break; 223 | case 2: op->basereg = R_EDX; break; 224 | case 3: op->basereg = R_EBX; break; 225 | case 4: op->basereg = R_ESP; break; 226 | case 6: op->basereg = R_ESI; break; 227 | case 7: op->basereg = R_EDI; break; 228 | case 5: 229 | if (mod == 0) { 230 | mod = 2; 231 | op->basereg = -1; 232 | } else 233 | op->basereg = R_EBP; 234 | break; 235 | } 236 | } 237 | switch (mod) { 238 | case 0: 239 | op->segment |= SEG_NODISP; 240 | break; 241 | case 1: 242 | op->segment |= SEG_DISP8; 243 | op->offset = (signed char) *data++; 244 | break; 245 | case 2: 246 | op->segment |= SEG_DISP32; 247 | op->offset = *data++; 248 | op->offset |= (*data++) << 8; 249 | op->offset |= ((long) *data++) << 16; 250 | op->offset |= ((long) *data++) << 24; 251 | break; 252 | } 253 | return data; 254 | } 255 | } 256 | 257 | /* 258 | * Determine whether the code string in r corresponds to the data 259 | * stream in data. Return the number of bytes matched if so. 260 | */ 261 | static int matches (unsigned char *r, unsigned char *data, int asize, 262 | int osize, int segsize, insn *ins) { 263 | unsigned char *origdata = data; 264 | int a_used = FALSE, o_used = FALSE; 265 | 266 | while (*r) { 267 | int c = *r++; 268 | if (c >= 01 && c <= 03) { 269 | while (c--) 270 | if (*r++ != *data++) 271 | return FALSE; 272 | } 273 | if (c == 04) { 274 | switch (*data++) { 275 | case 0x07: ins->oprs[0].basereg = 0; break; 276 | case 0x17: ins->oprs[0].basereg = 2; break; 277 | case 0x1F: ins->oprs[0].basereg = 3; break; 278 | default: return FALSE; 279 | } 280 | } 281 | if (c == 05) { 282 | switch (*data++) { 283 | case 0xA1: ins->oprs[0].basereg = 4; break; 284 | case 0xA9: ins->oprs[0].basereg = 5; break; 285 | default: return FALSE; 286 | } 287 | } 288 | if (c == 06) { 289 | switch (*data++) { 290 | case 0x06: ins->oprs[0].basereg = 0; break; 291 | case 0x0E: ins->oprs[0].basereg = 1; break; 292 | case 0x16: ins->oprs[0].basereg = 2; break; 293 | case 0x1E: ins->oprs[0].basereg = 3; break; 294 | default: return FALSE; 295 | } 296 | } 297 | if (c == 07) { 298 | switch (*data++) { 299 | case 0xA0: ins->oprs[0].basereg = 4; break; 300 | case 0xA8: ins->oprs[0].basereg = 5; break; 301 | default: return FALSE; 302 | } 303 | } 304 | if (c >= 010 && c <= 012) { 305 | int t = *r++, d = *data++; 306 | if (d < t || d > t+7) 307 | return FALSE; 308 | else { 309 | ins->oprs[c-010].basereg = d-t; 310 | ins->oprs[c-010].segment |= SEG_RMREG; 311 | } 312 | } 313 | if (c == 017) 314 | if (*data++) 315 | return FALSE; 316 | if (c >= 014 && c <= 016) { 317 | ins->oprs[c-014].offset = (signed char) *data++; 318 | ins->oprs[c-014].segment |= SEG_SIGNED; 319 | } 320 | if (c >= 020 && c <= 022) 321 | ins->oprs[c-020].offset = *data++; 322 | if (c >= 024 && c <= 026) 323 | ins->oprs[c-024].offset = *data++; 324 | if (c >= 030 && c <= 032) { 325 | ins->oprs[c-030].offset = *data++; 326 | ins->oprs[c-030].offset |= (*data++ << 8); 327 | } 328 | if (c >= 034 && c <= 036) { 329 | ins->oprs[c-034].offset = *data++; 330 | ins->oprs[c-034].offset |= (*data++ << 8); 331 | if (asize == 32) { 332 | ins->oprs[c-034].offset |= (((long) *data++) << 16); 333 | ins->oprs[c-034].offset |= (((long) *data++) << 24); 334 | } 335 | if (segsize != asize) 336 | ins->oprs[c-034].addr_size = asize; 337 | } 338 | if (c >= 040 && c <= 042) { 339 | ins->oprs[c-040].offset = *data++; 340 | ins->oprs[c-040].offset |= (*data++ << 8); 341 | ins->oprs[c-040].offset |= (((long) *data++) << 16); 342 | ins->oprs[c-040].offset |= (((long) *data++) << 24); 343 | } 344 | if (c >= 050 && c <= 052) { 345 | ins->oprs[c-050].offset = (signed char) *data++; 346 | ins->oprs[c-050].segment |= SEG_RELATIVE; 347 | } 348 | if (c >= 060 && c <= 062) { 349 | ins->oprs[c-060].offset = *data++; 350 | ins->oprs[c-060].offset |= (*data++ << 8); 351 | ins->oprs[c-060].segment |= SEG_RELATIVE; 352 | ins->oprs[c-060].segment &= ~SEG_32BIT; 353 | } 354 | if (c >= 064 && c <= 066) { 355 | ins->oprs[c-064].offset = *data++; 356 | ins->oprs[c-064].offset |= (*data++ << 8); 357 | if (asize == 32) { 358 | ins->oprs[c-064].offset |= (((long) *data++) << 16); 359 | ins->oprs[c-064].offset |= (((long) *data++) << 24); 360 | ins->oprs[c-064].segment |= SEG_32BIT; 361 | } else 362 | ins->oprs[c-064].segment &= ~SEG_32BIT; 363 | ins->oprs[c-064].segment |= SEG_RELATIVE; 364 | if (segsize != asize) 365 | ins->oprs[c-064].addr_size = asize; 366 | } 367 | if (c >= 070 && c <= 072) { 368 | ins->oprs[c-070].offset = *data++; 369 | ins->oprs[c-070].offset |= (*data++ << 8); 370 | ins->oprs[c-070].offset |= (((long) *data++) << 16); 371 | ins->oprs[c-070].offset |= (((long) *data++) << 24); 372 | ins->oprs[c-070].segment |= SEG_32BIT | SEG_RELATIVE; 373 | } 374 | if (c >= 0100 && c <= 0177) { 375 | int modrm = *data++; 376 | ins->oprs[c & 07].basereg = (modrm >> 3) & 07; 377 | ins->oprs[c & 07].segment |= SEG_RMREG; 378 | data = do_ea (data, modrm, asize, segsize, 379 | &ins->oprs[(c >> 3) & 07]); 380 | } 381 | if (c >= 0200 && c <= 0277) { 382 | int modrm = *data++; 383 | if (((modrm >> 3) & 07) != (c & 07)) 384 | return FALSE; /* spare field doesn't match up */ 385 | data = do_ea (data, modrm, asize, segsize, 386 | &ins->oprs[(c >> 3) & 07]); 387 | } 388 | if (c >= 0300 && c <= 0302) { 389 | if (asize) 390 | ins->oprs[c-0300].segment |= SEG_32BIT; 391 | else 392 | ins->oprs[c-0300].segment &= ~SEG_32BIT; 393 | a_used = TRUE; 394 | } 395 | if (c == 0310) { 396 | if (asize == 32) 397 | return FALSE; 398 | else 399 | a_used = TRUE; 400 | } 401 | if (c == 0311) { 402 | if (asize == 16) 403 | return FALSE; 404 | else 405 | a_used = TRUE; 406 | } 407 | if (c == 0312) { 408 | if (asize != segsize) 409 | return FALSE; 410 | else 411 | a_used = TRUE; 412 | } 413 | if (c == 0320) { 414 | if (osize == 32) 415 | return FALSE; 416 | else 417 | o_used = TRUE; 418 | } 419 | if (c == 0321) { 420 | if (osize == 16) 421 | return FALSE; 422 | else 423 | o_used = TRUE; 424 | } 425 | if (c == 0322) { 426 | if (osize != segsize) 427 | return FALSE; 428 | else 429 | o_used = TRUE; 430 | } 431 | if (c == 0330) { 432 | int t = *r++, d = *data++; 433 | if (d < t || d > t+15) 434 | return FALSE; 435 | else 436 | ins->condition = d - t; 437 | } 438 | } 439 | 440 | /* 441 | * Check for unused a/o prefixes. 442 | */ 443 | ins->nprefix = 0; 444 | if (!a_used && asize != segsize) 445 | ins->prefixes[ins->nprefix++] = (asize == 16 ? P_A16 : P_A32); 446 | if (!o_used && osize != segsize) 447 | ins->prefixes[ins->nprefix++] = (osize == 16 ? P_O16 : P_O32); 448 | 449 | return data - origdata; 450 | } 451 | 452 | long disasm (unsigned char *data, char *output, int segsize, long offset, 453 | int autosync, insn * ins_out) { 454 | struct itemplate **p; 455 | int length = 0; 456 | char *segover; 457 | int rep, lock, asize, osize, i, slen, colon; 458 | unsigned char *origdata; 459 | int works; 460 | insn ins; 461 | // int i; 462 | 463 | /* 464 | * Scan for prefixes. 465 | */ 466 | asize = osize = segsize; 467 | segover = NULL; 468 | rep = lock = 0; 469 | origdata = data; 470 | for (;;) { 471 | if (*data == 0xF3 || *data == 0xF2) 472 | rep = *data++; 473 | else if (*data == 0xF0) 474 | lock = *data++; 475 | else if (*data == 0x2E || *data == 0x36 || *data == 0x3E || 476 | *data == 0x26 || *data == 0x64 || *data == 0x65) { 477 | switch (*data++) { 478 | case 0x2E: segover = "cs"; break; 479 | case 0x36: segover = "ss"; break; 480 | case 0x3E: segover = "ds"; break; 481 | case 0x26: segover = "es"; break; 482 | case 0x64: segover = "fs"; break; 483 | case 0x65: segover = "gs"; break; 484 | } 485 | } else if (*data == 0x66) 486 | osize = 48 - segsize, data++; 487 | else if (*data == 0x67) 488 | asize = 48 - segsize, data++; 489 | else 490 | break; 491 | } 492 | 493 | ins.oprs[0].segment = ins.oprs[1].segment = ins.oprs[2].segment = 494 | ins.oprs[0].addr_size = ins.oprs[1].addr_size = ins.oprs[2].addr_size = 495 | (segsize == 16 ? 0 : SEG_32BIT); 496 | ins.condition = -1; 497 | works = TRUE; 498 | for (p = itable[*data]; *p; p++) 499 | if ( (length = matches((unsigned char *)((*p)->code), data, 500 | asize, osize, segsize, &ins)) ) { 501 | works = TRUE; 502 | /* 503 | * Final check to make sure the types of r/m match up. 504 | */ 505 | for (i = 0; i < (*p)->operands; i++) 506 | if ( 507 | 508 | /* If it's a mem-only EA but we have a register, die. */ 509 | ((ins.oprs[i].segment & SEG_RMREG) && 510 | !(MEMORY & ~(*p)->opd[i])) || 511 | 512 | /* If it's a reg-only EA but we have a memory ref, die. */ 513 | (!(ins.oprs[i].segment & SEG_RMREG) && 514 | !(REGNORM & ~(*p)->opd[i]) && 515 | !((*p)->opd[i] & REG_SMASK)) || 516 | 517 | /* Register type mismatch (eg FS vs REG_DESS): die. */ 518 | ((((*p)->opd[i] & (REGISTER | FPUREG)) || 519 | (ins.oprs[i].segment & SEG_RMREG)) && 520 | !whichreg ((*p)->opd[i], ins.oprs[i].basereg))) 521 | 522 | works = FALSE; 523 | if (works) 524 | break; 525 | } 526 | if (!length || !works) 527 | return 0; /* no instruction was matched */ 528 | 529 | slen = 0; 530 | 531 | if (rep) { 532 | slen += sprintf(output+slen, "rep%s ", 533 | (rep == 0xF2 ? "ne" : 534 | (*p)->opcode == I_CMPSB || 535 | (*p)->opcode == I_CMPSW || 536 | (*p)->opcode == I_CMPSD || 537 | (*p)->opcode == I_SCASB || 538 | (*p)->opcode == I_SCASW || 539 | (*p)->opcode == I_SCASD ? "e" : "")); 540 | } 541 | if (lock) 542 | slen += sprintf(output+slen, "lock "); 543 | for (i = 0; i < ins.nprefix; i++) 544 | switch (ins.prefixes[i]) { 545 | case P_A16: slen += sprintf(output+slen, "a16 "); break; 546 | case P_A32: slen += sprintf(output+slen, "a32 "); break; 547 | case P_O16: slen += sprintf(output+slen, "o16 "); break; 548 | case P_O32: slen += sprintf(output+slen, "o32 "); break; 549 | } 550 | 551 | ins.opcode = (*p)->opcode; 552 | 553 | for (i = 0; i < elements(ico); i++) 554 | if ((*p)->opcode == ico[i]) { 555 | slen += sprintf(output+slen, "%s%s", icn[i], 556 | whichcond(ins.condition)); 557 | break; 558 | } 559 | if (i >= elements(ico)) 560 | slen += sprintf(output+slen, "%s", insn_names[(*p)->opcode]); 561 | colon = FALSE; 562 | length += data - origdata; /* fix up for prefixes */ 563 | /*updata nprefix de l'instr*/ 564 | ins.nprefix = data - origdata; 565 | for (i=0; i<(*p)->operands; i++) { 566 | output[slen++] = (colon ? ':' : i==0 ? ' ' : ','); 567 | 568 | if (ins.oprs[i].segment & SEG_RELATIVE) { 569 | ins.oprs[i].offset += offset + length; 570 | /* 571 | * sort out wraparound 572 | */ 573 | if (!(ins.oprs[i].segment & SEG_32BIT)) 574 | ins.oprs[i].offset &= 0xFFFF; 575 | /* 576 | * add sync marker, if autosync is on 577 | */ 578 | if (autosync) 579 | /* add_sync (ins.oprs[i].offset, 0L)*/; 580 | } 581 | 582 | if ((*p)->opd[i] & COLON) 583 | colon = TRUE; 584 | else 585 | colon = FALSE; 586 | 587 | if (((*p)->opd[i] & (REGISTER | FPUREG)) || 588 | (ins.oprs[i].segment & SEG_RMREG)) { 589 | ins.oprs[i].basereg = whichreg ((*p)->opd[i], 590 | ins.oprs[i].basereg); 591 | slen += sprintf(output+slen, "%s", 592 | reg_names[ins.oprs[i].basereg-EXPR_REG_START]); 593 | } else if (!(UNITY & ~(*p)->opd[i])) { 594 | output[slen++] = '1'; 595 | } else if ( (*p)->opd[i] & IMMEDIATE ) { 596 | if ( (*p)->opd[i] & BITS8 ) { 597 | slen += sprintf(output+slen, "byte "); 598 | if (ins.oprs[i].segment & SEG_SIGNED) { 599 | if (ins.oprs[i].offset < 0) { 600 | ins.oprs[i].offset *= -1; 601 | output[slen++] = '-'; 602 | } else 603 | output[slen++] = '+'; 604 | } 605 | } else if ( (*p)->opd[i] & BITS16 ) { 606 | slen += sprintf(output+slen, "word "); 607 | } else if ( (*p)->opd[i] & BITS32 ) { 608 | slen += sprintf(output+slen, "dword "); 609 | } else if ( (*p)->opd[i] & NEAR ) { 610 | slen += sprintf(output+slen, "near "); 611 | } else if ( (*p)->opd[i] & SHORT ) { 612 | slen += sprintf(output+slen, "short "); 613 | } 614 | slen += sprintf(output+slen, "0x%lx", ins.oprs[i].offset); 615 | } else if ( !(MEM_OFFS & ~(*p)->opd[i]) ) { 616 | slen += sprintf(output+slen, "[%s%s%s0x%lx]", 617 | (segover ? segover : ""), 618 | (segover ? ":" : ""), 619 | (ins.oprs[i].addr_size == 32 ? "dword " : 620 | ins.oprs[i].addr_size == 16 ? "word " : ""), 621 | ins.oprs[i].offset); 622 | segover = NULL; 623 | } else if ( !(REGMEM & ~(*p)->opd[i]) ) { 624 | int started = FALSE; 625 | if ( (*p)->opd[i] & BITS8 ) 626 | slen += sprintf(output+slen, "byte "); 627 | if ( (*p)->opd[i] & BITS16 ) 628 | slen += sprintf(output+slen, "word "); 629 | if ( (*p)->opd[i] & BITS32 ) 630 | slen += sprintf(output+slen, "dword "); 631 | if ( (*p)->opd[i] & BITS64 ) 632 | slen += sprintf(output+slen, "qword "); 633 | if ( (*p)->opd[i] & BITS80 ) 634 | slen += sprintf(output+slen, "tword "); 635 | if ( (*p)->opd[i] & FAR ) 636 | slen += sprintf(output+slen, "far "); 637 | if ( (*p)->opd[i] & NEAR ) 638 | slen += sprintf(output+slen, "near "); 639 | output[slen++] = '['; 640 | if (ins.oprs[i].addr_size) 641 | slen += sprintf(output+slen, "%s", 642 | (ins.oprs[i].addr_size == 32 ? "dword " : 643 | ins.oprs[i].addr_size == 16 ? "word " : "")); 644 | if (segover) { 645 | slen += sprintf(output+slen, "%s:", segover); 646 | segover = NULL; 647 | } 648 | if (ins.oprs[i].basereg != -1) { 649 | slen += sprintf(output+slen, "%s", 650 | reg_names[(ins.oprs[i].basereg - 651 | EXPR_REG_START)]); 652 | started = TRUE; 653 | } 654 | if (ins.oprs[i].indexreg != -1) { 655 | if (started) 656 | output[slen++] = '+'; 657 | slen += sprintf(output+slen, "%s", 658 | reg_names[(ins.oprs[i].indexreg - 659 | EXPR_REG_START)]); 660 | if (ins.oprs[i].scale > 1) 661 | slen += sprintf(output+slen, "*%d", ins.oprs[i].scale); 662 | started = TRUE; 663 | } 664 | if (ins.oprs[i].segment & SEG_DISP8) { 665 | int sign = '+'; 666 | if (ins.oprs[i].offset & 0x80) { 667 | ins.oprs[i].offset = - (signed char) ins.oprs[i].offset; 668 | sign = '-'; 669 | } 670 | slen += sprintf(output+slen, "%c0x%lx", sign, 671 | ins.oprs[i].offset); 672 | } else if (ins.oprs[i].segment & SEG_DISP16) { 673 | if (started) 674 | output[slen++] = '+'; 675 | 676 | 677 | slen += sprintf(output+slen, "0x%lx", ins.oprs[i].offset); 678 | } else if (ins.oprs[i].segment & SEG_DISP32) { 679 | if (started) 680 | output[slen++] = '+'; 681 | slen += sprintf(output+slen, "0x%lx", ins.oprs[i].offset); 682 | } 683 | output[slen++] = ']'; 684 | } else { 685 | slen += sprintf(output+slen, "", i); 686 | } 687 | } 688 | output[slen] = '\0'; 689 | if (segover) { /* unused segment override */ 690 | char *p = output; 691 | int count = slen+1; 692 | while (count--) 693 | p[count+3] = p[count]; 694 | //strncpy (output, segover, 2); 695 | for (i=0;i<2;i++) 696 | { 697 | output[i] = output[i]; 698 | } 699 | 700 | output[2] = ' '; 701 | } 702 | *ins_out = ins; 703 | return length; 704 | } 705 | 706 | long eatbyte (unsigned char *data, char *output) { 707 | sprintf(output, "db 0x%02X", *data); 708 | return 1; 709 | } 710 | 711 | 712 | 713 | 714 | -------------------------------------------------------------------------------- /0.3/nasm.h: -------------------------------------------------------------------------------- 1 | /* nasm.h main header file for the Netwide Assembler: inter-module interface 2 | * 3 | * The Netwide Assembler is copyright (C) 1996 Simon Tatham and 4 | * Julian Hall. All rights reserved. The software is 5 | * redistributable under the licence given in the file "Licence" 6 | * distributed in the NASM archive. 7 | * 8 | * initial version: 27/iii/95 by Simon Tatham 9 | */ 10 | 11 | #ifndef NASM_NASM_H 12 | #define NASM_NASM_H 13 | 14 | #define NASM_MAJOR_VER 0 15 | #define NASM_MINOR_VER 97 16 | #define NASM_VER "0.97" 17 | 18 | #ifndef NULL 19 | #define NULL 0 20 | #endif 21 | 22 | #ifndef FALSE 23 | #define FALSE 0 /* comes in handy */ 24 | #endif 25 | #ifndef TRUE 26 | #define TRUE 1 27 | #endif 28 | 29 | #define NO_SEG -1L /* null segment value */ 30 | #define SEG_ABS 0x40000000L /* mask for far-absolute segments */ 31 | 32 | #ifndef FILENAME_MAX 33 | #define FILENAME_MAX 256 34 | #endif 35 | 36 | /* 37 | * Name pollution problems: on Digital UNIX pulls in some 38 | * strange hardware header file which sees fit to define R_SP. We 39 | * undefine it here so as not to break the enum below. 40 | */ 41 | #ifdef R_SP 42 | #undef R_SP 43 | #endif 44 | 45 | /* 46 | * We must declare the existence of this structure type up here, 47 | * since we have to reference it before we define it... 48 | */ 49 | struct ofmt; 50 | 51 | /* 52 | * ------------------------- 53 | * Error reporting functions 54 | * ------------------------- 55 | */ 56 | 57 | /* 58 | * An error reporting function should look like this. 59 | */ 60 | typedef void (*efunc) (int severity, char *fmt, ...); 61 | 62 | /* 63 | * These are the error severity codes which get passed as the first 64 | * argument to an efunc. 65 | */ 66 | 67 | #define ERR_WARNING 0 /* warn only: no further action */ 68 | #define ERR_NONFATAL 1 /* terminate assembly after phase */ 69 | #define ERR_FATAL 2 /* instantly fatal: exit with error */ 70 | #define ERR_PANIC 3 /* internal error: panic instantly 71 | * and dump core for reference */ 72 | #define ERR_MASK 0x0F /* mask off the above codes */ 73 | #define ERR_NOFILE 0x10 /* don't give source file name/line */ 74 | #define ERR_USAGE 0x20 /* print a usage message */ 75 | #define ERR_OFFBY1 0x40 /* report error as being on the line 76 | * we're just _about_ to read, not 77 | * the one we've just read */ 78 | #define ERR_PASS1 0x80 /* only print this error on pass one */ 79 | 80 | /* 81 | * These codes define specific types of suppressible warning. 82 | */ 83 | #define ERR_WARN_MNP 0x0100 /* macro-num-parameters warning */ 84 | #define ERR_WARN_OL 0x0200 /* orphan label (no colon, and 85 | * alone on line) */ 86 | #define ERR_WARN_NOV 0x0300 /* numeric overflow */ 87 | #define ERR_WARN_MASK 0xFF00 /* the mask for this feature */ 88 | #define ERR_WARN_SHR 8 /* how far to shift right */ 89 | #define ERR_WARN_MAX 3 /* the highest numbered one */ 90 | 91 | /* 92 | * ----------------------- 93 | * Other function typedefs 94 | * ----------------------- 95 | */ 96 | 97 | /* 98 | * A label-lookup function should look like this. 99 | */ 100 | typedef int (*lfunc) (char *label, long *segment, long *offset); 101 | 102 | /* 103 | * And a label-definition function like this. The boolean parameter 104 | * `is_norm' states whether the label is a `normal' label (which 105 | * should affect the local-label system), or something odder like 106 | * an EQU or a segment-base symbol, which shouldn't. 107 | */ 108 | typedef void (*ldfunc) (char *label, long segment, long offset, char *special, 109 | int is_norm, int isextrn, struct ofmt *ofmt, 110 | efunc error); 111 | 112 | /* 113 | * List-file generators should look like this: 114 | */ 115 | typedef struct { 116 | /* 117 | * Called to initialise the listing file generator. Before this 118 | * is called, the other routines will silently do nothing when 119 | * called. The `char *' parameter is the file name to write the 120 | * listing to. 121 | */ 122 | void (*init) (char *, efunc); 123 | 124 | /* 125 | * Called to clear stuff up and close the listing file. 126 | */ 127 | void (*cleanup) (void); 128 | 129 | /* 130 | * Called to output binary data. Parameters are: the offset; 131 | * the data; the data type. Data types are similar to the 132 | * output-format interface, only OUT_ADDRESS will _always_ be 133 | * displayed as if it's relocatable, so ensure that any non- 134 | * relocatable address has been converted to OUT_RAWDATA by 135 | * then. Note that OUT_RAWDATA+0 is a valid data type, and is a 136 | * dummy call used to give the listing generator an offset to 137 | * work with when doing things like uplevel(LIST_TIMES) or 138 | * uplevel(LIST_INCBIN). 139 | */ 140 | void (*output) (long, void *, unsigned long); 141 | 142 | /* 143 | * Called to send a text line to the listing generator. The 144 | * `int' parameter is LIST_READ or LIST_MACRO depending on 145 | * whether the line came directly from an input file or is the 146 | * result of a multi-line macro expansion. 147 | */ 148 | void (*line) (int, char *); 149 | 150 | /* 151 | * Called to change one of the various levelled mechanisms in 152 | * the listing generator. LIST_INCLUDE and LIST_MACRO can be 153 | * used to increase the nesting level of include files and 154 | * macro expansions; LIST_TIMES and LIST_INCBIN switch on the 155 | * two binary-output-suppression mechanisms for large-scale 156 | * pseudo-instructions. 157 | * 158 | * LIST_MACRO_NOLIST is synonymous with LIST_MACRO except that 159 | * it indicates the beginning of the expansion of a `nolist' 160 | * macro, so anything under that level won't be expanded unless 161 | * it includes another file. 162 | */ 163 | void (*uplevel) (int); 164 | 165 | /* 166 | * Reverse the effects of uplevel. 167 | */ 168 | void (*downlevel) (int); 169 | } ListGen; 170 | 171 | /* 172 | * The expression evaluator must be passed a scanner function; a 173 | * standard scanner is provided as part of nasmlib.c. The 174 | * preprocessor will use a different one. Scanners, and the 175 | * token-value structures they return, look like this. 176 | * 177 | * The return value from the scanner is always a copy of the 178 | * `t_type' field in the structure. 179 | */ 180 | struct tokenval { 181 | int t_type; 182 | long t_integer, t_inttwo; 183 | char *t_charptr; 184 | }; 185 | typedef int (*scanner) (void *private_data, struct tokenval *tv); 186 | 187 | /* 188 | * Token types returned by the scanner, in addition to ordinary 189 | * ASCII character values, and zero for end-of-string. 190 | */ 191 | enum { /* token types, other than chars */ 192 | TOKEN_INVALID = -1, /* a placeholder value */ 193 | TOKEN_EOS = 0, /* end of string */ 194 | TOKEN_EQ = '=', TOKEN_GT = '>', TOKEN_LT = '<', /* aliases */ 195 | TOKEN_ID = 256, TOKEN_NUM, TOKEN_REG, TOKEN_INSN, /* major token types */ 196 | TOKEN_ERRNUM, /* numeric constant with error in */ 197 | TOKEN_HERE, TOKEN_BASE, /* $ and $$ */ 198 | TOKEN_SPECIAL, /* BYTE, WORD, DWORD, FAR, NEAR, etc */ 199 | TOKEN_PREFIX, /* A32, O16, LOCK, REPNZ, TIMES, etc */ 200 | TOKEN_SHL, TOKEN_SHR, /* << and >> */ 201 | TOKEN_SDIV, TOKEN_SMOD, /* // and %% */ 202 | TOKEN_GE, TOKEN_LE, TOKEN_NE, /* >=, <= and <> (!= is same as <>) */ 203 | TOKEN_DBL_AND, TOKEN_DBL_OR, TOKEN_DBL_XOR, /* &&, || and ^^ */ 204 | TOKEN_SEG, TOKEN_WRT, /* SEG and WRT */ 205 | TOKEN_FLOAT /* floating-point constant */ 206 | }; 207 | 208 | /* 209 | * Expression-evaluator datatype. Expressions, within the 210 | * evaluator, are stored as an array of these beasts, terminated by 211 | * a record with type==0. Mostly, it's a vector type: each type 212 | * denotes some kind of a component, and the value denotes the 213 | * multiple of that component present in the expression. The 214 | * exception is the WRT type, whose `value' field denotes the 215 | * segment to which the expression is relative. These segments will 216 | * be segment-base types, i.e. either odd segment values or SEG_ABS 217 | * types. So it is still valid to assume that anything with a 218 | * `value' field of zero is insignificant. 219 | */ 220 | typedef struct { 221 | long type; /* a register, or EXPR_xxx */ 222 | long value; /* must be >= 32 bits */ 223 | } expr; 224 | 225 | /* 226 | * The evaluator can also return hints about which of two registers 227 | * used in an expression should be the base register. See also the 228 | * `operand' structure. 229 | */ 230 | struct eval_hints { 231 | int base; 232 | int type; 233 | }; 234 | 235 | /* 236 | * The actual expression evaluator function looks like this. When 237 | * called, it expects the first token of its expression to already 238 | * be in `*tv'; if it is not, set tv->t_type to TOKEN_INVALID and 239 | * it will start by calling the scanner. 240 | * 241 | * If a forward reference happens during evaluation, the evaluator 242 | * must set `*fwref' to TRUE if `fwref' is non-NULL. 243 | * 244 | * `critical' is non-zero if the expression may not contain forward 245 | * references. The evaluator will report its own error if this 246 | * occurs; if `critical' is 1, the error will be "symbol not 247 | * defined before use", whereas if `critical' is 2, the error will 248 | * be "symbol undefined". 249 | * 250 | * If `critical' has bit 4 set (in addition to its main value: 0x11 251 | * and 0x12 correspond to 1 and 2) then an extended expression 252 | * syntax is recognised, in which relational operators such as =, < 253 | * and >= are accepted, as well as low-precedence logical operators 254 | * &&, ^^ and ||. 255 | * 256 | * If `hints' is non-NULL, it gets filled in with some hints as to 257 | * the base register in complex effective addresses. 258 | */ 259 | typedef expr *(*evalfunc) (scanner sc, void *scprivate, struct tokenval *tv, 260 | int *fwref, int critical, efunc error, 261 | struct eval_hints *hints); 262 | 263 | /* 264 | * There's also an auxiliary routine through which the evaluator 265 | * needs to hear about the value of $ and the label (if any) 266 | * defined on the current line. 267 | */ 268 | typedef void (*evalinfofunc) (char *labelname, long segment, long offset); 269 | 270 | /* 271 | * Special values for expr->type. ASSUMPTION MADE HERE: the number 272 | * of distinct register names (i.e. possible "type" fields for an 273 | * expr structure) does not exceed 124 (EXPR_REG_START through 274 | * EXPR_REG_END). 275 | */ 276 | #define EXPR_REG_START 1 277 | #define EXPR_REG_END 124 278 | #define EXPR_UNKNOWN 125L /* for forward references */ 279 | #define EXPR_SIMPLE 126L 280 | #define EXPR_WRT 127L 281 | #define EXPR_SEGBASE 128L 282 | 283 | /* 284 | * Preprocessors ought to look like this: 285 | */ 286 | typedef struct { 287 | /* 288 | * Called at the start of a pass; given a file name, the number 289 | * of the pass, an error reporting function, an evaluator 290 | * function, and a listing generator to talk to. 291 | */ 292 | void (*reset) (char *, int, efunc, evalfunc, ListGen *); 293 | 294 | /* 295 | * Called to fetch a line of preprocessed source. The line 296 | * returned has been malloc'ed, and so should be freed after 297 | * use. 298 | */ 299 | char *(*getline) (void); 300 | 301 | /* 302 | * Called at the end of a pass. 303 | */ 304 | void (*cleanup) (void); 305 | } Preproc; 306 | 307 | /* 308 | * ---------------------------------------------------------------- 309 | * Some lexical properties of the NASM source language, included 310 | * here because they are shared between the parser and preprocessor 311 | * ---------------------------------------------------------------- 312 | */ 313 | 314 | /* isidstart matches any character that may start an identifier, and isidchar 315 | * matches any character that may appear at places other than the start of an 316 | * identifier. E.g. a period may only appear at the start of an identifier 317 | * (for local labels), whereas a number may appear anywhere *but* at the 318 | * start. */ 319 | 320 | #define isidstart(c) ( isalpha(c) || (c)=='_' || (c)=='.' || (c)=='?' || (c)=='@' ) 321 | 322 | #define isidchar(c) ( isidstart(c) || isdigit(c) || (c)=='$' || (c)=='#' || (c)=='~' ) 323 | 324 | 325 | /* Ditto for numeric constants. */ 326 | 327 | #define isnumstart(c) ( isdigit(c) || (c)=='$' ) 328 | #define isnumchar(c) ( isalnum(c) ) 329 | 330 | /* This returns the numeric value of a given 'digit'. */ 331 | 332 | #define numvalue(c) ((c)>='a' ? (c)-'a'+10 : (c)>='A' ? (c)-'A'+10 : (c)-'0') 333 | 334 | /* 335 | * Data-type flags that get passed to listing-file routines. 336 | */ 337 | enum { 338 | LIST_READ, LIST_MACRO, LIST_MACRO_NOLIST, LIST_INCLUDE, 339 | LIST_INCBIN, LIST_TIMES 340 | }; 341 | 342 | /* 343 | * ----------------------------------------------------------- 344 | * Format of the `insn' structure returned from `parser.c' and 345 | * passed into `assemble.c' 346 | * ----------------------------------------------------------- 347 | */ 348 | 349 | /* 350 | * Here we define the operand types. These are implemented as bit 351 | * masks, since some are subsets of others; e.g. AX in a MOV 352 | * instruction is a special operand type, whereas AX in other 353 | * contexts is just another 16-bit register. (Also, consider CL in 354 | * shift instructions, DX in OUT, etc.) 355 | */ 356 | 357 | /* size, and other attributes, of the operand */ 358 | #define BITS8 0x00000001L 359 | #define BITS16 0x00000002L 360 | #define BITS32 0x00000004L 361 | #define BITS64 0x00000008L /* FPU only */ 362 | #define BITS80 0x00000010L /* FPU only */ 363 | #define FAR 0x00000020L /* grotty: this means 16:16 or */ 364 | /* 16:32, like in CALL/JMP */ 365 | #define NEAR 0x00000040L 366 | #define SHORT 0x00000080L /* and this means what it says :) */ 367 | 368 | #define SIZE_MASK 0x000000FFL /* all the size attributes */ 369 | #define NON_SIZE (~SIZE_MASK) 370 | 371 | #define TO 0x00000100L /* reverse effect in FADD, FSUB &c */ 372 | #define COLON 0x00000200L /* operand is followed by a colon */ 373 | 374 | /* type of operand: memory reference, register, etc. */ 375 | #define MEMORY 0x00204000L 376 | #define REGISTER 0x00001000L /* register number in 'basereg' */ 377 | #define IMMEDIATE 0x00002000L 378 | 379 | #define REGMEM 0x00200000L /* for r/m, ie EA, operands */ 380 | #define REGNORM 0x00201000L /* 'normal' reg, qualifies as EA */ 381 | #define REG8 0x00201001L 382 | #define REG16 0x00201002L 383 | #define REG32 0x00201004L 384 | #define MMXREG 0x00201008L /* MMX registers */ 385 | #define FPUREG 0x01000000L /* floating point stack registers */ 386 | #define FPU0 0x01000800L /* FPU stack register zero */ 387 | 388 | /* special register operands: these may be treated differently */ 389 | #define REG_SMASK 0x00070000L /* a mask for the following */ 390 | #define REG_ACCUM 0x00211000L /* accumulator: AL, AX or EAX */ 391 | #define REG_AL 0x00211001L /* REG_ACCUM | BITSxx */ 392 | #define REG_AX 0x00211002L /* ditto */ 393 | #define REG_EAX 0x00211004L /* and again */ 394 | #define REG_COUNT 0x00221000L /* counter: CL, CX or ECX */ 395 | #define REG_CL 0x00221001L /* REG_COUNT | BITSxx */ 396 | #define REG_CX 0x00221002L /* ditto */ 397 | #define REG_ECX 0x00221004L /* another one */ 398 | #define REG_DX 0x00241002L 399 | #define REG_SREG 0x00081002L /* any segment register */ 400 | #define REG_CS 0x01081002L /* CS */ 401 | #define REG_DESS 0x02081002L /* DS, ES, SS (non-CS 86 registers) */ 402 | #define REG_FSGS 0x04081002L /* FS, GS (386 extended registers) */ 403 | #define REG_CDT 0x00101004L /* CRn, DRn and TRn */ 404 | #define REG_CREG 0x08101004L /* CRn */ 405 | #define REG_CR4 0x08101404L /* CR4 (Pentium only) */ 406 | #define REG_DREG 0x10101004L /* DRn */ 407 | #define REG_TREG 0x20101004L /* TRn */ 408 | 409 | /* special type of EA */ 410 | #define MEM_OFFS 0x00604000L /* simple [address] offset */ 411 | 412 | /* special type of immediate operand */ 413 | #define ONENESS 0x00800000L /* so UNITY == IMMEDIATE | ONENESS */ 414 | #define UNITY 0x00802000L /* for shift/rotate instructions */ 415 | 416 | /* 417 | * Next, the codes returned from the parser, for registers and 418 | * instructions. 419 | */ 420 | 421 | enum { /* register names */ 422 | R_AH = EXPR_REG_START, R_AL, R_AX, R_BH, R_BL, R_BP, R_BX, R_CH, 423 | R_CL, R_CR0, R_CR2, R_CR3, R_CR4, R_CS, R_CX, R_DH, R_DI, R_DL, 424 | R_DR0, R_DR1, R_DR2, R_DR3, R_DR6, R_DR7, R_DS, R_DX, R_EAX, 425 | R_EBP, R_EBX, R_ECX, R_EDI, R_EDX, R_ES, R_ESI, R_ESP, R_FS, 426 | R_GS, R_MM0, R_MM1, R_MM2, R_MM3, R_MM4, R_MM5, R_MM6, R_MM7, 427 | R_SI, R_SP, R_SS, R_ST0, R_ST1, R_ST2, R_ST3, R_ST4, R_ST5, 428 | R_ST6, R_ST7, R_TR3, R_TR4, R_TR5, R_TR6, R_TR7, REG_ENUM_LIMIT 429 | }; 430 | 431 | enum { /* instruction names */ 432 | I_AAA, I_AAD, I_AAM, I_AAS, I_ADC, I_ADD, I_AND, I_ARPL, 433 | I_BOUND, I_BSF, I_BSR, I_BSWAP, I_BT, I_BTC, I_BTR, I_BTS, 434 | I_CALL, I_CBW, I_CDQ, I_CLC, I_CLD, I_CLI, I_CLTS, I_CMC, I_CMP, 435 | I_CMPSB, I_CMPSD, I_CMPSW, I_CMPXCHG, I_CMPXCHG486, I_CMPXCHG8B, 436 | I_CPUID, I_CWD, I_CWDE, I_DAA, I_DAS, I_DB, I_DD, I_DEC, I_DIV, 437 | I_DQ, I_DT, I_DW, I_EMMS, I_ENTER, I_EQU, I_F2XM1, I_FABS, 438 | I_FADD, I_FADDP, I_FBLD, I_FBSTP, I_FCHS, I_FCLEX, I_FCMOVB, 439 | I_FCMOVBE, I_FCMOVE, I_FCMOVNB, I_FCMOVNBE, I_FCMOVNE, 440 | I_FCMOVNU, I_FCMOVU, I_FCOM, I_FCOMI, I_FCOMIP, I_FCOMP, 441 | I_FCOMPP, I_FCOS, I_FDECSTP, I_FDISI, I_FDIV, I_FDIVP, I_FDIVR, 442 | I_FDIVRP, I_FENI, I_FFREE, I_FIADD, I_FICOM, I_FICOMP, I_FIDIV, 443 | I_FIDIVR, I_FILD, I_FIMUL, I_FINCSTP, I_FINIT, I_FIST, I_FISTP, 444 | I_FISUB, I_FISUBR, I_FLD, I_FLD1, I_FLDCW, I_FLDENV, I_FLDL2E, 445 | I_FLDL2T, I_FLDLG2, I_FLDLN2, I_FLDPI, I_FLDZ, I_FMUL, I_FMULP, 446 | I_FNCLEX, I_FNDISI, I_FNENI, I_FNINIT, I_FNOP, I_FNSAVE, 447 | I_FNSTCW, I_FNSTENV, I_FNSTSW, I_FPATAN, I_FPREM, I_FPREM1, 448 | I_FPTAN, I_FRNDINT, I_FRSTOR, I_FSAVE, I_FSCALE, I_FSETPM, 449 | I_FSIN, I_FSINCOS, I_FSQRT, I_FST, I_FSTCW, I_FSTENV, I_FSTP, 450 | I_FSTSW, I_FSUB, I_FSUBP, I_FSUBR, I_FSUBRP, I_FTST, I_FUCOM, 451 | I_FUCOMI, I_FUCOMIP, I_FUCOMP, I_FUCOMPP, I_FXAM, I_FXCH, 452 | I_FXTRACT, I_FYL2X, I_FYL2XP1, I_HLT, I_IBTS, I_ICEBP, I_IDIV, 453 | I_IMUL, I_IN, I_INC, I_INCBIN, I_INSB, I_INSD, I_INSW, I_INT, 454 | I_INT1, I_INT01, I_INT3, I_INTO, I_INVD, I_INVLPG, I_IRET, 455 | I_IRETD, I_IRETW, I_JCXZ, I_JECXZ, I_JMP, I_LAHF, I_LAR, I_LDS, 456 | I_LEA, I_LEAVE, I_LES, I_LFS, I_LGDT, I_LGS, I_LIDT, I_LLDT, 457 | I_LMSW, I_LOADALL, I_LOADALL286, I_LODSB, I_LODSD, I_LODSW, 458 | I_LOOP, I_LOOPE, I_LOOPNE, I_LOOPNZ, I_LOOPZ, I_LSL, I_LSS, 459 | I_LTR, I_MOV, I_MOVD, I_MOVQ, I_MOVSB, I_MOVSD, I_MOVSW, 460 | I_MOVSX, I_MOVZX, I_MUL, I_NEG, I_NOP, I_NOT, I_OR, I_OUT, 461 | I_OUTSB, I_OUTSD, I_OUTSW, I_PACKSSDW, I_PACKSSWB, I_PACKUSWB, 462 | I_PADDB, I_PADDD, I_PADDSB, I_PADDSIW, I_PADDSW, I_PADDUSB, 463 | I_PADDUSW, I_PADDW, I_PAND, I_PANDN, I_PAVEB, I_PCMPEQB, 464 | I_PCMPEQD, I_PCMPEQW, I_PCMPGTB, I_PCMPGTD, I_PCMPGTW, 465 | I_PDISTIB, I_PMACHRIW, I_PMADDWD, I_PMAGW, I_PMULHRW, 466 | I_PMULHRIW, I_PMULHW, I_PMULLW, I_PMVGEZB, I_PMVLZB, I_PMVNZB, 467 | I_PMVZB, I_POP, I_POPA, I_POPAD, I_POPAW, I_POPF, I_POPFD, 468 | I_POPFW, I_POR, I_PSLLD, I_PSLLQ, I_PSLLW, I_PSRAD, I_PSRAW, 469 | I_PSRLD, I_PSRLQ, I_PSRLW, I_PSUBB, I_PSUBD, I_PSUBSB, 470 | I_PSUBSIW, I_PSUBSW, I_PSUBUSB, I_PSUBUSW, I_PSUBW, I_PUNPCKHBW, 471 | I_PUNPCKHDQ, I_PUNPCKHWD, I_PUNPCKLBW, I_PUNPCKLDQ, I_PUNPCKLWD, 472 | I_PUSH, I_PUSHA, I_PUSHAD, I_PUSHAW, I_PUSHF, I_PUSHFD, 473 | I_PUSHFW, I_PXOR, I_RCL, I_RCR, I_RDMSR, I_RDPMC, I_RDTSC, 474 | I_RESB, I_RESD, I_RESQ, I_REST, I_RESW, I_RET, I_RETF, I_RETN, 475 | I_ROL, I_ROR, I_RSM, I_SAHF, I_SAL, I_SALC, I_SAR, I_SBB, 476 | I_SCASB, I_SCASD, I_SCASW, I_SGDT, I_SHL, I_SHLD, I_SHR, I_SHRD, 477 | I_SIDT, I_SLDT, I_SMI, I_SMSW, I_STC, I_STD, I_STI, I_STOSB, 478 | I_STOSD, I_STOSW, I_STR, I_SUB, I_TEST, I_UMOV, I_VERR, I_VERW, 479 | I_WAIT, I_WBINVD, I_WRMSR, I_XADD, I_XBTS, I_XCHG, I_XLATB, 480 | I_XOR, I_CMOVcc, I_Jcc, I_SETcc 481 | }; 482 | 483 | enum { /* condition code names */ 484 | C_A, C_AE, C_B, C_BE, C_C, C_E, C_G, C_GE, C_L, C_LE, C_NA, C_NAE, 485 | C_NB, C_NBE, C_NC, C_NE, C_NG, C_NGE, C_NL, C_NLE, C_NO, C_NP, 486 | C_NS, C_NZ, C_O, C_P, C_PE, C_PO, C_S, C_Z 487 | }; 488 | 489 | /* 490 | * Note that because segment registers may be used as instruction 491 | * prefixes, we must ensure the enumerations for prefixes and 492 | * register names do not overlap. 493 | */ 494 | enum { /* instruction prefixes */ 495 | PREFIX_ENUM_START = REG_ENUM_LIMIT, 496 | P_A16 = PREFIX_ENUM_START, P_A32, P_LOCK, P_O16, P_O32, P_REP, P_REPE, 497 | P_REPNE, P_REPNZ, P_REPZ, P_TIMES 498 | }; 499 | 500 | enum { /* extended operand types */ 501 | EOT_NOTHING, EOT_DB_STRING, EOT_DB_NUMBER 502 | }; 503 | 504 | enum { /* special EA flags */ 505 | EAF_BYTEOFFS = 1, /* force offset part to byte size */ 506 | EAF_WORDOFFS = 2, /* force offset part to [d]word size */ 507 | EAF_TIMESTWO = 4 /* really do EAX*2 not EAX+EAX */ 508 | }; 509 | 510 | enum { /* values for `hinttype' */ 511 | EAH_NOHINT = 0, /* no hint at all - our discretion */ 512 | EAH_MAKEBASE = 1, /* try to make given reg the base */ 513 | EAH_NOTBASE = 2 /* try _not_ to make reg the base */ 514 | }; 515 | 516 | typedef struct { /* operand to an instruction */ 517 | long type; /* type of operand */ 518 | int addr_size; /* 0 means default; 16; 32 */ 519 | int basereg, indexreg, scale; /* registers and scale involved */ 520 | int hintbase, hinttype; /* hint as to real base register */ 521 | long segment; /* immediate segment, if needed */ 522 | long offset; /* any immediate number */ 523 | long wrt; /* segment base it's relative to */ 524 | int eaflags; /* special EA flags */ 525 | } operand; 526 | 527 | typedef struct extop { /* extended operand */ 528 | struct extop *next; /* linked list */ 529 | long type; /* defined above */ 530 | char *stringval; /* if it's a string, then here it is */ 531 | int stringlen; /* ... and here's how long it is */ 532 | long segment; /* if it's a number/address, then... */ 533 | long offset; /* ... it's given here ... */ 534 | long wrt; /* ... and here */ 535 | } extop; 536 | 537 | #define MAXPREFIX 4 538 | 539 | typedef struct { /* an instruction itself */ 540 | char *label; /* the label defined, or NULL */ 541 | int prefixes[MAXPREFIX]; /* instruction prefixes, if any */ 542 | int nprefix; /* number of entries in above */ 543 | int opcode; /* the opcode - not just the string */ 544 | int condition; /* the condition code, if Jcc/SETcc */ 545 | int operands; /* how many operands? 0-3 */ 546 | operand oprs[3]; /* the operands, defined as above */ 547 | extop *eops; /* extended operands */ 548 | long times; /* repeat count (TIMES prefix) */ 549 | int forw_ref; /* is there a forward reference? */ 550 | } insn; 551 | 552 | /* 553 | * ------------------------------------------------------------ 554 | * The data structure defining an output format driver, and the 555 | * interfaces to the functions therein. 556 | * ------------------------------------------------------------ 557 | */ 558 | 559 | struct ofmt { 560 | /* 561 | * This is a short (one-liner) description of the type of 562 | * output generated by the driver. 563 | */ 564 | char *fullname; 565 | 566 | /* 567 | * This is a single keyword used to select the driver. 568 | */ 569 | char *shortname; 570 | 571 | /* 572 | * This, if non-NULL, is a NULL-terminated list of `char *'s 573 | * pointing to extra standard macros supplied by the object 574 | * format (e.g. a sensible initial default value of __SECT__, 575 | * and user-level equivalents for any format-specific 576 | * directives). 577 | */ 578 | 579 | char **stdmac; 580 | 581 | /* 582 | * This procedure is called at the start of an output session. 583 | * It tells the output format what file it will be writing to, 584 | * what routine to report errors through, and how to interface 585 | * to the label manager and expression evaluator if necessary. 586 | * It also gives it a chance to do other initialisation. 587 | */ 588 | 589 | /***** OJO MODIFICACION DEL TEXTO ORIGINAL 590 | YA QUE UTILIZA DEFINES DE STDIO.H *******/ 591 | 592 | /* void (*init) (FILE *fp, efunc error, ldfunc ldef, evalfunc eval); */ 593 | 594 | 595 | /* 596 | * This procedure is called by assemble() to write actual 597 | * generated code or data to the object file. Typically it 598 | * doesn't have to actually _write_ it, just store it for 599 | * later. 600 | * 601 | * The `type' argument specifies the type of output data, and 602 | * usually the size as well: its contents are described below. 603 | */ 604 | void (*output) (long segto, void *data, unsigned long type, 605 | long segment, long wrt); 606 | 607 | /* 608 | * This procedure is called once for every symbol defined in 609 | * the module being assembled. It gives the name and value of 610 | * the symbol, in NASM's terms, and indicates whether it has 611 | * been declared to be global. Note that the parameter "name", 612 | * when passed, will point to a piece of static storage 613 | * allocated inside the label manager - it's safe to keep using 614 | * that pointer, because the label manager doesn't clean up 615 | * until after the output driver has. 616 | * 617 | * Values of `is_global' are: 0 means the symbol is local; 1 618 | * means the symbol is global; 2 means the symbol is common (in 619 | * which case `offset' holds the _size_ of the variable). 620 | * Anything else is available for the output driver to use 621 | * internally. 622 | * 623 | * This routine explicitly _is_ allowed to call the label 624 | * manager to define further symbols, if it wants to, even 625 | * though it's been called _from_ the label manager. That much 626 | * re-entrancy is guaranteed in the label manager. However, the 627 | * label manager will in turn call this routine, so it should 628 | * be prepared to be re-entrant itself. 629 | * 630 | * The `special' parameter contains special information passed 631 | * through from the command that defined the label: it may have 632 | * been an EXTERN, a COMMON or a GLOBAL. The distinction should 633 | * be obvious to the output format from the other parameters. 634 | */ 635 | void (*symdef) (char *name, long segment, long offset, int is_global, 636 | char *special); 637 | 638 | /* 639 | * This procedure is called when the source code requests a 640 | * segment change. It should return the corresponding segment 641 | * _number_ for the name, or NO_SEG if the name is not a valid 642 | * segment name. 643 | * 644 | * It may also be called with NULL, in which case it is to 645 | * return the _default_ section number for starting assembly in. 646 | * 647 | * It is allowed to modify the string it is given a pointer to. 648 | * 649 | * It is also allowed to specify a default instruction size for 650 | * the segment, by setting `*bits' to 16 or 32. Or, if it 651 | * doesn't wish to define a default, it can leave `bits' alone. 652 | */ 653 | long (*section) (char *name, int pass, int *bits); 654 | 655 | /* 656 | * This procedure is called to modify the segment base values 657 | * returned from the SEG operator. It is given a segment base 658 | * value (i.e. a segment value with the low bit set), and is 659 | * required to produce in return a segment value which may be 660 | * different. It can map segment bases to absolute numbers by 661 | * means of returning SEG_ABS types. 662 | * 663 | * It should return NO_SEG if the segment base cannot be 664 | * determined; the evaluator (which calls this routine) is 665 | * responsible for throwing an error condition if that occurs 666 | * in pass two or in a critical expression. 667 | */ 668 | long (*segbase) (long segment); 669 | 670 | /* 671 | * This procedure is called to allow the output driver to 672 | * process its own specific directives. When called, it has the 673 | * directive word in `directive' and the parameter string in 674 | * `value'. It is called in both assembly passes, and `pass' 675 | * will be either 1 or 2. 676 | * 677 | * This procedure should return zero if it does not _recognise_ 678 | * the directive, so that the main program can report an error. 679 | * If it recognises the directive but then has its own errors, 680 | * it should report them itself and then return non-zero. It 681 | * should also return non-zero if it correctly processes the 682 | * directive. 683 | */ 684 | int (*directive) (char *directive, char *value, int pass); 685 | 686 | /* 687 | * This procedure is called before anything else - even before 688 | * the "init" routine - and is passed the name of the input 689 | * file from which this output file is being generated. It 690 | * should return its preferred name for the output file in 691 | * `outname', if outname[0] is not '\0', and do nothing to 692 | * `outname' otherwise. Since it is called before the driver is 693 | * properly initialised, it has to be passed its error handler 694 | * separately. 695 | * 696 | * This procedure may also take its own copy of the input file 697 | * name for use in writing the output file: it is _guaranteed_ 698 | * that it will be called before the "init" routine. 699 | * 700 | * The parameter `outname' points to an area of storage 701 | * guaranteed to be at least FILENAME_MAX in size. 702 | */ 703 | void (*filename) (char *inname, char *outname, efunc error); 704 | 705 | /* 706 | * This procedure is called after assembly finishes, to allow 707 | * the output driver to clean itself up and free its memory. 708 | * Typically, it will also be the point at which the object 709 | * file actually gets _written_. 710 | * 711 | * One thing the cleanup routine should always do is to close 712 | * the output file pointer. 713 | */ 714 | void (*cleanup) (void); 715 | }; 716 | 717 | /* 718 | * values for the `type' parameter to an output function. Each one 719 | * must have the actual number of _bytes_ added to it. 720 | * 721 | * Exceptions are OUT_RELxADR, which denote an x-byte relocation 722 | * which will be a relative jump. For this we need to know the 723 | * distance in bytes from the start of the relocated record until 724 | * the end of the containing instruction. _This_ is what is stored 725 | * in the size part of the parameter, in this case. 726 | * 727 | * Also OUT_RESERVE denotes reservation of N bytes of BSS space, 728 | * and the contents of the "data" parameter is irrelevant. 729 | * 730 | * The "data" parameter for the output function points to a "long", 731 | * containing the address in question, unless the type is 732 | * OUT_RAWDATA, in which case it points to an "unsigned char" 733 | * array. 734 | */ 735 | #define OUT_RAWDATA 0x00000000UL 736 | #define OUT_ADDRESS 0x10000000UL 737 | #define OUT_REL2ADR 0x20000000UL 738 | #define OUT_REL4ADR 0x30000000UL 739 | #define OUT_RESERVE 0x40000000UL 740 | #define OUT_TYPMASK 0xF0000000UL 741 | #define OUT_SIZMASK 0x0FFFFFFFUL 742 | 743 | /* 744 | * ----- 745 | * Other 746 | * ----- 747 | */ 748 | 749 | /* 750 | * This is a useful #define which I keep meaning to use more often: 751 | * the number of elements of a statically defined array. 752 | */ 753 | 754 | #define elements(x) ( sizeof(x) / sizeof(*(x)) ) 755 | 756 | #endif 757 | --------------------------------------------------------------------------------