예제 #1
0
파일: ntvdm.c 프로젝트: staring/RosFE
VOID MenuEventHandler(PMENU_EVENT_RECORD MenuEvent)
{
    switch (MenuEvent->dwCommandId)
    {
        case ID_SHOWHIDE_MOUSE:
            ShowHideMousePointer(ConsoleOutput, ShowPointer);
            ShowPointer = !ShowPointer;
            break;

        case ID_VDM_DUMPMEM_TXT:
            DumpMemory(TRUE);
            break;

        case ID_VDM_DUMPMEM_BIN:
            DumpMemory(FALSE);
            break;

        case ID_VDM_QUIT:
            /* Stop the VDM */
            EmulatorTerminate();
            break;

        default:
            break;
    }
}
예제 #2
0
void TraceExecution(Instruction I)
{
 
   DumpMemory(TraceFile);
   fprintf(TraceFile,"%s %1d : ","Executing Instruction at line ",I);
   WriteString(TraceFile,OpCodeOf(I));
   fprintf(TraceFile, " ");

   if (OpCodeOf(I) ==  NOP   || OpCodeOf(I) == LITOP   ||
       OpCodeOf(I) == LLVOP  || OpCodeOf(I) == LGVOP   ||
       OpCodeOf(I) == SLVOP  || OpCodeOf(I) == LLIVOP  || 
       OpCodeOf(I) == LGIVOP || OpCodeOf(I) == SLIVOP  ||
       OpCodeOf(I) == SGIVOP || OpCodeOf(I) == LIMITOP ||
       OpCodeOf(I) == SGVOP  || OpCodeOf(I) == LLAOP   ||
       OpCodeOf(I) == LGAOP  || OpCodeOf(I) == LUVOP   ||
       OpCodeOf(I) == SUVOP  || OpCodeOf(I) == POPOP   ||
       OpCodeOf(I) == CALLOP || OpCodeOf(I) == RTNOP   ||
       OpCodeOf(I) == GOTOOP || OpCodeOf(I) == CONDOP  ||
       OpCodeOf(I) ==  CODEOP ) 
      fprintf(TraceFile, " %d ",Operand1Of(I));
 
   if (OpCodeOf(I) == SOSOP || OpCodeOf(I) == UOPOP ||
                               OpCodeOf(I) == BOPOP) 
   {
      WriteString(TraceFile,Operand1Of(I));
      fprintf(TraceFile, " ");
   }
 
   if (OpCodeOf(I) == CONDOP || OpCodeOf(I) == LUVOP  ||
                               OpCodeOf(I) == SUVOP)
      fprintf(TraceFile," %d ", Operand2Of(I));

   fprintf(TraceFile, "\n");
}
예제 #3
0
/*
	Creates an object allocator from the user's configuration.
*/
void  __fastcall TfrmObjAllocMain::CreateObjectAllocator(void)
{
	FStudents->Free();
	FStudents = new TList();
	FStudentCount = 0;

	int size = sizeof(TStudent);
	FMaxPages = StrToInt(edtMaxPages->Text);
	FObjectsPerPage = StrToInt(edtObjectsPerPage->Text);
	FPadBytes = StrToInt(edtPaddingSize->Text);
	FHeaderSize = StrToInt(edtHeaderSize->Text);
	FAlignment = StrToInt(edtAlignment->Text);

	OAConfig config(false,
									FObjectsPerPage,
									FMaxPages,
									chkDebugState->Checked,
									FPadBytes,
									FHeaderSize,
									FAlignment
								 );

	FStudentObjectMgr = new ObjectAllocator(size, config);
	assert(FStudentObjectMgr);
	btnCreate->Enabled = false;
	UpdateUI();
	DumpFreeList();
	DumpMemory();
}
예제 #4
0
/*
	Add another student to the list (allocate from object allocator).
	If dump is true, redisplay the lists. Returns true, if successful.
*/
bool TfrmObjAllocMain::AddStudent(bool dump)
{
	PStudent ps;
	try
	{
		ps = (PStudent)reinterpret_cast<PStudent>(FStudentObjectMgr->Allocate());
	}
	catch (const OAException& e)
	{
		MessageDlg(AnsiString("Exception caught!\n\n") +  e.what(), mtError, TMsgDlgButtons() << mbOK, 0);
		return false;
	}

	FStudentCount++;

		// Initializing data?
	if (chkInitializeData->Checked)
		FillStudent(ps);

		// Add the student and adjust UI counters
	FStudents->Add(ps);
	UpdateUI();

		// Redisplay memory
	if (dump)
	{
		DumpStudents();
		DumpFreeList();
		DumpMemory();
	}
	return true;
}
예제 #5
0
/*
	Deletes the selected student and returns the memory to
	the object allocator
*/
void TfrmObjAllocMain::DeleteSelectedStudent(void)
{
	if (!FStudentObjectMgr)
		return;

		// Get selected student
	int index = lstStudents->ItemIndex;
	if ( (FStudents->Count > 0) && (index > -1) )
	{
		PStudent student = reinterpret_cast<PStudent>(FStudents->Items[index]);
		FStudents->Delete(index);
		FStudentObjectMgr->Free(student);
		UpdateUI();
		DumpStudents();
		DumpFreeList();
	  DumpMemory();

			// If there are students remaining in the list, highlight the next one
		if (FStudents->Count > 0)
		{
			index = (index >= FStudents->Count) ? FStudents->Count - 1 : index;
			lstStudents->ItemIndex = index;
			lstStudents->Selected[index] = true;
		}
	}
}
예제 #6
0
void DumpCrashInfo(char * szFileName)
{
	int x=0;
	DWORD *pdwStack;

	FILE *f = fopen(szFileName,"a");
	if(!f) return;

	fputs("\r\n--------------------------\r\n",f);

	sprintf(szErrorString,
		"SA-MP Server: %s\r\n\r\n"
		"Exception At Address: 0x%08X\r\n\r\n"
		"Registers:\r\n"
		"EAX: 0x%08X\tEBX: 0x%08X\tECX: 0x%08X\tEDX: 0x%08X\r\n"
		"ESI: 0x%08X\tEDI: 0x%08X\tEBP: 0x%08X\tESP: 0x%08X\r\n"
		"EFLAGS: 0x%08X\r\n\r\nStack:\r\n",
		SAMP_VERSION,
		pContextRecord->Eip,
		pContextRecord->Eax,
		pContextRecord->Ebx,
		pContextRecord->Ecx,
		pContextRecord->Edx,
		pContextRecord->Esi,
		pContextRecord->Edi,
		pContextRecord->Ebp,
		pContextRecord->Esp,
		pContextRecord->EFlags);

	pdwStack = (DWORD *)pContextRecord->Esp;
	DumpMemory((BYTE *)pdwStack, 320, szErrorString, TRUE);

	fputs(szErrorString,f);
	fclose(f);
}
예제 #7
0
void __fastcall TfrmObjAllocMain::btnFreeEmptyPagesClick(TObject *Sender)
{
	if (!FStudentObjectMgr)
		return;

	FStudentObjectMgr->FreeEmptyPages();
	DumpFreeList();
	DumpMemory();
	UpdateUI();
}
예제 #8
0
/*
	Creates 'count' random students.
*/
void  __fastcall TfrmObjAllocMain::CreateStudents(int count)
{
	for (int i = 0; i < count; i++)
		if (!AddStudent(false))
			break;

	DumpStudents();
	DumpFreeList();
	DumpMemory();
}
예제 #9
0
/*
	Deletes the object allocator and reinitializes the UI
*/
void  __fastcall TfrmObjAllocMain::DestroyObjectAllocator(void)
{
	assert(FStudentObjectMgr);
	delete FStudentObjectMgr;
	FStudentObjectMgr = 0;

	btnCreate->Enabled = true;
	FStudents->Clear();
	DumpStudents();
	DumpFreeList();
	DumpMemory();
	UpdateUI();
}
예제 #10
0
/*
	Frees the first student in the list.
*/
void  __fastcall TfrmObjAllocMain::DeleteFirstStudent(void)
{
	assert(FStudentObjectMgr);
	if (FStudents->Count > 0)
	{
		PStudent student = reinterpret_cast<PStudent>(FStudents->Items[0]);
		FStudents->Delete(0);
		FStudentObjectMgr->Free(student);
		UpdateUI();
		DumpStudents();
		DumpFreeList();
		DumpMemory();
	}
}
예제 #11
0
void __fastcall TfrmObjAllocMain::edtColumnsChange(TObject *Sender)
{
	try
	{
		FDumpColumns = StrToInt(edtColumns->Text);
		if (FDumpColumns > 256)
			FDumpColumns = 256;
		if (FDumpColumns < 1)
			FDumpColumns = 1;
		DumpMemory();
	}
	catch (...) // hack to deal with invalid input
	{
	}
}
예제 #12
0
/*
	Frees all students in the list.
*/
void  __fastcall TfrmObjAllocMain::DeleteAllStudents(void)
{
	PStudent student;

	int count = FStudents->Count;
	for (int i = 0; i < count; i++)
	{
		student = reinterpret_cast<PStudent>(FStudents->Items[0]);
		FStudents->Delete(0);
		FStudentObjectMgr->Free(student);
	}
	UpdateUI();
	DumpStudents();
	DumpFreeList();
	DumpMemory();
}
예제 #13
0
VOID NTAPI VmxCrash (
  PCPU Cpu,
  PGUEST_REGS GuestRegs
)
{
  PHYSICAL_ADDRESS pa;
  NTSTATUS Status;
  _KdPrint (("!!!VMX CRASH!!!\n"));

#if DEBUG_LEVEL>1
  _KdPrint (("rax 0x%llX\n", GuestRegs->rax));
  _KdPrint (("rcx 0x%llX\n", GuestRegs->rcx));
  _KdPrint (("rdx 0x%llX\n", GuestRegs->rdx));
  _KdPrint (("rbx 0x%llX\n", GuestRegs->rbx));
  _KdPrint (("rsp 0x%llX\n", GuestRegs->rsp));
  _KdPrint (("rbp 0x%llX\n", GuestRegs->rbp));
  _KdPrint (("rsi 0x%llX\n", GuestRegs->rsi));
  _KdPrint (("rdi 0x%llX\n", GuestRegs->rdi));

  _KdPrint (("r8 0x%llX\n", GuestRegs->r8));
  _KdPrint (("r9 0x%llX\n", GuestRegs->r9));
  _KdPrint (("r10 0x%llX\n", GuestRegs->r10));
  _KdPrint (("r11 0x%llX\n", GuestRegs->r11));
  _KdPrint (("r12 0x%llX\n", GuestRegs->r12));
  _KdPrint (("r13 0x%llX\n", GuestRegs->r13));
  _KdPrint (("r14 0x%llX\n", GuestRegs->r14));
  _KdPrint (("r15 0x%llX\n", GuestRegs->r15));
  _KdPrint (("Guest MSR_EFER Read 0x%llx \n", Cpu->Vmx.GuestEFER));
  CmGetPagePaByPageVaCr3 (Cpu, VmxRead (GUEST_CR3), VmxRead (GUEST_RIP), &pa);
  _KdPrint (("VmxCrash() IOA: Failed to map PA 0x%p to VA 0x%p\n", pa.QuadPart, Cpu->SparePage));
#endif

#if DEBUG_LEVEL>2
  if (!NT_SUCCESS (Status = CmPatchPTEPhysicalAddress (Cpu->SparePagePTE, Cpu->SparePage, pa))) {
    _KdPrint (("VmxCrash() IOA: Failed to map PA 0x%p to VA 0x%p, status 0x%08hX\n", pa.QuadPart, Cpu->SparePage,
               Status));
  }
  DumpMemory ((PUCHAR)
              (((ULONG64) Cpu->SparePage) | ((VmxRead (GUEST_RIP) - 0x10) & 0xfff)), 0x50);
#endif
  while (1);
}
예제 #14
0
void IH_cbVirtualProtect() // Callback for VirtualProtect
{
    char szSecurityAddrRegister[4]=""; //Register that contains a pointer to security.dll

    DeleteAPIBreakPoint((char*)"kernel32.dll", (char*)"VirtualProtect", UE_APISTART);
    SetAPIBreakPoint((char*)"kernel32.dll", (char*)"OutputDebugStringA", UE_BREAKPOINT, UE_APISTART, (void*)IH_cbOutputDebugStringA);

    unsigned int security_addr=0,esp_addr=0,code_size=0;
    esp_addr=(unsigned int)GetContextData(UE_ESP);
    ReadProcessMemory(IH_fdProcessInfo->hProcess, (const void*)(esp_addr+4), &security_addr, 4, 0);
    ReadProcessMemory(IH_fdProcessInfo->hProcess, (const void*)(esp_addr+8), &code_size, 4, 0);

    DumpMemory(IH_fdProcessInfo->hProcess, (void*)security_addr, code_size, (char*)"security_code.mem");

    if(GetContextData(UE_EAX)==security_addr)
        strcpy(szSecurityAddrRegister, "EAX");

    else if(GetContextData(UE_ECX)==security_addr)
        strcpy(szSecurityAddrRegister, "ECX");

    else if(GetContextData(UE_EDX)==security_addr)
        strcpy(szSecurityAddrRegister, "EDX");

    else if(GetContextData(UE_EBX)==security_addr)
        strcpy(szSecurityAddrRegister, "EBX");

    else if(GetContextData(UE_ESI)==security_addr)
        strcpy(szSecurityAddrRegister, "ESI");

    else if(GetContextData(UE_EDI)==security_addr)
        strcpy(szSecurityAddrRegister, "EDI");

    else
    {
        g_ErrorMessageCallback((char*)"There was an error recovering the correct register.\n\nThe program will quit now!", (char*)"Error!");
        ExitProcess(1);
    }

    g_PtrTargetData->CodeSize=code_size;

    strcpy(g_PtrTargetData->SecurityAddrRegister, szSecurityAddrRegister);
}
예제 #15
0
	Header* AllocateNew( Header* header, size_t size, bool high )
	{
		// Create a new header
		Header* newHeader = (Header*) (high
			? (((Byte*) header) - size - sizeof( Header ))
			: (((Byte*) header) + header->Size + sizeof( Header )));

#ifdef DEBUG_MEMORY
		if ( !(Memory <= (Byte*) newHeader && (Byte*) newHeader <= (Memory + MEMORY_SIZE)) )
		{
			DumpMemory( high );
			assert( false );
		}
#endif

		newHeader->Prev = header;
		newHeader->Next = header->Next;
		newHeader->Size = size;
		newHeader->Free = false;
		header->Next = newHeader;
		return newHeader;
	}
예제 #16
0
파일: bdecmds.c 프로젝트: chunhualiu/OpenNT
VOID
dw(
    HANDLE CurrentProcess,
    HANDLE CurrentThread,
    DWORD CurrentPc,
    PWINDBG_EXTENSION_APIS ExtensionApis,
    LPSTR ArgumentString
    )
/*++

Routine Description:


Arguments:

    CurrentProcess -- Supplies a handle to the current process
    CurrentThread -- Supplies a handle to the current thread
    CurrentPc -- Supplies the current program counter. (may be meaningless)
    ExtensionApis -- Supplies pointers to ntsd support routines
    ArgumentString -- Supplies the arguments passed to the command

Return Value:

    None.

--*/
{
    UNREFERENCED_PARAMETER(CurrentPc);

    hCurrentProcess = CurrentProcess;
    hCurrentThread = CurrentThread;
    lpArgumentString = ArgumentString;
    SETUP_WINDBG_POINTERS(ExtensionApis);
    DumpMemory(2);

}
예제 #17
0
LRESULT	CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
    switch (wID)
    {
    case IDCANCEL:
        EndDialog(0);
        break;
    case IDC_BTN_CHOOSE_FILE:
    {
        g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_DumpMemory);

        CPath FileName;
        if (FileName.SelectFile(m_hWnd, CPath(CPath::MODULE_DIRECTORY), "Text file (*.txt)\0*.txt;\0All files (*.*)\0*.*\0", false))
        {
            if (FileName.GetExtension().length() == 0)
            {
                FileName.SetExtension("txt");
                SetDlgItemText(IDC_FILENAME, FileName);
            }
        }
        g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory);
    }
    break;
    case IDOK:
    {
        TCHAR FileName[MAX_PATH];
        int CurrentFormatSel = SendDlgItemMessage(IDC_FORMAT, CB_GETCURSEL, 0, 0);
        DumpFormat Format = (DumpFormat)SendDlgItemMessage(IDC_FORMAT, CB_GETITEMDATA, CurrentFormatSel, 0);
        DWORD StartPC = m_StartAddress.GetValue();
        DWORD EndPC = m_EndAddress.GetValue();
        DWORD DumpPC = m_PC.GetValue();
        GetDlgItemText(IDC_FILENAME, FileName, sizeof(FileName));
        if (strlen(FileName) == 0)
        {
            g_Notify->DisplayError("Please Choose target file");
            ::SetFocus(GetDlgItem(IDC_FILENAME));
            return false;
        }
        if (SendDlgItemMessage(IDC_USE_ALT_PC, BM_GETSTATE, 0, 0) != BST_CHECKED)
        {
            DumpPC = g_Reg->m_PROGRAM_COUNTER;
        }
        //disable buttons
        ::EnableWindow(GetDlgItem(IDC_E_START_ADDR), FALSE);
        ::EnableWindow(GetDlgItem(IDC_E_END_ADDR), FALSE);
        ::EnableWindow(GetDlgItem(IDC_E_ALT_PC), FALSE);
        ::EnableWindow(GetDlgItem(IDC_USE_ALT_PC), FALSE);
        ::EnableWindow(GetDlgItem(IDC_FILENAME), FALSE);
        ::EnableWindow(GetDlgItem(IDC_BTN_CHOOSE_FILE), FALSE);
        ::EnableWindow(GetDlgItem(IDC_FORMAT), FALSE);
        ::EnableWindow(GetDlgItem(IDOK), FALSE);
        ::EnableWindow(GetDlgItem(IDCANCEL), FALSE);
        g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_DumpMemory);
        if (!DumpMemory(FileName, Format, StartPC, EndPC, DumpPC))
        {
            //enable buttons
            g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory);
            return false;
        }
        g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory);
    }
    EndDialog(0);
    break;
    }
    return FALSE;
}
예제 #18
0
void Execute(void)
{
   Instruction I;
   int temp, temp1, temp2,temp3, Addr;
   char tempc;


    /* Start  here */
   I = StartInstruction;
   while (OpCodeOf(I) != HALTOP) 
   {
      if (TraceSpecified)
         TraceExecution(I);

      if (ValidOpCode(I)) 
      {
         switch (OpCodeOf(I)) 
         {
            case NOP     : break;

	    case LITOP   : PushLf(Operand1Of(I));
                           break;

	    case LLVOP   : PushLf(Lf(Operand1Of(I)));
                           break;

	    case LGVOP   : PushLf(Gf(Operand1Of(I)));
                           break;

            case SLVOP   : UpdateLf(Operand1Of(I),PopLf());
                           break;
 
            case SGVOP   : UpdateGf(Operand1Of(I),PopLf());
                           break;
 
            case LLIVOP  : PushLf(Gf(Lf(Operand1Of(I))));
                           break;
 
            case LGIVOP  : PushLf(Gf(Gf(Operand1Of(I))));
		    	   break;
 
            case SLIVOP  : UpdateGf(Lf(Operand1Of(I)),PopLf());
			   break;
 
            case SGIVOP  : UpdateGf(Gf(Operand1Of(I)),PopLf());
			   break;
 
            case LLAOP   : PushLf(LocalAddress(Operand1Of(I)));
			   break;
 
            case LGAOP   : PushLf(GlobalAddress(Operand1Of(I)));
			   break;

            case LUVOP   : Addr = LocalAddress(0);
                           for (temp = 1; temp <= Operand1Of(I); temp++) 
                           { 
                              if (Addr == 0) 
                              {
                                 fprintf(output,
                                         "TOO MANY FRAMES SPECIFIED IN LUV\n");
                                 FatalError();
	                      }
                              Addr = Gf(Addr);
                           }
                           PushLf(Gf(Addr + Operand2Of(I)));
		           break;

            case SUVOP   : Addr = LocalAddress(0);
                           for (temp = 1; temp <= Operand1Of(I); temp++) 
                           { 
                              if (Addr == 0)
                              {
                                 fprintf(output,
                                         "TOO MANY FRAMES SPECIFIED IN SUV\n");
                                 FatalError();
                              }
                              Addr = Gf(Addr);
                            }
                            UpdateGf (Addr+Operand2Of(I),PopLf());
                            break;

            case UOPOP   : temp = PopLf();
                           switch (Operand1Of(I)) 
                           {
                              case UNOT  : PushLf(1 - temp); 
                                           break;

                              case UNEG  : PushLf(- temp);
                                           break;

                              case USUCC : PushLf(temp + 1);
                                           break;

                              case UPRED : PushLf(temp - 1);
                                           break;
			    }
			    break;

	     case BOPOP   : temp2 = PopLf(); 
                            temp1 = PopLf();
                            if (ValidBinOp(I)) 
                            {
                               switch (Operand1Of(I)) 
                               {
                                  case BAND   : PushLf(temp1 * temp2);
                                                break;

                                  case BOR    : if ((temp1+temp2) > 0)
                                                   PushLf (1);
                                                else 
                                                   PushLf(0);
                                                break;

                                  case BPLUS  : PushLf(temp1 + temp2);
                                                break;

                                  case BMINUS : PushLf(temp1 - temp2);
                                                break;

                                  case BMULT  : PushLf(temp1 * temp2);
                                                break;

                                  case BDIV   : if (temp2 == 0) 
                                                {
                                                   fprintf(output,
                                                    "<<< MACHINE ERROR >>>: ");
                                                   fprintf(output,
                                                    "DIVISION BY ZERO.\n");
                                                   DumpMemory(output);
                                                   FatalError();
					        } 
                                                else 
                                                   PushLf(temp1 / temp2);
                                              
                                                break;

                                  case BEXP   : if (temp2 < 0) 
                                                {
                                                   fprintf(output,
                                                    "<<< MACHINE ERROR >>>: ");
                                                   fprintf(output,
                                                    "NEGATIVE EXPONENT. \n");
                                                   DumpMemory(output);
                                                   FatalError();
                                                } 
                                                else 
                                                {
                                                   temp = 1;
                                                   for (temp3=1; temp3<=temp2; temp3++)
                                                      temp = temp * temp1;
                                                   PushLf(temp);
					        }
					        break;

                                  case BMOD   : PushLf(temp1 % temp2);
                                                break;

                                  case BEQ    : if (temp1 ==  temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

                                  case BNE    : if (temp1 != temp2) 
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

                                  case BLE    : if (temp1 <= temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf (0);
                                                break;

                                  case BGE    : if (temp1 >= temp2)
                                                   PushLf (1);
                                                else
                                                   PushLf (0);
                                                break;

                                  case BLT    : if (temp1 <  temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

                                  case BGT    : if (temp1 >  temp2)
                                                   PushLf(1);
                                                else
                                                   PushLf(0);
                                                break;

			       } /* switch(Operand1Of(I)) */

			    } 
                            else 
                            {
                               fprintf(output,"<<< MACHINE ERROR >>>: ");
                               fprintf(output,"UNKNOWN OPERAND NAME: ");
    		               fprintf(TraceFile," %d ",Operand1Of(I));
                               fprintf(output,"\n");
                               DumpMemory(output);
                               FatalError();
		            }
		            break;

             case POPOP   : PopOffLf(Operand1Of(I));
                            break;
 
             case DUPOP   : PushLf(TopLf());
                            break;
 
             case SWAPOP  : temp1 = PopLf();
                            temp2 = PopLf();
                            PushLf(temp1);
                            PushLf(temp2);
		            break;

             case CALLOP  : PushReturnStack(I);
                            OpenFrame(Operand1Of(I));
                            I = PopLf() - 1;
		            break;
 
             case RTNOP   : temp = DepthLf() - Operand1Of(I);
                            if (temp > 0) 
                            {
                             for (temp1 = 0; temp1 <= (Operand1Of(I) - 1); temp1++)
                                UpdateLf(temp1, Lf(temp + temp1));

                             PopOffLf(temp);
		            }
                            I = PopReturnStack();
                            CloseFrame (Operand1Of(I));
			    break;
 
             case GOTOOP  : I = Operand1Of(I) - 1;
		  	    break;

             case CONDOP  : temp = PopLf();
                            if (temp == 0)
                               I = Operand2Of(I) - 1;
                            else
                               I = Operand1Of(I) - 1;
                            break;
 
             case CODEOP  : PushLf(Operand1Of(I));
                            break;
 
             case LIMITOP : temp2 = PopLf();  /* U */
                            temp1 = PopLf();  /* L */
                            temp  = PopLf();  /* X */
                            if ((temp >= temp1) && (temp <= temp2))
                               PushLf(temp);
                            else 
                            {
                               fprintf(output,"<<< MACHINE ERROR >>>: ");
                               fprintf(output,"VALUE OUT OF RANGE\n");
                               DumpMemory(output);
                               FatalError();
			    }
			    break;

             case SOSOP   : if (ValidOsOp(I)) 
                            {
                                switch (Operand1Of(I)) 
                                {
                                   case TRACEX  : if (TraceSpecified)
                                                     TraceSpecified = false;
                                                  else
                                                     TraceSpecified = true;
					          break;

                                   case DUMPMEM : DumpMemory(output);
                                                  break;

                                   case OSINPUT : fscanf(input," ");
					          if (feof(input)) { 
                                                     fprintf(output,
                                                      "<<< MACHINE ERROR >>>: ");
                                                     fprintf(output,
                                                      "TRIED TO READ PAST <EOF>\n");
                                                     DumpMemory(output);
                                                     FatalError();
                                                  } 
                                                  else 
                                                  {
                                                     fscanf(input,"%d",&temp);
                                                     PushLf(temp);
					          }
					          break;
 
                                  case OSINPUTC : fscanf(input," ");
					          if (feof(input)) 
                                                  {
                                                     fprintf(output,
                                                      "<<< MACHINE ERROR >>>: ");
                                                     fprintf(output,
                                                      "TRIED TO READ PAST <EOF>\n");
                                                     DumpMemory(output);
                                                     FatalError();
                                                  } 
                                                  else 
                                                  {
                                                     fscanf(input,"%c",&tempc);
                                                     PushLf(tempc);
					          }
					          break;
 
                                  case OSOUTPUT : temp = PopLf();
                                                  fprintf(output,"%d ",temp);
					          break;
 
                                  case OSOUTPUTC: tempc = PopLf();
                                                  fprintf(output,"%c",tempc);
					          break;
 
                                  case OSOUTPUTL: fprintf(output,"\n");
						  break;
 
                                  case OSEOF    : fscanf(input," ");
					          if (feof(input))
                                                     PushLf(1);
                                                  else
                                                     PushLf(0);
					          break;
                                }
			     } 
                             else 
                             {
                                fprintf(output,"%s","<<< MACHINE ERROR >>>: ");
                                fprintf(output,"%s%1d `",
                                        "UNKNOWN OPERAND NAME: ",Operand1Of(I));
    		                fprintf(TraceFile," %d ",Operand1Of(I));
                                fprintf(output, "` \n");
                                DumpMemory(output);
                                FatalError();
                             }
                             break;
	 } /* switch (OpCodeOf(I)) */
              
      } 
      else 
      {
         fprintf(output,"%s","<<< MACHINE ERROR >>>: ");
         fprintf(output,"%s","UNKNOWN OP CODE NAME: ");
    	 fprintf(output," %d ",OpCodeOf(I));
         fprintf(output,"\n");
         FatalError();
      }
 
      I++;
 
   }
}  
LRESULT	CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	switch(wID)
	{
	case IDCANCEL:
		EndDialog(0);
		break;
	case IDC_BTN_CHOOSE_FILE:
		{
			char FileName[_MAX_PATH],Directory[_MAX_PATH];
			OPENFILENAME openfilename;

			memset(&FileName, 0, sizeof(FileName));
			memset(&openfilename, 0, sizeof(openfilename));
			strcpy(Directory,CPath(CPath::MODULE_DIRECTORY));
			openfilename.lStructSize  = sizeof( openfilename );
			openfilename.hwndOwner    = m_hWnd;
			openfilename.lpstrFilter  = "Text file (*.txt)\0*.txt;\0All files (*.*)\0*.*\0";
			openfilename.lpstrFile    = FileName;
			openfilename.lpstrInitialDir    = Directory;
			openfilename.nMaxFile     = MAX_PATH;
			openfilename.Flags        = OFN_HIDEREADONLY;
			g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_DumpMemory); 
			if (GetOpenFileName (&openfilename)) 
			{							
				char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
				_splitpath( FileName, drive, dir, fname, ext );
				if (strlen(ext) == 0)
				{
                    strcat(FileName,".txt");
				}
				SetDlgItemText(IDC_FILENAME,FileName);
			}	
			g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory); 
		}
		break;
	case IDOK:
		{
			TCHAR FileName[MAX_PATH];
			int CurrentFormatSel = SendDlgItemMessage(IDC_FORMAT,CB_GETCURSEL,0,0);
			DumpFormat Format = (DumpFormat)SendDlgItemMessage(IDC_FORMAT,CB_GETITEMDATA,CurrentFormatSel,0);
			DWORD StartPC =m_StartAddress.GetValue();
			DWORD EndPC = m_EndAddress.GetValue();
			DWORD DumpPC = m_PC.GetValue();
			GetDlgItemText(IDC_FILENAME,FileName,sizeof(FileName));
			if (strlen(FileName) == 0) 
			{
				g_Notify->DisplayError(L"Please Choose target file");
				::SetFocus(GetDlgItem(IDC_FILENAME));
				return false;
			}
			if (SendDlgItemMessage(IDC_USE_ALT_PC,BM_GETSTATE, 0,0) != BST_CHECKED)
			{
				DumpPC = g_Reg->m_PROGRAM_COUNTER;
			}
			//disable buttons
			::EnableWindow(GetDlgItem(IDC_E_START_ADDR),FALSE);
			::EnableWindow(GetDlgItem(IDC_E_END_ADDR),FALSE);
			::EnableWindow(GetDlgItem(IDC_E_ALT_PC),FALSE);
			::EnableWindow(GetDlgItem(IDC_USE_ALT_PC),FALSE);
			::EnableWindow(GetDlgItem(IDC_FILENAME),FALSE);
			::EnableWindow(GetDlgItem(IDC_BTN_CHOOSE_FILE),FALSE);
			::EnableWindow(GetDlgItem(IDC_FORMAT),FALSE);
			::EnableWindow(GetDlgItem(IDOK),FALSE);
			::EnableWindow(GetDlgItem(IDCANCEL),FALSE);
			g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_DumpMemory); 
			if (!DumpMemory(FileName,Format,StartPC,EndPC,DumpPC))
			{
				//enable buttons
				g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory); 
				return false;
			}
			g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory); 
		}
		EndDialog(0);
		break;
	}
	return FALSE;
}
예제 #20
0
파일: console.c 프로젝트: Moteesh/reactos
VOID MenuEventHandler(PMENU_EVENT_RECORD MenuEvent)
{
    switch (MenuEvent->dwCommandId)
    {
        /*
         * System-defined menu commands
         */

        case WM_INITMENU:
        case WM_MENUSELECT:
        {
            /*
             * If the mouse is captured, release it or recapture it
             * when the menu opens or closes, respectively.
             */
            if (!CaptureMouse) break;
            CaptureMousePointer(CurrentConsoleOutput, MenuEvent->dwCommandId == WM_INITMENU ? FALSE : TRUE);
            break;
        }


        /*
         * User-defined menu commands
         */

        case ID_CAPTURE_MOUSE:
            CaptureMouse = !CaptureMouse;
            CaptureMousePointer(CurrentConsoleOutput, CaptureMouse);
            UpdateVdmMenuMouse();
            break;

        case ID_VDM_DUMPMEM_TXT:
            DumpMemory(TRUE);
            break;

        case ID_VDM_DUMPMEM_BIN:
            DumpMemory(FALSE);
            break;

        /* Drive 0 -- Mount */
        /* Drive 1 -- Mount */
        case ID_VDM_DRIVES + 0:
        case ID_VDM_DRIVES + 2:
        {
            ULONG DiskNumber = (MenuEvent->dwCommandId - ID_VDM_DRIVES) / 2;
            MountFloppy(DiskNumber);
            break;
        }

        /* Drive 0 -- Eject */
        /* Drive 1 -- Eject */
        case ID_VDM_DRIVES + 1:
        case ID_VDM_DRIVES + 3:
        {
            ULONG DiskNumber = (MenuEvent->dwCommandId - ID_VDM_DRIVES - 1) / 2;
            EjectFloppy(DiskNumber);
            break;
        }

        case ID_VDM_QUIT:
            /* Stop the VDM */
            // EmulatorTerminate();

            /* Nothing runs, so exit immediately */
            DPRINT1("Killing NTVDM via console menu!\n");
            VdmShutdown(TRUE);
            break;

        default:
            break;
    }
}