[?RELEASE?]Source(ugly, untested) of /dice fix

07/15/2013 16:19 TheMarv :<#1
Heyho,

ich weiß nicht obs funtzt oder nicht, und ja ich weiß die Source ist hässlich,
ich hatte diese ganzen Threads von wegen Fix für die /dice Funktion gefunden und habe dann einfach mal am Handy eine (wahrscheinlich buggy) Funktion zum Überschreiben geschrieben.

Es geht an sich um die Funktion number_ex...wenn jemand sieht das es nicht funktioniert, würde ich ihn doch liebend gerne beten es zu fixen und hier im Thread zu posten, das wäre sehr nett ^-^


Naja hier habt ihr die Source:


ob es funktioniert weiß ich wie gesagt nicht, ich hoffe schon xD

MfG
07/15/2013 16:28 .Bloddy#2
[Only registered and activated users can see links. Click Here To Register...] work 100%
07/15/2013 16:48 TheMarv :<#3
Quote:
Originally Posted by .Bloddy View Post
[Only registered and activated users can see links. Click Here To Register...] work 100%
are you sure? are you really, really sure?
07/15/2013 17:04 Mashkin#4
Seems legit because you first need to tell the compiler what thecore_random points to (you cannot call functions by name without introducing their addresses).

The function is roughly the same - except that the error handling looks better to me.
The reference to sys_err is missing though.
07/15/2013 17:10 TheMarv :<#5
Quote:
Originally Posted by Mashkin View Post
Seems legit because you first need to tell the compiler what thecore_random points to (you cannot call functions by name without introducing their addresses).

The function is roughly the same - except that the error handling looks better to me.
The reference to sys_err is missing though.
i knew i forgot something....could you tell me the address of the thecore_random function?
07/15/2013 17:42 Lord iRemix#6
Ein Tpp:

Wenn bei einer if-Abfrage nur eine Zeile folgt, musst du die geschweiften Klammern nicht machen.
Das Gleiche auch bei Schleifen etc.

So zB:
[Only registered and activated users can see links. Click Here To Register...]

Spart Zeit am Handy :p
07/15/2013 17:47 iMer#7
Quote:
Originally Posted by .Remix. View Post
Ein Tpp:

Wenn bei einer if-Abfrage nur eine Zeile folgt, musst du die geschweiften Klammern nicht machen.
Das Gleiche auch bei Schleifen etc.

So zB:
[Only registered and activated users can see links. Click Here To Register...]

Spart Zeit am Handy :p
Sollte man aber trozdem machen, da es zur lesbarkeit beiträgt.
07/15/2013 18:41 TheMarv :<#8
Quote:
Originally Posted by .Remix. View Post
Ein Tpp:

Wenn bei einer if-Abfrage nur eine Zeile folgt, musst du die geschweiften Klammern nicht machen.
Das Gleiche auch bei Schleifen etc.

So zB:
[Only registered and activated users can see links. Click Here To Register...]

Spart Zeit am Handy :p
jo schon, aber ist nicht so meine Art :P
Ab und zu mach ich es, meistens vergesse ich es einfach xD
07/15/2013 18:47 xCPx#9
Wieso zur hölle schaut eig niemand danach, was fürn rückgabewert number_ex eigentlich hat?
Selbst die Lösung von Luca ist falsch, da er auch nicht drauf geachtet hat.
Hier mal meine Variante (kp ob gut, aber immerhin mitm richtigen Rückgabe-Wert)

in den header:
Code:
unsigned int (*number_ex)(int arg1, int arg2) = (unsigned int(*)(int,int))0x08439620;
int (*thecore_random)() = (int(*)())0x08439610;
in die main.cpp
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <stdbool.h>
#include <dlfcn.h>
#include <sys/mman.h>
#include <inttypes.h>
#include "utils/ddetour.h"
#include "gamefunctions.h"


void __attribute__ ((constructor)) my_load(void);

unsigned int fix_number_ex(int a1, int a2)
{
	int temp;
	if(a1 <0)
	{
		a1 += -(a1*2);
	}
	if(a2 <0)
	{
		a2 += -(a2*2);
	}
	if(a1 > a2)
	{
		temp = a1;
		a1 = a2;
		a2 = temp;
	}
	temp = (a2 +1 - a1)
	if(temp <= 0)
	{
		temp = 1;
	}
	return a1 + thecore_random() % temp;
}

void my_load(void)
{
	srand(time(0));
	number_ex = (unsigned int (*)(int, int))detour((unsigned int*)0x08439620,(unsigned int *)fix_number_ex, DETOUR_LEN_AUTO, 0);
}
07/15/2013 19:00 TheMarv :<#10
Quote:
Originally Posted by xCPx View Post
Wieso zur hölle schaut eig niemand danach, was fürn rückgabewert number_ex eigentlich hat?
Selbst die Lösung von Luca ist falsch, da er auch nicht drauf geachtet hat.
Hier mal meine Variante (kp ob gut, aber immerhin mitm richtigen Rückgabe-Wert)

in den header:
Code:
unsigned int (*number_ex)(int arg1, int arg2) = (unsigned int(*)(int,int))0x08439620;
int (*thecore_random)() = (int(*)())0x08439610;
in die main.cpp
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <stdbool.h>
#include <dlfcn.h>
#include <sys/mman.h>
#include <inttypes.h>
#include "utils/ddetour.h"
#include "gamefunctions.h"


void __attribute__ ((constructor)) my_load(void);

unsigned int fix_number_ex(int a1, int a2)
{
	int temp;
	if(a1 <0)
	{
		a1 += -(a1*2);
	}
	if(a2 <0)
	{
		a2 += -(a2*2);
	}
	if(a1 > a2)
	{
		temp = a1;
		a1 = a2;
		a2 = temp;
	}
	temp = (a2 +1 - a1)
	if(temp <= 0)
	{
		temp = 1;
	}
	return a1 + thecore_random() % temp;
}

void my_load(void)
{
	srand(time(0));
	number_ex = (unsigned int (*)(int, int))detour((unsigned int*)0x08439620,(unsigned int *)fix_number_ex, DETOUR_LEN_AUTO, 0);
}
Und was wenn beide Werte gleich sind? :P
07/15/2013 19:15 xCPx#11
Quote:
Originally Posted by TheMarv :< View Post
Und was wenn beide Werte gleich sind? :P
Haste die exception doch drin:
temp = (a2 +1 - a1)


Wenn beide gleich sind ergibt das 1

Und sollte doch 0 rauskommen, so ist es danach durch:
if(temp <= 0)
{
temp = 1;
}
Wd 1

also von daher sollte das alles gefixxt sein.
07/15/2013 19:45 TheMarv :<#12
Quote:
Originally Posted by xCPx View Post
Haste die exception doch drin:
temp = (a2 +1 - a1)


Wenn beide gleich sind ergibt das 1

Und sollte doch 0 rauskommen, so ist es danach durch:
if(temp <= 0)
{
temp = 1;
}
Wd 1

also von daher sollte das alles gefixxt sein.
achso ja, hatte nur drüber geschaut gehabt xD
naja aber was solls, es werden sowieso ein großteil der server nicht einbauen :P
07/15/2013 20:11 Computerfreek#13
Gut, dass es uns ohne die ddetour.h was nützt.
07/15/2013 20:14 TheMarv :<#14
Quote:
Originally Posted by Computerfreek View Post
Gut, dass es uns ohne die ddetour.h was nützt.
die gibts beim thread wie man .so extensions macht mit dabei....
07/15/2013 23:24 Mi4uric3#15
Quote:
Originally Posted by Computerfreek View Post
Gut, dass es uns ohne die ddetour.h was nützt.
Eine Detour-Funktion zu schreiben ist nicht sonderlich kompliziert..

Pseudocode
Code:
void detour(void* src, void* dest) {
	mprotect von src mit size 5
	unsigned char array mit größe 5 erstellen
	array[0] = E9
	array[1] = dest - src - 5
	memcpy von array nach src mit der länge 5
}