gpt4 book ai didi

c++ - 在 xvi32 中扫描 .o 文件

转载 作者:行者123 更新时间:2023-11-28 08:04:59 24 4
gpt4 key购买 nike

谁能解释一下 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;
}

最佳答案

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

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

它不是最好的反汇编程序(无论如何),但 Microsoft Windows SDK 包含一个名为 dumpbin 的工具,它可以使用 /disasm 标志反汇编可执行文件中的代码.如果您四处看看,还有各种其他反汇编程序可用。如果你愿意花点钱,我推荐IDA Pro作为我用过的最好的。它绝对不是免费的,甚至不是特别便宜,但如果您要这样做的话,每一分钱都是值得的。

关于c++ - 在 xvi32 中扫描 .o 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10456258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com