建档
This commit is contained in:
86
source/Tool/Ifstream_NPK.cpp
Normal file
86
source/Tool/Ifstream_NPK.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "Ifstream_NPK.h"
|
||||
|
||||
// 密钥初始化
|
||||
Ifstream_NPK::Ifstream_NPK() : Key{112, 117, 99, 104, 105, 107, 111, 110, 64, 110, 101, 111, 112, 108, 101, 32, 100, 117, 110, 103, 101, 111, 110, 32, 97, 110, 100, 32, 102, 105, 103, 104, 116, 101, 114, 32, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 68, 78, 70, 0}
|
||||
{
|
||||
// 构造函数体可以为空
|
||||
}
|
||||
|
||||
// char* 转整数
|
||||
int Ifstream_NPK::CharToInt(char *Str)
|
||||
{
|
||||
return *(int *)Str;
|
||||
}
|
||||
|
||||
// char* 转Long
|
||||
long Ifstream_NPK::CharToLong(char *Str)
|
||||
{
|
||||
return *(long long *)Str;
|
||||
}
|
||||
|
||||
// 读整数
|
||||
int Ifstream_NPK::ReadInt()
|
||||
{
|
||||
char *CountBuffer = new char[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
this->get(CountBuffer[i]);
|
||||
}
|
||||
int Count = CharToInt(CountBuffer);
|
||||
delete[] CountBuffer;
|
||||
return Count;
|
||||
}
|
||||
|
||||
// 读字符串
|
||||
std::string Ifstream_NPK::ReadString()
|
||||
{
|
||||
char *CharBuffer = new char[1024];
|
||||
this->get(CharBuffer, 1024, '\0');
|
||||
std::string Str = CharBuffer;
|
||||
delete[] CharBuffer;
|
||||
this->seekg(1, std::ios::cur);
|
||||
return Str;
|
||||
}
|
||||
|
||||
// 读取信息
|
||||
std::string Ifstream_NPK::ReadInfo()
|
||||
{
|
||||
char *CharBuffer = new char[256];
|
||||
char var;
|
||||
int i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
this->get(var);
|
||||
CharBuffer[i] = var ^ Key[i];
|
||||
++i;
|
||||
}
|
||||
std::string Str = CharBuffer;
|
||||
delete[] CharBuffer;
|
||||
return Str;
|
||||
}
|
||||
|
||||
// 读LONG
|
||||
int Ifstream_NPK::ReadLong()
|
||||
{
|
||||
char *CountBuffer = new char[8];
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
this->get(CountBuffer[i]);
|
||||
}
|
||||
long Count = CharToLong(CountBuffer);
|
||||
delete[] CountBuffer;
|
||||
return Count;
|
||||
}
|
||||
|
||||
// 读指定长度数据
|
||||
BYTE *Ifstream_NPK::ReadCustomSize(int Size)
|
||||
{
|
||||
BYTE *CharBuffer = new BYTE[Size];
|
||||
for (int j = 0; j < Size; j++)
|
||||
{
|
||||
char var;
|
||||
this->get(var);
|
||||
CharBuffer[j] = var;
|
||||
}
|
||||
return CharBuffer;
|
||||
}
|
||||
Reference in New Issue
Block a user