![]() |
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,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. |
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! |
Quote:
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 |
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 FirstPatchThe 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 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! |
Quote:
Look forward to talking to you |
Quote:
|
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 |
Awesome guys, i'll start contributing to your project when i'm on holidays =]
keep it up! |
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 :) |
Quote:
Quote:
Also, I take exception with this statement right here: Quote:
Another quote: Quote:
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. |
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. |
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::onread instead of just changing the revision which is cake. |
Quote:
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. |
Quote:
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. |
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:
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. |
this topic turned bad fast :x
|
| All times are GMT. The time now is 15:09. |