;EasyCodeName=CardFile,1
;
Title	GeneSys Opcode CardFile, 1.0.1
; ___________________________________________________
;|                                                   |
;| GeneSys Opcode CardFile, 1.0.1      Paul Brennick |
;| pebrennick@verizon.net   http://www.pbrennick.com |
;|___________________________________________________|
;|                                                   |
;| Version key:  GeneSys Opcode CardFile a.b.c       |
;|           a:  a major change to the GUI           |
;|           b:  functions added and/or changed      |
;|           c:  bug fixes                           |
;|                                                   |
;| Version History:                                  |
;| October 27, 2006   Major rewrite and first        |
;|                    release of the software        |
;|                    Version tracking starts        |
;|                    from this point, on.           |
;|                                                   |
;| Written by: Paul Brennick                         |
;| Email     : pebrennick@verizon.net                |
;| Page      : http://www.pbrennick.com/             |
;| Compiler  : Microsoft Macro Assembler v6.14.8444  |
;| Date      : 27-Oct-2006                           |
;| Purpose   : This Opcode CardFile Manager can be   |
;|           : used to examine various MASM Opcodes  |
;|           : and Mnemonics.                        |
;|                                     Editor's Note |
;|___________________________________________________|
;|                                                   |
;
.Data
;---------------------------------------
ClassName       DB  "DLGCLASS", 0
MenuName        DB  "MyMenu", 0
DlgName         DB  "MainDialog", 0
AbtName         DB  "AboutDialog", 0
num2            DB  "%lu", 0
hInstance       HINSTANCE   ?
buff            DB  256 Dup (?)
menuhand        DWord       ?
ASCIIname       DB  "OpCodeDatabase.asc", 0
ASCIIdata       DB  "fld1"
                DB  "fld2"
                DB  "fld3"
                DB  "fld4"
                DB  "fld5"
szOpen          DB  "open", 0
szAppName       DB  "CardFile", 0
szNotFound      DB  ": File not found", 0

;
.Data?
;---------------------------------------
hover           BOOL    ?
hFinger         DD      ?
orgStatic       DD      ?
hwndDlg         DD      ?
filehand1       DWord   ?
memhand         DWord   ?
filesize        DWord   ?
mem             DWord   ?
sizeread        DWord   ?
temp            DWord   ?
memdata         DWord   ?
parts           DWord   ?
memmax          DWord   ?
index           DWord   ?
;
.Const
;---------------------------------------
IDC_NEXT        Equ     3000
IDC_PREV        Equ     3001
IDC_EXIT        Equ     3002
IDM_EXIT        Equ     32003
IDM_ABOUT       Equ     32002
IDI_ICON1       Equ     5
IDC_URL         Equ     9
;
;
.Code
;---------------------------------------
start:  Invoke  GetModuleHandle, NULL
        Mov hInstance, Eax
        invoke  WinMain, hInstance, NULL, NULL, SW_SHOWDEFAULT
        Invoke  ExitProcess, Eax
;
;
WinMain Proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWord
;---------------------------------------
        Local wc:WNDCLASSEX
        LOCAL   msg:MSG
        Local hDlg:HWND
;
        Mov wc.cbSize, SizeOf WNDCLASSEX
        mov     wc.style, CS_HREDRAW or CS_VREDRAW
        Mov wc.lpfnWndProc, Offset WndProc
        mov     wc.cbClsExtra, NULL
        Mov wc.cbWndExtra, DLGWINDOWEXTRA
        push    hInst
        Pop wc.hInstance
        mov     wc.hbrBackground, COLOR_BTNFACE+1
        Mov wc.lpszMenuName, Offset MenuName
        mov     wc.lpszClassName, OFFSET ClassName
        Invoke  LoadIcon, hInstance, IDI_ICON1
        Mov wc.hIcon, Eax
        mov     wc.hIconSm, eax
        Invoke  LoadCursor, NULL, IDC_ARROW
        Mov wc.hCursor, Eax
        invoke  RegisterClassEx, addr wc
        Invoke  CreateDialogParam, hInstance, Addr DlgName, NULL, NULL, NULL
        Mov hDlg, Eax
        invoke  ShowWindow, hDlg, SW_SHOWNORMAL
        Invoke  UpdateWindow, hDlg
        .While TRUE
          Invoke GetMessage, Addr msg, NULL, 0, 0
          .Break .If (!Eax)
          Invoke IsDialogMessage, hDlg, Addr msg
          .If Eax == FALSE
            Invoke  TranslateMessage, Addr msg
            Invoke  DispatchMessage, Addr msg
          .EndIf
        .EndW
        Mov Eax, msg.wParam
        ret
;---------------------------------------
WinMain EndP
;
;
WndProc Proc Uses Ebx Esi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
;---------------------------------------
        Mov Eax, uMsg
        .if ax==WM_GETMINMAXINFO        ; 24
;          cmp     first, FALSE
;          jne     nob1
          Invoke  GetMenu, hWnd
          Mov menuhand, Eax
          invoke  DefWindowProc, hWnd, uMsg, wParam, lParam
          Invoke  OpenASCII, hWnd
          Mov Eax, mem
          mov     memdata, eax
          Mov index, 1
          ret
        .ElseIf Ax == WM_INITDIALOG
        .ElseIf Ax == WM_ACTIVATE
          Cmp mem, 0
          jne     okok2
          Mov Eax, mem
          mov     memdata, eax
          Invoke  OpenASCII, hWnd
okok2:    Invoke  ASCIIscan, hWnd
          Mov Eax, parts
          push    eax
          Push Offset num2
          push    offset buff
          Call wsprintfA
          invoke  SendDlgItemMessage, hWnd, 506, WM_SETTEXT, 0, ADDR buff
          Ret
        .ElseIf Ax == WM_DESTROY
          .If memhand != NULL
          	Invoke  GlobalFree, memhand
          .EndIf
          Invoke  PostQuitMessage, NULL
          Ret
        .ElseIf Ax == WM_COMMAND
          Mov Eax, wParam
          .if lParam==0
            .If Ax == IDM_EXIT
              Invoke  DestroyWindow, hWnd
              Ret
            .ElseIf Ax == IDC_NEXT
              Jmp gonext
            .elseif ax==IDC_PREV
              Jmp goprev
            .elseif ax==IDM_ABOUT
              Invoke  CreateDialogParam, hInstance, Addr AbtName, hWnd, Offset AboutDlgProc, NULL
              Mov hwndDlg, Eax
            .endif
          .Else
            .If Ax == IDC_EXIT
              Invoke  SendMessage, hWnd, WM_COMMAND, IDM_EXIT, 0
              Ret
            .ElseIf Ax == IDC_NEXT
gonext:       Mov Ebx, index
              cmp     ebx, parts
              Jae toobig
              mov     esi, memdata
              Add Esi, 4
              cmp     esi, memmax
              Jae toobig
gosi:         inc     esi
              Cmp Esi, memmax
              je      toobig
              Cmp [Esi], Word Ptr 0D0AH     ; CRLF?
              jne     gosi
              Add Esi, 3
              mov     memdata, esi
              Inc index
              invoke  ASCIIscan, hWnd
toobig:     .ElseIf Ax == IDC_PREV
goprev:       Mov Ebx, index
              or      ebx, ebx
              Jz nodec
              mov     esi, memdata
              Cmp Esi, mem
              je      nodec
              Sub Esi, 4
gosi2:        dec     esi
              Cmp Esi, mem
              je      foundtop
              Cmp [Esi], Word Ptr 0D0AH     ; CRLF?
              jne     gosi2
              Add Esi, 3
foundtop:     mov     memdata, esi
              Dec index
              invoke  ASCIIscan, hWnd
nodec:      .EndIf
          .EndIf
        .Else
          Invoke  DefWindowProc, hWnd, uMsg, wParam, lParam
          Ret
        .EndIf
nob1:   Xor Eax, Eax
        ret
;---------------------------------------
WndProc EndP
;
;
HyperLinkWndProc Proc Uses Ebx hWnd:DWord, uMsg:DWord, wParam:DWord, lParam:DWord
;---------------------------------------
        Local tmpFont:LOGFONT
        LOCAL   rect:RECT
        Local pt:POINT
;
        Mov Eax, uMsg
        .if eax==WM_NCHITTEST
          Mov Eax, 1                ; We want to handle the non client hit test so we return true or 1
          ret
        .ElseIf Eax == WM_CTLCOLORSTATIC
          Push Ebx
          push    edx
          Invoke  SendMessage, hWnd, WM_GETFONT, 0, 0
          Mov Edx, Eax
          invoke  GetObject, edx, sizeof LOGFONT, addr tmpFont
          Mov tmpFont.lfUnderline, TRUE
          invoke  CreateFontIndirect, addr tmpFont
          Mov Ebx, Eax
          invoke  SelectObject, wParam, ebx
          .If hover == FALSE
            Invoke  SetTextColor, wParam, Blue
          .Else
            Invoke  SetTextColor, wParam, Red
          .EndIf
          Invoke  GetSysColor, COLOR_MENU
          Invoke  SetBkColor, wParam, Eax
          Invoke  DeleteObject, Ebx
          Invoke  GetStockObject, HOLLOW_BRUSH
          Pop Edx
          pop     ebx
          Ret
        .ElseIf Eax == WM_MOUSEMOVE
          Invoke  GetParent, hWnd
          Push Ebx
          mov     ebx, eax
          Invoke  GetActiveWindow
          .If Eax == Ebx
            Invoke  GetCursorPos, Addr pt
            Invoke  GetWindowRect, hWnd, Addr rect
            Invoke  PtInRect, Addr rect, pt.x, pt.y
            .If Eax
              Invoke  GetCapture
              .If !Eax
                Invoke  SetCapture, hWnd
                Mov hover, TRUE
                invoke  InvalidateRect, hWnd, FALSE, FALSE
                Invoke  SetCursor, hFinger
              .EndIf
            .Else
              Invoke  GetCapture
              .If Eax
                Invoke  ReleaseCapture
                Mov hover, FALSE
                invoke  InvalidateRect, hWnd, FALSE, FALSE
              .EndIf
            .EndIf
          .EndIf
          Pop Ebx
          xor     eax, eax
          Ret
        .ElseIf Eax == WM_LBUTTONDOWN
          Invoke  GetWindowText, hWnd, Offset buff, SizeOf buff ; Change this for using a preset url
          Invoke  ShellExecute, NULL, Offset szOpen, Offset buff, NULL, NULL, SW_MAXIMIZE   ; Change this to represent your preset url
          Mov hover, FALSE
          invoke  InvalidateRect, hWnd, FALSE, FALSE
          Invoke  SendMessage, hWnd, WM_GETFONT, 0, 0           ; Get the defualt system font
          Mov Edx, Eax                                      ; Store result
          invoke  GetObject, edx, sizeof LOGFONT, addr tmpFont  ; Get our font into a logfont structure
          Mov tmpFont.lfUnderline, TRUE                     ; Under line the link
          invoke  CreateFontIndirect, addr tmpFont              ; Create the new font
          Mov Ebx, Eax                                      ; We need the return to free the memory later
          invoke  SelectObject, wParam, ebx                     ; Select our control
          Invoke  SetTextColor, wParam, Blue                    ; Change this to change the color of the link
          Xor Eax, Eax
          ret
        .EndIf
        Invoke  CallWindowProc, orgStatic, hWnd, uMsg, wParam, lParam
        Ret
;---------------------------------------
HyperLinkWndProc EndP
;
;
AboutDlgProc Proc hWnd:HWND, iMsg:DWord, wParam:WPARAM, lParam:LPARAM
;---------------------------------------
        Mov Eax, iMsg
        .if eax==WM_INITDIALOG
          Invoke  GetDlgItem, hWnd, IDC_URL
          Invoke  SetWindowLong, Eax, GWL_WNDPROC, Addr HyperLinkWndProc
          Mov orgStatic, Eax
          mov     hFinger, eax
          Xor Eax, Eax
          ret
        .ElseIf Eax == WM_CTLCOLORSTATIC
          Invoke  SendMessage, lParam, iMsg, wParam, lParam
          Ret
        .ElseIf Eax == WM_CLOSE
          Invoke  EndDialog, hWnd, NULL
          Mov hwndDlg, 0
        .ElseIf Eax == WM_COMMAND
          Push Edx
          mov     eax, wParam
          Mov Edx, Eax
          shr     edx, 16
          .If Eax == IDC_EXIT
            Invoke  SendMessage, hWnd, WM_CLOSE, NULL, NULL
            Invoke  EndDialog, hWnd, NULL
            Mov hwndDlg, 0
          .endif
          Pop Edx
        .else
          Mov Eax, FALSE
          ret
        .EndIf
        Mov Eax, TRUE
        ret
;---------------------------------------
AboutDlgProc EndP
;
;
OpenASCII Proc Uses Ebx Esi hWnd:HWND
;---------------------------------------

invoke  CreateFile, ADDR ASCIIname, GENERIC_READ, 0, \
                NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL
        Cmp Eax, INVALID_HANDLE_VALUE
        Jne @F
        .If Eax == INVALID_HANDLE_VALUE
        	Invoke lstrcpy, Addr buff, Addr ASCIIname
			Invoke lstrcat, Addr buff, Addr szNotFound
        	Invoke MessageBox, hWnd, Addr buff, Addr szAppName, MB_OK
        	Mov memhand, NULL
        	Invoke SendMessage, hWnd, WM_DESTROY, 0, 0
        	Invoke  ExitProcess, Eax
        	Ret
		.EndIf
@@:     Mov filehand1, Eax
        invoke  GetFileSize, filehand1, addr temp
        Mov filesize, Eax
        invoke  GlobalAlloc, GMEM_MOVEABLE + GMEM_ZEROINIT, filesize
        Mov memhand, Eax
        invoke  GlobalLock, eax
        Mov mem, Eax
        mov     esi, eax
        Mov [Esi], DWord Ptr 1
        invoke  ReadFile, filehand1, mem, filesize, addr sizeread, NULL
        Mov Esi, mem
        mov     ecx, filesize
        Mov Ebx, Ecx
        add     ebx, esi
        Mov memmax, Ebx
        xor     eax, eax 
notset: Inc Esi
        cmp     [esi], dword ptr 031646c66h
        Jne notset2
        inc     eax
notset2:
        Loop notset
        inc     eax
        Mov parts, Eax
		Ret
;---------------------------------------
OpenASCII EndP
;
;
ASCIIscan Proc Uses Esi Edi hWnd:HWND
;---------------------------------------
        Mov Esi, memdata
bigtry: lea     edi, ASCIIdata
        Xor Ecx, Ecx
retry:  mov     al, [esi]
        Cmp Al, [Edi]
        jne     notit
        Xor Ch, Ch
        push    esi
        Push Edi
retry1: inc     esi
        Inc Edi
        mov     al, [esi]
        Cmp Al, [Edi]
        jne     notit2
        Inc Ch
        cmp     ch, 3
        Jb retry1
        xor     eax, eax
        Mov Al, Cl
        add     eax, 501
        Inc Esi
        inc     esi
        Invoke  SendDlgItemMessage, hWnd, Eax, WM_SETTEXT, 0, Esi
notit2: Pop Edi
        pop     esi
notit:  Add Edi, 4
        inc     cl
        Cmp Cl, 6
        jb      retry
foundone:
        Cmp Esi, memmax
        jae     overit
        Inc Esi
        cmp     [esi], byte ptr 0ah
        Jne foundone
        cmp     esi, memmax
        Jae overit
        inc     esi
        Cmp [Esi], Byte Ptr 0DH
        jne     bigtry
overit: Mov Eax, index
        push    eax
        Push Offset num2
        push    offset buff
        Call wsprintfA
        invoke  SendDlgItemMessage, hWnd, 507, WM_SETTEXT, 0, ADDR buff
        Ret
;---------------------------------------
ASCIIscan EndP
;
;
        End     start

