Foro de elhacker.net

Programación => ASM => Mensaje iniciado por: Krackwar ™ en 11 Marzo 2009, 16:36 pm



Título: EOFEXTRACT - Funcion para extraer el EOF
Publicado por: Krackwar ™ en 11 Marzo 2009, 16:36 pm
Código
  1. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  2. ;@                                     @
  3. ;@   EOFEXTRACT by krackwar            @
  4. ;@   krackwar@hotmail.com              @
  5. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  6. include 'win32ax.inc'
  7. .code
  8. start:
  9. stdcall EOFEXTRACT,"C:\archivo.exe"
  10. xor ebx,ebx
  11. mov ebx,eax
  12. invoke GlobalAlloc,GPTR,4
  13. push eax
  14. invoke wsprintf,eax,"0x%x",ebx
  15. pop eax
  16. push eax
  17. invoke MessageBox,0,eax,"EOF data",0
  18. pop eax
  19.  
  20. invoke GlobalFree,eax
  21. invoke ExitProcess,0
  22. proc EOFEXTRACT,ruta
  23. locals
  24.    DireccionPE dd ?
  25.    bUsados dd ?
  26.    PE dd ?
  27.    NumeroSecciones dd ?
  28.    BeginLastSection   dd ?
  29.    hFile   dd ?
  30.    EOF dd ?
  31.    tamAr   dd ?
  32.    PointerToRawData dd ?
  33.    IB      dd ?
  34.    SizeOfRawData dd ?
  35. endl
  36. invoke  CreateFile, [ruta], GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0
  37. mov [hFile], eax
  38. invoke  GetFileSize, [hFile], 0
  39. mov [tamAr], eax
  40. invoke  GlobalAlloc, GPTR, eax
  41. mov [IB], eax
  42. invoke  ReadFile, [hFile], [IB], [tamAr], addr bUsados, 0
  43. mov ebx ,[IB]
  44. add ebx, 0x3c
  45. mov eax,dword[ebx]
  46. mov [DireccionPE] ,eax
  47. xor ebx,ebx
  48. mov ebx,[IB]
  49. add ebx,eax
  50. mov [PE],ebx
  51. add ebx,0x6
  52. xor edx,edx
  53. mov dx,word[ebx]
  54. mov [NumeroSecciones],edx
  55. mov eax,$28
  56. mov ebx,[NumeroSecciones]
  57. dec ebx
  58. mul ebx
  59. xor edx,edx
  60. mov edx,[DireccionPE]
  61. add edx,$F8
  62. add edx,eax
  63. mov [BeginLastSection],edx
  64. xor eax,eax
  65. xor ebx,ebx
  66. xor edx,edx
  67. mov eax,[IB]
  68. mov edx,[BeginLastSection]
  69. add eax,edx
  70. add eax,16
  71. mov ebx,DWORD[eax]
  72. mov [SizeOfRawData],ebx
  73. add eax,4
  74. xor ebx,ebx
  75. mov ebx,DWORD[eax]
  76. mov [PointerToRawData],ebx
  77. xor ebx,ebx
  78. xor eax,eax
  79. mov  edx, [PointerToRawData]
  80. mov ebx,[SizeOfRawData]
  81. add ebx,edx
  82. mov [EOF],ebx
  83. mov eax,[EOF]
  84. ret
  85. endp
  86.  
  87. .end start

Gracias a E0N ya que me apoye en un codigo de el en visual basic :P


Título: Re: EOFEXTRACT - Funcion para extraer el EOF
Publicado por: Krackwar ™ en 11 Marzo 2009, 19:26 pm
Modifique un  poco este mismo source para que agregue todo lo que este en el EOF lo agregue a la ultima sección, la función esta ultima dse puede mejorar mucho pero mas rato lo paso en "limpio" devuelve el archivo modificado en eax , el tamaño en ebx y el handle en edx .

Código
  1. proc KillEOF,ruta
  2. locals
  3. SizeOfRawDataAumentado dd ?
  4.    DireccionPE dd ?
  5.    bUsados dd ?
  6.    TamañoEOF dd ?
  7.    PE dd ?
  8.    NumeroSecciones dd ?
  9.    BeginLastSection   dd ?
  10.    hFile   dd ?
  11.    EOF dd ?
  12.    tamAr   dd ?
  13.    PointerToRawData dd ?
  14.    IB      dd ?
  15.    SizeOfRawData dd ?
  16.    Virualsize dd ?
  17.    VirualsizeAumentado dd ?
  18. endl
  19. invoke  CreateFile, [ruta], GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0
  20. mov [hFile], eax
  21. invoke  GetFileSize, [hFile], 0
  22. mov [tamAr], eax
  23. invoke  GlobalAlloc, GPTR, eax
  24. mov [IB], eax
  25. invoke  ReadFile, [hFile], [IB], [tamAr], addr bUsados, 0
  26. mov ebx ,[IB]
  27. add ebx, 0x3c
  28. mov eax,dword[ebx]
  29. mov [DireccionPE] ,eax
  30. xor ebx,ebx
  31. mov ebx,[IB]
  32. add ebx,eax
  33. mov [PE],ebx
  34. add ebx,0x6
  35. xor edx,edx
  36. mov dx,word[ebx]
  37. mov [NumeroSecciones],edx
  38. mov eax,$28
  39. mov ebx,[NumeroSecciones]
  40. dec ebx
  41. mul ebx
  42. xor edx,edx
  43. mov edx,[DireccionPE]
  44. add edx,$F8
  45. add edx,eax
  46. mov [BeginLastSection],edx
  47. xor eax,eax
  48. xor ebx,ebx
  49. xor edx,edx
  50. mov eax,[IB]
  51. mov edx,[BeginLastSection]
  52. add eax,edx
  53. add eax,10h
  54. mov ebx,DWORD[eax]
  55. mov [SizeOfRawData],ebx
  56. xor eax,eax
  57. xor ebx,ebx
  58. xor edx,edx
  59. mov eax,[IB]
  60. mov edx,[BeginLastSection]
  61. add eax,edx
  62. add eax,14h
  63. mov ebx,DWORD[eax]
  64. mov [PointerToRawData],ebx
  65. xor ebx,ebx
  66. xor eax,eax
  67. mov  edx, [PointerToRawData]
  68. mov ebx,[SizeOfRawData]
  69. add ebx,edx
  70. mov [EOF],ebx
  71. mov eax,[EOF]
  72. mov ebx,[tamAr]
  73. sub ebx,eax
  74. mov [TamañoEOF],ebx
  75. xor eax,eax
  76. mov eax,[SizeOfRawData]
  77. add eax,ebx
  78. mov [SizeOfRawDataAumentado],eax
  79. xor ebx,ebx
  80. mov ebx, [IB]
  81. add ebx,[BeginLastSection]
  82. add ebx,10h
  83. mov dword[ebx],eax
  84. xor eax,eax
  85. sub  ebx,[BeginLastSection]
  86. sub ebx,10h
  87. add ebx ,[BeginLastSection]
  88. add ebx,0x8
  89. mov eax,dword[ebx]
  90. add eax,[TamañoEOF]
  91. mov dword[ebx],eax
  92. sub ebx,0x8
  93. sub ebx,[BeginLastSection]
  94. xor eax,eax
  95. ;Virualsize
  96. mov eax,ebx
  97. xor ebx,ebx
  98. mov ebx,[tamAr]
  99. xor edx,edx
  100. mov edx,[hFile]
  101. ret
  102. endp  


Título: Re: EOFEXTRACT - Funcion para extraer el EOF
Publicado por: Micah Genji en 30 Abril 2009, 02:47 am
Hola estuve leyendo este code, normamelnte estoy empezando a usar C.
Justamente andaba averiguando sobre el valor de EOF en el stdio.h, pero veo que este code es para asm si no me equivoco  :-X

Cual es la idea de esta extraccion de EOF ?

haber si me sirve de alguna idea para un code que quiero realizar :)

Byt3s


Título: Re: EOFEXTRACT - Funcion para extraer el EOF
Publicado por: YST en 30 Abril 2009, 03:10 am
borrado por que me canse del foro .


Título: Re: EOFEXTRACT - Funcion para extraer el EOF
Publicado por: Micah Genji en 1 Mayo 2009, 02:41 am
Ok gracias por la aclaracion.

Creo que hay mucho por recorrer.

Byt3s