| 10859 | } |
| 10860 | |
| 10861 | void testSelfModifyingMovsb() { |
| 10862 | // initialize |
| 10863 | newInstruction(0); |
| 10864 | |
| 10865 | EDI = 0; |
| 10866 | ESI = 512; |
| 10867 | ECX = 3; // 3 bytes to copy |
| 10868 | |
| 10869 | // code to copy |
| 10870 | // sub eax, 0x05 |
| 10871 | memory->writeb(CODE_ADDRESS + 512, 0x83); |
| 10872 | memory->writeb(CODE_ADDRESS + 513, 0xe8); |
| 10873 | memory->writeb(CODE_ADDRESS + 514, 0x05); |
| 10874 | |
| 10875 | cpu->setSeg(ES, CODE_ADDRESS, 1); |
| 10876 | |
| 10877 | // add eax, 0x20 (3 bytes) |
| 10878 | pushCode8(0x83); |
| 10879 | pushCode8(0xc0); |
| 10880 | pushCode8(0x20); |
| 10881 | |
| 10882 | // test edx, edx (2 bytes) |
| 10883 | pushCode8(0x85); |
| 10884 | pushCode8(0xd2); |
| 10885 | |
| 10886 | // jnz (2 bytes) |
| 10887 | pushCode8(0x75); |
| 10888 | pushCode8(0x6); |
| 10889 | |
| 10890 | // inc edx (1 byte) |
| 10891 | pushCode8(0x42); |
| 10892 | |
| 10893 | // modify previous block |
| 10894 | // movsb es:edi cs:esi (3 bytes) |
| 10895 | |
| 10896 | pushCode8(0xf3); // repeat |
| 10897 | pushCode8(0x2e); // CS source |
| 10898 | pushCode8(0xa4); // movsb |
| 10899 | |
| 10900 | // jmp (2 bytes) |
| 10901 | pushCode8(0xeb); |
| 10902 | pushCode8(0xf3); // jmp -13 |
| 10903 | |
| 10904 | runTestCPU(); |
| 10905 | |
| 10906 | assertTrue(EDX == 1); |
| 10907 | assertTrue(EAX == 0x1b); // 0x20 from first run - 0x05 from second run |
| 10908 | } |
| 10909 | |
| 10910 | void testReverseBits() { |
| 10911 | // initialize |
nothing calls this directly
no test coverage detected