Chameleon

Chameleon Commit Details

Date:2010-08-29 05:51:34 (10 years 28 days ago)
Author:Evan Lojewski
Commit:442
Parents: 441
Message:Kernel patcher changes, initial lapic_configure patch, as well as a test patch for lapic_interrupt.
Changes:
M/branches/meklort/i386/modules/KernelPatcher/kernel_patcher.c
M/branches/meklort/i386/modules/KernelPatcher/kernel_patcher.h

File differences

branches/meklort/i386/modules/KernelPatcher/kernel_patcher.c
2626
2727
2828
29
30
31
32
2933
3034
3135
3236
3337
3438
35
39
40
41
42
43
44
45
46
3647
3748
3849
......
627638
628639
629640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
register_kernel_patch(patch_commpage_stuff_routine, KERNEL_32, CPUID_MODEL_ANY);
register_kernel_patch(patch_lapic_init, KERNEL_32, CPUID_MODEL_ANY);
//register_kernel_patch(patch_lapic_configure, KERNEL_32, CPUID_MODEL_ANY);
register_kernel_patch(patch_lapic_interrupt, KERNEL_32, CPUID_MODEL_ANY);
register_kernel_symbol(KERNEL_32, "_panic");
register_kernel_symbol(KERNEL_32, "_cpuid_set_info");
register_kernel_symbol(KERNEL_32, "_pmCPUExitHaltToOff");
register_kernel_symbol(KERNEL_32, "_lapic_init");
register_kernel_symbol(KERNEL_32, "_commpage_stuff_routine");
// LAPIC configure symbols
register_kernel_symbol(KERNEL_32, "_lapic_configure");
register_kernel_symbol(KERNEL_32, "_lapic_interrupt");
register_kernel_symbol(KERNEL_32, "_lapic_start");
register_kernel_symbol(KERNEL_32, "_lapic_interrupt_base");
// TODO: register needed symbols
}
void patch_lapic_interrupt(void* kernelData)
{
UInt8* bytes = (UInt8*)kernelData;
kernSymbols_t *symbol = lookup_kernel_symbol("_lapic_interrupt");
if(symbol == 0 || symbol->addr == 0)
{
printf("Unable to locate %s\n", "_lapic_interrupt");
return;
}
UInt32 patchLocation = symbol->addr - textAddress + textSection;
symbol = lookup_kernel_symbol("_panic");
if(symbol == 0 || symbol->addr == 0)
{
printf("Unable to locate %s\n", "_panic");
return;
}
UInt32 panicAddr = symbol->addr - textAddress;
patchLocation -= (UInt32)kernelData;
panicAddr -= (UInt32)kernelData;
while(
(bytes[patchLocation -1] != 0xE8) ||
( ( (UInt32)(panicAddr - patchLocation - 4) + textSection ) != (UInt32)((bytes[patchLocation + 0] << 0 |
bytes[patchLocation + 1] << 8 |
bytes[patchLocation + 2] << 16 |
bytes[patchLocation + 3] << 24)))
)
{
patchLocation++;
}
patchLocation--;
// Replace panic with nops
bytes[patchLocation + 0] = 0x90;
bytes[patchLocation + 1] = 0x90;
bytes[patchLocation + 2] = 0x90;
bytes[patchLocation + 3] = 0x90;
bytes[patchLocation + 4] = 0x90;
}
void patch_lapic_configure(void* kernelData)
{
UInt8* bytes = (UInt8*)kernelData;
UInt32 patchLocation;
UInt32 lapicStart;
UInt32 lapicInterruptBase;
kernSymbols_t *symbol = lookup_kernel_symbol("_lapic_configure");
if(symbol == 0 || symbol->addr == 0)
{
printf("Unable to locate %s\n", "_lapic_configure");
return;
}
patchLocation = symbol->addr - textAddress + textSection;
symbol = lookup_kernel_symbol("_lapic_start");
if(symbol == 0 || symbol->addr == 0)
{
printf("Unable to locate %s\n", "_lapic_start");
return;
}
lapicStart = symbol->addr;
symbol = lookup_kernel_symbol("_lapic_interrupt_base");
if(symbol == 0 || symbol->addr == 0)
{
printf("Unable to locate %s\n", "_lapic_interrupt_base");
return;
}
lapicInterruptBase = symbol->addr - textAddress;
patchLocation -= (UInt32)kernelData;
lapicStart -= (UInt32)kernelData;
lapicInterruptBase -= (UInt32)kernelData;
printf("\n\n\n\n\n\n\n"); // new lines so I can see things...
// Looking for the following:
//movl _lapic_start,%e_x
//addl $0x00000360,%e_x
// 8b 15 __ __ __ __ 81 c2 d0 00 00 00 65
while(
(bytes[patchLocation - 2] != 0x8b) ||
//bytes[patchLocation -1] != 0x8b) ||// Register, we don't care what it is
( lapicStart != (UInt32)(
(bytes[patchLocation + 0] << 0 |
bytes[patchLocation + 1] << 8 |
bytes[patchLocation + 2] << 16 |
bytes[patchLocation + 3] << 24
)
)
) ||
(bytes[patchLocation + 7 ] != 0x00) ||
(bytes[patchLocation + 8 ] != 0x00) ||
(bytes[patchLocation + 9 ] != 0x00) ||
(bytes[patchLocation + 10] != 0x65)
)
{
printf("0x%X 0x%X 0x%X 0x%X 0x%X, 0x%X\n", bytes[patchLocation - 1], bytes[patchLocation + 0], bytes[patchLocation + 1], bytes[patchLocation + 2], bytes[patchLocation + 3], lapicStart);
//getc();
patchLocation++;
}
patchLocation-=2;
printf("Patch location located at 0x%X\n", patchLocation);
printf("0x%X 0x%X 0x%X 0x%X 0x%X, 0x%X\n", bytes[patchLocation - 0], bytes[patchLocation + 1], bytes[patchLocation + 2], bytes[patchLocation + 3], bytes[patchLocation + 4], lapicStart);
getc();
// TODO: Patch location has been located, verify that the function hasen't changed to and unpachable state
// backup movl _lapic_interrupt_base,%e_x, so we know what the register is
}
branches/meklort/i386/modules/KernelPatcher/kernel_patcher.h
6161
6262
6363
64
65
66
6467
void patch_pmCPUExitHaltToOff(void* kernelData);
void patch_lapic_init(void* kernelData);
void patch_commpage_stuff_routine(void* kernelData);
void patch_lapic_configure(void* kernelData);
void patch_lapic_interrupt(void* kernelData);
#endif /* !__BOOT2_KERNEL_PATCHER_H */

Archive Download the corresponding diff file

Revision: 442