• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

MS-DOS memory access from Win32 application

What I'm looking to do is to have access from a Win32 application to the MSDOS memory (specially video memory) an be able to read it.
In case it would be possible I would like to have some control of the 8086 virtual machine and be able to stop the process, copy everything from my Win32 application and save it on disk. Time after be able to recreate the same process and continue it.
I know this is much complicated so by now I would like just to see its output from my Win32 app.
Thanks in advance
0
jleni
Asked:
jleni
  • 5
  • 3
  • 3
  • +4
1 Solution
 
danny_pavCommented:
I think you may have to write a VxD.
0
 
laeuchliCommented:
If you know how to do it in assmebly you might be able to do it in a win32 app. Use the __asm keyword.

0
 
jleniAuthor Commented:
I don't think that writing something in assembler would solve my problem. Programming language it's not the problem...
Win32 applications run in protected mode and its not that easy to access another program memory area. I know I have to run something in Ring 0 by a VxD, but don't really how much about this.. That's the reason I made this question. I'm looking particulary for some service that could provide me some communication with the DOS VM. In case I would have to program a VxD what would you recommend ?

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
nietodCommented:
Using assembly definitely won't help.

Is the process you are trying to save a DOS or WINDOWS process?  If it is a windows process why are you concerned with DOS memory?

why are you trying to save and restore a process through these means?  That is almost impossible.  But using an object oriented approach it is--well not easy, but doable.
0
 
jleniAuthor Commented:
I'm trying to save a DOS process by now.
I know how to save the state of any program I design, however, I'm interested in doing this with external programs. I'm working in this because I want to make more realible some external programs that need to be online always and run under MS-DOS.
The process of saving and restoring a process is like a second stage.. By now I would like just to access video memory (at least 80x25 color !!) just to record the output of the program. I've already done this by redirecting stdio/stdout and works perfect but only if the program input/output is made this way.. However as soon as the program uses another way...

0
 
sergemCommented:
1. To acess speific videomemory you need read/write ports. It's not easy but you can find information about it.

2. To read any block of memory at any adress which is not property of your application you need to call VirtualAlloc and specify startadress and so on.

0
 
nietodCommented:
>> To acess speific videomemory you need read/write ports.

No you just need to access the right physical addresses.  but that can pretty much oinly be done by a device driver or a DOS program.

>>To read any block of memory at any adress which is not
>> property of your application you need to call
>> VirtualAlloc and specify startadress and so on.

I don't think you can use Virtualloc() for this.  It allocates from virtual memory, not physical memory.

jleni, my question to you is what are you going to do after you get the screen working properly?  In general you can't just make a copy of a program's memory image  and later reload it in memory.  That image may contain pointers and handles that will not longer be valid.  That program may have open files or altered interrupt chains.  How can you recreate that?
0
 
mnguyen021997Commented:
you will need to write a VDD for your dos which is essentially a device driver but not quite as complicated and specifically suited for the DOS VM.  its essentially a 32 bit dll that can communicate to your dos world via interrupts and also has the advantage of getting at all of the WIN32 apis.  leave me specifics on what you are trying to accomplish and i will try and answer as best i can:

1) basically you need a VDD running along with your DOS app.
2) it communicates to the DOS app through a special interupt provided by the DOS VM
3) it can get at the dos memory (its still virtual under NT)
4) it can communicate to other 32 bit processes via any means of IPC as well as spawn threads etc.  


0
 
jleniAuthor Commented:
sergem > I think much like nietod

nietod > As I told you, restoring a running application is like a second stage... By now, I don't mind about it and don't have though much about it. What I need by now, is just accessing video memory. I want to do this to send via TCP/IP these information to another computer.

mnguyen > I like that very much. If I understood.. is like writing a TSR program that can communicate with a Win32 application. I didn't think about it and it sounds great. However, I don't know very well how to program a DOS/WIN hybrid application..  (I just know how to change window title from a DOS program !!!) Where could I get more information on this ?

0
 
mnguyen021997Commented:
check in the the DDK SDK for VDD (virtual dos driver).  just look up VDD in the msdn for a high level view.  
0
 
nietodCommented:
If you are search by long names, I think VDD is "virtual DEVICE driver", not "virtual DOS driver".  
0
 
cessi0gCommented:
Hi,

Of course, you need a VxD.
But the VxD you are searching for, is very easy.

You have to write a VxD that does:
1) trap OnCreateVM message.
2) When a Virtual Machines is created, the system pass the
VM Handle to this VM. This handle is a linear address to the
virtual address where DOS Virtual Machine begin.
3) Adding 0xb8000000 to this linear address, you are accessing
to video memory from this VM.
4) A VxD executes at Ring0 level so you can do whatever you want.

If you need more help, I could post some code.

Regards.
0
 
jleniAuthor Commented:
cessi0g > Will this work on WinNT and Win95 ?
I liked the idea very much, however, I don't have DDK SDK... I do I have to buy it ? Or there exist any way of programming a VxD without it? I'm very new to VxD so I wonder how my application is going to communicate with the VxD.

0
 
cessi0gCommented:
jleni,
1) On Windows NT, you need another kind of module. a VDD (Virtual DOS driver).
2) You need the DDK. Microsoft sends it with MSDN. Programming directly with the DDK is in assembler, so i prefer to use another tool to programming in C, like VToolsD from Vireo Software (www.vireo.com). There is another shareware available on the web. Search for VxD.
3) Communicate with a Win32 App, is very easy. Think that Operating System is made by this modules, so there's a well documented way to do that.

Explain here how works VxD is too much complicated. If I have a minute (I hope) I'll post some example (code and executables).

Regards.

0
 
cessi0gCommented:
jleni,
I wrote some code that shown how you can do it.
Because you don't have DDK I need to send you executables and sources but I don't know how to post binary code here. Do you know it?
Or, Do you know how can I send you a zip file?

The source code follows.

Source of VxD using VToolsD.

/****************************************************************/
/* VScreenD.h                                                   */
/****************************************************************/
#include <vtoolsc.h>

#define VSCREEND_Major         1
#define VSCREEND_Minor         0
#define VSCREEND_DeviceID      UNDEFINED_DEVICE_ID
#define VSCREEND_Init_Order    UNDEFINED_INIT_ORDER

#define SCREEN_OFFSET          0xB8000
#define SCREEN_SIZE            4000      // Attribute + Character, 80 x 25
#define GET_SCREEN_DATA        1

typedef struct
{
      DWORD     VMID;
      LPSTR     Buffer;
} SCREENDATA, *LPSCREENDATA;

-------------------------------


/****************************************************************/
/* VScreenD.c                                                   */
/****************************************************************/
#define   DEVICE_MAIN
#include  "vscreend.h"
#undef    DEVICE_MAIN

/****************************************************************/
/* Prototypes                                                   */
/****************************************************************/
void GetScreenData( LPSCREENDATA );

/****************************************************************/
/* VxD Msgs Control Dispatch Code                               */
/****************************************************************/
#include LOCKED_CODE_SEGMENT
Declare_Virtual_Device( VSCREEND )

DefineControlHandler( SYS_DYNAMIC_DEVICE_INIT, OnSysDynamicDeviceInit );
DefineControlHandler( SYS_DYNAMIC_DEVICE_EXIT, OnSysDynamicDeviceExit );
DefineControlHandler( W32_DEVICEIOCONTROL, OnW32Deviceiocontrol );

BOOL __cdecl ControlDispatcher( DWORD dwControlMessage, DWORD EBX, DWORD EDX, DWORD ESI, DWORD EDI, DWORD ECX )
{
      START_CONTROL_DISPATCH
           ON_SYS_DYNAMIC_DEVICE_INIT( OnSysDynamicDeviceInit );
           ON_SYS_DYNAMIC_DEVICE_EXIT( OnSysDynamicDeviceExit );
           ON_W32_DEVICEIOCONTROL( OnW32DeviceIOControl );
      END_CONTROL_DISPATCH
      return TRUE;
}
/****************************************************************/
/* GetScreenData()                                              */
/****************************************************************/
void GetScreenData( LPSCREENDATA lpScreenData )
{
VMHANDLE   hVM;
VMHANDLE   CurVM;
LPSTR      lpData;

      hVM = Get_Sys_VM_Handle();
      if( hVM->CB_VMID == lpScreenData->VMID )
      {
           strcpy( lpScreenData->Buffer, "Invalid VM. System VM." );
           return;
      }

      CurVM = Get_Cur_VM_Handle();
      hVM = Get_Next_VM_Handle( CurVM );
      while( hVM != CurVM )
      {
           if( hVM->CB_VMID == lpScreenData->VMID )
           {
                lpData = (LPSTR)( hVM->CB_High_Linear + SCREEN_OFFSET );
                memcpy( lpScreenData->Buffer, lpData, SCREEN_SIZE );
                return;
           }
           hVM = Get_Next_VM_Handle( hVM );
      }

      strcpy( lpScreenData->Buffer, "Invalid VM." );
}

/****************************************************************/
/*                                                              */
/* VMM Msgs Dispatch Functions                                  */
/*                                                              */
/****************************************************************/
/* OnSysDynamicDeviceInit()                                     */
/****************************************************************/
BOOL OnSysDynamicDeviceInit()
{
      return TRUE;
}

/****************************************************************/
/* OnSysDynamicDeviceExit()                                     */
/****************************************************************/
BOOL OnSysDynamicDeviceExit()
{
      return TRUE;
}

/**************************************************************************/
/* OnW32DeviceIOControl()                                                 */
/**************************************************************************/
DWORD OnW32DeviceIOControl( PIOCTLPARAMS p )
{
LPSCREENDATA    lpScreenData;

      switch( p->dioc_IOCtlCode )
      {
           case DIOC_OPEN:
           case DIOC_CLOSEHANDLE:
                return 0;

           case GET_SCREEN_DATA:
                lpScreenData = (LPSCREENDATA)p->dioc_InBuf;
                GetScreenData( lpScreenData );
                return 0;

           default:
                return -1;
      }
}

-----------------------------------------
And the code for Win32 App.
-----------------------------------------
/***************************************************************************/
/* TestVxD.c                                                               */
/***************************************************************************/
#include <windows.h>

/***************************************************************************/
/* Definitions                                                             */
/***************************************************************************/
#define GET_SCREEN_DATA        1

typedef struct
{
      DWORD     VMID;
      LPSTR     Buffer;
} SCREENDATA, *LPSCREENDATA;

/***************************************************************************/
/* Global Variables                                                        */
/***************************************************************************/
char       VxDName[] = "\\\\.\\VSCREEND.VXD";
HANDLE     hVxD = 0;
BYTE       Buffer[ 4000 ];

/***************************************************************************/
/* WinMain()                                                               */
/***************************************************************************/
int APIENTRY WinMain( HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow )
{
SCREENDATA ScreenData;
DWORD      Ret;
DWORD      BytesRet;

//    VxD must be in Windows\System directory.
      hVxD = CreateFile( VxDName, 0, 0, 0, CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0 );
      if( hVxD == INVALID_HANDLE_VALUE ) return FALSE;
/*
      VMID 1 = System VM, not DOS.
      VMID 2 = First Virtual DOS Machine
      VMID 3 = Secon Virtual DOS Machine
      and so on
*/
      ScreenData.VMID = 2;
      ScreenData.Buffer = Buffer;

      Ret = DeviceIoControl( hVxD, GET_SCREEN_DATA, (LPVOID)&ScreenData, sizeof( LPVOID ), NULL, 0, &BytesRet, NULL );
//    If Ret = OK, now Buffer contains DOS Screen Characters and Attributes

      CloseHandle( hVxD );
      return 0;
}

--------------------
I hope this will help you

0
 
jleniAuthor Commented:
Wow ! Thanks a lot !
I didn't expect you to solve my problem... Great answer !
I would appreciate a lot if you could send me the executables because I don't have neither DDK nor VtoolsD.
I would like if it is possible to be able to pass SCREEN_OFFSET and SCREEN_SIZE so that would help me to access any memory area I need..
You can e-mail me a ZIP as an attachment to jleni@geocities.com
Thanks a lot !


0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 5
  • 3
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now