请根据调试信息以及代码指出为什么经过qtextedit转换一次,就不匹配,指出问题,并给出解决方案。请着重关注qtextedit操作相关的代码
//输出信息如下:
/*
版本号: 100
文件数量: 20113
偏移位置: 1377057156
文件长度: 999395
这个是二代加密的txt文件! "npcdata.txt" "npcdata.txt"
processVector可逆
读取之后不可逆
*/
void on_pushButtonOpenFile_clicked()
{
QFile file(PKG_Path);
QDataStream in(&file);
// 读取信息
quint32 version = ReadInt(in);
quint32 filenums = ReadInt(in);
quint32 filename_table_offset = ReadInt(in);
quint32 filename_table_len = ReadInt(in);
in.device()->seek(filename_table_offset);
quint32 max = 0;
for (quint32 index = 0; index < filenums; ++index) {
quint16 name_len = ReadShort(in);
QString name = ReadString(in, name_len);
quint32 flag = ReadInt(in);
quint32 offset = ReadInt(in);
quint32 size = ReadInt(in); // 文件原始的大小
quint32 zlib_size = ReadInt(in); // 文件压缩后的大小
quint32 currentPosition = in.device()->pos();
in.device()->seek(offset);
QByteArray text(zlib_size, '\0');
in.readRawData(text.data(), zlib_size);
in.device()->seek(currentPosition);
QFileInfo fileInfo(name);
QString extension = fileInfo.suffix();
if ((extension == "txt" || extension == "lua") && extractFileName(name) == "npcdata.txt") {
QByteArray decompressedData = decompressUsingStreams(text);
QString privateKey = "";
QByteArray CeshiJieMi = NULL;
QByteArray CeshiJiaMi = NULL;
if (decompressedData.length() > 8 &&
(uint)(unsigned char)decompressedData[0] == 0x3F &&
(uint)(unsigned char)decompressedData[1] == 0x3F &&
(uint)(unsigned char)decompressedData[2] == 0x53 &&
(uint)(unsigned char)decompressedData[3] == 0x47) {
privateKey = "reaishenghuo“;
qDebug() << "这个是二代加密的txt文件!" << name << extractFileName(name);
decompressedData = decrypt(decompressedData, privateKey.toUtf8());
CeshiJieMi = decompressedData;
CeshiJiaMi = processVector(decompressedData);
if (CeshiJieMi == processVector(CeshiJiaMi)) {
qDebug() << "processVector可逆";
}
else {
qDebug() << "processVector不可逆";
}
}
QTextCodec* codec = QTextCodec::codecForName("GBK");
QString stdstring = codec->toUnicode(decompressedData);
ui.plainTextEdit->setPlainText(stdstring);
QString content = ui.plainTextEdit->toPlainText();
QByteArray contentArray = codec->fromUnicode(content);
contentArray = processVector(contentArray);
if (contentArray == CeshiJiaMi) {
qDebug() << "读取之后可逆";
}
else {
qDebug() << "读取之后不可逆";
}
decompressedData.clear();
}
}
}
QByteArray processVector(const QByteArray& data) {
QByteArray result = data; // 创建一个副本
if (result.isEmpty()) {
return result;
}
int length = result.size();
int index = 0;
int tempIndex = length - 1;
while (index <= tempIndex) {
uchar byteOne = result[tempIndex];
uchar byteTwo = result[index];
byteOne ^= 0x23;
byteTwo ^= 0x23;
result[index] = byteOne;
result[tempIndex] = byteTwo;
++index;
--tempIndex;
}
return result;
}
//ui.plainTextEdit->setPlainText(stdstring) 和 ui.plainTextEdit->toPlainText()
//为什么经过这两部数据就变了 不应该一样的吗,请为我给出解决方法,不要搬AI 试过了 不好用