遠線程運行彙編代碼

來源:互聯網
上載者:User

VB.NET 2008 寫的代碼,主要是前幾天看人家寫的VB6什麼的代碼,運行起來 不錯,可改成VB.NET 2008一寫,直接壞事了,在XP系統D325的U上跑的都挺好, 可放到VISTA系統TK55的本子上,VB6的還行,.NET的直接非法。針對這個,完整 重寫了一下代碼。

簡單介紹步驟:

1、通過ID擷取進程控制代碼,並替它申請一塊記憶體:

'擷取對方進程
RemoteProcess = Process.GetProcessById (PID)
'為對方進程申請4KB記憶體
AllocBaseAddress = VirtualAllocEx (RemoteProcess.Handle, 0, MEM_SIZE, MEM_COMMIT Or MEM_RESERVE, PAGE_EXECUTE_READWRITE)

2、構建彙編代碼,這裡分兩種情況

A、添加代碼

'添加整型
    Protected Sub AddInt2Code(ByVal Value As Integer)
        Dim bytes() As Byte = BitConverter.GetBytes(CInt (Value))    '擷取位元組內容
        Add2Memory(bytes, PtrAddressOffset)                          '寫入參數堆棧
        PtrAddressOffset += 4                                        '堆棧位置指標向後移動
    End Sub
    '添加位元組型
    Protected Sub AddByte2Code(ByVal Value As Byte)
        Dim bytes(0) As Byte
        bytes(0) = Value
        Add2Memory(bytes, PtrAddressOffset)
        PtrAddressOffset += 1
    End Sub

    '添加位元組數組
    Protected Sub AddBytes2Code(ByVal Value As Byte())
        Add2Memory(Value, PtrAddressOffset)
        PtrAddressOffset += Value.Length
    End Sub

B、添加資料

Add2Memory(Value, ObjAddressOffset)             ' 將資料寫入“資料區”
            Dim odata As New mData                           '記錄每個資料(地址和長度)
            odata.prt = ObjAddressOffset + AllocBaseAddress
            odata.len = Value.Length
            DataArraylist.Add(odata)
            ObjAddressOffset += Value.Length                 '堆棧資料指標向後移動
            ObjAddressOffset += ObjAddressOffset Mod 4       '四位元組對齊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.