📄 tcwiz1.cpp
字号:
Variable v2; int v2Type;
// Is it part of any known variable?
if (LocalVars.PartOfAnyVariable(v1,v2,v2Type) ||
GlobalVars.PartOfAnyVariable(v1,v2,v2Type))
{
// Is it a long-int?
if (v2Type==VAR_LONG)
// Is it the 1st word of a long-int?
return (v1.GetAddress()==v2.GetAddress());
}
return 0;
}
/*----------------------------------------------------------------------
IsInternalLongIntProc - returns 1 if the address given points to one
of the procedures for long-int manipulation.
eg: LXMUL@ - multiplies two long-ints passed in DX:AX & BX:CX
*** Makes use of the LongIntProcTable, hence the procedure must have
*** been previously searched in the library and registered by calling
*** RegisterLongIntProc function.
----------------------------------------------------------------------*/
int TcWizard::IsInternalLongIntProc(InstInfo &inst)
{
Variable v;
inst.GetVariable(v,1);
char *ProcName = GlobalVars.GetName(v);
if (!ProcName) return 0;
char *NameEnd = ProcName + strlen(ProcName);
if (strncmp(NameEnd-4,"MUL@",4)==0) LongIntMultiply();
else if (strncmp(NameEnd-4,"DIV@",4)==0) LongIntDivide("/");
else if (strncmp(NameEnd-4,"MOD@",4)==0) LongIntDivide("%");
else if (strncmp(NameEnd-4,"LSH@",4)==0) LongIntShift("<<");
else if (strncmp(NameEnd-4,"RSH@",4)==0) LongIntShift(">>");
else return 0;
return 1;
}
#define IsHexDigit(x) ((x>='0' && x<='9') || \
(x>='A' && x<='F') || \
(x>='a' && x<='f'))
int IsOnlyNumber(String &s)
{
char *ptr = (char *)s;
if (!*ptr) return 0;
while(*ptr)
{
if(!IsHexDigit(*ptr)) return 0;
ptr++;
}
return 1;
}
void TcWizard::LongIntShift(char *Oper)
{
String oper1,oper2;
if (IsOnlyNumber(Regs[REG_DX]))
{
if(!IsOnlyNumber(Regs[REG_AX]))
{
sprintf(errorStr,"Error decoding long-int shifting code at %X",InstAddr);
ErrorList.Add(errorStr);
}
else
oper1=Regs[REG_DX]+Regs[REG_AX];
}
else oper1=Regs[REG_AX];
oper2=Regs[REG_CL];
String s=oper1+" "+Oper+" "+oper2;
Regs[REG_AX]=s;
oper1="HIWORD(";
Regs[REG_DX]=oper1 + s + ")";
}
void TcWizard::LongIntDivide(char *Oper)
{
String oper1,oper2;
if (IsOnlyNumber(Stack[StackTop-1]))
{
if(!IsOnlyNumber(Stack[StackTop-2]))
{
sprintf(errorStr,"Error decoding long-int operation code at %X",InstAddr);
ErrorList.Add(errorStr);
}
else
oper1=Stack[StackTop-2]+Stack[StackTop-1];
}
else oper1=Stack[StackTop-1];
if (IsOnlyNumber(Stack[StackTop-3]))
{
if(!IsOnlyNumber(Stack[StackTop-4]))
{
sprintf(errorStr,"Error decoding long-int division code at %X",InstAddr);
ErrorList.Add(errorStr);
}
else
oper2=Stack[StackTop-4]+Stack[StackTop-3];
}
else oper2=Stack[StackTop-3];
String s; s="("; s += oper1 +") " + Oper + " ("+ oper2+")";
Regs[REG_AX]=s;
oper1="HIWORD(";
Regs[REG_DX]=oper1 + s + ")";
}
void TcWizard::LongIntMultiply()
{
String oper1,oper2;
if (IsOnlyNumber(Regs[REG_CX]))
{
if(!IsOnlyNumber(Regs[REG_BX]))
{
sprintf(errorStr,"Error decoding long-int multiply code at %X",InstAddr);
ErrorList.Add(errorStr);
}
else
oper1=Regs[REG_CX]+Regs[REG_BX];
}
else oper1=Regs[REG_BX];
if (IsOnlyNumber(Regs[REG_DX]))
{
if(!IsOnlyNumber(Regs[REG_AX]))
{
sprintf(errorStr,"Error decoding long-int multiply code at %X",InstAddr);
ErrorList.Add(errorStr);
}
else
oper2=Regs[REG_DX]+Regs[REG_AX];
}
else oper2=Regs[REG_AX];
String s; s="("; s += oper1 +") * ("+ oper2+")";
Regs[REG_AX]=s;
oper1="HIWORD(";
Regs[REG_DX]=oper1 + s + ")";
}
void TcWizard::FindAndRegisterDataTypes(InstInfo &inst)
{
// return;
Variable v;
int size=-1;
switch(inst.Operand1)
{
case REG_DIRECT :
switch(inst.Operand2)
{
case MEMORY :
case INDEXED_BYTE :
case INDEXED_WORD :
inst.GetVariable(v,2);
// Is it operating on a 8-bit register?
size=(inst.Data11 < REG_AX)?0:1;
}
break;
case MEMORY :
case INDEXED_BYTE :
case INDEXED_WORD :
inst.GetVariable(v,1);
switch(inst.Operand2)
{
case IMMEDIATE : size=inst.operSize1; break;
case REG_DIRECT: size=(inst.Data21 < REG_AX)?0:1; break;
}
}
// Add new datatype only if it is not registered previously as a long int.
if (!IsLongInt(v))
{
if (size==0)
AddVar(v,VAR_CHAR,1);
else if (size==1)
AddVar(v,VAR_INT,2);
}
}
void TcWizard::AddVar(Variable &v,int type,int size)
{
VariableList *vList=NULL;
switch(v.Operand)
{
case IMMEDIATE :
if (type==VAR_LIB_FUNCTION || type==VAR_USER_FUNCTION)
vList=&GlobalVars;
break;
case INDEXED_BYTE : case INDEXED_WORD :
vList=&LocalVars; break;
case MEMORY : vList=&GlobalVars; break;
}
if (vList) vList->Add(v,type,size);
}
void TcWizard::DelVar(Variable &v)
{
VariableList *vList=NULL;
switch(v.Operand)
{
case IMMEDIATE :
vList=&GlobalVars; break;
case INDEXED_BYTE : case INDEXED_WORD :
vList=&LocalVars; break;
case MEMORY : vList=&GlobalVars; break;
}
if (vList) vList->Del(v);
}
void TcWizard::DeCompileFull()
{
Dword ctr,ProcSize;
Byte far *ProcAddr;
Pass1(GetMain(),1);
FlushAll();
GlobalVars.NameUnknownVariables();
VariableList *vList=&GlobalVars;
do
{
if (vList->Type==VAR_USER_FUNCTION)
{
ProcAddr = (Byte far *)MK_FP(vList->Data.Data2,vList->Data.Data1);
Pass1(ProcAddr);
/* ctr=SkipProcInit(ProcAddr,ProcSize);
// Register the local variables used.
TranslateBlock(ProcAddr+ctr,ProcSize,TcWizard::SEPARATE_LINES,NULL);
// Now do the actual display*/
LocalVars.NameUnknownVariables();
LocalVars.MakeAllReadOnly();
DisplayProc(ProcAddr);
LocalVars.Flush();
}
vList=vList->Next;
}while(vList);
}
/*--------------------------------------------------------------
IsReturnStatement - finds if the current instruction ('JMP') is
actually a jmp to the procedure's end. if so, this is a
return statement.
--------------------------------------------------------------*/
int TcWizard::IsReturnStatement()
{
/* Byte far *Inst = (Byte far *)MK_FP(FP_SEG(CodePtr),InstAddr);
Disasm d;
do
{
// have we reached the end of the procedure?
if (Inst>=ProcEndAddress) return 1;
// if no, check this instruction.
int InstLen;
d.TraceInst(Inst,InstLen);
if (d.CurInst.Instr==JMP)
Inst=(Byte far *)MK_FP(d.CurInst.Data12,d.CurInst.Data11);
}while(d.CurInst.Instr==JMP);*/
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -