print ABR file structure recursively

This commit is contained in:
2019-02-07 22:05:30 +01:00
parent 17d5320ecb
commit f76a5c2fc3
4 changed files with 100 additions and 54 deletions

View File

@@ -77,7 +77,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;libs\openvr\headers;libs\nanort;libs\hash-library;$(IncludePath)</IncludePath>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;libs\openvr\headers;libs\nanort;libs\hash-library;libs\fmt\include;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);libs\bugtrap-client\lib;libs\openvr\lib\win64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -87,7 +87,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;libs\openvr\headers;libs\nanort;libs\hash-library;$(IncludePath)</IncludePath>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;libs\openvr\headers;libs\nanort;libs\hash-library;libs\fmt\include;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);libs\bugtrap-client\lib;libs\openvr\lib\win64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@@ -169,6 +169,14 @@
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="libs\fmt\src\format.cc">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="libs\fmt\src\posix.cc">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="libs\hash-library\md5.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>

View File

@@ -49,6 +49,9 @@
<Filter Include="libs\hash">
<UniqueIdentifier>{2a784067-6741-47a3-b668-cc45f2224286}</UniqueIdentifier>
</Filter>
<Filter Include="libs\fmt">
<UniqueIdentifier>{7b4f5b47-7a8b-4e4c-9e82-399bb5047ffc}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\app.cpp">
@@ -291,6 +294,12 @@
<ClCompile Include="src\abr.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="libs\fmt\src\format.cc">
<Filter>libs\fmt</Filter>
</ClCompile>
<ClCompile Include="libs\fmt\src\posix.cc">
<Filter>libs\fmt</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\app.h">

View File

@@ -45,6 +45,8 @@ bool ABR::section_desc()
auto name = rkey_or_string();
auto list = rstring(4);
auto list_val = call(list);
auto out = list_val->str(0, "");
std::cout << out;
return true;
}
@@ -66,14 +68,14 @@ std::shared_ptr<ABR::List> ABR::parse_vlls()
{
auto ret = std::make_shared<List>();
auto count = ru32();
printf("list: %d\n", count);
//printf("list: %d\n", count);
for (int i = 0; i < count; i++)
{
auto type = rstring(4);
auto item = call(type);
if (!item)
return nullptr;
ret->children.push_back(item);
ret->items.push_back(item);
}
return ret;
}
@@ -82,7 +84,7 @@ std::shared_ptr<ABR::String> ABR::parse_text()
{
auto ret = std::make_shared<String>();
ret->value = rwstring();
wprintf(L"text: %s\n", ret->value.c_str());
//wprintf(L"text: %s\n", ret->value.c_str());
return ret;
}
@@ -100,7 +102,7 @@ std::shared_ptr<ABR::Descriptor> ABR::parse_objc()
ret->name = rwstring();
ret->class_id = rkey_or_string();
auto count = ru32();
printf("objc type %s, %d props\n", ret->class_id.c_str(), count);
//printf("objc type %s, %d props\n", ret->class_id.c_str(), count);
for (int i = 0; i < count; i++)
{
auto key = rkey_or_string();
@@ -121,7 +123,7 @@ std::shared_ptr<ABR::UnitFloat> ABR::parse_untf()
auto ret = std::make_shared<UnitFloat>();
ret->unit = rstring(4);
ret->value = rdbl();
printf("float %s: %f\n", ret->unit.c_str(), ret->value);
//printf("float %s: %f\n", ret->unit.c_str(), ret->value);
return ret;
}
@@ -129,7 +131,7 @@ std::shared_ptr<ABR::Boolean> ABR::parse_bool()
{
auto ret = std::make_shared<Boolean>();
ret->value = ru8();
printf("bool: %s\n", ret->value ? "true" : "false");
//printf("bool: %s\n", ret->value ? "true" : "false");
return ret;
}
@@ -137,7 +139,7 @@ std::shared_ptr<ABR::Integer> ABR::parse_long()
{
auto ret = std::make_shared<Integer>();
ret->value = ru32();
printf("long: %d\n", ret->value);
//printf("long: %d\n", ret->value);
return ret;
}
@@ -145,7 +147,7 @@ std::shared_ptr<ABR::Double> ABR::parse_doub()
{
auto ret = std::make_shared<Double>();
ret->value = rdbl();
printf("double: %d\n", ret->value);
//printf("double: %d\n", ret->value);
return ret;
}
@@ -154,7 +156,7 @@ std::shared_ptr<ABR::Enum> ABR::parse_enum()
auto ret = std::make_shared<Enum>();
auto t = rkey_or_string();
auto e = rkey_or_string();
printf("enum: %s %s\n", t.c_str(), e.c_str());
//printf("enum: %s %s\n", t.c_str(), e.c_str());
return ret;
}

113
src/abr.h
View File

@@ -1,6 +1,8 @@
#pragma once
#include "asset.h"
#include <codecvt>
#include <fmt/core.h>
#include "util.h"
class BinaryStream
{
@@ -31,9 +33,9 @@ public:
m_byte_order = byte_order;
m_swap = byte_order == ByteOrder::Host ? false : byte_order != sys_order();
}
inline void skip(size_t bytes) { m_cur += bytes; }
inline bool eof() { return std::distance(m_ptr, m_cur) >= m_size; }
inline bool has_data(size_t sz) { return std::distance(m_ptr, m_cur + sz) < m_size; }
void skip(size_t bytes) { m_cur += bytes; }
bool eof() { return std::distance(m_ptr, m_cur) >= m_size; }
bool has_data(size_t sz) { return std::distance(m_ptr, m_cur + sz) < m_size; }
uint8_t ru8() { return read<uint8_t>(); }
uint16_t ru16() { return m_swap ? swap(read<uint16_t>()) : read<uint16_t>(); }
uint32_t ru32() { return m_swap ? swap(read<uint32_t>()) : read<uint32_t>(); }
@@ -45,21 +47,23 @@ public:
float rflt() { return read<float>(); }
double rdbl() { return read<double>(); }
std::string pick(size_t chars) { return { (char*)m_cur, chars }; }
std::string rstring() { auto len = ru32(); return { advance<char>(len), len }; }
std::string rstring()
{
auto len = ru32();
return { advance<char>(len), len };
}
std::string rstring(size_t len) { return { advance<char>(len), len }; }
std::wstring rwstring() { auto len = ru32(); return rwstring(len); }
std::wstring rwstring(size_t len) {
//std::wstring_convert<std::codecvt_utf16<char>> conv;
char* ptr = advance<char>(len * 2);
std::wstring rwstring()
{
auto len = ru32();
return rwstring(len);
}
std::wstring rwstring(size_t len)
{
auto ptr = advance<char>(len * 2);
for (int i = 0; i < len; i++)
std::swap(ptr[i * 2], ptr[i * 2 + 1]);
//auto s = conv.from_bytes(ptr, ptr + len);
wchar_t* wptr = (wchar_t*)ptr;
//std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert;
//std::string utf8 = convert.to_bytes(wptr, wptr + len);
//std::wstring ws(len, 0);
//mbsrtowcs((wchar_t*)ws.data(), (const char**)&ptr, len, nullptr);
return std::wstring(wptr, len);
return std::wstring((wchar_t*)ptr, len);
}
protected:
template<typename T> inline T align4(T x) { return ((x - T{1}) & (~(T{3}))) + T{4}; }
@@ -127,43 +131,56 @@ private:
ByteOrder m_byte_order = ByteOrder::Host;
};
static constexpr const uint32_t abr_s2sig(const char s[4])
{
return (uint32_t)(s[0]) << 0
| (uint32_t)(s[1]) << 8
| (uint32_t)(s[2]) << 16
| (uint32_t)(s[3]) << 24;
}
static constexpr const std::array<char, 5> abr_sig2sz(uint32_t x)
{
return {
(char)(x >> 0 ),
(char)(x >> 8 ),
(char)(x >> 16),
(char)(x >> 24),
0
};
}
class ABR : public BinaryStream
{
struct Type {
struct Type
{
using Vec = std::vector<std::shared_ptr<Type>>;
using Map = std::map<std::string, std::shared_ptr<Type>>;
using Ref = std::shared_ptr<Type>;
virtual std::string str() const { return "type"; }
virtual std::string str(int indent, const std::string& prefix) const
{
return "type";
}
};
struct Class : public Type { };
struct Property : public Type { };
struct Reference : public Type { };
struct List : public Type{
Type::Vec children;
struct List : public Type
{
Type::Vec items;
virtual std::string str(int indent, const std::string& prefix) const override
{
//return std::string(indent, '-') + prefix + fmt::format("list: {} items", items.size());
auto ret = std::string(indent, '-') + fmt::format("list: {} props:\n", items.size());
for (int i = 0; i < items.size(); i++)
ret += items[i]->str(indent + 1, fmt::format("{}) ", i) + "\n");
return ret;
}
};
struct Double : public Type
{
double value;
virtual std::string str(int indent, const std::string& prefix) const override
{ return std::string(indent, '-') + prefix + fmt::format("double: {}", value); }
};
struct UnitFloat : public Type
{
std::string unit;
double value;
virtual std::string str(int indent, const std::string& prefix) const override
{ return std::string(indent, '-') + prefix + fmt::format("float: {} ({})", value, unit); }
};
struct String : public Type
{
std::wstring value;
virtual std::string str(int indent, const std::string& prefix) const override
{ return std::string(indent, '-') + prefix + fmt::format("string: {}", wstr2str(value)); }
};
struct Enum : public Type
{
};
struct Double : public Type { double value; };
struct UnitFloat : public Type { std::string unit; double value; };
struct String : public Type { std::wstring value; };
struct Enum : public Type { };
struct EnumRef : public Type { };
struct Offset : public Type { };
struct Identifier : public Type { };
@@ -172,12 +189,15 @@ class ABR : public BinaryStream
struct Integer : public Type
{
int32_t value;
virtual std::string str(int indent, const std::string& prefix) const override
{ return std::string(indent, '-') + prefix + fmt::format("int: {}", value); }
};
struct LargeInteger : public Type { };
struct Boolean : public Type
{
bool value;
virtual std::string str() const override { return "Boolean: " + ; }
virtual std::string str(int indent, const std::string& prefix) const override
{ return std::string(indent, '-') + prefix + fmt::format("bool: {}", value); }
};
struct Alias : public Type { };
struct Descriptor : public Type
@@ -185,6 +205,13 @@ class ABR : public BinaryStream
std::wstring name;
std::string class_id;
Type::Map props;
virtual std::string str(int indent, const std::string& prefix) const override
{
auto ret = std::string(indent, '-') + fmt::format("objc: {} props:", props.size());
for (const auto& p : props)
ret += "\n" + p.second->str(indent + 1, fmt::format("'{}' ", p.first));
return ret;
}
};
public: