flat assembler
Message board for the users of flat assembler.
Index
> Windows > Files.! |
Author |
|
AsmER 01 Jan 2007, 21:20
Here's the converted source file:
Code: .386 .model flat, stdcall option casemap :none include \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc include \masm32\include\comdlg32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\comdlg32.lib ;// Data section .data ;// Initialized data ofn_szFilter db 'All Files (*.*)',0,'*.*',0,0 FILE_EMPTY_MSG db 'File is empty, nothing to convert.',0 FILE_TOO_BIG_MSG db 'File is too big, please specify a smaller file.',0 UNKNOWN_ERR_MSG db 'Unknow error occured.',0 MEM_ERR_MSG db 'Unable to allocate memory.',0 RES_ERR_MSG db 'Low Resource',0 SUCCESS_MSG db 'File conversion completed successfuly',0 COMPLETED_MSG db 'Complete',0 ABORT_MSG db 'Abort',0 ERROR_MSG db 'Error',0 dwWritten dd 0 s_OFN OPENFILENAME <0,0,0,ofn_szFilter,0,0,0,ofn_szOutFile,0100h,0,0,0,0,OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST, 0,0,0,0,0,0> ;// Uninitialized memory after initialized data (makes output smaller) s_ErrorMessage db 256 dup(?) ofn_szOutFile db 256 dup(?) ;// Code section .code Start: ;// MAIN CODE main proc ;// File Handle Holder LOCAL hFileHandle:DWORD ;// Get File Size LOCAL iFileSize:DWORD LOCAL i:DWORD LOCAL hHeap:DWORD LOCAL dLastError:DWORD LOCAL pData: DWORD ;// I is out counter ;// Initialize OFN Struct mov s_OFN.lStructSize, sizeof OPENFILENAME invoke GetOpenFileName, ADDR s_OFN cmp eax,0 ;// Zero is returned when user closes the dialog of presses cancel je ExitProcess_JUMP ;// We have the file, open it and convert invoke CreateFile, ADDR ofn_szOutFile,GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ, \ 0,OPEN_EXISTING,0,0 cmp eax, INVALID_HANDLE_VALUE jne @F ;// Jump to the next @@ label ;// We have a wrong handle, Tell the user, then exit call GET_LAST_ERROR_PROC invoke ExitProcess,0 ;//------------------------------- Handle valid, continue @@: mov hFileHandle,eax invoke GetFileSize,hFileHandle,0 mov iFileSize,eax cmp iFileSize,0 je InvalidFileSize cmp iFileSize,40*1024*1024 ;// Set our limit to 40MB, since usuall RAM's these day are alteast 128MB ;// And, our paging is also active jg FileTooBig jmp StartConversion ;// Invalid File Size, File too big, InvalidFileSize: invoke MessageBox,0, ADDR FILE_EMPTY_MSG,ADDR ABORT_MSG,16 invoke CloseHandle, hFileHandle invoke ExitProcess,0 FileTooBig: invoke MessageBox,0,ADDR FILE_TOO_BIG_MSG,ADDR ABORT_MSG,16 invoke CloseHandle, hFileHandle invoke ExitProcess,0 ;// FileSize valid, start conversion StartConversion: ;// Allocate pData equal to file size invoke GetProcessHeap mov hHeap ,eax cmp eax,0 jne @f ;// Error invoke MessageBox,0,ADDR UNKNOWN_ERR_MSG,ADDR ABORT_MSG,0 invoke CloseHandle, hFileHandle invoke ExitProcess,0 ;// We have the HEAP @@: invoke HeapAlloc,hHeap,0,iFileSize cmp eax,0 jne @f ;// Memory allocation failed invoke MessageBox,0,ADDR MEM_ERR_MSG,ADDR RES_ERR_MSG,16 invoke CloseHandle,hFileHandle invoke ExitProcess,0 ;// We have the memory @@: mov pData,eax ;// Read the file invoke ReadFile,hFileHandle,pData,iFileSize, ADDR dwWritten,0 ;// Note that dwWritten is not used in this function cmp eax,0 jne @f call GET_LAST_ERROR_PROC invoke HeapFree, hHeap,0,pData invoke CloseHandle,hFileHandle invoke ExitProcess,0 ;Continue, file read successful @@: mov i,0 mov ebx,pData ;// Start of Loop ConversionLoop: ;// Check i mov eax,i cmp eax,iFileSize jge ExitLoop ;// Check for case mov al,byte ptr [ebx] mov ah,0 cmp al, 'Z' ja @f cmp al, 'A' jb @f add al,0x20 mov byte [ebx],al jmp @END @@: cmp al, 'z' ja .@END cmp al, 'a' jb @END sub al,0x20 mov byte [ebx],al @END: ;// Increase i and repeat inc ebx inc i jmp ConversionLoop ;// End of Loop ExitLoop: ;// Write to file invoke SetFilePointer,hFileHandle,0,0,FILE_BEGIN invoke WriteFile,hFileHandle,pData,iFileSize, ADDR dwWritten,0 ;// Note that dwWritten is not used in this function cmp eax,0 jne @f ;// File Write Failed call GET_LAST_ERROR_PROC invoke HeapFree,hHeap,0,pData invoke CloseHandle,hFileHandle invoke ExitProcess,0 ;// End of our process @@: invoke MessageBox,0,ADDR SUCCESS_MSG,ADDR COMPLETED_MSG,64 ;// Release Memory invoke HeapFree,hHeap,0,pData ;//------------------------------- Close the file invoke CloseHandle,hFileHandle ;// Terminate APP ExitProcess_JUMP: invoke ExitProcess,0 main endp ;// GetLastError Procedures finds the failure reason in system-level GET_LAST_ERROR_PROC proc invoke GetLastError invoke FormatMessage,FORMAT_MESSAGE_FROM_SYSTEM,0,eax,0,ADDR s_ErrorMessage,256,0 invoke MessageBox,0,s_ErrorMessage,ERROR_MSG,16 GET_LAST_ERROR_PROC endp end Start Regards |
|||
01 Jan 2007, 21:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.