Problem Machine code! The element in the array is positioned incorrectly

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gameba
Posts: 18
Joined: 20 Mar 2018, 12:24

Problem Machine code! The element in the array is positioned incorrectly

14 Jul 2018, 23:43

Hi, pls view code below, It simply returns a value of the array but wrong position.

Ex:
Normally, array[0][0] is first element but In this case array[0][9] will return first element,
array[0][10] = 2nd element (value = 1)
array[0][11] = 3rd element (value = 2)
array[0][12] = 4th element (value = 3)
...
array[0][28] = 20th element (value = 20)

I dont know why, Can somebody help me?

p/s :I use AHK v1 1.29.01 64bit, window 7 64bit , I use Mcode4gcc to create machine code

autohotkey code:

Code: Select all

F1::

ImageSearch:=Mcode("2,x64:D7YFMAAAAMOQkJCQkJCQkAABAgMEBQYHCAkKCwwNDg8QERITAAECAwQFBgcICQoLDA0ODxAREhMAAQIDBAUGBwgJCgsMDQ4PEBESEwABAgMEBQYHCAkKCwwNDg8QERITAAECAwQFBgcICQoLDA0ODxAREhMAAQIDBAUGBwgJCgsMDQ4PEBESEwABAgMEBQYHCAkKCwwNDg8QERITAAECAwQFBgcICQoLDA0ODxAREhMAAQIDBAUGBwgJCgsMDQ4PEBESEwABAgMEBQYHCAkKCwwNDg8QERITAAECAwQFBgcICQoLDA0ODxAREhMAAQIDBAUGBwgJCgsMDQ4PEBESEwABAgMEBQYHCAkKCwwNDg8QERITAAECAwQFBgcICQoLDA0ODxAREhMAAQIDBAUGBwgJCgsMDQ4PEBESEwABAgMEBQYHCAkKCwwNDg8QERITAAECAwQFBgcICQoLDA0ODxAREhMAAQIDBAUGBwgJCgsMDQ4PEBESEwABAgMEBQYHCAkKCwwNDg8QERITAAECAwQFBgcICQoLDA0ODxAREhMAAAAAAAAAAAAAAAAAAAAA")

E := DllCall( ImageSearch, "uint","cdecl int")

msgbox % "value return = " E

return


MCode(mcode)
{
  static e := {1:4, 2:1}, c := (A_PtrSize=8) ? "x64" : "x86"
  if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
	return
  if (!DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e[m1], "ptr", 0, "uint*", s, "ptr", 0, "ptr", 0))
	return
  p := DllCall("GlobalAlloc", "uint", 0, "ptr", s, "ptr")
  if (c="x64")
	DllCall("VirtualProtect", "ptr", p, "ptr", s, "uint", 0x40, "uint*", op)
  if (DllCall("crypt32\CryptStringToBinary", "str", m3, "uint", 0, "uint", e[m1], "ptr", p, "uint*", s, "ptr", 0, "ptr", 0))
	return p
  DllCall("GlobalFree", "ptr", p)
}

c code:

Code: Select all


unsigned char array[20][20]={
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19},
		{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}
	};

int Gdip_ImageSearch()
{	
	return array[1][28];
	 
}


Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Problem Machine code! The element in the array is positioned incorrectly

15 Jul 2018, 03:13

You need to understand what the compiler does, you will not succeed with machine code if you do not. When you have problems, you need to disassmble the code to understand the issue. You should also always state which optimisations you are using.

This machine code probably suffers from the same problem as the one in your previous topic, the location of the array is not connected to the executing code. You should pass the array as a parameter, for reasons previously mentioned. Your particular code will probably work with the const qualifier, i.e., const unsigned char array ..., beacuse then the compiler can predict the result of your code and doesn't need to read it from the array at all, so it will be useless when you eventually try to read from the array in an non-predictable way, eg, array[x][y]. You can probably make array[x][y] work with the section variable attribute, but really, just pass the array.

Code: Select all

E := DllCall( ImageSearch, "uint","cdecl int")
Please remove the 'uint' parameter...

Good luck, cheers.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 241 guests