summaryrefslogtreecommitdiff
path: root/utils/aurez/AuRsrc.cc
blob: ab7933e8d9660334350e7fdd98efdce9eaf8fb53 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//          Copyright Jean Pierre Cimalando 2018.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#include "AuRsrc.h"
#include <string.h>
#include <arpa/inet.h>

std::vector<uint8_t> MakeSTR(const std::string &string)
{
    size_t size = string.size();
    if (size > 255)
        size = 255;

    std::vector<uint8_t> pstr;
    pstr.reserve(size + 1);
    pstr.push_back((uint8_t)size);
    pstr.insert(pstr.end(), &string[0], &string[size]);

    return pstr;
}

std::vector<uint8_t> MakeCSTR(const std::string &string)
{
    const char *cstr = string.c_str();
    return std::vector<uint8_t>(cstr, cstr + string.size() + 1);
}

std::vector<uint8_t> MakeThng(
    unsigned archs, uint16_t id_plugin, uint16_t id_info, uint32_t version,
    const char type[4], const char subtype[4], const char manuf[4])
{
    unsigned num_archs = 0;
    for (unsigned a = ArchsBegin; a < ArchsEnd; ++a)
        num_archs += (archs & (1 << a)) != 0;

    std::vector<uint8_t> thng_buf(sizeof(CarbonThng) + num_archs * sizeof(CarbonThng::PlatformInfo));
    CarbonThng *thng = (CarbonThng *)thng_buf.data();
    memcpy(thng->Type, type, 4);
    memcpy(thng->Subtype, subtype, 4);
    memcpy(thng->Manufacturer, manuf, 4);
    memcpy(thng->NameType, "STR ", 4);
    thng->NameId = htons(id_plugin);
    memcpy(thng->InfoType, "STR ", 4);
    thng->InfoId = htons(id_info);
    thng->ComponentVersion = htonl(version);
    thng->RegistrationFlags = htonl(9);  // componentHasMultiplePlatforms | componentDoAutoVersion
    thng->PlatformInfoCount = htonl(num_archs);

    for (unsigned a = ArchsBegin, i = 0; a < ArchsEnd; ++a) {
        if ((archs & (1 << a)) == 0) continue;
        CarbonThng::PlatformInfo &pl = thng->PlatformInfos[i];
        pl.ComponentFlags = htonl(0x10000000);  // cmpThreadSafeOnMac
        memcpy(pl.CodeType, "dlle", 4);
        pl.CodeId = htons(id_plugin);
        pl.PlatformType = htons(a);
        ++i;
    }

    return thng_buf;
}