Skip to content

Commit

Permalink
Bridge to IDA: errors fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
crypto2011 authored Sep 12, 2021
1 parent ffa11a7 commit 35c7dd8
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 19 deletions.
9 changes: 7 additions & 2 deletions Infos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,12 @@ String __fastcall InfoRec::MakeCppPrototype(int Adr, String FType)
if (kind == ikFunc)
{
if (type != "")
result = TrimTypeName(type);
{
result = SanitizeName(TrimTypeName(type));
typeKind = GetTypeKind(result, &size);
if (typeKind == ikRecord || typeKind == ikVMT)
result = "struct " + result + "*";
}
else
result = "DWORD";
}
Expand All @@ -1659,7 +1664,7 @@ String __fastcall InfoRec::MakeCppPrototype(int Adr, String FType)
typeKind = GetTypeKind(argType, &size);
if (typeKind == ikRecord || typeKind == ikVMT)
result += "struct ";
result += argType;
result += SanitizeName(argType);
if (typeKind == ikVMT)
result += "*";
}
Expand Down
73 changes: 68 additions & 5 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13575,6 +13575,7 @@ CPPvsDELPHIdecl ForwardDeclarations[] = {
{"wchar_t*", "string"},
{"wchar_t*", "WideString"},
{"wchar_t*", "UString"},
{"wchar_t*", "UnicodeString"},
{"wchar_t", "Char"},
{"wchar_t", "WideChar"},
{"void*", "Pointer"},
Expand Down Expand Up @@ -13720,6 +13721,7 @@ void __fastcall TFMain_11011981::OutputForwardDeclarationsOfKind(FILE* hF, BYTE
break;
case ikRecord:
case ikClass:
case ikMethod:
fprintf(hF, "struct %s;\n", RTTIName.c_str());
break;
case ikPointer:
Expand All @@ -13730,8 +13732,6 @@ void __fastcall TFMain_11011981::OutputForwardDeclarationsOfKind(FILE* hF, BYTE
break;
case ikProcedure:
break;
case ikMethod:
break;
case ikInterface:
fprintf(hF, "struct %s_vt\n", RTTIName.c_str());
fprintf(hF, "{\n");
Expand All @@ -13749,16 +13749,41 @@ void __fastcall TFMain_11011981::OutputForwardDeclarationsOfKind(FILE* hF, BYTE
}
}
//---------------------------------------------------------------------------
typedef struct _VMT_PROC
{
DWORD Adr;
int CurIdx;
BYTE Multiple;
} VMT_PROC, *PVMT_PROC;
//---------------------------------------------------------------------------
PVMT_PROC __fastcall GetProcFromVmtList(TList* list, DWORD procAdr)
{
PVMT_PROC Result = 0;

for (int n = 0; n < list->Count; n++)
{
PVMT_PROC vmtProc = (PVMT_PROC)list->Items[n];
if (vmtProc->Adr == procAdr)
{
Result = vmtProc;
break;
}
}
return Result;
}
//---------------------------------------------------------------------------
void __fastcall TFMain_11011981::CreateCppHeaderFile(FILE* hF)
{
BYTE len, RTTIKind;
int n, m, id, adr, kind, pos, size, sort, virtNum;
int n, m, id, adr, kind, pos, size, sort, virtNum, idx;
PUnitRec recU;
PInfoRec recN;
String unitName, RTTIName, str, name;
PFIELDINFO fInfo;
TList* virtList;
TList* vmtProcs;
PMethodRec recM;
PVMT_PROC vmtProc;

//Save sort style
sort = RTTISortField;
Expand Down Expand Up @@ -13788,6 +13813,8 @@ void __fastcall TFMain_11011981::CreateCppHeaderFile(FILE* hF)
OutputForwardDeclarationsOfKind(hF, ikClass);
fprintf(hF, "//<Record>\n");
OutputForwardDeclarationsOfKind(hF, ikRecord);
fprintf(hF, "//<Method>\n");
OutputForwardDeclarationsOfKind(hF, ikMethod);
fprintf(hF, "//<Interface>\n");
OutputForwardDeclarationsOfKind(hF, ikInterface);
//Restore old sort style
Expand Down Expand Up @@ -13913,6 +13940,28 @@ void __fastcall TFMain_11011981::CreateCppHeaderFile(FILE* hF)
//Output virtual functions
virtList = new TList;
virtNum = LoadVirtualTable(adr, virtList);
//Fill VMT_PROCS list
vmtProcs = new TList;
for (m = 0, id = 0; m < virtNum; m++)
{
recM = (PMethodRec)virtList->Items[m];
if (recM->id >= 0)
{
vmtProc = GetProcFromVmtList(vmtProcs, recM->address);
if (!vmtProc)
{
vmtProc = new VMT_PROC;
vmtProc->Adr = recM->address;
vmtProc->CurIdx = 0;
vmtProc->Multiple = 0;
vmtProcs->Add((void*)vmtProc);
}
else
{
vmtProc->Multiple = 1;
}
}
}
//Output function prorotype declarations
for (m = 0, id = 0; m < virtNum; m++)
{
Expand Down Expand Up @@ -13943,17 +13992,30 @@ void __fastcall TFMain_11011981::CreateCppHeaderFile(FILE* hF)
{
name = recM->name;
recN = GetInfoRec(recM->address);
vmtProc = GetProcFromVmtList(vmtProcs, recM->address);
idx = -1;
if (vmtProc && vmtProc->Multiple)
{
idx = vmtProc->CurIdx;
vmtProc->CurIdx++;
}
if (recN)
{
if (name == "")
name = recN->GetName();
fprintf(hF, "P%s_m%lX sub_%08lX;", RTTIName.c_str(), id, recM->address);
fprintf(hF, "P%s_m%lX %s_sub_%08lX", RTTIName.c_str(), id, RTTIName.c_str(), recM->address);
if (idx >= 0)
fprintf(hF, "_%d", idx);
fprintf(hF, ";");
if (name != "")
fprintf(hF, "//%s", name.c_str());
}
else
{
fprintf(hF, "P%s_m%lX sub_%08lX;", RTTIName.c_str(), id, recM->address);
fprintf(hF, "P%s_m%lX %s_sub_%08lX", RTTIName.c_str(), id, RTTIName.c_str(), recM->address);
if (idx >= 0)
fprintf(hF, "_%d", idx);
fprintf(hF, ";");
if (name != "")
fprintf(hF, "//%s", name.c_str());
}
Expand All @@ -13962,6 +14024,7 @@ void __fastcall TFMain_11011981::CreateCppHeaderFile(FILE* hF)
}
}
fprintf(hF, "};\n\n");
delete vmtProcs;
delete virtList;

//Output fields
Expand Down
31 changes: 19 additions & 12 deletions TypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
typeKind = GetTypeKind(typname, &size);
if (typeKind == ikVMT || typeKind == ikProcedure)
result += "struct ";
result += typname;
result += SanitizeName(typname);
if (typeKind == ikVMT)
result += "*";
if (paramFlags & PfVar)
Expand All @@ -1440,9 +1440,9 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
}
typeKind = GetTypeKind(name, &size);
if (typeKind == ikVMT)
result = name + "* " + result;
result = SanitizeName(name) + "* " + result;
else
result = name + " " + result;
result = SanitizeName(name) + " " + result;
}
if (DelphiVersion > 6)
{
Expand Down Expand Up @@ -1486,7 +1486,7 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
typeKind = GetTypeKind(typname, &size);
if (typeKind == ikVMT || typeKind == ikProcedure)
result += "struct ";
result += typname;
result += SanitizeName(typname);
if (typeKind == ikVMT)
result += "*";
if (paramFlags & PfVar)
Expand All @@ -1502,9 +1502,9 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
typname = GetTypeName(resultTypeAdr);
typeKind = GetTypeKind(typname, &size);
if (typeKind == ikVMT)
result = typname + "* " + result;
result = SanitizeName(typname) + "* " + result;
else
result = typname + " " + result;
result = SanitizeName(typname) + " " + result;
}
}
}
Expand Down Expand Up @@ -1713,7 +1713,7 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
if (typeKind == ikInterface) size = 4;
if (typeKind == ikRecord || typeKind == ikVMT)
result += "struct ";
result += FieldInfo->Type;
result += SanitizeName(FieldInfo->Type);
if (typeKind == ikVMT)
result += "*";
}
Expand Down Expand Up @@ -1830,7 +1830,7 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
pos += 4;
//elType
elType = *((DWORD*)(Code + pos)); pos += 4;
result = GetTypeName(elType);
result = SanitizeName(GetTypeName(elType));
//varType
pos += 4;
if (DelphiVersion >= 6)
Expand All @@ -1845,7 +1845,7 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
{
//DynArrElType
elType = *((DWORD*)(Code + pos));
result = GetTypeName(elType);
result = SanitizeName(GetTypeName(elType));
}
break;
case ikUString:
Expand Down Expand Up @@ -1898,7 +1898,7 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
typeKind = GetTypeKind(typname, &size);
if (typeKind == ikRecord || typeKind == ikVMT)
result += "struct ";
result += typname;
result += SanitizeName(typname);
if (typeKind == ikVMT)
result += "*";
if (paramFlags & 1) result += "*";
Expand All @@ -1910,7 +1910,14 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
result += ")";

if (resultTypeAdr)
result = GetTypeName(resultTypeAdr) + " " + result;
{
typname = GetTypeName(resultTypeAdr);
typeKind = GetTypeKind(typname, &size);
if (typeKind == ikRecord || typeKind == ikVMT)
result = "struct " + SanitizeName(typname) + "* " + result;
else
result = SanitizeName(typname) + " " + result;
}
else
result = "void " + result;
}
Expand Down Expand Up @@ -1972,7 +1979,7 @@ String __fastcall TFTypeInfo_11011981::GetCppTypeInfo(DWORD adr, int* o_pSize, i
if (typeKind == ikInterface) size = 4;
if (typeKind == ikRecord || typeKind == ikVMT)
result += "struct ";
result += fInfo->Type;
result += SanitizeName(fInfo->Type);
if (typeKind == ikVMT)
result += "*";
}
Expand Down

0 comments on commit 35c7dd8

Please sign in to comment.