NTSTATUS DriverEntry (IN PDRIVER_OBJECT theDriverObject, IN PUNICODE_STRING theRegistryPath) { IDTINFO idt_info; // this structure is obtained by calling store idt (sidt) Idtentry * idt_entries; // and then this pointer is obtained from idt_info Idtentry * I; Unsigned long ADDR; Unsigned long count; Char _ t [255]; Thedriverobject-> driverunload = onUnload; // Initialize the Global interrupt count table below, which stores the number of calls to each interrupt. The interrupt number corresponds to // The offset in the array For (COUNT = start_idt_offset; count <max_idt_entries; count ++) { G_ I _count [count] = 0; } // Load idt_info _ Asm sidt idt_info Idt_entries = (IDTENTRY *) MAKELONG (idt_info.LowIDTbase, idt_info.HiIDTbase ); //////////////////////////////////////// //// // Save old idt pointers //////////////////////////////////////// //// For (count = START_IDT_OFFSET; count <MAX_IDT_ENTRIES; count ++) { I = & idt_entries [count]; Addr = MAKELONG (I-> LowOffset, I-> HiOffset ); _ Snprintf (_ t, 253, "Interrupt % d: ISR 0x % 08X", count, addr ); Dbuplint (_ t ); Old_ISR_pointers [count] = MAKELONG (idt_entries [count]. LowOffset, idt_entries [count]. HiOffset ); } // Allocate enough memory below to store all jump templates. This memory must be in // NonPagedpool //////////////////////////////////////// /// // Setup the detour table //////////////////////////////////////// /// Idt_detour_tablebase = ExAllocatePool (NonPagedPool, sizeof (jump_template) * 256 ); // Use the following code to obtain the pointer of each jump table position in NonPagePool. Rewrite the jump template to this position, then, paste the correct re-entry address and interrupt number into the jump template. Perform these operations for each interrupt // each time. For (count = START_IDT_OFFSET; count <MAX_IDT_ENTRIES; count ++) { Int offset = sizeof (jump_template) * count; Char * entry_ptr = idt_detour_tablebase + offset; // Entry_ptr points to the start of our jump code in the detour_table // Copy the starter code into the template location Memcpy (entry_ptr, jump_template, sizeof (jump_template )); # Ifndef _ DEBUG // Stamp the interrupt number Entry_ptr [4] = (char) count; // Stamp the far call to the hook routine * (Unsigned long *) (& entry_ptr [10]) = (unsigned long) count_interrupts; # Endif // Stamp the far jump to the original ISR * (Unsigned long *) (& entry_ptr [20]) = old_isr_pointers [count]; // Modify the interrupt table entry to point to the newly created jump Template // Finally, make the interrupt point to our template code _ Asm cli Idt_entries [count]. LowOffset = (unsigned short) entry_ptr; Idt_entries [count]. HiOffset = (unsigned short) (unsigned long) entry_ptr> 16 ); _ Asm sti } Dbuplint ("Hooking Interrupt complete "); Return STATUS_SUCCESS; } |