forked from czajowaty/ad_resources_dumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdResourcesIterator.cpp
39 lines (34 loc) · 1.26 KB
/
AdResourcesIterator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "AdResourcesIterator.hpp"
AdResourcesIterator::AdResourcesIterator(QByteArray const& resourcesData)
: resourcesDataStart_{
reinterpret_cast<uint8_t const*>(resourcesData.constData())},
resourcesDataEnd_{
reinterpret_cast<uint8_t const*>(resourcesData.constEnd())},
resourceHeaderStart_{resourcesDataStart_}
{}
bool AdResourcesIterator::hasNext() const
{ return currentHeader()->type != ResourceType::None; }
AdResourceDescriptor AdResourcesIterator::next()
{
AdResourceDescriptor nextDescriptor;
nextDescriptor.header = moveHeader();
nextDescriptor.data =
resourcesDataStart_ + nextDescriptor.header->dataStartOffset;
if (hasNext())
{
nextDescriptor.size =
currentHeader()->dataStartOffset -
nextDescriptor.header->dataStartOffset;
}
else
{ nextDescriptor.size = resourcesDataEnd_ - nextDescriptor.data; }
return nextDescriptor;
}
ResourceHeader const* AdResourcesIterator::currentHeader() const
{ return reinterpret_cast<ResourceHeader const*>(resourceHeaderStart_); }
ResourceHeader const* AdResourcesIterator::moveHeader()
{
auto resourceHeader = currentHeader();
resourceHeaderStart_ += resourceHeader->headerSize;
return resourceHeader;
}