诸位大大大虾,我有问题请教,125分我豁出去了。(100分)

  • 主题发起人 主题发起人 lingru
  • 开始时间 开始时间
L

lingru

Unregistered / Unconfirmed
GUEST, unregistred user!
诸位大大大虾,我有问题请教,125分我豁出去了。
老板让我编一个程序,能够记录其他程序运行时在
屏幕上的所有数据。而且那个鬼程序还是DOS版本下
的。帮忙帮到底,您最好能给我一个例子。
 
黑程序?
写一个TSR,截获Int21中的2,9这两个中断功能就可以了,
注意不要删除它的内容,还要将内容指向原来的。
至于如何写TSR,我也说不清楚,找本书看看。
 
将dos程序输出重定向可以吗?
 
是在Windows下监视DOS程序吧。
 
>>将dos程序输出重定向可以吗?
一些程序可以,但更多的是不可以。不过也可试试。
 
不知你的波斯何意!
wg>
 
终端仿真?125分可不够。
 
DOS重定向可以考虑,
但我要在程序正常运转的同时重定向到一个文件中去,可以吗?
也就是一边output screen,一边output file,可以吗?
另外我DOS没好好学,哪位指导一下重定向的问题。
 
可以在程序正常运转的同时重定向到一个文件中去.
 
设一个FAR 指针指向B800,
然后根据屏幕显示模式(25*80/40)
做一个定时中断处理,读取指针以后的东西
我以前做过这样的东西
 
cmldy,能否详细点。能否详细点。拜托了。
 
示例如下(转贴,分两次):

Redirecting DOS App Output D2 D3 D4
A function to execute a DOS or Win32 consoloe mode application and wait
for it to close before continuing. Input for the app can be directed from a
file, and the output will be redirected to a file.
uses
Controls, Windows, SysUtils, Forms;

{---------------------------CreateDOSProcessRedirected--------------------------
Description : executes a (DOS!) app defined in the CommandLine parameter
redirected to take input from InputFile (optional) and give
output to OutputFile
Result : True on success
Parameters : CommandLine : the command line for app, including full path
InputFile : the ascii file where from the app takes input,
empty if no input needed/required.
OutputFile : the ascii file to which the output is redirected
ErrMsg : additional error message string. Can be empty
Error checking : YES
Target : Delphi 2, 3, 4
Author : Theodoros Bebekis, email bebekis@otenet.gr
Notes :
Example call : CreateDOSProcessRedirected('C:/MyDOSApp.exe',
'C:/InputPut.txt',
'C:/OutPut.txt',
'Please, record this message')
-------------------------------------------------------------------------------}
function CreateDOSProcessRedirected(const CommandLine, InputFile, OutputFile,
ErrMsg :string): boolean;
const
ROUTINE_ID = '[function: CreateDOSProcessRedirected]';
var
OldCursor : TCursor;
pCommandLine : array[0..MAX_PATH] of char;
pInputFile,
pOutPutFile : array[0..MAX_PATH] of char;
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
SecAtrrs : TSecurityAttributes;
hAppProcess,
hAppThread,
hInputFile,
hOutputFile : THandle;
begin
Result := FALSE;

{ check for InputFile existence }
if (InputFile <> '') and (not FileExists(InputFile)) then
raise Exception.CreateFmt(ROUTINE_ID + #10 + #10 +
'Input file * %s *' + #10 +
'does not exist' + #10 + #10 +
ErrMsg, [InputFile]);

hAppProcess := 0;
hAppThread := 0;
hInputFile := 0;
hOutputFile := 0;

{ save the cursor }
OldCursor := Screen.Cursor;
Screen.Cursor := crHourglass;

try
{ copy the parameter Pascal strings to null terminated strings }
StrPCopy(pCommandLine, CommandLine);
StrPCopy(pInputFile, InputFile);
StrPCopy(pOutPutFile, OutputFile);

{ prepare SecAtrrs structure for the CreateFile calls. This SecAttrs
structure is needed in this case because we want the returned handle to
be inherited by child process. This is true when running under WinNT.
As for Win95, the parameter is ignored. }
FillChar(SecAtrrs, SizeOf(SecAtrrs), #0);
SecAtrrs.nLength := SizeOf(SecAtrrs);
SecAtrrs.lpSecurityDescriptor := nil;
SecAtrrs.bInheritHandle := TRUE;
 
; if InputFile <> '' then
begin
{ create the appropriate handle for the input file }
hInputFile := CreateFile(
pInputFile, { pointer to name of the file }
GENERIC_READ or GENERIC_WRITE, { access (read-write) mode }
FILE_SHARE_READ or FILE_SHARE_WRITE, { share mode }
@SecAtrrs, { pointer to security attributes }
OPEN_ALWAYS, { how to create }
FILE_ATTRIBUTE_NORMAL
or FILE_FLAG_WRITE_THROUGH, { file attributes }
0); { handle to file with attrs to copy }

{ is hInputFile a valid handle? }
if hInputFile = INVALID_HANDLE_VALUE then
raise Exception.CreateFmt(ROUTINE_ID + #10 + #10 +
'WinApi function CreateFile returned an invalid handle value' + #10 +
'for the input file * %s *' + #10 + #10 +
ErrMsg, [InputFile]);
end else
{ we aren't using an input file }
hInputFile := 0;

{ create the appropriate handle for the output file }
hOutputFile := CreateFile(
pOutPutFile, { pointer to name of the file }
GENERIC_READ or GENERIC_WRITE, { access (read-write) mode }
FILE_SHARE_READ or FILE_SHARE_WRITE, { share mode }
@SecAtrrs, { pointer to security attributes }
CREATE_ALWAYS, { how to create }
FILE_ATTRIBUTE_NORMAL
or FILE_FLAG_WRITE_THROUGH, { file attributes }
0 ); { handle to file with attrs to copy }

{ is hOutputFile a valid handle? }
if hOutputFile = INVALID_HANDLE_VALUE then
raise Exception.CreateFmt(ROUTINE_ID + #10 + #10 +
'WinApi function CreateFile returned an invalid handle value' + #10 +
'for the output file * %s *' + #10 + #10 +
ErrMsg, [OutputFile]);

{ prepare StartupInfo structure }
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
StartupInfo.wShowWindow := SW_HIDE;
StartupInfo.hStdOutput := hOutputFile;
StartupInfo.hStdInput := hInputFile;

{ create the app }
Result := CreateProcess(
NIL, { pointer to name of executable module }
pCommandLine, { pointer to command line string }
NIL, { pointer to process security attributes }
NIL, { pointer to thread security attributes }
TRUE, { handle inheritance flag }
HIGH_PRIORITY_CLASS, { creation flags }
NIL, { pointer to new environment block }
NIL, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo); { pointer to PROCESS_INF }

{ wait for the app to finish its job and take the handles to free them later }
if Result then
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
hAppProcess := ProcessInfo.hProcess;
hAppThread := ProcessInfo.hThread;
end else
raise Exception.Create(ROUTINE_ID + #10 + #10 +
'Function failure' + #10 + #10 + ErrMsg);

finally
{ close the handles
Kernel objects, like the process and the files we created in this case,
are maintained by a usage count.
So, for cleaning up purposes we have to close the handles
to inform the system that we don't need the objects anymore }
if hOutputFile <> 0 then
CloseHandle(hOutputFile);
if hInputFile <> 0 then
CloseHandle(hInputFile);
if hAppThread <> 0 then
CloseHandle(hAppThread);
if hAppProcess <> 0 then
CloseHandle(hAppProcess);
{ restore the old cursor }
Screen.Cursor:= OldCursor;
end;
end; { CreateDOSProcessRedirected }
 
windows 监视dos?
 
DOS下的程序最好用DOS的驻留程序来监视,
一般情况下(除需加快显示速度而操作硬件端口
或接读写显存外),均使用BIOS或DOS的中断来实现,
(包括各类语言中的显示函数)
而DOS中断都是调用BIOS中断来实现的.
而BIOS显示中断为INT10H中断,
故可以截取INT10H中断达到监视目的.
具体可以(以Turbo C 2.0为例):
先用getvect()获取INT10H中断地址,
再用setvect()挂上自己的中断处理程序,
最后用keep()实现驻留.
在自己的中断处理程序中再根据AH值,
判断调用目的,如为写入字符或移动光标,
则记入文件.
如果截取INT21H中断,
则在写文件时可能出错,
因为DOS是不可重入的.
 
沈前卫,对inputfile能否解释一下。比如我有一长串的控制命令。
 
lingru:
其实是Dos的格式: Command.com〈InputFile 〉OutputFile
Inputfile格式是文本格式,不过要注意,每一行都要以回车结尾,铁别是最后一行
,否则程序将呈死态。(可以参考原程序)
下面举一例:
Inputfile: i.txt
Dir C:/
Exit
在Delphi程序中:
调用CreateDOSProcessRedirected('command.com','c:/i.txt','c:/o.txt','Error Message');

如果还有疑问,<a href="mailto:shenqw@cmmail.com">MailMe</a>
 
时间太久,强制结束。 wjiachun
 
<h1>还有使DOS的?</h1>
 
后退
顶部