mirror of
https://github.com/sfall-team/int2ssl.git
synced 2026-07-27 16:52:42 -07:00
Code formating
This commit is contained in:
+41
-32
@@ -1,20 +1,8 @@
|
|||||||
// FalloutScript.cpp : implementation file
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "FalloutScript.h"
|
#include "FalloutScript.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Constants
|
|
||||||
//c_strBogusProcedureName = "..............";
|
|
||||||
//c_strArgumentTemplate = "arg%u";
|
|
||||||
//c_strGlobalVarTemplate = "GVar%u";
|
|
||||||
//c_strLocalVarTemplate = "LVar%u";
|
|
||||||
|
|
||||||
|
|
||||||
// CFalloutScript
|
|
||||||
|
|
||||||
CFalloutScript::CFalloutScript()
|
CFalloutScript::CFalloutScript()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -118,37 +106,45 @@ void CFalloutScript::Serialize(CArchive& ar)
|
|||||||
|
|
||||||
CString strNumOfArgsWarning("Warning: Omitted \"# of argument to \'start\' procedure\"\n");
|
CString strNumOfArgsWarning("Warning: Omitted \"# of argument to \'start\' procedure\"\n");
|
||||||
|
|
||||||
if (!HeaderTail.IsEmpty()) {
|
if (!HeaderTail.IsEmpty())
|
||||||
|
{
|
||||||
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
||||||
|
|
||||||
if (opcode.GetOperator() == COpcode::O_CRITICAL_DONE) {
|
if (opcode.GetOperator() == COpcode::O_CRITICAL_DONE)
|
||||||
|
{
|
||||||
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
||||||
|
|
||||||
if (!HeaderTail.IsEmpty()) {
|
if (!HeaderTail.IsEmpty())
|
||||||
|
{
|
||||||
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
||||||
|
|
||||||
if (opcode.HasArgument()) {
|
if (opcode.HasArgument())
|
||||||
|
{
|
||||||
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("%s", strNumOfArgsWarning.c_str());
|
printf("%s", strNumOfArgsWarning.c_str());
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("%s", strNumOfArgsWarning.c_str());
|
printf("%s", strNumOfArgsWarning.c_str());
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Warning: Omitted expected opcode 0x8003. Opcode with # of arguments will be not analysed\n");
|
printf("Warning: Omitted expected opcode 0x8003. Opcode with # of arguments will be not analysed\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("%s", strNumOfArgsWarning.c_str());
|
printf("%s", strNumOfArgsWarning.c_str());
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@@ -169,12 +165,14 @@ void CFalloutScript::Serialize(CArchive& ar)
|
|||||||
// Global variables
|
// Global variables
|
||||||
printf(" Extract \"Global variables\" section\n");
|
printf(" Extract \"Global variables\" section\n");
|
||||||
|
|
||||||
for(INT_PTR i = 0; i < HeaderTail.GetSize(); i++) {
|
for(INT_PTR i = 0; i < HeaderTail.GetSize(); i++)
|
||||||
|
{
|
||||||
WORD wGlobalVarOperator = HeaderTail.at(i).GetOperator();
|
WORD wGlobalVarOperator = HeaderTail.at(i).GetOperator();
|
||||||
|
|
||||||
if ((wGlobalVarOperator != COpcode::O_STRINGOP) &&
|
if ((wGlobalVarOperator != COpcode::O_STRINGOP) &&
|
||||||
(wGlobalVarOperator != COpcode::O_FLOATOP) &&
|
(wGlobalVarOperator != COpcode::O_FLOATOP) &&
|
||||||
(wGlobalVarOperator != COpcode::O_INTOP)) {
|
(wGlobalVarOperator != COpcode::O_INTOP))
|
||||||
|
{
|
||||||
printf("Error: Malformed \"Global variables\" section\n");
|
printf("Error: Malformed \"Global variables\" section\n");
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
@@ -213,27 +211,35 @@ void CFalloutScript::ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Des
|
|||||||
{
|
{
|
||||||
INT_PTR i = 0;
|
INT_PTR i = 0;
|
||||||
|
|
||||||
for(; i < Source.GetSize(); i++) {
|
for(; i < Source.GetSize(); i++)
|
||||||
if (Source.at(i).GetOperator() == wDelimeter) {
|
{
|
||||||
|
if (Source.at(i).GetOperator() == wDelimeter)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i < Source.GetSize()) {
|
if (i < Source.GetSize())
|
||||||
if (i < nSizeOfCodeItem - 1) {
|
{
|
||||||
|
if (i < nSizeOfCodeItem - 1)
|
||||||
|
{
|
||||||
printf(lpszErrorMessage);
|
printf(lpszErrorMessage);
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
|
|
||||||
while(Source.at(i).GetOperator() == wDelimeter) {
|
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))) {
|
for(INT_PTR j = 0; j < nSizeOfCodeItem - 1; j++)
|
||||||
|
{
|
||||||
|
if (!((this->*pCheckFunc)(Source.at(i - nSizeOfCodeItem + 1 + j).GetOperator(), j)))
|
||||||
|
{
|
||||||
printf(lpszErrorMessage);
|
printf(lpszErrorMessage);
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(INT_PTR j = 0; j < nSizeOfCodeItem - 1; j++) {
|
for(INT_PTR j = 0; j < nSizeOfCodeItem - 1; j++)
|
||||||
|
{
|
||||||
Destination.Add(Source.at(i - nSizeOfCodeItem + 1));
|
Destination.Add(Source.at(i - nSizeOfCodeItem + 1));
|
||||||
Source.RemoveAt(i - nSizeOfCodeItem + 1);
|
Source.RemoveAt(i - nSizeOfCodeItem + 1);
|
||||||
}
|
}
|
||||||
@@ -241,7 +247,8 @@ void CFalloutScript::ExtractCodeElements(COpcodeArray& Source, COpcodeArray& Des
|
|||||||
Source.RemoveAt(i - nSizeOfCodeItem + 1); // Delimeter
|
Source.RemoveAt(i - nSizeOfCodeItem + 1); // Delimeter
|
||||||
|
|
||||||
|
|
||||||
if (i > Source.GetUpperBound()) {
|
if (i > Source.GetUpperBound())
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,7 +262,8 @@ BOOL CFalloutScript::CheckExportVarCode(WORD wOperator, INT_PTR nIndex)
|
|||||||
|
|
||||||
BOOL CFalloutScript::CheckSetExportedVarValueCode(WORD wOperator, INT_PTR nIndex)
|
BOOL CFalloutScript::CheckSetExportedVarValueCode(WORD wOperator, INT_PTR nIndex)
|
||||||
{
|
{
|
||||||
switch(nIndex) {
|
switch(nIndex)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return (wOperator == COpcode::O_STRINGOP) ||
|
return (wOperator == COpcode::O_STRINGOP) ||
|
||||||
(wOperator == COpcode::O_FLOATOP) ||
|
(wOperator == COpcode::O_FLOATOP) ||
|
||||||
@@ -279,3 +287,4 @@ bool CFalloutScript::ArgNeedParens( const CNode& node, const CNode& argument, CF
|
|||||||
&& ((GetPriority(argument.m_Opcode.GetOperator()) != GetPriority(node.m_Opcode.GetOperator()))
|
&& ((GetPriority(argument.m_Opcode.GetOperator()) != GetPriority(node.m_Opcode.GetOperator()))
|
||||||
|| (GetAssociation(node.m_Opcode.GetOperator()) != assoc)));
|
|| (GetAssociation(node.m_Opcode.GetOperator()) != assoc)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-9
@@ -1,5 +1,3 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef FALLOUT_SCRIPT_H
|
#ifndef FALLOUT_SCRIPT_H
|
||||||
#define FALLOUT_SCRIPT_H
|
#define FALLOUT_SCRIPT_H
|
||||||
|
|
||||||
@@ -8,11 +6,8 @@
|
|||||||
#include "Namespace.h"
|
#include "Namespace.h"
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
|
|
||||||
|
class CFalloutScript
|
||||||
// Constants
|
{
|
||||||
|
|
||||||
// CFalloutScript
|
|
||||||
class CFalloutScript : public CObject {
|
|
||||||
public:
|
public:
|
||||||
CFalloutScript();
|
CFalloutScript();
|
||||||
virtual ~CFalloutScript();
|
virtual ~CFalloutScript();
|
||||||
@@ -73,8 +68,9 @@ private:
|
|||||||
Assoc GetAssociation(WORD wOperator);
|
Assoc GetAssociation(WORD wOperator);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// CDefObject
|
|
||||||
class CDefObject {
|
class CDefObject
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
enum ObjectType {
|
enum ObjectType {
|
||||||
OBJECT_VARIABLE,
|
OBJECT_VARIABLE,
|
||||||
|
|||||||
+279
-204
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,12 @@
|
|||||||
// FalloutScript.cpp : implementation file
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "FalloutScript.h"
|
#include "FalloutScript.h"
|
||||||
|
|
||||||
|
|
||||||
// CFalloutScript::CDefObject
|
|
||||||
CFalloutScript::CDefObject::CDefObject(ObjectType type, ULONG ulAttributes, ULONG ulObjectData)
|
CFalloutScript::CDefObject::CDefObject(ObjectType type, ULONG ulAttributes, ULONG ulObjectData)
|
||||||
{
|
{
|
||||||
m_ulAttributes = ulAttributes;
|
m_ulAttributes = ulAttributes;
|
||||||
|
|
||||||
switch(m_ObjectType = type) {
|
switch(m_ObjectType = type)
|
||||||
|
{
|
||||||
case OBJECT_VARIABLE:
|
case OBJECT_VARIABLE:
|
||||||
m_ulVarValue = ulObjectData;
|
m_ulVarValue = ulObjectData;
|
||||||
break;
|
break;
|
||||||
|
|||||||
+15
-10
@@ -1,7 +1,6 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "FalloutScript.h"
|
#include "FalloutScript.h"
|
||||||
|
|
||||||
// CFalloutScript
|
|
||||||
void CFalloutScript::Dump(CArchive& ar)
|
void CFalloutScript::Dump(CArchive& ar)
|
||||||
{
|
{
|
||||||
ar.WriteString("============== Procedures table ==================\n");
|
ar.WriteString("============== Procedures table ==================\n");
|
||||||
@@ -67,16 +66,20 @@ void CFalloutScript::Dump(CArchive& ar)
|
|||||||
|
|
||||||
ar.WriteString("============== Exported variables ==================\n");
|
ar.WriteString("============== Exported variables ==================\n");
|
||||||
|
|
||||||
if (m_ExportedVarValue.IsEmpty()) {
|
if (m_ExportedVarValue.IsEmpty())
|
||||||
|
{
|
||||||
ar.WriteString("Not found\n");
|
ar.WriteString("Not found\n");
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
for(INT_PTR i = 0; i < m_ExportedVarValue.GetSize(); i += 2) {
|
{
|
||||||
|
for(INT_PTR i = 0; i < m_ExportedVarValue.GetSize(); i += 2)
|
||||||
|
{
|
||||||
wOperator = m_ExportedVarValue.at(i).GetOperator();
|
wOperator = m_ExportedVarValue.at(i).GetOperator();
|
||||||
ulArgument = m_ExportedVarValue.at(i).GetArgument();
|
ulArgument = m_ExportedVarValue.at(i).GetArgument();
|
||||||
ULONG ulNameArgument = m_ExportedVarValue.at(i + 1).GetArgument();
|
ULONG ulNameArgument = m_ExportedVarValue.at(i + 1).GetArgument();
|
||||||
|
|
||||||
switch(wOperator) {
|
switch(wOperator)
|
||||||
|
{
|
||||||
case COpcode::O_STRINGOP:
|
case COpcode::O_STRINGOP:
|
||||||
strOutLine.Format("%s := \"%s\"\n",
|
strOutLine.Format("%s := \"%s\"\n",
|
||||||
m_Namespace[ulNameArgument].c_str(),
|
m_Namespace[ulNameArgument].c_str(),
|
||||||
@@ -107,19 +110,21 @@ void CFalloutScript::Dump(CArchive& ar)
|
|||||||
ar.WriteString("============== Procedures ==================\n");
|
ar.WriteString("============== Procedures ==================\n");
|
||||||
ar.WriteString("\n");
|
ar.WriteString("\n");
|
||||||
|
|
||||||
for(INT_PTR nIndexOfProc = 0; nIndexOfProc < m_ProcTable.GetSize(); nIndexOfProc++) {
|
for(INT_PTR nIndexOfProc = 0; nIndexOfProc < m_ProcTable.GetSize(); nIndexOfProc++)
|
||||||
|
{
|
||||||
strOutLine.Format("%d: %s (0x%08x)\n", nIndexOfProc,
|
strOutLine.Format("%d: %s (0x%08x)\n", nIndexOfProc,
|
||||||
m_Namespace[m_ProcTable[nIndexOfProc].m_ulNameOffset].c_str(),
|
m_Namespace[m_ProcTable[nIndexOfProc].m_ulNameOffset].c_str(),
|
||||||
m_ProcTable[nIndexOfProc].m_ulBodyOffset
|
m_ProcTable[nIndexOfProc].m_ulBodyOffset);
|
||||||
);
|
|
||||||
ar.WriteString(strOutLine);
|
ar.WriteString(strOutLine);
|
||||||
ar.WriteString("===============================\n");
|
ar.WriteString("===============================\n");
|
||||||
|
|
||||||
for(INT_PTR i = 0; i < m_ProcBodies.at(nIndexOfProc).GetSize(); i++) {
|
for(INT_PTR i = 0; i < m_ProcBodies.at(nIndexOfProc).GetSize(); i++)
|
||||||
|
{
|
||||||
wOperator = m_ProcBodies.at(nIndexOfProc).at(i).m_Opcode.GetOperator();
|
wOperator = m_ProcBodies.at(nIndexOfProc).at(i).m_Opcode.GetOperator();
|
||||||
ulArgument = m_ProcBodies.at(nIndexOfProc).at(i).m_Opcode.GetArgument();
|
ulArgument = m_ProcBodies.at(nIndexOfProc).at(i).m_Opcode.GetArgument();
|
||||||
|
|
||||||
switch(wOperator) {
|
switch(wOperator)
|
||||||
|
{
|
||||||
case COpcode::O_STRINGOP:
|
case COpcode::O_STRINGOP:
|
||||||
case COpcode::O_INTOP:
|
case COpcode::O_INTOP:
|
||||||
strOutLine.Format("0x%08X: 0x%04X 0x%08x - %s(0x%08x) // %u (%d)\n",
|
strOutLine.Format("0x%08X: 0x%04X 0x%08x - %s(0x%08x) // %u (%d)\n",
|
||||||
|
|||||||
+277
-165
File diff suppressed because it is too large
Load Diff
+62
-65
@@ -25,88 +25,87 @@ CNamespace::~CNamespace()
|
|||||||
|
|
||||||
void CNamespace::Serialize(CArchive& ar)
|
void CNamespace::Serialize(CArchive& ar)
|
||||||
{
|
{
|
||||||
//if (ar.IsStoring()) {
|
m_Map.RemoveAll();
|
||||||
if (false)
|
m_Order.RemoveAll();
|
||||||
|
|
||||||
|
ULONG ulLength;
|
||||||
|
|
||||||
|
if (ReadMSBULong(ar, ulLength) != 4)
|
||||||
{
|
{
|
||||||
//ASSERT(FALSE);
|
printf("Error: Unable read length of namespace\n");
|
||||||
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
m_Map.RemoveAll();
|
|
||||||
m_Order.RemoveAll();
|
|
||||||
|
|
||||||
ULONG ulLength;
|
if (ulLength == 0xFFFFFFFF) return;
|
||||||
|
|
||||||
if (ReadMSBULong(ar, ulLength) != 4)
|
ULONG ulTotalRead = 0;
|
||||||
|
WORD wLengthOfString;
|
||||||
|
LPTSTR lpszNewString;
|
||||||
|
|
||||||
|
while(ulTotalRead < ulLength)
|
||||||
|
{
|
||||||
|
CString strNewString;
|
||||||
|
|
||||||
|
if (ReadMSBWord(ar, wLengthOfString) != 2)
|
||||||
{
|
{
|
||||||
printf("Error: Unable read length of namespace\n");
|
printf("Error: Unable read length of string\n");
|
||||||
|
AfxThrowUserException();
|
||||||
|
};
|
||||||
|
|
||||||
|
if ((wLengthOfString < 2) || (wLengthOfString & 0x0001))
|
||||||
|
{
|
||||||
|
printf("Error: Invalid length of string\n");
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ulLength != 0xFFFFFFFF)
|
lpszNewString = strNewString.GetBuffer(wLengthOfString);
|
||||||
|
|
||||||
|
if (ar.Read(lpszNewString, wLengthOfString) != wLengthOfString)
|
||||||
{
|
{
|
||||||
ULONG ulTotalRead = 0;
|
strNewString.ReleaseBufferSetLength(0);
|
||||||
WORD wLengthOfString;
|
printf("Error: Unable read string in namespace\n");
|
||||||
LPTSTR lpszNewString;
|
AfxThrowUserException();
|
||||||
|
}
|
||||||
|
|
||||||
while(ulTotalRead < ulLength)
|
if ((lpszNewString[wLengthOfString - 1] != '\x00') && (lpszNewString[wLengthOfString - 2] != '\x00'))
|
||||||
{
|
{
|
||||||
CString strNewString;
|
strNewString.ReleaseBufferSetLength(0);
|
||||||
|
printf("Error: Invalid end of string in namespace\n");
|
||||||
|
AfxThrowUserException();
|
||||||
|
}
|
||||||
|
|
||||||
if (ReadMSBWord(ar, wLengthOfString) != 2) {
|
std::string tmpString(lpszNewString);
|
||||||
printf("Error: Unable read length of string\n");
|
strNewString = tmpString.c_str();//.ReleaseBuffer();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string tmpString(lpszNewString);
|
|
||||||
strNewString = tmpString.c_str();//.ReleaseBuffer();
|
|
||||||
|
|
||||||
|
|
||||||
// Convert Nongraphic Characters to Escape sequence
|
// Convert Nongraphic Characters to Escape sequence
|
||||||
CString strNonGraph("\\\a\b\f\n\r\t\"");
|
CString strNonGraph("\\\a\b\f\n\r\t\"");
|
||||||
CString strEscape("\\abfnrt\"");
|
CString strEscape("\\abfnrt\"");
|
||||||
|
|
||||||
for(int i = 0; i < strNonGraph.GetLength(); i++)
|
for(int i = 0; i < strNonGraph.GetLength(); i++)
|
||||||
{
|
{
|
||||||
strNewString.Replace(CString(strNonGraph[i]), CString("\\" + strEscape[i]));
|
strNewString.Replace(CString(strNonGraph[i]), CString("\\" + strEscape[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Map.SetAt(ulTotalRead + 6, strNewString);
|
m_Map.SetAt(ulTotalRead + 6, strNewString);
|
||||||
m_Order.Add(ulTotalRead + 6);
|
m_Order.Add(ulTotalRead + 6);
|
||||||
|
|
||||||
ulTotalRead += (2 + wLengthOfString);
|
ulTotalRead += (2 + wLengthOfString);
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG ulTerminator;
|
ULONG ulTerminator;
|
||||||
|
|
||||||
if (ReadMSBULong(ar, ulTerminator) != 4)
|
if (ReadMSBULong(ar, ulTerminator) != 4)
|
||||||
{
|
{
|
||||||
printf("Error: Unable read terminator of namespace\n");
|
printf("Error: Unable read terminator of namespace\n");
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ulTerminator != 0xFFFFFFFF) {
|
if (ulTerminator != 0xFFFFFFFF)
|
||||||
printf("Error: Invalid terminator of namespace\n");
|
{
|
||||||
AfxThrowUserException();
|
printf("Error: Invalid terminator of namespace\n");
|
||||||
}
|
AfxThrowUserException();
|
||||||
|
}
|
||||||
|
|
||||||
// //For debugging only
|
// //For debugging only
|
||||||
// for(INT_PTR i = 0; i < GetSize(); i++) {
|
// for(INT_PTR i = 0; i < GetSize(); i++) {
|
||||||
@@ -114,8 +113,6 @@ void CNamespace::Serialize(CArchive& ar)
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// printf("\n");
|
// printf("\n");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INT_PTR CNamespace::GetSize() const
|
INT_PTR CNamespace::GetSize() const
|
||||||
|
|||||||
+3
-5
@@ -1,13 +1,11 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAMESPACE_H
|
#ifndef NAMESPACE_H
|
||||||
#define NAMESPACE_H
|
#define NAMESPACE_H
|
||||||
|
|
||||||
#include "Hacks/CArchive.h"
|
#include "Hacks/CArchive.h"
|
||||||
#include "Hacks/CMap.h"
|
#include "Hacks/CMap.h"
|
||||||
|
|
||||||
// CNamespace
|
class CNamespace
|
||||||
class CNamespace : public CObject {
|
{
|
||||||
public:
|
public:
|
||||||
CNamespace();
|
CNamespace();
|
||||||
virtual ~CNamespace();
|
virtual ~CNamespace();
|
||||||
@@ -33,4 +31,4 @@ private:
|
|||||||
CDWordArray m_Order;
|
CDWordArray m_Order;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif //NAMESPACE_H
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
// Node.cpp : implementation file
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
|
|
||||||
|
|
||||||
// CNode
|
|
||||||
|
|
||||||
CNode::CNode(Type type) :
|
CNode::CNode(Type type) :
|
||||||
m_ulOffset(0),
|
m_ulOffset(0),
|
||||||
m_Type(type)
|
m_Type(type)
|
||||||
@@ -28,28 +22,31 @@ CNode::~CNode()
|
|||||||
|
|
||||||
CNode& CNode::operator = (const CNode& node)
|
CNode& CNode::operator = (const CNode& node)
|
||||||
{
|
{
|
||||||
if (&node != this) {
|
if (&node != this)
|
||||||
|
{
|
||||||
m_ulOffset = node.m_ulOffset;
|
m_ulOffset = node.m_ulOffset;
|
||||||
m_Opcode = node.m_Opcode;
|
m_Opcode = node.m_Opcode;
|
||||||
m_Type = node.m_Type;
|
m_Type = node.m_Type;
|
||||||
m_Arguments.Copy(node.m_Arguments);
|
m_Arguments.Copy(node.m_Arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex)
|
void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex)
|
||||||
{
|
{
|
||||||
// Indent
|
// Indent
|
||||||
if (nIndex != 0) {
|
if (nIndex != 0)
|
||||||
|
{
|
||||||
ar.WriteString(" ");
|
ar.WriteString(" ");
|
||||||
|
|
||||||
for(int i = 0; i < nIndent; i++) {
|
for(int i = 0; i < nIndent; i++)
|
||||||
|
{
|
||||||
ar.WriteString(" ");
|
ar.WriteString(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(m_Type) {
|
switch(m_Type)
|
||||||
|
{
|
||||||
case TYPE_BEGIN_OF_BLOCK:
|
case TYPE_BEGIN_OF_BLOCK:
|
||||||
ar.WriteString("========= begin of block =========\n");
|
ar.WriteString("========= begin of block =========\n");
|
||||||
return;
|
return;
|
||||||
@@ -64,7 +61,8 @@ void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex)
|
|||||||
WORD wOperator = m_Opcode.GetOperator();
|
WORD wOperator = m_Opcode.GetOperator();
|
||||||
ULONG ulArgument = m_Opcode.GetArgument();
|
ULONG ulArgument = m_Opcode.GetArgument();
|
||||||
|
|
||||||
switch(wOperator) {
|
switch(wOperator)
|
||||||
|
{
|
||||||
case COpcode::O_STRINGOP:
|
case COpcode::O_STRINGOP:
|
||||||
case COpcode::O_INTOP:
|
case COpcode::O_INTOP:
|
||||||
strOutLine.Format("0x%04X 0x%08x ",
|
strOutLine.Format("0x%04X 0x%08x ",
|
||||||
@@ -85,12 +83,15 @@ void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex)
|
|||||||
wOperator);
|
wOperator);
|
||||||
ar.WriteString(strOutLine);
|
ar.WriteString(strOutLine);
|
||||||
}
|
}
|
||||||
if (!m_Arguments.IsEmpty()) {
|
if (!m_Arguments.IsEmpty())
|
||||||
for(int i = 0; i < m_Arguments.GetSize(); i++) {
|
{
|
||||||
|
for(int i = 0; i < m_Arguments.GetSize(); i++)
|
||||||
|
{
|
||||||
m_Arguments.at(i).StoreTree(ar, nIndent + 1, i);
|
m_Arguments.at(i).StoreTree(ar, nIndent + 1, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
ar.WriteString("\n");
|
ar.WriteString("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,9 +100,13 @@ void CNode::StoreTree(CArchive& ar, int nIndent, int nIndex)
|
|||||||
ULONG CNode::GetTopOffset()
|
ULONG CNode::GetTopOffset()
|
||||||
{
|
{
|
||||||
if (m_Arguments.GetSize() > 0)
|
if (m_Arguments.GetSize() > 0)
|
||||||
|
{
|
||||||
return m_Arguments.at(0).GetTopOffset();
|
return m_Arguments.at(0).GetTopOffset();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return m_ulOffset;
|
return m_ulOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CNode::IsExpression() const
|
bool CNode::IsExpression() const
|
||||||
|
|||||||
@@ -1,22 +1,15 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NODE_H
|
#ifndef NODE_H
|
||||||
#define NODE_H
|
#define NODE_H
|
||||||
|
|
||||||
#include "Namespace.h"
|
#include "Namespace.h"
|
||||||
#include "Opcode.h"
|
#include "Opcode.h"
|
||||||
|
|
||||||
|
|
||||||
// Forward declaration of CNode
|
|
||||||
class CNode;
|
class CNode;
|
||||||
|
|
||||||
|
|
||||||
// CNodeArray
|
|
||||||
typedef CArray<CNode, CNode&> CNodeArray;
|
typedef CArray<CNode, CNode&> CNodeArray;
|
||||||
|
typedef CArray<CNodeArray, CNodeArray&> CArrayOfNodeArray;
|
||||||
|
|
||||||
|
class CNode
|
||||||
// CNode
|
{
|
||||||
class CNode : public CObject {
|
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
TYPE_NORMAL,
|
TYPE_NORMAL,
|
||||||
@@ -51,15 +44,8 @@ public:
|
|||||||
CNodeArray m_Arguments;
|
CNodeArray m_Arguments;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// CNodeArray
|
|
||||||
typedef CArray<CNode, CNode&> CNodeArray;
|
|
||||||
|
|
||||||
// CArrayOfNodeArray
|
|
||||||
typedef CArray<CNodeArray, CNodeArray&> CArrayOfNodeArray;
|
|
||||||
|
|
||||||
// 'Begin' end 'End of block' 'End Else Begin' nodes
|
// 'Begin' end 'End of block' 'End Else Begin' nodes
|
||||||
const CNode c_NodeBeginOfBlock(CNode::TYPE_BEGIN_OF_BLOCK);
|
const CNode c_NodeBeginOfBlock(CNode::TYPE_BEGIN_OF_BLOCK);
|
||||||
const CNode c_NodeEndOfBlock(CNode::TYPE_END_OF_BLOCK);
|
const CNode c_NodeEndOfBlock(CNode::TYPE_END_OF_BLOCK);
|
||||||
|
|
||||||
#endif
|
#endif //NODE_H
|
||||||
|
|||||||
+1
-5
@@ -1,9 +1,6 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef OBJECT_ATTRIBUTES_H
|
#ifndef OBJECT_ATTRIBUTES_H
|
||||||
#define OBJECT_ATTRIBUTES_H
|
#define OBJECT_ATTRIBUTES_H
|
||||||
|
|
||||||
|
|
||||||
// ProcedureAttributes
|
// ProcedureAttributes
|
||||||
enum ProcAttributes {
|
enum ProcAttributes {
|
||||||
P_TIMED = 0x01,
|
P_TIMED = 0x01,
|
||||||
@@ -15,7 +12,6 @@ enum ProcAttributes {
|
|||||||
P_NOTIMPLEMENTED = 0x80000000
|
P_NOTIMPLEMENTED = 0x80000000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// VariableAtributes
|
// VariableAtributes
|
||||||
enum VariableAtributes {
|
enum VariableAtributes {
|
||||||
V_GLOBAL = 0x00010000,
|
V_GLOBAL = 0x00010000,
|
||||||
@@ -23,4 +19,4 @@ enum VariableAtributes {
|
|||||||
V_EXPORT = 0x00040000
|
V_EXPORT = 0x00040000
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif //OBJECT_ATTRIBUTES_H
|
||||||
|
|||||||
+48
-39
@@ -1,19 +1,12 @@
|
|||||||
// Opcode.cpp : implementation file
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "Opcode.h"
|
#include "Opcode.h"
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
extern int g_nFalloutVersion;
|
extern int g_nFalloutVersion;
|
||||||
|
|
||||||
|
|
||||||
// COpcode
|
|
||||||
|
|
||||||
COpcode::COpcode() :
|
COpcode::COpcode() :
|
||||||
m_wOperator(O_NOOP),
|
m_wOperator(O_NOOP),
|
||||||
m_ulArgument(0)
|
m_ulArgument(0)
|
||||||
@@ -41,41 +34,47 @@ COpcode& COpcode::operator = (const COpcode& opcode)
|
|||||||
|
|
||||||
void COpcode::Serialize(CArchive& ar)
|
void COpcode::Serialize(CArchive& ar)
|
||||||
{
|
{
|
||||||
if (ReadMSBWord(ar, m_wOperator) != OPERATOR_SIZE) {
|
if (ReadMSBWord(ar, m_wOperator) != OPERATOR_SIZE)
|
||||||
|
{
|
||||||
|
printf("Error: Unable read opcode\n");
|
||||||
|
AfxThrowUserException();
|
||||||
|
}
|
||||||
|
|
||||||
printf("Error: Unable read opcode\n");
|
if ((m_wOperator < O_OPERATOR) ||
|
||||||
|
((m_wOperator >= O_END_OP) &&
|
||||||
|
(m_wOperator != O_STRINGOP) &&
|
||||||
|
(m_wOperator != O_FLOATOP)&&
|
||||||
|
(m_wOperator != O_INTOP)))
|
||||||
|
{
|
||||||
|
ar.Flush();
|
||||||
|
printf("Error: Invalid opcode at 0x%08x\n", ar.GetFile()->GetPosition() - 2);
|
||||||
|
AfxThrowUserException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((m_wOperator == O_STRINGOP) || (m_wOperator == O_FLOATOP) || (m_wOperator == O_INTOP))
|
||||||
|
{
|
||||||
|
if (ReadMSBULong(ar, m_ulArgument) != ARGUMENT_SIZE)
|
||||||
|
{
|
||||||
|
printf("Error: Unable read opcode argument\n");
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ((m_wOperator < O_OPERATOR) ||
|
|
||||||
((m_wOperator >= O_END_OP) &&
|
|
||||||
(m_wOperator != O_STRINGOP) &&
|
|
||||||
(m_wOperator != O_FLOATOP)&&
|
|
||||||
(m_wOperator != O_INTOP))) {
|
|
||||||
ar.Flush();
|
|
||||||
printf("Error: Invalid opcode at 0x%08x\n", ar.GetFile()->GetPosition() - 2);
|
|
||||||
AfxThrowUserException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((m_wOperator == O_STRINGOP) || (m_wOperator == O_FLOATOP) || (m_wOperator == O_INTOP)) {
|
|
||||||
if (ReadMSBULong(ar, m_ulArgument) != ARGUMENT_SIZE) {
|
|
||||||
printf("Error: Unable read opcode argument\n");
|
|
||||||
AfxThrowUserException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void COpcode::Expect(CArchive& ar, WORD wOperator, BOOL bArgumentFound, ULONG ulArgument)
|
void COpcode::Expect(CArchive& ar, WORD wOperator, BOOL bArgumentFound, ULONG ulArgument)
|
||||||
{
|
{
|
||||||
Serialize(ar);
|
Serialize(ar);
|
||||||
|
|
||||||
if (m_wOperator != wOperator) {
|
if (m_wOperator != wOperator)
|
||||||
|
{
|
||||||
printf("Error: Unexpected opcode (0x%04X expected, but 0x%04X found)\n", wOperator, m_wOperator);
|
printf("Error: Unexpected opcode (0x%04X expected, but 0x%04X found)\n", wOperator, m_wOperator);
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bArgumentFound && ((m_wOperator == O_STRINGOP) || (m_wOperator == O_FLOATOP) || (m_wOperator == O_INTOP))) {
|
if (bArgumentFound && ((m_wOperator == O_STRINGOP) || (m_wOperator == O_FLOATOP) || (m_wOperator == O_INTOP)))
|
||||||
if (m_ulArgument != ulArgument) {
|
{
|
||||||
|
if (m_ulArgument != ulArgument)
|
||||||
|
{
|
||||||
printf("Error: Unexpected argument of opcode. (0x%08X expected, but 0x%08X found)\n", ulArgument, m_ulArgument);
|
printf("Error: Unexpected argument of opcode. (0x%08X expected, but 0x%08X found)\n", ulArgument, m_ulArgument);
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
@@ -87,18 +86,23 @@ void COpcode::Expect(CArchive& ar, int nCount, WORD pwOperators[])
|
|||||||
Serialize(ar);
|
Serialize(ar);
|
||||||
BOOL bFound = FALSE;
|
BOOL bFound = FALSE;
|
||||||
|
|
||||||
for(int i = 0; i < nCount; i++) {
|
for(int i = 0; i < nCount; i++)
|
||||||
if (m_wOperator == pwOperators[i]) {
|
{
|
||||||
|
if (m_wOperator == pwOperators[i])
|
||||||
|
{
|
||||||
bFound = TRUE;
|
bFound = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bFound) {
|
if (!bFound)
|
||||||
|
{
|
||||||
printf("Error: Unexpected opcode (");
|
printf("Error: Unexpected opcode (");
|
||||||
|
|
||||||
for(int i = 0; i < nCount; i++) {
|
for(int i = 0; i < nCount; i++)
|
||||||
if (i != 0) {
|
{
|
||||||
|
if (i != 0)
|
||||||
|
{
|
||||||
printf(" or ");
|
printf(" or ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,10 +121,12 @@ BOOL COpcode::HasArgument() const
|
|||||||
|
|
||||||
int COpcode::GetSize() const
|
int COpcode::GetSize() const
|
||||||
{
|
{
|
||||||
if ((m_wOperator == O_STRINGOP) || (m_wOperator == O_FLOATOP) || (m_wOperator == O_INTOP)) {
|
if ((m_wOperator == O_STRINGOP) || (m_wOperator == O_FLOATOP) || (m_wOperator == O_INTOP))
|
||||||
|
{
|
||||||
return OPERATOR_SIZE + ARGUMENT_SIZE;
|
return OPERATOR_SIZE + ARGUMENT_SIZE;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return OPERATOR_SIZE;
|
return OPERATOR_SIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,13 +153,16 @@ const COpcode::COpcodeAttributes COpcode::GetAttributes() const
|
|||||||
|
|
||||||
COpcodeAttributes result;
|
COpcodeAttributes result;
|
||||||
|
|
||||||
if (g_nFalloutVersion == 1) {
|
if (g_nFalloutVersion == 1)
|
||||||
if (f1OpcodeAttributes.Lookup(m_wOperator, result)) {
|
{
|
||||||
|
if (f1OpcodeAttributes.Lookup(m_wOperator, result))
|
||||||
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!f2OpcodeAttributes.Lookup(m_wOperator, result)) {
|
if (!f2OpcodeAttributes.Lookup(m_wOperator, result))
|
||||||
|
{
|
||||||
printf("Error: Attempt to obtain attributes of unknown opcode\n");
|
printf("Error: Attempt to obtain attributes of unknown opcode\n");
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "Hacks/CArchive.h"
|
#include "Hacks/CArchive.h"
|
||||||
#include "Hacks/CMap.h"
|
#include "Hacks/CMap.h"
|
||||||
|
|
||||||
// COpcode
|
|
||||||
class COpcode
|
class COpcode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -21,8 +20,6 @@ public:
|
|||||||
O_OPERATOR = 0x8000
|
O_OPERATOR = 0x8000
|
||||||
};
|
};
|
||||||
|
|
||||||
// const O_IF_EXPR = 1000;
|
|
||||||
|
|
||||||
enum O_Core {
|
enum O_Core {
|
||||||
O_NOOP = O_OPERATOR,
|
O_NOOP = O_OPERATOR,
|
||||||
O_CONST,
|
O_CONST,
|
||||||
@@ -800,13 +797,15 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// CF2OpcodeAttributesMap
|
// CF2OpcodeAttributesMap
|
||||||
class CF2OpcodeAttributesMap : public CMap<WORD, WORD, COpcodeAttributes, const COpcodeAttributes&> {
|
class CF2OpcodeAttributesMap : public CMap<WORD, WORD, COpcodeAttributes, const COpcodeAttributes&>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
CF2OpcodeAttributesMap();
|
CF2OpcodeAttributesMap();
|
||||||
};
|
};
|
||||||
|
|
||||||
// C12OpcodeAttributesMap
|
// C12OpcodeAttributesMap
|
||||||
class CF1OpcodeAttributesMap : public CMap<WORD, WORD, COpcodeAttributes, const COpcodeAttributes&> {
|
class CF1OpcodeAttributesMap : public CMap<WORD, WORD, COpcodeAttributes, const COpcodeAttributes&>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
CF1OpcodeAttributesMap();
|
CF1OpcodeAttributesMap();
|
||||||
};
|
};
|
||||||
@@ -838,7 +837,6 @@ private:
|
|||||||
ULONG m_ulArgument;
|
ULONG m_ulArgument;
|
||||||
};
|
};
|
||||||
|
|
||||||
// COpcodeArray
|
|
||||||
typedef CArray<COpcode, COpcode&> COpcodeArray;
|
typedef CArray<COpcode, COpcode&> COpcodeArray;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-10
@@ -1,15 +1,6 @@
|
|||||||
// OpcodeMnemonic.cpp : COpcode class implementation file
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "Opcode.h"
|
#include "Opcode.h"
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
#define new DEBUG_NEW
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// COpcode::COpcodeAttributes
|
|
||||||
COpcode::COpcodeAttributes::COpcodeAttributes(std::string mnemonic,
|
COpcode::COpcodeAttributes::COpcodeAttributes(std::string mnemonic,
|
||||||
std::string name,
|
std::string name,
|
||||||
ULONG ulNumArgs,
|
ULONG ulNumArgs,
|
||||||
@@ -40,7 +31,8 @@ COpcode::COpcodeAttributes::COpcodeAttributes(const COpcodeAttributes& attribute
|
|||||||
|
|
||||||
COpcode::COpcodeAttributes& COpcode::COpcodeAttributes::operator = (const COpcodeAttributes& attributes)
|
COpcode::COpcodeAttributes& COpcode::COpcodeAttributes::operator = (const COpcodeAttributes& attributes)
|
||||||
{
|
{
|
||||||
if (&attributes != this) {
|
if (&attributes != this)
|
||||||
|
{
|
||||||
m_strMnemonic = attributes.m_strMnemonic;
|
m_strMnemonic = attributes.m_strMnemonic;
|
||||||
m_strName = attributes.m_strName;
|
m_strName = attributes.m_strName;
|
||||||
m_ulNumArgs = attributes.m_ulNumArgs;
|
m_ulNumArgs = attributes.m_ulNumArgs;
|
||||||
|
|||||||
+121
-118
@@ -1,6 +1,3 @@
|
|||||||
// ProcTable.cpp : implementation file
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "ProcTable.h"
|
#include "ProcTable.h"
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
@@ -9,8 +6,6 @@
|
|||||||
#include "Hacks/CString.h"
|
#include "Hacks/CString.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// CProcDescriptor
|
|
||||||
|
|
||||||
CProcDescriptor::CProcDescriptor() :
|
CProcDescriptor::CProcDescriptor() :
|
||||||
m_ulNameOffset(0),
|
m_ulNameOffset(0),
|
||||||
m_ulType(0),
|
m_ulType(0),
|
||||||
@@ -38,7 +33,8 @@ CProcDescriptor::~CProcDescriptor()
|
|||||||
|
|
||||||
CProcDescriptor& CProcDescriptor::operator = (const CProcDescriptor& Item)
|
CProcDescriptor& CProcDescriptor::operator = (const CProcDescriptor& Item)
|
||||||
{
|
{
|
||||||
if (&Item != this) {
|
if (&Item != this)
|
||||||
|
{
|
||||||
m_ulNameOffset = Item.m_ulNameOffset;
|
m_ulNameOffset = Item.m_ulNameOffset;
|
||||||
m_ulType = Item.m_ulType;
|
m_ulType = Item.m_ulType;
|
||||||
m_ulTime = Item.m_ulTime;
|
m_ulTime = Item.m_ulTime;
|
||||||
@@ -52,35 +48,29 @@ CProcDescriptor& CProcDescriptor::operator = (const CProcDescriptor& Item)
|
|||||||
|
|
||||||
void CProcDescriptor::Serialize(CArchive& ar)
|
void CProcDescriptor::Serialize(CArchive& ar)
|
||||||
{
|
{
|
||||||
//if (ar.IsStoring()) {
|
UINT uiTotalRead;
|
||||||
if (false)
|
|
||||||
|
uiTotalRead = ReadMSBULong(ar, m_ulNameOffset);
|
||||||
|
uiTotalRead += ReadMSBULong(ar, m_ulType);
|
||||||
|
uiTotalRead += ReadMSBULong(ar, m_ulTime);
|
||||||
|
uiTotalRead += ReadMSBULong(ar, m_ulExpressionOffset);
|
||||||
|
uiTotalRead += ReadMSBULong(ar, m_ulBodyOffset);
|
||||||
|
uiTotalRead += ReadMSBULong(ar, m_ulNumArgs);
|
||||||
|
|
||||||
|
// printf("=================\n");
|
||||||
|
// printf("uiTotalRead = %u\n", uiTotalRead);
|
||||||
|
// printf("m_ulNameOffset = 0x%08X\n", m_ulNameOffset);
|
||||||
|
// printf("m_ulType = 0x%08X\n", m_ulType);
|
||||||
|
// printf("m_ulTime = 0x%08X\n", m_ulTime);
|
||||||
|
// printf("m_ulExpressionOffset = 0x%08X\n", m_ulExpressionOffset);
|
||||||
|
// printf("m_ulBodyOffset = 0x%08X\n", m_ulBodyOffset);
|
||||||
|
// printf("m_ulNumArgs = 0x%08X\n", m_ulNumArgs);
|
||||||
|
|
||||||
|
|
||||||
|
if (uiTotalRead != (sizeof(ULONG) * 6))
|
||||||
{
|
{
|
||||||
// ASSERT(FALSE);
|
printf("Error: Unable read procedure descriptor\n");
|
||||||
}
|
AfxThrowUserException();
|
||||||
else {
|
|
||||||
UINT uiTotalRead;
|
|
||||||
|
|
||||||
uiTotalRead = ReadMSBULong(ar, m_ulNameOffset);
|
|
||||||
uiTotalRead += ReadMSBULong(ar, m_ulType);
|
|
||||||
uiTotalRead += ReadMSBULong(ar, m_ulTime);
|
|
||||||
uiTotalRead += ReadMSBULong(ar, m_ulExpressionOffset);
|
|
||||||
uiTotalRead += ReadMSBULong(ar, m_ulBodyOffset);
|
|
||||||
uiTotalRead += ReadMSBULong(ar, m_ulNumArgs);
|
|
||||||
|
|
||||||
// printf("=================\n");
|
|
||||||
// printf("uiTotalRead = %u\n", uiTotalRead);
|
|
||||||
// printf("m_ulNameOffset = 0x%08X\n", m_ulNameOffset);
|
|
||||||
// printf("m_ulType = 0x%08X\n", m_ulType);
|
|
||||||
// printf("m_ulTime = 0x%08X\n", m_ulTime);
|
|
||||||
// printf("m_ulExpressionOffset = 0x%08X\n", m_ulExpressionOffset);
|
|
||||||
// printf("m_ulBodyOffset = 0x%08X\n", m_ulBodyOffset);
|
|
||||||
// printf("m_ulNumArgs = 0x%08X\n", m_ulNumArgs);
|
|
||||||
|
|
||||||
|
|
||||||
if (uiTotalRead != (sizeof(ULONG) * 6)) {
|
|
||||||
printf("Error: Unable read procedure descriptor\n");
|
|
||||||
AfxThrowUserException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +108,8 @@ void CProcDescriptor::Dump(CArchive& ar)
|
|||||||
|
|
||||||
strType += ")";
|
strType += ")";
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
strType = "No special types";
|
strType = "No special types";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,20 +148,26 @@ int compareProcBodyOffsets(const void* elem0, const void* elem1)
|
|||||||
ProcBodyOffset offset0 = *((ProcBodyOffset*)elem0);
|
ProcBodyOffset offset0 = *((ProcBodyOffset*)elem0);
|
||||||
ProcBodyOffset offset1 = *((ProcBodyOffset*)elem1);
|
ProcBodyOffset offset1 = *((ProcBodyOffset*)elem1);
|
||||||
|
|
||||||
if (offset0.m_ulBodyOffset < offset1.m_ulBodyOffset) {
|
if (offset0.m_ulBodyOffset < offset1.m_ulBodyOffset)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (offset0.m_ulBodyOffset > offset1.m_ulBodyOffset) {
|
else if (offset0.m_ulBodyOffset > offset1.m_ulBodyOffset)
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (offset0.m_ulProcIndex < offset1.m_ulProcIndex) {
|
{
|
||||||
|
if (offset0.m_ulProcIndex < offset1.m_ulProcIndex)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (offset0.m_ulProcIndex > offset1.m_ulProcIndex) {
|
else if (offset0.m_ulProcIndex > offset1.m_ulProcIndex)
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,91 +175,95 @@ int compareProcBodyOffsets(const void* elem0, const void* elem1)
|
|||||||
|
|
||||||
void CProcTable::Serialize(CArchive& ar)
|
void CProcTable::Serialize(CArchive& ar)
|
||||||
{
|
{
|
||||||
//if (ar.IsStoring()) {
|
m_Table.RemoveAll();
|
||||||
if(false)
|
m_ProcSize.RemoveAll();
|
||||||
|
|
||||||
|
ULONG ulSizeOfTable;
|
||||||
|
ULONG ulRead;
|
||||||
|
|
||||||
|
ar.Flush();
|
||||||
|
ULONG ulSizeOfFile = ULONG(ar.GetFile()->GetLength());
|
||||||
|
|
||||||
|
ulRead = ReadMSBULong(ar, ulSizeOfTable);
|
||||||
|
|
||||||
|
if (ulRead != sizeof(ulSizeOfTable))
|
||||||
{
|
{
|
||||||
// ASSERT(FALSE);
|
printf("Error: Unable read size of procedures table\n");
|
||||||
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
m_Table.RemoveAll();
|
|
||||||
m_ProcSize.RemoveAll();
|
|
||||||
|
|
||||||
ULONG ulSizeOfTable;
|
m_Table.SetSize(ulSizeOfTable);
|
||||||
ULONG ulRead;
|
m_ProcSize.SetSize(ulSizeOfTable);
|
||||||
|
|
||||||
ar.Flush();
|
ULONG ulIndexOfProcOffset = 0;
|
||||||
ULONG ulSizeOfFile = ULONG(ar.GetFile()->GetLength());
|
ProcBodyOffset* pOffsets = new ProcBodyOffset[ulSizeOfTable + 1];
|
||||||
|
|
||||||
ulRead = ReadMSBULong(ar, ulSizeOfTable);
|
if (pOffsets == NULL)
|
||||||
|
{
|
||||||
|
// AfxThrowMemoryException();
|
||||||
|
throw 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (ulRead != sizeof(ulSizeOfTable))
|
for(ULONG i = 0; i < ulSizeOfTable; i++)
|
||||||
|
{
|
||||||
|
// printf("======== %u =========\n", i);
|
||||||
|
m_Table.at(i).Serialize(ar);
|
||||||
|
m_ProcSize.at(i) = 0; // Initialize size of procedure
|
||||||
|
|
||||||
|
if (!(m_Table.at(i).m_ulType & P_IMPORT))
|
||||||
{
|
{
|
||||||
printf("Error: Unable read size of procedures table\n");
|
if ((m_Table.at(i).m_ulBodyOffset != 0) && (m_Table.at(i).m_ulBodyOffset != ulSizeOfFile))
|
||||||
|
{
|
||||||
|
pOffsets[ulIndexOfProcOffset].m_ulProcIndex = i;
|
||||||
|
pOffsets[ulIndexOfProcOffset].m_ulBodyOffset = m_Table.at(i).m_ulBodyOffset;
|
||||||
|
ulIndexOfProcOffset++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_Table.at(i).m_ulType |= P_NOTIMPLEMENTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pOffsets[ulIndexOfProcOffset].m_ulProcIndex = ulIndexOfProcOffset + 1;
|
||||||
|
pOffsets[ulIndexOfProcOffset].m_ulBodyOffset = ulSizeOfFile;
|
||||||
|
|
||||||
|
qsort(pOffsets, ulIndexOfProcOffset, sizeof(ProcBodyOffset), compareProcBodyOffsets);
|
||||||
|
|
||||||
|
// Sizes of procedures
|
||||||
|
for(ULONG i = 0; i < ulIndexOfProcOffset; i++)
|
||||||
|
{
|
||||||
|
if (pOffsets[i + 1].m_ulBodyOffset >= pOffsets[i].m_ulBodyOffset)
|
||||||
|
{
|
||||||
|
m_ProcSize.at(pOffsets[i].m_ulProcIndex) = pOffsets[i + 1].m_ulBodyOffset - pOffsets[i].m_ulBodyOffset;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Error: Procedures are not sorted in ascending address order\n");
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Table.SetSize(ulSizeOfTable);
|
|
||||||
m_ProcSize.SetSize(ulSizeOfTable);
|
|
||||||
|
|
||||||
ULONG ulIndexOfProcOffset = 0;
|
|
||||||
ProcBodyOffset* pOffsets = new ProcBodyOffset[ulSizeOfTable + 1];
|
|
||||||
|
|
||||||
if (pOffsets == NULL) {
|
|
||||||
// AfxThrowMemoryException();
|
|
||||||
throw 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(ULONG i = 0; i < ulSizeOfTable; i++) {
|
|
||||||
// printf("======== %u =========\n", i);
|
|
||||||
m_Table.at(i).Serialize(ar);
|
|
||||||
m_ProcSize.at(i) = 0; // Initialize size of procedure
|
|
||||||
|
|
||||||
if (!(m_Table.at(i).m_ulType & P_IMPORT)) {
|
|
||||||
if ((m_Table.at(i).m_ulBodyOffset != 0) && (m_Table.at(i).m_ulBodyOffset != ulSizeOfFile)) {
|
|
||||||
pOffsets[ulIndexOfProcOffset].m_ulProcIndex = i;
|
|
||||||
pOffsets[ulIndexOfProcOffset].m_ulBodyOffset = m_Table.at(i).m_ulBodyOffset;
|
|
||||||
ulIndexOfProcOffset++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_Table.at(i).m_ulType |= P_NOTIMPLEMENTED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pOffsets[ulIndexOfProcOffset].m_ulProcIndex = ulIndexOfProcOffset + 1;
|
|
||||||
pOffsets[ulIndexOfProcOffset].m_ulBodyOffset = ulSizeOfFile;
|
|
||||||
|
|
||||||
qsort(pOffsets, ulIndexOfProcOffset, sizeof(ProcBodyOffset), compareProcBodyOffsets);
|
|
||||||
|
|
||||||
// Sizes of procedures
|
|
||||||
for(ULONG i = 0; i < ulIndexOfProcOffset; i++) {
|
|
||||||
if (pOffsets[i + 1].m_ulBodyOffset >= pOffsets[i].m_ulBodyOffset) {
|
|
||||||
m_ProcSize.at(pOffsets[i].m_ulProcIndex) = pOffsets[i + 1].m_ulBodyOffset - pOffsets[i].m_ulBodyOffset;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("Error: Procedures are not sorted in ascending address order\n");
|
|
||||||
AfxThrowUserException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete [] pOffsets;
|
|
||||||
|
|
||||||
for(ULONG i = 0; i < ulSizeOfTable; i++) {
|
|
||||||
if (m_Table.at(i).m_ulBodyOffset != 0) {
|
|
||||||
m_ulOffsetOfProcSection = m_Table.at(i).m_ulBodyOffset;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// // For debugging only
|
|
||||||
// printf("Total: %d\n", m_Table.GetSize());
|
|
||||||
//
|
|
||||||
// for(i = 0; i < ulSizeOfTable; i++) {
|
|
||||||
// printf("Offset: 0x%08X, size: 0x%08X\n", m_Table.at(i).m_ulBodyOffset, m_ProcSize.at(i));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// printf("m_ulOffsetOfProcSection: 0x%08X\n", m_ulOffsetOfProcSection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete [] pOffsets;
|
||||||
|
|
||||||
|
for(ULONG i = 0; i < ulSizeOfTable; i++)
|
||||||
|
{
|
||||||
|
if (m_Table.at(i).m_ulBodyOffset != 0)
|
||||||
|
{
|
||||||
|
m_ulOffsetOfProcSection = m_Table.at(i).m_ulBodyOffset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// // For debugging only
|
||||||
|
// printf("Total: %d\n", m_Table.GetSize());
|
||||||
|
|
||||||
|
// for(i = 0; i < ulSizeOfTable; i++)
|
||||||
|
// {
|
||||||
|
// printf("Offset: 0x%08X, size: 0x%08X\n", m_Table.at(i).m_ulBodyOffset, m_ProcSize.at(i));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// printf("m_ulOffsetOfProcSection: 0x%08X\n", m_ulOffsetOfProcSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
INT_PTR CProcTable::GetSize()
|
INT_PTR CProcTable::GetSize()
|
||||||
@@ -272,7 +273,8 @@ INT_PTR CProcTable::GetSize()
|
|||||||
|
|
||||||
ULONG CProcTable::GetSizeOfProc(INT_PTR nIndex)
|
ULONG CProcTable::GetSizeOfProc(INT_PTR nIndex)
|
||||||
{
|
{
|
||||||
if ((nIndex < 0) || (nIndex > m_ProcSize.GetUpperBound())) {
|
if ((nIndex < 0) || (nIndex > m_ProcSize.GetUpperBound()))
|
||||||
|
{
|
||||||
printf("Warning: Invalid index of procedure (%d). Exception will be thrown\n", nIndex);
|
printf("Warning: Invalid index of procedure (%d). Exception will be thrown\n", nIndex);
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
@@ -303,7 +305,8 @@ void CProcTable::Dump(CArchive& ar)
|
|||||||
|
|
||||||
CProcDescriptor& CProcTable::operator [] (INT_PTR nIndex)
|
CProcDescriptor& CProcTable::operator [] (INT_PTR nIndex)
|
||||||
{
|
{
|
||||||
if ((nIndex < 0) || (nIndex > m_ProcSize.GetUpperBound())) {
|
if ((nIndex < 0) || (nIndex > m_ProcSize.GetUpperBound()))
|
||||||
|
{
|
||||||
printf("Warning: Invalid index of procedure (%d). Exception will be thrown\n", nIndex);
|
printf("Warning: Invalid index of procedure (%d). Exception will be thrown\n", nIndex);
|
||||||
AfxThrowUserException();
|
AfxThrowUserException();
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -6,7 +6,8 @@
|
|||||||
#include "Hacks/CArchive.h"
|
#include "Hacks/CArchive.h"
|
||||||
|
|
||||||
// CProcDescriptor
|
// CProcDescriptor
|
||||||
class CProcDescriptor : public CObject {
|
class CProcDescriptor
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
CProcDescriptor();
|
CProcDescriptor();
|
||||||
CProcDescriptor(const CProcDescriptor& Item);
|
CProcDescriptor(const CProcDescriptor& Item);
|
||||||
@@ -29,9 +30,8 @@ public:
|
|||||||
ULONG m_ulNumArgs; // Number of args to procedure
|
ULONG m_ulNumArgs; // Number of args to procedure
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CProcTable
|
||||||
// CProcTable
|
{
|
||||||
class CProcTable : public CObject {
|
|
||||||
public:
|
public:
|
||||||
CProcTable();
|
CProcTable();
|
||||||
virtual ~CProcTable();
|
virtual ~CProcTable();
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef STARTUP_CODE_H
|
#ifndef STARTUP_CODE_H
|
||||||
#define STARTUP_CODE_H
|
#define STARTUP_CODE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef UTILITY_H
|
#ifndef UTILITY_H
|
||||||
#define UTILITY_H
|
#define UTILITY_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
CObject::CObject()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AfxThrowUserException()
|
void AfxThrowUserException()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user