diff --git a/SHNFileDecryptor/AbState.shn b/SHNFileDecryptor/AbState.shn index 4d96d5c..0841484 100644 Binary files a/SHNFileDecryptor/AbState.shn and b/SHNFileDecryptor/AbState.shn differ diff --git a/SHNFileDecryptor/AbState.shn.bak b/SHNFileDecryptor/AbState.shn.bak index 4d96d5c..0841484 100644 Binary files a/SHNFileDecryptor/AbState.shn.bak and b/SHNFileDecryptor/AbState.shn.bak differ diff --git a/SHNFileDecryptor/AbState.shn_decoded.bak b/SHNFileDecryptor/AbState.shn_decoded.bak new file mode 100644 index 0000000..b09099a Binary files /dev/null and b/SHNFileDecryptor/AbState.shn_decoded.bak differ diff --git a/SHNFileDecryptor/SHNFileDecryptor.cpp b/SHNFileDecryptor/SHNFileDecryptor.cpp index ca79ef4..76bf140 100644 --- a/SHNFileDecryptor/SHNFileDecryptor.cpp +++ b/SHNFileDecryptor/SHNFileDecryptor.cpp @@ -9,6 +9,13 @@ typedef std::byte byte; typedef char sbyte; class SHNFile{ + std::vectorReadBytes(std::ifstream&file){ + std::vectorbyteArr; + while(!file.eof()){ + byteArr.push_back(byte(file.get())); + } + return byteArr; + } std::vectorReadBytes(std::ifstream&file,int bytes){ std::vectorbyteArr; for(int i=0;i&data){ + for(int i=0;iintBytes=ReadBytes(file,4); int numb = int(intBytes[3])<<24|int(intBytes[2])<<16|int(intBytes[1])<<8|int(intBytes[0]); return numb; } + void Encrypt(){ + Decrypt(); + } void Decrypt(){ byte num = byte(data.size()); for(int i=data.size()-1;i>=0;i--){ @@ -58,26 +73,44 @@ class SHNFile{ return byte(0); } } + void WriteByte(std::ofstream&f,byte b){ + f<intBytes=ReadBytes(2); uint16_t numb = uint16_t(intBytes[1])<<8|uint16_t(intBytes[0]); return numb; } + void WriteUInt16(std::ofstream&f,uint16_t val){ + f<>8)&0xFF); + } int16_t ReadInt16(){ std::vectorintBytes=ReadBytes(2); int16_t numb = int16_t(intBytes[1])<<8|int16_t(intBytes[0]); return numb; } + void WriteInt16(std::ofstream&f,int16_t val){ + f<>8)&0xFF); + } uint32_t ReadUInt32(){ std::vectorintBytes=ReadBytes(4); uint32_t numb = uint32_t(intBytes[3])<<24|uint32_t(intBytes[2])<<16|uint32_t(intBytes[1])<<8|uint32_t(intBytes[0]); return numb; } + void WriteUInt32(std::ofstream&f,uint32_t val){ + f<>8)&0xFF)<>16)&0xFF)<>24)&0xFF); + } int ReadInt32(){ std::vectorintBytes=ReadBytes(4); int numb = int(intBytes[3])<<24|int(intBytes[2])<<16|int(intBytes[1])<<8|int(intBytes[0]); return numb; } + void WriteInt32(std::ofstream&f,int32_t val){ + f<>8)&0xFF)<>16)&0xFF)<>24)&0xFF); + } struct Column{ std::string name; uint32_t type=0; @@ -93,13 +126,33 @@ class SHNFile{ } return str; } + void WriteString(std::ofstream&f,std::string str,int bytes){ + for(int i=0;istrBytes=ReadBytes(4); byte bytes[]={strBytes[0],strBytes[1],strBytes[2],strBytes[3]}; float f; - memcpy(&f,&bytes,sizeof(float)); + memcpy(&f,&bytes,4); return f; } + void WriteSingle(std::ofstream&f,float n){ + byte bytes[4]; + memcpy(&n,&bytes,4); + for(int i=0;i<4;i++){ + f<data; @@ -238,6 +298,8 @@ public: //FILE OPERATIONS! std::ifstream f(filename,std::ios::binary); + //Since we don't just read in the entire file raw, we have to do some additional work here as the header provides us with some basic info on how to decrypt this file. + //The backup itself needs all the data from the original file, so we're appending it to rawData as we continue reading it. cryptHeader=ReadBytes(f,0x20); std::copy(cryptHeader.begin(),cryptHeader.end(),std::back_inserter(rawData)); int readAmt=ReadInt32(f); @@ -269,40 +331,40 @@ public: std::vectorrow; for(int j=0;j&row:contents){ + std::streampos marker = f.tellp(); + WriteUInt16(f,uint16_t(0)); + int colNum=0; + for(Data&col:row){ + switch(columns[colNum].type){ + case 1: + case 12: + case 0x10:{ + WriteByte(f,col.GetByte()); + }break; + case 2:{ + WriteUInt16(f,col.GetUInt16()); + }break; + case 3: + case 11: + case 0x12: + case 0x1b:{ + WriteUInt32(f,col.GetUInt32()); + }break; + case 5:{ + WriteSingle(f,col.GetFloat()); + }break; + case 9: + case 0x18:{ + WriteString(f,col.GetString(),columns[colNum].length); + }break; + case 13: + case 0x15:{ + WriteInt16(f,col.GetInt16()); + }break; + case 20:{ + WriteSByte(f,col.GetSByte()); + }break; + case 0x16:{ + WriteInt32(f,col.GetInt32()); + }break; + case 0x1a:{ + WriteString(f,col.GetString(),-1); + }break; + } + colNum++; + } + std::streampos offset = f.tellp() - marker; + std::streampos newMarker = f.tellp(); + f.seekp(marker); + WriteUInt16(f,uint16_t(offset)); + f.seekp(newMarker); + } + f.close(); + std::ifstream finishedFile(filename,std::ios::binary); + data=ReadBytes(finishedFile); + std::ofstream encryptedFile(filename,std::ios::binary); + std::cout<<"Encrypting..."<