help with non-text file reading 
Author Message
 help with non-text file reading

I would like to be able to read in a non-text file (such as an .EXE file) and
change each character to HEX (along with formatting the output and other
simple stuff) and finally save the HEX values into another file.  
The problem is that I am fairly new to Pascal programming but I do have a few
programs under my belt.  I would appreciate any help anyone can offer, either
in email or posted here.
I'm running both BP7 and TPW 1.5 (and delphi 1.0) and would prefer a response
to the TPW (wincrt or otherwise) version though any and all responses will be
appreciated.



Fri, 24 Jul 1998 03:00:00 GMT  
 help with non-text file reading

Quote:

>I would like to be able to read in a non-text file (such as an .EXE file) and
>change each character to HEX (along with formatting the output and other
>simple stuff) and finally save the HEX values into another file.  
>The problem is that I am fairly new to Pascal programming but I do have a few
>programs under my belt.  I would appreciate any help anyone can offer, either
>in email or posted here.
>I'm running both BP7 and TPW 1.5 (and Delphi 1.0) and would prefer a response
>to the TPW (wincrt or otherwise) version though any and all responses will be
>appreciated.

To read a non-text file you could do:

Var  F : file of byte;
     B : byte;

begin
   assign(F,<FileName>);
   Reset(F);

   Now you can use  Read(F,B);

   So it's al(l?)most the same as reading a text-file.
Hope this helps,
                 Bruno



Mon, 27 Jul 1998 03:00:00 GMT  
 help with non-text file reading
Quote:

> I would like to be able to read in a non-text file (such as an .EXE file) and
> change each character to HEX (along with formatting the output and other
> simple stuff) and finally save the HEX values into another file.

...
--

Hi Eriko,

you can read it either byte after byte as suggested, but this takes a very
long time. A better approach is to use the BlockRead() function, that reads
more than 1 byte at a time into a buffer, this is much faster. Check the
online help for the syntax.

Thomas...

 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 Thomas Petzke                                                  TU Ilmenau      
 =========================================================================
 Snail Mail : Gottfried-Jaehnichen-Weg 6         Tel.   : (0341) 65 15 076    
              D-04457 Baalsdorf
 -------------------------------------------------------------------------              

 HomePage   : http://www.rz.tu-ilmenau.de/~ai60732/tom.html
 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>



Mon, 27 Jul 1998 03:00:00 GMT  
 help with non-text file reading
Hi there

If using windows libraries, check wvsprintf for quick decimal to binary
string conversion.

For file manipulation, check OpenFile, _lRead, -lWrite... etc.

Thanking you

James Burroughs

ARS Administrator

Service desk / Hulpburo (7I5G)

Information Technology / Inligtings Tegnologie

Telkom S.A.



ph      : +27(012)311-4280 (Service Desk)

ph      : +27(012)311-2461 (Direct)

Fax     : +27(012)324-4478

Pager   : +27(012)341-7607 Code:24342

~~~~~~~~~~~~~~~~~~~ ORIGINAL MESSAGE STARTS ~~~~~~~~~~~~~~~~~~~

I would like to be able to read in a non-text file (such as an .EXE file)
and

change each character to HEX (along with formatting the output and other

simple stuff) and finally save the HEX values into another file.  

The problem is that I am fairly new to Pascal programming but I do have a
few

programs under my belt.  I would appreciate any help anyone can offer,
either

in email or posted here.

I'm running both BP7 and TPW 1.5 (and Delphi 1.0) and would prefer a
response

to the TPW (wincrt or otherwise) version though any and all responses
will be

appreciated.

~~~~~~~~~~~~~~~~~~~ ORIGINAL MESSAGE ENDS ~~~~~~~~~~~~~~~~~~~



Mon, 27 Jul 1998 03:00:00 GMT  
 help with non-text file reading

Quote:

>I would like to be able to read in a non-text file (such as an .EXE file) and
>change each character to HEX (along with formatting the output and other
>simple stuff) and finally save the HEX values into another file.  
>The problem is that I am fairly new to Pascal programming but I do have a few
>programs under my belt.  I would appreciate any help anyone can offer, either
>in email or posted here.
>I'm running both BP7 and TPW 1.5 (and Delphi 1.0) and would prefer a response
>to the TPW (wincrt or otherwise) version though any and all responses will be
>appreciated.

This is a first stab, UNTESTED! (and will likely be VERY slow), but
should get you started:

------------------>8  cut here  8<---------------------
program HexView ;
uses
  WinCRT ;

const
  BuffSize = 16 ;
var
  InFile : file ;
  InBuffer : array [1..BuffSize] of byte ;
  ReadCnt, i : integer ;

function Num2Hex( x: byte ) : string ;
const
  NibbleLookup : array [0..15] of char =
    ( '0', '1', '2', '3',
      '4', '5', '6', '7',
      '8', '9', 'A', 'B',
      'C', 'D', 'E', 'F' ) ;
var
  HiNibble, LoNibble : byte ;
begin
  HiNibble := x div 16 ;
  LoNibble := x - (( HiNibble ) * 16 ) ;
  Num2Hex := NibbleLookup[HiNibble] + NibbleLookup[LoNibble]
end ;

begin
    InitWinCRT ;

    {$I- }
    Assign( InFile, 'SOMEFILE.EXE' ) ;
    (* Set file for 1 byte records *)
    Reset( InFile, 1 ) ;

    if IOResult <> 0 then
    begin
      WriteLn( output, 'Input File open error' ) ;
      Halt ;
    end ;
    {$I+ }

    repeat
      (* read in 16 bytes of file *)
      BlockRead( InFile, InBuffer, SizeOf( InBuffer ), ReadCnt ) ;

      (* convert and write hex equivalents of 16 bytes *)
      for i := 1 to BuffSize do
        Write( output, Num2Hex( InBuffer[i] ) + ' ' ) ;

      (* skip to next line *)
      WriteLn( output ) ;

    until ( EOF( InFile )) or  ( ReadCnt = 0 ) ;

    Close( InFile ) ;
end .
------------------>8  cut here  8<---------------------

Let me know if this has any serious problems or you have any questions.

HTH

-* Stephen *-
Stephen Posey
University of New Orleans

WWW    : http://www.uno.edu/~slp



Tue, 28 Jul 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Converting Non-Text File to Text File

2. Help please: non-BDE, non-ODBC database files

3. How to APPEND a non-text file?

4. non text files in pascal

5. flush or append with non-text files?

6. SORTING RECORDS-NON TEXT FILES

7. Please help with Text File reading...

8. Please help read/write text files

9. Help! Reading hex data from text file

10. Teacher needs help in reading and display text file

11. reading from nontext files

12. Text File Read / Dbase file Write

 

 
Powered by phpBB® Forum Software