diff --git a/SHNFileDecryptor/AbState.shn.bak b/SHNFileDecryptor/AbState.shn.bak new file mode 100644 index 0000000..7d427d3 Binary files /dev/null and b/SHNFileDecryptor/AbState.shn.bak differ diff --git a/SHNFileDecryptor/SHNFileDecryptor.cpp b/SHNFileDecryptor/SHNFileDecryptor.cpp index 1b9940a..31d8cd2 100644 --- a/SHNFileDecryptor/SHNFileDecryptor.cpp +++ b/SHNFileDecryptor/SHNFileDecryptor.cpp @@ -3,13 +3,13 @@ #include #include #include +#include +#include typedef std::byte byte; typedef char sbyte; class SHNFile{ - std::vectorcryptHeader; - std::vectordata; std::vectorReadBytes(std::ifstream&file,int bytes){ std::vectorbyteArr; for(int i=0;iReadBytes(int bytes){ - std::vectorbyteArr={}; + std::listReadBytes(int bytes){ + std::listbyteArr={}; for(int i=0;ib=ReadBytes(1); + std::listb=ReadBytes(1); if(b.size()>0){ - return b[0]; + return b.front(); } else { return byte(0); } } uint16_t ReadUInt16(){ - std::vectorintBytes=ReadBytes(2); - uint16_t numb = uint16_t(intBytes[1])<<8|uint16_t(intBytes[0]); + std::listintBytes=ReadBytes(2); + uint16_t numb = uint16_t(intBytes.back())<<8; + intBytes.pop_back(); + numb |= uint16_t(intBytes.back()); return numb; } int16_t ReadInt16(){ - std::vectorintBytes=ReadBytes(2); - int16_t numb = int16_t(intBytes[1])<<8|int16_t(intBytes[0]); + std::listintBytes=ReadBytes(2); + int16_t numb = int16_t(intBytes.back())<<8; + intBytes.pop_back(); + numb |= int16_t(intBytes.back()); return numb; } 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]); + std::listintBytes=ReadBytes(4); + uint32_t numb = uint32_t(intBytes.back())<<24; + intBytes.pop_back(); + numb |= uint32_t(intBytes.back())<<16; + intBytes.pop_back(); + numb |= uint32_t(intBytes.back())<<8; + intBytes.pop_back(); + numb |= uint32_t(intBytes.back()); return numb; } int ReadInt32(){ - std::vectorintBytes=ReadBytes(4); - int numb = int(intBytes[3])<<24|int(intBytes[2])<<16|int(intBytes[1])<<8|int(intBytes[0]); + std::listintBytes=ReadBytes(4); + int numb = int(intBytes.back())<<24; + intBytes.pop_back(); + numb |= int(intBytes.back())<<16; + intBytes.pop_back(); + numb |= int(intBytes.back())<<8; + intBytes.pop_back(); + numb |= int(intBytes.back()); return numb; } struct Column{ @@ -86,39 +101,44 @@ class SHNFile{ int length=0; }; std::string ReadString(int bytes){ - std::vectorstrBytes=ReadBytes(bytes); + std::liststrBytes=ReadBytes(bytes); std::string str=""; - for(int i=0;istrBytes=ReadBytes(4); - byte bytes[]={strBytes[0],strBytes[1],strBytes[2],strBytes[3]}; + std::liststrBytes=ReadBytes(4); + byte bytes[4]; + bytes[0]=strBytes.front(); + strBytes.pop_front(); + bytes[1]=strBytes.front(); + strBytes.pop_front(); + bytes[2]=strBytes.front(); + strBytes.pop_front(); + bytes[3]=strBytes.front(); float f; memcpy(&f,&bytes,sizeof(float)); return f; } sbyte ReadSByte(){ - return sbyte(ReadBytes(1)[0]); + return sbyte(ReadBytes(1).front()); } std::string ReadString(){ std::string str=""; while(true){ - std::vectorbyteArr=ReadBytes(1); - if(byteArr.size()>0&&byteArr[0]!=byte(0)){ - str+=unsigned char(byteArr[0]); + std::listbyteArr=ReadBytes(1); + if(byteArr.size()>0&&byteArr.front()!=byte(0)){ + str+=unsigned char(byteArr.front()); }else{ break; } } return str; } - uint32_t header,recordCount,defaultRecordLength,columnCount; - std::vectorcolumns; public: struct Data{ std::shared_ptrdata; @@ -217,14 +237,28 @@ class SHNFile{ } }; private: - std::vector>contents; friend std::ostream&operator<<(std::ostream&out,SHNFile::Data&d){ out<cryptHeader; + std::vectordata; + uint32_t header=0,recordCount=0,defaultRecordLength=0,columnCount=0; + std::vectorcolumns; + std::vector>contents; + std::string filename; public: - SHNFile(std::string file){ - std::ifstream f(file,std::ios::binary); + void Load(std::string file){ + cryptHeader.clear(); + data.clear(); + header=recordCount=defaultRecordLength=columnCount=0; + columns.clear(); + contents.clear(); + marker=0; + std::chrono::time_pointtimer=std::chrono::high_resolution_clock::now(); + filename=file; + std::ifstream f(filename,std::ios::binary); cryptHeader=ReadBytes(f,0x20); data=ReadBytes(f,ReadInt32(f)-0x24); Decrypt(); @@ -248,53 +282,62 @@ public: std::vectorrow; for(int j=0;jdur=std::chrono::high_resolution_clock::now()-timer; + std::cout<<"Loaded "<