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

Add command to rebase analysis information #13753

Open
radare opened this issue Apr 15, 2019 · 11 comments
Open

Add command to rebase analysis information #13753

radare opened this issue Apr 15, 2019 · 11 comments
Assignees
Labels
IMPORTANT RAnal types Parsing, propagating and inferring simple and complex types

Comments

@radare
Copy link
Collaborator

radare commented Apr 15, 2019

We need a command that takes this as arguments:

  • initiial address of current data (for a specific module)
  • end address of current data (for a specific module)
  • new base address

The command will walk all the comments, hints, breakpoints, functions, basic blocks, types bindings, xrefs... and rebase all of them that are poiniting in the specified range.

Example propsal:

aR 0x8000 0xa000 @ 0x6000
aR 0x6000 0x8000 0xa000

When this command (and api) is ready, we can use it to solve the problem of ood in aslr by rebasing all the debugmaps comparing them to the new ones and calling aR.

@radare radare added RAnal types Parsing, propagating and inferring simple and complex types labels Apr 15, 2019
@radare radare added this to the 3.5.0 milestone Apr 15, 2019
@XVilka
Copy link
Contributor

XVilka commented Apr 15, 2019

Isn't this a duplicate of #6495 ?

@XVilka
Copy link
Contributor

XVilka commented Apr 15, 2019

Also related #5905

@radare
Copy link
Collaborator Author

radare commented Apr 15, 2019

yes it is. we can close the old one, because it's better described/explained in here

@radare
Copy link
Collaborator Author

radare commented Apr 16, 2019

im thinking that this wont work unless i provide the full mapping translations of all the regions at once. otherwise we can recursively rebase things that fall on other used areas and result in a broken state

@radare radare added this to To do in Type Analysis Improvements via automation Apr 17, 2019
@radare radare modified the milestones: 3.5.0, 3.6.0 May 10, 2019
@radare radare modified the milestones: 3.6.0, 3.7.0 Jun 16, 2019
@radare
Copy link
Collaborator Author

radare commented Jun 16, 2019

maybe do this with two different RCore instances like radiff works?

@Hamled
Copy link

Hamled commented Jun 17, 2019

This is also related to #13390.

One question to ask, I think, is what are the use cases for the analysis rebasing command? The most obvious one to me is when switching into and out of debugging mode (in particular ASLR scenarios as you've mentioned).

If that's the only meaningful use case, we might have some less-general solutions that still work vs. needing to generally support rebasing an RAnal instance.

For example, maybe have two RAnal instances referenced from RCore:

  • One for static analysis, written/read when using analysis commands while not debug mode.
  • One for current dynamic analysis, written/read when using analysis commands while debugging.

The rebasing operation could be contained entirely within the processing of oo[d], for the case where there is existing analysis data when you reopen a file in debug mode.

This might simplify:

  • needing to have all loaded maps at once, so everything can be rebased atomically
  • code changes, if we switch the RCore.anal pointer as needed, and store the above two instances in separate members.
  • switching out of debug mode, no need to "un-rebase"

There's obviously other complications, in particular synchronizing the analysis data as it is modified in either mode. My guess is that would be simpler to implement than rewriting RAnal to include an address translation piece, given how complex that code is and how frequently address fields are directly referenced.

@Hamled
Copy link

Hamled commented Jun 17, 2019

As happens so often, just as I was drifting off to sleep I had an idea that might result in both fewer changes to the existing analysis code base while also being more flexible than what I suggested yesterday.

Rather than keep multiple copies of RCore or RAnal, or update all accesses to analysis objects' addresses to go through a translation layer, we could maintain a separate "address table" with entries for all analysis objects which are reachable from RCore.anal.

Each entry in the table would include, in addition to a reference to the address field on a specific object, whatever information was needed to support rebasing the address.

Rebasing for debugging would mean walking the entire table and rebasing the address through each reference, according to the current maps (or lack thereof). Rebasing with the aR command would just be the same process, but filtered to a entries where the current addresses were within the specified range. Or, perhaps more in the r2 style, entering/exiting debugging state could be implemented as a series of aR commands (at a slight performance hit).

Any address-based indexes (RAnal.fcn_tree and RAnal.fcn_addr_tree at least) would need to be re-built after each rebase, but I guess that's true for any implementation.

I'm also not clear enough yet on how analysis data is persisted with r2, so I'm not sure how or if that would need to be updated.

The clear benefits I see to this approach over the other choices mentioned above:

  • There's no indirection when reading addresses from analysis objects, which is almost certainly the dominating behavior with that data.
  • The code that does rebasing doesn't need to know how to walk through all parts of RAnal to find each address, making it hopefully much simpler.

I'm very new to the radare2 codebase, so please let me know if I'm missing something major with this idea.

@XVilka XVilka added this to To do in Analysis via automation Jul 2, 2019
@XVilka XVilka modified the milestones: 3.7.0, 3.8.0 - after r2con Jul 30, 2019
@XVilka XVilka modified the milestones: 3.9.0, 4.0.0 Sep 14, 2019
@radare radare modified the milestones: 4.0.0, 4.1.0 Oct 26, 2019
@radare
Copy link
Collaborator Author

radare commented Jan 17, 2020

aren't we closer to this after eadbbaf ?

cc @yossizap can you add a command to use this api?

@yossizap
Copy link
Contributor

Will look into it, need to finish rebase based on debug maps instead of sections first.

@radare
Copy link
Collaborator Author

radare commented Jan 17, 2020 via email

@yossizap
Copy link
Contributor

Too much work left, maybe tomorrow morning.

@radare radare modified the milestones: 4.3.0, 4.4.0 Feb 18, 2020
@radare radare modified the milestones: 4.4.0 - pangolin, 4.5.0 Apr 10, 2020
@XVilka XVilka modified the milestones: 4.5.0 - Organized Chaos, 4.6.0 May 21, 2020
@ret2libc ret2libc removed this from the 4.6.0 milestone Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IMPORTANT RAnal types Parsing, propagating and inferring simple and complex types
Projects
Analysis
  
To do
Debugger
  
Awaiting triage
Development

No branches or pull requests

5 participants