[Scummvm-cvs-logs] SF.net SVN: scummvm:[51449] tools/branches/gsoc2010-decompiler/decompiler
pidgeot at users.sourceforge.net
pidgeot at users.sourceforge.net
Thu Jul 29 01:24:35 CEST 2010
Revision: 51449
http://scummvm.svn.sourceforge.net/scummvm/?rev=51449&view=rev
Author: pidgeot
Date: 2010-07-28 23:24:35 +0000 (Wed, 28 Jul 2010)
Log Message:
-----------
Add TEXT chunk reading to KYRA disassembler
Also remove constness from Engine::getDisassembler to allow storing
metadata (e.g. strings) in Engine class during disassembly.
Modified Paths:
--------------
tools/branches/gsoc2010-decompiler/decompiler/engine.h
tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp
tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.h
tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.cpp
tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.h
tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp
tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h
Modified: tools/branches/gsoc2010-decompiler/decompiler/engine.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/engine.h 2010-07-28 23:21:27 UTC (rev 51448)
+++ tools/branches/gsoc2010-decompiler/decompiler/engine.h 2010-07-28 23:24:35 UTC (rev 51449)
@@ -38,7 +38,7 @@
*
* @return Pointer to a Disassembler for the engine.
*/
- virtual Disassembler *getDisassembler() const = 0;
+ virtual Disassembler *getDisassembler() = 0;
/**
* Decode a jump instruction to get the destination address.
Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp 2010-07-28 23:21:27 UTC (rev 51448)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp 2010-07-28 23:24:35 UTC (rev 51449)
@@ -21,6 +21,7 @@
*/
#include "disassembler.h"
+#include "engine.h"
#include <iostream>
#include <boost/format.hpp>
@@ -28,6 +29,9 @@
_data = NULL;
}
+Kyra::Disassembler::Disassembler(Engine *engine) : _engine(engine) {
+}
+
Kyra::Disassembler::~Disassembler() {
if (_textChunk._data)
delete[] _textChunk._data;
@@ -52,7 +56,7 @@
return;
}
- // Read chunks
+ // Read chunks into memory
do {
IFFChunk temp;
temp._chunkType = _f.readUint32BE();
@@ -74,10 +78,26 @@
delete [] temp._data;
return;
}
- if (temp._size % 2 != 0) // skip padding byte
+ if (temp._size % 2 != 0) // Skip padding byte
_f.readByte();
} while (_f.pos() != (int)_f.size());
+ // Extract strings from TEXT chunk
+ uint16 minTextOffset = 0xFFFF;
+ for (uint16 i = 0; i < _textChunk._size / 2; ++i) {
+ if (minTextOffset > READ_BE_UINT16(&((uint16 *)_textChunk._data)[i])) {
+ minTextOffset = READ_BE_UINT16(&((uint16 *)_textChunk._data)[i]);
+ }
+ if (minTextOffset <= i*2)
+ break;
+ }
+ uint16 numStrings = minTextOffset / 2;
+#define posString(x) (char*)&_textChunk._data[READ_BE_UINT16(&((uint16 *)_textChunk._data)[(x)])]
+ for (uint16 i = 0; i < numStrings; ++i) {
+ _engine->_textStrings.push_back(posString(i));
+ }
+#undef posString
+
// Disassemble
// TODO
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.h 2010-07-28 23:21:27 UTC (rev 51448)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.h 2010-07-28 23:24:35 UTC (rev 51449)
@@ -28,27 +28,42 @@
typedef uint32 IFF_ID;
+/**
+ * Container for a chunk from an IFF file.
+ */
struct IFFChunk {
public:
- IFF_ID _chunkType;
- uint32 _size;
- uint8 *_data;
+ IFF_ID _chunkType; ///< Type of chunk, as specified by its magic number in the IFF file.
+ uint32 _size; ///< The size of the chunk contents.
+ uint8 *_data; ///< Pointer to the data in the chunk.
+ /**
+ * Default constructor for IFFChunk.
+ */
IFFChunk();
};
namespace Kyra {
+class Engine;
+
/**
* Disassembler for KYRA.
*/
class Disassembler : public ::Disassembler {
private:
- IFF_ID _formType; ///< File type as listed in the IFF formatted file.
- IFFChunk _textChunk; ///< Contents of the TEXT chunk.
- IFFChunk _ordrChunk; ///< Contents of the ORDR chunk.
- IFFChunk _dataChunk; ///< Contents of the DATA chunk.
+ IFF_ID _formType; ///< File type as listed in the IFF formatted file.
+ IFFChunk _textChunk; ///< Contents of the TEXT chunk.
+ IFFChunk _ordrChunk; ///< Contents of the ORDR chunk.
+ IFFChunk _dataChunk; ///< Contents of the DATA chunk.
+ Engine *_engine; ///< Pointer to the Kyra::Engine used for this script.
public:
+ /**
+ * Constructor for Disassembler.
+ *
+ * @param engine Pointer to the Kyra::Engine used for this script.
+ */
+ Disassembler(Engine *engine);
~Disassembler();
void doDisassemble() throw(UnknownOpcodeException);
};
Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.cpp 2010-07-28 23:21:27 UTC (rev 51448)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.cpp 2010-07-28 23:24:35 UTC (rev 51449)
@@ -23,8 +23,8 @@
#include "engine.h"
#include "disassembler.h"
-::Disassembler *Kyra::Engine::getDisassembler() const {
- return new Disassembler();
+::Disassembler *Kyra::Engine::getDisassembler() {
+ return new Disassembler(this);
}
uint32 Kyra::Engine::getDestAddress(ConstInstIterator it) const {
Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.h 2010-07-28 23:21:27 UTC (rev 51448)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/engine.h 2010-07-28 23:24:35 UTC (rev 51449)
@@ -25,6 +25,9 @@
#include "decompiler/engine.h"
+#include <string>
+#include <vector>
+
namespace Kyra {
/**
@@ -32,11 +35,13 @@
*/
class Engine : public ::Engine {
public:
- ::Disassembler *getDisassembler() const;
+ ::Disassembler *getDisassembler();
uint32 getDestAddress(ConstInstIterator it) const;
::CodeGenerator *getCodeGenerator(std::ostream &output);
bool supportsCodeFlow() { return false; }
bool supportsCodeGen() { return false; }
+
+ std::vector<std::string> _textStrings;
};
} // End of namespace KYRA
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp 2010-07-28 23:21:27 UTC (rev 51448)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.cpp 2010-07-28 23:24:35 UTC (rev 51449)
@@ -24,7 +24,7 @@
#include "disassembler.h"
#include "codegen.h"
-::Disassembler *Scumm::v6::Engine::getDisassembler() const {
+::Disassembler *Scumm::v6::Engine::getDisassembler() {
return new Disassembler();
}
Modified: tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h 2010-07-28 23:21:27 UTC (rev 51448)
+++ tools/branches/gsoc2010-decompiler/decompiler/scummv6/engine.h 2010-07-28 23:24:35 UTC (rev 51449)
@@ -34,7 +34,7 @@
*/
class Engine : public ::Engine {
public:
- ::Disassembler *getDisassembler() const;
+ ::Disassembler *getDisassembler();
uint32 getDestAddress(ConstInstIterator it) const;
::CodeGenerator *getCodeGenerator(std::ostream &output);
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list