[Help me]Problem with using function pointer in Debug builds menu

User Tag List

Results 1 to 7 of 7
  1. #1
    wanyancan's Avatar Member
    Reputation
    1
    Join Date
    May 2009
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Help me]Problem with using function pointer in Debug builds

    I've got a weird problem using CreateRemoteThread... When built in "Release", the dummy codes are copied correctly to remote process and invoked properly, however for "debug" build, some non-sense bytes are copied from a wrong function address, not the actual "mySnubber" address.. Is there any options should be changed when building debug binaries? I think these are caused by the compiler to help to debug. Any solutions? I still need to debug it anyway.

    Codes as below
    Code:
    #define INJECTSIZE 4096
    DWORD __stdcall mySnubber( DWORD c )
    {
    		/*
    		0   float float float 
    		0xC float float float 
    		0x18 float float float
    		0x24 float
    		0x28 float (flag)
    		0x2C float float float
    		*/
    	typedef bool (__cdecl *tTraceLine)(int*, int*, int*, int*, int*, int*);
    	tTraceLine pTraceLine = (tTraceLine)0x506060;
    	return pTraceLine((int*)c, (int*)(c+0xC), (int*)(c+0x18), (int*)(c+0x24) ,(int*)(c+0x28) , (int*)0);	
    }
    void testRemoteCall(){
    	DWORD RmThdId;
    	LPVOID procAdd, paraAdd;
    	procAdd = VirtualAllocEx(wowprohnd,NULL, INJECTSIZE,  MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    	if(!procAdd){
    		printf("can't allocate proc Memory\n");
    		goto cleanup;
    	}
    	paraAdd = VirtualAllocEx(wowprohnd,NULL, INJECTSIZE,  MEM_COMMIT, PAGE_READWRITE );
    	if(!paraAdd){
    		printf("can't allocate parameters Memory\n");
    		goto cleanup;
    	}
    	DWORD szWritten;
    	if(!WriteProcessMemory(wowprohnd, procAdd, &mySnubber, INJECTSIZE, &szWritten)){
    		printf("can't write procedure into proc memory\n");
    		goto cleanup;
    	}
    	char testbuff[INJECTSIZE+4];
    	ReadStr(procAdd, testbuff, INJECTSIZE); // for test
    
    	// Setting [in]paraAddress as well , omitted
    
    	HANDLE hRmThd = CreateRemoteThread(wowprohnd, NULL, NULL,(DWORD (__stdcall *)( void *))procAdd, paraAdd, NULL, &RmThdId);
    	if(!hRmThd){
    		printf("can't create thread \n");
    		goto cleanup;
    	}
    	RmThdId = WaitForSingleObject(hRmThd, 3000);
    	CloseHandle(hRmThd);
    cleanup:
    	
    	if(procAdd)
    		if(!VirtualFreeEx(wowprohnd, procAdd, 0, MEM_RELEASE))
    			printf("Can't free allocated proc memory\n");
    	if(paraAdd)
    		if(!VirtualFreeEx(wowprohnd, paraAdd, 0, MEM_RELEASE))
    			printf("Can't free allocated proc memory\n");
    }
    This line
    Code:
    WriteProcessMemory(wowprohnd, procAdd, &mySnubber, INJECTSIZE, &szWritten)
    works correctly for "Release" build, but not in "Debug" build. The address for "mySnubber" is wrong...

    Another thing I'm concerning is about the WriteProcessMemory.. Is it currently being checked/detected by warden when reading/writing in the newly allocated memory space (I'm avoiding the word 'safe' )?
    Last edited by wanyancan; 01-05-2010 at 07:24 PM.

    [Help me]Problem with using function pointer in Debug builds
  2. #2
    kynox's Avatar Account not activated by Email
    Reputation
    830
    Join Date
    Dec 2006
    Posts
    888
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Debug builds generally have incremental linking enabled by default. Turn that off.

  3. #3
    wanyancan's Avatar Member
    Reputation
    1
    Join Date
    May 2009
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AHa it works!
    The traceline is indeed amazing! When it hit obstacles, it returns the hitting point! Thank you kynox for your information!

    Here's my codes. I used big memory size as in debug build, there's additional codes when mySnubber returns... very annoying.
    Code:
    #define INJECTSIZE 65536
    DWORD __stdcall mySnubber( DWORD c )
    {
    		/*
    		0   float float float 
    		0xC float float float 
    		0x18 float float float
    		0x24 float
    		0x28 int (flag)
    		0x2C int
    		*/
    	typedef bool (__cdecl *tTraceLine)(int*, int*, int*, int*, int, int*);
    	tTraceLine pTraceLine = (tTraceLine)0x506060;  // changed to your version
    	*(int*)(c+0x28) =  pTraceLine((int*)c, (int*)(c+0xC), (int*)(c+0x18), (int*)(c+0x24) ,*(int*)(c+0x28) , (int*)0);	// use flag as return value
    	return 1;
    }
    typedef struct TraceArg{
    	float startY;
    	float startX;
    	float startZ;
    	float endY;
    	float endX;
    	float endZ;
    	float outY;
    	float outX;
    	float outZ;
    	float distance;
    	DWORD flag;
    	DWORD option;
    }TRACEARG, *PTRACEARG;
    void testRemoteCall(){
    	DWORD RmThdId;
    	LPVOID procAdd, paraAdd;
    	TRACEARG localarg = {player.y,player.x,player.z+1.0f,player.y+cosf(player.facing)*1.0f,player.x+sinf(player.facing)*1.0f, player.z+1.0f, 0.0f,0.0f,0.0f,1.0f, 0x1000124, 0}; // I use flag value 0x1000124, not sure about other possible values like 0x20000, 0x120171
    	procAdd = VirtualAllocEx(wowprohnd,NULL, INJECTSIZE,  MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    	if(!procAdd){
    		printf("can't allocate proc Memory\n");
    		goto cleanup;
    	}
    	paraAdd = VirtualAllocEx(wowprohnd,NULL, INJECTSIZE,  MEM_COMMIT, PAGE_READWRITE );
    	if(!paraAdd){
    		printf("can't allocate parameters Memory\n");
    		goto cleanup;
    	}
    	DWORD szWritten;
    	if(!WriteProcessMemory(wowprohnd, procAdd, mySnubber, INJECTSIZE, &szWritten)){
    		printf("can't write procedure into proc memory\n");
    		goto cleanup;
    	}
    	if(!WriteProcessMemory(wowprohnd, paraAdd, &localarg, sizeof(TRACEARG), &szWritten)){
    		printf("can't write procedure into proc memory\n");
    		goto cleanup;
    	}
    
    	char testbuff[INJECTSIZE+4];
    	ReadStr(procAdd, testbuff, INJECTSIZE);
    
    	HANDLE hRmThd = CreateRemoteThread(wowprohnd, NULL, NULL,(DWORD (__stdcall *)( void *))procAdd, paraAdd, NULL, &RmThdId);
    	if(!hRmThd){
    		printf("can't create thread \n");
    		goto cleanup;
    	}
    	RmThdId = WaitForSingleObject(hRmThd, 3000);
    	CloseHandle(hRmThd);
    	ReadStr(LPCVOID((int*)paraAdd+0), &localarg, sizeof(TRACEARG));
    	printf("traceline returned: %08X %.2f %.2f %.2f\n", localarg.flag, localarg.outY, localarg.outX, localarg.outZ);
    	//POINT pt;
    	//if(localarg.flag){
    	//	scrPos(localarg.outX, localarg.outY, localarg.outZ, &pt);
    	//	MouseClick(wowhwnd, pt.x,pt.y, FALSE);
    	//}
    	
    cleanup:
    	
    	if(procAdd)
    		if(!VirtualFreeEx(wowprohnd, procAdd, 0, MEM_RELEASE))
    			printf("Can't free allocated proc memory\n");
    	if(paraAdd)
    		if(!VirtualFreeEx(wowprohnd, paraAdd, 0, MEM_RELEASE))
    			printf("Can't free allocated proc memory\n");
    }

  4. #4
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's quite an interesting method to call a function in another process

  5. #5
    wanyancan's Avatar Member
    Reputation
    1
    Join Date
    May 2009
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Theoretically it can call any thread safe function with any arguments in another process.
    Enjoy!

  6. #6
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally I'd suggest using AsmJit if you're going to be doing shit like this.

    Actually, personally I'd just inject a DLL, but if you're set on remote threads and injecting code stubs, use AsmJit. Seriously, it's awesome.

    asmjit - Project Hosting on Google Code

  7. #7
    wanyancan's Avatar Member
    Reputation
    1
    Join Date
    May 2009
    Posts
    40
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's an interesting problem when calling TraceLine in another thread.
    Normally, I pass 0x1000124 or 0x120171 as the fifth argument (flag value), and it can run for about 5 minutes, then suddenly I can walk through certain wall or into a tree (in only, can't get out)... Even after I quit the bot, it's still the same.
    Cypher, do you have any more details about this TraceLine functions?

Similar Threads

  1. [help] small problem with my memory scanner
    By anon145236 in forum WoW Memory Editing
    Replies: 11
    Last Post: 11-28-2011, 07:24 PM
  2. Problem with offsets and pointers
    By Neverhaven in forum WoW Memory Editing
    Replies: 10
    Last Post: 10-01-2009, 09:08 AM
  3. (HELP) Login Problems with arcemu r429
    By Insignia in forum World of Warcraft Emulator Servers
    Replies: 5
    Last Post: 07-19-2008, 02:06 PM
  4. [Help Request]Problem with warglaives
    By m2]IceMan in forum WoW ME Questions and Requests
    Replies: 14
    Last Post: 02-21-2008, 03:21 PM
  5. Need help! got problem with Ascent.exe will +rep :P
    By Anthraxx in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 01-26-2008, 10:12 AM
All times are GMT -5. The time now is 11:29 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search