nand-nor / dedelf

Deep elf EDitor
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Implement configuration file parsing #5

Open nand-nor opened 4 years ago

nand-nor commented 4 years ago

Need to add an additional mechanism to specify complex injection and modification options (see issues #4 and #3, which depend on this to work) .

Intention is to enable users to specify a config file in json format, such as path/to/dedelf.json where the contents of dedelf.json includes some combination of the following:

{
  "mode": "",
  "infile": "",
  "outfile": "",
  "injection-options": {
    "section": "",
    "entry": "",
    "size": "",
    "replace": "",
    "byte-offset": ""
  },
  "modify-options": {
    "exec-options": {
      "field": "",
      "replacement": ""
    },
    "header-sec-options": {
      "name": "",
      "index": "",
      "field": "",
      "replacement": ""
    },
    "header-seg-options": {
      "index": "",
      "field": "",
      "replacement": ""
    },
    "new-sec-options": {
      "sec-header-options": {
        "sh_name": "",
        "sh_type":"",
        "sh_flags": "",
        "sh_addr":"",
        "sh_offset":"",
        "sh_size;":"",
        "sh_link":"",
        "sh_info":"",
        "sh_addralign":"",
        "sh_entsize":""
      },
      "name": ""
    },
    "new-seg-options" : {
      "prog-header-options": {
        "p_type": "",
        "p_flags": "",
        "p_vaddr": "",
        "p_paddr": "",
        "p_offset": "",
        "p_filesz": "",
        "p_memsz": "",
        "p_align": ""
      }
    }
  }
}

Where mode may be one of the following: injection, modify,or dual. If injection mode, provide desired fields under the injection-options header, add the same for modify mode, and provide any desired injection options (if not wanting the defaults) along with at least 1 modification option (see exec-options fields, header-sec-options fields, etc. Optionally specify outfile-- if omitted then the bytes will be written to the infile name with _inj appended to the string.

Users should omit the fields relating to functionality that is not to be applied, rather than leave then blank. Any blank fields retained in the .json will be treated as an error and halt program execution. Note: need to look up if this is possible for json parsing in this manner...

nand-nor commented 4 years ago

May potentially be support for this in a more heavyweight arg parsing crate (possible such as clap?). Would not mind upgrading from argparse to a better mechanism-- argparse, while nice for many reasons, is somewhat limited and it may be the case that the complexity of this program requires something more heavyweight. Need to do more research into potential options.