Advertisement
Guest User

Untitled

a guest
Jul 21st, 2014
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. format PE console 4.0
  2. entry start
  3.  
  4. ;Help needed below where marked
  5.  
  6. include 'win32ax.inc'
  7.  
  8. section '.data' data readable writeable
  9. polynomial dd 0x04C11DB7
  10. ;polynomial dd 0xEDB88320
  11. remainder dd 0
  12.  
  13. fileNotFound db "Error: File Not Found.",10,0
  14. NEA db "Error: No arguements specified",10,0
  15. printResult db "CRC32 of file: 0x%s",10,0
  16. title db "CRC32 program in Assembly",0
  17.  
  18. testcount dd ?
  19.  
  20. inputFile dd ?
  21. numArgs dd ?
  22. numBytes dd ?
  23. bytesRead dd ?
  24. hSrcFile dd ?
  25. lpBuffer db ?
  26. htosSTR dd ?
  27. reflection dd ?
  28.  
  29. memPTR dd ?
  30.  
  31. filePathArg dd ?
  32.  
  33. section '.text' code readable executable
  34. start:
  35. ;========Set Console Title========
  36. invoke SetConsoleTitleA,title
  37. ;========Get Command Line PTR=====
  38. invoke GetCommandLineW
  39. ;========Parse To Args============
  40. invoke CommandLineToArgvW,eax,numArgs
  41. cmp [numArgs],2
  42. jl not_enough_args
  43. ;========Load Second Arg==========
  44. xor ebx,ebx
  45. mov ebx,[eax+4] ;ptr to second arg
  46. mov [inputFile],ebx
  47. ;========Does File Exist?=========
  48. invoke GetFileAttributes,[inputFile]
  49. cmp eax,-1
  50. je file_not_found
  51. ;========Open File================
  52. invoke CreateFile,[inputFile],GENERIC_READ,FILE_SHARE_READ,0,\
  53.                        OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
  54. cmp eax,3
  55. jnge exit
  56. mov [hSrcFile],eax
  57. ;========Get File Size============
  58. invoke GetFileSize,[hSrcFile],0
  59. mov [numBytes],eax
  60. ;========Clear Registers==========
  61. xor ebx,ebx ;int byte = 0
  62. xor edx,edx ;remainder = 0
  63. ;========Allocate Memory For File=
  64. invoke GlobalAlloc,0,[numBytes]
  65. mov [memPTR],eax
  66. ;=========Read Entire File========
  67. invoke ReadFile,[hSrcFile],[memPTR],[numBytes],bytesRead,0
  68. ;for(int byte = 0; byte < nBytes; ++byte)
  69. ;=========CRC32 Algorithm=========
  70. xor ecx,ecx ;temporary storage for byte
  71.  
  72. mov eax,[memPTR]
  73. mov [remainder],0xFFFFFFFF
  74. firstfor:
  75. ;inc ebx
  76. mov cl,byte [eax+ebx]
  77. shl ecx,24
  78.  
  79. xor [remainder],ecx ; remainder ^= (message[byte]) << (width-8)
  80.  
  81. push ecx
  82. ;for(uint8_t bit = 8; bit > 0; --bit)
  83. mov ecx,8
  84. bitbybitfor:
  85.  
  86. ;if(remainder & TOPBIT)
  87. mov edx,[remainder]
  88.  
  89. ;HELP NEEDED HERE V HELP NEEDED HERE V HELP NEEDED HERE V HELP NEEDED HERE V HELP NEEDED HERE V
  90. test edx,edx          ;Logical and without modifying registers
  91. jns not1          ;Checking for odd/even number, equivalent to if (remainder & 80000000h) == 1
  92. inc [testcount]       ;Put for debugging purposes, this count
  93.                       ;Changes every time the program is run, why?
  94. ;HELP NEEDED HERE ^ HELP NEEDED HERE ^ HELP NEEDED HERE ^ HELP NEEDED HERE ^ HELP NEEDED HERE ^
  95.  
  96. mov edx,[remainder]
  97. shl edx,1
  98. xor edx,[polynomial]
  99. mov [remainder],eax
  100. jmp endfor
  101.  
  102. ;else
  103. not1:
  104. shl [remainder],1
  105. endfor:
  106.  
  107. dec ecx
  108. cmp ecx,0
  109. jnz bitbybitfor
  110.  
  111. inc ebx
  112. cmp ebx,[numBytes]
  113. jnz firstfor
  114. ;=========Reflection==============
  115. xor edx,edx
  116. mov eax,31
  117. mov ecx,[remainder]
  118. rfor:
  119.  
  120. test ecx,01h
  121.  
  122. jnz past
  123. sub eax,edx
  124. shl eax,1
  125. ;mov [reflection],eax
  126. past:
  127. shr ecx,1
  128.  
  129. inc edx
  130. cmp edx,32
  131. jnz rfor
  132. mov [remainder],eax
  133. ;=========Final XOR===============
  134. xor [remainder],0xFFFFFFFF
  135. ;=========Move Last Calculation===
  136. ;mov [remainder],edx
  137. ;=========Hex to String===========
  138. invoke htos,remainder,htosSTR
  139. ;=========Flip String=============
  140. invoke flipDW,htosSTR
  141. ;=========Print String============
  142. invoke printf,printResult,htosSTR
  143. ;=========Stall Exitation=========
  144. invoke getchar
  145. ;=========Exit====================
  146. exit:
  147. invoke ExitProcess,0
  148. ;=========File not found==========
  149. file_not_found:
  150. invoke printf,fileNotFound
  151. invoke getchar
  152. jmp exit
  153. ;=========Not Enough Args=========
  154. not_enough_args:
  155. invoke printf,NEA
  156. invoke getchar
  157. jmp exit
  158. ;=========Imports=================
  159. section '.idata' import data readable writeable
  160. library kernel,'KERNEL32.DLL',\
  161.         user,'USER32.DLL',\
  162.         shell,'SHELL32.DLL',\
  163.         msvcrt,'MSVCRT.DLL',\
  164.         stringfuncs,'STRINGFUNCS.DLL'
  165. import kernel,\
  166.        SetConsoleTitleA,'SetConsoleTitleA',\
  167.        GetCommandLineW,'GetCommandLineW',\
  168.        CreateFile,'CreateFileW',\
  169.        GlobalAlloc,'GlobalAlloc',\
  170.        ReadFile,'ReadFile',\
  171.        GetFileAttributes,'GetFileAttributesW',\
  172.        GetFileSize,'GetFileSize',\
  173.        SetFilePointer,'SetFilePointer',\
  174.        ExitProcess,'ExitProcess'
  175. import msvcrt,\
  176.         printf,'printf',\
  177.         getchar,'_fgetchar'
  178. import user,\
  179.        MessageBox,'MessageBoxW'
  180. import shell,\
  181.        CommandLineToArgvW,'CommandLineToArgvW'
  182. import stringfuncs,\
  183.        htos,'htos',\
  184.        flipDW,'flipDW'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement