home *** CD-ROM | disk | FTP | other *** search
- Program DeterminOVROrder;
- { This program is used to display the oreder of the units in }
- { a program as they were placed into the OVR file. Since }
- { each unit contains a call to a signature procedure, we will }
- { read from a file that contains a unit name and its unique }
- { signature. Then, when we find a signature within the OVR }
- { file, we can output the unit name that has that signature. }
- { This should be saved with the file name OVRORDER.PAS }
-
- Uses
- Crt, Dos; { Necessary Support Units }
-
- Const
- MaxSigs = 100; { Maximum number of signatures }
-
- Type
- SigType = Array[1..2] of Byte; { Size of each signature }
-
- SigRec = Record { Type to hold name and signature }
- UnitName : String;
- Signature : SigType;
- End;
-
- Var
- F : File of Byte; { Open the OVR file as a file of BYTE }
- TotalSigs, { Total number read from sig file }
- B : Byte; { Value read from the file }
- Signatures : Array[1..MaxSigs] of SigRec;
- SigRead : SigType; { Signature read from the OVR file }
- SigFileName, { Name of the Signature File }
- OvrFileName : String; { Name of the OVR file used as input }
-
- Function Exists( FName : String ) : Boolean;
- { This function uses a new technique to determine if a file }
- { exists. It uses the FExpand function, and passes it the }
- { name of the file we are looking for. If FExpand returns a }
- { NUL string, then ther file does not exist in the current }
- { directory. Note that this can be changed to accept a }
- { second parameter, which would be a list of directories to }
- { search. }
-
- Var
- S : String; { Result of call to FSearch Function }
-
- Begin
- FName := FExpand( FName );{ Expand the name to a full name }
- S := FSearch( FName, '' );{ Check for existence of file }
- Exists := S <> ''; { Return result in function name }
- End;
-
- Function GetFileNames( Var S, O : String ) : Boolean;
- { This function will read the command line for the two files }
- { that will be searched. If either of them is not found, or }
- { if there are not two arguments on the command line, the }
- { function will return FALSE. It also returns FALSE if }
- { either of the two files do not exist. Otherwise, it will }
- { return TRUE, and the program will continue. }
-
- Begin
- GetFileNames := True; { Assume success }
- If( ParamCount < 2 ) Then { See how many parameters passed }
- Begin { If fewer than two, quit }
- Writeln( 'Usage: OVRORDER signaturefile ovrfile' );
- Writeln;
- GetFileNames := False; { Set result to Failure }
- Exit;
- End;
- S := ParamStr( 1 ); { Get first command line argument }
- If( Not( Exists( S ) ) ) Then
- Begin { If file not there, fail }
- Writeln( 'Signature file NOT FOUND.' );
- Writeln;
- GetFileNames := False;
- Exit;
- End;
- O := ParamStr( 2 ); { Get second command line argument }
- If( Not( Exists( O ) ) ) Then
- Begin
- Writeln( 'Overlay file NOT FOUND.' );
- Writeln;
- GetFileNames := False;
- End;
- End;
-
- Procedure ReadSigFile( FName : String );
- { This procedure will read from the signature file, the unit }
- { name and its corresponding signature. }
-
- Var
- Temp,
- S : String; { Temporary working strings }
- Err, { Result of calling VAL procedure }
- Index, { Index into the SigRec Array }
- P : Integer; { Result of Pos function call }
- F : Text; { Input File Variable }
-
- Begin
- FillChar( Signatures, SizeOf( Signatures ), #0 );
- Assign( F, FName );
- Reset( F ); { Open the Input File }
- Index := 1; { Set Starting position }
- While( ( Not( EOF( F ) ) ) And ( Index <= MaxSigs ) ) Do
- Begin
- Readln( F, S ); { Read a data item }
- P := Pos( ' ', S ); { Parse the information }
- Signatures[Index].UnitName := Copy( S, 1, P - 1 );
- Delete( S, 1, P );
- P := Pos( ' ', S );
- Temp := Copy( S, 1, P - 1 );
- Val( Temp, Signatures[Index].Signature[1], Err );
- Delete( S, 1, P );
- Val( S, Signatures[Index].Signature[2], Err );
- End;
- TotalSigs := Index;
- Close( F );
- End;
-
- Procedure ShowIt( S : SigType );
- { This procedure will step through the array of signatures, }
- { and write out the unit name that has the signature passed. }
- { If no signature is found, the procedure will terminate. }
-
- Var
- Index : Byte; { Index into Signature Array }
-
- Begin
- Index := 1;
- While( Index <= TotalSigs ) Do
- Begin
- If( ( Signatures[Index].Signature[1] = S[1] ) And
- ( Signatures[Index].Signature[2] = S[2] ) ) Then
- Begin
- GotoXY( 10,WhereY ); { Position the cursor for output }
- Writeln( Signatures[Index].UnitName );
- Exit;
- End;
- Inc( Index );
- End;
- End;
-
- Begin
- If( Not( GetFileNames( SigFileName, OvrFileName ) ) ) Then
- Halt; { If files not found, exit program }
- ClrScr;
- GotoXY( 5,2 );
- Writeln( 'Unit order in ', OvrFileName, ':' );
- Writeln;
- ReadSigFile( SigFileName ); { Read the signature file }
- Assign( F, OvrFileName ); { Associate the OVR file with F }
- Reset( F ); { Open the file F }
- While( Not( EOF( F ) ) ) Do { Read the entire file }
- Begin
- Read( F, B ); { Read a byte from the file. }
- If( B = $90 ) Then { Compare to NOP OpCode value }
- Begin
- Read( F, SigRead[1] ); { Found a possible signature }
- Read( F, SigRead[2] ); { Get next two bytes from file }
- ShowIt( SigRead ); { Now see if valid signature }
- End;
- End;
- Close( F ); { Close the input file }
- End.