0

I realize that there's never a good reason for doing this, but I'm curious for the purposes of security. Is it possible to crawl the stack and capture variables from different frames?

void Func1(string parameter)
{
    Func2(MakeSafeParameter(parameter));
}

// external user code
void Func2(string safeParameter)
{
  // from here could I craw the stack to get Func1's parameter?
}

EDIT: From the linked question it appears this isn't directly possible within C# without special references. Thanks for the answers/comments!

mhand
  • 1,231
  • 1
  • 11
  • 21
  • In response to your "never a good reason for doing this" statement, I would imagine it might be helpful in logging errors (assuming it's possible). – mason Aug 04 '15 at 19:41
  • 2
    What do you want to hide? if there is something in your code to hide, you can't. Reverse engineering can reveal everything. – EZI Aug 04 '15 at 19:42
  • Should `Func1(MakeSafeParameter(parameter));` be `Func2(MakeSafeParameter(parameter));`? – mason Aug 04 '15 at 19:42
  • 1
    Visual Studio debugger does it. So to answer your question: Yes. – Sam Axe Aug 04 '15 at 19:44
  • @SamAxe - really? I thought VS was just keeping track of the stack on its way down, not necessarily that it could reach back up and grab additional data. – Adam V Aug 04 '15 at 19:45
  • @EZI: well.. not *everything*. It won't reveal xml comments without a pdb file. Code comments are usually lost forever after compilation. What I ate for dinner is only recoverable by a forensic scientist.. :) Whitespace, which is just as important as the code, is completely unrecoverable. – Sam Axe Aug 04 '15 at 19:46
  • @AdamV: if you hit a breakpoint and pull up the Call Stack window, then double-click on any item in the call stack window (item == method calls) then you can inspect the state of any variable at that "moment" in time when the method was called. – Sam Axe Aug 04 '15 at 19:48
  • @AdamV - code type fixed. – mhand Aug 04 '15 at 20:12
  • @Blorgbeard - thanks, didn't find that initially – mhand Aug 04 '15 at 20:13
  • @EZI - I'm running user code on the cloud and was just curious if this was possible, it appears to *NOT* be possible without external process/other tools. I specifically wanted to prevent access to certain components that exist on the stack but aren't passed into user code – mhand Aug 04 '15 at 20:14
  • @IdiotDeletingMyComments I won't say anything. But you understand it :) – EZI Aug 04 '15 at 20:19
  • @EZI I forget what the comment said by now, but I don't recall it being out of line. tough mods. – mhand Aug 04 '15 at 22:19
  • @mhand No problem, it was only related with *Sam Axe*'s digestion problem :) – EZI Aug 04 '15 at 22:21

0 Answers0