public static void Iam_The_IntelCPU_HaHaHa(VCpuState state, uint ip) { uint eax = state.Eax; uint ebx = state.Ebx; uint ecx = state.Ecx; uint edx = state.Edx; uint esp = state.Esp; uint esi = state.Esi; uint edi = state.Edi; uint ebp = state.Ebp; uint cache_last_page1 = 0xffffffff; uint last_used_cache = 0; byte * cache_last_realaddr1 = null; uint cache_last_page2 = 0xffffffff; byte * cache_last_realaddr2 = null; uint vaddr = 0, vaddr1_index = 0, vaddr1_offset = 0; uint write_tmp = 0, read_tmp = 0; uint compare_result = 0; VMemory Memory = state.Memory; VPageTableEntry *pte = Memory.PageTableEntry; byte * cont_memory = Memory.ContiguousMemory; uint cont_start = Memory.ContiguousStart; uint cont_end = Memory.ContiguousEnd; byte * cont_memory_minus_start = (byte *)(Memory.ContiguousMemory - cont_start); uint next_ip = ip; CallRetAddress next_return = (CallRetAddress)0x7fffffff; ref ushort al = ref *((ushort *)(&eax) + 0); ref ushort ah = ref *((ushort *)(&eax) + 1);
public static void ExecTest() { int count = 11; using (VProcess proc = new VProcess()) { uint stackPtr = 0x500000 + 0x10000 / 2; if (VConsts.Addressing == AddressingMode.Paging) { proc.Memory.AllocateMemory(0x8000000, 0x100000); proc.Memory.AllocateMemory(0x500000, 0x10000); } else { proc.Memory.AllocateContiguousMemory(0x500000, 0x8000000 + 0x100000 - 0x500000); } VCpuState state = new VCpuState(proc); uint ret = 0xffffffff; Stopwatch sw = new Stopwatch(); //sw.Start(); for (int i = 0; i < count; i++) { if (i == 1) { sw.Start(); } state.Esp = stackPtr; state.Esp -= 4; proc.Memory.Write(state.Esp, (uint)VCode.CallRetAddress._MagicReturn); VCode.Iam_The_IntelCPU_HaHaHa(state, (uint)VCode.FunctionTable.test_target1); if (state.ExceptionString != null) { throw new ApplicationException($"Error: {state.ExceptionString} at 0x{state.ExceptionAddress:x}."); } else { uint r = state.Eax; if (ret == 0xffffffff) { ret = r; Console.WriteLine($"ret = {state.Eax}"); } else if (ret == r) { } else { throw new ApplicationException("Error: Invalid result: " + r); } } } sw.Stop(); long result = sw.Elapsed.Ticks * 100 / (count - 1); Console.WriteLine($"time = {result:#,0}"); } }