|
| 1 | +#include <aux.h> |
| 2 | + |
| 3 | +#include "MP4.h" |
| 4 | + |
| 5 | + |
| 6 | +std::string MP4_labeler::traverse(Node &node){ |
| 7 | + |
| 8 | + std::string output; |
| 9 | + |
| 10 | + for(int i=0; i < node.children().size(); i++){ |
| 11 | + |
| 12 | + Node &child = tree->get_node(node.children()[i]); |
| 13 | + |
| 14 | + output += traverse(child); |
| 15 | + } |
| 16 | + |
| 17 | + |
| 18 | + uint32_t size; |
| 19 | + |
| 20 | + if(node.get_id() == 0){ |
| 21 | + size = 20; |
| 22 | + }else{ |
| 23 | + size = node.get_label().size() + output.size() + 4; |
| 24 | + } |
| 25 | + |
| 26 | + std::string label = node.get_label(); |
| 27 | + uint32_t label_size = label.size(); |
| 28 | + |
| 29 | + output = uint32_to_string_BE(size) + label + output; |
| 30 | + |
| 31 | + return output; |
| 32 | +} |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +MP4_labeler::MP4_labeler(RandomTree *in_tree) { |
| 37 | + |
| 38 | + this->tree = in_tree; |
| 39 | + |
| 40 | + priv_name = "MP4"; |
| 41 | + |
| 42 | + Node &root = this->tree->get_node(0); |
| 43 | + |
| 44 | + std::string root_label = "ftyp"; |
| 45 | + root_label += "dash"; |
| 46 | + root_label += "AAAABBBB"; |
| 47 | + |
| 48 | + root.set_label(root_label); |
| 49 | + |
| 50 | + for(int i=1; i < this->tree->size(); i++){ |
| 51 | + |
| 52 | + Node &node = this->tree->get_node(i); |
| 53 | + |
| 54 | + |
| 55 | + uint32_t fourcc; |
| 56 | + |
| 57 | + uint32_t padding; |
| 58 | + |
| 59 | + uint32_t random_data; |
| 60 | + |
| 61 | + |
| 62 | + if(node.children().size() == 0){ |
| 63 | + |
| 64 | + //LEAF |
| 65 | + |
| 66 | + uint32_t random = rand_uint32(0, FOURCC_LIST_SIZE-1); |
| 67 | + |
| 68 | + fourcc = FOURCC_LIST[random].fourcc; |
| 69 | + |
| 70 | + padding = FOURCC_LIST[random].min_size; |
| 71 | + |
| 72 | + random_data = rand_uint32(4, 16); |
| 73 | + |
| 74 | + |
| 75 | + }else{ |
| 76 | + |
| 77 | + //CONTAINER |
| 78 | + |
| 79 | + uint32_t random = rand_uint32(0, CONTAINER_LIST_SIZE-1); |
| 80 | + |
| 81 | + fourcc = CONTAINER_LIST[random].fourcc; |
| 82 | + |
| 83 | + padding = CONTAINER_LIST[random].min_size; |
| 84 | + |
| 85 | + random_data = 0; |
| 86 | + |
| 87 | + } |
| 88 | + |
| 89 | + std::string label = uint32_to_string(fourcc); |
| 90 | + |
| 91 | + label += std::string(padding, '\x00'); |
| 92 | + |
| 93 | + label += std::string(random_data, '\x41'); |
| 94 | + |
| 95 | + node.set_label(label); |
| 96 | + |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +std::string MP4_labeler::serialize(){ |
| 104 | + |
| 105 | + std::string output; |
| 106 | + |
| 107 | + Node &root = tree->get_node(0); |
| 108 | + |
| 109 | + output = traverse(root); |
| 110 | + |
| 111 | + return output; |
| 112 | + |
| 113 | +} |
| 114 | + |
0 commit comments