Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- format PE console 4.0
- entry start
- include 'win32ax.inc'
- section '.data' data readable writeable
- polynomial dd 0x04C11DB7
- remainder dd 0
- fileNotFound db "Error: File Not Found.",10,0
- NEA db "Error: No arguements specified",10,0
- printResult db "CRC32 of file: 0x%X",10,0
- title db "CRC32 program in Assembly",0
- filename du "crc32.exe",0
- inputFile dd ?
- numArgs dd ?
- numBytes dd ?
- bytesRead dd ?
- hSrcFile dd ?
- lpBuffer db ?
- htosSTR dd ?
- memPTR dd ?
- section '.text' code readable executable
- start:
- ;========Set Console Title========
- invoke SetConsoleTitleA,title
- ;========Get Command Line PTR=====
- invoke GetCommandLineW
- ;========Parse To Args============
- invoke CommandLineToArgvW,eax,numArgs
- cmp [numArgs],2
- jl not_enough_args
- ;========Load Second Arg==========
- xor ebx,ebx
- mov ebx,[eax+4] ;ptr to second arg
- mov [inputFile],ebx
- no_path_skip:
- ;========Does File Exist?=========
- invoke GetFileAttributes,[inputFile]
- cmp eax,-1
- je file_not_found
- ;========Open File================
- invoke CreateFile,[inputFile],GENERIC_READ,FILE_SHARE_READ,0,\
- OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
- cmp eax,3
- jnge exit
- mov [hSrcFile],eax
- ;========Get File Size============
- invoke GetFileSize,[hSrcFile],0
- mov [numBytes],eax
- ;========Clear Registers==========
- xor ebx,ebx
- xor edx,edx
- ;========Allocate Memory For File=
- invoke GlobalAlloc,0,[numBytes]
- mov [memPTR],eax
- ;=========Read Entire File========
- invoke ReadFile,[hSrcFile],[memPTR],[numBytes],bytesRead,0
- ;=========CRC32 Algorithm=========
- xor ecx,ecx
- mov eax,[memPTR]
- mov [remainder],0xFFFFFFFF
- firstfor:
- mov cl,byte [eax+ebx]
- shl ecx,24
- xor [remainder],ecx
- mov ecx,8
- bitbybitfor:
- mov edx,[remainder]
- test edx,edx
- jns not1
- mov edx,[remainder]
- shl edx,1
- xor edx,[polynomial]
- mov [remainder],edx
- jmp endfor
- ;else
- not1:
- shl [remainder],1
- endfor:
- dec ecx
- cmp ecx,0
- jnz bitbybitfor
- inc ebx
- cmp ebx,[numBytes]
- jnz firstfor
- ;=========Final XOR===============
- xor [remainder],0xFFFFFFFF
- ;=========Print String============
- invoke printf,printResult,[remainder]
- ;=========Exit====================
- exit:
- invoke ExitProcess,0
- ;=========File not found==========
- file_not_found:
- invoke printf,fileNotFound
- jmp exit
- ;=========Not Enough Args=========
- not_enough_args:
- mov eax,filename
- mov [inputFile],eax
- jmp no_path_skip
- ;=========Imports=================
- section '.idata' import data readable writeable
- library kernel,'KERNEL32.DLL',\
- user,'USER32.DLL',\
- shell,'SHELL32.DLL',\
- msvcrt,'MSVCRT.DLL'
- import kernel,\
- SetConsoleTitleA,'SetConsoleTitleA',\
- GetCommandLineW,'GetCommandLineW',\
- CreateFile,'CreateFileW',\
- GlobalAlloc,'GlobalAlloc',\
- ReadFile,'ReadFile',\
- GetFileAttributes,'GetFileAttributesW',\
- GetFileSize,'GetFileSize',\
- SetFilePointer,'SetFilePointer',\
- ExitProcess,'ExitProcess'
- import msvcrt,\
- printf,'printf'
- import user,\
- MessageBox,'MessageBoxW'
- import shell,\
- CommandLineToArgvW,'CommandLineToArgvW'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement