forked from soutade/libgourou
PDF DRM removing : Try to parse all objects wether they're or not in xref table
This commit is contained in:
parent
16a13eed89
commit
25f5049ab9
|
@ -1091,16 +1091,18 @@ namespace gourou
|
||||||
|
|
||||||
uPDFParser::Integer* ebxVersion;
|
uPDFParser::Integer* ebxVersion;
|
||||||
std::vector<uPDFParser::Object*> objects = parser.objects();
|
std::vector<uPDFParser::Object*> objects = parser.objects();
|
||||||
std::vector<uPDFParser::Object*>::reverse_iterator it;
|
std::vector<uPDFParser::Object*>::iterator it;
|
||||||
|
std::vector<uPDFParser::Object*>::reverse_iterator rIt;
|
||||||
unsigned char decryptedKey[RSA_KEY_SIZE];
|
unsigned char decryptedKey[RSA_KEY_SIZE];
|
||||||
|
int ebxId;
|
||||||
for(it = objects.rbegin(); it != objects.rend(); it++)
|
|
||||||
|
for(rIt = objects.rbegin(); rIt != objects.rend(); rIt++)
|
||||||
{
|
{
|
||||||
// Update EBX_HANDLER with rights
|
// Update EBX_HANDLER with rights
|
||||||
if ((*it)->hasKey("Filter") && (**it)["Filter"]->str() == "/EBX_HANDLER")
|
if ((*rIt)->hasKey("Filter") && (**rIt)["Filter"]->str() == "/EBX_HANDLER")
|
||||||
{
|
{
|
||||||
EBXHandlerFound = true;
|
EBXHandlerFound = true;
|
||||||
uPDFParser::Object* ebx = *it;
|
uPDFParser::Object* ebx = *rIt;
|
||||||
|
|
||||||
ebxVersion = (uPDFParser::Integer*)(*ebx)["V"];
|
ebxVersion = (uPDFParser::Integer*)(*ebx)["V"];
|
||||||
if (ebxVersion->value() != 4)
|
if (ebxVersion->value() != 4)
|
||||||
|
@ -1114,8 +1116,13 @@ namespace gourou
|
||||||
}
|
}
|
||||||
|
|
||||||
uPDFParser::String* licenseObject = (uPDFParser::String*)(*ebx)["ADEPT_LICENSE"];
|
uPDFParser::String* licenseObject = (uPDFParser::String*)(*ebx)["ADEPT_LICENSE"];
|
||||||
|
|
||||||
|
std::string value = licenseObject->value();
|
||||||
|
ByteArray zippedData = ByteArray::fromBase64(value);
|
||||||
|
|
||||||
ByteArray zippedData = ByteArray::fromBase64(licenseObject->value());
|
if (zippedData.size() == 0)
|
||||||
|
EXCEPTION(DRM_ERR_ENCRYPTION_KEY, "Invalid ADEPT_LICENSE");
|
||||||
|
|
||||||
ByteArray rightsStr;
|
ByteArray rightsStr;
|
||||||
client->inflate(zippedData, rightsStr);
|
client->inflate(zippedData, rightsStr);
|
||||||
|
|
||||||
|
@ -1125,6 +1132,8 @@ namespace gourou
|
||||||
std::string encryptedKey = extractTextElem(rightsDoc, "/adept:rights/licenseToken/encryptedKey");
|
std::string encryptedKey = extractTextElem(rightsDoc, "/adept:rights/licenseToken/encryptedKey");
|
||||||
|
|
||||||
decryptADEPTKey(encryptedKey, decryptedKey);
|
decryptADEPTKey(encryptedKey, decryptedKey);
|
||||||
|
ebxId = ebx->objectId();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1134,24 +1143,18 @@ namespace gourou
|
||||||
EXCEPTION(DRM_ERR_ENCRYPTION_KEY, "EBX_HANDLER not found");
|
EXCEPTION(DRM_ERR_ENCRYPTION_KEY, "EBX_HANDLER not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uPDFParser::XRefValue> xrefTable = parser.xrefTable();
|
for(it = objects.begin(); it != objects.end(); it++)
|
||||||
std::vector<uPDFParser::XRefValue>::iterator xrefIt;
|
|
||||||
|
|
||||||
for(xrefIt = xrefTable.begin(); xrefIt != xrefTable.end(); xrefIt++)
|
|
||||||
{
|
{
|
||||||
GOUROU_LOG(DEBUG, "XREF obj " << (*xrefIt).objectId() << " used " << (*xrefIt).used());
|
uPDFParser::Object* object = *it;
|
||||||
|
|
||||||
if (!(*xrefIt).used())
|
if (object->objectId() == ebxId)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uPDFParser::Object* object = (*xrefIt).object();
|
if (object->hasKey("Type") && (*object)["Type"]->str() == "/XRef")
|
||||||
|
|
||||||
if (!object)
|
|
||||||
{
|
|
||||||
GOUROU_LOG(DEBUG, "No object");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
|
GOUROU_LOG(DEBUG, "Obj " << object->objectId());
|
||||||
|
|
||||||
unsigned char tmpKey[16];
|
unsigned char tmpKey[16];
|
||||||
|
|
||||||
generatePDFObjectKey(ebxVersion->value(),
|
generatePDFObjectKey(ebxVersion->value(),
|
||||||
|
@ -1197,7 +1200,7 @@ namespace gourou
|
||||||
dictionary.replace(dictIt->first, dictIt->second);
|
dictionary.replace(dictIt->first, dictIt->second);
|
||||||
|
|
||||||
std::vector<uPDFParser::DataType*>::iterator datasIt;
|
std::vector<uPDFParser::DataType*>::iterator datasIt;
|
||||||
std::vector<uPDFParser::DataType*>& datas = (*xrefIt).object()->data();
|
std::vector<uPDFParser::DataType*>& datas = object->data();
|
||||||
uPDFParser::Stream* stream;
|
uPDFParser::Stream* stream;
|
||||||
|
|
||||||
for (datasIt = datas.begin(); datasIt != datas.end(); datasIt++)
|
for (datasIt = datas.begin(); datasIt != datas.end(); datasIt++)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user