Jump to content

AutoItX AU3_PixelSearch Access Violation


CultOfSun
 Share

Go to solution Solved by Andreik,

Recommended Posts

I made a few changes to the code @Andreik provided!

#define AUT_MANUALSTEP   0
#define AUT_AUTOSTEP   1

bool PixelSearch(LPRECT lpRect, int nCol, int nVar, int nStep, LPPOINT pPointResult, int stepMode = AUT_MANUALSTEP, int nCoordPixelMode = AUT_COORDMODE_SCREEN) {
    int         q, r;
    int         col;
    BYTE        red, green, blue;
    BYTE        red_low, red_high, green_low, green_high, blue_low, blue_high;
    HDC         hdc;
    RECT        relrect;
    POINT       ptOrigin;
    bool        m_bColorModeBGR = false;

    relrect.left = lpRect->left;
    relrect.top = lpRect->top;
    relrect.right = lpRect->right;
    relrect.bottom = lpRect->bottom;

    ConvertCoords(nCoordPixelMode, ptOrigin);
    relrect.left += ptOrigin.x;
    relrect.top += ptOrigin.y;
    relrect.right += ptOrigin.x;
    relrect.bottom += ptOrigin.y;

    col = nCol;
    if (m_bColorModeBGR == false)
        Util_RGBtoBGR(col);

    red = GetRValue(col);
    green = GetGValue(col);
    blue = GetBValue(col);

    if (nVar < 0)
        nVar = 0;
    else if (nVar > 0xff)
        nVar = 0xff;

    if (nVar == 0)
    {
        red_low = red_high = red;
        green_low = green_high = green;
        blue_low = blue_high = blue;
    }
    else
    {
        red_low = (nVar > red) ? 0 : red - nVar;
        green_low = (nVar > green) ? 0 : green - nVar;
        blue_low = (nVar > blue) ? 0 : blue - nVar;
        red_high = (nVar > 0xFF - red) ? 0xFF : red + nVar;
        green_high = (nVar > 0xFF - green) ? 0xFF : green + nVar;
        blue_high = (nVar > 0xFF - blue) ? 0xFF : blue + nVar;
    }

    hdc = GetDC(NULL);

    if (stepMode == AUT_MANUALSTEP) {

        for (q = relrect.left; q <= relrect.right; q = q + nStep)
        {
            for (r = relrect.top; r <= relrect.bottom; r = r + nStep)
            {
                col = GetPixel(hdc, q, r);
                red = GetRValue(col);
                green = GetGValue(col);
                blue = GetBValue(col);

                if (red >= red_low && red <= red_high && green >= green_low && green <= green_high
                    && blue >= blue_low && blue <= blue_high)
                {
                    q -= ptOrigin.x;
                    r -= ptOrigin.y;
                    pPointResult->x = q;
                    pPointResult->y = r;
                    ReleaseDC(NULL, hdc);
                    return 0;
                }
            }
        }

    }
    else if (stepMode == AUT_AUTOSTEP) {

        nStep = lpRect->right - lpRect->left;

        for (int i = nStep; i > 0; i -= (i / 2)) {

            for (q = relrect.left; q <= relrect.right; q = q + i)
            {
                for (r = relrect.top; r <= relrect.bottom; r = r + i)
                {
                    col = GetPixel(hdc, q, r);
                    red = GetRValue(col);
                    green = GetGValue(col);
                    blue = GetBValue(col);

                    if (red >= red_low && red <= red_high && green >= green_low && green <= green_high
                        && blue >= blue_low && blue <= blue_high)
                    {
                        q -= ptOrigin.x;
                        r -= ptOrigin.y;
                        pPointResult->x = q;
                        pPointResult->y = r;
                        ReleaseDC(NULL, hdc);
                        return 0;
                    }
                }
            }

        }

    }

    ReleaseDC(NULL, hdc);
    return 1;
}

Changed the return type of the PixelSearch function to return a bool. If it finds the color it returns 0, if not it returns 1. I also added a parameter stepMode, its default is AUT_MANUALSTEP or 0. The AUT_AUTOSTEP basically just takes the difference of lpRect->right - lpRect->left and uses that as the step amount. It divides the difference by 2 each time it cycles through those for loops. If anyone can add to this or make this even better that would be awesome!

Link to comment
Share on other sites

9 hours ago, Andreik said:

without seeing the actual implementation.

You can try looking at the machine code ;)

9 hours ago, Andreik said:

here is an adaptation of PixelSearch() based on a previous AutoIt version.

Which version exactly? If it's the "other" version on the internet then it may not be a wise choice to use it, legally speaking. :sweating:

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Not sure what do you mean by "other". AutoIt was once open source code and I am not publicly release or do anything to the code. Am I able to look at the code to fix possible bugs?

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

3 minutes ago, Andreik said:

Not sure what do you mean by "other".

Someone had leaked the code for an AutoIt v3.x version which was not under GPL.

4 minutes ago, Andreik said:

AutoIt was once open source code and I am not publicly release or do anything to the code.

That's correct, however I was unable to find a copy of the GPL'ed source code, do you have access to it? If so, can you share? It's perfectly legal by the way, GPL cannot be taken back retroactively.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

7 minutes ago, Andreik said:

I have a version since... I don't even know.

Can you upload it to GitHub? Would be great to have a GPL version of AutoIt.

7 minutes ago, Andreik said:

If there is any problem with the code

You should be fine as long as the code originates from a GPL codebase, did you check the LICENSE file?

 

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

This one. I don't know why I should upload it to github since there it's I think the very same version (just google AutoIt source code). And since it was deleted from AutoIt forum I suppose it's for a reason but I don't think that I should delete what once was published as open source. If there is a chance that this code is not suppose to be published, not even in such basic forms that not expose anything about AutoIt core, just report the post and some admins will check this issue.

What do you think @Jon? If there is any copyright infringement just let me know and I will remove my post.

When the words fail... music speaks.

Link to comment
Share on other sites

2 hours ago, Andreik said:

I think the very same version (just google AutoIt source code).

Yeah nah, that's the "other version" I was talking about. The README.txt file makes it clear that it is the internal copy only available to contributors:

NOTE: For obvious reasons this archive doesn't contain all the new features in the current
version of AutoIt.  The code for these features may be made available at a later date.

Excluded features are:
- GUI
- DllCall
- ControlListView
- InetGet

However, as the primary goal of releasing this source is to help people contribute to the AutoIt
project, the missing features aren't so important.

This is not the GPL licensed version, and as such it is technically illegal to redistribute.

2 hours ago, Andreik said:

This one.

I wonder if anyone has archived that version or any older 3.x release with source.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

There is no difference between what Zedna said it was the last version of AutoIt source code and what can be found on the internet. I might have even older source code version somewhere but I have to check some old hard drives.

When the words fail... music speaks.

Link to comment
Share on other sites

24 minutes ago, Andreik said:

There is no difference between what Zedna said it was the last version of AutoIt source code and what can be found on the internet.

How are you so sure? Also turns out I missed the "LICENSE.txt" file in the same repository which clearly states that it can't be redistributed, it's under a proprietary license and not GPL. So it can't be the same as the version pointed out by Zedna.

You may not: 

- Distribute the AutoIt source code and/or compiled versions of AutoIt 
created with the AutoIt source code.
- Create derivative works based on the AutoIt source code for distribution 
or usage outside your organisation. 
- Modify and/or remove any copyright notices or labels included in the 
AutoIt source code.

Full LICENSE.txt:

Spoiler
AutoIt Source Code

Author  : Jonathan Bennett and the AutoIt Team 
WWW : http://www.autoitscript.com/autoit3/ 
Email   : support@hiddensoft.com 
________________________________________________________

          END-USER LICENSE AGREEMENT FOR THIS SOFTWARE
                   Important - read carefully:

This End-User License Agreement ("EULA") is a legal agreement
between you (either an individual or a single entity) and the
mentioned author of this Software for the software product
identified above, which includes computer software and may
include associated media, printed materials, and "online"
or electronic documentation.
By installing, copying, or otherwise using the AutoIt source code,
you agree to be bound by the terms of this EULA. If you do not
agree to the terms of this EULA, do not install or use the
AutoIt source code. 


SOFTWARE PRODUCT LICENSE

AutoIt and AutoIt source code is protected by copyright laws and
international copyright treaties, as well as other intellectual 
property laws and treaties. AutoIt source code is licensed, not sold.


1. GRANT OF LICENSE. 

You may: 

- Customize the design and operation of the AutoIt source code to suit
the internal needs of your organization except to the extent not 
permitted in this Agreement 

You may not: 

- Distribute the AutoIt source code and/or compiled versions of AutoIt 
created with the AutoIt source code.
- Create derivative works based on the AutoIt source code for distribution 
or usage outside your organisation. 
- Modify and/or remove any copyright notices or labels included in the 
AutoIt source code.


2. COPYRIGHT.

All title and copyrights in and to the AutoIt source code
(including but not limited to any images, photographs, animations,
video, audio, music, text, and "applets" incorporated into the
AutoIt source code), the accompanying printed materials, and any
copies of the AutoIt source code are owned by the Author of this
Software. AutoIt source code is protected by copyright laws
and international treaty provisions. Therefore, you must treat
AutoIt source code like any other copyrighted material.


MISCELLANEOUS 

If you acquired this product in the United Kingdom, this EULA is
governed by the laws of the United Kingdom.

If this product was acquired outside the United Kingdom, then local
law may apply.

Should you have any questions concerning this EULA, or if you desire
to contact the author of this Software for any reason, please contact
him/her at the email address mentioned at the top of this EULA.


LIMITED WARRANTY 

NO WARRANTIES.
The Author of this Software expressly disclaims any warranty for
the AutoIt source code. AutoIt source code and any related
documentation is provided "as is" without warranty of any kind,
either express or implied, including, without limitation, the
implied warranties or merchantability, fitness for a particular
purpose, or noninfringement. The entire risk arising out of use
or performance of the AutoIt source code remains with you.

NO LIABILITY FOR DAMAGES.
In no event shall the author of this Software be liable for any
damages whatsoever (including, without limitation, damages for
loss of business profits, business interruption, loss of business
information, or any other pecuniary loss) arising out of the use
of or inability to use this product, even if the Author of this
Software has been advised of the possibility of such damages.
Because some states/jurisdictions do not allow the exclusion
or limitation of liability for consequential or incidental damages,
the above limitation may not apply to you.

[END OF LICENSE]

 

Edit: I mixed things up, the version pointed out by Zedna also has missing stuff, so it could very well be the same thing. So sadly this is not the GPL version that I'm after.

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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