diff --git a/SHNFileDecryptor/SHNFileDecryptor.cpp b/SHNFileDecryptor/SHNFileDecryptor.cpp index 2369308..1b9940a 100644 --- a/SHNFileDecryptor/SHNFileDecryptor.cpp +++ b/SHNFileDecryptor/SHNFileDecryptor.cpp @@ -2,8 +2,10 @@ #include #include #include +#include typedef std::byte byte; +typedef char sbyte; class SHNFile{ std::vectorcryptHeader; @@ -39,7 +41,7 @@ class SHNFile{ } int marker=0; std::vectorReadBytes(int bytes){ - std::vectorbyteArr; + std::vectorbyteArr={}; for(int i=0;ib=ReadBytes(1); + if(b.size()>0){ + return b[0]; + } else { + return byte(0); + } + } + uint16_t ReadUInt16(){ + std::vectorintBytes=ReadBytes(2); + uint16_t numb = uint16_t(intBytes[1])<<8|uint16_t(intBytes[0]); + return numb; + } + int16_t ReadInt16(){ + std::vectorintBytes=ReadBytes(2); + int16_t numb = int16_t(intBytes[1])<<8|int16_t(intBytes[0]); + 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]); @@ -62,19 +82,146 @@ class SHNFile{ } struct Column{ std::string name; - uint32_t type; - int length; + uint32_t type=0; + int length=0; }; std::string ReadString(int bytes){ std::vectorstrBytes=ReadBytes(bytes); - std::string str; + std::string str=""; for(int i=0;istrBytes=ReadBytes(4); + byte bytes[]={strBytes[0],strBytes[1],strBytes[2],strBytes[3]}; + float f; + memcpy(&f,&bytes,sizeof(float)); + return f; + } + sbyte ReadSByte(){ + return sbyte(ReadBytes(1)[0]); + } + 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]); + }else{ + break; + } } return str; } uint32_t header,recordCount,defaultRecordLength,columnCount; std::vectorcolumns; + public: + struct Data{ + std::shared_ptrdata; + int type=0; + Data(byte b){ + std::shared_ptrptr=std::make_shared(byte(b)); + data=std::static_pointer_cast(ptr); + type=1; + } + Data(sbyte b){ + std::shared_ptrptr=std::make_shared(sbyte(b)); + data=std::static_pointer_cast(ptr); + type=7; + } + Data(uint16_t n){ + std::shared_ptrptr=std::make_shared(uint16_t(n)); + data=std::static_pointer_cast(ptr); + type=2; + } + Data(int16_t n){ + std::shared_ptrptr=std::make_shared(int16_t(n)); + data=std::static_pointer_cast(ptr); + type=6; + } + Data(uint32_t n){ + std::shared_ptrptr=std::make_shared(uint32_t(n)); + data=std::static_pointer_cast(ptr); + type=3; + } + Data(int32_t n){ + std::shared_ptrptr=std::make_shared(int32_t(n)); + data=std::static_pointer_cast(ptr); + type=8; + } + Data(float n){ + std::shared_ptrptr=std::make_shared(float(n)); + data=std::static_pointer_cast(ptr); + type=4; + } + Data(std::string str){ + std::shared_ptrptr=std::make_shared(str); + data=std::static_pointer_cast(ptr); + type=5; + } + byte GetByte(){ + return *std::static_pointer_cast(data); + } + uint16_t GetUInt16(){ + return *std::static_pointer_cast(data); + } + int16_t GetInt16(){ + return *std::static_pointer_cast(data); + } + sbyte GetSByte(){ + return *std::static_pointer_cast(data); + } + uint32_t GetUInt32(){ + return *std::static_pointer_cast(data); + } + int32_t GetInt32(){ + return *std::static_pointer_cast(data); + } + float GetFloat(){ + return *std::static_pointer_cast(data); + } + std::string GetString(){ + return *std::static_pointer_cast(data); + } + std::string GetDisplayText(){ + switch(type){ + case 1:{ + return std::to_string(int(GetByte())); + }break; + case 7:{ + return std::to_string(int(GetSByte())); + }break; + case 2:{ + return std::to_string(GetUInt16()); + }break; + case 6:{ + return std::to_string(GetInt16()); + }break; + case 3:{ + return std::to_string(GetUInt32()); + }break; + case 8:{ + return std::to_string(GetInt32()); + }break; + case 4:{ + return std::to_string(GetFloat()); + }break; + case 5:{ + return GetString(); + }break; + } + } + }; + private: + std::vector>contents; + friend std::ostream&operator<<(std::ostream&out,SHNFile::Data&d){ + out<row; + for(int j=0;j