mirror of
https://github.com/sfall-team/int2ssl.git
synced 2026-07-27 16:52:42 -07:00
CString::operator== implemented
This commit is contained in:
+167
-173
@@ -26,193 +26,187 @@ CFalloutScript::~CFalloutScript()
|
||||
void CFalloutScript::Serialize(CArchive& ar)
|
||||
{
|
||||
|
||||
//if (ar.IsStoring()) {
|
||||
if (false)
|
||||
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())
|
||||
{
|
||||
// ASSERT(FALSE);
|
||||
}
|
||||
else {
|
||||
printf(" Read strtup code\n");
|
||||
m_StartupCode.Serialize(ar);
|
||||
opcode.Serialize(ar);
|
||||
ullCurrentOffset += opcode.GetSize();
|
||||
HeaderTail.Add(opcode);
|
||||
}
|
||||
|
||||
printf(" Read procedures table\n");
|
||||
m_ProcTable.Serialize(ar);
|
||||
// Jump to 'start' procedure
|
||||
printf(" Check \"Jump to \'start\' procedure\" / \"Jump to end of statup code\"\n");
|
||||
|
||||
printf(" Read namespace\n");
|
||||
m_Namespace.Serialize(ar);
|
||||
if (!HeaderTail.IsEmpty())
|
||||
{
|
||||
INT_PTR nIndexOfStart = GetIndexOfProc("start");
|
||||
ULONG ulStartProcAddress = (nIndexOfStart != -1) ? m_ProcTable[nIndexOfStart].m_ulBodyOffset : 18;
|
||||
|
||||
printf(" Read stringspace\n");
|
||||
m_Stringspace.Serialize(ar);
|
||||
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
||||
|
||||
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())
|
||||
if (opcode.GetOperator() == COpcode::O_JMP)
|
||||
{
|
||||
INT_PTR nIndexOfStart = GetIndexOfProc("start");
|
||||
ULONG ulStartProcAddress = (nIndexOfStart != -1) ? m_ProcTable[nIndexOfStart].m_ulBodyOffset : 18;
|
||||
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
||||
|
||||
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
||||
|
||||
if (opcode.GetOperator() == COpcode::O_JMP)
|
||||
if (HeaderTail.IsEmpty())
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printf("Warning: Omitted address of jump\n");
|
||||
printf("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n");
|
||||
printf("Warning: Omitted \"Jump to \'start\' procedure\" / \"Jump to end of statup code\"\n");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
opcode = HeaderTail.at(HeaderTail.GetUpperBound());
|
||||
|
||||
// # of argument to 'start' procedure
|
||||
printf(" Check \"# of argument to \'start\' procedure\"\n");
|
||||
if (opcode.GetOperator() == COpcode::O_INTOP)
|
||||
{
|
||||
HeaderTail.RemoveAt(HeaderTail.GetUpperBound());
|
||||
|
||||
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++)
|
||||
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(" 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);
|
||||
printf("\n");
|
||||
printf("Warning: Omitted \"Jump to \'start\' procedure\" / \"Jump to end of statup code\"\n");
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
// # 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))
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ private:
|
||||
BOOL CheckSetExportedVarValueCode(WORD wOperator, INT_PTR nIndex);
|
||||
BOOL CheckExportProcCode(WORD wOperator, INT_PTR nIndex);
|
||||
|
||||
INT_PTR GetIndexOfProc(LPCTSTR lpszName);
|
||||
INT_PTR GetIndexOfProc(const char* lpszName);
|
||||
INT_PTR GetIndexOfProc(ULONG ulNameOffset);
|
||||
INT_PTR GetIndexOfExportedVariable(ULONG ulNameOffset);
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ void CFalloutScript::ProcessCode()
|
||||
TryRenameImportedVariables();
|
||||
}
|
||||
|
||||
INT_PTR CFalloutScript::GetIndexOfProc(LPCTSTR lpszName)
|
||||
INT_PTR CFalloutScript::GetIndexOfProc(const char* lpszName)
|
||||
{
|
||||
INT_PTR nResult = -1;
|
||||
CString strName(lpszName);
|
||||
@@ -123,8 +123,10 @@ INT_PTR CFalloutScript::GetIndexOfProc(ULONG ulNameOffset)
|
||||
{
|
||||
INT_PTR nResult = -1;
|
||||
|
||||
for(INT_PTR i = 0; i < m_ProcTable.GetSize(); i++) {
|
||||
if (m_ProcTable[i].m_ulNameOffset == ulNameOffset) {
|
||||
for(INT_PTR i = 0; i < m_ProcTable.GetSize(); i++)
|
||||
{
|
||||
if (m_ProcTable[i].m_ulNameOffset == ulNameOffset)
|
||||
{
|
||||
nResult = i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// FalloutScript.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "FalloutScript.h"
|
||||
|
||||
@@ -30,15 +27,19 @@ void CFalloutScript::Dump(CArchive& ar)
|
||||
|
||||
ar.WriteString("============== Global variables values ==================\n");
|
||||
|
||||
if (m_GlobalVar.IsEmpty()) {
|
||||
if (m_GlobalVar.IsEmpty())
|
||||
{
|
||||
ar.WriteString("Not found\n");
|
||||
}
|
||||
else {
|
||||
for(INT_PTR i = 0; i < m_GlobalVar.GetSize(); i++) {
|
||||
else
|
||||
{
|
||||
for(unsigned int i = 0; i < m_GlobalVar.GetSize(); i++)
|
||||
{
|
||||
wOperator = m_GlobalVar.at(i).GetOperator();
|
||||
ulArgument = m_GlobalVar.at(i).GetArgument();
|
||||
|
||||
switch(wOperator) {
|
||||
switch(wOperator)
|
||||
{
|
||||
case COpcode::O_STRINGOP:
|
||||
case COpcode::O_INTOP:
|
||||
strOutLine.Format("%d: %s(0x%08x) // %u (%d)\n",
|
||||
|
||||
@@ -44,6 +44,11 @@ CString& CString::operator+(const char* value)
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool CString::operator==(CString& other)
|
||||
{
|
||||
return _string == other._string;
|
||||
}
|
||||
|
||||
CString::operator const char* () const
|
||||
{
|
||||
return _string.c_str();
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
|
||||
const char* c_str() const;
|
||||
CString& operator=(const char* value);
|
||||
bool operator==(CString& other);
|
||||
CString& operator+=(const char* value);
|
||||
CString& operator+(const char* value);
|
||||
operator const char* () const;
|
||||
|
||||
-10
@@ -41,21 +41,12 @@ COpcode& COpcode::operator = (const COpcode& opcode)
|
||||
|
||||
void COpcode::Serialize(CArchive& ar)
|
||||
{
|
||||
//if (ar.IsStoring()) {
|
||||
if (false)
|
||||
{
|
||||
// ASSERT(FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ReadMSBWord(ar, m_wOperator) != OPERATOR_SIZE) {
|
||||
|
||||
printf("Error: Unable read opcode\n");
|
||||
AfxThrowUserException();
|
||||
}
|
||||
|
||||
std::cout << std::hex << m_wOperator << std::endl;
|
||||
|
||||
if ((m_wOperator < O_OPERATOR) ||
|
||||
((m_wOperator >= O_END_OP) &&
|
||||
(m_wOperator != O_STRINGOP) &&
|
||||
@@ -72,7 +63,6 @@ void COpcode::Serialize(CArchive& ar)
|
||||
AfxThrowUserException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void COpcode::Expect(CArchive& ar, WORD wOperator, BOOL bArgumentFound, ULONG ulArgument)
|
||||
|
||||
Reference in New Issue
Block a user