Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- format PE console 4.0
- entry start
- ;Help needed below where marked
- include 'win32ax.inc'
- section '.data' data readable writeable
- polynomial dd 0x04C11DB7
- ;polynomial dd 0xEDB88320
- 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%s",10,0
- title db "CRC32 program in Assembly",0
- testcount dd ?
- inputFile dd ?
- numArgs dd ?
- numBytes dd ?
- bytesRead dd ?
- hSrcFile dd ?
- lpBuffer db ?
- htosSTR dd ?
- reflection dd ?
- memPTR dd ?
- filePathArg 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
- ;========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 ;int byte = 0
- xor edx,edx ;remainder = 0
- ;========Allocate Memory For File=
- invoke GlobalAlloc,0,[numBytes]
- mov [memPTR],eax
- ;=========Read Entire File========
- invoke ReadFile,[hSrcFile],[memPTR],[numBytes],bytesRead,0
- ;for(int byte = 0; byte < nBytes; ++byte)
- ;=========CRC32 Algorithm=========
- xor ecx,ecx ;temporary storage for byte
- mov eax,[memPTR]
- mov [remainder],0xFFFFFFFF
- firstfor:
- ;inc ebx
- mov cl,byte [eax+ebx]
- shl ecx,24
- xor [remainder],ecx ; remainder ^= (message[byte]) << (width-8)
- push ecx
- ;for(uint8_t bit = 8; bit > 0; --bit)
- mov ecx,8
- bitbybitfor:
- ;if(remainder & TOPBIT)
- mov edx,[remainder]
- ;HELP NEEDED HERE V HELP NEEDED HERE V HELP NEEDED HERE V HELP NEEDED HERE V HELP NEEDED HERE V
- test edx,edx ;Logical and without modifying registers
- jns not1 ;Checking for odd/even number, equivalent to if (remainder & 80000000h) == 1
- inc [testcount] ;Put for debugging purposes, this count
- ;Changes every time the program is run, why?
- ;HELP NEEDED HERE ^ HELP NEEDED HERE ^ HELP NEEDED HERE ^ HELP NEEDED HERE ^ HELP NEEDED HERE ^
- mov edx,[remainder]
- shl edx,1
- xor edx,[polynomial]
- mov [remainder],eax
- jmp endfor
- ;else
- not1:
- shl [remainder],1
- endfor:
- dec ecx
- cmp ecx,0
- jnz bitbybitfor
- inc ebx
- cmp ebx,[numBytes]
- jnz firstfor
- ;=========Reflection==============
- xor edx,edx
- mov eax,31
- mov ecx,[remainder]
- rfor:
- test ecx,01h
- jnz past
- sub eax,edx
- shl eax,1
- ;mov [reflection],eax
- past:
- shr ecx,1
- inc edx
- cmp edx,32
- jnz rfor
- mov [remainder],eax
- ;=========Final XOR===============
- xor [remainder],0xFFFFFFFF
- ;=========Move Last Calculation===
- ;mov [remainder],edx
- ;=========Hex to String===========
- invoke htos,remainder,htosSTR
- ;=========Flip String=============
- invoke flipDW,htosSTR
- ;=========Print String============
- invoke printf,printResult,htosSTR
- ;=========Stall Exitation=========
- invoke getchar
- ;=========Exit====================
- exit:
- invoke ExitProcess,0
- ;=========File not found==========
- file_not_found:
- invoke printf,fileNotFound
- invoke getchar
- jmp exit
- ;=========Not Enough Args=========
- not_enough_args:
- invoke printf,NEA
- invoke getchar
- jmp exit
- ;=========Imports=================
- section '.idata' import data readable writeable
- library kernel,'KERNEL32.DLL',\
- user,'USER32.DLL',\
- shell,'SHELL32.DLL',\
- msvcrt,'MSVCRT.DLL',\
- stringfuncs,'STRINGFUNCS.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',\
- getchar,'_fgetchar'
- import user,\
- MessageBox,'MessageBoxW'
- import shell,\
- CommandLineToArgvW,'CommandLineToArgvW'
- import stringfuncs,\
- htos,'htos',\
- flipDW,'flipDW'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement