flat assembler
Message board for the users of flat assembler.

Index > Main > Search files current directory

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
How to find .txt files in the current directory and translate them to string to hex?
Thanks
Post 08 Oct 2021, 12:52
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
dir *.txt -> HIEW -> F4 -> F2
Post 08 Oct 2021, 13:16
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
dir *.txt -> HIEW -> F4 -> F2

I don't understand, can you do it in code?
Post 08 Oct 2021, 13:21
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
dir *.txt -> HIEW -> F4 -> F2

the contents of the files must be converted to hex
Post 08 Oct 2021, 13:23
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
unknown334 wrote:
I don't understand, can you do it in code?

I didn't understand your question either.
At least they would specify for which system / programming language / processor type
macomics wrote:
rem a DOS batch command that will find everything .txt files in the current directory
dir *.txt

rem use one of the programs (for example HIEW)
hiew txt_file_spec

rem to display as HEX in HIEW, press F4 twice
Post 08 Oct 2021, 13:29
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
unknown334 wrote:
I don't understand, can you do it in code?

I didn't understand your question either.
At least they would specify for which system / programming language / processor type
macomics wrote:
rem a DOS batch command that will find everything .txt files in the current directory
dir *.txt

rem use one of the programs (for example HIEW)
hiew txt_file_spec

rem to display as HEX in HIEW, press F4 twice

FASM, WINDOWS
Post 08 Oct 2021, 13:30
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
unknown334 wrote:
I don't understand, can you do it in code?

I didn't understand your question either.
At least they would specify for which system / programming language / processor type
macomics wrote:
rem a DOS batch command that will find everything .txt files in the current directory
dir *.txt

rem use one of the programs (for example HIEW)
hiew txt_file_spec

rem to display as HEX in HIEW, press F4 twice

After starting the program on Fasm, it should translate all .txt files in the directory into hex
Post 08 Oct 2021, 13:33
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
Code:
; for /F "usebackq" %%I in (`dir /b *.txt`) do ( echo FileName fix "%%~dpnI.tmp" > temp.inc
;  ren %%~fI %%~nI.tmp
;  fasm %~f0 %%~fI
; )
; del temp.inc
; exit /b 0

  format BINARY
  include "temp.inc"
  virtual
    hexdigit::
    db '0123456789ABCDEF'
  end virtual
  virtual at 0
    source::
       file FileName
    txtfile.Length = $
  end virtual
  repeat txtfile.Length
    if (% - 1) and 15 = 0
      a = % - 1
      repeat 8
        b = a shr (( % - 1 ) * 4
        load b byte from hexdigit:b and 15
        db b
      end if
      db '  '
    end if
    load a byte from source:(%-1)
    load b byte from hexdigit:a shr 4
    load a byte from hexdigit:a and 15
    db b,a,' '
    if (% - 1) and 15 = 0
      a = % - 1 - 16 - 1
      repeat 16
        load b byte from source:a + %
        if b < 32
          db '.'
        else
          db b
        end if
      end repeat
      db 13, 10
    end if
  end repeat
    
save as .bat or .cmd and run

add: formating. . .
Post 08 Oct 2021, 14:17
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
I'll say right now. Of the 3 questions I asked, you answered 2. For 32 and 64-bit Windows, the above code (script) should work the same way.


Last edited by macomics on 08 Oct 2021, 14:41; edited 1 time in total
Post 08 Oct 2021, 14:40
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
Code:
; for /F "usebackq" %%I in (`dir /b *.txt`) do ( echo FileName fix "%%~dpnI.tmp" > temp.inc
;  ren %%~fI %%~nI.tmp
;  fasm %~f0 %%~fI
; )
; del temp.inc
; exit /b 0

  format BINARY
  include "temp.inc"
  virtual
    hexdigit::
    db '0123456789ABCDEF'
  end virtual
  virtual at 0
    source::
       file FileName
    txtfile.Length = $
  end virtual
  repeat txtfile.Length
    if (% - 1) and 15 = 0
      a = % - 1
      repeat 8
        b = a shr (( % - 1 ) * 4
        load b byte from hexdigit:b and 15
        db b
      end if
      db '  '
    end if
    load a byte from sourceSad%-1)
    load b byte from hexdigit:a shr 4
    load a byte from hexdigit:a and 15
    db b,a,' '
    if (% - 1) and 15 = 0
      a = % - 1 - 16 - 1
      repeat 16
        load b byte from source:a + %
        if b < 32
          db '.'
        else
          db b
        end if
      end repeat
      db 13, 10
    end if
  end repeat
    
save as .bat or .cmd and run

add: formating. . .

temp.inc?
Post 08 Oct 2021, 14:40
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
temp.inc is generated by a Windows batch file to pass the parameter to the fasm program. It would be possible to pass the parameter via the -d key, but each command-line system will have different features of operation (when passing quotes). I can't check this script on Windows right now. In the proposed version, it should work without problems.
Post 08 Oct 2021, 14:45
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
temp.inc is generated by a Windows batch file to pass the parameter to the fasm program. It would be possible to pass the parameter via the -d key, but each command-line system will have different features of operation (when passing quotes). I can't check this script on Windows right now. In the proposed version, it should work without problems.

not work, file.txt simply becomes file.tmp without processing
Post 08 Oct 2021, 14:50
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
possible:
Code:
;  fasm %~f0 %%~fI    

change to
Quote:
; fasm "%~f0" "%%~fI"
Post 08 Oct 2021, 14:54
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
temp.inc is generated by a Windows batch file to pass the parameter to the fasm program. It would be possible to pass the parameter via the -d key, but each command-line system will have different features of operation (when passing quotes). I can't check this script on Windows right now. In the proposed version, it should work without problems.

is it possible to do this just using FASM without .bat, .cmd files?
Post 08 Oct 2021, 14:54
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
possible:
Code:
;  fasm %~f0 %%~fI    

change to
Quote:
; fasm "%~f0" "%%~fI"

not work
Post 08 Oct 2021, 14:56
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
possible:
Code:
;  fasm %~f0 %%~fI    

change to
Quote:
; fasm "%~f0" "%%~fI"



Code:
C:\Users\Administrator\Desktop\fasmw17328>test.cmd

C:\Users\Administrator\Desktop\fasmw17328>for /F "usebackq" %I in (`dir /b *.txt`) do (
echo FileName fix "%~dpnI.tmp"  1>temp.inc
 ren %~fI %~nI.tmp
 fasm C:\Users\Administrator\Desktop\fasmw17328\test.cmd %~fI
)

C:\Users\Administrator\Desktop\fasmw17328>(
echo FileName fix "C:\Users\Administrator\Desktop\fasmw17328\test.tmp"  1>temp.inc
 ren C:\Users\Administrator\Desktop\fasmw17328\test.txt test.tmp
 fasm C:\Users\Administrator\Desktop\fasmw17328\test.cmd C:\Users\Administrator\Desktop\fasmw17328\test.txt
)
flat assembler  version 1.73.28  (373941 kilobytes memory)
C:\Users\Administrator\Desktop\fasmw17328\test.cmd [26]:
      end if
processed: end if
error: unexpected instruction.

C:\Users\Administrator\Desktop\fasmw17328>del temp.inc

C:\Users\Administrator\Desktop\fasmw17328>exit /b 0

C:\Users\Administrator\Desktop\fasmw17328>    
Post 08 Oct 2021, 15:04
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
unknown334 wrote:
is it possible to do this just using FASM without .bat, .cmd files?
Solutions for 32-bit and 64-bit Windows will differ slightly in design/definitions.
To search for files, use the FindNextFile[A/W] function in the loop by calling FindFirstFile[A/W] before entering the loop and getting a handle for the search.
To read files, you will need to perform a sequence of actions:
open (CreateFile[A/W](find_data.cFileName, ..., OPEN_EXISTING, ...)), read to the buffer (ReadFile, possibly in a loop), close (CloseHandle).
For each byte from the buffer, it will be necessary to convert each digit of the number. The principle of translation is similar to the one I gave in the script
Code:
 lodsb ; rsi / esi - pointer to text file buffer
; in al - byte, rbx / ebx - pointer to hexdidits
mov ah, al
shr ah, 4
and al, 15
xlatb
rol ax, 8
xlatb
; out ax - HEX string (for example: in al = 0F5h; out ah = 035h e.g. '5', al = 046h e.g. 'F')
stosw ; rdi / edi - pointer to string buffer
...
hexdigits db '0123456789ABCDEF'
    


Last edited by macomics on 08 Oct 2021, 15:21; edited 1 time in total
Post 08 Oct 2021, 15:07
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
ouch. there should be end repeat instead of end if
Post 08 Oct 2021, 15:11
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
ouch. there should be end repeat instead of end if


Code:
 b = a shr (( % - 1 ) * 4    


is now complaining about this
I replaced end if with end repeat
Post 08 Oct 2021, 15:27
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
This is all the points when typing in the browser. There is not enough of a bracket closing at the end.
Quote:
b = a shr (( % - 1 ) * 4 )



ADD line 26:
Code:
 if (% - 1) and 15 = 0    

Should be
Quote:
if (% > 1) & (% - 1) and 15 = 0


Last edited by macomics on 08 Oct 2021, 15:44; edited 1 time in total
Post 08 Oct 2021, 15:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.