Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
235
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. include 'win32ax.inc'
  5.  
  6. section '.data' data readable writeable
  7. polynomial dd 0x04C11DB7
  8. remainder dd 0
  9.  
  10. fileNotFound db "Error: File Not Found.",10,0
  11. NEA db "Error: No arguements specified",10,0
  12. printResult db "CRC32 of file: 0x%X",10,0
  13. title db "CRC32 program in Assembly",0
  14. filename du "crc32.exe",0
  15.  
  16. inputFile dd ?
  17. numArgs dd ?
  18. numBytes dd ?
  19. bytesRead dd ?
  20. hSrcFile dd ?
  21. lpBuffer db ?
  22. htosSTR dd ?
  23.  
  24. memPTR dd ?
  25.  
  26. section '.text' code readable executable
  27. start:
  28. ;========Set Console Title========
  29. invoke SetConsoleTitleA,title
  30. ;========Get Command Line PTR=====
  31. invoke GetCommandLineW
  32. ;========Parse To Args============
  33. invoke CommandLineToArgvW,eax,numArgs
  34. cmp [numArgs],2
  35. jl not_enough_args
  36. ;========Load Second Arg==========
  37. xor ebx,ebx
  38. mov ebx,[eax+4] ;ptr to second arg
  39. mov [inputFile],ebx
  40.  
  41. no_path_skip:
  42.  
  43. ;========Does File Exist?=========
  44. invoke GetFileAttributes,[inputFile]
  45. cmp eax,-1
  46. je file_not_found
  47. ;========Open File================
  48. invoke CreateFile,[inputFile],GENERIC_READ,FILE_SHARE_READ,0,\
  49.                        OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
  50. cmp eax,3
  51. jnge exit
  52. mov [hSrcFile],eax
  53. ;========Get File Size============
  54. invoke GetFileSize,[hSrcFile],0
  55. mov [numBytes],eax
  56. ;========Clear Registers==========
  57. xor ebx,ebx
  58. xor edx,edx
  59. ;========Allocate Memory For File=
  60. invoke GlobalAlloc,0,[numBytes]
  61. mov [memPTR],eax
  62. ;=========Read Entire File========
  63. invoke ReadFile,[hSrcFile],[memPTR],[numBytes],bytesRead,0
  64. ;=========CRC32 Algorithm=========
  65. xor ecx,ecx
  66.  
  67. mov eax,[memPTR]
  68. mov [remainder],0xFFFFFFFF
  69. firstfor:
  70. mov cl,byte [eax+ebx]
  71. shl ecx,24
  72.  
  73. xor [remainder],ecx
  74. mov ecx,8
  75. bitbybitfor:
  76.  
  77. mov edx,[remainder]
  78.  
  79. test edx,edx
  80. jns not1
  81. mov edx,[remainder]
  82. shl edx,1
  83. xor edx,[polynomial]
  84. mov [remainder],edx
  85. jmp endfor
  86.  
  87. ;else
  88. not1:
  89. shl [remainder],1
  90. endfor:
  91.  
  92. dec ecx
  93. cmp ecx,0
  94. jnz bitbybitfor
  95.  
  96. inc ebx
  97. cmp ebx,[numBytes]
  98. jnz firstfor
  99. ;=========Final XOR===============
  100. xor [remainder],0xFFFFFFFF
  101. ;=========Print String============
  102. invoke printf,printResult,[remainder]
  103. ;=========Exit====================
  104. exit:
  105. invoke ExitProcess,0
  106. ;=========File not found==========
  107. file_not_found:
  108. invoke printf,fileNotFound
  109. jmp exit
  110. ;=========Not Enough Args=========
  111. not_enough_args:
  112. mov eax,filename
  113. mov [inputFile],eax
  114. jmp no_path_skip
  115. ;=========Imports=================
  116. section '.idata' import data readable writeable
  117. library kernel,'KERNEL32.DLL',\
  118.         user,'USER32.DLL',\
  119.         shell,'SHELL32.DLL',\
  120.         msvcrt,'MSVCRT.DLL'
  121. import kernel,\
  122.        SetConsoleTitleA,'SetConsoleTitleA',\
  123.        GetCommandLineW,'GetCommandLineW',\
  124.        CreateFile,'CreateFileW',\
  125.        GlobalAlloc,'GlobalAlloc',\
  126.        ReadFile,'ReadFile',\
  127.        GetFileAttributes,'GetFileAttributesW',\
  128.        GetFileSize,'GetFileSize',\
  129.        SetFilePointer,'SetFilePointer',\
  130.        ExitProcess,'ExitProcess'
  131. import msvcrt,\
  132.         printf,'printf'
  133. import user,\
  134.        MessageBox,'MessageBoxW'
  135. import shell,\
  136.        CommandLineToArgvW,'CommandLineToArgvW'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement