Guest User

Untitled

a guest
Feb 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. extern __imp__MessageBoxA@16
  2. extern __imp__wsprintfA
  3. extern __imp__ExitProcess@4
  4. global start
  5. section .text
  6. putflagPlus:
  7. mov byte[flags], 1
  8. jz flag
  9. putflagMinus:
  10. mov byte[flags + 1], 1
  11. jz flag
  12. putflagHashCode:
  13. mov byte[flags + 2], 1
  14. jz flag
  15. putflagZero:
  16. mov byte[flags + 3], 1
  17. jz flag
  18.  
  19. percent:
  20. inc esi
  21. cmp byte[esi], '+'
  22. jz putflagPlus
  23. cmp byte[esi], '-'
  24. jz putflagMinus
  25. cmp byte[esi], '#'
  26. jz putflagHashCode
  27. cmp byte[esi], '0'
  28. jz putflagZero
  29. mov edx, [esi]
  30. sub edx, 48
  31. cmp edx, 9
  32. jbe digit
  33. cmp byte[esi], '.'
  34. jz point
  35. cmp byte[esi], 'd'
  36. jz formatD
  37. cmp byte[esi], 'i'
  38. jz formatI
  39. cmp byte[esi], 'x'
  40. jz formatX
  41. cmp byte[esi], 's'
  42. jz formatS
  43. cmp byte[esi], 'c'
  44. jz formatC
  45. cmp byte[esi], 'h'
  46. jz lenh
  47. cmp byte[esi], 'l'
  48. jz lenl
  49. cmp byte[esi], 'L'
  50. jz lenL
  51. flag:
  52. inc esi
  53. jmp percent
  54.  
  55.  
  56. digit:
  57. mov ecx, 0
  58. mov edx, [esi]
  59. sub edx, 48
  60. cmp edx, 9
  61. jbe cycleDigit
  62. cycleDigit:
  63. mov [wid + ecx], edx
  64. inc ecx
  65. inc esi
  66. jmp digit
  67. cmp byte[esi], 'd'
  68. jz formatD
  69. cmp byte[esi], 'i'
  70. jz formatI
  71. cmp byte[esi], 'x'
  72. jz formatX
  73. cmp byte[esi], 's'
  74. jz formatS
  75. cmp byte[esi], 'c'
  76. jz formatC
  77. cmp byte[esi], 'h'
  78. jz lenh
  79. cmp byte[esi], 'l'
  80. jz lenl
  81. cmp byte[esi], 'L'
  82. jz lenL
  83. lenh:
  84. mov byte[lengths], 1
  85. inc esi
  86. jmp len
  87. lenL:
  88. mov byte[lengths + 1], 1
  89. inc esi
  90. jmp len
  91. lenl:
  92. mov byte[lengths + 2], 1
  93. inc esi
  94. jmp len
  95. len:
  96. cmp byte[esi], 'd'
  97. jz formatD
  98. cmp byte[esi], 'i'
  99. jz formatI
  100. cmp byte[esi], 'x'
  101. jz formatX
  102. cmp byte[esi], 's'
  103. jz formatS
  104. cmp byte[esi], 'c'
  105. jz formatC
  106. point:
  107. jmp toDigitPrecision
  108.  
  109. toDigitPrecision:
  110. inc esi
  111. mov ecx, 0
  112. mov edx, [esi]
  113. sub edx, 48
  114. cmp edx, 9
  115. jbe cycleDigitPrecision
  116. cycleDigitPrecision:
  117. mov [precision + ecx], edx
  118. inc ecx
  119. jmp toDigitPrecision
  120. cmp byte[esi], 'd'
  121. jz formatD
  122. cmp byte[esi], 'i'
  123. jz formatI
  124. cmp byte[esi], 'x'
  125. jz formatX
  126. cmp byte[esi], 's'
  127. jz formatS
  128. cmp byte[esi], 'c'
  129. jz formatC
  130. cmp byte[esi], 'h'
  131. jz lenh
  132. cmp byte[esi], 'l'
  133. jz lenl
  134. cmp byte[esi], 'L'
  135. jz lenL
  136.  
  137. formatS:
  138. mov edx, 0
  139. mov ecx, [parameters]
  140. step:
  141. cmp byte[ecx + edx], 0
  142. jz normal
  143. mov edi, [ecx + edx]
  144. mov [buf + edx], edi
  145. jmp step
  146. cmp word[esi], 0
  147. jnz normal
  148. formatC:
  149. formatD:
  150. formatI:
  151. formatX:
  152.  
  153. normal:
  154. mov byte[lengths], 0
  155. mov byte[lengths + 1], 0
  156. mov byte[lengths + 2], 0
  157. mov byte[flags], 0
  158. mov byte[flags + 1], 0
  159. mov byte[flags + 2], 0
  160. mov byte[flags + 3], 0
  161. jmp percent
  162. sprintf:
  163. push esi
  164. push edi
  165. push ebx
  166. push ebp
  167. mov ebp, esp
  168. sub esp, 24; width(8), precision(12), len(16), flag
  169. wid equ ebp - 12 ; 4 bytes
  170. precision equ ebp - 16 ; 4 bytes
  171. parameters equ ebp + 16; 4 bytes
  172. lengths equ ebp - 8; 4 bytes
  173. buf equ ebp + 8
  174. flags equ ebp - 4
  175. mov esi, [ebp + 12]
  176. jmp normal
  177. start:
  178. push s
  179. push f
  180. push res
  181. call sprintf
  182. pop eax
  183. pop ebx
  184. pop ecx
  185. push 0
  186. push prog_title
  187. push res
  188. push 0
  189. call [__imp__MessageBoxA@16]
  190.  
  191. push 0
  192. call [__imp__ExitProcess@4]
  193. section .data
  194. res db " ",0
  195. section .rodata
  196. prog_title db "sprintf",0
  197. f db "%s",0
  198. s db "Hello",0
  199. end
Add Comment
Please, Sign In to add comment