what im trying to do is to convert my code in PureBasic (http://forums.purebasic.com/english/viewtopic.php?t=16676&start=0 <--this code) to fasm and i have learned alot from tutorials available but for some reason this just doesnt work... (i removed my "fixes"
this code tries to inject "procedure"(they are procedures in PB) to notepad.exe... thanks
format PE gui 4.0
entry ENTRYPOINT
include 'C:\fasm\include\win32axp.inc'
include 'C:\fasm\include\urlmon.inc'
; Procedure RemoteThread()
ENTRYPOINT:
JMP _EndProcedure0
_Procedure0:
PUSH ebx
PUSH ecx
PUSH ebp
PUSH esi
PUSH edi
MOV esi,esp
SUB esp,4
MOV eax,esp
MOV edx,eax
ADD edx,4
_ClearLoop0:
MOV dword [eax],0
ADD eax,4
CMP eax,edx
JNE _ClearLoop0
; hLibrary.l = LoadLibrary_("URLMON.DLL")
PUSH dword _S1
CALL [LoadLibrary]
MOV dword [esp],eax
; URLDownloadToFile_(#Null, "http://forums.purebasic.com/english/templates/subSilver/images/logo_phpBB.gif", "c:\logo_phpBB.gif", #Null, #Null)
PUSH dword 0
PUSH dword 0
PUSH dword _S2
PUSH dword _S3
PUSH dword 0
CALL [URLDownloadToFile]
; EndProcedure
XOR eax,eax
_EndProcedure1:
ADD esp,4
POP edi
POP esi
POP ebp
POP ecx
POP ebx
RET
_EndProcedure0:
; CreateProcess_(0, "notepad.exe", 0, 0, 0, #CREATE_SUSPENDED, 0 , 0, @sinfo.STARTUPINFO, @pinfo.PROCESS_INFORMATION)
PUSH dword v_pinfo
PUSH dword v_sinfo
PUSH dword 0
PUSH dword 0
PUSH dword 4
PUSH dword 0
PUSH dword 0
PUSH dword 0
PUSH dword _S5
PUSH dword 0
CALL [CreateProcess]
; dwPID = pinfo\dwProcessId
LEA ebp,[v_pinfo]
PUSH dword [ebp+8]
POP dword [v_dwPID]
; hProcess = pinfo\hProcess
PUSH dword [ebp]
POP dword [v_hProcess]
; dwWritten.l = #Null
MOV dword [v_dwWritten],0
; pbModule.l = GetModuleHandle_(0)
PUSH dword 0
CALL [GetModuleHandle]
MOV dword [v_pbModule],eax
invoke Sleep,5000
; DwSize.l = PeekL(pbmodule+PeekW(pbmodule+$3c)+$50)
MOV ebx,dword [v_pbModule]
MOV edi,dword [v_pbModule]
ADD edi,60
CALL PB_PeekW ; <------------CAUSES ERROR...
ADD ebx,eax
ADD ebx,80
MOV eax,[ebx+80]
CALL PB_PeekL ;<--------------CAUSES ERROR
MOV dword [v_DwSize],eax
; VirtualFreeEx_(hProcess, pbModule, 0, #MEM_RELEASE)
PUSH dword 32768
PUSH dword 0
PUSH dword [v_pbModule]
PUSH dword [v_hProcess]
CALL [VirtualFreeEx]
; lpBuffer.l = VirtualAllocEx_(hProcess, pbModule, dwSize, #MEM_COMMIT | #MEM_RESERVE, #PAGE_EXECUTE_READWRITE)
PUSH dword 64
PUSH dword 12288
PUSH dword [v_DwSize]
PUSH dword [v_pbModule]
PUSH dword [v_hProcess]
CALL [VirtualAllocEx]
MOV dword [v_lpBuffer],eax
; If lpBuffer = #Null
MOV ebx,dword [v_lpBuffer]
CMP ebx,0
JNE _EndIf2
; While ResumeThread_(pinfo\hThread) > 1
_While3:
LEA ebp,[v_pinfo]
PUSH dword [ebp+4]
CALL [ResumeThread]
MOV ebx,eax
CMP ebx,1
JLE _Wend3
; Wend
JMP _While3
_Wend3:
; CloseHandle_(hProcess)
PUSH dword [v_hProcess]
CALL [CloseHandle]
; End
JMP _PB_EOP_NoValue
; EndIf
_EndIf2:
; If WriteProcessMemory_(hProcess, lpBuffer, pbModule, dwSize, dwWritten) = 0
PUSH dword [v_dwWritten]
PUSH dword [v_DwSize]
PUSH dword [v_pbModule]
PUSH dword [v_lpBuffer]
PUSH dword [v_hProcess]
CALL [WriteProcessMemory]
MOV ebx,eax
CMP ebx,0
JNE _EndIf5
; While ResumeThread_(pinfo\hThread) > 1
_While6:
LEA ebp,[v_pinfo]
PUSH dword [ebp+4]
CALL [ResumeThread]
MOV ebx,eax
CMP ebx,1
JLE _Wend6
; Wend
JMP _While6
_Wend6:
; CloseHandle_(hProcess)
PUSH dword [v_hProcess]
CALL [CloseHandle]
; End
JMP _PB_EOP_NoValue
; EndIf
_EndIf5:
; hThread.l = CreateRemoteThread_(hProcess, #Null, 0, @RemoteThread(), pbModule, #Null, #Null)
PUSH dword 0
PUSH dword 0
PUSH dword [v_pbModule]
LEA eax,[_Procedure0]
PUSH eax
PUSH dword 0
PUSH dword 0
PUSH dword [v_hProcess]
CALL [CreateRemoteThread]
MOV dword [v_hThread],eax
; If hThread=#Null
MOV ebx,dword [v_hThread]
CMP ebx,0
JNE _EndIf8
; CloseHandle_(hProcess)
PUSH dword [v_hProcess]
CALL [CloseHandle]
; End
JMP _PB_EOP_NoValue
; EndIf
_EndIf8:
; While ResumeThread_(pinfo\hThread) > 1
_While9:
LEA ebp,[v_pinfo]
PUSH dword [ebp+4]
CALL [ResumeThread]
MOV ebx,eax
CMP ebx,1
JLE _Wend9
; Wend
JMP _While9
_Wend9:
; CloseHandle_(hThread)
PUSH dword [v_hThread]
CALL [CloseHandle]
; End
JMP _PB_EOP_NoValue
_PB_EOP_NoValue:
_PB_EOP:
_PB_EndFunctions:
RET
section '.idata' import data readable writeable
library kernel32, 'KERNEL32.DLL'
library kernel32, 'USER32.DLL'
include 'C:\fasm\include\APIA\KERNEL32.INC'
include 'C:\fasm\include\APIA\USER32.INC'
section '.data' data readable writeable
;
_PB_DataSection:
_PB_DEBUGGER_LineNumber: dd -1
_PB_DEBUGGER_IncludedFiles: dd 0
_PBV_ExecutableType: dd 0
_S1: db "URLMON.DLL",0
_S2: db "c:\logo_phpBB.gif",0
_S3: db "http://forums.purebasic.com/english/templates/subSilver/images/logo_phpBB.gif",0
_S4: db "c:\notepad.exe",0
_S5: db "notepad.exe",0
v_dwPID rd 1
v_DwSize rd 1
v_dwWritten rd 1
v_hProcess rd 1
v_hThread rd 1
v_lpBuffer rd 1
v_pbModule rd 1
v_pinfo rb 16
v_sinfo rb 68