Some Reminders

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Message
Author
User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#21 Post by Administrator » Mon Jan 26, 2015 2:42 pm

OK, sure. But, one thing to take notice (and this threw me off at first, too) is that IsWow64Process() doesn't work the way you think it does. It does not tell you if the process is 64-bit, nor will it tell you that it is definitely 32-bit. It only gives true if it is a 32-bit process under 64-bit Windows (ie. 32-bit programs running inside the Wow64 emulator); both 32-bit processes under 32-bit Windows and 64-bit processes under 64-bit Windows will give you a false result.

To check if you it 32-bit or 64-bit, check the code I wrote here: https://code.google.com/p/micromacro/so ... ss_lua.cpp

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#22 Post by BlubBlab » Mon Jan 26, 2015 4:37 pm

>.< yeah what it really mean is if the process runs in the 64-bit emulation box yes or no?, so under MM 32-bit this have no meaning and can be always true, so more or less this:
(I don't know did you swapped ifndef and ifdef ?)

Code: Select all

bool IsWow64(HANDLE process)
{
// we compile a 32-bit application 
#ifndef _WIN64
	return true;
// we compile a 64-bit application 
#else
	BOOL bIsWow64 = FALSE;
	LPFN_ISWOW64PROCESS fnIsWow64Process;
	//IsWow64Process is not available on all supported versions of Windows.
	//Use GetModuleHandle to get a handle to the DLL that contains the function
	//and GetProcAddress to get a pointer to the function if available.

	fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
		GetModuleHandle(TEXT("kernel32")),"IsWow64Process");

	if(NULL != fnIsWow64Process)
	{
		if (!fnIsWow64Process(process,&bIsWow64))
		{
			Logger::instance()->add("Failed to call IsWow64Process() in %s. Error code: %d\n",
	 	__FUNCTION__, GetLastError());
		
		}
	}
	return bIsWow64;
#endif
}
I didn't need to change much code open looks now like this:

Code: Select all

int Process_lua::open(lua_State *L)
{
	if( lua_gettop(L) != 1 )
		wrongArgs(L);
	checkType(L, LT_NUMBER, 1);

	HANDLE handle;
	DWORD procId = (DWORD)lua_tointeger(L, 1);
	DWORD access = PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE  | PROCESS_QUERY_INFORMATION;

	handle = OpenProcess(access, false, procId);

	if ((handle != NULL) && (GetProcessId(handle) !=  procId))
	{ /* !!! re-check result of OpenProcess, if handle is not pointing to the selected pid, close the handle */
		Logger::instance()->add("Mismatched Handle with PID possible run into something which prevent us in %s. Error code: %d\n",
	 	__FUNCTION__, GetLastError());
		CloseHandle(handle); handle = NULL; SetLastError(0);
	}
	if( handle == NULL)
	{ // An error occurred!
		Logger::instance()->add("Failed to open Handle in %s. Error code: %d\n",
	 	__FUNCTION__, GetLastError());
		return 0;
	}
	//means it runs in 64-bit emulation so it is 32-bit
	if (IsWow64(handle))
	{
		is32bit = true;
	}
	else
	{
		is32bit = false;
	}
	HANDLE *pHandle = (HANDLE *)lua_newuserdata(L, sizeof(HANDLE));
	luaL_getmetatable(L, LuaType::metatable_handle);
	lua_setmetatable(L, -2);
	*pHandle = handle;

	return 1;
}

Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#23 Post by Administrator » Mon Jan 26, 2015 6:01 pm

what it really mean is if the process runs in the 64-bit emulation box yes or no?
Yes.


_WIN64 will be defined when MicroMacro is 64-bit, definitely not running under Wow64 emulation, and we can assume that they are running a 64-bit OS (it is impossible to run 64-big programs under 32-bit Windows).

So, if _WIN64 is not defined (ifndef), the program is 32-bit and you need to check if it is running under Wow64.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#24 Post by BlubBlab » Mon Jan 26, 2015 7:15 pm

Administrator wrote:
what it really mean is if the process runs in the 64-bit emulation box yes or no?
Yes.
Sry wasn't a question I should had make ! at the end of the sentence :D silly me
Administrator wrote: _WIN64 will be defined when MicroMacro is 64-bit, definitely not running under Wow64 emulation, and we can assume that they are running a 64-bit OS (it is impossible to run 64-big programs under 32-bit Windows).

So, if _WIN64 is not defined (ifndef), the program is 32-bit and you need to check if it is running under Wow64.
That is what I meant if _WIN64 is defined the program will be compiled as x64 so it will be a 64-bit application which will run under a 64-bit os, which make is possible that one process which we attach will run under Wow64.

What under 32-bit happens I must over think a bit. :arrow:
EDIT: I think I got it but seriously when you are an 32-bit application ask yourself if you under wow64 that is tricky.

I went the indirect way because MS says it is not guaranteed that the function "IsWow64Process" is there so far I did understand older version don't have it. I experimented a little with stuff nothing is really finished but you can take a look what I did until now.
Attachments
process_lua.cpp
(61.44 KiB) Downloaded 116 times
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#25 Post by Administrator » Mon Jan 26, 2015 8:44 pm

You're right that if MicroMacro is 64-bit and the target program is 32-bit, we would potentially run into issues reading pointers. What I've been working on is changing the userdata that holds the handle into a struct that can hold the handle + other data, such as whether or not the process is 32-bit. Now, when it is opened, we can easily mark the handle for 32-bit reads--so we only need to check IsWow64Process once. This only needs to be done for reading the pointers from the target app.

I committed my changes, but it is hard to thoroughly test it all. I may be making a few extra fixes as needed.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#26 Post by BlubBlab » Tue Jan 27, 2015 4:24 pm

Okay I went through it I will test tomorrow but things I take note:

In readPtr:
You read "uint" twice one time it meant "uint64" it is a typo.

is32bit/is64bit still use Handles .. which we don't have any more I changed them to I ask now the ProcHandle *pHandle struct if it is 32-bit or not :D
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#27 Post by Administrator » Tue Jan 27, 2015 4:52 pm

Thanks. I've fixed those bugs, and also included the code to check for IsWow64Process; though I can't imagine many people using such old versions of Windows, it is a good idea.

Also, I would just like to say you've been very helpful with your code, code reviews, and ideas. I appreciate it.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#28 Post by BlubBlab » Wed Jan 28, 2015 3:06 pm

I think we benefit from that each other look over the others code. :D

I debugged my version, my readrules for readPtr had some serious bugs in it. I didn't tested multilevel pointer but the simple one working now. I also finally found the reason of the memory issue I think (I hope so) , I had some messed up debug options after resetting to standard things worked again.

You may notices I also implemented "long double" and writeUstring and completed readBatch, I didn't test the fist 2 because it more for fun and later , "long double " isn't needed and VS don't support it well and writeUstring I haven't test it but I'm to 90% sure it won't work in the first try, but I have seen you have also wrote a char to wchar_t function^^
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#29 Post by Administrator » Wed Jan 28, 2015 4:51 pm

You may notices I also implemented "long double"
I did. I also thought, "What the fuck is a long double?" A double is basically just an 8-byte float, so I'm not even sure how a long double would behave. Would that be 12 bytes, or 16? Does it behave as a floating-point type, or integral?
and writeUstring
Unless I'm mistaken, this isn't necessary. writeString() is just a direct character copy using the original string's length, so if it is a wide (multi-byte) string, it should just copy the original as-is (ie. it stays wide).
completed readBatch
What part of readBatch() needed completing?

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#30 Post by BlubBlab » Wed Jan 28, 2015 5:11 pm

Administrator wrote:
You may notices I also implemented "long double"
I did. I also thought, "What the fuck is a long double?" A double is basically just an 8-byte float, so I'm not even sure how a long double would behave. Would that be 12 bytes, or 16? Does it behave as a floating-point type, or integral?
It is an bigger type of double with higher precision at least it should be:
http://en.wikipedia.org/wiki/Long_double
In VS I would need to activate some legacy stuff MS kicked the type out of it.
Administrator wrote:
and writeUstring
Unless I'm mistaken, this isn't necessary. writeString() is just a direct character copy using the original string's length, so if it is a wide (multi-byte) string, it should just copy the original as-is (ie. it stays wide).
wchar_t is bigger than char it basically use 2 bytes (UTF-16), so it would have gabs between each char if I'm not mistaken.
Administrator wrote:
completed readBatch
What part of readBatch() needed completing?
Let me see I added : MEM_UBYTE, MEM_LDOUBLE, MEM_USTRING Okay basically only MEM_UBYTE
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#31 Post by Administrator » Fri Jan 30, 2015 11:58 am

BlubBlab wrote: wchar_t is bigger than char it basically use 2 bytes (UTF-16), so it would have gabs between each char if I'm not mistaken.
You're right, but it still works when writing since we aren't doing any conversion. A 10-character wchar_t would be 20 bytes wide, just like a regular char * would be 20 bytes wide. It will contain embedded zeroes (the gaps between characters), but those get copied over also because we take the length to write from the original string's length instead of strlen().
Let me see I added : MEM_UBYTE, MEM_LDOUBLE, MEM_USTRING Okay basically only MEM_UBYTE
Unless I'm mistaken, MEM_UBYTE is already handled in both readBatch_parsefmt() and readBatch().

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#32 Post by BlubBlab » Wed Jul 29, 2015 3:41 pm

Okay a reminder Lua 5.3.1 came out I think some small bug fixes.

Okay some questions:
- virtualPress has no extra argument for modifier ?
- I see you support the Hooks I suggest inside MM is this only limited to keys ? and do the keys come in twice I mean also inside the event functions ?

Edit:We did put the hwnd into the pocHandle so only the wiki is out of date?
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#33 Post by BlubBlab » Thu Jul 30, 2015 4:16 am

I currently going through your code one problem I found:

Code: Select all

			case 'h':
					job.type = MicroMacro::MEM_INT64;
					length += sizeof(int) * job.count;
					out.push_back(job);
				break;
				case 'H':
					job.type = MicroMacro::MEM_UINT64;
					length += sizeof(unsigned int) * job.count;
					out.push_back(job);
either you use 'long long' and 'unsigned long long' or the macros 'int64_t' and 'uint64_t' (or size_t for uint_64) but not 'int' and 'unsigned int'

edit:
:removeHook() must return a value -> return 0;

EDIT: Like you may noticed I pulled the source from your git repository ^^
I think I must wait until you finish your work beside the Lua update I think about using yield :
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx

I compiled already lanes against lua 5.3.1 in 32 and 64 bit with your rest command I can pause a thread, yield would be nice to gave the CPU time away instead of busy waiting. I'm only not sure about where to put this properly also system hm. :?:
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#34 Post by Administrator » Fri Jul 31, 2015 12:42 pm

BlubBlab wrote:Okay a reminder Lua 5.3.1 came out I think some small bug fixes.
I'lll look into updating eventually.
Okay some questions:
- virtualPress has no extra argument for modifier ?
Nope. That's just due to how the virtual presses work. I might consider changing this at some point to be automatic, perhaps, but for the time being you would want to send a virtualHold() on the modifier before the actual press, and then a virtualRelease() afterwards.
- I see you support the Hooks I suggest inside MM is this only limited to keys ? and do the keys come in twice I mean also inside the event functions ?
Yes, for the time it is limited to just keys. It is using a low-level hook so that it can intersect everything. The problem with that is that only works for keyboard hooks.
Edit:We did put the hwnd into the pocHandle so only the wiki is out of date?
I'm not entirely sure I understand your question here. Can you elaborate what you mean?
either you use 'long long' and 'unsigned long long' or the macros 'int64_t' and 'uint64_t' (or size_t for uint_64) but not 'int' and 'unsigned int'
:removeHook() must return a value -> return 0;
Thanks. Nice catch. I'll fix that up on my end.

I compiled already lanes against lua 5.3.1 in 32 and 64 bit with your rest command I can pause a thread, yield would be nice to gave the CPU time away instead of busy waiting. I'm only not sure about where to put this properly also system hm. :?:
What do you mean? Does system.rest() cause your CPU usage to spike while it should be resting? That should not happen. For me, it will stay at 0% usage.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#35 Post by BlubBlab » Fri Jul 31, 2015 1:51 pm

With procHandel I mean ..okay I was wrong but I must change the code anyway.

With yield I mean you have sometimes when you write threads code like this:

Code: Select all

while(wait_for_other_thread)do
	yield()
end
What it does is giving the CPU times free for other threads while waiting for a change.

The thing I missed to mention was that after I compiled the code MM popped up a ncurse test screen which I also saw somewhere here. How can I turn this off?
Do I need to include some settings so that it will turned off?
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#36 Post by Administrator » Fri Jul 31, 2015 2:04 pm

BlubBlab wrote: What it does is giving the CPU times free for other threads while waiting for a change.
I believe I've used a mutex wait in all those places, meaning it is waiting for the thread to be ready and consuming 0 CPU time. If you mean to handle it synchronously (so that those threads run in the background while the Lua side is doing its own processing) that would very much break a lot of things because the result would not be ready by the time the main thread tries to return it. I suppose you can throw the results into the queue for handling by the main thread (much like is already being done by sockets) though.

The thing I missed to mention was that after I compiled the code MM popped up a ncurse test screen which I also saw somewhere here. How can I turn this off?
Do I need to include some settings so that it will turned off?
Unless you're doing something to enter Ncurses mode, that should not happen. Do you just mean a console window?

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#37 Post by BlubBlab » Fri Jul 31, 2015 2:12 pm

yeah it open an extra window.
maybe I load accidentally something with a config
Image
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#38 Post by Administrator » Fri Jul 31, 2015 2:42 pm

Well that's certainly odd. I assume it has something to do with how you had compiled it, or maybe some code you had added to use PDcurses.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#39 Post by BlubBlab » Fri Jul 31, 2015 2:59 pm

AH it is the entrypoint with subsystem console it is main I will test some stuff
EDIT:okay I changed to native but now it doesn't find some lib information about .
"NtProcessStartup". I suspect it is a part of NTDLL but what is the lib for this?
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Some Reminders

#40 Post by BlubBlab » Sat Aug 01, 2015 12:19 pm

I simply changed to the old main header.

By the way there are too many slashes under windows

Code: Select all

			scriptsFullPath = baseDirectory;
			//scriptsFullPath += "/";
			scriptsFullPath += scriptsDir;
			scriptsFullPath = fixSlashes(fixFileRelatives(scriptsFullPath), SLASHES_TO_WINDOWS);
some goes for :

Code: Select all

		configFilename = baseDirectory;
		//configFilename += "/";
		configFilename += CONFIG_FILENAME;
I found out because I had to debug because all those global strings went missing again *grr* ( I think I have finally an idea what is going on but this take some time)

About the threads I was only thinking generally I have no real concrete plan for it more like stuff I will do someday and I simple want to add some possibilities to framework I working on. I can use and create mutexes with lua lanes but sometimes you need to wait not necessary of another thread but perhaps of an user input inside of a thread. The funny thing is I know that until Java 6 yield was implemented there as sleep(1) those other command I linked up there simply inform the OS run another thread instead of me.

EDIT: Wuuuhu I found it or at least I think http://stackoverflow.com/questions/2538 ... r-function
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest