mirror of
https://github.com/sfall-team/int2ssl.git
synced 2026-07-27 16:52:42 -07:00
initial commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build (by default Debug)")
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(int2ssl)
|
||||
|
||||
set(SOURCES main.cpp
|
||||
Hacks/Types.h
|
||||
Hacks/CString.h
|
||||
Hacks/CString.cpp
|
||||
Hacks/CArray.h
|
||||
Hacks/CArray.cpp
|
||||
Hacks/CArchive.h
|
||||
Hacks/CArchive.cpp
|
||||
Hacks/CFile.h
|
||||
Hacks/CFile.cpp
|
||||
Hacks/CMap.h
|
||||
Hacks/CMap.cpp
|
||||
FalloutScript.h
|
||||
Namespace.h
|
||||
Node.h
|
||||
ObjectAttributes.h
|
||||
Opcode.h
|
||||
ProcTable.h
|
||||
StartupCode.h
|
||||
stdafx.h
|
||||
Utility.h
|
||||
XGetopt.h
|
||||
FalloutScript.cpp
|
||||
FalloutScriptDecompile.cpp
|
||||
FalloutScriptDefObject.cpp
|
||||
FalloutScriptDump.cpp
|
||||
FalloutScriptStore.cpp
|
||||
Namespace.cpp
|
||||
Node.cpp
|
||||
OpcodeAttributes.cpp
|
||||
Opcode.cpp
|
||||
ProcTable.cpp
|
||||
StartupCode.cpp
|
||||
stdafx.cpp
|
||||
Utility.cpp
|
||||
XGetopt.cpp
|
||||
)
|
||||
|
||||
add_definitions (-std=c++11 -Wall)
|
||||
|
||||
add_executable(int2ssl ${SOURCES})
|
||||
#target_link_libraries(int2ssl)
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
// FalloutScript.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "FalloutScript.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// Constants
|
||||
//c_strBogusProcedureName = "..............";
|
||||
//c_strArgumentTemplate = "arg%u";
|
||||
//c_strGlobalVarTemplate = "GVar%u";
|
||||
//c_strLocalVarTemplate = "LVar%u";
|
||||
|
||||
|
||||
// CFalloutScript
|
||||
|
||||
CFalloutScript::CFalloutScript()
|
||||
{
|
||||
}
|
||||
|
||||
CFalloutScript::~CFalloutScript()
|
||||
{
|
||||
}
|
||||
|
||||
void CFalloutScript::Serialize(CArchive& ar)
|
||||
{
|
||||
|
||||
//if (ar.IsStoring()) {
|
||||
if (false)
|
||||
{
|
||||
// ASSERT(FALSE);
|
||||
}
|
||||
else {
|
||||
printf(" Read strtup code\n");
|
||||
m_StartupCode.Serialize(ar);
|
||||
|
||||
printf(" Read procedures table\n");
|
||||
m_ProcTable.Serialize(ar);
|
||||
|
||||
printf(" Read namespace\n");
|
||||
m_Namespace.Serialize(ar);
|
||||
|
||||
printf(" Read stringspace\n");
|
||||
m_Stringspace.Serialize(ar);
|
||||
|
||||
COpcode opcode;
|
||||
|
||||
printf(" Read tail of startup code\n");
|
||||
opcode.Expect(ar, COpcode::O_SET_GLOBAL);
|
||||
|
||||
// Sections with variable sizes
|
||||
ar.Flush();
|
||||
ULONG ullCurrentOffset = ar.GetFile()->GetPosition();
|
||||
|
||||
// Load globals
|
||||
m_GlobalVar.RemoveAll();
|
||||
m_ExportedVar.RemoveAll();
|
||||
m_ExportedVarValue.RemoveAll();
|
||||
m_ExportedProc.RemoveAll();
|
||||
|
||||
COpcodeArray HeaderTail;
|
||||
|
||||
while(ullCurrentOffset < m_ProcTable.GetOffsetOfProcSection()) {
|
||||
opcode.Serialize(ar);
|
||||
ullCurrentOffset += opcode.GetSize();
|
||||
HeaderTail.Add(opcode);
|
||||
}
|
||||
|
||||
// Jump to 'start' procedure
|
||||
printf(" Check \"Jump to \'start\' procedure\" / \"Jump to end of statup code\"\n");
|
||||
|
||||
if (!HeaderTail.IsEmpty()) {
|
||||
INT_PTR nIndexOfStart = GetIndexOfProc("start");
|
||||
ULONG ulStartProcAddress = (nIndexOfStart != -1) ? m_ProcTable[nIndexOfStart].m_ulBodyOffset : 18;
|
||||
|
||||
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
||||
|
||||
if (opcode.GetOperator() == COpcode::O_JMP) {
|
||||
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
||||
|
||||
if (HeaderTail.IsEmpty()) {
|
||||
printf("\n");
|
||||
printf("Warning: Omitted address of jump\n");
|
||||
printf("\n");
|
||||
}
|
||||
else {
|
||||
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
||||
|
||||
if (opcode.GetOperator() == COpcode::O_INTOP) {
|
||||
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
||||
|
||||
if (opcode.GetArgument() != ulStartProcAddress) {
|
||||
printf("\n");
|
||||
printf("Warning: Invalid jump address\n");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\n");
|
||||
printf("Warning: Invalid opcode for jump addres\n");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\n");
|
||||
printf("Warning: Omitted \"Jump to \'start\' procedure\" / \"Jump to end of statup code\"\n");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// # of argument to 'start' procedure
|
||||
printf(" Check \"# of argument to \'start\' procedure\"\n");
|
||||
|
||||
CString strNumOfArgsWarning("Warning: Omitted \"# of argument to \'start\' procedure\"\n");
|
||||
|
||||
if (!HeaderTail.IsEmpty()) {
|
||||
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
||||
|
||||
if (opcode.GetOperator() == COpcode::O_CRITICAL_DONE) {
|
||||
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
||||
|
||||
if (!HeaderTail.IsEmpty()) {
|
||||
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
||||
|
||||
if (opcode.HasArgument()) {
|
||||
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
||||
}
|
||||
else {
|
||||
printf("\n");
|
||||
printf("%s", strNumOfArgsWarning.c_str());
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\n");
|
||||
printf("%s", strNumOfArgsWarning.c_str());
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\n");
|
||||
printf("Warning: Omitted expected opcode 0x8003. Opcode with # of arguments will be not analysed\n");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("\n");
|
||||
printf("%s", strNumOfArgsWarning.c_str());
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// Extract 'Export var' section
|
||||
printf(" Extract \"Export var\" section\n");
|
||||
ExtractCodeElements(HeaderTail, m_ExportedVar, COpcode::O_EXPORT_VAR, 2, "Error: Malformed \"Export var\" section\n", &CFalloutScript::CheckExportVarCode);
|
||||
|
||||
// Extract 'Set exported var values' section
|
||||
printf(" Extract \"Set exported var values\" section\n");
|
||||
ExtractCodeElements(HeaderTail, m_ExportedVarValue, COpcode::O_STORE_EXTERNAL, 3, "Error: Malformed \"Set exported var values\" section\n", &CFalloutScript::CheckSetExportedVarValueCode);
|
||||
|
||||
// Extract 'Export procedures' section
|
||||
printf(" Extract \"Export procedures\" section\n");
|
||||
ExtractCodeElements(HeaderTail, m_ExportedProc, COpcode::O_EXPORT_PROC, 3, "Error: Malformed \"Export procedures\" section\n", &CFalloutScript::CheckExportProcCode);
|
||||
|
||||
// Global variables
|
||||
printf(" Extract \"Global variables\" section\n");
|
||||
|
||||
for(INT_PTR i = 0; i < HeaderTail.GetSize(); i++) {
|
||||
WORD wGlobalVarOperator = HeaderTail.at(i).GetOperator();
|
||||
|
||||
if ((wGlobalVarOperator != COpcode::O_STRINGOP) &&
|
||||
(wGlobalVarOperator != COpcode::O_FLOATOP) &&
|
||||
(wGlobalVarOperator != COpcode::O_INTOP)) {
|
||||
printf("Error: Malformed \"Global variables\" section\n");
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
m_GlobalVar.Add(HeaderTail.at(i));
|
||||
}
|
||||
|
||||
// Procedures bodyes
|
||||
printf(" Read procedure\'s bodies\n");
|
||||
m_ProcBodies.RemoveAll(); // Destroy old data
|
||||
m_Conditions.RemoveAll();
|
||||
m_ProcBodies.SetSize(m_ProcTable.GetSize());
|
||||
m_Conditions.SetSize(m_ProcTable.GetSize());
|
||||
|
||||
CNode node;
|
||||
|
||||
for(INT_PTR i = 0; i < m_ProcTable.GetSize(); i++) {
|
||||
printf(" Procedure: %d\r", i);
|
||||
ULONG ulOffset = m_ProcTable[i].m_ulBodyOffset;
|
||||
ULONG ulSize = m_ProcTable.GetSizeOfProc(i);
|
||||
ar.Flush();
|
||||
ar.GetFile()->Seek(ulOffset, CFile::begin);
|
||||
|
||||
while(ulOffset < m_ProcTable[i].m_ulBodyOffset + ulSize) {
|
||||
node.m_Opcode.Serialize(ar);
|
||||
node.m_ulOffset = ulOffset;
|
||||
m_ProcBodies.at(i).Add(node);
|
||||
ulOffset += node.m_Opcode.GetSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CFalloutScript::ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Destination, WORD wDelimeter, int nSizeOfCodeItem, LPCTSTR lpszErrorMessage, BOOL (CFalloutScript::*pCheckFunc)(WORD, INT_PTR))
|
||||
{
|
||||
INT_PTR i = 0;
|
||||
|
||||
for(; i < Source.GetSize(); i++) {
|
||||
if (Source.at(i).GetOperator() == wDelimeter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < Source.GetSize()) {
|
||||
if (i < nSizeOfCodeItem - 1) {
|
||||
printf(lpszErrorMessage);
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
while(Source.at(i).GetOperator() == wDelimeter) {
|
||||
for(INT_PTR j = 0; j < nSizeOfCodeItem - 1; j++) {
|
||||
if (!((this->*pCheckFunc)(Source.at(i - nSizeOfCodeItem + 1 + j).GetOperator(), j))) {
|
||||
printf(lpszErrorMessage);
|
||||
AfxThrowUserException();
|
||||
}
|
||||
}
|
||||
|
||||
for(INT_PTR j = 0; j < nSizeOfCodeItem - 1; j++) {
|
||||
Destination.Add(Source.at(i - nSizeOfCodeItem + 1));
|
||||
Source.RemoveAt(i - nSizeOfCodeItem + 1);
|
||||
}
|
||||
|
||||
Source.RemoveAt(i - nSizeOfCodeItem + 1); // Delimeter
|
||||
|
||||
|
||||
if (i > Source.GetUpperBound()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CFalloutScript::CheckExportVarCode(WORD wOperator, INT_PTR nIndex)
|
||||
{
|
||||
return (nIndex == 0) && (wOperator == COpcode::O_STRINGOP);
|
||||
}
|
||||
|
||||
BOOL CFalloutScript::CheckSetExportedVarValueCode(WORD wOperator, INT_PTR nIndex)
|
||||
{
|
||||
switch(nIndex) {
|
||||
case 0:
|
||||
return (wOperator == COpcode::O_STRINGOP) ||
|
||||
(wOperator == COpcode::O_FLOATOP) ||
|
||||
(wOperator == COpcode::O_INTOP);
|
||||
case 1:
|
||||
return (wOperator == COpcode::O_STRINGOP);
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CFalloutScript::CheckExportProcCode(WORD wOperator, INT_PTR nIndex)
|
||||
{
|
||||
return ((nIndex == 0) || (nIndex == 1)) && (wOperator == COpcode::O_INTOP);
|
||||
}
|
||||
|
||||
bool CFalloutScript::ArgNeedParens( const CNode& node, const CNode& argument, CFalloutScript::Assoc assoc)
|
||||
{
|
||||
return (argument.IsInfix()
|
||||
&& ((GetPriority(argument.m_Opcode.GetOperator()) != GetPriority(node.m_Opcode.GetOperator()))
|
||||
|| (GetAssociation(node.m_Opcode.GetOperator()) != assoc)));
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FALLOUT_SCRIPT_H
|
||||
#define FALLOUT_SCRIPT_H
|
||||
|
||||
#include "StartupCode.h"
|
||||
#include "ProcTable.h"
|
||||
#include "Namespace.h"
|
||||
#include "Node.h"
|
||||
|
||||
|
||||
// Constants
|
||||
|
||||
// CFalloutScript
|
||||
class CFalloutScript : public CObject {
|
||||
public:
|
||||
CFalloutScript();
|
||||
virtual ~CFalloutScript();
|
||||
|
||||
public:
|
||||
virtual void Serialize(CArchive& ar);
|
||||
|
||||
void Dump(CArchive& ar);
|
||||
|
||||
void InitDefinitions();
|
||||
void ProcessCode();
|
||||
|
||||
void StoreSource(CArchive& ar);
|
||||
void StoreTree(CArchive& ar);
|
||||
|
||||
private:
|
||||
enum Assoc {
|
||||
NON_ASSOC,
|
||||
LEFT_ASSOC,
|
||||
RIGHT_ASSOC,
|
||||
};
|
||||
|
||||
private:
|
||||
void ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Destination, WORD wDelimeter, int nSizeOfCodeItem, LPCTSTR lpszErrorMessage, BOOL (CFalloutScript::*pCheckFunc)(WORD, INT_PTR));
|
||||
BOOL CheckExportVarCode(WORD wOperator, INT_PTR nIndex);
|
||||
BOOL CheckSetExportedVarValueCode(WORD wOperator, INT_PTR nIndex);
|
||||
BOOL CheckExportProcCode(WORD wOperator, INT_PTR nIndex);
|
||||
|
||||
INT_PTR GetIndexOfProc(LPCTSTR lpszName);
|
||||
INT_PTR GetIndexOfProc(ULONG ulNameOffset);
|
||||
INT_PTR GetIndexOfExportedVariable(ULONG ulNameOffset);
|
||||
|
||||
void SetExternalVariable(ULONG ulNameOffset);
|
||||
void TryRenameGlobalVariables();
|
||||
void TryRenameImportedVariables();
|
||||
|
||||
INT_PTR NextNodeIndex( CNodeArray& NodeArray, INT_PTR nCurrentIndex, INT_PTR nSteep);
|
||||
BOOL CheckSequenceOfNodes(CNodeArray& NodeArray, INT_PTR nStartIndex, const WORD wSequence[], INT_PTR nSequenceLen);
|
||||
BOOL RemoveSequenceOfNodes(CNodeArray& NodeArray,INT_PTR nStartIndex, INT_PTR nCount, const WORD wSequence[], INT_PTR nSequenceLen);
|
||||
|
||||
void InitialReduce();
|
||||
void BuildTree(CNodeArray& NodeArray);
|
||||
void ExtractAndReduceCondition(CNodeArray& Source, CNodeArray& Destination, INT_PTR nStartIndex);
|
||||
void SetBordersOfBlocks(CNodeArray& NodeArray);
|
||||
ULONG BuildTreeBranch(CNodeArray& NodeArray, ULONG nStartIndex, ULONG ulEndOffset);
|
||||
void ReduceConditionalExpressions(CNodeArray& NodeArray);
|
||||
BOOL IsOmittetArgsAllowed(WORD wOpcode);
|
||||
|
||||
void StoreDefinitions(CArchive& ar);
|
||||
void StoreDeclarations(CArchive& ar);
|
||||
|
||||
CString GetSource( CNode& node, BOOL bLabel, ULONG ulNumArgs);
|
||||
CString GetSource( CNode& node, BOOL bLabel, ULONG ulNumArgs, ULONG aulProcArg[], ULONG ulProcArgCount);
|
||||
bool ArgNeedParens(const CNode& node, const CNode& argument, CFalloutScript::Assoc assoc = CFalloutScript::NON_ASSOC);
|
||||
CString GetIndentString(INT_PTR nLevel);
|
||||
|
||||
int GetPriority(WORD wOperator);
|
||||
Assoc GetAssociation(WORD wOperator);
|
||||
|
||||
private:
|
||||
// CDefObject
|
||||
class CDefObject {
|
||||
public:
|
||||
enum ObjectType {
|
||||
OBJECT_VARIABLE,
|
||||
OBJECT_PROCEDURE
|
||||
};
|
||||
|
||||
public:
|
||||
CDefObject(ObjectType type = OBJECT_VARIABLE, ULONG ulAttributes = 0, ULONG ulObjectData = 0);
|
||||
|
||||
public:
|
||||
ObjectType m_ObjectType;
|
||||
ULONG m_ulAttributes;
|
||||
|
||||
union {
|
||||
ULONG m_ulVarValue;
|
||||
ULONG m_ulProcIndex;
|
||||
};
|
||||
};
|
||||
|
||||
private:
|
||||
// CMapULongToDefObject
|
||||
typedef CMap<ULONG, ULONG, CDefObject, CDefObject&> CMapULongToDefObject;
|
||||
|
||||
CStartupCode m_StartupCode;
|
||||
CProcTable m_ProcTable;
|
||||
CNamespace m_Namespace;
|
||||
CNamespace m_Stringspace;
|
||||
|
||||
COpcodeArray m_GlobalVar;
|
||||
COpcodeArray m_ExportedVar;
|
||||
COpcodeArray m_ExportedVarValue;
|
||||
COpcodeArray m_ExportedProc;
|
||||
|
||||
CArrayOfNodeArray m_ProcBodies;
|
||||
CArrayOfNodeArray m_Conditions;
|
||||
|
||||
CMapULongToDefObject m_Definitions;
|
||||
CStringArray m_GlobalVarsNames;
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
// FalloutScript.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "FalloutScript.h"
|
||||
|
||||
|
||||
// CFalloutScript::CDefObject
|
||||
CFalloutScript::CDefObject::CDefObject(ObjectType type, ULONG ulAttributes, ULONG ulObjectData)
|
||||
{
|
||||
m_ulAttributes = ulAttributes;
|
||||
|
||||
switch(m_ObjectType = type) {
|
||||
case OBJECT_VARIABLE:
|
||||
m_ulVarValue = ulObjectData;
|
||||
break;
|
||||
|
||||
case OBJECT_PROCEDURE:
|
||||
m_ulProcIndex = ulObjectData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
// FalloutScript.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "FalloutScript.h"
|
||||
|
||||
// CFalloutScript
|
||||
void CFalloutScript::Dump(CArchive& ar)
|
||||
{
|
||||
ar.WriteString("============== Procedures table ==================\n");
|
||||
ar.WriteString("\n");
|
||||
m_ProcTable.Dump(ar);
|
||||
ar.WriteString("\n");
|
||||
ar.WriteString("\n");
|
||||
|
||||
ar.WriteString("============== Namespace ==================\n");
|
||||
m_Namespace.Dump(ar);
|
||||
ar.WriteString("\n");
|
||||
ar.WriteString("\n");
|
||||
|
||||
ar.WriteString("============== Stringspace ==================\n");
|
||||
m_Stringspace.Dump(ar);
|
||||
ar.WriteString("\n");
|
||||
ar.WriteString("\n");
|
||||
|
||||
|
||||
CString strOutLine;
|
||||
WORD wOperator;
|
||||
ULONG ulArgument = 0;
|
||||
|
||||
ar.WriteString("============== Global variables values ==================\n");
|
||||
|
||||
if (m_GlobalVar.IsEmpty()) {
|
||||
ar.WriteString("Not found\n");
|
||||
}
|
||||
else {
|
||||
for(INT_PTR i = 0; i < m_GlobalVar.GetSize(); i++) {
|
||||
wOperator = m_GlobalVar.at(i).GetOperator();
|
||||
ulArgument = m_GlobalVar.at(i).GetArgument();
|
||||
|
||||
switch(wOperator) {
|
||||
case COpcode::O_STRINGOP:
|
||||
case COpcode::O_INTOP:
|
||||
strOutLine.Format("%d: %s(0x%08x) // %u (%d)\n",
|
||||
i,
|
||||
m_GlobalVar.at(i).GetAttributes().m_strMnemonic.c_str(),
|
||||
ulArgument,
|
||||
ulArgument,
|
||||
ulArgument);
|
||||
ar.WriteString(strOutLine);
|
||||
break;
|
||||
|
||||
case COpcode::O_FLOATOP:
|
||||
strOutLine.Format("%d: %s(0x%08x) // %05f\n",
|
||||
i,
|
||||
m_GlobalVar.at(i).GetAttributes().m_strMnemonic.c_str(),
|
||||
ulArgument,
|
||||
*((float*)(&ulArgument)));
|
||||
ar.WriteString(strOutLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ar.WriteString("\n");
|
||||
ar.WriteString("\n");
|
||||
|
||||
ar.WriteString("============== Exported variables ==================\n");
|
||||
|
||||
if (m_ExportedVarValue.IsEmpty()) {
|
||||
ar.WriteString("Not found\n");
|
||||
}
|
||||
else {
|
||||
for(INT_PTR i = 0; i < m_ExportedVarValue.GetSize(); i += 2) {
|
||||
wOperator = m_ExportedVarValue.at(i).GetOperator();
|
||||
ulArgument = m_ExportedVarValue.at(i).GetArgument();
|
||||
ULONG ulNameArgument = m_ExportedVarValue.at(i + 1).GetArgument();
|
||||
|
||||
switch(wOperator) {
|
||||
case COpcode::O_STRINGOP:
|
||||
strOutLine.Format("%s := \"%s\"\n",
|
||||
m_Namespace[ulNameArgument].c_str(),
|
||||
m_Stringspace[ulArgument].c_str());
|
||||
ar.WriteString(strOutLine);
|
||||
break;
|
||||
|
||||
case COpcode::O_INTOP:
|
||||
strOutLine.Format("%s := %u (%d)\n",
|
||||
m_Namespace[ulNameArgument].c_str(),
|
||||
ulArgument,
|
||||
ulArgument);
|
||||
ar.WriteString(strOutLine);
|
||||
break;
|
||||
|
||||
case COpcode::O_FLOATOP:
|
||||
strOutLine.Format("%s := %05f\n",
|
||||
m_Namespace[ulNameArgument].c_str(),
|
||||
*((float*)(&ulArgument)));
|
||||
ar.WriteString(strOutLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ar.WriteString("\n");
|
||||
ar.WriteString("\n");
|
||||
|
||||
ar.WriteString("============== Procedures ==================\n");
|
||||
ar.WriteString("\n");
|
||||
|
||||
for(INT_PTR nIndexOfProc = 0; nIndexOfProc < m_ProcTable.GetSize(); nIndexOfProc++) {
|
||||
strOutLine.Format("%d: %s (0x%08x)\n", nIndexOfProc,
|
||||
m_Namespace[m_ProcTable[nIndexOfProc].m_ulNameOffset].c_str(),
|
||||
m_ProcTable[nIndexOfProc].m_ulBodyOffset
|
||||
);
|
||||
ar.WriteString(strOutLine);
|
||||
ar.WriteString("===============================\n");
|
||||
|
||||
for(INT_PTR i = 0; i < m_ProcBodies.at(nIndexOfProc).GetSize(); i++) {
|
||||
wOperator = m_ProcBodies.at(nIndexOfProc).at(i).m_Opcode.GetOperator();
|
||||
ulArgument = m_ProcBodies.at(nIndexOfProc).at(i).m_Opcode.GetArgument();
|
||||
|
||||
switch(wOperator) {
|
||||
case COpcode::O_STRINGOP:
|
||||
case COpcode::O_INTOP:
|
||||
strOutLine.Format("0x%08X: 0x%04X 0x%08x - %s(0x%08x) // %u (%d)\n",
|
||||
m_ProcBodies.at(nIndexOfProc).at(i).m_ulOffset,
|
||||
wOperator,
|
||||
ulArgument,
|
||||
m_ProcBodies.at(nIndexOfProc).at(i).m_Opcode.GetAttributes().m_strMnemonic.c_str(),
|
||||
ulArgument,
|
||||
ulArgument,
|
||||
ulArgument);
|
||||
ar.WriteString(strOutLine);
|
||||
break;
|
||||
|
||||
case COpcode::O_FLOATOP:
|
||||
strOutLine.Format("0x%08X: 0x%04X 0x%08X - %s // %05f\n",
|
||||
m_ProcBodies.at(nIndexOfProc).at(i).m_ulOffset,
|
||||
wOperator,
|
||||
ulArgument,
|
||||
m_ProcBodies.at(nIndexOfProc).at(i).m_Opcode.GetAttributes().m_strMnemonic.c_str(),
|
||||
*((float*)(&ulArgument)));
|
||||
ar.WriteString(strOutLine);
|
||||
break;
|
||||
|
||||
default:
|
||||
strOutLine.Format("0x%08X: 0x%04X - %s\n",
|
||||
m_ProcBodies.at(nIndexOfProc).at(i).m_ulOffset,
|
||||
wOperator,
|
||||
m_ProcBodies.at(nIndexOfProc).at(i).m_Opcode.GetAttributes().m_strMnemonic.c_str());
|
||||
ar.WriteString(strOutLine);
|
||||
}
|
||||
}
|
||||
|
||||
ar.WriteString("\n");
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
#include "CArchive.h"
|
||||
|
||||
CArchive::CArchive(CFile* file, unsigned int mode)
|
||||
{
|
||||
_file = file;
|
||||
}
|
||||
|
||||
void CArchive::Flush()
|
||||
{
|
||||
}
|
||||
|
||||
CFile* CArchive::GetFile()
|
||||
{
|
||||
return _file;
|
||||
}
|
||||
|
||||
void CArchive::WriteString(const char * value)
|
||||
{
|
||||
_file->_ostream << value;
|
||||
}
|
||||
|
||||
ULONG CArchive::Read(char *buffer, ULONG size)
|
||||
{
|
||||
ULONG count;
|
||||
count = _file->_istream.readsome(buffer, size);
|
||||
//_file->_istream.seekg(_file->_istream.tellg(), std::ios_base::beg);
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef CARCHIVE_H
|
||||
#define CARCHIVE_H
|
||||
|
||||
#include "../Hacks/Types.h"
|
||||
#include "../Hacks/CFile.h"
|
||||
|
||||
class CArchive
|
||||
{
|
||||
protected:
|
||||
CFile* _file = 0;
|
||||
|
||||
public:
|
||||
static const unsigned int load = 1;
|
||||
static const unsigned int store = 2;
|
||||
|
||||
CArchive(CFile* file, unsigned int mode);
|
||||
void Flush();
|
||||
|
||||
CFile* GetFile();
|
||||
|
||||
void WriteString(const char * value);
|
||||
|
||||
ULONG Read(char * buffer, ULONG size);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // CARCHIVE_H
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "CArray.h"
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef CARRAY_H
|
||||
#define CARRAY_H
|
||||
|
||||
#include "../Hacks/Types.h"
|
||||
#include <vector>
|
||||
|
||||
template<typename A, typename B>
|
||||
class CArray
|
||||
{
|
||||
std::vector<A> _vector;
|
||||
public:
|
||||
CArray()
|
||||
{
|
||||
}
|
||||
|
||||
void RemoveAll()
|
||||
{
|
||||
while (!_vector.empty()) _vector.pop_back();
|
||||
}
|
||||
|
||||
void Add(A value)
|
||||
{
|
||||
_vector.push_back(value);
|
||||
}
|
||||
|
||||
bool IsEmpty()
|
||||
{
|
||||
return _vector.empty();
|
||||
}
|
||||
|
||||
INT_PTR GetUpperBound()
|
||||
{
|
||||
if (_vector.size() == 0) return 0;
|
||||
return _vector.size() - 1;
|
||||
}
|
||||
|
||||
void RemoveAt(ULONG n, ULONG count = 1)
|
||||
{
|
||||
_vector.erase(_vector.begin() + n, _vector.begin() + n + count);
|
||||
}
|
||||
|
||||
ULONG GetSize()
|
||||
{
|
||||
return _vector.size();
|
||||
}
|
||||
|
||||
void SetSize(ULONG n)
|
||||
{
|
||||
_vector.resize(n);
|
||||
}
|
||||
|
||||
void InsertAt(ULONG position, A value)
|
||||
{
|
||||
_vector.insert(_vector.begin() + position, value);
|
||||
}
|
||||
|
||||
A& at(ULONG n)
|
||||
{
|
||||
return _vector.at(n);
|
||||
}
|
||||
|
||||
void Copy(CArray source)
|
||||
{
|
||||
for (auto it = source._vector.begin(); it != source._vector.end(); ++it)
|
||||
{
|
||||
_vector.push_back(*it);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CARRAY_H
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "CFile.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
CFile::CFile()
|
||||
{
|
||||
}
|
||||
|
||||
bool CFile::Open(CString name, unsigned int mode)
|
||||
{
|
||||
switch (_mode)
|
||||
{
|
||||
case modeRead:
|
||||
_istream.open(name.c_str(), std::ios_base::in | std::ios_base::binary);
|
||||
return _istream.is_open();
|
||||
break;
|
||||
|
||||
case modeWrite:
|
||||
_ostream.open(name.c_str(), std::ios_base::out | std::ios_base::ate);
|
||||
return _ostream.is_open();
|
||||
}
|
||||
}
|
||||
|
||||
ULONG CFile::GetPosition()
|
||||
{
|
||||
switch (_mode)
|
||||
{
|
||||
case modeWrite:
|
||||
return _ostream.tellp();
|
||||
break;
|
||||
}
|
||||
|
||||
return _istream.tellg();
|
||||
}
|
||||
|
||||
void CFile::Seek(ULONG position, unsigned int mode)
|
||||
{
|
||||
switch (_mode)
|
||||
{
|
||||
case modeWrite:
|
||||
_ostream.seekp(position, std::ios_base::beg);
|
||||
break;
|
||||
default:
|
||||
_istream.seekg(position, std::ios_base::beg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ULONG CFile::GetLength()
|
||||
{
|
||||
ULONG size = 0;
|
||||
switch (_mode)
|
||||
{
|
||||
case modeWrite:
|
||||
{
|
||||
ULONG oldPosition = _ostream.tellp();
|
||||
_ostream.seekp(0, std::ios_base::end);
|
||||
size = _ostream.tellp();
|
||||
_ostream.seekp(oldPosition, std::ios_base::beg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ULONG oldPosition = _istream.tellg();
|
||||
_istream.seekg(0, std::ios_base::end);
|
||||
size = _istream.tellg();
|
||||
_istream.seekg(oldPosition, std::ios_base::beg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
CStdioFile::CStdioFile() : CFile()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef CFILE_H
|
||||
#define CFILE_H
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "../Hacks/Types.h"
|
||||
#include "../Hacks/CString.h"
|
||||
|
||||
class CFile
|
||||
{
|
||||
protected:
|
||||
unsigned int _mode = 1;
|
||||
|
||||
|
||||
public:
|
||||
std::ifstream _istream;
|
||||
std::ofstream _ostream;
|
||||
static const unsigned int modeRead = 1;
|
||||
static const unsigned int modeWrite = 2;
|
||||
static const unsigned int shareDenyWrite = 3;
|
||||
static const unsigned int modeCreate = 4;
|
||||
static const unsigned int typeText = 5;
|
||||
static const unsigned int begin = 6;
|
||||
|
||||
|
||||
CFile();
|
||||
|
||||
bool Open(CString name, unsigned int mode);
|
||||
ULONG GetPosition();
|
||||
void Seek(ULONG position, unsigned int mode);
|
||||
ULONG GetLength();
|
||||
|
||||
};
|
||||
|
||||
class CStdioFile : public CFile
|
||||
{
|
||||
protected:
|
||||
unsigned int _mode = 2;
|
||||
public:
|
||||
CStdioFile();
|
||||
};
|
||||
|
||||
#endif // CFILE_H
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "CMap.h"
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef CMAP_H
|
||||
#define CMAP_H
|
||||
|
||||
#include <map>
|
||||
#include "../Hacks/Types.h"
|
||||
|
||||
template<typename A, typename B, typename C,typename D>
|
||||
class CMap
|
||||
{
|
||||
std::map<A, C> _map;
|
||||
|
||||
public:
|
||||
CMap()
|
||||
{
|
||||
}
|
||||
|
||||
ULONG GetSize() const
|
||||
{
|
||||
return _map.size();
|
||||
}
|
||||
|
||||
void RemoveAll()
|
||||
{
|
||||
_map.clear();
|
||||
}
|
||||
|
||||
void SetAt(ULONG offset, C value)
|
||||
{
|
||||
if (_map.find(offset) != _map.end())
|
||||
{
|
||||
_map.at(offset) = value;
|
||||
}
|
||||
|
||||
_map.insert(std::pair<A, C>(offset, value));
|
||||
}
|
||||
|
||||
bool Lookup(ULONG offset, C& value) const
|
||||
{
|
||||
if (_map.find(offset) != _map.end())
|
||||
{
|
||||
value = _map.at(offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void InitHashTable(ULONG n)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CMAP_H
|
||||
@@ -0,0 +1,101 @@
|
||||
#include "CString.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
CString::CString()
|
||||
{
|
||||
}
|
||||
|
||||
CString::CString(std::string string)
|
||||
{
|
||||
_string = string;
|
||||
}
|
||||
|
||||
CString::CString(const CString& cstring)
|
||||
{
|
||||
_string = cstring._string;
|
||||
}
|
||||
|
||||
const char * CString::c_str() const
|
||||
{
|
||||
return _string.c_str();
|
||||
}
|
||||
|
||||
CString& CString::operator=(const char* value)
|
||||
{
|
||||
_string += value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CString& CString::operator+=(const char* value)
|
||||
{
|
||||
_string += value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CString& CString::operator+(const char* value)
|
||||
{
|
||||
_string += value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CString::operator const char* () const
|
||||
{
|
||||
return _string.c_str();
|
||||
}
|
||||
|
||||
void CString::MakeLower()
|
||||
{
|
||||
std::transform(_string.begin(), _string.end(), _string.begin(), ::tolower);
|
||||
}
|
||||
|
||||
ULONG CString::GetLength()
|
||||
{
|
||||
return _string.length();
|
||||
}
|
||||
|
||||
char* CString::GetBuffer(ULONG size)
|
||||
{
|
||||
return (char*) _string.data();
|
||||
}
|
||||
|
||||
|
||||
void CString::ReleaseBufferSetLength(ULONG size)
|
||||
{
|
||||
_string.resize(size);
|
||||
}
|
||||
|
||||
void CString::ReleaseBuffer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CString::Format(const char *format, ...)
|
||||
{
|
||||
char buff[1024];
|
||||
int size;
|
||||
|
||||
va_list args;
|
||||
va_start( args, format );
|
||||
|
||||
size = sprintf(buff, format, args);
|
||||
std::string stroka(buff, size);
|
||||
_string = stroka;
|
||||
}
|
||||
|
||||
std::string CString::str()
|
||||
{
|
||||
return _string;
|
||||
}
|
||||
|
||||
void CString::Replace(CString search, CString replace)
|
||||
{
|
||||
std::string str = _string;
|
||||
size_t pos = 0;
|
||||
while((pos = str.find(search.str(), pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(pos, search.str().length(), replace.str());
|
||||
pos += replace.str().length();
|
||||
}
|
||||
_string = str;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef CSTRING_H
|
||||
#define CSTRING_H
|
||||
|
||||
#include <string>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "../Hacks/Types.h"
|
||||
|
||||
class CString
|
||||
{
|
||||
protected:
|
||||
std::string _string;
|
||||
public:
|
||||
CString();
|
||||
CString(std::string string);
|
||||
CString(const CString& cstring);
|
||||
|
||||
const char* c_str() const;
|
||||
CString& operator=(const char* value);
|
||||
CString& operator+=(const char* value);
|
||||
CString& operator+(const char* value);
|
||||
operator const char* () const;
|
||||
void MakeLower();
|
||||
ULONG GetLength();
|
||||
char* GetBuffer(ULONG size);
|
||||
void ReleaseBufferSetLength(ULONG size);
|
||||
void ReleaseBuffer();
|
||||
std::string str();
|
||||
|
||||
void Format(const char * format, ...);
|
||||
void Replace(CString search, CString replacement);
|
||||
};
|
||||
#endif // CSTRING_H
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
typedef char BYTE;
|
||||
typedef const char * LPCTSTR;
|
||||
typedef char * LPTSTR;
|
||||
typedef unsigned int ULONG;
|
||||
typedef uint16_t WORD;
|
||||
typedef uint32_t DWORD;
|
||||
typedef unsigned int UINT;
|
||||
typedef bool BOOL;
|
||||
typedef char TCHAR;
|
||||
#define TRUE true
|
||||
#define FALSE false
|
||||
typedef size_t INT_PTR;
|
||||
|
||||
#endif // TYPES_H
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
// Namespace.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Namespace.h"
|
||||
#include "Utility.h"
|
||||
|
||||
#include "Hacks/CString.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
|
||||
// CNamespace
|
||||
|
||||
CNamespace::CNamespace()
|
||||
{
|
||||
m_Map.InitHashTable(128);
|
||||
}
|
||||
|
||||
CNamespace::~CNamespace()
|
||||
{
|
||||
}
|
||||
|
||||
void CNamespace::Serialize(CArchive& ar)
|
||||
{
|
||||
//if (ar.IsStoring()) {
|
||||
if (false)
|
||||
{
|
||||
//ASSERT(FALSE);
|
||||
}
|
||||
else {
|
||||
m_Map.RemoveAll();
|
||||
m_Order.RemoveAll();
|
||||
|
||||
ULONG ulLength;
|
||||
|
||||
if (ReadMSBULong(ar, ulLength) != 4) {
|
||||
printf("Error: Unable read length of namespace\n");
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
if (ulLength != 0xFFFFFFFF) {
|
||||
ULONG ulTotalRead = 0;
|
||||
WORD wLengthOfString;
|
||||
CString strNewString;
|
||||
LPTSTR lpszNewString;
|
||||
|
||||
while(ulTotalRead < ulLength) {
|
||||
if (ReadMSBWord(ar, wLengthOfString) != 2) {
|
||||
printf("Error: Unable read length of string\n");
|
||||
AfxThrowUserException();
|
||||
};
|
||||
|
||||
if ((wLengthOfString < 2) || (wLengthOfString & 0x0001)) {
|
||||
printf("Error: Invalid length of string\n");
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
lpszNewString = strNewString.GetBuffer(wLengthOfString);
|
||||
|
||||
if (ar.Read(lpszNewString, wLengthOfString) != wLengthOfString) {
|
||||
strNewString.ReleaseBufferSetLength(0);
|
||||
printf("Error: Unable read string in namespace\n");
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
if ((lpszNewString[wLengthOfString - 1] != '\x00') && (lpszNewString[wLengthOfString - 2] != '\x00')) {
|
||||
strNewString.ReleaseBufferSetLength(0);
|
||||
printf("Error: Invalid end of string in namespace\n");
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
strNewString.ReleaseBuffer();
|
||||
|
||||
/*
|
||||
// Convert Nongraphic Characters to Escape sequence
|
||||
CString strNonGraph("\\\a\b\f\n\r\t\"");
|
||||
CString strEscape("\\abfnrt\"");
|
||||
|
||||
for(int i = 0; i < strNonGraph.GetLength(); i++) {
|
||||
strNewString.Replace(CString(strNonGraph[i]), CString('\\') + strEscape[i]);
|
||||
}
|
||||
*/
|
||||
m_Map.SetAt(ulTotalRead + 6, strNewString);
|
||||
m_Order.Add(ulTotalRead + 6);
|
||||
|
||||
ulTotalRead += (2 + wLengthOfString);
|
||||
}
|
||||
|
||||
ULONG ulTerminator;
|
||||
|
||||
if (ReadMSBULong(ar, ulTerminator) != 4) {
|
||||
printf("Error: Unable read terminator of namespace\n");
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
if (ulTerminator != 0xFFFFFFFF) {
|
||||
printf("Error: Invalid terminator of namespace\n");
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
// //For debugging only
|
||||
// for(INT_PTR i = 0; i < GetSize(); i++) {
|
||||
// printf("Offset: 0x%08X (%9d), string: %s\n", m_Order[i], m_Order[i], GetStringByIndex(i));
|
||||
// }
|
||||
//
|
||||
// printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
INT_PTR CNamespace::GetSize() const
|
||||
{
|
||||
return m_Map.GetSize();
|
||||
}
|
||||
|
||||
CString CNamespace::GetStringByIndex(INT_PTR nIndex)
|
||||
{
|
||||
return (this->operator [] (m_Order.at(nIndex)));
|
||||
}
|
||||
|
||||
ULONG CNamespace::GetOffsetByIndex(INT_PTR nIndex)
|
||||
{
|
||||
return m_Order.at(nIndex);
|
||||
}
|
||||
|
||||
void CNamespace::Dump(CArchive& ar)
|
||||
{
|
||||
CString strOutLine;
|
||||
|
||||
if (m_Order.IsEmpty()) {
|
||||
ar.WriteString("Empty\n");
|
||||
}
|
||||
else {
|
||||
for(INT_PTR i = 0; i < m_Order.GetSize(); i++) {
|
||||
strOutLine.Format("0x%08X: \"%s\"\n", m_Order.at(i), GetStringByIndex(i).c_str());
|
||||
ar.WriteString(strOutLine);
|
||||
}
|
||||
|
||||
ar.WriteString("==================\n");
|
||||
strOutLine.Format("%d item(s)\n", m_Order.GetSize());
|
||||
ar.WriteString(strOutLine);
|
||||
}
|
||||
}
|
||||
|
||||
CString CNamespace::operator [] (ULONG ulOffset) const
|
||||
{
|
||||
CString strResult;
|
||||
|
||||
if (!m_Map.Lookup(ulOffset, strResult)) {
|
||||
printf("Error: No string at offset 0x%08x\n", ulOffset);
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
return strResult;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NAMESPACE_H
|
||||
#define NAMESPACE_H
|
||||
|
||||
#include "Hacks/CArchive.h"
|
||||
#include "Hacks/CMap.h"
|
||||
|
||||
// CNamespace
|
||||
class CNamespace : public CObject {
|
||||
public:
|
||||
CNamespace();
|
||||
virtual ~CNamespace();
|
||||
|
||||
public:
|
||||
virtual void Serialize(CArchive& ar);
|
||||
|
||||
public:
|
||||
INT_PTR GetSize() const;
|
||||
CString GetStringByIndex(INT_PTR nIndex) ;
|
||||
ULONG GetOffsetByIndex(INT_PTR nIndex) ;
|
||||
|
||||
void Dump(CArchive& ar);
|
||||
|
||||
public:
|
||||
CString operator [] (ULONG ulOffset) const;
|
||||
|
||||
private:
|
||||
// CMapDWordToString
|
||||
typedef CMap<DWORD, DWORD, CString, LPCTSTR> CMapDWordToString;
|
||||
|
||||
CMapDWordToString m_Map;
|
||||
CDWordArray m_Order;
|
||||
};
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user