Is there any way to find the names and addresses of virtual functions of a class, without manually typing in the names?
Wait, why do you want to do that?
Wrong forum, poop
[QUOTE=shill le 2nd;27378228]Wait, why do you want to do that?[/QUOTE]
If you're talking to me, I'm making a game engine, and I'm trying to figure out how I'll do netcode.
In a doubly-linked list, when the list has only one element, do both the head and the tail point to the same element?
I want to be able to slow down people editing variables in my game such as the lives and kills they have with things like Cheat Engine. Are there any easy ways to do this?
[QUOTE=Sc00by22;27381523]I want to be able to slow down people editing variables in my game such as the lives and kills they have with things like Cheat Engine. Are there any easy ways to do this?[/QUOTE]
Pretty easy, if you have frame independent movement(so movement is like Move(250 * time) or something) just add another factor so it's like Move(250 * time * factor) and change the factor accordingly.
[QUOTE=WTF Nuke;27381586]Pretty easy, if you have frame independent movement(so movement is like Move(250 * time) or something) just add another factor so it's like Move(250 * time * factor) and change the factor accordingly.[/QUOTE]
ou seem to have missed the point completelly
[QUOTE=Richy19;27381640]ou seem to have missed the point completelly[/QUOTE]
Oh woops misread sorry.
[QUOTE=Sc00by22;27381523]I want to be able to slow down people editing variables in my game such as the lives and kills they have with things like Cheat Engine. Are there any easy ways to do this?[/QUOTE]
One easy way to do it is storing the value in memory with a few mathematical operations applied to it. For example, a multiplication and an addition. That way it will be a lot harder for people to find the right memory address.
For some reason, I can't implement zlib properly.
It always works in debug mode, but it always crashes on initialization in release mode. What am I doing wrong?
(Crash is at inflateInit, so the rest doesn't matter, e.g. inflateEnd)
[code]
#include <stdio.h>
#include <iostream>
#pragma comment(lib, "ZDLL")
#include "zconf.h"
#include "zlib.h"
z_stream strm;
int main()
{
printf("Okay!\n");
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
int ret = inflateInit(&strm);
if (ret != Z_OK)
{
std::cout << "Error at inflateInit!\n";
std::cout.flush();
throw 1;
return 0;
}
return 0;
}
[/code]
In debug mode, this runs fine. In release mode, it returns "Unhandled exception at 0x00905a4d in zlibTest.exe: 0xC0000005: Access violation.". I used pragma comment to make it obvious that it isn't a configuration problem.
Using [url=http://www.zlib.net/]zlib 1.2.5[/url].
Are you sure you're linking with the release build of zlib?
zlib's documentation recommends using a precompiled zlib1.dll, so I did that. Their archive contains only a single dll file and a single lib file, and that's what I'm using...
[QUOTE=shill le 2nd;27370628]Start writing to random addresses? It's hard [i]not[/i] to cause a BSOD in assembly.[/QUOTE]
Do you know what you're talking about?
We've had this thing called protected mode for almost two decades now.
Uh-oh.
[img]http://eagle.undo.it:8083/img/optref.png[/img]
(Pictured: Comic Sans. Also, /OPT:REF was interfering with stuff)
(Captioned: Used the same joke twice. See also: redundant systems.)
Now, what's broken? My code, zlib's code, /OPT:REF, or Stroustrup?
Either way, I'm happy that it's w-...no longer crashing. Test later, post now.
[QUOTE=mmavipc;27378103]Is there any way to find the names and addresses of virtual functions of a class, without manually typing in the names?[/QUOTE]
How do you want to refer to the function instead, if not by name? Unless you just want an alias, in which case a function reference would do.
[QUOTE=mmavipc;27378103]Is there any way to find the names and addresses of virtual functions of a class, without manually typing in the names?[/QUOTE]
I suspect you mean something like runtime introspection, which you do get in dynamic languages and languages with featureful runtimes like .NET and JVM (but not with the default C++ runtime, if that's what you are using).
Google "reflection" or "runtime introspection".
[editline]13th January 2011[/editline]
[QUOTE=Sc00by22;27381523]I want to be able to slow down people editing variables in my game such as the lives and kills they have with things like Cheat Engine. Are there any easy ways to do this?[/QUOTE]
Use a XOR cipher with a one-time pad.
[QUOTE=Overv;27384858]One easy way to do it is storing the value in memory with a few mathematical operations applied to it. For example, a multiplication and an addition. That way it will be a lot harder for people to find the right memory address.[/QUOTE]
Cheers :D
[img]http://no-named.dk/files/upload/fuuu.png[/img]
[editline]13th January 2011[/editline]
Yes, it's a little messy.
Are you sure your numeric types are signed?
[QUOTE=Overv;27388043]Are you sure your numeric types are signed?[/QUOTE]
All of them are ints.
[QUOTE=mmavipc;27378103]Is there any way to find the names and addresses of virtual functions of a class, without manually typing in the names?[/QUOTE]
Just saw this, sorry.
You can get the pointer to the vtable of a class with this:
[cpp]int* vtable = *(int**)classptr;[/cpp]
So that if you know the offsets, you can call the functions like this (using MSVC++):
[cpp]
__asm mov ecx, classptr;
// for this example the function takes no arguments and returns an int, and is at offset 3 (4th function) in the vtable
int retval = (((int(*)())vtable[3])(); // cast into a function pointer and call
[/cpp]
This has its pitfalls however, because if you change the function parameters without updating the code that calls it you won't get a compile time error and your program will likely crash. Also if you add a function before the one you call by the vtable index, you'll have to update the offsets of all of them that you've done that way.
[QUOTE=Combino;27385759]Do you know what you're talking about?
We've had this thing called protected mode for almost two decades now.[/QUOTE]
you are too smart for your own good mister
[QUOTE=yakahughes;27388411]Just saw this, sorry.
You can get the pointer to the vtable of a class with this:
[cpp]int* vtable = *(int**)classptr;[/cpp]
So that if you know the offsets, you can call the functions like this:
[cpp]
__asm mov ecx, classptr;
// for this example the function takes no arguments and returns an int, and is at offset 3 (4th function) in the vtable
int retval = (((int(*)())vtable[3])(); // cast into a function pointer and call
[/cpp]
This has its pitfalls however, because if you change the function parameters without updating the code that calls it you won't get a compile time error and your program will likely crash. Also if you add a function before the one you call by the vtable index, you'll have to update the offsets of all of them that you've done that way.[/QUOTE]
intptr_t
Also, this will be dependent on the compiler and platform, so you should probably consult the compiler manual first.
Instead of the inline assembly you could also cast to a member-function pointer.
[QUOTE=ZeekyHBomb;27388708]intptr_t
...
Instead of the inline assembly you could also cast to a member-function pointer.[/QUOTE]
Why intptr_t? Screw typedefs, the compiler just turns the into int* anyway, and something as basic as intptr_t will never be changed to anything other than int*.
Also, online assembly efteedublyu, but for the guy who asked, here's the member-method cast version:
[cpp]typedef int(Class::*funcptr)();
int* vtable = *(int**)classptr;
funcptr f = (funcptr)vtable[3];
(classptr->*f)();
[/cpp]
Oh, and I thought the inline assembly syntax made it clear that it was MSVC++ being used, since no other compiler that I've seen does it that way.
[editline]13th January 2011[/editline]
[QUOTE=ZeekyHBomb;27388708]
Also, this will be dependent on the compiler and platform, so you should probably consult the compiler manual first.[/QUOTE]
To clarify why for anyone who wants to know (as for the compiler part), it's because Visual C++ stores the vtable pointer as the first pointer in a class. Other compilers store it at a different position, so casting it to an int** and dereferencing it once won't work any more.
[QUOTE=yakahughes;27389037]To clarify why for anyone who wants to know (as for the compiler part), it's because Visual C++ stores the vtable pointer as the first pointer in a class. Other compilers store it at a different position, so casting it to an int** and dereferencing it once won't work any more.[/QUOTE]
Actually, every common compiler uses a vtable for virtual functions with the same ABI. It's the de-facto standard way of doing it. The problem is putting the this pointer in ECX using inline assembly. There are many different versions of thiscall, and they don't all put the this pointer in ECX. And again, as you know, inline assembly is not standardised either.
Using a member function pointer solves both problems, leaving only the issue of vtable lookup, which is not a problem in practice.
@below, it's "inline assembly", not "online assembly" :P
[QUOTE=jA_cOp;27389448]There are many different versions of thiscall, and they don't all put the this pointer in ECX. And again, as you know, inline assembly is not standardised either.[/QUOTE]
Ah, I didn't know this. Thanks.
It is also worth noting that the online assembly way won't work for member varargs functions, which are cdecl (and I believe that the this pointer is passed as the last argument on the stack, not sure though).
I have a fucking naughty problem:
I have a string, S, which contains "23". I need to use S.at(i) to extract each number in the string through a for loop which goes from 0 to S.length().
The problem is that S.at(0) returns the whole string instead of just "2". And that fucks over the whole program.
How do I fix / get around that?
[QUOTE=TerabyteS;27390599]I have a fucking naughty problem:
I have a string, S, which contains "23". I need to use S.at(i) to extract each number in the string through a for loop which goes from 0 to S.length().
The problem is that S.at(0) returns the whole string instead of just "2". And that fucks over the whole program.
How do I fix / get around that?[/QUOTE]
string.at returns a const char&, not a string or a character sequence. Are you casting the result?
Also, you can use S[i] since you don't need string.at's range-checking.
[editline]13th January 2011[/editline]
Could you post your code?
[QUOTE=Metroid48;27391033]string.at returns a const char&, not a string or a character sequence. Are you casting the result?
Also, you can use S[i] since you don't need string.at's range-checking.[/QUOTE]
I don't understand: I need to use atoi() on that part of the string (should be a char) but when I use atoi on it I get:
D:\CodeBlocks\Projects\multilife\main.cpp|273|error: invalid conversion from 'char' to 'const char*'|
I tried fixing it by using atoi(&S.at()), but that's probably what causes the thing to output 23 instead of 2 when the character at 0 is chosen. It does the same with S[0]. What the fuck.
Sorry, you need to Log In to post a reply to this thread.