I am trying to port Microsoft's VB example from http://support.microsoft.com/kb/285879 to asm. I think I almost have it but I can't figure out what's going wrong. I analyzed the stack on the compliled VB and the stack of my asm program and it's the same from what I can tell. I have constants for the MultiByteToWideChar conversions right now, those will get fixed later on.
wUser Byte 20 Dup (?) ; Dim wUser As String
wPass Byte 20 Dup (?) ; Dim wPassword As String
wDomain Byte 20 Dup (?) ; Dim wDomain As String
wProg Byte 50 Dup (?) ; Dim wCommandLine As String
wCurrentDir Byte 50 Dup (?) ; Dim wCurrentDir As String
user DB "User", 0
pass DB "1", 0
domain DB ".", 0
prog DB "C:\windows\notepad.exe", 0
CurrentDir DB "C:\", 0
Local PI:PROCESS_INFORMATION ;Dim pi As PROCESS_INFORMATION
Local Startinfo:STARTUPINFO ;Dim Si As STARTUPINFO
.If uMsg == WM_LBUTTONUP
Invoke MultiByteToWideChar, CP_ACP, NULL, Addr user, -1, Addr wUser, 20 ;wUser = StrConv(UserName + Chr$(0), vbUnicode)
Invoke MultiByteToWideChar, CP_ACP, NULL, Addr pass, -1, Addr wPass, 20 ;wPassword = StrConv(Password + Chr$(0), vbUnicode)
Invoke MultiByteToWideChar, CP_ACP, NULL, Addr domain, -1, Addr wDomain, 20 ;wDomain = StrConv(DomainName + Chr$(0), vbUnicode)
Invoke MultiByteToWideChar, CP_ACP, NULL, Addr prog, -1, Addr wProg, 50 ;wCommandLine = StrConv(CommandLine + Chr$(0), vbUnicode)
Invoke MultiByteToWideChar, CP_ACP, NULL, Addr CurrentDir, -1, Addr wCurrentDir, 50 ;wCurrentDir = StrConv(CurrentDirectory + Chr$(0), vbUnicode)
Push SizeOf Startinfo ;si.cb = Len(si)
;CreateProcessWithLogonW (wUser, wDomain, wPassword, LOGON_WITH_PROFILE, 0&, wCommandLine, CREATE_DEFAULT_ERROR_MODE, 0&, wCurrentDir, si, pi)
Invoke CreateProcessWithLogonW, Addr wUser, Addr wDomain, Addr wPass, LOGON_WITH_PROFILE, 0, Addr wProg, CREATE_DEFAULT_ERROR_MODE, 0, Addr wCurrentDir, Addr Startinfo, Addr PI
.If Eax != 0
Invoke CloseHandle, Addr PI.hThread
Invoke CloseHandle, Addr PI.hProcess
Invoke MessageBox, NULL, NULL, NULL, MB_OK
Got it figured out. My local variables are being initalized with random data instead of zero's. Is there a way I can initialize all my local variables with zeros? Or should I just move it to .Data section because that seems to work.
You should always initialize buffers where it's required. The data section isn't guaranteed to be always zeroed (although it always is zeroed). You can use msvcrt.dll's memset - both for local variables and the data section.
Thanks, I'll keep that in mind or write a short loop to zero it out first. I forgot that local variables were created with previously used space from the stack. I can't believe that no code was available already for this. I usually just go to google type in invoke function, addr blah blah and usually get come good code from various websites.