Jump to content

Recommended Posts

Posted (edited)

You have created a user-defined resource type "rt_bitmap" rather than BITMAP (RT_BITMAP = 2). Replace

#AutoIt3Wrapper_Res_File_Add=test.bmp, rt_bitmap, TEST_BMP

to

#AutoIt3Wrapper_Res_File_Add=test.bmp, 2, TEST_BMP
Edited by Yashied
Posted

Still "Not Found" after changing the script:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=test.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_File_Add=test.bmp, 2, TEST_BMP
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ImageSearch.au3>
#include <Resources.au3>

Global $x=0,$y=0
Global $image = @ScriptDir & "\test.bmp"

Sleep (1000)

_normal()
Sleep (1000)
MouseMove(0,0,0)
_with_ResourceGet()
Sleep (1000)
MouseMove(0,0,0)
_with_ResourceGetAsImage()
Sleep (1000)
MouseMove(0,0,0)
_with_ResourceGetAsBitmap()



Func _with_ResourceGetAsBitmap()
    $hBmp = _ResourceGetAsBitmap("TEST_BMP", $RT_BITMAP,$RT_RCDATA)
    if _ImageSearcharea($hBmp,1,1619,510,1760,557,$x,$y,100) = 1 Then
        MouseMove($x,$y,0)
        MsgBox(0,"Found","Found @ " & $x & " - " & $y & @CR)
    Else
        MsgBox(0,"Error","Not Found" & @CR)
    EndIf
EndFunc


Func _with_ResourceGetAsImage()
    $hBmp = _ResourceGetAsImage("TEST_BMP", $RT_BITMAP, $RT_RCDATA)
    if _ImageSearcharea($hBmp,1,1619,510,1760,557,$x,$y,100) = 1 Then
        MouseMove($x,$y,0)
        MsgBox(0,"Found","Found @ " & $x & " - " & $y & @CR)
    Else
        MsgBox(0,"Error","Not Found" & @CR)
    EndIf
EndFunc

Func _with_ResourceGet()
    $hBmp = _ResourceGet("TEST_BMP", $RT_BITMAP)
    if _ImageSearcharea($hBmp,1,1619,510,1760,557,$x,$y,100) = 1 Then
        MouseMove($x,$y,0)
        MsgBox(0,"Found","Found @ " & $x & " - " & $y & @CR)
    Else
        MsgBox(0,"Error","Not Found" & @CR)
    EndIf
EndFunc

func _normal()
    if _ImageSearcharea($image,1,1619,510,1760,557,$x,$y,100) = 1 Then
        MouseMove($x,$y,0)
        MsgBox(0,"Found","Found @ " & $x & " - " & $y & @CR)
    Else
        MsgBox(0,"Error","Not Found" & @CR)
    EndIf
EndFunc

What am I doing wrong?

M.

Posted

Anyone know how I can delete resource type 10 "RC_DATA" from a PE file?

I want my script to be able to delete a resource from another autoit exe.

Or at least update a resource with a smaller resource to decrease its size?

Posted (edited)

Anyone know how I can delete resource type 10 "RC_DATA" from a PE file?

I want my script to be able to delete a resource from another autoit exe.

Or at least update a resource with a smaller resource to decrease its size?

Read these carefully particularly UpdateResource when passing lpData a null parameter to remove a resource item

BeginUpdareResource

UpdateResource

EndUpdateResource

Ed:

You said another AutoIt3 executable, this will not be possible since the api will remove the a3x overlay of a compiled Au3 exe.

Using it on the interpreter before you actually compile the Au3 exe would be fine, but watch out for those fugly PADDINGXX bytes at the tail of the interpreter after using the api though.

Edited by Mobius

wtfpl-badge-1.png

Posted (edited)

Thanks guys, I'll be looking into this!

I remember trying to delete a RC_DATA resource of a compiles autoit executable only to find that it no longer worked, I guess I must take another rout of action.

I was just hoping some one might have recently came out with a break through, everything's possible in the digital world.

Edited by THAT1ANONYMOUSEDUDE
Posted (edited)

Thanks guys, I'll be looking into this!

I remember trying to delete a RC_DATA resource of a compiles autoit executable only to find that it no longer worked, I guess I must take another rout of action.

I was just hoping some one might have recently came out with a break through, everything's possible in the digital world.

Break through :)

If your target Au3 exe is packed with upx unpack the target with upx commandline switch "-d" BEFORE attempting anything.

If your target is packed with another type of software armoring tool. Don't bother.:mellow:

If your target is unpacked.

1) Separate the A3x tail component from the interpreter (compiled executable) to a file.

2) Save just the Interpreter part of the same program to a file.

3) Modify resources of the interpreter file using api.

4) Attach the a3x file to the tail of the modified interpreter.

[5] If it was packed with upx before then go ahead and pack it again.

Are these programs your own AutoIt3 executables?

Edited by Mobius

wtfpl-badge-1.png

Posted (edited)

Break through ?

If your target Au3 is packed with upx unpack the target with upx commandline switch "-d" BEFORE attempting anything.

If your target is packed with another type of software armoring tool. Don't bother.

If your target is unpacked.

1) Separate the A3x tail component from the interpreter (compiled executable) to a file.

2) Save just the Interpreter part of the same program to a file.

3) Modify resources of the interpreter file using api.

4) Attach the a3x file to the tail of the modified interpreter.

[5] If it was packed with upx before then go ahead and pack it again.

Are these programs your own AutoIt3 executables?

Yeah, there mine and I don't pack them with any compression utility.

as for the following-

1) Separate the A3x tail component from the interpreter (compiled executable) to a file.

2) Save just the Interpreter part of the same program to a file.

3) Modify resources of the interpreter file using api.

4) Attach the a3x file to the tail of the modified interpreter.

That's moon talk to me, I'm not familiar with editing binaries at all in the manner you expressed, but non the less, thank you.

For some reason when I update the resource of a compiled autoit exe (5mb) in size, it reverts to 631Kb in size, but if I use reshacker to delete the resource, the exe works fine and doesn't give me a "unable to open the script file" error.

Edit: now that I look into this, as a matter of fact, the autoit compiled exe still works, I think I see what you mean now, when I use the API calls to update the resource or remove it completely, for some reason the script data within the exe is deleted right?

Because that seems to be whats happening since the error is that of autoit and not windows telling me the PE file is corrupted, but actually the AutoIt binary informing me that the script data it was compiled along with cannot be located. I'd really like to know how I can identify the A3x stub/tail you're talking about but I don't want to bother you too much, but I think I know what your talking about, this "a3x" tail is the actual script that is bundled into the PE file when compiling is commenced, am I right?

Details-

1) I compile a script and end up with a 1.83Mb PE file

2) I add some RCDATA and end up with a 5Mb PE file

3) I attempt to remove the RCDATA and end up with a 631Kb PE file telling me it was unable to load the script it was compiled with.

Edited by THAT1ANONYMOUSEDUDE
Posted (edited)

hi

why dont read from dll

#include "resources.au3"
 
$gui = GUICreate("Data from resources simple example 1",400,150)
$pic1 = GUICtrlCreatePic("",0,0,400,150)
;_ResourceSetImageToCtrl($pic1, "1",$RT_RCDATA, @ScriptDir & "\mydll.dll") 
;or
$pic1 = _ResourceGet("1", $RT_RCDATA, 1033, @ScriptDir & "\mydll.dll")

; set JPG image to picture control from resource
GUISetState(@SW_SHOW)


While 1
 If GUIGetMsg() = -3 Then Exit
WEnd

thank you now

Edited by mesale0077
Posted

Hi

probably ,dont work for xp

thank you now

There is really problem,

Firstly I tried it on Win7 and it worked fine.

Now on WinXP it doesn't work.

Syntax

_ResourceSetImageToCtrl($pic1, "#1", $RT_RCDATA, @ScriptDir & "\mydll.dll")

seems to be fine because inside _ResourceSetImageToCtrl() it crashes on line

_MemMoveMemory($ResData,$pData,$nSize)

so it correctly find resource get correct resource size (52862)

allocates memory but copying memory from DLL into EXE crashes.

I don't know why and why only on WinXP and not Win7.

Posted (edited)

hi

This code worked

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <Memory.au3>
#include <GDIPlus.au3>
#include <Constants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("[#] Form1 [#]", 700, 700, -1, -1)
$Pic1 = GUICtrlCreatePic("", 0, 0, 200, 200)
$Pic2 = GUICtrlCreatePic("", 48, 224, 513, 169)
Global $bgBinary = _ResourceGetAsRaw(@ScriptDir & "\1MyyDll.dll", "JPG_1", "S_1")
Global $bBinary_1 = _ResourceGetAsRaw(@ScriptDir & "\1MyyDll.dll", "JPG_1", "S_2")
_SetImageBinaryToCtrl($Form1,$Pic1,$bgBinary )
_SetImageBinaryToCtrl($Form1,$Pic2,$bBinary_1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Func _SetImageBinaryToCtrl($Wnd,$CtrlId, ByRef $Binary)
$kk=""
local $kk=$CtrlId&"_1"
$kk = ControlGetPos($Wnd, "", $CtrlId)

    Local $picdata = Binary($Binary) ; Fetch the Data
    Local $piclength = BinaryLen($picdata) ; Get Length

    Local $picstruct = DllStructCreate("byte[" & $piclength & "]")
        DllStructSetData($picstruct,1,$picdata)
        Local $picmemory = DllStructGetPtr($picstruct)
        _SetMemoryImageToCtrl($CtrlId, $picmemory, $piclength)
        DllStructSetData($picstruct,1,0)
    $picstruct = ""
    ControlMove($Wnd, "", $CtrlId,$kk[0],$kk[1],$kk[2], $kk[3])
EndFunc


Func _ResourceGetAsRaw($sModule, $vResType, $vResName, $iResLang = 0)

    Local $hResDll = _WinAPI_LoadLibraryEx($sModule, $LOAD_LIBRARY_AS_DATAFILE)
    If @error Then Return SetError(1, 0, 0)

    Local $sTypeType = "wstr"
    If IsNumber($vResType) Then $sTypeType = "int"

    Local $sNameType = "wstr"
    If IsNumber($vResName) Then $sNameType = "int"

    Local $aCall = DllCall("kernel32.dll", "handle", "FindResourceExW", _
            "handle", $hResDll, _
            $sTypeType, $vResType, _
            $sNameType, $vResName, _
            "int", $iResLang)
    If @error Or Not $aCall[0] Then
        _WinAPI_FreeLibrary($hResDll)
        Return SetError(2, 0, 0)
    EndIf

    Local $hResource = $aCall[0]

    $aCall = DllCall("kernel32.dll", "int", "SizeofResource", "handle", $hResDll, "handle", $hResource)
    If @error Or Not $aCall[0] Then
        _WinAPI_FreeLibrary($hResDll)
        Return SetError(3, 0, 0)
    EndIf

    Local $iSizeOfResource = $aCall[0]

    $aCall = DllCall("kernel32.dll", "handle", "LoadResource", "handle", $hResDll, "handle", $hResource)
    If @error Or Not $aCall[0] Then
        _WinAPI_FreeLibrary($hResDll)
        Return SetError(4, 0, 0)
    EndIf

    $hResource = $aCall[0]

    $aCall = DllCall("kernel32.dll", "ptr", "LockResource", "handle", $hResource)
    If @error Or Not $aCall[0] Then
        _WinAPI_FreeLibrary($hResDll)
        Return SetError(5, 0, 0)
    EndIf

    Local $pResource = $aCall[0]

    Local $tBinary = DllStructCreate("byte[" & $iSizeOfResource & "]", $pResource)
    Local $bBinary = DllStructGetData($tBinary, 1)

    _WinAPI_FreeLibrary($hResDll)

    Return $bBinary

EndFunc   ;==>_ResourceGetAsRaw

; Authors: Zedna, based on code by Prog@ndy
Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize)
    Local $hData, $pData, $pStream, $pBitmap, $hBitmap

        ; use GDI+ for converting to bitmap first
    $hData = _MemGlobalAlloc($nSize,2)
    $pData = _MemGlobalLock($hData)
    _MemMoveMemory($Pointer,$pData,$nSize)
    _MemGlobalUnlock($hData)
    $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0)
    $pStream = $pStream[3]

    _GDIPlus_Startup()
    $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0)
    $pBitmap = $pBitmap[2]
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
    _SetBitmapToCtrl($CtrlId, $hBitmap)
    If @error Then SetError(3, 0, 0)
    _GDIPlus_BitmapDispose($pBitmap)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($pStream)
    _MemGlobalFree($hData)
EndFunc

; internal helper function
; Out of resources.au3 :)
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
        ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
        Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

thank you now

Edited by mesale0077
  • 2 weeks later...
Posted

As far as I know

_ImageSearcharea() needs image as file on disk, it doesn't work with image in memory.

Search forum for details, I complained about that already but author of that _ImageSearch() didn't respond.

Is there then another suitable solution similar to _ImageSearcharea() that allows working with images in memory?

(sorry for late reply but I was on holidays..)

M.

Posted (edited)

I discovered nice example for loading/playing AVI files from resources in VB

SAMPLE: AVIRSCE.EXE Plays an AVI Stored in a Resource .dll File

http://support.microsoft.com/kb/173668/en-us?fr=1

It can be translated to Autoit so we can use this as _ResourcePlayAVI()

EDIT:

here is another approach for this in VB using animation standard control

http://code.msdn.microsoft.com/CppWindowsCommonControls-9ea0de64

A. Animation Control

Step1. Add the AVI resource IDR_UPLOAD_AVI according to the KB article:

How to create a resource .dll file that contains an AVI file
[url="http://support.microsoft.com/kb/178199"]http://support.microsoft.com/kb/178199[/url]

Step2. In OnInitAnimationDialog, load and register animation control class.

    INITCOMMONCONTROLSEX iccx;
    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
    iccx.dwICC = ICC_ANIMATE_CLASS;
    if (!InitCommonControlsEx(&iccx))
        return FALSE;

Step3. Create the animation control.

    RECT rc = { 20, 20, 280, 60 };
    HWND hAnimate = CreateWindowEx(0, ANIMATE_CLASS, 0,
        ACS_TIMER | ACS_AUTOPLAY | ACS_TRANSPARENT | WS_CHILD | WS_VISIBLE,
        rc.left, rc.top, rc.right, rc.bottom,
        hWnd, (HMENU)IDC_ANIMATION, hInst, 0);

Step4. Open and play the AVI clip in the animation control.

    SendMessage(hAnimate, ACM_OPEN, (WPARAM)0,
        (LPARAM)MAKEINTRESOURCE(IDR_UPLOAD_AVI));
    SendMessage(hAnimate, ACM_PLAY, (WPARAM)-1,
        MAKELONG(/*from frame*/0, /*to frame*/-1));
Edited by Zedna
Posted (edited)

I found several problems in Resources.au3:

1. Trying to load resources from the external modules leads to crash the script because you call _WinAPI_FreeLibrary().

#Region
#AutoIt3Wrapper_Res_File_Add=Silverlight.png, 10, TEST
#EndRegion
 
#Include "Resources.au3"
 
GUICreate('', 256, 256)
$Pic = GUICtrlCreatePic('', 64, 64, 128, 128)
GUISetState()
 
FileCopy(@ScriptFullPath, @ScriptDir & 'Duplicate.exe', 1)
_ResourceSetImageToCtrl($Pic, 'TEST', 10, @ScriptDir & 'Duplicate.exe')
 
Do
Until GUIGetMsg() = -3

2. A memory leak.

#Region
#AutoIt3Wrapper_Res_File_Add=Silverlight.png, 10, TEST
#EndRegion
 
#Include "Resources.au3"
 
GUICreate('', 256, 256)
$Pic = GUICtrlCreatePic('', 64, 64, 128, 128)
GUISetState()
 
Run(@SystemDir & 'taskmgr.exe')
MsgBox(0, '', '')
For $i = 1 To 1000
    _ResourceSetImageToCtrl($Pic, 'TEST')
Next
MsgBox(0, '', '')
 
Do
Until GUIGetMsg() = -3

3. _ResourceSetImageToCtrl() does not fully supports transparent and semitransparent images such as .png. Because _GDIPlus_BitmapCreateHBITMAPFromBitmap() creates a DDB, but need to DIB. Just replace _GDIPlus_BitmapCreateHBITMAPFromBitmap() to _GDIPlus_BitmapCreateDIBFromBitmap()...

Posted Image Posted Image

Func _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
 
    Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0
 
    $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($Ret[0]) Then
        Return 0
    EndIf
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then
        Return 0
    EndIf
    $tBIHDR = DllStructCreate('dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword')
    DllStructSetData($tBIHDR, 1, DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 2, $Ret[2])
    DllStructSetData($tBIHDR, 3, $Ret[3])
    DllStructSetData($tBIHDR, 4, 1)
    DllStructSetData($tBIHDR, 5, 32)
    DllStructSetData($tBIHDR, 6, 0)
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult[0]) Then
        DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $Ret[2] * $Ret[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
        $hResult = $hResult[0]
    Else
        $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
EndFunc   ;==>_GDIPlus_BitmapCreateDIBFromBitmap

post-42455-0-80008200-1315444463_thumb.p

Edited by Yashied

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...