Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 20 | pmbaty | 1 | #include "register.h" |
| 2 | #include "harness/trace.h" |
||
| 3 | |||
| 4 | #include "brlists.h" |
||
| 5 | #include "fwsetup.h" |
||
| 6 | #include "pattern.h" |
||
| 7 | #include "resource.h" |
||
| 8 | |||
| 9 | // IDA: void* __usercall BrRegistryNew@<EAX>(br_registry *reg@<EAX>) |
||
| 10 | void* BrRegistryNew(br_registry* reg) { |
||
| 11 | LOG_TRACE10("(%p)", reg); |
||
| 12 | |||
| 13 | BrNewList(®->list); |
||
| 14 | reg->count = 0; |
||
| 15 | return reg; |
||
| 16 | } |
||
| 17 | |||
| 18 | // IDA: void* __usercall BrRegistryClear@<EAX>(br_registry *reg@<EAX>) |
||
| 19 | void* BrRegistryClear(br_registry* reg) { |
||
| 20 | br_registry_entry* e; |
||
| 21 | LOG_TRACE10("(%p)", reg); |
||
| 22 | |||
| 23 | e = (br_registry_entry*)reg->list.head; |
||
| 24 | while (e->node.next != NULL) { |
||
| 25 | BrRemove(&e->node); |
||
| 26 | BrResFree(e); |
||
| 27 | e = (br_registry_entry*)reg->list.head; |
||
| 28 | } |
||
| 29 | reg->count = 0; |
||
| 30 | return reg; |
||
| 31 | } |
||
| 32 | |||
| 33 | // IDA: void* __usercall BrRegistryAdd@<EAX>(br_registry *reg@<EAX>, void *item@<EDX>) |
||
| 34 | void* BrRegistryAdd(br_registry* reg, void* item) { |
||
| 35 | br_registry_entry* e; |
||
| 36 | LOG_TRACE10("(%p, %p)", reg, item); |
||
| 37 | |||
| 38 | e = (br_registry_entry*)BrResAllocate(fw.res, sizeof(br_registry_entry), BR_MEMORY_REGISTRY); |
||
| 39 | e->item = (char**)item; |
||
| 40 | BrAddHead(®->list, (br_node*)e); |
||
| 41 | reg->count++; |
||
| 42 | return item; |
||
| 43 | } |
||
| 44 | |||
| 45 | // IDA: int __usercall BrRegistryAddMany@<EAX>(br_registry *reg@<EAX>, void **items@<EDX>, int n@<EBX>) |
||
| 46 | int BrRegistryAddMany(br_registry* reg, void** items, int n) { |
||
| 47 | br_registry_entry* e; |
||
| 48 | int i; |
||
| 49 | LOG_TRACE10("(%p, %p, %d)", reg, items, n); |
||
| 50 | |||
| 51 | for(i = 0; i < n; i++) { |
||
| 52 | e = BrResAllocate(fw.res, sizeof(br_registry_entry), BR_MEMORY_REGISTRY); |
||
| 53 | e->item = ((char ***)items)[i]; |
||
| 54 | BrAddHead(®->list, (br_node *)&e->node); |
||
| 55 | reg->count++; |
||
| 56 | } |
||
| 57 | return n; |
||
| 58 | } |
||
| 59 | |||
| 60 | // IDA: void* __usercall BrRegistryRemove@<EAX>(br_registry *reg@<EAX>, void *item@<EDX>) |
||
| 61 | void* BrRegistryRemove(br_registry* reg, void* item) { |
||
| 62 | br_registry_entry* e; |
||
| 63 | void* r; |
||
| 64 | LOG_TRACE10("(%p, %p)", reg, item); |
||
| 65 | |||
| 66 | e = (br_registry_entry*)reg->list.head; |
||
| 67 | while ((e->node.next != NULL) && (e->item != item)) { |
||
| 68 | e = (br_registry_entry*)e->node.next; |
||
| 69 | } |
||
| 70 | if (e->node.next == NULL) { |
||
| 71 | return NULL; |
||
| 72 | } |
||
| 73 | BrRemove((br_node*)e); |
||
| 74 | r = e->item; |
||
| 75 | BrResFree(e); |
||
| 76 | reg->count--; |
||
| 77 | return r; |
||
| 78 | } |
||
| 79 | |||
| 80 | // IDA: int __usercall BrRegistryRemoveMany@<EAX>(br_registry *reg@<EAX>, void **items@<EDX>, int n@<EBX>) |
||
| 81 | int BrRegistryRemoveMany(br_registry* reg, void** items, int n) { |
||
| 82 | //int i; // Pierre-Marie Baty -- unused variable |
||
| 83 | int r; |
||
| 84 | LOG_TRACE("(%p, %p, %d)", reg, items, n); |
||
| 85 | |||
| 86 | r = 0; |
||
| 87 | for (; n != 0; n--) { |
||
| 88 | if (BrRegistryRemove(reg, *items) != NULL) { |
||
| 89 | r++; |
||
| 90 | } |
||
| 91 | items++; |
||
| 92 | } |
||
| 93 | return r; |
||
| 94 | } |
||
| 95 | |||
| 96 | // IDA: void* __usercall BrRegistryFind@<EAX>(br_registry *reg@<EAX>, char *pattern@<EDX>) |
||
| 97 | void* BrRegistryFind(br_registry* reg, char* pattern) { |
||
| 98 | br_registry_entry* e; |
||
| 99 | LOG_TRACE8("(%p, \"%s\")", reg, pattern); |
||
| 100 | |||
| 101 | e = (br_registry_entry*)reg->list.head; |
||
| 102 | while (e->node.next != NULL) { |
||
| 103 | // 2nd element of item must be char pointer. |
||
| 104 | if (BrNamePatternMatch(pattern, e->item[1]) != 0) { |
||
| 105 | return e->item; |
||
| 106 | } |
||
| 107 | e = (br_registry_entry*)e->node.next; |
||
| 108 | } |
||
| 109 | if (reg->find_failed_hook != NULL) { |
||
| 110 | return reg->find_failed_hook(pattern); |
||
| 111 | } |
||
| 112 | return NULL; |
||
| 113 | } |
||
| 114 | |||
| 115 | // IDA: int __usercall BrRegistryFindMany@<EAX>(br_registry *reg@<EAX>, char *pattern@<EDX>, void **items@<EBX>, int max@<ECX>) |
||
| 116 | int BrRegistryFindMany(br_registry* reg, char* pattern, void** items, int max) { |
||
| 117 | br_registry_entry* e; |
||
| 118 | int n; |
||
| 119 | LOG_TRACE("(%p, \"%s\", %p, %d)", reg, pattern, items, max); |
||
| 120 | |||
| 121 | n = 0; |
||
| 122 | e = (br_registry_entry*)reg->list.head; |
||
| 123 | while ((e->node.next != NULL) && (n < max)) { |
||
| 124 | if (BrNamePatternMatch(pattern, e->item[1]) != 0) { |
||
| 125 | *items = e->item; |
||
| 126 | items++; |
||
| 127 | n++; |
||
| 128 | } |
||
| 129 | e = (br_registry_entry*)e->node.next; |
||
| 130 | } |
||
| 131 | return n; |
||
| 132 | } |
||
| 133 | |||
| 134 | // IDA: int __usercall BrRegistryCount@<EAX>(br_registry *reg@<EAX>, char *pattern@<EDX>) |
||
| 135 | int BrRegistryCount(br_registry* reg, char* pattern) { |
||
| 136 | br_registry_entry* e; |
||
| 137 | int n; |
||
| 138 | LOG_TRACE("(%p, \"%s\")", reg, pattern); |
||
| 139 | |||
| 140 | if (pattern == NULL) { |
||
| 141 | return reg->count; |
||
| 142 | } |
||
| 143 | n = 0; |
||
| 144 | e = (br_registry_entry*)reg->list.head; |
||
| 145 | while (e->node.next != NULL) { |
||
| 146 | if (BrNamePatternMatch(pattern, e->item[1]) != 0) { |
||
| 147 | n++; |
||
| 148 | } |
||
| 149 | e = (br_registry_entry*)e->node.next; |
||
| 150 | } |
||
| 151 | return n; |
||
| 152 | } |
||
| 153 | |||
| 154 | // IDA: int __usercall BrRegistryEnum@<EAX>(br_registry *reg@<EAX>, char *pattern@<EDX>, br_enum_cbfn *callback@<EBX>, void *arg@<ECX>) |
||
| 155 | int BrRegistryEnum(br_registry* reg, char* pattern, br_enum_cbfn* callback, void* arg) { |
||
| 156 | br_registry_entry* e; |
||
| 157 | int r; |
||
| 158 | LOG_TRACE("(%p, \"%s\", %p, %p)", reg, pattern, callback, arg); |
||
| 159 | |||
| 160 | if (pattern == NULL) { |
||
| 161 | e = (br_registry_entry*)reg->list.tail; |
||
| 162 | while (e->node.prev != NULL) { |
||
| 163 | r = callback(e->item, arg); |
||
| 164 | if (r != 0) { |
||
| 165 | return r; |
||
| 166 | } |
||
| 167 | e = (br_registry_entry*)e->node.prev; |
||
| 168 | } |
||
| 169 | } else { |
||
| 170 | e = (br_registry_entry*)reg->list.tail; |
||
| 171 | while (e->node.prev != NULL) { |
||
| 172 | // as a char**, e->item[1] actually points to `identifier` field in a br_* struct etc |
||
| 173 | r = BrNamePatternMatch(pattern, e->item[1]); |
||
| 174 | if (r != 0) { |
||
| 175 | r = callback(e->item, arg); |
||
| 176 | if (r != 0) { |
||
| 177 | return r; |
||
| 178 | } |
||
| 179 | } |
||
| 180 | e = (br_registry_entry*)e->node.prev; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | return 0; |
||
| 184 | } |
||
| 185 | |||
| 186 | // IDA: void* __usercall BrRegistryNewStatic@<EAX>(br_registry *reg@<EAX>, br_registry_entry *base@<EDX>, int limit@<EBX>) |
||
| 187 | void* BrRegistryNewStatic(br_registry* reg, br_registry_entry* base, int limit) { |
||
| 188 | LOG_TRACE("(%p, %p, %d)", reg, base, limit); |
||
| 189 | return NULL; |
||
| 190 | } |
||
| 191 | |||
| 192 | // IDA: void* __usercall BrRegistryAddStatic@<EAX>(br_registry *reg@<EAX>, br_registry_entry *base@<EDX>, void *item@<EBX>) |
||
| 193 | void* BrRegistryAddStatic(br_registry* reg, br_registry_entry* base, void* item) { |
||
| 194 | LOG_TRACE("(%p, %p, %p)", reg, base, item); |
||
| 195 | return NULL; |
||
| 196 | } |
||
| 197 | |||
| 198 | // IDA: void* __usercall BrRegistryRemoveStatic@<EAX>(br_registry *reg@<EAX>, void *item@<EDX>) |
||
| 199 | void* BrRegistryRemoveStatic(br_registry* reg, void* item) { |
||
| 200 | LOG_TRACE("(%p, %p)", reg, item); |
||
| 201 | return NULL; |
||
| 202 | } |