Post Pacific  

Go Back   Post Pacific > Lineage 2 > Lineage 2 Server Modifications ONLY!
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 11.12.2006, 15:01   #1
HongK
Архивный участник
 
Join Date: Jun 2005
Posts: 258
Default Writing your own C5 DLL

Well since there's not a whole lot of information on EXACTLY how to start doing it, I did some research by talking to people and looking at AmpeDx64 internals and came up with a basic framework to get going. Hopefully, if people haven't already started on it, this can be a good beginning point. Maybe those who already have experience with this can add their notes and thoughts as well. So until the real C5 server gets leaked(if it even does) here's a fun way to spend your time :P

First off, go learn the x64 calling convention .. There's lots of good and boring documents to read on it. I'm still reading them.

Next, writing the actual DLL:

Here is a VERY basic framework, and it will not actually do anything unless you figure out what to do with it, but it will at least get you passed not knowing how to modify l2servers memory. The majority of this is information I found by disasm'ing AmpeDx64. So here goes:

Code:
DllExport BOOL WINAPI DllMain( HINSTANCE hinstDLL,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		{

			DWORD dwNumBytesWritten;

			file << "L2Extendx64 got called.\n";
			file.flush();
			
			//open process to get handle
			HANDLE hL2Proc = OpenProcess(PROCESS_ALL_ACCESS, TRUE, GetCurrentProcessId());
			
			//virtualprotectex - change memory read/write permission
			if ( VirtualProtectEx(hL2Proc, LPVOID lpAddress, SIZE_T dwSize, PAGE_EXECUTE_READWRITE, &dwNumBytesWritten) != 0)
			{
				file << "Successfully changed protection\n";
				if (WriteProcessMemory(hL2Proc, LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize, &dwNumBytesWritten))
					file << "Successfully wrote xxx bytes\n";
				else
					file << "Couldn't write xxx bytes. Error Code: " << GetLastError() << "\n";
				
				CloseHandle(hL2Proc);
			}
			else
			{
				file << "Couldn't alter memory protection\n";
				file << "Error Code: " << GetLastError() << "\n";
				file << "Process ID: " << GetCurrentProcessId() << "\n";
			}
			file.flush();

		}
		break;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
    return TRUE;
}
The two things that need to be called in order to directly modify memory are VirtualProtectEx, and WriteProcessMemory.

Straight from MSDN:
VirtualProtectEx

Changes the protection on a region of committed pages in the virtual address space of a specified process.

WriteProcessMemory

Writes data to an area of memory in a specified process. The entire area to be written to must be accessible or the operation fails.

And that's about it for now ... Since you can't use inline asm anymore, you'll have to do it a different way. Mcrabben7 has posted info relating to this in his C5 packetfixing thread.

Lastly, hopefully more people can contribute to this if they want to start doing a PP C5 dll :P .. I'll continue posting more as I go along as well.
HongK is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 22:21.