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: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#41 Post by Administrator » Sat Aug 01, 2015 2:52 pm

Thanks. I just pushed changes for those two.

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

Re: Some Reminders

#42 Post by BlubBlab » Sat Aug 01, 2015 3:04 pm

The problem with that again I had NULL strings was simply that:

Code: Select all

	static std::string buffer = psettings->getString(CONFVAR_LOG_DIRECTORY);
	static const char *logDir = buffer.c_str();
So far I understood it from teh link I posted it is so that a std::string which will be returned to an const char *var is temporary object it is not save to call a function on it e.g..c_str() It could be gone in the meantime.->NULL
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: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#43 Post by Administrator » Sat Aug 01, 2015 5:28 pm

c_str() returns a const char *. It should be valid until the base string is modified or goes out of scope. At worst, you would have an invalid pointer, but it should never be changed to NULL. What file & line is that call on, and at what point did you get an error about a NULL pointer?

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

Re: Some Reminders

#44 Post by BlubBlab » Sat Aug 01, 2015 5:56 pm

Administrator wrote:c_str() returns a const char *. It should be valid until the base string is modified or goes out of scope. At worst, you would have an invalid pointer, but it should never be changed to NULL. What file & line is that call on, and at what point did you get an error about a NULL pointer?
This is out of openLog(which makes trouble since forever) there is a second line in the main.cpp where it is the same(take a look in the download or the repo), c_str() itself isn't the problem it is you so that when an object is only on the right side in this case string it will be there only for a very little time, at least this is was I get out of the link I posted and basically when I make a var which contain it from a return value a real copy will be made of the object.

Without it it could be there it could be not. About what c_str() return basically an empty string so that logDir[0] == NULL true is, that was what I meant.
I'm not sure if this behaviour is written down somewhere but it is what Visual Studio with its compiler made out of it.(?)

EDIT:Hm at least the static problem with the export cars seems to be gone which is very confusing, after I compiled MM2 in 32-bit extern vars which I imported with static caused memory errors , so I had to remove them and everything seems to work afterwards. The really strange think was in 64-bit everything worked as well :shock: .

Hm I always have some strange luck with stuff like that like reading input from the linux bash while writing my own bash through a memory error,getting from TS overwolf injection errors inside eclipse in my compiler project like WTF which class is that this isn't part of my project? xD
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

#45 Post by BlubBlab » Thu Aug 06, 2015 9:05 pm

Okay first some problem I found or I let found:

Code: Select all

int Process_lua::readBatch(lua_State *L)
{
	if( lua_gettop(L) != 3 )
		wrongArgs(L);
	checkType(L, LT_USERDATA, 1);
	checkType(L, LT_NUMBER, 2);
	checkType(L, LT_STRING, 3);

	ProcHandle *pHandle = static_cast<ProcHandle *>(lua_touserdata(L, 1));
	size_t address = (size_t)lua_tointeger(L, 2);
	const char *fmt = lua_tostring(L, 3);

	std::vector<BatchJob> jobs;
	size_t readLen = readBatch_parsefmt(fmt, jobs);

	char *readBuffer = 0;
	try {
		readBuffer = new char[readLen+1];
	} catch( std::bad_alloc &ba ) { badAllocation(); }

	SIZE_T bytesRead = 0;
	int success = ReadProcessMemory(pHandle->handle, (LPVOID)address, (void *)readBuffer, readLen, &bytesRead);

	if( !success || bytesRead != readLen )
	{ // Throw error
		delete []readBuffer;
		int errCode = GetLastError();
		pushLuaErrorEvent(L, "Failure reading memory from 0x%p at 0x%p. "\
			"Error code %i (%s)",
			pHandle->handle, address, errCode, getWindowsErrorString(errCode).c_str());
		return 0;
	}
that return statement is missing without it a memory violation is possible.

The other thing is hm I'm still not sure if it is necessary but I think the way MM2 reading and writing memory isn't so different from MM1:
so my idea would be ?!:

Code: Select all


template <class T>
			static T readMemory(HANDLE process, size_t address, int &err)
			{
				T buffer;
				SIZE_T bytesread = 0;
				err = 0;
				int success = 0;

				success = ReadProcessMemory(process, (LPCVOID)address,
				(void *)&buffer, sizeof(T), &bytesread);

				if( success == 0 ){
					int trys_counter = 0;
					
					NtSuspendProcess pfnNtSuspendProcess = (NtSuspendProcess)GetProcAddress(GetModuleHandle("ntdll"), "NtSuspendProcess");
					NtResumeProcess pfnNtResumeProcess = (NtResumeProcess)GetProcAddress(GetModuleHandle("ntdll"), "NtResumeProcess");

					while(success == 0 && trys_counter < 50){
						pfnNtSuspendProcess(process);
						success = ReadProcessMemory(process, (LPCVOID)address,
						(void *)&buffer, sizeof(T), &bytesread);
						pfnNtResumeProcess(process);
						// if it still fail the only reason could be we looked it in a state where it access itself the memory
						// so give it sometime and try again
						if( success == 0 )
							Sleep(5);
						trys_counter ++;
					}
					
				}
				if( success == 0 )
						err = MEMORY_READ_FAIL;

				return buffer;
			}

			template <class T>
			static void writeMemory(HANDLE process, size_t address, T data, int &err)
			{
				SIZE_T byteswritten = 0;
				err = 0;
				int success = 0;
				DWORD old;

				VirtualProtectEx(process, (void *)address, sizeof(T), PAGE_READWRITE, &old);
				success = WriteProcessMemory(process, (void *)address,
				(void*)&data, sizeof(T), &byteswritten);
				VirtualProtectEx(process, (void *)address, sizeof(T), old, &old);

				if( success == 0 ){
					int trys_counter = 0;
					
					NtSuspendProcess pfnNtSuspendProcess = (NtSuspendProcess)GetProcAddress(GetModuleHandle("ntdll"), "NtSuspendProcess");
					NtResumeProcess pfnNtResumeProcess = (NtResumeProcess)GetProcAddress(GetModuleHandle("ntdll"), "NtResumeProcess");
	
					while(success == 0 && trys_counter < 50){
						pfnNtSuspendProcess(process);
						VirtualProtectEx(process, (void *)address, sizeof(T), PAGE_READWRITE, &old);
						success = WriteProcessMemory(process, (void *)address,
						(void*)&data, sizeof(T), &byteswritten);
						VirtualProtectEx(process, (void *)address, sizeof(T), old, &old);
						// if it still fail the only reason could be we looked it in a state where it access itself the memory
						// so give it sometime and try again
						pfnNtResumeProcess(process);
						if( success == 0 )
							Sleep(5);
						trys_counter ++;
					}

					if( success == 0 )
						err = MEMORY_WRITE_FAIL;
				}
					
			}
The idea is we first try to read the memory without any fancy stuff so that it is fast if it fails we suspend the process and read/write than in hope that we get a more stable result. I packed that in a loop so to be sure as it can be I made basically additionally the memoryReadRepeat inside, so if it fails it fails hard. (the process will be stopped maximal around 300-400 msc)

Okay I have one question:
NtSuspendProcess pfnNtSuspendProcess = (NtSuspendProcess)GetProcAddress(GetModuleHandle("ntdll"), "NtSuspendProcess");
NtResumeProcess pfnNtResumeProcess = (NtResumeProcess)GetProcAddress(GetModuleHandle("ntdll"), "NtResumeProcess");

I would love not to load every time but define them inside a header cause some problem is there a way around it ?

With this suspend and resume abilities we could in any case also add some process function suspend/resume.
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

#46 Post by BlubBlab » Sun Aug 09, 2015 9:06 am

Okay I found something different I'm not 100% sure but splitArgs don't work as intended or it was forgotten.

The problem is it splits directory names which have a whitespace in it. Seems there is still more messed up about the paths.
Edit: since it happened with the new open file GUI
Here is my work around:

Code: Select all


	std::string fullcmd;
	std::string result;
	std::string ex = "\"";
	std::cin.clear();
	getline(std::cin, fullcmd);
	std::cin.clear();

	if (fullcmd == "") {
		result = scriptGUIDialog(previousScript);
		fullcmd = ex + result + ex;
	}

	//previousScript = fullcmd; // Remember this.
	return fullcmd;
}
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: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#47 Post by Administrator » Sun Aug 09, 2015 12:36 pm

Finally got around to catching up on things outside of work today.

I rewrote a bunch of path code, so go ahead and check out that commit here: https://github.com/elverion/micromacro/ ... fc8b623919
That should resolve your issue with openLog() (although I'm unable to reproduce it) as well as make the code cleaner and more robust.
that return statement is missing without it a memory violation is possible.
Another good catch. Fixed that up.
The other thing is hm I'm still not sure if it is necessary but I think the way MM2 reading and writing memory isn't so different from MM1:
so my idea would be ?!:
Hmm... I'm a bit torn on this one. I'm not sure that freezing the application for 3-400ms will help with memory reading, but it can definitely make things a bit of a mess for the user. It is definitely an interesting idea though. Go ahead and give it a shot and see what happens. Report back with your results. I think if I include it, it will be togglable in the config.
Okay I found something different I'm not 100% sure but splitArgs don't work as intended or it was forgotten.
Wouldn't surprise me if there was a bug as I'm using a bit of a hack to get around using complex regex, but it seems to be working fine for me.

I have a script located at: micromacro/scripts/test scripts/args.lua
It simply prints out a list of arguments passed to the script (first argument is always going to be the path to the script).

Code: Select all

Script> "test scripts/args" abc "def 123"
Running './scripts/test scripts/args.lua'

Args:
1       ./scripts/test scripts/args.lua
2       abc
3       def 123
CWD:    D:/sync/micromacro/scripts/test scripts
To use a script with whitespace in it, you need to enclose the script name with quotes ("). If you want to use an argument with whitespace, those also should be enclosed in quotes.

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

Re: Some Reminders

#48 Post by BlubBlab » Sun Aug 09, 2015 1:13 pm

My directory looks like C:/user/FirstName LastName/somedirectory/..
Take a look at the whitespace between first name and last name , this is only an issue when open with the GUI in the other case you can't use " so I putted the return string into " ".

Yeah I also thought about making the execution freeze configurable what I did was basically implementing ReadRepeat inside MM2 in case it fails(and only than) and yeah I still must test it first. That 400 msc are the guaranteed return time which I think is only possible when things go very wrong.
I rewrote a bunch of path code, so go ahead and check out that commit here: https://github.com/elverion/micromacro/ ... fc8b623919
That should resolve your issue with openLog() (although I'm unable to reproduce it) as well as make the code cleaner and more robust.
I just finished recompiling MM2 new XD

AH yeah I forgot I lost the other post so: I updated to VS 2015 from VS 2012 E for preparing to do some work on drivers. The speed increase is amazing my performance script(increase counter 15sec) shown 15.000 which mean no speed lose whatsoever(my before about 13.000 your 14.350.. yeah I think on better PC you will always have 15.000) and OpenCV starting time when you first use it has also dramatically shorten . In addition I it has android support , hotmail AC integration (I don't use it), iOS support , Git , Python and CMake support.

EDIT: Okay I tested the resume/suspend code it basically it does working but you can kill you system with it , suspend backfire when the system is already suspended ... Okay I will always wake the process up before I but them to sleep.
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: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: Some Reminders

#49 Post by Administrator » Thu Aug 20, 2015 2:45 pm


User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: Some Reminders

#50 Post by beanybabe » Thu Aug 20, 2015 6:08 pm

I had problems with folders that start with the ` by ~ on the keyboard on first version of micromacro. I use them to sort folders on top or bottom of other folders. You might test it on the new version. /`foldername/

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests