C++使用文件格式

发布于 2024-09-29 02:01:11 字数 347 浏览 4 评论 0原文

几天前,我问如何对文件格式进行逆向工程。虽然这并没有真正解决问题,但有人给了我文件格式。 (单击此处)谢谢 Xadet。

我对这一切还很陌生,我想知道我应该从这里去哪里。我猜我必须在 C++ 中使用 inline-asm 才能使用这种格式,但我不知道如何使用它实际打开文件,或将数据插入其中。

那么问题是,如何使用文件格式来获取或插入数据?而且文件格式看起来像asm,但我不想以纯ASM开始编程。我以前见过人们用 C++ 编程 asm,这就是为什么我认为这将是一个不错的选择

任何帮助将不胜感激。

A couple of days ago, I asked how you could reverse engineer a file format. While that didn't really work out, someone gave me the file format. (Click Here) Thank you Xadet.

I'm still quite new to all this, and I was wondering where I should go from here. I am guessing I will have to use inline-asm in C++ to use this format, but I wouldn't know how to actually open the file using this, or insert data into it.

So the question would be, how do I use the file format to get or insert data? And the file format looks like asm, but I don't want to start programming in pure ASM. I've seen people programming asm in C++ before, that's why I think it would be a good choice

Any help would be greatly apreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

宁愿没拥抱 2024-10-06 02:01:11

文件格式描述看起来不像asm,它看起来像伪代码。

The file format description doesn't look like asm, it looks like pseudocode.

盗梦空间 2024-10-06 02:01:11

我假设您不希望 C++ 程序在启动时读取该文件格式文档,然后在此基础上解析实际的数据文件。相反,您只想要一个专门用于读取该文件格式的当前版本的 C++ 程序? (这更简单并且运行速度更快)。您不需要使用 ASM。您需要做的是计算出与格式文件中使用的名称等效的 C++ 类型。例如,我认为 Microsoft 语言中使用 DWORD 来指代特定大小的整数 - 可能是 32 或 64 位。跟踪这些内容,然后创建具有等效成员的 C++ 结构。

例如:

#include <inttypes.h> // if on Windows, try __int32, __int64 etc. instead

typedef int64_t DWORD;  // or whatever width you find it's meant to be
typedef int32_t WORD;
typedef ??? ZSTR;  // google it...?
typedef float FLOAT;

struct dds
{
    ZSTR path;
    WORD is_skin;
    WORD alpha_enabled;
    WORD two_sided;
    WORD alpha_test_enabled;
    WORD alpha_ref;
    WORD z_write_enabled;
    WORD z_test_enabled;
    WORD blending_mode; // None = 0, Custom = 1, Normal = 2, Lighten = 3
    WORD specular_enabled;
    FLOAT alpha;
    WORD glow_type; // None = 0, NotSet = 1, Simple = 2, Light = 3, Texture = 4, TextureLight = 5, Alpha = 6
    FLOAT red;
    FLOAT green;
    FLOAT blue;
};

// point p at the entire input, which you'll have loaded into memory somewhere
// (e.g. f/stat() the file size then allocate heap and read into it, or memory map)
const char* p = input;
DWORD mesh_count = *(const DWORD*)p;
p += sizeof(DWORD);
for (int i = 0; i < mesh_count; ++i)
{
    const dds& d = *(const dds*)p;
    // you can use d.red, d.alpha etc. here to do anything you like
    p += sizeof dds;
}

// continue processing effect count etc... in same style

HTH、
托尼

I assume you don't want to have a C++ program that reads that file format document when it starts, then parses the actual data file on that basis. Instead, you just want a C++ program dedicated to reading the current version of that file format? (This is much simpler and will run faster). You don't need to use ASM. What you do need to do is work out the C++ types that are equivalent to the names used in the format file. For example, I think DWORD is used in Microsoft languages to refer to an integer of a specific size - maybe 32 or 64 bits. Track that stuff down, then create C++ structs with equivalent members.

For example:

#include <inttypes.h> // if on Windows, try __int32, __int64 etc. instead

typedef int64_t DWORD;  // or whatever width you find it's meant to be
typedef int32_t WORD;
typedef ??? ZSTR;  // google it...?
typedef float FLOAT;

struct dds
{
    ZSTR path;
    WORD is_skin;
    WORD alpha_enabled;
    WORD two_sided;
    WORD alpha_test_enabled;
    WORD alpha_ref;
    WORD z_write_enabled;
    WORD z_test_enabled;
    WORD blending_mode; // None = 0, Custom = 1, Normal = 2, Lighten = 3
    WORD specular_enabled;
    FLOAT alpha;
    WORD glow_type; // None = 0, NotSet = 1, Simple = 2, Light = 3, Texture = 4, TextureLight = 5, Alpha = 6
    FLOAT red;
    FLOAT green;
    FLOAT blue;
};

// point p at the entire input, which you'll have loaded into memory somewhere
// (e.g. f/stat() the file size then allocate heap and read into it, or memory map)
const char* p = input;
DWORD mesh_count = *(const DWORD*)p;
p += sizeof(DWORD);
for (int i = 0; i < mesh_count; ++i)
{
    const dds& d = *(const dds*)p;
    // you can use d.red, d.alpha etc. here to do anything you like
    p += sizeof dds;
}

// continue processing effect count etc... in same style

HTH,
Tony

神魇的王 2024-10-06 02:01:11

它是一种用于定义数据格式的脚本语言,类似于 XDR
您只需为其编写一个解析器(不要尝试在运行时使用该脚本)。编写一些函数,例如 get_WORD_BE()get_DWORD_LE() 等,这样您就不会依赖于字节序。

是的,如果您想使用 Tony 的方法,请添加一些 #pragma pack(1)

It's a kind of scripting language for defining data format, something similar to XDR.
You just have to write a parser for it (don't try to use the script in the runtime). Write some functions like get_WORD_BE() or get_DWORD_LE(), etc so that you don't depend on endiannes.

Yes, and if you want to use Tony's approach, add some #pragma pack(1).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文