Solved

MS-DOS memory access from Win32 application

Posted on 1998-06-23
16
347 Views
Last Modified: 2013-12-03
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
Comment
Question by:jleni
  • 5
  • 3
  • 3
  • +4
16 Comments
 
LVL 3

Expert Comment

by:danny_pav
ID: 1408477
I think you may have to write a VxD.
0
 
LVL 5

Expert Comment

by:laeuchli
ID: 1408478
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
 

Author Comment

by:jleni
ID: 1408479
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
 
LVL 22

Expert Comment

by:nietod
ID: 1408480
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
 

Author Comment

by:jleni
ID: 1408481
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
 
LVL 1

Expert Comment

by:sergem
ID: 1408482
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
 
LVL 22

Expert Comment

by:nietod
ID: 1408483
>> 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
 
LVL 2

Expert Comment

by:mnguyen021997
ID: 1408484
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:jleni
ID: 1408485
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
 
LVL 2

Expert Comment

by:mnguyen021997
ID: 1408486
check in the the DDK SDK for VDD (virtual dos driver).  just look up VDD in the msdn for a high level view.  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1408487
If you are search by long names, I think VDD is "virtual DEVICE driver", not "virtual DOS driver".  
0
 
LVL 2

Expert Comment

by:cessi0g
ID: 1408488
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
 

Author Comment

by:jleni
ID: 1408489
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
 
LVL 2

Expert Comment

by:cessi0g
ID: 1408490
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
 
LVL 2

Accepted Solution

by:
cessi0g earned 240 total points
ID: 1408491
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
 

Author Comment

by:jleni
ID: 1408492
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now