📄 main.c
字号:
else if ((c&0x0F)==0x0D) choice=6; // ward
else if ((c&0x0F)==0x0F) choice=2; // byte data
else if ((c&0x0F)==0x0C) choice=3; // CC block
else if ((c&0x0F)==0x0B) choice=4; // Pascal String
else if ((c&0x0F)==0x09) choice=5; // NULL String
else choice=0;
}
/*------------*/pushTrace(1110);
addressprint1(choice);
/*------------*/popTrace();
/*------------*/pushTrace(1120);
tok = instruction(choice);
/*------------*/popTrace();
if (tok==0) {fatalError=-1; break;}
/*------------*/pushTrace(1130);
bodyprint(choice);
/*------------*/popTrace();
lineno++;
/*------------*/pushTrace(1140);
markCodes();
/*------------*/popTrace();
if (nextMode&&needJump)break;
//if (nextMode&&needCall)break;
/*------------*/pushTrace(1150);
if (zeroCheckMode)
{checkZeros(); checkCrossing();}
/*------------*/popTrace();
if (fatalError) break;
}
/* go round the loop */
}
void Disassembler1()
{
//static int bb=0;
int tok;
BYTE c;
int i, limit;
if (nextMode) limit=CodeSize; else limit=48;
for(i=0;i<limit;i++)
{
/*-----------*/pushTrace(1200);
addressfix();
/*-----------*/popTrace();
c = getMap(cur_position);
if ((c&0x08)==0x08) return;
else if ((c&0x05)==0x05) return;
/*-----------*/pushTrace(1210);
addressprint1(0);
/*-----------*/popTrace();
/*-----------*/pushTrace(1220);
tok = instruction(0);
/*-----------*/popTrace();
if (tok==0) {fatalError=-11; break;}
/*-----------*/pushTrace(1230);
bodyprint(0);
/*-----------*/popTrace();
lineno++;
/*-----------*/pushTrace(1240);
markCodes();
/*-----------*/popTrace();
/*-----------*/pushTrace(1250);
if (zeroCheckMode)
{
checkZeros1();
checkCrossing();
}
/*-----------*/popTrace();
if (fatalError) break;
if (needJump) break;
//if (needCall||needJump) break;
}
/* go round the loop */
}
// **************************************************
// disassembler monitoring or surporting functions
// **************************************************
/* ---------------------------------------------------------------------
* the possible error cases:
* -1, -11, 100~399, 900, 990 = unrecovable cur_position must be erased.
* 992 = Address blocks has been decoded as instruction stream
* so referenced position must be erased. - emergency case.
* -2 = cur instruction passes over the next instruction
* 3 possible cases: (1) me-OK,you-NOT (2) me-NOT,you-OK (3) me-NOT,you-NOT
* -3,-4,-5,-6,-7 = zero check error
* 2 possible cases: (1) good code - data, (2) bad code
* 994 = reference of cur instruction touches data
* = reference of cur instruction touches body of some other instruction
* 3 possible cases: (1) me-OK,you-NOT (2) me-NOT,you-OK (3) me-NOT,you-NOT
* 999 = some other instruction touches my body
* 3 possible cases: (1) me-OK,you-NOT (2) me-NOT,you-OK (3) me-NOT,you-NOT
* ----------------------------------------------------------------------
*/
void markCodes()
{
int i;
DWORD r;
r=cur_position;
if (nextMode)
{
if (i_opcode==0xCC && getByteFile(r-1)==0xCC && getByteFile(r+1)==0xCC)
{
/*------------*/pushTrace(1300);
setMap(r,0x0C);
/*------------*/popTrace();
}
else
{
if (nextMode==1)
{
/*-----------*/pushTrace(1310);
orMap(r, 0x05);
/*-----------*/popTrace();
for(i=1;i<i_col_save;i++)
if(getMap(r+(DWORD)i)&0x40)
{
fatalError=900;
break;
}
else
{
/*--------*/pushTrace(1320);
orMap(r+(DWORD)i,0x04);
/*--------*/popTrace();
}
}
else
{
/*------------*/pushTrace(1330);
orMap(r, 0x07);
/*------------*/popTrace();
for(i=1;i<i_col_save;i++)
if(getMap(r+(DWORD)i)&0x40)
{
fatalError=900;
break;
}
else
{
/*--------*/pushTrace(1340);
orMap(r+(DWORD)i,0x06);
/*--------*/popTrace();
}
}
if(fatalError==0)
for(i=1;i<i_col_save;i++)
if (getMap(r+(DWORD)i)&0x20)
{
dmLabels[dmc++]=r+(DWORD)i;
fatalError=999;
/*---------*/pushTrace(1350);
exMap(r+(DWORD)i,0x20);
/*---------*/popTrace();
}
}
}
}
int ErrorRecoverNum=0;
history my_h;
void ErrorRecover()
{
//int i;
//printf("\nError Recover %08X::code=%5d ", cur_position, fatalError);
my_h.m=nextMode;
my_h.f=fatalError;
my_h.r=lastReset;
my_h.c=cur_position;
if (fatalError==256)
{
/*------------*/pushTrace(1400);
trySomeAddress(cur_position);
/*------------*/popTrace();
}
else if (fatalError==999)
{
//fprintf(stdout,"\n:%08X ",cur_position);
//for(i=cur_position-2;i<cur_position+i_col_save+3;i++)
//fprintf(stdout," %02X",getMap(i));
//fprintf(stdout,"\n:%08X ",cur_position);
//for(i=cur_position-2;i<cur_position+i_col_save+3;i++)
//fprintf(stdout," %02X",getByteFile(i));
/*------------*/pushTrace(1410);
if (dmc>0) clearSomeBadGuy(&my_h);
/*------------*/popTrace();
}
else if (fatalError!=0)
{
//for(i=cur_position-2;i<cur_position+3;i++)
//fprintf(stdout," %02X",getMap(i));
/*------------*/pushTrace(1420);
eraseUncertain(cur_position, &my_h);
/*------------*/popTrace();
//fprintf(stderr,"=%d",fatalError);
}
//getch();
/*------------*/pushTrace(1415);
if (dmc>0) clearSomeBadGuy(&my_h);
/*------------*/popTrace();
ErrorRecoverNum++;
dmc=0;
fatalError=0;
}
void clearSomeBadGuy(PHISTORY ph)
{
int i;
//fprintf(stderr,"\n Clear Some Bad Guy ");
for (i=0;i<dmc;i++)
{
/*-----------*/pushTrace(1450);
eraseCarefully(dmLabels[i], ph);
/*-----------*/popTrace();
}
dmc=0;
//for (i=0;i<dmc;i++)
// fprintf(stderr,"\ndmLabels==%08X",dmLabels[i]);//,getch();
if(nextMode==3)
{
//fprintf(stderr,"**************** LOOK HERE ********************");
//getch();
}
}
//
// minimum filter to check if this is code or not.
//
void checkZeros()
{
static int colsave=-1;
if (i_opcode==0x90 && opsave==0 && modsave==0) fatalError=-4;
if (i_opcode==0 && i_mod==0 && opsave==0x90) fatalError=-5;
if (i_opcode==0 && i_mod==0 && opsave==0xC3) fatalError=-6;
if (i_opcode==opsave && i_opcode <0x0A
&& i_col_save == colsave && i_mod<0x0A && i_mod == modsave)
{
fatalError=-7;
//fprintf(stderr,"\nWWW %08X -7::",cur_position);
}
if (i_opcode==0 && i_mod==0 && opsave==0 && modsave==0) fatalError=-3;
opclassSave=opclass; opsave=i_opcode; modsave=i_mod; colsave=i_col_save;
}
void checkZeros1()
{
static int opsave1=-1, modsave1=-1, colsave1=-1;
if (i_opcode==0x90 && opsave1==0 && modsave1==0) fatalError=-4;
if (i_opcode==0 && i_mod==0 && opsave1==0x90) fatalError=-5;
if (i_opcode==0 && i_mod==0 && opsave1==0xC3) fatalError=-6;
if (i_opcode==opsave1 && i_opcode <0x1F
&& i_col_save == colsave1 && i_mod<0x1F && i_mod == modsave1) fatalError=-7;
if (i_opcode==0 && i_mod==0 && opsave1==0 && modsave1==0) fatalError=-3;
//if (i_opcode==opsave1 && i_col_save == colsave1) fatalError=-1;
opsave1=i_opcode; modsave1=i_mod; colsave1=i_col_save;
}
//extern FILE *d_fp;
void checkCrossing()
{
DWORD i;
DWORD r=0;
for(i=cur_position+1;i<cur_position+i_col_save;i++) if (getMap(i)&0x49) break;
if (i==cur_position+i_col_save) return;
if (getByteFile(cur_position)==0x00)
{
/*-------------*/pushTrace(1460);
setMap(cur_position,0x0F);
/*-------------*/popTrace();
return;
}
//fprintf(d_fp,"\n.cc. %08X: nM=%d :",cur_position,nextMode);
//for(i=cur_position;i<cur_position+i_col_save;i++)
// fprintf(d_fp,"%02X ",getByteFile(i));
//fprintf(d_fp,"\n.cc. %08X: :",cur_position);
//for(i=cur_position;i<cur_position+i_col_save;i++)
// fprintf(d_fp,"%02X ",getMap(i));
//if ((getMap(i)&0xF0)==0xF0) r=tryToSaveIt(cur_position+i_col_save);
if (r==0) fatalError=-8;
else
{
//fprintf(stderr," GOTIT %08X-%08X ", cur_position,r);
/*--------------*/pushTrace(1470);
for(i=cur_position;i<r;i++) setMap(i,0x00);
/*--------------*/popTrace();
/*--------------*/pushTrace(1480);
saveIt(cur_position);
/*--------------*/popTrace();
//getch();
}
}
// *****************************************
DWORD GetNextOne()
{
DWORD r, rr;
BYTE b;
if (needJump==1)
{
/*--------------*/pushTrace(1490);
rr=isItStartAnyWay(needJumpNext);
if (rr) addLabels(needJumpNext, 2);
/*--------------*/popTrace();
needJump=0; needJumpNext=0;
}
while(1)
{
r=getLabels();
r=AddressCheck(r);
if (r==0) break;
b=getMap(r);
if((b&0x0F)==0x00) break;
}
return r;
}
int isThisGoodRef(DWORD ref, DWORD s, DWORD e)
{
DWORD r;
_key_ k;
PKEY pk;
k.c_ref=ref; k.c_pos=-1; k.class=0;
pk = searchBtree3(&k);
if (pk==NULL) return 0;
r=pk->c_pos;
if (isGoodAddress(r)&&(r<s||e<r)) return 1;
return 0;
}
int tryToSaveIt(DWORD ref)
{
//int i, j, n, r, s, pos;
//BYTE b, d;
if (!isGoodAddress(ref)) return 0;
//if((getMap(ref)&0x05)==0x05)return 1;
pushEnvironment();
nextMode=0;
zeroCheckMode=0;
//printMode=0;
resetDisassembler(ref);
/*-----------*/pushTrace(1500);
Disassembler1();
/*-----------*/popTrace();
if (fatalError==0)
{
popEnvironment();
fprintf(stderr,".");
showDotsNum++; if (showDotsNum%COLSIZE==0) fprintf(stderr,"\n");
return 1;
}
popEnvironment();
return 0;
}
void saveIt(DWORD ref)
{
//int i, j, n, r, s, pos;
//BYTE b, d;
DWORD r;
if (!isGoodAddress(ref)) return;
pushEnvironment();
nextMode=1;
zeroCheckMode=0;
//printMode=0;
resetDisassembler(ref);
/*-----------*/pushTrace(1550);
Disassembler1();
/*-----------*/popTrace();
if (fatalError==0)
{
r=cur_position;
popEnvironment();
return;
}
popEnvironment();
}
int isItStartAnyWay(DWORD ref)
{
static BYTE CodeTab[100]={
0x0F,0x2D,0x31,0x32,0x33,0x39,0x3A,0x3B,0x3D,0x46,0x47,
0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5D,0x5E,0x5F,
0x64,0x66,0x68,0x6A,0x7C,0x7D,0x80,0x81,0x83,0x84,0x85,0x88,0x89,0x8A,0x8B,0x8D,
0xA1,0xA8,0xA9,0xAC,0xB0,0xB2,0xB3,0xB8,0xB9,0xBA,0xBB,0xBD,0xBE,0xBF,
0xC1,0xC2,0xC3,0xC6,0xC7,0xC8,0xD9,0xDB,0xDD,0xDF,0xE8,0xE9,0xEB,0xF6,0xF7,0xFF,0x00,};
int i, j, tok;
DWORD r, t;
BYTE b, c, d;
//fprintf(stderr, "1");
if (ref==0) return 0;
if (nextMode>0 && ref==needJumpNext)
{
r=ref;
while((b=getByteFile(r))==0x00 && getMap(r)==0x00) {setMap(r++,0x0F);}
i = getIntFile(r);
if (i==-1)
{
setMap(r,0x0F); setMap(r+1,0x0F); setMap(r+2,0x0F); setMap(r+3,0x0F);
}
}
b = getByteFile(ref);
if (b==0) return 0;
//if (ref==debugAdd)fprintf(stderr,"\nisItstartAnyWay=%08X %02X",ref,getMap(ref)),getch();
if (strchr(CodeTab,b)==NULL) return 0;
if (getMap(ref)&0x0F) return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -