flat assembler
Message board for the users of flat assembler.
Index
> Windows > Help with this, WriteFile everytime returns bool false |
Author |
|
wisepenguin 29 Sep 2006, 17:37
ive just done a check and it fails at the first ReadFile on my
comp |
|||
29 Sep 2006, 17:37 |
|
OzzY 29 Sep 2006, 17:40
BytesWritten should be declared as doubleword (dd).
Take a look: Code: format PE GUI entry start include 'win32ax.inc' section '.code' code readable executable start: mov [ofn.lStructSize],sizeof.OPENFILENAME mov [ofn.hwndOwner],0 mov [ofn.hInstance],eax mov [ofn.lpstrCustomFilter],NULL mov [ofn.nFilterIndex],1 mov [ofn.nMaxFile],1000h mov [ofn.lpstrFileTitle],name_buffer mov [ofn.nMaxFileTitle],100h mov [ofn.lpstrInitialDir],NULL mov [ofn.lpstrDefExt],file_extension mov [ofn.lpstrFile],path_buffer mov [path_buffer],byte 0 mov [ofn.lpstrFilter],file_filter mov [ofn.Flags],OFN_EXPLORER+OFN_ALLOWMULTISELECT+OFN_FILEMUSTEXIST+OFN_HIDEREADONLY mov [ofn.lpstrFileTitle],name_buffer mov [ofn.lpstrTitle],NULL invoke GetOpenFileName,ofn invoke CreateFile,name_buffer,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL cmp eax,INVALID_HANDLE_VALUE jne @f jmp Exit @@: mov [HANDLE],eax ;invoke GetFileSize,eax,FileSizeHigh invoke GetFileSize,eax,0 ;can be just NULL cmp eax,-1 jne @f jmp Exit @@: invoke ReadFile, dword[HANDLE], FileBuffer, eax, BytesRead, NULL test eax,eax jnz @f jmp Exit @@: invoke CloseHandle,dword [HANDLE] test eax,eax jnz @f jmp Exit @@: invoke CreateFile,DestFileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL cmp eax,-1 jne @f jmp Exit @@: mov [HANDLE],eax invoke WriteFile,eax,FileBuffer,$168000,BytesWritten,NULL test eax,eax jnz @f jmp Exit @@: invoke CloseHandle,dword[HANDLE] Exit: invoke ExitProcess,0 section '.data' data readable writable ofn OPENFILENAME file_extension db 'BIN',0 file_filter: db 'Binary Files',0,'*.BIN;*.286',0 db 'All files',0,'*.*',0 db 0 DestFileName db 'mykernel.bin',0 align 4 ; You should use dd to reserve space to write integer numbers ;HANDLE = $ ;FileSizeLow = HANDLE+4 ;FileSizeHigh = FileSizeLow+4 ;BytesRead = FileSizeHigh+4 ;BytesWritten = BytesRead+4 ;name_buffer = BytesWritten+4 ;path_buffer = name_buffer+100h ;FileBuffer = path_buffer+1000h HANDLE dd 0 ;Dword-sized to store the File Handle BytesRead dd 0 ;The API will store the bytes read BytesWritten dd 0 ;The API will store the bytes written ;name_buffer, path_buffer and FileBuffer must be Dynamic Allocated in your program source-code. Check MSDN for GlobalAlloc() API. ;If you don't want dynamic allocated, you should specify fixex-size reserved data: ;FileBuffer rb 2000 ; Will reserve 2000 bytes section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ comdlg32,'COMDLG32.DLL' include 'apia\kernel32.inc' include 'apia\user32.inc' include 'apia\comdlg32.inc' Not fully working. You need to add the code to dynamic allocate space for the data. But I think you'll get the idea. If you have any questions post here. |
|||
29 Sep 2006, 17:40 |
|
OzzY 29 Sep 2006, 18:24
Not working here. It's very strange problem.
If someone knows how to fix it, please post. I'm curious. |
|||
29 Sep 2006, 18:24 |
|
wisepenguin 29 Sep 2006, 18:29
i posted a working version but deleted it when i seen that you posted a version
i will find it and post it in a jiffy. all i changed was the variable declarations like you did and $ to 0x Last edited by wisepenguin on 29 Sep 2006, 18:30; edited 1 time in total |
|||
29 Sep 2006, 18:29 |
|
wisepenguin 29 Sep 2006, 18:29
Code: format PE GUI entry start include 'win32ax.inc' section '.code' code readable executable start: mov [ofn.lStructSize],sizeof.OPENFILENAME mov [ofn.hwndOwner],0 mov [ofn.hInstance],eax mov [ofn.lpstrCustomFilter],NULL mov [ofn.nFilterIndex],1 mov [ofn.nMaxFile],1000h mov [ofn.lpstrFileTitle],name_buffer mov [ofn.nMaxFileTitle],100h mov [ofn.lpstrInitialDir],NULL mov [ofn.lpstrDefExt],file_extension mov [ofn.lpstrFile],path_buffer mov [path_buffer],byte 0 mov [ofn.lpstrFilter],file_filter mov [ofn.Flags],OFN_EXPLORER+OFN_ALLOWMULTISELECT+OFN_FILEMUSTEXIST+OFN_HIDEREADONLY mov [ofn.lpstrFileTitle],name_buffer mov [ofn.lpstrTitle],NULL invoke GetOpenFileName,ofn invoke CreateFile,name_buffer,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL cmp eax,INVALID_HANDLE_VALUE jne @f jmp Exit @@: mov [HANDLE],eax invoke GetFileSize,eax,FileSizeHigh cmp eax,-1 jne @f jmp Exit @@: invoke ReadFile, dword[HANDLE], FileBuffer, eax, BytesRead, NULL test eax,eax jnz @f jmp Exit @@: invoke CloseHandle,dword [HANDLE] test eax,eax jnz @f jmp Exit @@: invoke CreateFile,DestFileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL cmp eax,-1 jne @f jmp Exit @@: mov [HANDLE],eax invoke WriteFile,eax,FileBuffer,0x168000,BytesWritten,NULL test eax,eax jnz @f jmp Exit @@: invoke CloseHandle,dword[HANDLE] Exit: invoke ExitProcess,0 section '.data' data readable writable ofn OPENFILENAME file_extension db 'BIN',0 file_filter: db 'Binary Files',0,'*.BIN;*.286',0 db 'All files',0,'*.*',0 db 0 DestFileName db 'mykernel.bin',0 align 4 HANDLE rd 1 ;HANDLE = $ FileSizeLow rd 1 ;FileSizeLow = HANDLE+4 FileSizeHigh rd 1 ;FileSizeHigh = FileSizeLow+4 BytesRead rd 1 ;BytesRead = FileSizeHigh+4 BytesWritten rd 1 ;BytesWritten = BytesRead+4 name_buffer rb 256 ;name_buffer = BytesWritten+4 path_buffer rb 256 ;path_buffer = name_buffer+100h FileBuffer rb 0x168000 * 10 ; reserves 10 floppy disks of space, FileBuffer = path_buffer+1000h section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ comdlg32,'COMDLG32.DLL' include 'apia\kernel32.inc' include 'apia\user32.inc' include 'apia\comdlg32.inc' |
|||
29 Sep 2006, 18:29 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.