flat assembler
Message board for the users of flat assembler.
Index
> Main > search for files in a directory and encoding |
Author |
|
unknown334 20 Jan 2022, 11:57
Hello, FLATASSEMBLER team!
I need to find the first 10 txt files in the directory with the executable file and encode them with the AES algorithm I'm attaching the library I would like variations for windows and for linux
|
|||||||||||
20 Jan 2022, 11:57 |
|
FlierMate 21 Jan 2022, 02:05
Done! Win32 programs modified from your aesexample1.asm.
It finds first 10 *.txt files in the current directory, encode or decode them all.(WARNING: It overwrites existing .txt files) But I notice got a bug, the last few bytes of the text file sometimes not decoded properly...... Hmm.. And it won't work with text file shorter than 48 bytes (TEXTSIZE) Tested on wine (Linux x64). As a side note, there is AES extension set in x86 CPU instruction that you might want to make use of it. EDIT: Please add the following line right before "redo:" label if you have downloaded both .asm file below Code: mov dword [fileptr], 0 redo:
Last edited by FlierMate on 21 Jan 2022, 09:44; edited 1 time in total |
|||||||||||||||||||||
21 Jan 2022, 02:05 |
|
unknown334 21 Jan 2022, 05:28
FlierMate wrote: Done! Win32 programs modified from your aesexample1.asm. perhaps because the size of the source file is different from the encrypted one? |
|||
21 Jan 2022, 05:28 |
|
unknown334 21 Jan 2022, 05:40
FlierMate wrote: Done! Win32 programs modified from your aesexample1.asm. I found an error fix Code: TEXTSIZE equ BLOCK_SIZE replace Code: TEXTSIZE equ 3*BLOCK_SIZE up: no, it still doesn't work... |
|||
21 Jan 2022, 05:40 |
|
FlierMate 21 Jan 2022, 08:16
unknown334 wrote:
I have run multiple tests, the file buffer copying is actually correct, size after = size before, content after = content before. You can redo it using this barebone example: Code: format PE CONSOLE 4.0 entry start include 'include/win32a.inc' TEXTSIZE equ 48 FILELIMIT equ 10 section '.text' code readable executable start: invoke GetStdHandle, -11 mov [stdout], eax invoke lstrcat, buf, filepath call find_files invoke ExitProcess, 0 proc find_files locals hfind dd ? endl invoke FindFirstFile,buf,wfd cmp eax,INVALID_HANDLE_VALUE je exit mov [hfind], eax check: test [wfd.dwFileAttributes],FILE_ATTRIBUTE_DIRECTORY jz found jmp next found: invoke WriteConsole, [stdout], wfd.cFileName, 256, 0, 0 invoke CreateFile, wfd.cFileName, GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 mov dword [fd], eax cmp eax, INVALID_HANDLE_VALUE je quit mov dword [fileptr], 0 redo: invoke SetFilePointer, dword [fd], dword [fileptr], 0, FILE_BEGIN cmp eax, -1 ;INVALID_SET_FILE_POINTER je quit invoke ReadFile, dword [fd], buffer, TEXTSIZE, len, 0 test eax, eax jz quit mov ecx, dword [len] test ecx, ecx jz close ; ;Do something with [buffer] ; invoke SetFilePointer, dword [fd], dword [fileptr], 0, FILE_BEGIN cmp eax, -1 ;INVALID_SET_FILE_POINTER je quit mov ecx, dword [len] add dword [fileptr], ecx invoke WriteFile, dword [fd], buffer, dword [len], 0, 0 jmp redo close: invoke CloseHandle, dword [fd] quit: add [filecount],1 cmp [filecount],FILELIMIT jae exit next: invoke FindNextFile,[hfind],wfd test eax,eax jne check invoke FindClose, [hfind] exit: ret endp section '.data' data readable writeable buf rb 256 filepath db '.\*.txt',0 wfd WIN32_FIND_DATA stdout dd ? filecount dw ? fd dd ? buffer rb TEXTSIZE len dd ? fileptr dd ? section '.idata' import data readable writeable library kernel,'KERNEL32.DLL' import kernel,\ ExitProcess,'ExitProcess',\ WriteConsole, 'WriteConsoleA',\ GetStdHandle,'GetStdHandle', \ FindFirstFile, 'FindFirstFileA',\ FindNextFile, 'FindNextFileA',\ FindClose, 'FindClose',\ CreateFile, 'CreateFileA', \ ReadFile, 'ReadFile', \ WriteFile, 'WriteFile', \ GetLastError, 'GetLastError', \ SetFilePointer, 'SetFilePointer',\ CloseHandle, 'CloseHandle',\ lstrcat,'lstrcatA' Last edited by FlierMate on 21 Jan 2022, 09:37; edited 1 time in total |
|||
21 Jan 2022, 08:16 |
|
unknown334 21 Jan 2022, 08:54
FlierMate wrote:
not work... |
|||
21 Jan 2022, 08:54 |
|
FlierMate 21 Jan 2022, 08:54
I think the read/write of text file must be aligned to BLOCK_SIZE(16 bytes) or TEXTSIZE(48 bytes).... Below is the version which encode with 48-byte alignment, you still use the same decoder, but the decoded text file will have extra characters at the end of file.
The first example of encaes.asm + decaes.asm (text file size doesn't change) Code: d, of the Nullsecurity Proj��� The second example of encaes.asm(V2) + decaes.asm (text file increased to be 48-byte aligned) Code: d, of the Nullsecurity Project.pressed or i So it is like apple and orange. I give up, maybe someone more skillful should give it a try.
Last edited by FlierMate on 21 Jan 2022, 09:10; edited 1 time in total |
|||||||||||
21 Jan 2022, 08:54 |
|
FlierMate 21 Jan 2022, 08:57
unknown334 wrote:
Yes, this barebone example will write what it read, so you would notice no difference after running it. Just meant for testing its accuracy of read/write. Perhaps we should reset the file pointer: Code: mov dword [fileptr], 0 redo: |
|||
21 Jan 2022, 08:57 |
|
unknown334 21 Jan 2022, 09:20
FlierMate wrote:
Thanks , Work |
|||
21 Jan 2022, 09:20 |
|
FlierMate 21 Jan 2022, 09:29
unknown334 wrote:
You're welcome! But I am shocked, the wine (windows emulator) in Linux did not give any error. |
|||
21 Jan 2022, 09:29 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.