Results 1 to 18 of 18

Thread: Extract image from vb.exe

  1. #1

    Thread Starter
    Addicted Member Sanko's Avatar
    Join Date
    Mar 2000
    Location
    Argentina
    Posts
    128

    Cool Extract image from vb.exe

    Hi there

    I have and old card games i make in Vb6, i lost the source but i wnat to make a new version. I search for the images from the game and also i cant find them so i dont want to re-scan the images and cards.

    ¿there is a way to extract the images from the old game exe (picture boxes and image boxes)?

    i look for programs bu they only extract the icons.

    Thanks

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Extract image from vb.exe

    Give a shot to this sample:
    VB Code:
    1. 'This project needs a PictureBox, called 'Picture1'
    2.  
    3. 'In general section
    4. Private Declare Function DrawIcon Lib "user32" Alias "DrawIcon" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
    5. Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
    6. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    7.  
    8.  
    9. Private Sub Form_Load()
    10.     'KPD-Team 1998
    11.     'URL: [url]http://www.allapi.net/[/url]
    12.     'E-Mail: [email][email protected][/email]
    13.  
    14.     Dim Path as String, strSave as string
    15.     'Create a buffer string
    16.     strSave = String(200, Chr$(0))
    17.     'Get the windows directory and append '\REGEdit.exe' to it
    18.     Path = Left$(strSave, GetWindowsDirectory(strSave, Len(strSave))) + "\REGEdit.exe"
    19.     'No pictures
    20.     Picture1.Picture = LoadPicture()
    21.     'Set graphicmode to 'persistent
    22.     Picture1.AutoRedraw = True
    23.     'Extract the icon from REGEdit
    24.     return1& = ExtractIcon(Me.hWnd, Path, 2)
    25.     'Draw the icon on the form
    26.     return2& = DrawIcon(Picture1.hdc, 0, 0, return1&)
    27. End Sub

  3. #3
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Extract image from vb.exe

    I am not quite sure that is what they are looking for.
    It sounds like he wrote the app, and had 52 pictures in an array of pic boxes, or something similar.
    He compiled the exe, but lost the source.

    How on earth could you extract the pictures from the raw bytes of an EXE???

    I am really not sure this is possible using code.

    WOka

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Extract image from vb.exe

    It sure is possible ...
    From MSDN:
    The ExtractIcon function retrieves a handle to an icon from the specified executable file, dynamic-link library (DLL), or icon file.

    To retrieve an array of handles to large or small icons, use the ExtractIconEx function.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Extract image from vb.exe

    Those image bits are sitting in the .EXE perfectly the same as the original image - that's my guess anyway. The easiest way to prove this is to make a new exe - put an image into it - and see if you can find that "string of bits" in the .EXE - compared to the image file. If so you will have your first clue as to where in the .EXE the image is stored. It most likely will have some obvious stuff in front of and behind it.

    The next challege is to extract those bits and get them into an image file - such as a .JPG (if that's what you use). I'm sure those files have header info that's only pertinent to the storage of the file on the disk.

    Seems like a daunting task.

    Can you screen capture the images somehow??

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Extract image from vb.exe

    here is a sampe for the extended function:
    VB Code:
    1. Const PS_DOT = 2
    2. Const PS_SOLID = 0
    3. Const RGN_AND = 1
    4. Const RGN_COPY = 5
    5. Const RGN_OR = 2
    6. Const RGN_XOR = 3
    7. Const RGN_DIFF = 4
    8. Const HS_DIAGCROSS = 5
    9. Private Type POINTAPI
    10.     x As Long
    11.     y As Long
    12. End Type
    13. Private Type RECT
    14.     Left As Long
    15.     Top As Long
    16.     Right As Long
    17.     Bottom As Long
    18. End Type
    19. Private Type LOGPEN
    20.     lopnStyle As Long
    21.     lopnWidth As POINTAPI
    22.     lopnColor As Long
    23. End Type
    24. Private Declare Function CreateHatchBrush Lib "gdi32" (ByVal nIndex As Long, ByVal crColor As Long) As Long
    25. Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
    26. Private Declare Function CreatePenIndirect Lib "gdi32" (lpLogPen As LOGPEN) As Long
    27. Private Declare Function CreateRectRgnIndirect Lib "gdi32" (lpRect As RECT) As Long
    28. Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    29. Private Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long
    30. Private Declare Function FloodFill Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    31. Private Declare Function FrameRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
    32. Private Declare Function FrameRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    33. Private Declare Function InvertRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
    34. Private Declare Function OffsetRgn Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
    35. Private Declare Function Pie Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long
    36. Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    37. Private Declare Function RoundRect Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    38. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    39. Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    40. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    41. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    42. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    43. Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
    44. Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
    45. Private Sub Form_Load()
    46.     'KPD-Team 1998
    47.     'URL: [url]http://www.allapi.net/[/url]
    48.     'E-Mail: [email][email protected][/email]
    49.     Me.ScaleMode = vbPixels
    50. End Sub
    51. Private Sub Form_Paint()
    52.     Dim hHBr As Long, R As RECT, hFRgn As Long, hRRgn As Long, hRPen As Long, LP As LOGPEN
    53.     Dim hFFBrush As Long, mIcon As Long, Cnt As Long
    54.     'Clear the form
    55.     Me.Cls
    56.     'Set the rectangle's values
    57.     SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
    58.     'Create a new brush
    59.     hHBr = CreateHatchBrush(HS_DIAGCROSS, vbRed)
    60.     'Draw a frame
    61.     FrameRect Me.hdc, R, hHBr
    62.     'Draw a rounded rectangle
    63.     hFRgn = CreateRoundRectRgn(0, 0, Me.ScaleWidth, Me.ScaleHeight, (Me.ScaleWidth / 3) * 2, (Me.ScaleHeight / 3) * 5)
    64.     'Draw a frame
    65.     FrameRgn Me.hdc, hFRgn, hHBr, Me.ScaleWidth, Me.ScaleHeight
    66.     'Invert a region
    67.     InvertRgn Me.hdc, hFRgn
    68.     'Move our region
    69.     OffsetRgn hFRgn, 10, 10
    70.     'Create a new region
    71.     hRRgn = CreateRectRgnIndirect(R)
    72.     'Combine our two regions
    73.     CombineRgn hRRgn, hFRgn, hRRgn, RGN_XOR
    74.     'Draw a frame
    75.     FrameRgn Me.hdc, hRRgn, hHBr, Me.ScaleWidth, Me.ScaleHeight
    76.     'Crete a new pen
    77.     hRPen = CreatePen(PS_SOLID, 5, vbBlue)
    78.     'Select our pen into the form's device context and delete the old pen
    79.     DeleteObject SelectObject(Me.hdc, hRPen)
    80.     'Draw a rectangle
    81.     Rectangle Me.hdc, Me.ScaleWidth / 2 - 25, Me.ScaleHeight / 2 - 25, Me.ScaleWidth / 2 + 25, Me.ScaleHeight / 2 + 25
    82.     'Delete our pen
    83.     DeleteObject hRPen
    84.     LP.lopnStyle = PS_DOT
    85.     LP.lopnColor = vbGreen
    86.     'Create a new pen
    87.     hRPen = CreatePenIndirect(LP)
    88.     'Select our pen into the form's device context
    89.     SelectObject Me.hdc, hRPen
    90.     'Draw a rounded rectangle
    91.     RoundRect Me.hdc, Me.ScaleWidth / 2 - 25, Me.ScaleHeight / 2 - 25, Me.ScaleWidth / 2 + 25, Me.ScaleHeight / 2 + 25, 50, 50
    92.     'Create a new solid brush
    93.     hFFBrush = CreateSolidBrush(vbYellow)
    94.     'Select this brush into our form's device context
    95.     SelectObject Me.hdc, hFFBrush
    96.     'Floodfill our form
    97.     FloodFill Me.hdc, Me.ScaleWidth / 2, Me.ScaleHeight / 2, vbBlue
    98.     'Delete our brush
    99.     DeleteObject hFFBrush
    100.     'Create a new solid brush
    101.     hFFBrush = CreateSolidBrush(vbMagenta)
    102.     'Select our solid brush into our form's device context
    103.     SelectObject Me.hdc, hFFBrush
    104.     'Draw a Pie
    105.     Pie Me.hdc, Me.ScaleWidth / 2 - 15, Me.ScaleHeight / 2 - 15, Me.ScaleWidth / 2 + 15, Me.ScaleHeight / 2 + 15, 20, 20, 20, 20
    106.     'Extract icons from 'shell32.dll' and draw them on the form
    107.     For Cnt = 0 To Me.ScaleWidth / 32
    108.         ExtractIconEx "shell32.dll", Cnt, mIcon, ByVal 0&, 1
    109.         DrawIcon Me.hdc, 32 * Cnt, 0, mIcon
    110.         DestroyIcon mIcon
    111.     Next Cnt
    112.     'Clean up
    113.     DeleteObject hFFBrush
    114.     DeleteObject hRPen
    115.     DeleteObject hRRgn
    116.     DeleteObject hFRgn
    117.     DeleteObject hHBr
    118. End Sub
    119. Private Sub Form_Resize()
    120.     Form_Paint
    121. End Sub

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Extract image from vb.exe

    Quote Originally Posted by RhinoBull
    It sure is possible ...
    From MSDN:
    I am almost 99% sure that the ExtractIcon API returns icons associated with the exe or dll. ie, ie an applications icon (that you see on your desktop or the startbar)

    Will have a further look into it.

    Woka

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Extract image from vb.exe

    On the second thought, if images are incorporated into some imageboxes then it might not be possible ... not sure how images are compiled within exe or dll and also not sure if any of those functions are working only when exe or dll has some resource within it.

  9. #9
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Extract image from vb.exe

    Just doubled checked.
    Created a file called woof.exe, with some images and pic boxes. Compiled, and used that code about. It still only retrieved the applications icon.

    This ones really hard, if at all possible.

    Woka

  10. #10

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Extract image from vb.exe

    are they the standard 52 cards that are in a deck? I thought that M$ included them in a .dll, maybe called CARDS.dll. I was thinking bout using them for a re-write of my DOS poker game.

  12. #12

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Extract image from vb.exe

    I googled, and got this. Is it the images, or just the logic?

    http://www.vbforums.com/showthread.php?t=318815

    EDIT: I was right. Here is a link to Crazy8's using them

    http://www.rookscape.com/vbgaming/tutU.php

  14. #14

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Extract image from vb.exe

    I meant that he could just use these instead of trying to get the ones that he scanned into his old program.

  16. #16

  17. #17

    Thread Starter
    Addicted Member Sanko's Avatar
    Join Date
    Mar 2000
    Location
    Argentina
    Posts
    128

    Re: Extract image from vb.exe

    Wow

    I think this is really hard, so i go for the easy solution: i will take screenshots of the game and then edit with a image editor to extract the images i need.

    however i still try to find the way to extact the images from a vb exe.

    Thanks to all for your help


  18. #18
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Extract image from vb.exe

    Your best bet is to use an existing cards ocx/dll Cards.dll, Cards32.dll, Qcard32.dll, Vbcards.ocx. If you are really set on using picture cards then use Resource Hacker. It will extract all the playing cards and card backs from Cards32.dll.

    http://www.users.on.net/johnson/resourcehacker/

    Last edited by Keithuk; Jan 24th, 2005 at 06:55 AM.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width