Code formating

This commit is contained in:
alexeevdv
2015-02-14 14:38:14 +03:00
parent fc7d3e31ac
commit db90d25ea6
20 changed files with 890 additions and 727 deletions
+121 -118
View File
@@ -1,6 +1,3 @@
// ProcTable.cpp : implementation file
//
#include "stdafx.h"
#include "ProcTable.h"
#include "Utility.h"
@@ -9,8 +6,6 @@
#include "Hacks/CString.h"
#include <iostream>
// CProcDescriptor
CProcDescriptor::CProcDescriptor() :
m_ulNameOffset(0),
m_ulType(0),
@@ -38,7 +33,8 @@ CProcDescriptor::~CProcDescriptor()
CProcDescriptor& CProcDescriptor::operator = (const CProcDescriptor& Item)
{
if (&Item != this) {
if (&Item != this)
{
m_ulNameOffset = Item.m_ulNameOffset;
m_ulType = Item.m_ulType;
m_ulTime = Item.m_ulTime;
@@ -52,35 +48,29 @@ CProcDescriptor& CProcDescriptor::operator = (const CProcDescriptor& Item)
void CProcDescriptor::Serialize(CArchive& ar)
{
//if (ar.IsStoring()) {
if (false)
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))
{
// ASSERT(FALSE);
}
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();
}
printf("Error: Unable read procedure descriptor\n");
AfxThrowUserException();
}
}
@@ -118,7 +108,8 @@ void CProcDescriptor::Dump(CArchive& ar)
strType += ")";
}
else {
else
{
strType = "No special types";
}
@@ -157,20 +148,26 @@ int compareProcBodyOffsets(const void* elem0, const void* elem1)
ProcBodyOffset offset0 = *((ProcBodyOffset*)elem0);
ProcBodyOffset offset1 = *((ProcBodyOffset*)elem1);
if (offset0.m_ulBodyOffset < offset1.m_ulBodyOffset) {
if (offset0.m_ulBodyOffset < offset1.m_ulBodyOffset)
{
return -1;
}
else if (offset0.m_ulBodyOffset > offset1.m_ulBodyOffset) {
else if (offset0.m_ulBodyOffset > offset1.m_ulBodyOffset)
{
return 1;
}
else {
if (offset0.m_ulProcIndex < offset1.m_ulProcIndex) {
else
{
if (offset0.m_ulProcIndex < offset1.m_ulProcIndex)
{
return -1;
}
else if (offset0.m_ulProcIndex > offset1.m_ulProcIndex) {
else if (offset0.m_ulProcIndex > offset1.m_ulProcIndex)
{
return 1;
}
else {
else
{
return 0;
}
}
@@ -178,91 +175,95 @@ int compareProcBodyOffsets(const void* elem0, const void* elem1)
void CProcTable::Serialize(CArchive& ar)
{
//if (ar.IsStoring()) {
if(false)
m_Table.RemoveAll();
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;
ULONG ulRead;
m_Table.SetSize(ulSizeOfTable);
m_ProcSize.SetSize(ulSizeOfTable);
ar.Flush();
ULONG ulSizeOfFile = ULONG(ar.GetFile()->GetLength());
ULONG ulIndexOfProcOffset = 0;
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();
}
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()
@@ -272,7 +273,8 @@ INT_PTR CProcTable::GetSize()
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);
AfxThrowUserException();
}
@@ -303,7 +305,8 @@ void CProcTable::Dump(CArchive& ar)
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);
AfxThrowUserException();
}