All pastes #190149 Raw Edit

Sans nom

public text v1 · immutable
·published 2006-10-03 19:31 UTC
rendered paste body
// Function attempts to calculate address of assembler instruction which is n
// lines back in the listing. Maximal stepback is limited to 127. In general,
// this is rather non-trivial task. Proposed solution may cause problems which
// however are not critical here.
ULONG abuf[131];

ULONG Disassembleback(UCHAR *block,ULONG base,ULONG size,ULONG ip,int n) {
  int i;
  ULONG addr,back,cmdsize;
  UCHAR *pdata;
  t_disasm da;
  if (block==NULL) return 0;           // Error, no code!
  if (n<0) n=0; else if (n>127) n=127; // Try to correct obvious errors
  if (ip>base+size) ip=base+size;
  if (n==0) return ip;                 // Obvious answers
  if (ip<=base+n) return base;
  back=MAXCMDSIZE*(n+3);               // Command length limited to MAXCMDSIZE
  if (ip<base+back) back=ip-base;
  addr=ip-back;
  pdata=block+(addr-base);
  for (i=0; addr<ip; i++) {
    abuf[i%128]=addr;
    cmdsize=Disasm(pdata,back,addr,&da,DISASM_SIZE);
    pdata+=cmdsize;
    addr+=cmdsize;
    back-=cmdsize; };
  if (i<n) return abuf[0];
  else return abuf[(i-n+128)%128];
};