flat assembler
Message board for the users of flat assembler.
Index
> Main > Search files current directory Goto page 1, 2 Next |
Author |
|
unknown334 08 Oct 2021, 12:52
How to find .txt files in the current directory and translate them to string to hex?
Thanks |
|||
08 Oct 2021, 12:52 |
|
macomics 08 Oct 2021, 13:16
dir *.txt -> HIEW -> F4 -> F2
|
|||
08 Oct 2021, 13:16 |
|
unknown334 08 Oct 2021, 13:21
macomics wrote: dir *.txt -> HIEW -> F4 -> F2 I don't understand, can you do it in code? |
|||
08 Oct 2021, 13:21 |
|
unknown334 08 Oct 2021, 13:23
macomics wrote: dir *.txt -> HIEW -> F4 -> F2 the contents of the files must be converted to hex |
|||
08 Oct 2021, 13:23 |
|
unknown334 08 Oct 2021, 13:30
macomics wrote:
FASM, WINDOWS |
|||
08 Oct 2021, 13:30 |
|
unknown334 08 Oct 2021, 13:33
macomics wrote:
After starting the program on Fasm, it should translate all .txt files in the directory into hex |
|||
08 Oct 2021, 13:33 |
|
macomics 08 Oct 2021, 14:17
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 add: formating. . . |
|||
08 Oct 2021, 14:17 |
|
macomics 08 Oct 2021, 14:40
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 |
|||
08 Oct 2021, 14:40 |
|
unknown334 08 Oct 2021, 14:40
macomics wrote:
temp.inc? |
|||
08 Oct 2021, 14:40 |
|
macomics 08 Oct 2021, 14:45
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.
|
|||
08 Oct 2021, 14:45 |
|
unknown334 08 Oct 2021, 14:50
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 |
|||
08 Oct 2021, 14:50 |
|
macomics 08 Oct 2021, 14:54
possible:
Code: ; fasm %~f0 %%~fI change to Quote: ; fasm "%~f0" "%%~fI" |
|||
08 Oct 2021, 14:54 |
|
unknown334 08 Oct 2021, 14:54
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? |
|||
08 Oct 2021, 14:54 |
|
unknown334 08 Oct 2021, 14:56
macomics wrote: possible: not work |
|||
08 Oct 2021, 14:56 |
|
unknown334 08 Oct 2021, 15:04
macomics wrote: possible: 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> |
|||
08 Oct 2021, 15:04 |
|
macomics 08 Oct 2021, 15:07
unknown334 wrote: is it possible to do this just using FASM without .bat, .cmd files? 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 |
|||
08 Oct 2021, 15:07 |
|
macomics 08 Oct 2021, 15:11
ouch. there should be end repeat instead of end if
|
|||
08 Oct 2021, 15:11 |
|
unknown334 08 Oct 2021, 15:27
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 |
|||
08 Oct 2021, 15:27 |
|
macomics 08 Oct 2021, 15:34
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 |
|||
08 Oct 2021, 15:34 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.