Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
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  
Old 11.12.2006, 16:34   #2
RipperX
Архивный участник
 
Join Date: Dec 2005
Posts: 242
Default

The code is the same with all dlls, and use GetCurrentProcessId(), anyway today and tomorrow I have some exams so the Wednesday I will post some code

Good Luck!
RipperX is offline  
Old 11.12.2006, 17:04   #3
HongK
Архивный участник
 
Join Date: Jun 2005
Posts: 258
Default

Quote:
Originally Posted by RipperX View Post
The code is the same with all dlls, and use GetCurrentProcessId(), anyway today and tomorrow I have some exams so the Wednesday I will post some code

Good Luck!
lol yea just realized I wrote that wrong .. I was copying and pasting some stuff out my current dll and changed that but forgot to change it back to currentprocessid.

I realize the code will be the same with all dll's but when I started I had nothing to go off. If you've never even written a dll or don't know anything about them, this would be a good place to start learning. That's all :P
HongK is offline  
Old 12.12.2006, 15:08   #4
HongK
Архивный участник
 
Join Date: Jun 2005
Posts: 258
Default

Ok so I managed to finally figure out how to overwrite some data without crashing the server :P

First off, what you need to do is add a .asm file to your sources and call it whatever you want. I called mine FirstPatch.asm since it was the first thing I tried. Next create a custom build step so that your asm file is compiled and linked in to the dll. You'll need to add the function prototype to your header file. It should just be void since you're not doing anything but overwriting some bytes. Here's what my asm file looks like:

Code:
PUBLIC FirstPatch
.DATA

sMessage	word	"C","o","n","g","r","a","t","s",","," ","Y","o","u"," ","O","v","e","r","w","r","o","t","e"," ","I","t",0
lastFunc	dq	0064DC60h
returnAdd	dq	006362EFh
.CODE

FirstPatch:

	lea r8, sMessage
	call qword ptr [lastFunc]
	jmp returnAdd

END
Whether or not that call instruction is the best way of doing it, I'm not sure. I'm not really an assembler guru, but it compiles ok and works so atm that was all I cared about :P

The string up there is defined as Unicode since that's what the function you're calling is expecting the string to be in. If you do it in ASCII you will just see junk on the console window. Also, to get it so you don't have a prologue and epilogue just create the function label and leave it as is like I did.

So what this does is simply overwrite what's already in r8, which was "Load QuestItem" with my string defined by sMessage. Why change that? It just happened to be one of the first unicode strings I came across while messing around in l2server. I used it as an example to myself to test whether or not this method would work.

Anyway, if you go back to your dll, I was having problems with writeprocessmemory writing just a byte for the the jmp instruction, so I changed the bytes like in L2Extension project using pointers and it seems to be working fine. I kept crashing the server originally before I realized it was probably crashing on leaving my firstpatch function. You used to be able to push a return address on the stack and call retn, but that's obviously not the case anymore. Instead I just jmped back to the return address and everything went smoothly.
HongK is offline  
Old 12.12.2006, 20:50   #5
RipperX
Архивный участник
 
Join Date: Dec 2005
Posts: 242
Default

HongK do you have 64bits asm reference ? I need update my knowledge =)
btw, if you want we could speak by messenger and talk about C2/C5 Project :P

gL!
RipperX is offline  
Old 12.12.2006, 22:03   #6
HongK
Архивный участник
 
Join Date: Jun 2005
Posts: 258
Default

Quote:
Originally Posted by RipperX View Post
HongK do you have 64bits asm reference ? I need update my knowledge =)
btw, if you want we could speak by messenger and talk about C2/C5 Project :P

gL!
Sure, I sent you a private message with my msn info...

Look forward to talking to you
HongK is offline  
Old 12.12.2006, 22:21   #7
RipperX
Архивный участник
 
Join Date: Dec 2005
Posts: 242
Default

Quote:
Originally Posted by HongK View Post
Sure, I sent you a private message with my msn info...

Look forward to talking to you
I added you, but I dunno if you are online :P I saw you offline, otherway addme you. [email protected]
RipperX is offline  
Old 13.12.2006, 15:19   #8
HongK
Архивный участник
 
Join Date: Jun 2005
Posts: 258
Default Calling C++ Functions from Assembly

Any functions you want to call from your asm file must be defined with the "C" and extern modifiers in your source or header file.

Example:

extern "C" funcName ( paramlist )
{ . . . }

or like this:

extern "C" {

void myFunc();
int thisFunc(int x, int y);
blah blah
}

I've read from within your asm file you can call INVOKE <funcName>, but I tried doing that and I get an error, so I guess that's not an option anymore... So I tried just using a call <funcName> instruction and that worked fine.

EDIT: Heheh .. "You do not have to use the INVOKE statement, of course. The same effect could be produced by using the CALL instruction"

Well that and I think INVOKE must be outdated or at least not used in 64 bit asm
HongK is offline  
Old 16.12.2006, 23:32   #9
~Marquis~
Архивный участник
 
Join Date: Dec 2006
Posts: 252
Default

Awesome guys, i'll start contributing to your project when i'm on holidays =]
keep it up!
~Marquis~ is offline  
Old 17.12.2006, 01:17   #10
mcrabben7
Архивный участник
 
Join Date: Apr 2006
Posts: 461
Default

I linked you guys to a load of 64bit ASM information in my C5 Packet Fixing thread. There are better ways of writing the ASM files and functions but if it works, it works.

Anyways, not a bad start, but would be nice to see you get a working, useful prototype out here. It's one thing to write a string, and another to make a working program
mcrabben7 is offline  
Old 17.12.2006, 06:19   #11
HongK
Архивный участник
 
Join Date: Jun 2005
Posts: 258
Default

Quote:
Originally Posted by mcrabben7 View Post
I linked you guys to a load of 64bit ASM information in my C5 Packet Fixing thread. There are better ways of writing the ASM files and functions but if it works, it works.

Anyways, not a bad start, but would be nice to see you get a working, useful prototype out here. It's one thing to write a string, and another to make a working program
Umm a load of info? Here's the only info you provided: (note how in the quote above you said "load" of info, and then how in the quote below you said "a bit" of... hmmm

Quote:
Anyone curious about learning a bit of x64 architecture changes, x64 Visual Studio 2005, and how to call .asm files from C++, read up.

MSDN x64 Primer:
http://msdn.microsoft.com/msdnmag/is...4/default.aspx
Intel C++/ASM example
http://www3.intel.com/cd/ids/develop...eng/257129.htm

Rest of you, ignore this post :P
The rest of your thread is just filled with "Ohhhh gj guys" or you and your friends congratulating each other on fixes that one another did while one or the other was asleep. Oh, that and screenshots which seem to be everyones favorite thing to share on PP.

Also, I take exception with this statement right here:

Quote:
It's not done anyways, so almost no one would care to leech a DLL they couldn't go start a C5 server with and get players.
Just being able to see examples would be good enough for a few people to pick up and start making progress. Doesn't seem like that will ever materialize though.

Another quote:

Quote:
Remind me not to share anything on PP anymore, since no one ever cares about anything, only the leecher shares where you one-click and got 'zomg c5' or 'zomg c5 skills' without having to do any work...
Some people may not respond to posts because they simply download and study ..

Soooooo to recap, you said you provided a load of resources on 64 bit asm programming ... I only saw two links, both of which I read, but was still left with certain questions as I'm sure many other people were. The problem is, like I've said before, not everyone went to school to be a programmer. I certainly didn't. I only learn by seeing examples and going over those examples again and again until it sticks. If I had time to go sit down for months and study programming hardcore I would, but unfortunately real life does not permit it. The real issue is that there is a lack of reading on 64 bit assembly since there really aren't a whole lot of people who still use asm (save the hackers/crackers). It's not like you can just google "64 bit assembly programming" and get back a million links with programming examples like googling for the same thing except with c or c++.

Anyway, there's a lack of people interested in this so I gave up on it.
HongK is offline  
Old 17.12.2006, 15:19   #12
Nevyn
Архивный участник
 
Join Date: Sep 2006
Posts: 114
Default

Just to point out.
http://softwarecommunity.intel.com/isn/home/
I can't find the specific url link to which where mcrabben7 ment, they seem to have moved it.
Is filled with loads of information how to write your asm code to work
for 64bits. Thats probably what he means. Its highly detailed and does give you a great insight in what and what did not change.
As for the rest of the thread indeed, nothing really worth looking at there.
Concentrate on the urls to begin with HonK. Those are the resources you might have use of.

oh and, you can take a look here http://shareit.intel.com/WikiHome/Articles/111111287 <- Proably will find an example.
Nevyn is offline  
Old 17.12.2006, 16:54   #13
HongK
Архивный участник
 
Join Date: Jun 2005
Posts: 258
Default

I'm not doing this anymore .. I'm done with L2

If you wanted people to really learn how to do it, you could share just ONE example of hooking a function and the asm that you used for it. Mcrabben says he's got a better way to do it than in this thread, so it would be good to see. And I mean something good like hooking usersocket:nread instead of just changing the revision which is cake.
HongK is offline  
Old 18.12.2006, 12:55   #14
mcrabben7
Архивный участник
 
Join Date: Apr 2006
Posts: 461
Default

Quote:
Originally Posted by HongK View Post
I'm not doing this anymore .. I'm done with L2

If you wanted people to really learn how to do it, you could share just ONE example of hooking a function and the asm that you used for it. Mcrabben says he's got a better way to do it than in this thread, so it would be good to see. And I mean something good like hooking usersocket:nread instead of just changing the revision which is cake.
I shared far more than one example in L2EP "Elhaym" and you're still not satisfied? You can't apply the same techniques to the new L2Server? It's the same hooking methods, the assembly is similar, the main difference is there are now 16 registers and the calling convention is done using stack-based variables after the first 4 registers rcx, rdx, r8, and r9. There's also no more stack pointer shifting, as in 32-bit. All it takes is some reading (like in the links I provided) and some disassembly to see that. It doesn't hurt to ask for help, but, trying to say I don't help is pretty low and shallow. Many people I help to program all the time on MSN, but I won't name any names. They keep learning and trying, and don't give up and ask for free stuff.

Hooking C1 is the same as hooking C4. It's all assembly. I shared one of my largest projects in my entire life on PP and people still moan and complain it's not enough. I help you on MSN and send my some of my personal files with function names/addresses and you moan and complain it's not enough. I told you to use WriteProcessMemory and VirtualProtect (not VirtualProtectEx) and you still come back and moan and complain.

Hacking and all this is not for the hobby programmer. You have to be good at it. Very good. I can't make you or anyone else very good at this style of programming. You either got the gift and determination, or you don't.

About my links: they contain ALL you need to know. A working example of x64 assembly, programming, and even compiler intrinsics, as well as an MSDN overview of 64-bit vs 32-bit assembly calling conventions, etc. It's pretty much everything you need to be able to start understanding. No one gave me links to x64 programming tutorials. No one taught me to hack and hook and do anything. Stop being spoiled and use the resources available to you. I have personally shared many resources, and many examples, and got pretty much nothing in return. Nevyn linked you to many more, and there should be plenty of examples to follow there. If you want to get it done

HongK, if you're going to moan and complain that I don't "share" you can bite me, because without my shares, or my help, you'd never even have been able to attempt your C2 project, or anything like it. Stop being ungrateful. You can't expect everything for free on a silver platter.
mcrabben7 is offline  
Old 18.12.2006, 15:05   #15
HongK
Архивный участник
 
Join Date: Jun 2005
Posts: 258
Default

Quote:
Originally Posted by mcrabben7 View Post
I shared far more than one example in L2EP "Elhaym" and you're still not satisfied? You can't apply the same techniques to the new L2Server? It's the same hooking methods, the assembly is similar, the main difference is there are now 16 registers and the calling convention is done using stack-based variables after the first 4 registers rcx, rdx, r8, and r9. There's also no more stack pointer shifting, as in 32-bit. All it takes is some reading (like in the links I provided) and some disassembly to see that. It doesn't hurt to ask for help, but, trying to say I don't help is pretty low and shallow. Many people I help to program all the time on MSN, but I won't name any names. They keep learning and trying, and don't give up and ask for free stuff.

Hooking C1 is the same as hooking C4. It's all assembly. I shared one of my largest projects in my entire life on PP and people still moan and complain it's not enough. I help you on MSN and send my some of my personal files with function names/addresses and you moan and complain it's not enough. I told you to use WriteProcessMemory and VirtualProtect (not VirtualProtectEx) and you still come back and moan and complain.

Hacking and all this is not for the hobby programmer. You have to be good at it. Very good. I can't make you or anyone else very good at this style of programming. You either got the gift and determination, or you don't.

About my links: they contain ALL you need to know. A working example of x64 assembly, programming, and even compiler intrinsics, as well as an MSDN overview of 64-bit vs 32-bit assembly calling conventions, etc. It's pretty much everything you need to be able to start understanding. No one gave me links to x64 programming tutorials. No one taught me to hack and hook and do anything. Stop being spoiled and use the resources available to you. I have personally shared many resources, and many examples, and got pretty much nothing in return. Nevyn linked you to many more, and there should be plenty of examples to follow there. If you want to get it done

HongK, if you're going to moan and complain that I don't "share" you can bite me, because without my shares, or my help, you'd never even have been able to attempt your C2 project, or anything like it. Stop being ungrateful. You can't expect everything for free on a silver platter.
First of all, I never was ungrateful. I was one of the first people to praise your release of l2ep so don't give me that bullshit. Second, when did I say anything about not sharing? You might want to re-read. You posted two links on the topic. Maybe those links made more sense to you than others. And when does seeing one example of a hook for a c4 function and its assembly constitute having EVERYTHING for free on a silver platter. I've spent the last two weeks sifting through l2server and trying to understand how its passing certain variables and pointers and trying to find a place to catch those. It can be frustrating at times and sometimes more questions arise. But I will not be addressed by you as if I just sit here and want it all for free. You can eat a dick.

The whole problem is that the examples that are specific to l2 are being kept like a trade secret. It's ok to pass out examples to conceptual ideas because that would take a lot longer for someone to figure out how to apply to L2. But showing examples relating EXACTLY to L2 would be bad. I don't know if you're worried other people will start their own C5 server or not. I could care less. It's never been about that with me.

This forum SHOULD be about people learning together and moving forward. It shouldn't be about just one or two people learning. If someone knows a way to do things thats better than what's out there, by all means show others how to do it. But don't go start threads stating you have a project and then post screenshots or congratulatory comments to your friends because you're the only people working on it. I had some people msg me on msn one time about the c2 server and how to understand the assembly. I explained away every detail I knew on the subject and how I had done what I did. The questions were sometimes very basic to the point of where I could have just said "you noob, go read a manual" .. But I didn't do that. I spent 20-30 minutes explaining it all in detail. That's what I consider lending a helping a hand. I guess to you that's giving it all away on a silver platter. But I don't buy that.

Anyway, like I said, I'm done with this. It's been too many years that I've been addicted to L2 and it's a good time to move on. This post is only so that you and others like you will try and understand some of the other people that may not speak up.
HongK is offline  
Old 19.12.2006, 03:55   #16
mcrabben7
Архивный участник
 
Join Date: Apr 2006
Posts: 461
Default

Well HongK, say what you will, but the one time I asked you for something simple, you wouldn't even tell me. That's a great way to return the favor to someone. I never asked you for code, or files. You started talking to me about an exploit, and I asked you how it works, and you said nothing to help me. Just gloated that you had a private build of AmpeD DLL. Yea, good for you.

Most people here can't program. Programming is a field of study, not a hobby. Most people here want a compiled file with all the answers, not code. You want code, you ask for help in private, or you go learn and study.

Quote:
Originally Posted by HongK View Post
Anyway, like I said, I'm done with this. It's been too many years that I've been addicted to L2 and it's a good time to move on. This post is only so that you and others like you will try and understand some of the other people that may not speak up.
People like me, who worked on their own time for months to learn this, MONTHS HongK. No one here has ever, ever, ever given me the type of information you've been able to get for free. I started L2EP as a test of the PP community, and it was a failure. The PP community doesn't care. I can still count the people who helped me in PP on both hands, and the number isn't even 10. More like 5. You're spoiled. I worked my ass off to learn everything I know, so you can stop being such an ingrate.

All this boils down to is you want my code, blah blah, well you can't have it. Get over it. Last time I released my code no one cared, so why should I release anything now.

I continue to help people code via MSN every day. I guess you won't be one of them any more, since you had to go on your parade and attack me because you're patience is gone and you're unable to learn something. Don't attack me out of your own stress. It's your fault you can't do it, no one else's fault.

Have a nice life.
mcrabben7 is offline  
Old 19.12.2006, 04:34   #17
testdude
Архивный участник
 
Join Date: Nov 2005
Posts: 504
Default

this topic turned bad fast :x
testdude 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 16:17.