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 symbols.unredact config variable #144

Merged
merged 4 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/agent/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const config = {
'stalker.timeout': 5 * 60,
'stalker.in': 'raw',
'hook.backtrace': true,
'hook.verbose': true
'hook.verbose': true,
'symbols.unredact': true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be set to false outside iOS (and maybe macOS) too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh ok

};

const configHelp = {
Expand All @@ -17,7 +18,8 @@ const configHelp = {
'stalker.timeout': configHelpStalkerTimeout,
'stalker.in': configHelpStalkerIn,
'hook.backtrace': configHelpHookBacktrace,
'hook.verbose': configHelpHookVerbose
'hook.verbose': configHelpHookVerbose,
'symbols.unredact': configHelpSymbolsUnredact
};

const configValidator = {
Expand All @@ -26,7 +28,8 @@ const configValidator = {
'stalker.timeout': configValidateStalkerTimeout,
'stalker.in': configValidateStalkerIn,
'hook.backtrace': configValidateHookBacktrace,
'hook.verbose': configValidateHookVerbose
'hook.verbose': configValidateHookVerbose,
'symbols.unredact': configValidateSymbolsUnredact
};

function configHelpSearchIn () {
Expand Down Expand Up @@ -112,6 +115,14 @@ function configHelpStalkerIn () {
`;
}

function configHelpSymbolsUnredact () {
return `Try to get symbol names from debug symbols when they're "redacted":

true try to unredact (the default)
false do not attempt to unredact
`;
}

function configValidateHookVerbose (val) {
if (typeof (val) === 'boolean') {
return true;
Expand All @@ -127,6 +138,13 @@ function configValidateStalkerIn (val) {
return ['raw', 'app', 'modules'].indexOf(val) !== -1;
}

function configValidateSymbolsUnredact (val) {
if (typeof (val) === 'boolean') {
return true;
}
return ['true', 'false'].indexOf(val) !== -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about return (/(true|false)/i).test(val); so its case insensitive. Also, we have the isTrue() helper below

}

function isTrue (x) {
return (x === true || x === 1 || x === 'true');
}
Expand Down
29 changes: 27 additions & 2 deletions src/agent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const allocPool = {};
const pendingCmds = {};
const pendingCmdSends = [];
let sendingCommand = false;
const insaneSet = new Set(['`', '$', '{', '}', '~', '|', ';', '#', '@', '&', '<', '>', ' ', '(', ')']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a single string is probably faster imho. const specialChars = "`${}~|;#...".

and then use sspecialChars.indexOf(ch) !== -1


function numEval (expr) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -836,17 +837,41 @@ function listSymbols (args) {

function listSymbolsR2 (args) {
return listSymbolsJson(args)
.filter(({ address }) => !address.isNull())
.map(({ type, name, address }) => {
return ['f', 'sym.' + type.substring(0, 3) + '.' + name, '=', address].join(' ');
return ['f', 'sym.' + type.substring(0, 3) + '.' + sanitizeString(name), '=', address].join(' ');
})
.join('\n');
}

function sanitizeString (str) {
const result = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about using map/filter for this?

return str.split().map(_ => insaneSet.has(x)? c:'_').join('')


for (const c of str) {
if (insaneSet.has(c)) {
result.push('_');
} else {
result.push(c);
}
}

return result.join('');
}

function listSymbolsJson (args) {
const currentModule = (args.length > 0)
? Process.getModuleByName(args[0])
: Process.getModuleByAddress(offset);
return Module.enumerateSymbols(currentModule.name);
const symbols = Module.enumerateSymbols(currentModule.name);
return symbols.map(sym => {
if (config.getBoolean('symbols.unredact') && sym.name.indexOf('redacted') !== -1) {
const dbgSym = DebugSymbol.fromAddress(sym.address);
if (dbgSym !== null) {
sym.name = dbgSym.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm, when we find the symbol we dont need to continue searching , right? maybe good to use a for loop to break it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're not searching here, it's just iterating over all the results of enumerateSymbols

}
}
return sym;
});
}

function lookupDebugInfo (args) {
Expand Down