#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#define TRUE (1==1)
#define FALSE (1==0)
#define STRINGMAX_SIZE 255
void inicializa_variaveis(void);
void addCaracterToString(char *s, char c);
void toLowerCase(char *s);
int copia_ateh_trocar_string(FILE *arq_origem, FILE *arq_destino, char *sorig, char *snovo);
bool shouldRebuildCraqueado(char *host);
void removeInvalidCharsAtTheEnd(char *s);
void readParameters(int argc, char *argv[]);
char tibia_server[45][45];
char otserv_rsakey[45][45];
char tibia_rsakey[45][45];
char stringdoida[10];
bool gameMasterMode = false; // por default, gamemaster eh false
char host[STRINGMAX_SIZE]="localhost";
char pathConfig[STRINGMAX_SIZE]=""; //path de configuracao do cliente
char enginePar[STRINGMAX_SIZE]=""; // engine 0, 1 etc
char temporaryFileName[STRINGMAX_SIZE] = "actualServer.inf";
char temporatyExecutableName[STRINGMAX_SIZE] = "./craqueado";
int main(int argc, char *argv[])
{
int aux,aux2, c;
FILE *arq_origem,*arq_destino;
char pedacodehost[5],pedacodeoldhost[5];
char *hostpos,*oldhostpos;
readParameters(argc, argv);
removeInvalidCharsAtTheEnd(host);
printf("Connecting to \"%s\"", host);
if (strlen(pathConfig)>0)
printf(" using configuration at \"%s\"", pathConfig);
if (gameMasterMode)
printf(" with gamemaster mode");
printf(".\n");
if (shouldRebuildCraqueado(host)) {
if (strlen(host)>strlen("login01.tibia.com")){
printf("Host name grande demais. Ao inves do hostname experimente colocar o endereco ip. \n");
printf("OBS: Para achar o endereco IP voce pode digitar ping seguido de hostname, como em: \n");
printf("ping www.tibia.com\n");
return(1);
}
if ((arq_origem=fopen("./Tibia","rb"))==NULL) {
printf("Impossivel abrir arquivo tibia original.\n");
return(1);
}
if ((arq_destino=fopen("./craqueado","wb"))==NULL) {
printf("Impossivel criar arquivo craqueado. Provavelmente o ipchanger ja estah sendo usado.\n");
fclose(arq_origem);
return(1);
}
inicializa_variaveis();
for (aux=0;aux<10;aux++) {
if (!copia_ateh_trocar_string(arq_origem,arq_destino,tibia_rsakey[aux],otserv_rsakey[aux])){
printf("RSA key numero %d nao foi encontrada.\n",aux);
fclose(arq_origem);
fclose(arq_destino);
return(1);
}
}
if (!copia_ateh_trocar_string(arq_origem,arq_destino,stringdoida,stringdoida)) {
printf("String doida nao encontrada. \n");
fclose(arq_origem);
fclose(arq_destino);
return(1);
}
for (aux=0;aux<10;aux++) {
int sizehostoldname=strlen(tibia_server[aux]);
hostpos=host;
oldhostpos=tibia_server[aux];
for (int aux2=0;aux2<=int(sizehostoldname)/4;aux2++) {
pedacodehost[0]=*hostpos;
hostpos++;
pedacodehost[1]=*hostpos;
hostpos++;
pedacodehost[2]=*hostpos;
hostpos++;
pedacodehost[3]=*hostpos;
hostpos++;
pedacodehost[4]='\0';
pedacodeoldhost[0]=*oldhostpos;
oldhostpos++;
pedacodeoldhost[1]=*oldhostpos;
oldhostpos++;
pedacodeoldhost[2]=*oldhostpos;
oldhostpos++;
pedacodeoldhost[3]=*oldhostpos;
oldhostpos++;
pedacodeoldhost[4]='\0';
if (!copia_ateh_trocar_string(arq_origem,arq_destino,pedacodeoldhost,pedacodehost)) {
printf("Host nao encontrado %d %d %s %s.\n", aux, aux2,pedacodeoldhost,pedacodehost);
fclose(arq_origem);
fclose(arq_destino);
return(1);
}
}
}
while((c=getc(arq_origem))!=EOF) //termina de copiar o final
putc(c,arq_destino);
fclose(arq_origem);
fclose(arq_destino);
char chmodEcho[STRINGMAX_SIZE] = "chmod +x ";
strcat(chmodEcho, temporatyExecutableName);
system("chmod +x ./craqueado");
char msgRm[STRINGMAX_SIZE]="rm ";
strcat(msgRm, temporaryFileName);
system(msgRm);
char msgEcho[STRINGMAX_SIZE]="echo ";
strcat(msgEcho, host);
strcat(msgEcho, ">> ");
strcat(msgEcho, temporaryFileName);
system(msgEcho);
}
char execString[STRINGMAX_SIZE];
strcpy(execString, temporatyExecutableName);
if (gameMasterMode)
strcat(execString, " gamemaster");
if (strlen(pathConfig)>0) {
strcat(execString, " path ");
strcat(execString, pathConfig);
}
if (strlen(enginePar)>0) {
strcat(execString, " engine ");
strcat(execString, enginePar);
}
system(execString);
return(0);
}
void readParameters(int argc, char *argv[])
{
char argvAtual[STRINGMAX_SIZE];
int pos = 1;
while (pos < argc) {
strcpy(argvAtual, argv[pos]);
toLowerCase(argvAtual);
if (strcmp(argvAtual, "path")==0) {
if (pos + 1 < argc) {
strcpy(pathConfig, argv[pos+1]);
pos++;
}
}
else if (strcmp(argvAtual, "engine")==0) {
if (pos+1 < argc) {
strcpy(enginePar, argv[pos+1]);
pos++;
}
}
else if (strcmp(argvAtual, "gamemaster")==0)
gameMasterMode = true;
else
strcpy(host, argv[pos]);
pos++;
}
}
void toLowerCase(char *s)
{
int aux;
for (aux = 0; aux < strlen(s); aux++) {
int i = (int)s[aux];
if ((i>=int('A')) && (i<=int('Z')))
s[aux] = char(i + int('a') - int('A'));
}
}
bool shouldRebuildCraqueado(char *host)
{
FILE *arq;
bool ret = true;
if ((arq=fopen(temporaryFileName,"r"))==NULL)
return(true);
char oldHost[STRINGMAX_SIZE];
if (fgets(oldHost, sizeof(oldHost),arq)!=NULL) {
removeInvalidCharsAtTheEnd(oldHost);
if (strcmp(oldHost, host) == 0)
ret = false;
}
fclose(arq);
return(ret);
}
void removeInvalidCharsAtTheEnd(char *s)
{
int size = strlen(s);
if (size>=1) {
if ((s[size-1]=='\n') || (s[size-1]==' ')) {
s[size-1] = '\0';
removeInvalidCharsAtTheEnd(s);
}
}
}
void addCaracterToString(char *s, char c)
{
int size = strlen(s);
s[size] = c;
s[size+1] = '\0';
}
int copia_ateh_trocar_string(FILE *arq_origem,FILE *arq_destino,char *sorig,char *snovo)
{
char *s;
char c;
int pos=0;
int erro,aux3;
int sizenovo=strlen(snovo);
int sizeorig=strlen(sorig);
s=(char*)malloc(sizeof(char)*(sizeorig+1));
do {
erro=fread(&c,sizeof(char),1,arq_origem);
s[pos]=c;
if (c!=sorig[pos]) {
for (aux3=0;aux3<=pos;aux3++)
fputc(s[aux3],arq_destino);
pos=0;
}
else
{
s[pos]=c;
pos++;
if (pos==sizeorig) {
free(s);
for (aux3=0;aux3<sizenovo;aux3++)
fputc(snovo[aux3],arq_destino);
for (aux3=sizenovo;aux3<sizeorig;aux3++)
fputc('\0',arq_destino);
for (aux3=sizeorig;aux3<sizenovo;aux3++)
if(fread(&c,sizeof(char),1,arq_origem)==0){
printf("Erro! Fim de arquivo encontrado.\n");
return(FALSE);
}
return(TRUE);
}
}
}
while(erro==1);
free(s); // ESTAS DUAS ULTIMAS LINHAS NAO SERAO EXECUTADAS SE NAO HOUVER PROBLEMAS.
return(FALSE);
}
void inicializa_variaveis(void)
{
strcpy(tibia_server[0],"login01.tibia.com");
strcpy(tibia_server[1],"login02.tibia.com");
strcpy(tibia_server[2],"login03.tibia.com");
strcpy(tibia_server[3],"login04.tibia.com");
strcpy(tibia_server[4],"login05.tibia.com");
strcpy(tibia_server[5],"tibia01.cipsoft.com");
strcpy(tibia_server[6],"tibia02.cipsoft.com");
strcpy(tibia_server[7],"tibia03.cipsoft.com");
strcpy(tibia_server[8],"tibia04.cipsoft.com");
strcpy(tibia_server[9],"tibia05.cipsoft.com");
strcpy(tibia_rsakey[0],"13212774320587228406229509908229");
strcpy(tibia_rsakey[1],"33849527763264961655079678763618");
strcpy(tibia_rsakey[2],"43343953435544496682053323833394");
strcpy(tibia_rsakey[3],"35179772895415509701210392836078");
strcpy(tibia_rsakey[4],"69598211322144732915757121388004");
strcpy(tibia_rsakey[5],"95033169914814069637740318278150");
strcpy(tibia_rsakey[6],"29073368403252417478274013435762");
strcpy(tibia_rsakey[7],"96990629870233111328210165697754");
strcpy(tibia_rsakey[8],"88792221429527047321331896351555");
strcpy(tibia_rsakey[9],"606801473202394175817");
strcpy(otserv_rsakey[0],"10912013296739942927886096050899");
strcpy(otserv_rsakey[1],"55415282375029027981291234687579");
strcpy(otserv_rsakey[2],"37266291492576446330739696001110");
strcpy(otserv_rsakey[3],"60390723088861007265581882535850");
strcpy(otserv_rsakey[4],"34290575928276294364131085660290");
strcpy(otserv_rsakey[5],"93628212635953836686562675849720");
strcpy(otserv_rsakey[6],"62078627943109021801768106152175");
strcpy(otserv_rsakey[7],"50567108238764764442605581471797");
strcpy(otserv_rsakey[8],"07119674283982419152118103759076");
strcpy(otserv_rsakey[9],"030616683978566631413");
//132127743205872284062295099082293384952776326496165507967876361843343953435544496682053323833394351797728954155097012103928360786959821132214473291575712138800495033169914814069637740318278150290733684032524174782740134357629699062987023311132821016569775488792221429527047321331896351555606801473202394175817
strcpy(stringdoida,"Windows Server 2008 R2 Web Server Edition 64 Bit");
}