<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:12px"><div id="yui_3_16_0_1_1443689901807_8445">Java variable name information is not even included in the bytecode when compiled without</div><div dir="ltr" id="yui_3_16_0_1_1443689901807_8379">-g:vars option; see <a id="yui_3_16_0_1_1443689901807_8425" href="http://stackoverflow.com/questions/744226/java-reflection-how-to-get-the-name-of-a-variable">Java Reflection: How to get the name of a variable?</a><br></div><div style="width:450px; font-family: 'Georgia', 'Times', 'Times New Roman', 'serif';margin-top:5px; margin-bottom: 5px; background-color: #ffffff;" id="enhancrCard_0" class="link-enhancr-attachment link-enhancr-element richcompose-card" contenteditable="false"><table id="yui_3_16_0_1_1443689901807_8450" class="link-enhancr-element" style="width:450px; height:170px; position: relative; display: block;" border="0" cellpadding="0" cellspacing="0"><tbody id="yui_3_16_0_1_1443689901807_8449"><tr id="yui_3_16_0_1_1443689901807_8929" class="link-enhancr-element"><td id="yui_3_16_0_1_1443689901807_8928" class="link-enhancr-element" colspan="8" style="height: 1px; background-color: #e5e5e5; font-size: 1px; border-collapse: collapse;"><div id="yui_3_16_0_1_1443689901807_8927" class="link-enhancr-element" style="height: 1px; background-color: #e5e5e5; font-size: 1px; line-height:0px;">&nbsp;</div></td></tr><tr id="yui_3_16_0_1_1443689901807_8448" class="link-enhancr-element"><td rowspan="5" class="link-enhancr-element" style="width: 1px; background-color: #e5e5e5; font-size: 1pt; border-collapse: collapse;"><div class="link-enhancr-element" style="width: 1px; background-color: #e5e5e5; font-size: 1pt;">&nbsp;</div></td><td id="yui_3_16_0_1_1443689901807_8920" class="link-enhancr-element link-enhancr-image-wrap enhancr-image-crop" rowspan="5" style="vertical-align: middle; width: 168px; height: 168px; background-color: rgb(255, 255, 255); border-collapse: collapse;"><div id="yui_3_16_0_1_1443689901807_8919" class="link-enhancr-element" style="width: 168px;" align="center"><a id="yui_3_16_0_1_1443689901807_8918" href="http://stackoverflow.com/questions/744226/java-reflection-how-to-get-the-name-of-a-variable" class="link-enhancr-card-urlWrapper link-enhancr-element" style="text-decoration: none !important;text-decoration:none; color: #000000 !important;"><img id="yui_3_16_0_1_1443689901807_8917" data-id="a2c50f28-1360-5d3f-2795-15c83f0b5da5" alt="image" src="https://s.yimg.com/vv//api/res/1.2/uiIdpk8fSP.2.eZA9ag7bQ--/YXBwaWQ9bWFpbDtmaT1maWxsO2g9MTY4O3B5b2ZmPTA7dz0xNjg-/http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded&amp;a.cf.jpg" class="link-enhancr-thumbnail-image link-enhancr-element yahoo-ignore-inline-image" style="display: block; margin: auto;" height="168" width="168"></a></div></td><td rowspan="5" class="link-enhancr-element" style="width: 1px; background-color: #e5e5e5; font-size: 0pt; border-collapse: collapse;"><div class="link-enhancr-element" style="width: 1px; background-color: #e5e5e5; font-size: 1pt;">&nbsp;</div></td><td id="yui_3_16_0_1_1443689901807_9733" rowspan="5" class="link-enhancr-element" style="width: 14px; background-color: #ffffff; font-size: 0pt; border-collapse: collapse;"><div class="link-enhancr-element" style="width: 14px; background-color: #ffffff; font-size: 14pt;">&nbsp;</div></td><td id="yui_3_16_0_1_1443689901807_8447" colspan="2" class="link-enhancr-element" style="height: 6px; background-color: #ffffff; font-size: 0pt; border-collapse: collapse;"><div id="yui_3_16_0_1_1443689901807_8446" class="link-enhancr-element" style="height: 6px; background-color: #ffffff; font-size: 6pt;">&nbsp;</div></td><td id="yui_3_16_0_1_1443689901807_8473" rowspan="5" class="link-enhancr-element" style="width: 20px; background-color: #ffffff; font-size: 0pt; border-collapse: collapse;"><div class="link-enhancr-element" style="width: 20px; background-color: #ffffff; font-size: 20pt;">&nbsp;</div></td><td id="yui_3_16_0_1_1443689901807_8457" class="link-enhancr-element" rowspan="5" style="width: 1px; background-color: #e5e5e5; font-size: 1pt; border-collapse: collapse;" width="1"><div class="link-enhancr-element" style="width: 1px; background-color: #e5e5e5; font-size: 1pt;">&nbsp;</div></td></tr><tr id="yui_3_16_0_1_1443689901807_8456"><td id="yui_3_16_0_1_1443689901807_8455" class="link-enhancr-element" colspan="2" style="width: 100%; vertical-align: middle; font-family: 'Georgia', 'Times', 'Times New Roman', 'serif';"><div id="yui_3_16_0_1_1443689901807_8454" class="link-enhancr-text-part link-enhancr-element" style="line-height:16.5px; background-color: #ffffff; height: 135px; width: 245px;"><div id="yui_3_16_0_1_1443689901807_8453" class="link-enhancr-element" style="word-wrap: break-word; word-break: break-all;"><span class="link-enhancr-element icon  icon-shrink link-enhancr-toggle"></span><span class="link-enhancr-element icon icon-close link-enhancr-delete"></span><a id="yui_3_16_0_1_1443689901807_8452" href="http://stackoverflow.com/questions/744226/java-reflection-how-to-get-the-name-of-a-variable" class="link-enhancr-card-urlWrapper link-enhancr-element" style="text-decoration: none !important;text-decoration:none; color: #000000 !important; line-height: 100%; font-size: 18px; display: block;"><span id="yui_3_16_0_1_1443689901807_8451" class="link-enhancr-element link-enhancr-card-title" style="margin: 0; font-weight: normal;margin-bottom: 3px; font-size: 18px; line-height: 21px; max-height: 43px; color: #000000; overflow: hidden !important; display: inline-block;">Java Reflection: How to get the name of a variable?</span></a><div id="yui_3_16_0_1_1443689901807_8926" style="font-size: 13px; line-height: 20px; color: #999999; max-height: 81px; font-family: 'Georgia', 'Times', 'Times New Roman', 'serif';overflow: hidden;" class="link-enhancr-card-description link-enhancr-element">Using Java Reflection, is it possible to get the name of a local variable? For example, if I have this: Foo b = new Foo(); Foo a = new Foo(); Foo r = new Foo(); is ...</div></div></div></td></tr><tr id="yui_3_16_0_1_1443689901807_9004"><td id="yui_3_16_0_1_1443689901807_9003" colspan="2" class="link-enhancr-element" style="height: 4px; background-color: #ffffff; font-size: 0pt; border-collapse: collapse;"><div id="yui_3_16_0_1_1443689901807_9002" class="link-enhancr-element" style="height: 4px; background-color: #ffffff; font-size: 4pt;"></div></td></tr><tr id="yui_3_16_0_1_1443689901807_9010"><td id="yui_3_16_0_1_1443689901807_9009" class="link-enhancr-element" style="vertical-align: middle; font-family: 'Arial', 'Helvetica Neue', 'Helvetica', 'sans-serif';"><div id="yui_3_16_0_1_1443689901807_9008" class="link-enhancr-element" style="font-size: 0pt;"><a id="yui_3_16_0_1_1443689901807_9007" href="http://stackoverflow.com/questions/744226/java-reflection-how-to-get-the-name-of-a-variable" class="link-enhancr-card-url link-enhancr-element" style="color: black; text-decoration: none !important;text-decoration:none;cursor:pointer !important;" target="_blank"><span id="yui_3_16_0_1_1443689901807_8442" class="link-enhancr-element link-enhancr-view-on" style="display: inline-block; line-height: 11px; max-width: 145px; min-width: 85px; overflow: hidden; max-height: 13px; word-break: break-all;"><span id="yui_3_16_0_1_1443689901807_9006" class="link-enhancr-element link-enhancr-mobile-no-resize" style="vertical-align:middle; font-size: 9px; line-height: 11px; color: #999999; -moz-text-size-adjust: none; -ms-text-size-adjust: none; -webkit-text-size-adjust:none; text-size-adjust:none;">View on <span id="yui_3_16_0_1_1443689901807_9005" style="font-weight: bold" class="link-enhancr-view-on-domain">stackoverflow.com</span></span></span></a></div></td><td id="yui_3_16_0_1_1443689901807_9308" class="link-enhancr-element" style="vertical-align: middle; width: 100px; font-family: 'Arial', 'Helvetica Neue', 'Helvetica', 'sans-serif';"><div id="yui_3_16_0_1_1443689901807_9307" class="link-enhancr-element link-enhancr-preview-wrapper" style="max-width: 100px; min-width: 80px; overflow: hidden; text-align: right; line-height: 11px; max-height: 13px; font-size: 0pt;"><span id="yui_3_16_0_1_1443689901807_9734" class="link-enhancr-element link-enhancr-preview-by link-enhancr-mobile-no-resize" style="vertical-align:middle; font-size: 9px; line-height: 11px; color: #999999; -moz-text-size-adjust: none; -ms-text-size-adjust: none; -webkit-text-size-adjust:none; text-size-adjust:none;">Preview by Yahoo</span></div></td></tr><tr id="yui_3_16_0_1_1443689901807_9013"><td id="yui_3_16_0_1_1443689901807_9012" colspan="2" class="link-enhancr-element" style="height: 9px; background-color: #ffffff; font-size: 0pt; border-collapse: collapse;"><div id="yui_3_16_0_1_1443689901807_9011" class="link-enhancr-element" style="height: 9px; background-color: #ffffff; font-size: 9pt;"></div></td></tr><tr id="yui_3_16_0_1_1443689901807_9311" class="link-enhancr-element"><td id="yui_3_16_0_1_1443689901807_9310" class="link-enhancr-element" colspan="8" style="height: 1px; background-color: #e5e5e5; font-size: 1px; border-collapse: collapse;"><div id="yui_3_16_0_1_1443689901807_9309" class="link-enhancr-element" style="height: 1px; background-color: #e5e5e5; font-size: 1px; line-height:0px">&nbsp;</div></td></tr></tbody></table></div><div id="yui_3_16_0_1_1443689901807_8292"><span></span></div><div id="yui_3_16_0_1_1443689901807_9043" dir="ltr">  I don't know enough to be able to tell if Soot can take advantage of Java variable names in the</div><div id="yui_3_16_0_1_1443689901807_10336" dir="ltr">bytecode whenever they are available for creating Jimple code with Java variable names. It seems<br></div><div id="yui_3_16_0_1_1443689901807_9144" dir="ltr">it might be not too complicated to support this feature in the future if it's not already supported.</div><div id="yui_3_16_0_1_1443689901807_9340" dir="ltr"><br></div><div id="yui_3_16_0_1_1443689901807_9341" dir="ltr">The expression "a * b" in balloon in Eclipse in Figure 5 of the Soot Survivor's Guide</div><div id="yui_3_16_0_1_1443689901807_9509" dir="ltr"> <a id="yui_3_16_0_1_1443689901807_9475" href="http://www.brics.dk/SootGuide/sootsurvivorsguide.pdf">http://www.brics.dk/SootGuide/sootsurvivorsguide.pdf</a> seems to suggest that it is possible</div><div id="yui_3_16_0_1_1443689901807_10067" dir="ltr">to obtain Java variable names for annotating the bytecode. However, as yet I am not able</div><div id="yui_3_16_0_1_1443689901807_10424" dir="ltr">to run Soot's Eclipse plugin and I do not know how Eclipse plugins work.</div><div id="yui_3_16_0_1_1443689901807_10455" dir="ltr"><br></div><div id="yui_3_16_0_1_1443689901807_10425" dir="ltr">Best,</div><div dir="ltr">Andrew<br></div><div id="yui_3_16_0_1_1443689901807_8553" class="qtdSeparateBR"><br></div><div style="display: block;" id="yui_3_16_0_1_1443689901807_8557" class="yahoo_quoted"> <div id="yui_3_16_0_1_1443689901807_8556" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif; font-size: 12px;"> <div id="yui_3_16_0_1_1443689901807_8555" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif; font-size: 16px;"> <div id="yui_3_16_0_1_1443689901807_8554" dir="ltr"> <font id="yui_3_16_0_1_1443689901807_9128" face="Arial" size="2"> On Thursday, 1 October 2015, 8:43, Jason Ott &lt;jott002@ucr.edu&gt; wrote:<br> </font> </div>  <br><br> <div id="yui_3_16_0_1_1443689901807_10543" class="y_msg_container"><div id="yiv5549304000"><div id="yui_3_16_0_1_1443689901807_10542"><div dir="ltr">One last question regarding this topic:<div><br clear="none"></div><div>In the native Java, "getFlashlightEnabled()" looks like this:</div><div><div>public boolean getFlashlightEnabled() {</div><div>&nbsp; &nbsp; try {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; FileInputStream fis = new FileInputStream(FLASHLIGHT_FILE);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; int result = fis.read();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; fis.close();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return (result != '0');</div><div>&nbsp; &nbsp; } catch (Exception e) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div>&nbsp; &nbsp; }</div><div>}</div></div><div><br clear="none"></div><div>Now, I know I can get the value of $r3 without a problem, but is there any way for me to get the *java variable name*(fis) and not the jimple name ($r3)?&nbsp; My gut is no, as that is lost by the jimple conversion.&nbsp; I've looked at baf, shimple, and gimple, and they all seem to lose the Java-based variable name in the conversion.</div><div><br clear="none"></div><div>Thanks,</div><div>Jason</div></div><div class="yiv5549304000yqt7176991372" id="yiv5549304000yqt60282"><div id="yui_3_16_0_1_1443689901807_10541" class="yiv5549304000gmail_extra"><br clear="none"><div id="yui_3_16_0_1_1443689901807_10540" class="yiv5549304000gmail_quote">On Wed, Sep 30, 2015 at 9:25 AM, Jason Ott <span dir="ltr">&lt;<a rel="nofollow" shape="rect" ymailto="mailto:jott002@ucr.edu" target="_blank" href="mailto:jott002@ucr.edu">jott002@ucr.edu</a>&gt;</span> wrote:<br clear="none"><blockquote id="yui_3_16_0_1_1443689901807_10539" class="yiv5549304000gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr">You are correct.&nbsp; Thank you.&nbsp; I'm not sure how I missed that; I have the code that outputs that exact information.</div><div id="yui_3_16_0_1_1443689901807_10538" class="yiv5549304000HOEnZb"><div id="yui_3_16_0_1_1443689901807_10537" class="yiv5549304000h5"><div id="yui_3_16_0_1_1443689901807_10536" class="yiv5549304000gmail_extra"><br clear="none"><div id="yui_3_16_0_1_1443689901807_10535" class="yiv5549304000gmail_quote">On Wed, Sep 30, 2015 at 1:06 AM, Andrew Santosa <span dir="ltr">&lt;<a rel="nofollow" shape="rect" ymailto="mailto:santosa_1999@yahoo.com" target="_blank" href="mailto:santosa_1999@yahoo.com">santosa_1999@yahoo.com</a>&gt;</span> wrote:<br clear="none"><blockquote id="yui_3_16_0_1_1443689901807_10534" class="yiv5549304000gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div id="yui_3_16_0_1_1443689901807_10533"><div id="yui_3_16_0_1_1443689901807_10532" style="color:#000;background-color:#fff;font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:12px;"><div dir="ltr">Given invkExpr of type InvokeExprBox is the invocation expression of the special invocation statement,<br clear="none"></div><div dir="ltr">we can obtain the list of use boxes within the expression in the following way:</div><div dir="ltr"><br clear="none"></div><div dir="ltr">List&lt;ValueBox&gt; boxesList = invkExpr.getValue().getUseBoxes();</div><div dir="ltr"><br clear="none"></div><div dir="ltr">One of the boxes in boxesList should be the local that you want.</div><div dir="ltr"><br clear="none"></div><div dir="ltr">Best,<br clear="none"></div><div dir="ltr">Andrew<br clear="none"></div><div><span></span></div>  <br clear="none"><div id="yui_3_16_0_1_1443689901807_10531"><br clear="none"><br clear="none"></div><div style="display:block;"> <div style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:12px;"> <div style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:16px;"><div><div> <div dir="ltr"> <font face="Arial" size="2"> On Wednesday, 30 September 2015, 10:38, Jason Ott &lt;<a rel="nofollow" shape="rect" ymailto="mailto:jott002@ucr.edu" target="_blank" href="mailto:jott002@ucr.edu">jott002@ucr.edu</a>&gt; wrote:<br clear="none"> </font> </div>  <br clear="none"><br clear="none"> </div></div><div><div><div><div><div dir="ltr">I have the following Jimple:<div><div><br clear="none"></div><div>&nbsp;public boolean getFlashlightEnabled()</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; com.android.server.lights.LightsService$1 r0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; int i0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; java.io.FileInputStream $r1, r3; // I'm interested in this</div><div>&nbsp; &nbsp; &nbsp; &nbsp; java.lang.Exception $r2;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; boolean $z0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; r0 := @this: com.android.server.lights.LightsService$1;</div><div>&nbsp; &nbsp; &nbsp;label1:</div><div>&nbsp; &nbsp; &nbsp; &nbsp; $r1 = new java.io.FileInputStream;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; specialinvoke $r1.&lt;java.io.FileInputStream: void &lt;init&gt;(java.lang.String)&gt;("/sys/class/leds/spotlight/brightness"); &nbsp;// But my interest in $r1 and r3 are predicated upon this</div><div>&nbsp; &nbsp; &nbsp; &nbsp; r3 = $r1;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; i0 = virtualinvoke r3.&lt;java.io.FileInputStream: int read()&gt;();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; virtualinvoke r3.&lt;java.io.FileInputStream: void close()&gt;();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if i0 == 48 goto label2;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; $z0 = 1;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; goto label3;</div><div>&nbsp; &nbsp; &nbsp;label2:</div><div>&nbsp; &nbsp; &nbsp; &nbsp; $z0 = 0;</div><div>&nbsp; &nbsp; &nbsp;label3:</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return $z0;</div><div>&nbsp; &nbsp; &nbsp;label4:</div><div>&nbsp; &nbsp; &nbsp; &nbsp; $r2 := @caughtexception;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return 0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; catch java.lang.Exception from label1 to label3 with label4;</div><div>&nbsp; &nbsp; }</div></div><div><br clear="none"></div><div>You can see that I am interested in the variable that, in some way or another, uses the "/sys/class/leds/spotlight/brightness" string.&nbsp; Thus, I am interested in the variable $r1.&nbsp; But I don't know that I'm interested in $r1 until I see that $r1 is using the string that I am interested.</div><div><br clear="none"></div><div>Now I know that $r1 is a local, more specifically a LinkedRValueBox.&nbsp; I know that the string, "/sys/class/..." is an ImmediateBox, which is leveraged in an InvokeExprBox (specialinvoke $r1...).&nbsp; What I cannot seem to manage to figure out is how to derive the Local $r1 variable from either the InvokeExprBox or the ImmediateBox.&nbsp; Neither of them have any formal link to $r1 (a Local) other than by parsing the string representation of them and then going through the Locals looking for what you want.</div><div><br clear="none"></div><div>So my question is: Is there a way to get the Local from the InvokeExprBox or the ImmediateBox in this case, or the general case?&nbsp; I can only get ValueBoxes from anything which is of ValueBox, as defined by the ValueBox interface.</div><div><br clear="none"></div><div>Thanks.</div></div></div><br clear="none"></div></div>_______________________________________________<br clear="none">Soot-list mailing list<br clear="none"><a rel="nofollow" shape="rect" ymailto="mailto:Soot-list@CS.McGill.CA" target="_blank" href="mailto:Soot-list@CS.McGill.CA">Soot-list@CS.McGill.CA</a><br clear="none"><a rel="nofollow" shape="rect" target="_blank" href="https://mailman.cs.mcgill.ca/mailman/listinfo/soot-list">https://mailman.CS.McGill.CA/mailman/listinfo/soot-list</a><br clear="none"><br clear="none"><br clear="none"></div>  </div> </div>  </div></div></div></blockquote></div><br clear="none"></div>
</div></div></blockquote></div><br clear="none"></div></div></div></div><br><br></div>  </div> </div>  </div></div></body></html>