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
Workaround issue with DebugSymbol #48
Conversation
Here the issue with DebugSymbol frida/frida-gum#186 |
Interesting. What does |
mm. It does work from REPL but it wasn't on r2frida side
|
|
This from REPL fails
|
Is kind of random behavior. With Tweetbot works but with cat it doesn't. |
src/agent/index.js
Outdated
@@ -961,7 +961,19 @@ function traceFormat(args) { | |||
const traceOnEnter = format.indexOf('^') !== -1; | |||
const traceBacktrace = format.indexOf('+') !== -1; | |||
|
|||
const at = DebugSymbol.fromAddress(ptr(address)) || '' + ptr(address); | |||
var module = Process.enumerateModulesSync()[0].name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use const instead of var here
src/agent/index.js
Outdated
var module = Process.enumerateModulesSync()[0].name; | ||
var imports = Module.enumerateImportsSync(module); | ||
var at = ''; | ||
for (var index = 0; index < imports.length; index++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use let instead of var
src/agent/index.js
Outdated
@@ -961,7 +961,19 @@ function traceFormat(args) { | |||
const traceOnEnter = format.indexOf('^') !== -1; | |||
const traceBacktrace = format.indexOf('+') !== -1; | |||
|
|||
const at = DebugSymbol.fromAddress(ptr(address)) || '' + ptr(address); | |||
var module = Process.enumerateModulesSync()[0].name; | |||
var imports = Module.enumerateImportsSync(module); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imports are const
src/agent/index.js
Outdated
var module = Process.enumerateModulesSync()[0].name; | ||
var imports = Module.enumerateImportsSync(module); | ||
var at = ''; | ||
for (var index = 0; index < imports.length; index++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can iterate here with for (let import of imports) { if (imp.address === address) {
src/agent/index.js
Outdated
var imports = Module.enumerateImportsSync(module); | ||
var at = ''; | ||
for (var index = 0; index < imports.length; index++) { | ||
if (imports[index].address == address) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ===
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of using ==
instead of ===
it does work. Maybe @oleavr that is the issue with DebugSymbol?
src/agent/index.js
Outdated
break; | ||
} | ||
} | ||
if (at == '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ===, but better check for undefined. what if the import name is '' ? :P
src/agent/index.js
Outdated
@@ -961,7 +961,19 @@ function traceFormat(args) { | |||
const traceOnEnter = format.indexOf('^') !== -1; | |||
const traceBacktrace = format.indexOf('+') !== -1; | |||
|
|||
const at = DebugSymbol.fromAddress(ptr(address)) || '' + ptr(address); | |||
var module = Process.enumerateModulesSync()[0].name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this logic into a separate function
src/agent/index.js
Outdated
if (at == '') { | ||
'' + ptr(address); | ||
} | ||
//const at = DebugSymbol.fromAddress(ptr(address)) || '' + ptr(address); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove leftover
src/agent/index.js
Outdated
} | ||
} | ||
if (at == '') { | ||
'' + ptr(address); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line does nothing
src/agent/index.js
Outdated
const module = Process.enumerateModulesSync()[0].name; | ||
const imports = Module.enumerateImportsSync(module); | ||
for (let imp of imports) { | ||
if (imp.address == address) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So ==
is needed to make a type conversion? If I use ===
it doesn't work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also use compare
method for native pointers/addresses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Local::ProcName::cat]-> imports[0].address
"0x7fffb458f374"
[Local::ProcName::cat]-> imports[0].address.compare
function
[Local::ProcName::cat]-> imports[0].address.compare("0x0") // better to use `isNull()`
1
[Local::ProcName::cat]-> imports[0].address.compare(imports[0].address)
0
[Local::ProcName::cat]-> imports[0].address.compare(imports[1].address)
-1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compare doesn't work.
[Local::ProcName::cat]-> imports[36].address.compare("0x7fff98084910")
0
[Local::ProcName::cat]-> imports[36].address == "0x7fff98084910"
true
[Local::ProcName::cat]-> imports[36]
{
"address": "0x7fff98084910",
"module": "/usr/lib/libSystem.B.dylib",
"name": "write",
"type": "function"
}
Javascript ¯\(ツ)/¯
@alvarofe Yeah always use strict equality checking, the others shouldn't be used IMO. In this case though, the value is a |
Btw, if you feel like a little tour of non-strict equality craziness, check out this lightning talk: |
I should review other places when DebugSymbol is used in case it fails |
compare(ptr("0x...
… On 19 Feb 2017, at 20:41, Álvaro Felipe Melchor ***@***.***> wrote:
@alvarofe commented on this pull request.
In src/agent/index.js:
> @@ -947,6 +947,22 @@ function getPtr(p) {
return Module.findExportByName(null, p);
}
+function nameFromAddress(address) {
+ var at = '';
+ const module = Process.enumerateModulesSync()[0].name;
+ const imports = Module.enumerateImportsSync(module);
+ for (let imp of imports) {
+ if (imp.address == address) {
So == is need to make a type conversion?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
src/agent/index.js
Outdated
@@ -91,6 +91,24 @@ const RTLD_GLOBAL = 0x8; | |||
const RTLD_LAZY = 0x1; | |||
const allocPool = {}; | |||
|
|||
function nameFromAddress(address) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space between function name and opening parenthesis as per semistandard.
src/agent/index.js
Outdated
@@ -91,6 +91,24 @@ const RTLD_GLOBAL = 0x8; | |||
const RTLD_LAZY = 0x1; | |||
const allocPool = {}; | |||
|
|||
function nameFromAddress(address) { | |||
let at = DebugSymbol.fromAddress(ptr(address)).name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space and missing semicolon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By guaranteeing that this function is always called with a NativePointer
(see suggestion below), we can drop ptr()
here so it's just:
let at = DebugSymbol.fromAddress(address).name;
@@ -960,8 +978,8 @@ function traceFormat(args) { | |||
} | |||
const traceOnEnter = format.indexOf('^') !== -1; | |||
const traceBacktrace = format.indexOf('+') !== -1; | |||
const at = nameFromAddress (address); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be simpler to always pass a NativePointer
value to this function, by changing the else
above from:
var address = offset;
to:
var address = ptr(offset);
(Note to self: we should refactor so offset
is always a NativePointer
.)
src/agent/index.js
Outdated
const module = Process.enumerateModulesSync()[0].name; | ||
const imports = Module.enumerateImportsSync(module); | ||
for (let imp of imports) { | ||
if (imp.address.equals(ptr(address))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this ptr()
.
src/agent/index.js
Outdated
} | ||
} | ||
if (at === null) { | ||
at = '' + ptr(address); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this ptr()
.
I had only time to update the PR. I couldn't look at other instances of DebugSymbol. Regarding code style are you using https://github.com/Flet/semistandard ? just to make sure the next time I upload code in here. Regarding |
src/agent/index.js
Outdated
@@ -91,6 +91,24 @@ const RTLD_GLOBAL = 0x8; | |||
const RTLD_LAZY = 0x1; | |||
const allocPool = {}; | |||
|
|||
function nameFromAddress (address) { | |||
let at = DebugSymbol.fromAddress(address).name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon.
} | ||
} | ||
if (at === null) { | ||
at = '' + address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at = address.toString();
would be clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is also done in several other places in this js, so i would go to change this in a separate pr
src/agent/index.js
Outdated
@@ -91,6 +91,24 @@ const RTLD_GLOBAL = 0x8; | |||
const RTLD_LAZY = 0x1; | |||
const allocPool = {}; | |||
|
|||
function nameFromAddress (address) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if fromAddress() return null the .name will throw an exception that is not catched. i think that this code should be written in a different way. But Frida should already resolve those symbols . so it's a bug in Frida. Can you provide a reproducer? cc @oleavr
The problem here is that Frida is not exposing the address of the imports in the PLT/STUB inside the binary, so the symbols that hasnt been executed yet cannot be resolved. that's why you cant resolve write in cat because it's on hold in read. One solution that comes to my mind will be to make Frida resolve the PLT symbols with the DebugSymbol API, or maybe provide an api to do that without having to iterate in js |
nvm happens with |
Thats because frida uses CoreSymbolication framework which depends on CoreFoundation and those libs are not loaded in cat. Its an issue in Frida that should be addressed there. We can have a workaround but I would prefer to have this solved using ApiResolver or making Frida use ApiResolver in case the symbolicator cant be instantiated.
… On 21 Feb 2017, at 23:04, Sergi Àlvarez i Capilla ***@***.***> wrote:
nvm happens with read too.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I agree on that, do not have any clue about Frida's internals but If I can help to sort this out let me know. Ok to close this PR and move the issue into Frida? Where is this in handled in Frida within frida-gum? |
i'll merge this workaround, and do some tweaks later. but the fix should be done in Frida, not in r2frida, as long as we have other workarounds for Frida in r2frida, it's ok for me to have this merged to make r2frida useful outside mac |
I agree on that but Frida code is out of my reach for the time being, I asked where to open the issue, basically in which frida's repo. But if you want to include this temporary is ok for me |
if (at === null) { | ||
const module = Process.enumerateModulesSync()[0].name; | ||
const imports = Module.enumerateImportsSync(module); | ||
for (let imp of imports) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use Process.findModuleByAddress(address) to avoid having to iterate over all modules to find which import falls in this address
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, iterate over the Exports too
Fixed the comments and merged from 8e5401d |
Dunno if this is the best solution but I noticed that when using
dtf
to trace calls instead ofI was getting
This can be a hassle when you are tracing many functions. DebugSymbol should be doing this, but as far I know it does not work so is just a dirty workaround.
If this is not good javascript just tell me quite noob tbh.