⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memorybrowserformunit.pas

📁 冒险岛吸怪源码UCE的制作材料 用于冒险岛游戏的外挂
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      srow:=((y-7) div textheight);
      scolumn:=(x-a) div 20;

      i:=(srow*8*rows8)+scolumn;
      //caption:=Inttohex(memoryaddress+i,8);
      selected:=memoryaddress+i;

      if ssLeft in shift then
      with HexEdit do
      begin
        if visible then
        begin
          if length(hexedit.text)=2 then
          begin
            bt:=strtoint('$'+hexedit.text);
            writeprocessmemory(processhandle,pointer(selected),@bt,1,acr);
          end;
        end;

        top:=(srow+1)*(textheight)+3;
        left:=1+a+20*(scolumn);

        acr:=0;
        readprocessmemory(processhandle,pointer(selected),@bt,1,acr);

        if acr=1 then
        begin
          text:=IntToHex(bt,2);
          visible:=true;
          SelectAll;
          SetFocus;
        end else visible:=false;
      end;
    end
    else
    begin
      //not on a byte click
      for i:=1 to 8*rows8 do
        temp:=temp+'D';

      srow:=((y-7) div textheight);


      i:=(x-(1+a+20*8*rows8));

      scolumn:=i div mbcanvas.Canvas.TextWidth('D');

      if scolumn<8*rows8 then
      begin
        i:=scolumn*mbcanvas.Canvas.TextWidth('D');
        selected:=scolumn+memoryaddress+(8*rows8)*srow;

        if ssLeft in shift then
        with textedit do
        begin
          if visible then
          begin
            if length(textedit.Text)>0 then
            begin
              bt:=byte(textedit.Text[1]);
              if (editing2) and (bt>32) then
                writeprocessmemory(processhandle,pointer(selected),@bt,1,acr);
            end;
          end;

          textedit.top:=(srow+1)*(textheight)+3;
          textedit.Left:=1+a+20*8*rows8+i;   //  (1+(20+mbimage.Canvas.TextWidth('00400000'))+20*8*rows8+(scolumn*mbcanvas.Canvas.TextWidth('D'))  )

          acr:=0;
          readprocessmemory(processhandle,pointer(selected),@bt,1,acr);

          if acr=1 then
          begin
            if bt>32 then text:=chr(bt) else text:='';
            visible:=true;
            editing2:=false;
            SelectAll;
            SetFocus;
          end else visible:=false;
        end;
      end;
    end;
  end;

end;

procedure TMemoryBrowser.MBCanvasMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
var a,part,srow,scolumns,i: integer;
begin
  a:=20+mbimage.Canvas.TextWidth('00400000');

  if x>a then
  begin
    if x<(a+20*8*rows8) then //bytepoint
    begin
      mbcanvas.Cursor:=crHandpoint;

     { if ssLeft in shift then
      begin
        part:=0; //address
        if x>a then
        begin  //didnt klick on the address
          part:=2; //textfield ad the left side
          if x<(a+20*8*rows8) then //byteclick
          begin
            part:=1; //a byte
            srow:=((y-7) div textheight);
            scolumn:=(x-a) div 20;

            i:=(srow*8*rows8)+scolumn;
            //caption:=Inttohex(memoryaddress+i,8);

            if selected2<>memoryaddress+i then
            begin
              selected2:=memoryaddress+i;
              //and repaint the selected region
            end;
          end;
        end;
      end; }

    end else mbcanvas.Cursor:=crDefault;
  end else mbcanvas.Cursor:=crdefault;
end;

procedure TMemoryBrowser.MBCanvasDblClick(Sender: TObject);
begin
  if mbcanvas.Cursor=crHandpoint then
  begin
    if part=1 then
    begin
     //edit
      with Tvaluechangeform.Create(application) do
      begin
        address:=selected;
        ShowModal;
        refreshmb;
      end;
    end;
  end;
end;

procedure TMemoryBrowser.Panel2Resize(Sender: TObject);
begin
  updatedisassemblerview;
end;

procedure TMemoryBrowser.updatedisassemblerview;
var lines,i,j,k: integer;
    rct: trect;
    address: dword;
    maddress: dword;
    disassembled: string;
    descript: string;
    newdselected2: integer;
    repaintornot: boolean;

    {$ifndef net}addresses: tdissectarray;{$endif}
    symbol: PImagehlpSymbol;
    sn: pchar;
    ok: boolean;
    x:dword;
    y,z:string;

    mi: TModuleInfo;


  procedure addline(i:integer);
  var j: integer;
  begin
    rct.Top:=i*(textheight+2);
    rct.Bottom:=rct.top+textheight+1;

    {$ifndef net}


    if (debuggerthread2<>nil) and (address<>0) then
    begin
      for j:=0 to 3 do
        if address=debuggerthread2.breakpoints[j] then
        begin
          disimage.Canvas.Brush.Color:=clRed;
          disimage.Canvas.font.Color:=clBlack;
          break;  //get out of this for loop
        end;
    end;


    if (debuggerthread<>nil) and (debuggerthread.userisdebugging) then
    begin
      for j:=0 to length(debuggerthread.userbreakpoints)-1 do
        if address=debuggerthread.userbreakpoints[j] then
        begin
          disimage.Canvas.Brush.Color:=clRed;
          disimage.Canvas.font.Color:=clBlack;
          break;  //get out of this for loop
        end;

      for j:=0 to length(debuggerthread.int3userbreakpoints)-1 do
        if address=debuggerthread.int3userbreakpoints[j].address then
        begin
          disimage.Canvas.Brush.Color:=clRed;
          disimage.Canvas.font.Color:=clBlack;
          break;  //get out of this for loop
        end;

    end;
    {$endif}

    if dselected=address then
    begin
      disimage.Canvas.Brush.Color:=Highlightcolor;
      disimage.Canvas.font.Color:=clHighlightText;

      {$ifndef net}

      if (debuggerthread2<>nil) and (address<>0) then
      begin
        for j:=0 to 3 do
          if address=debuggerthread2.breakpoints[j] then
          begin
            disimage.Canvas.Brush.Color:=clGreen;
            disimage.Canvas.font.Color:=clWhite;
            break;  //get out of this for loop
          end;
      end;

      if debuggerthread<>nil then
      begin
        for j:=0 to length(debuggerthread.userbreakpoints)-1 do
          if address=debuggerthread.userbreakpoints[j] then
          begin
            disimage.Canvas.Brush.Color:=clGreen;
            disimage.Canvas.font.Color:=clWhite;
            break;  //get out of this for loop
          end;

        for j:=0 to length(debuggerthread.int3userbreakpoints)-1 do
          if address=debuggerthread.int3userbreakpoints[j].address then
          begin
            disimage.Canvas.Brush.Color:=clGreen;
            disimage.Canvas.font.Color:=clWhite;
            break;  //get out of this for loop
          end;
      end;
      {$endif}

      if PANEL6.caption<>disassemblerlines[i].description then panel6.Caption:=disassemblerlines[i].description;
    end;

    disimage.Canvas.FillRect(rct);
    disimage.Canvas.TextOut(8,i*(textHeight+2),disassembled);

    disimage.Canvas.Brush.color:=clBtnFace;
    disimage.Canvas.font.color:=clWindowText;

    disassemblerlines[i].disassembled:=disassembled;
    disassemblerlines[i].address:=address;
  end;
begin
  if not disassembler then exit;

  try
    try
    getmem(symbol,sizeof(_Imagehlp_symbol)+100);
    symbol.SizeOfStruct:=sizeof(_Imagehlp_symbol)+100;
    symbol.MaxNameLength:=100;


    if not symhandler.isloaded then
      label1.Caption:='Symbols are getting loaded'
    else
    begin
      label1.Caption:=symhandler.getnamefromaddress(disassembleraddress);
    end;

    rct.Left:=0;
    rct.Right:=discanvas.Width;

    disimage.Width:=0;
    disimage.width:=discanvas.Width;
    disimage.Height:=discanvas.Height;
    DisCanvas.Canvas.Font:=DisImage.Canvas.Font;

    lines:=(Discanvas.Height) div (textheight+2);

    if numberofaddresses<>lines then
    begin
      setlength(disassemblerlines,0); //freemem
      setlength(disassemblerlines,lines+1);
    end;

    numberofaddresses:=lines;

    maddress:=disassembleraddress;

    i:=0;
    while i<=lines do
    begin
      ok:=false;
            
      if SymGetSymFromAddr(processhandle,maddress,0,symbol^) then
      begin
        if symbol.Address=maddress then
        begin
          if ((i>0) and (disassemblerlines[i-1].address<>maddress)) then
          begin
            disassemblerlines[i].description:='';
            disassembled:=pchar(@symbol.Name[0]);
            addresS:=maddress;
            ok:=true;

            addline(i);
            inc(i);

            continue;
          end;
        end;
      end;

      {$ifndef net}
      if dissectcode<>nil then
      begin
        setlength(addresses,0);
        if dissectcode.checkaddress(maddress,addresses) then
        begin
          disassembled:='Referenced by ';
          for k:=0 to length(addresses)-1 do
          begin
            if i>lines then break;

            disassemblerlines[i].description:='';
            x:=addresses[k].address;
            for j:=0 to dissectcode.accuracy-1 do
              x:=previousopcode(x);

            for j:=0 to dissectcode.accuracy-1 do
              disassemble(x);



            if x=addresses[k].address then
            begin
              if disassembled[length(disassembled)]=')' then disassembled:=disassembled+', ';
              case addresses[k].jumptype of
                jtUnconditional: disassembled:=disassembled+inttohex(addresses[k].address,8)+'(U)';
                jtConditional: disassembled:=disassembled+inttohex(addresses[k].address,8)+'(C)';
                jtCall: disassembled:=disassembled+inttohex(addresses[k].address,8)+'(Call)';
              end;

              if length(disassembled)>50 then
              begin
                //disassembled:=disassembled+
                address:=maddress;
                addline(i);
                inc(i);
                disassembled:='Referenced by ';
              end;

            end;
          end;

          if disassembled<>'Referenced by ' then
          begin
            addresS:=maddress;
            addline(i);
            inc(i);
          end;

          if i<=lines then
          begin
            disassembled:=translatestring(disassemble(maddress,disassemblerlines[i].description),bytestoshow-1);
            addline(i);
            inc(i);
          end;

          setlength(addresses,0);
          continue;
        end;
      end;
      {$endif}

      if not ok then
      begin
        address:=maddress;
        disassembled:=translatestring(disassemble(maddress,disassemblerlines[i].description),bytestoshow-1);

        if Showmoduleaddresses1.Checked then
        begin
          //replace the address part with a modulename+offset when possible
          if symhandler.getmodulebyaddress(address,mi) then
          begin
            y:=inttohex(address,8);
            z:=mi.modulename+'+'+inttohex(address-mi.baseaddress,4);

            disassembled:=stringreplace(disassembled,y,z,[rfReplaceAll]);
          end;

        end;

      end;

      addline(i);
      inc(i);
    end;


    rct.Top:=0;
    rct.Bottom:=disimage.Height;
    discanvas.Canvas.CopyRect(rct,disimage.Canvas,rct);
    finally
      freemem(symbol);
    end;
  except
    ;//
  end;

end;

procedure TMemoryBrowser.DisCanvasPaint(Sender: TObject);
var cr: Trect;
begin
  cr:=discanvas.Canvas.ClipRect;
  discanvas.Canvas.CopyRect(cr,disimage.Canvas,cr);
end;

procedure TMemoryBrowser.DisCanvasMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var i,j,line: integer;
    rct: trect;
    disassembled: string;
begin
  if not fcontrol1.Focused then fcontrol1.SetFocus;

  discanvas.Canvas.font.Name:='Courier';
  disimage.Canvas.Font.Name:='Courier';

  line:=y div (textheight+2);

  if disassemblerlines[line].address<>dselected then
  begin
    if panel6.caption<>disassemblerlines[line].description then panel6.caption:=disassemblerlines[line].description;

    if (disassembleraddress+line)>$FFFFFFFF then exit;
    for i:=0 to numberofaddresses do
    begin
      if disassemblerlines[i].address=dselected then
      begin
        {$ifndef net}
        if (debuggerthread2<>nil) and (disassemblerlines[i].address<>0) then
        begin
          for j:=0 to 3 do

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -