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

时间:2019-03-18 22:27:53

标签: python binary decode adventure

我敢肯定,你们中的许多人都知道1976年的游戏Colossal Cave Adventure。我在Mac上下载了它,它允许您保存进度,并将其保存在.adv文件中,您可以打开该文件并从上次中断的地方继续游戏。我在TextEdit中打开了它(将其更改为.txt文件),它看起来像一堆乱七八糟的上帝编码文本,知道什么语言。我附了图片

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

以及Google驱动器上指向.txt文件的链接

https://drive.google.com/file/d/1Ku4QO4cpx61X8mS9bBgGK3AyViczczNl/view?usp=sharing 出于某种原因,谷歌驱动器预览看起来像中文或其他语言,但是如果您下载.txt,则会看到它与igmur图片相同。

我使用以下命令通过python运行了文件: import io with io.open(filename, 'rb') as f: text = f.read()

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

仅是一个示例(单击上面的链接即可查看完整文件): 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

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

我尝试了多种解码方式,但都失败了。我需要将其解码为可读的内容。我该怎么办?它用什么“文本语言”?

谢谢

1 个答案:

答案 0 :(得分:1)

没有什么比经典游戏中的骇客和戳戳更重要了。

哪个版本?原始文件以Fortran编写,并在PDP-11上运行。所以,那不是您所拥有的。

也许您拥有最新的OSS? https://gitlab.com/esr/open-adventure

因此,您需要查看游戏的特定实现,并获取其用于保存游戏状态的数据结构。

这是您想要做的:

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

这将运行游戏并将您放置在其中。

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

那是二进制的。所以我们去追寻游戏的源头。

saveresume.c是一个很好的起点。

我们在struct game_t游戏代码中找到了对suspend()的引用。该结构在advent.h

中定义

它看起来像:

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 */
};

这就是文件中的内容。玩游戏C代码,并使用暂停/恢复功能加载保存的文件并对其进行破解,以使自己喝醉了!