Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using duplicate keys in JSON: take 2 #20

Merged
merged 4 commits into from
Oct 16, 2018

Conversation

roblabla
Copy link
Contributor

@roblabla roblabla commented Sep 27, 2018

Description

Currently, the NPDM-JSON format abuses duplicate keys where it should be using arrays instead. While cJSON supports this, most JSON parsers don't. This is causing issues for me currently when building linkle as serde-json (a deserializer for JSON in rust) doesn't support this. While I could probably fix that issue in serde-json, I think moving to a saner format using JSON arrays is also a good idea.

The main reason why this tool needs fixing, however, is that it makes it impossible to create tools that reason about NPDM-JSON generated by hactool. I've been meaning to create some tools that allows visualizing the interactions between all processes of the switch OS, using the NPDMs, and that is currently not possible without either manually parsing the raw NPDM, or using one of the few, rare JSON parsers that allow duplicate keys. This situation is annoying.

Solution

After debating with SciresM a bit in the RS server, it was decided that kernel_capabilities should be changed to an object that takes two keys ("type" and "value"), and service_access would be split into two string arrays: service_host and service_access

{
    "kernel_capabilities": [
        { "type": "irq_pair", "value": [1, 2] }
    ],
    "service_host": ["*"],
    "service_access": ["*"]
}

This PR deprecates duplicate-key style. It still allows parsing them though, to give some time for homebrew to migrate. It may get removed in a later PR.

Meta

Associated PR:

I'll also mass-PR fixes to all open source homebrews.

The array-style kernel caps look like:

"kernel_capabilities": [
    { type: "irq_pair", value: [1, 2] },
    // ...
]

Deprecates duplicate-key style.
@ThatNerdyPikachu
Copy link

You forgot hbloader :p
(Also, are these PRs automated?)

@roblabla
Copy link
Contributor Author

roblabla commented Sep 28, 2018

Yeah, I used a quick script that used gh search to find all json containing kernel_capabilities, and auto-submit a pr.

Not sure whi hbl got missed. I'll do a manual fix I guess

@roblabla
Copy link
Contributor Author

Alright, I found a better search term that managed to find more repositories with NPDM-JSONs, including nx-hbloader. Going to fix the script and open a few more PRs.

@roblabla
Copy link
Contributor Author

Yeah OK there was a bug in my script actually. Fixed it, got 4 new PRs. That should be all of them now :).

Splits service_access into service_host and service_access, both arrays of
strings.

We output service_host first, as that seems to be what Nintendo is doing - all
their NPDMs have service hosts before service accesses.
@roblabla
Copy link
Contributor Author

Added implementation to parse service_access/service_host. It's also implemented in hactool, and all the homebrew PRs got updated.

@yellows8
Copy link
Collaborator

That service-list commit only updated npdmtool, not elf2kip.

@roblabla
Copy link
Contributor Author

KIPs don't have service lists?

@yellows8
Copy link
Collaborator

nvm

@yellows8 yellows8 merged commit 1c382d5 into switchbrew:master Oct 16, 2018
@ThatNerdyPikachu
Copy link

Will a release follow shortly after? :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants