Extract global variables from a.out file

心不动则不痛 提交于 2019-11-29 04:06:00

Here is what I will do. Why reinvent the wheel!

  1. Download linux commands that will be needing on windows from here.

    on the bin directory there should be: readelf.exe

    Note we will not need Cygwin or any program so deploying will be simple!

  2. Once we have that file execute in cmd:

    // cd "path where readelf.exe is"
    readelf.exe -s a.out
    

    and this is the list that will come out:

    so if you take a look we are interested in getting all the variables that are of type OBJECT with size greater than 0.

  3. Once we got the variables we can use the readelf.exe -w a.out command to take a look at the tree and it looks like:

    let's start looking for one of the variable we found on step 2 (SOME_GREAT_COUNTER) Note that at the top we know the location where the variable is being declared, we got more information such as the line where it was declared and the memory address
  4. The last thing we are missing to do is to get the type. if you take a look we see that the type is = <0x522>. What that means is that we have to go to 522 of the tree to get more info about that time. If we go to that part this is what we get:

    From looking at the tree we know that SOME_LARGE_VARIABLE is of type unsigned long
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!