在xvi32中扫描.o文件

时间:2012-05-04 21:18:08

标签: c++ hex bit

有人可以解释this hexadecimal view of the .o file in xvi32 对应于.cpp中的数据?即'/ 18'/ 65'/ 139和“.rdata”这样的数字是什么意思? 当我打开相应的exe例如,然后我看到文件非常相似,略有不同,至少从这开始。但特别是:为什么在exe中这个“.rdata”变成“.data”? 这里是创建.o的.cpp:

    // exercise_for.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <list>
#include <map>

#include <iterator>
#include <algorithm>
#include <fstream>

#include <limits>

struct myStruct{
    int a;
    double b;
    virtual void func()=0;
    void f(){};
};
struct sB{virtual void g()=0;};
struct myStruct2:sB{
    void f(){};
    void g(){std::cout<<"\nmyStruct2";}
};
struct myStruct3:sB{
    void f(int const &in){a=in;};
    void g(){std::cout<<"\nmyStruct3";};
    myStruct3():a(0){};
    int show(){return a;};
private:
    int a;
};

class myC : public myStruct{
    int i;
    void func(){};
};

std::map<std::string,int> histogram;
void record(const std::string& in ){
    histogram[in]++;
}
void print(const std::pair<const std::string,int>& in ){
    std::cout<<(in.first)<<" "<<in.second<<"\n";
}

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout<<"largest float:"<<std::numeric_limits<float>::max()<<
        "\nchar is signed:"<<std::numeric_limits<char>::is_signed<<
        "\nlargest int:"<<std::numeric_limits<int>::max()<<
        "\nlargest double:"<<std::numeric_limits<double>::max()<<
        "\nlargest short int:"<<std::numeric_limits<short int>::max()<<
        "\nlargest long int:"<<std::numeric_limits<long int>::max()<<"\n\n";

    for(int i=0;i<10;++i){
        std::cout<<++i;
    }

    myC mC;
    myStruct2 m;
    myStruct3 n;
    std::cout<<"n: "<<n.show();
    m.f();
    n.f(4);
    std::cout<<"\nn: "<<n.show();

    std::cout<<"\nmem_fun";
    std::list<sB*> myList;
    myList.push_back(&m);
    myList.push_back(&n);
    std::for_each(myList.begin(),myList.end(),std::mem_fun(&sB::g));
    std::list<sB*>::iterator it=myList.begin(); 

    std::istream_iterator<std::string> ii(std::cin);
    std::istream_iterator<std::string> eos;
    std::for_each(ii,eos,record);
    int i=0xffff;
    std::string z;
    std::cout<<"\n\nprinting: sizeof(int)="<<sizeof(int)<<"  i:"<<i<<"\n";
    int* i_ptr;
    std::cout<<"sizeof(int*)="<<sizeof(i_ptr)<<"\n";
    std::cout<<"sizeof(double)="<<sizeof(double)<<"\n";
    std::cout<<"sizeof(double*)="<<sizeof(double*)<<"\n";
    std::cout<<"sizeof(string)="<<sizeof(z)<<"\n";
    float fl=1000+1.6+1.6+1.6+1.6;
    std::cout<<"\nf:"<<fl;
    std::for_each(histogram.begin(),histogram.end(),print);

    std::vector<std::string> sL;
    std::string s("spadaj");
    sL.push_back(s);
    std::copy(sL.begin(),sL.end(),std::ostream_iterator<std::string>(std::cout, " "));
    std::ofstream f("myFile.txt"); 
    std::copy(sL.begin(),sL.end(),std::ostream_iterator<std::string>(f, " "));
    return 0;
}

1 个答案:

答案 0 :(得分:1)

这有点像看着一个汉堡包,并问“这头牛的哪一部分来自哪里?”给定的汉堡包含三到四只不同奶牛的六个不同部位的肉。

为了获得更多功能,您可能希望从比目标文件(或可执行文件)的普通十六进制转储更智能的东西开始。您可能希望使用反汇编程序,至少可以让您在输出中或多或少地直接看作汇编语言源代码。如果没有这个,你需要对目标文件格式有一些相当深入的了解,甚至知道要真正查看哪些部分,哪些部分是重定位记录,或者甚至可能只是部分之间的填充(即,完全没有意义)。显然可以这样做,但除非你别无选择,否则花费你的时间很少是一种令人满意的方式。

它不是最好的反汇编程序(无论如何),但Microsoft Windows SDK包含一个名为dumpbin的工具,可以使用/disasm标志反汇编可执行文件中的代码。如果你做一些环顾四周,还有其他各种反汇编程序。如果你愿意花一些钱,我建议IDA Pro作为我用过的最好的。这绝对不是免费,甚至特别便宜,但如果你打算这么做,那就值得每一分钱。