(json_text, output_file)
| 190 | |
| 191 | |
| 192 | def parse_json(json_text, output_file): |
| 193 | # Default options |
| 194 | OptionMatch = Regs.REG_INVALID |
| 195 | OptionIgnore = Regs.REG_NONE |
| 196 | OptionABI = ABI.ABI_SYSTEMV |
| 197 | OptionMode = Mode.MODE_64 |
| 198 | OptionHostFeatures = HostFeatures.FEATURE_ANY |
| 199 | OptionStackSize = 4096 |
| 200 | OptionEntryPoint = 1 |
| 201 | OptionRegData = {} |
| 202 | OptionMemoryRegions = {} |
| 203 | OptionMemoryData = {} |
| 204 | OptionEnvironmentVariables = {} |
| 205 | |
| 206 | json_object = json.loads(json_text) |
| 207 | json_object = {k.upper(): v for k, v in json_object.items()} |
| 208 | |
| 209 | # Begin parsing the JSON |
| 210 | if ("MATCH" in json_object): |
| 211 | data = json_object["MATCH"] |
| 212 | if (type(data) is str): |
| 213 | data = [data] |
| 214 | |
| 215 | for data_val in data: |
| 216 | data_val = data_val.upper() |
| 217 | if not (data_val in RegStringLookup): |
| 218 | sys.exit("Invalid Match register option") |
| 219 | if (OptionMatch == Regs.REG_INVALID): |
| 220 | OptionMatch = Regs.REG_NONE |
| 221 | RegOption = RegStringLookup[data_val] |
| 222 | OptionMatch = OptionMatch | RegOption |
| 223 | |
| 224 | if ("IGNORE" in json_object): |
| 225 | data = json_object["IGNORE"] |
| 226 | if (type(data) is str): |
| 227 | data = [data] |
| 228 | |
| 229 | for data_val in data: |
| 230 | data_val = data_val.upper() |
| 231 | if not (data_val in RegStringLookup): |
| 232 | sys.exit("Invalid Ignore register option") |
| 233 | if (OptionMatch == Regs.REG_INVALID): |
| 234 | OptionMatch = Regs.REG_NONE |
| 235 | RegOption = RegStringLookup[data_val] |
| 236 | OptionIgnore = OptionIgnore | RegOption |
| 237 | |
| 238 | if ("ABI" in json_object): |
| 239 | data = json_object["ABI"] |
| 240 | data = data.upper() |
| 241 | if not (data in ABIStringLookup): |
| 242 | sys.exit("Invalid ABI") |
| 243 | OptionABI = ABIStringLookup[data] |
| 244 | |
| 245 | if ("MODE" in json_object): |
| 246 | data = json_object["MODE"] |
| 247 | data = data.upper() |
| 248 | if not (data in ModeStringLookup): |
| 249 | sys.exit("Invalid Mode") |
no test coverage detected