2013-10-27 04:21:49 +00:00
|
|
|
#pragma once
|
2006-06-15 04:19:30 +00:00
|
|
|
|
|
|
|
#include "Types.h"
|
2006-10-12 06:16:48 +00:00
|
|
|
#include <map>
|
2012-05-21 06:31:50 +00:00
|
|
|
#include <vector>
|
2015-04-20 01:46:41 -04:00
|
|
|
#include <functional>
|
2022-09-11 17:32:15 -04:00
|
|
|
#include <string>
|
2006-06-15 04:19:30 +00:00
|
|
|
|
|
|
|
class CMIPS;
|
|
|
|
|
|
|
|
class CMIPSAnalysis
|
|
|
|
{
|
|
|
|
public:
|
2006-10-12 06:16:48 +00:00
|
|
|
struct SUBROUTINE
|
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
uint32 start;
|
|
|
|
uint32 end;
|
|
|
|
uint32 stackAllocStart;
|
|
|
|
uint32 stackAllocEnd;
|
|
|
|
uint32 stackSize;
|
|
|
|
uint32 returnAddrPos;
|
2006-10-12 06:16:48 +00:00
|
|
|
};
|
|
|
|
|
2012-05-24 05:57:31 +00:00
|
|
|
typedef std::vector<uint32> CallStackItemArray;
|
2012-05-21 06:31:50 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
CMIPSAnalysis(CMIPS*);
|
|
|
|
void Analyse(uint32, uint32, uint32 = -1);
|
|
|
|
const SUBROUTINE* FindSubroutine(uint32) const;
|
|
|
|
void Clear();
|
2012-04-01 00:47:39 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void InsertSubroutine(uint32, uint32, uint32, uint32, uint32, uint32);
|
|
|
|
void ChangeSubroutineStart(uint32, uint32);
|
|
|
|
void ChangeSubroutineEnd(uint32, uint32);
|
2013-10-27 04:21:49 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
static CallStackItemArray GetCallStack(CMIPS*, uint32 pc, uint32 sp, uint32 ra);
|
2022-09-10 12:07:01 -04:00
|
|
|
static bool TryGetStringAtAddress(CMIPS*, uint32, std::string&);
|
2023-11-04 21:18:49 -04:00
|
|
|
static bool TryGetSJISLatinStringAtAddress(CMIPS*, uint32, std::string&);
|
2012-05-21 06:31:50 +00:00
|
|
|
|
2006-06-15 04:19:30 +00:00
|
|
|
private:
|
2012-04-01 00:47:39 +00:00
|
|
|
typedef std::map<uint32, SUBROUTINE, std::greater<uint32>> SubroutineList;
|
2006-10-12 06:16:48 +00:00
|
|
|
|
2024-03-20 19:51:12 -04:00
|
|
|
uint32 GetInstruction(uint32) const;
|
2024-03-21 11:44:24 -04:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void AnalyseSubroutines(uint32, uint32, uint32);
|
|
|
|
void AnalyseStringReferences();
|
2013-02-05 03:37:58 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
void FindSubroutinesByStackAllocation(uint32, uint32);
|
|
|
|
void FindSubroutinesByJumpTargets(uint32, uint32, uint32);
|
|
|
|
void ExpandSubroutines(uint32, uint32);
|
2014-08-16 21:27:09 -04:00
|
|
|
|
2024-03-20 19:51:12 -04:00
|
|
|
CMIPS* m_ctx = nullptr;
|
2018-04-30 21:01:23 +01:00
|
|
|
SubroutineList m_subroutines;
|
2006-06-15 04:19:30 +00:00
|
|
|
};
|