Remote Inject

{*******************************************************}
{                                                       }
{       Remote Inject                                   }
{       Creation Date 2010.12.23                        }
{       Created By: ming                                }
{                                                       }
{*******************************************************}
unit unitMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TlHelp32, StdCtrls, ExtCtrls;

type
  TfrmMain = class(TForm)
    btnInject: TButton;
    ListBox1: TListBox;
    btnUnInject: TButton;
    btnGetProcess: TButton;
    btnSetPath: TButton;
    OpenDialog1: TOpenDialog;
    lbledtDllPath: TLabeledEdit;
    lbledtPID: TLabeledEdit;
    btnExit: TButton;
    procedure btnInjectClick(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnUnInjectClick(Sender: TObject);
    procedure btnGetProcessClick(Sender: TObject);
    procedure btnSetPathClick(Sender: TObject);
    procedure btnExitClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

function GetProcessID(List:TStrings; ProcessName: string = ''): TProcessEntry32;
var
  ret: Boolean;
  processID: Cardinal;
  _processName: string;
  FSnapshotHandle: HWND;
  FProcessEntry32: TProcessEntry32;
begin
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
  ret := Process32First(FSnapshotHandle,FProcessEntry32);
  while ret do
  begin
    _processName := ExtractFileName(FProcessEntry32.szExeFile);
    if (ProcessName = '') then
    begin
      processID := FProcessEntry32.th32ProcessID;
      List.Add(Format('%-20s%d',[_processName,processID]));
    end
    else if (AnsiCompareText(_processName,ProcessName)=0) then
    begin
      processID := FProcessEntry32.th32ProcessID;
      List.Add(Format('%-20s%d',[_processName,processID]));
      Result := FProcessEntry32;
      Break;
    end;
    ret := Process32Next(FSnapshotHandle,FProcessEntry32);
  end;
end;

function EnableDebugPrivilege(const bEnabled: Boolean):Boolean;
const
  SE_DEBUG_NAME = 'SeDebugPrivilege';
var
  hToken: THandle;
  tp: TOKEN_PRIVILEGES;
  len: DWORD;
begin
  Result := False;
  if OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES,hToken) then
  begin
    tp.PrivilegeCount := 1;
    LookupPrivilegeValue(nil,SE_DEBUG_NAME,tp.Privileges[0].Luid);
    if bEnabled then
      tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
    else
      tp.Privileges[0].Attributes := 0;
    len := 0;
    AdjustTokenPrivileges(hToken,False,tp,SizeOf(tp),nil,len);
    Result := GetLastError = ERROR_SUCCESS;
    CloseHandle(hToken);
  end;
end;

function InjectDll(const DllFullPath:AnsiString; const dwRemoteProcessId: DWORD):Boolean;
var
  hRemoteProcess,hRemoteThread: THandle;
  pszLibFileRemote: Pointer;
  pszLibFileName: PWideChar;
  pfnStartAddr: TFNThreadStartRoutine;
  memSize,writeSize,lpThreadId: Cardinal;
begin
  Result := False;
  if EnableDebugPrivilege(True) then
  begin
    hRemoteProcess := OpenProcess(PROCESS_ALL_ACCESS,False,dwRemoteProcessId);
    try
      GetMem(pszLibFileName,Length(DllFullPath)*2+1);
      StringToWideChar(DllFullPath,pszLibFileName,Length(DllFullPath)*2+1);
      memSize := (1+lstrlenw(pszLibFileName)) * SizeOf(WCHAR);
      pszLibFileRemote := VirtualAllocEx(hRemoteProcess,nil,memSize,MEM_COMMIT,PAGE_READWRITE);
      if Assigned(pszLibFileRemote) then
      begin
        if WriteProcessMemory(hRemoteProcess,pszLibFileRemote,pszLibFileName,memSize,writeSize)
          and (writeSize=memSize) then
        begin
          lpThreadId := 0;
          pfnStartAddr := GetProcAddress(LoadLibrary('Kernel32.dll'),'LoadLibraryW');
          hRemoteThread := CreateRemoteThread(hRemoteProcess,nil,0,pfnStartAddr
            ,pszLibFileRemote,0,lpThreadId);
          if hRemoteThread <> 0 then
            Result := True;
          CloseHandle(hRemoteThread);
        end;
      end;
    finally
      CloseHandle(hRemoteProcess);
    end;
  end;
end;

function UnInjectDll(const DllFullPath:AnsiString; const dwRemoteProcessId: DWORD):Boolean;
var
  hRemoteProcess,hRemoteThread: THandle;
  pszLibFileRemote: Pointer;
  pszLibFileName: PWideChar;
  pfnStartAddr: TFNThreadStartRoutine;
  memSize,writeSize,lpThreadId,dwExitCode: Cardinal;
begin
  Result := False;
  if EnableDebugPrivilege(True) then
  begin
    hRemoteProcess := OpenProcess(PROCESS_ALL_ACCESS,False,dwRemoteProcessId);
    try
      GetMem(pszLibFileName,Length(DllFullPath)*2+1);
      StringToWideChar(DllFullPath,pszLibFileName,Length(DllFullPath)*2+1);
      memSize := (1+lstrlenw(pszLibFileName)) * SizeOf(WCHAR);
      pszLibFileRemote := VirtualAllocEx(hRemoteProcess,nil,memSize,MEM_COMMIT,PAGE_READWRITE);
      if Assigned(pszLibFileRemote) then
      begin
        if WriteProcessMemory(hRemoteProcess,pszLibFileRemote,pszLibFileName,memSize,writeSize)
          and (writeSize=memSize) then
        begin
          lpThreadId := 0;
          pfnStartAddr := GetProcAddress(LoadLibrary('Kernel32.dll'),'GetModuleHandleW');
          hRemoteThread := CreateRemoteThread(hRemoteProcess,nil,0,pfnStartAddr
            ,pszLibFileRemote,0,lpThreadId);
          WaitForSingleObject(hRemoteThread,INFINITE);
          GetExitCodeThread(hRemoteThread,dwExitCode);
          CloseHandle(hRemoteThread);
          pfnStartAddr := GetProcAddress(LoadLibrary('Kernel32.dll'),'FreeLibrary');
          hRemoteThread := CreateRemoteThread(hRemoteProcess,nil,0,pfnStartAddr
            ,Pointer(dwExitCode),0,lpThreadId);
          WaitForSingleObject(hRemoteThread,INFINITE);
          if hRemoteThread <> 0 then
            Result := True;
          VirtualFreeEx(hRemoteProcess,pszLibFileRemote,Length(DllFullPath)+1,MEM_DECOMMIT);
          CloseHandle(hRemoteThread);
        end;
      end;
    finally
      CloseHandle(hRemoteProcess);
    end;
  end;
end;

procedure TfrmMain.btnExitClick(Sender: TObject);
begin
  if mrYes = MessageDlg('Are you sure exit? :)',mtInformation,[mbYes,mbNo],0) then
    Close;
end;

procedure TfrmMain.btnGetProcessClick(Sender: TObject);
begin
  ListBox1.Clear;
  GetProcessID(TStrings(ListBox1.Items),'');
end;

procedure TfrmMain.btnInjectClick(Sender: TObject);
var
  PID: Cardinal;
  _ErrorCount: Byte;
begin
  _ErrorCount := 0;
  PID := StrToInt(lbledtPid.Text);
  if PID <=0  then
  begin
    ShowMessage('Please Enter PID.');
    Inc(_ErrorCount);
  end;
  if lbledtDllPath.Text = '' then
  begin
    ShowMessage('Please Enter Dll Path.');
    Inc(_ErrorCount);
  end;
  if _ErrorCount = 0 then
  begin
    InjectDll(lbledtDllPath.Text,PID);
  end;
  //InjectDll(extractfilepath(paramstr(0))+'Project2.dll',PID);
end;

procedure TfrmMain.btnSetPathClick(Sender: TObject);
begin
  OpenDialog1.Filter := '*.dll|*.dll';
  if OpenDialog1.Execute then
  begin
    lbledtDllPath.Text := OpenDialog1.FileName;
  end;
end;

procedure TfrmMain.btnUnInjectClick(Sender: TObject);
var
  PID: Cardinal;
  _ErrorCount: Byte;
begin
  _ErrorCount := 0;
  PID := StrToInt(lbledtPid.Text);
  if PID <=0  then
  begin
    ShowMessage('Please Enter PID.');
    Inc(_ErrorCount);
  end;
  if lbledtDllPath.Text = '' then
  begin
    ShowMessage('Please Enter Dll Path.');
    Inc(_ErrorCount);
  end;
  if _ErrorCount = 0 then
  begin
    UnInjectDll(lbledtDllPath.Text,PID);
  end;
  //UnInjectDll(extractfilepath(paramstr(0))+'Project2.dll',PID);
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  GetProcessID(TStrings(ListBox1.Items),'');
  ListBox1.Font.Name := 'Courier New';
end;

procedure TfrmMain.ListBox1Click(Sender: TObject);
begin
  if ListBox1.ItemIndex < 0 then Exit;
  lbledtPid.Text := ListBox1.Items[ListBox1.ItemIndex];
  with TStringList.Create do
  try
    DelimitedText := lbledtPid.Text;
    lbledtPid.Text := Strings[1];
  finally
    Free;
  end;
end;

end.


//.dfm
object frmMain: TfrmMain
  Left = 453
  Top = 404
  BorderStyle = bsDialog
  Caption = 'Remote Inject'
  ClientHeight = 345
  ClientWidth = 354
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesigned
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object btnInject: TButton
    Left = 249
    Top = 142
    Width = 75
    Height = 25
    Caption = 'Inject'
    TabOrder = 0
    OnClick = btnInjectClick
  end
  object ListBox1: TListBox
    Left = 0
    Top = 39
    Width = 225
    Height = 289
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    ItemHeight = 13
    ParentFont = False
    TabOrder = 1
    OnClick = ListBox1Click
  end
  object btnUnInject: TButton
    Left = 249
    Top = 189
    Width = 75
    Height = 25
    Caption = 'UnInject'
    TabOrder = 2
    OnClick = btnUnInjectClick
  end
  object btnGetProcess: TButton
    Left = 249
    Top = 95
    Width = 75
    Height = 25
    Caption = 'GetProcess'
    TabOrder = 3
    OnClick = btnGetProcessClick
  end
  object btnSetPath: TButton
    Left = 231
    Top = 12
    Width = 24
    Height = 25
    Caption = '...'
    TabOrder = 4
    OnClick = btnSetPathClick
  end
  object lbledtDllPath: TLabeledEdit
    Left = 0
    Top = 14
    Width = 225
    Height = 21
    EditLabel.Width = 36
    EditLabel.Height = 13
    EditLabel.Caption = 'Dll Path'
    TabOrder = 5
  end
  object lbledtPID: TLabeledEdit
    Left = 249
    Top = 58
    Width = 82
    Height = 21
    EditLabel.Width = 82
    EditLabel.Height = 13
    EditLabel.Caption = 'Inject Process ID'
    TabOrder = 6
  end
  object btnExit: TButton
    Left = 249
    Top = 240
    Width = 75
    Height = 25
    Caption = 'Exit'
    TabOrder = 7
    OnClick = btnExitClick
  end
  object OpenDialog1: TOpenDialog
    Left = 184
    Top = 56
  end
end

转载于:https://www.cnblogs.com/Jekhn/archive/2011/08/28/2156268.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Nuxt Content 是 Nuxt.js 中的内容管理模块,可以用于管理静态内容,例如 markdown 文件、JSON 数据等。如果要使用远程数据源,可以这样做: 1. 安装 axios 库:在你的 Nuxt 项目中,执行 `npm install axios` 或 `yarn add axios`。 2. 创建一个插件:在项目的 plugins 目录中,创建一个文件,例如 `remote-content.js`。在该文件中,使用 axios 获取远程数据源。 ``` import axios from 'axios' export default ({ app }, inject) => { inject('fetchRemoteContent', async () => { const { data } = await axios.get('https://my-api.com/content') return data }) } ``` 3. 注册插件:在 nuxt.config.js 文件中,将刚才创建的插件添加到 plugins 数组中。 ``` export default { plugins: [ '~/plugins/remote-content.js' ] } ``` 4. 在页面或组件中使用:在需要使用远程数据的页面或组件中,调用 `fetchRemoteContent` 方法即可。 ``` <template> <div> {{ remoteContent }} </div> </template> <script> export default { async asyncData({ app }) { const remoteContent = await app.fetchRemoteContent() return { remoteContent } } } </script> ``` 这样,就可以使用远程数据源了。 ### 回答2: 要使用Nuxt Content与远程资源进行集成,您需要遵循以下步骤: 1. 首先,在您的Nuxt项目中安装Nuxt Content插件。您可以使用以下命令来完成安装: ``` npm install @nuxt/content ``` 2. 接下来,确保您具有一个远程源的数据。您可以使用REST API或GraphQL等技术获取数据。 3. 创建一个新的Content目录,并在其中创建一个新的content.js文件。在此文件中,您需要使用`$content`方法从远程源获取数据。以下是一个示例content.js文件的结构: ```js import { $content } from '@nuxt/content' export async function fetchData() { const data = await $content('your_remote_source').fetch() return data } export default { fetchData } ``` 4. 在您的页面组件中,导入刚刚创建的content.js文件,并在页面的`asyncData`生命周期钩子中使用`fetchData`方法获取数据。以下是一个页面组件的示例: ```vue <template> <div> <h1>{{ content.title }}</h1> <p>{{ content.description }}</p> </div> </template> <script> import { fetchData } from '~/content' export default { async asyncData() { const data = await fetchData() return { content: data } } } </script> ``` 5. 最后,您可以在页面组件中使用从远程源获取的数据。在上面的示例中,我们使用`content`对象来显示标题和描述。 通过按照以上步骤,您就可以使用Nuxt Content与远程源集成,并从中获取数据。 ### 回答3: 要使用Nuxt Content与远程资源,请遵循以下步骤: 1. 首先,确保已经正确安装和配置了Nuxt项目。 2. 在项目根目录的`nuxt.config.js`文件中,添加`@nuxt/content`模块的配置。示例代码如下: ```javascript modules: [ '@nuxt/content', ], content: { // 添加远程源的配置 markdown: { // 设置远程源的URL remote: [ { name: '<name>', endpoint: '<remote-source-url>', }, ], }, }, ``` 在这个配置中,你需要将`<name>`替换为你自己定义的远程源的名称,并将`<remote-source-url>`替换为你的远程源的URL地址。 3. 然后,在你的项目中创建一个Markdown文件,命名为`<name>.md`。请确保该文件与远程源的名称相匹配。 4. 在页面组件中使用Nuxt Content提供的`this.$content`对象来获取远程源的内容。例如,在Vue页面组件的`asyncData`钩子中,可以通过以下方式获取远程源的Markdown内容: ```javascript async asyncData({ $content }) { const remoteContent = await $content('<name>').fetch() return { remoteContent } }, ``` 在这个例子中,`<name>`应该是你前面在`nuxt.config.js`中定义的远程源的名称。 5. 接下来,你就可以在页面模板中使用`remoteContent`来展示远程源的内容。例如: ```html <template> <div> <h1>{{ remoteContent.title }}</h1> <div v-html="remoteContent.bodyHtml"></div> </div> </template> ``` 在这里,`remoteContent`对象中的`title`和`bodyHtml`属性是远程源Markdown文件的内容。你可以根据自己的需求自定义页面模板。 以上就是使用Nuxt Content与远程源的步骤。通过这种方式,你可以轻松地获取和展示远程源的内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值