简体   繁体   English

巨大的洞穴冒险文件:从二进制 (?) 解码为可读格式 (Python)

[英]Colossal Cave Adventure File: Decode From Binary (?) to readable format (Python)

I'm sure many of you guys know about the 1976 game Colossal Cave Adventure.我相信你们很多人都知道 1976 年的游戏 Colossal Cave Adventure。 I downloaded it on my Mac, and it allows you to save your progress, and it saves it in a .adv file which you can open up and resume your game where you left off.我在 Mac 上下载了它,它允许您保存进度,并将其保存在一个 .adv 文件中,您可以打开该文件并从上次中断的地方继续您的游戏。 I opened it up in TextEdit (changed it to a .txt file) and it looks like a whole mess of encoded text of God-knows what language.我在 TextEdit 中打开它(将其更改为 .txt 文件),它看起来像是天知道是什么语言的编码文本。 I attached a picture我附上了一张图片

https://i.stack.imgur.com/RkBlb.png https://i.stack.imgur.com/RkBlb.png

as well as a link on google drive to the .txt file以及谷歌驱动器上指向 .txt 文件的链接

https://drive.google.com/file/d/1Ku4QO4cpx61X8mS9bBgGK3AyViczczNl/view?usp=sharing For some reason the google drive preview looks like Chinese or some other language, but if you download the .txt you will see it's the same thing as the igmur picture. https://drive.google.com/file/d/1Ku4QO4cpx61X8mS9bBgGK3AyViczczNl/view?usp=sharing出于某种原因,谷歌驱动器预览看起来像中文或其他语言,但如果你下载 .txt 你会看到它是一样的如igmur图片。

I ran the file through python using this: import io with io.open(filename, 'rb') as f: text = f.read()我使用这个通过 python 运行文件: import io with io.open(filename, 'rb') as f: text = f.read()

And text gave me this: https://drive.google.com/file/d/1KyjdPxUDkBy5ATZfg1GdIexeP9nK-Km6/view?usp=sharing text给了我这个: https : //drive.google.com/file/d/1KyjdPxUDkBy5ATZfg1GdIexeP9nK-Km6/view?usp=sharing

Just a sample of it (click on above link to see full file): b'\\xc1\\xdfd\\x00\\x84K\\xfd\\xcb\\xff\\x93\\xcb\\xf9\\x90\\\\xa9\\xd5\\xdb\\x10\\xaf\\xdb\\xb5{_\\xd1\\xf9\\xcaw\\xd2\\xc13\\x8e\\xd1\\xd6\\x06\\xce\\xe3V\\xd0\\xa8只是它的一个示例(单击上面的链接查看完整文件): b'\\xc1\\xdfd\\x00\\x84K\\xfd\\xcb\\xff\\x93\\xcb\\xf9\\x90\\\\xa9\\xd5\\xdb\\x10\\ xaf\\xdb\\xb5{_\\xd1\\xf9\\xcaw\\xd2\\xc13\\x8e\\xd1\\xd6\\x06\\xce\\xe3V\\xd0\\xa8

Trying to decode it in Python gave me this error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc1 in position 0: invalid start byte尝试在 Python 中解码它给了我这个错误: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc1 in position 0: invalid start byte

I tried decoding it many many ways and they all failed.我尝试了很多方法来解码它,但都失败了。 I need to decode this into something readable.我需要将其解码为可读的内容。 How do I, and what "text language" is it in?我如何,它是什么“文本语言”?

Thanks谢谢

Nothing like hacking and poking around on classic games.没有什么比在经典游戏中进行黑客攻击和闲逛更合适的了。

Which version?哪个版本? The original, is written in Fortran and ran on a PDP-11.原始版本是用 Fortran 编写的,并在 PDP-11 上运行。 So, that isn't the one you've got.所以,那不是你所拥有的。

Perhaps you have the latest OSS one?也许你有最新的OSS? https://gitlab.com/esr/open-adventure https://gitlab.com/esr/open-adventure

So, you need to look at the specific implementation of the game, and grab the data structures it uses to save out the game state.因此,您需要查看游戏的具体实现,并获取它用于保存游戏状态的数据结构。

This is what you want to do:这是你想要做的:

git clone https://gitlab.com/esr/open-adventure.git open-adventure
make
./advent

This runs game and places you in it.这将运行游戏并将您置于其中。

Welcome to Adventure!!  Would you like instructions?

> no

You are standing at the end of a road before a small brick building.
Around you is a forest.  A small stream flows out of the building and
down a gully.

> save

I can suspend your Adventure for you so that you can resume later, but
it will cost you 5 points.

Is this acceptable?

> yes

OK

File name: saved_game

Richs-MBP:open-adventure randrews$ ls -l saved_game 
-rw-r--r--  1 randrews  staff  3192 Mar 18 19:11 saved_game
Richs-MBP:open-adventure randrews$ file saved_game
saved_game: data
Richs-MBP:open-adventure randrews$ strings saved_game
E'HTH

That's binary alright.那是二进制好吧。 So we go after the game source.所以我们去寻找游戏源。

saveresume.c is a great place to start. saveresume.c是一个很好的起点。

Within we find a reference to struct game_t in the code that suspend() s the game.我们在游戏suspend()的代码中找到了对struct game_t的引用。 And that struct is defined in advent.h该结构在advent.h定义

It looks like:看起来像:

struct game_t {
    int32_t lcg_x;
    int abbnum;                  // How often to print int descriptions
    score_t bonus;               // What kind of finishing bonus we are getting
    loc_t chloc;                 // pirate chest location
    loc_t chloc2;                // pirate chest alternate location
    turn_t clock1;               // # turns from finding last treasure to close
    turn_t clock2;               // # turns from warning till blinding flash
    bool clshnt;                 // has player read the clue in the endgame?
    bool closed;                 // whether we're all the way closed
    bool closng;                 // whether it's closing time yet
    bool lmwarn;                 // has player been warned about lamp going dim?
    bool novice;                 // asked for instructions at start-up?
    bool panic;                  // has player found out he's trapped?
    bool wzdark;                 // whether the loc he's leaving was dark
    bool blooded;                // has player drunk of dragon's blood?
... it is big! ...
    obj_t link[NOBJECTS * 2 + 1];// object-list links
    loc_t place[NOBJECTS + 1];   // location of object
    int hinted[NHINTS];          // hinted[i] = true iff hint i has been used.
    int hintlc[NHINTS];          // hintlc[i] = how int at LOC with cond bit i
    int prop[NOBJECTS + 1];      // object state array */
};

And that's what's in your file.这就是您的文件中的内容。 Have fun taking the game C code and using the suspend/resume functions to load your saved file and hack it so that you have drunk of dragons blood!玩得开心玩游戏 C 代码并使用挂起/恢复功能加载您保存的文件并破解它,以便您喝龙血!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM