Source file: /~heha/hsn/borg.zip/USER_FN.CPP

/************************************************************************
* user_fn.cpp								*
* - the functions here are various user dialogs and directly callable	*
*   routines, these are all primary thread routines			*
* - Extracted from various classes v2.22				*
************************************************************************/

#include <windows.h>
#include <stdio.h>

#include "dasm.h"
#include "schedule.h"
#include "decrypt.h"
//#include "menuids.rh"
#include "resource.h"
#include "range.h"
#include "debug.h"


/************************************************************************
* global variables							*
* - save state of decryption dialog, etc.....				*
************************************************************************/
dectype lastdec=decxor;
ditemtype lastditem=decbyte;
char lastvalue[20]={'\0'},last_seg[20]={'\0'},lastoffset[20]={'\0'};
bool patchexe=false;

/************************************************************************
* shutbox								*
* - this is a shutdown warning box if Borg is having difficulty		*
*   quitting. It just puts up a 'shutting down' message for a couple of *
*   seconds								*
************************************************************************/
//BOOL CALLBACK shutbox(HWND,UINT,WPARAM,LPARAM) {
// return FALSE;
//}

/************************************************************************
* choosecolour								*
* - a small dialog box for colour choice (standard dialog) when setting *
*   background or text colours						*
************************************************************************/
BOOL choosecolour(COLORREF &cr) {
 CHOOSECOLOR cc;
 COLORREF crCustColors[16];

 ZeroMemory(&cc,sizeof(cc));
 cc.lStructSize=sizeof(CHOOSECOLOR);
 cc.hwndOwner=MainWnd;
 cc.rgbResult=cr;
 cc.lpCustColors=crCustColors;
 cc.Flags=CC_RGBINIT|CC_FULLOPEN;
 if (ChooseColor(&cc)) {
  cr=cc.rgbResult;
  return TRUE;
 }else return FALSE;
}

/************************************************************************
* decbox								*
* - the decryptor dialog, it only allows patching if the file is not	*
*   readonly, and adds the decryptor to the list and calls the process	*
*   and patch functions.						*
************************************************************************/
BOOL CALLBACK decbox(HWND Wnd,UINT Msg,WPARAM wParam,LPARAM) {
 dword dec_id,d_val;
 lptr d_adr;

 switch (Msg) {
  case WM_INITDIALOG: {
   UINT idc=idc_xor;
   switch (lastdec) {
    case decmul: idc=idc_mul;	break;
    case decadd: idc=idc_add;	break;
    case decsub: idc=idc_sub;	break;
    case decrot: idc=idc_rot;	break;
    case decxadd:idc=idc_xadd;	break;
   }
   CheckDlgButton(Wnd,idc,TRUE);
   idc=idc_byte;
   switch (lastditem) {
    case decword: idc=idc_word; break;
    case decdword:idc=idc_dword;break;
    case decarray:idc=idc_array;break;
   }
   CheckDlgButton(Wnd,idc,TRUE);
   SetDlgItemText(Wnd,idc_value,lastvalue);
   SetDlgItemText(Wnd,idc_arrayseg,last_seg);
   SetDlgItemText(Wnd,idc_arrayoffset,lastoffset);
   CheckDlgButton(Wnd,idc_applytoexe,patchexe);
  }return TRUE;

  case WM_COMMAND: switch (LOWORD(wParam)) {
   case IDOK: {
    if (IsDlgButtonChecked(Wnd,idc_xor))	lastdec=decxor;
    else if (IsDlgButtonChecked(Wnd,idc_mul))	lastdec=decmul;
    else if (IsDlgButtonChecked(Wnd,idc_add))	lastdec=decadd;
    else if (IsDlgButtonChecked(Wnd,idc_sub))	lastdec=decsub;
    else if (IsDlgButtonChecked(Wnd,idc_rot))	lastdec=decrot;
    else if (IsDlgButtonChecked(Wnd,idc_xadd))	lastdec=decxadd;
    else lastdec=decnull;
    if(IsDlgButtonChecked(Wnd,idc_word))	lastditem=decword;
    else if(IsDlgButtonChecked(Wnd,idc_dword))	lastditem=decdword;
    else if(IsDlgButtonChecked(Wnd,idc_array))	lastditem=decarray;
    else lastditem=decbyte;
    GetDlgItemText(Wnd,idc_value,lastvalue,18);
    GetDlgItemText(Wnd,idc_arrayseg,last_seg,18);
    GetDlgItemText(Wnd,idc_arrayoffset,lastoffset,18);
    patchexe=IsDlgButtonChecked(Wnd,idc_applytoexe)!=0;
    sscanf(lastvalue,"%lx",&d_val);
    sscanf(last_seg,"%lx",&d_adr.segm);
    sscanf(lastoffset,"%lx",&d_adr.offs);
    if (options.readonly && patchexe) {
     patchexe=false;
     MessageBox(Wnd,"File opened readonly - unable to patch","Borg Message",MB_OK);
    }
    dec_id=decrypter.add_decrypted(blk.top,blk.bottom,lastdec,lastditem,d_val,d_adr,patchexe);
    decrypter.process_dec(dec_id);
    if (patchexe) decrypter.exepatch(dec_id);
   }nobreak;
   case IDCANCEL: EndDialog(Wnd,wParam);
  }
 }
 return FALSE;
}

/************************************************************************
* dialg									*
* - we stop the thread whilst displaying the decryptor dialog and doing *
*   the patch								*
************************************************************************/
void decrypterdialog(void)
{ //scheduler.stopthread();
  if(!blk.checkblock())
    return;
  DialogBox(hInst,MAKEINTRESOURCE(Decrypt_Dialog),MainWnd,decbox);
//  scheduler.continuethread();
}

Detected encoding: ASCII (7 bit)2