|
2 | 2 | #include <hal/video.h>
|
3 | 3 | #include <windows.h>
|
4 | 4 |
|
| 5 | +struct idtr_t |
| 6 | +{ |
| 7 | + uint16_t limit; |
| 8 | + uint32_t base; |
| 9 | +} __attribute__((packed)); |
| 10 | + |
| 11 | +struct idt_descriptor_t |
| 12 | +{ |
| 13 | + uint16_t offset_low; |
| 14 | + uint16_t selector; |
| 15 | + uint8_t zero; |
| 16 | + uint8_t type_attr; |
| 17 | + uint16_t offset_high; |
| 18 | +} __attribute__((packed)); |
| 19 | + |
| 20 | +void get_idtr (struct idtr_t *idtr) |
| 21 | +{ |
| 22 | + asm ("sidt %0" : "=m" (*idtr)); |
| 23 | +} |
| 24 | + |
| 25 | +uint32_t dbg_output_original_isr_addr; |
| 26 | +extern char dbg_output_isr_stub; |
| 27 | + |
| 28 | +void hook_int_2d () |
| 29 | +{ |
| 30 | + struct idtr_t idtr; |
| 31 | + struct idt_descriptor_t *entries; |
| 32 | + uint32_t new_isr = (uint32_t)&dbg_output_isr_stub; |
| 33 | + |
| 34 | + get_idtr(&idtr); |
| 35 | + entries = (struct idt_descriptor_t *)idtr.base; |
| 36 | + |
| 37 | + uint32_t old_isr = (((uint32_t)entries[0x2d].offset_high) << 16) | entries[0x2d].offset_low; |
| 38 | + dbg_output_original_isr_addr = old_isr; |
| 39 | + entries[0x2d].offset_low = ((uint32_t)new_isr) & 0xffff; |
| 40 | + entries[0x2d].offset_high = (((uint32_t)new_isr) >> 16) & 0xffff; |
| 41 | +} |
| 42 | + |
| 43 | +void unhook_int_2d () |
| 44 | +{ |
| 45 | + struct idtr_t idtr; |
| 46 | + struct idt_descriptor_t *entries; |
| 47 | + |
| 48 | + get_idtr(&idtr); |
| 49 | + entries = (struct idt_descriptor_t *)idtr.base; |
| 50 | + entries[0x2d].offset_low = dbg_output_original_isr_addr & 0xffff; |
| 51 | + entries[0x2d].offset_high = (dbg_output_original_isr_addr >> 16) & 0xffff; |
| 52 | +} |
| 53 | + |
| 54 | +__cdecl void dbg_output (uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx, uint32_t esi, uint32_t edi, uint32_t ebp) |
| 55 | +{ |
| 56 | + if (eax == 1) { |
| 57 | + PANSI_STRING s = (PANSI_STRING)ecx; |
| 58 | + debugPrint("%s\n", s->Buffer); |
| 59 | + } |
| 60 | +} |
| 61 | + |
5 | 62 | int main(void)
|
6 | 63 | {
|
7 | 64 | XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
|
8 | 65 |
|
| 66 | + hook_int_2d(); |
| 67 | + |
| 68 | + // This will be visible on screen |
| 69 | + OutputDebugString("test\n"); |
| 70 | + |
| 71 | + unhook_int_2d(); |
| 72 | + |
| 73 | + // This will not be visible on screen |
| 74 | + OutputDebugString("test2\n"); |
| 75 | + |
| 76 | + debugPrint("tests done\n"); |
| 77 | + |
9 | 78 | while(1) {
|
10 |
| - debugPrint("Hello nxdk!\n"); |
11 | 79 | Sleep(2000);
|
12 | 80 | }
|
13 | 81 |
|
|
0 commit comments