/* * TNS2XML v2.0 * * Copyright (C) 2014 Excale * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #define A(_, __, ___) ((__(*)___)nl_osvalue((int*)_, sizeof(_)/sizeof(_[0]))) #define B(_, __, ___) A(_, __, (___)) #define C(_) nl_osvalue((int*)_, sizeof(_)/sizeof(_[0])) static const uintptr_t _D[]={0x10103A40, 0x10104064, 0x10103554, 0x10103BA0, 0x0, 0x0, 0x10138664, 0x10138C88, 0x101380A8, 0x101386FC}; #define D B(_D, void*, void) static const uintptr_t _E[]={0x10263474, 0x10263BA0, 0x10262EE4, 0x10263674, 0x0, 0x0, 0x102E6C28, 0x102E7668, 0x102E66A4, 0x102E7114}; #define E B(_E, void*, void*) static const uintptr_t _F[]={0x10263810, 0x10263F3C, 0x10263280, 0x10263A10, 0x0, 0x0, 0x102E6FC4, 0x102E7A04, 0x102E6A40, 0x102E74B0}; #define F B(_F, void*, void*) static const uintptr_t _G[]={0x101032E4, 0x10103908, 0x10102DF8, 0x10103444, 0x0, 0x0, 0x10137F04, 0x10138528, 0x10137948, 0x10137F9C}; #define G A(_G, void, (void*, char*, int)) static const uintptr_t _H[]={0x101034FC, 0x10103B20, 0x10103010, 0x1010365C, 0x0, 0x0, 0x1013811C, 0x10138740, 0x10137B60, 0x101381B4}; #define H B(_H, char*, void*) static const uintptr_t _I[]={0x1010391C, 0x10103F40, 0x10103430, 0x10103A7C, 0x0, 0x0, 0x1013853C, 0x10138B60, 0x10137F80, 0x101385D4}; #define I B(_I, void, void*) static const uintptr_t _J[]={0x10383CDC, 0x1038440C, 0x1038159C, 0x10381D2C, 0x0, 0x0, 0x10408768, 0x104091A8, 0x104065EC, 0x1040705C}; #define J B(_J, void, char*) #define K "/documents/TNS2XML/" #define L "TNS2XML" static int32_t M; static const uintptr_t N[]={0x102636A4, 0x10263DD0, 0x10263114, 0x102638A4, 0x0, 0x0, 0x102E6E58, 0x102E7898, 0x102E68D4, 0x102E7344}; HOOK_DEFINE(O) { if((M>0x0)||(HOOK_SAVED_REGS(O)[0x7]!=0x1)) { M-=0x400; HOOK_RESTORE_RETURN_SKIP(O, 0x0, 0x0); } HOOK_RESTORE_RETURN_SKIP(O, 0x104, 0x1); } int main() { HOOK_INSTALL(C(N), O); FILE*P=NULL; P=fopen(K"in.tns", "rb"); if(P==NULL) { show_msgbox(L, "Cannot open file 'in.tns'. Please put the input file in '"K"in.tns' and try again.\nAborting."); goto Q; } if(fseek(P, 0x0, SEEK_END)) { show_msgbox(L, "fseek failed.\nAborting."); fclose(P); goto Q; } size_t R=(size_t)ftell(P); rewind(P); char*S=(char*)malloc(sizeof(char)*R); if(S==NULL) { show_msgbox(L, "malloc failed.\nAborting."); fclose(P); goto Q; } if(fread(S, 0x1, R, P)!=R) { show_msgbox(L, "fread failed.\nAborting."); fclose(P); goto Q; } if(strncmp(S, "*TIMLP", 0x6)!=0x0) { show_msgbox(L, "This does not look like a legit tns file.\nAborting"); fclose(P); goto Q; } J(K"*"); fclose(P); size_t T=0x6; S[0x6]='\x50'; S[0x7]='\x4B'; S[0x8]='\x03'; S[0x9]='\x04'; char U[0xFF+sizeof(K)]; memcpy(U, K, sizeof(K)); while((T0xFF) { I(V); show_msgbox(L, "Hum hum.\nAborting."); goto Q; } size_t X=(S[T+0x3]<<0x18)+(S[T+0x2]<<0x10)+(S[T+0x1]<<0x08)+(S[T+0x0]<<0x00); memcpy(&(U[sizeof(K)-0x1]), &(S[T+0xC]), W); U[sizeof(K)+W-0x1]='\0'; T+=0xC+W+(S[T+0xB]<<0x08)+(S[T+0xA]<<0x00); G(V, &(S[T]), X); size_t*Y; if((S[T+0x0]==0x0F)&&(S[T+0x1]==0xCE)&&(S[T+0x2]==0xD8)&&(S[T+0x3]==0xD2)) { M=X; Y=E(V); } else { Y=F(V); } if(Y==NULL) { I(V); show_msgbox(L, "Operation failed.\nAborting."); goto Q; } size_t Z=Y[0x0]; I(V); V=H(Y); P=fopen(U, "wb"); if(P==NULL) { show_msgbox(L, "Cannot open the following file for write.\nAborting."); show_msgbox(L, U); goto Q; } if(fwrite(V, 0x1, Z, P)!=Z) { show_msgbox(L, "fwrite failed.\nAborting."); fclose(P); goto Q; } fclose(P); I(Y); free(V); T+=X; } show_msgbox(L, "Done!"); Q: HOOK_UNINSTALL(C(N), O); return 0x0; }