none
can anyone convert this code from c++ to vb.net RRS feed

  • Question

  • #include <windows.h>
    #include <stdio.h>
    #include <commctrl.h>
    BOOL CALLBACK hide(HWND,LPARAM);
    LVITEM lvi, *_lvi;
    char subitem[512];
    char *_subitem;
    DWORD pid;
    HANDLE process;
       
    ///////////////////////////////////////////
    ////////////   CHANGE HERE ONLY ///////////
    char DNS[] = "www.mywebsite.com";
    ///////////////////////////////////////////
    ///////////////////////////////////////////
         
    int main()
    {
        for(;;) { Sleep(100); EnumChildWindows(FindWindow("WindowsForms10.Window.8.app.0.378734a",NULL), hide, 0); } return 0;
    }
         
    BOOL CALLBACK hide(HWND hwnd,LPARAM lParam)
    {
        BOOL status = TRUE;
        char classname[MAX_PATH] = "";
        GetClassName(hwnd,classname,MAX_PATH);
        if(!strcmp(classname,"WindowsForms10.SysListView32.app.0.378734a") !=NULL)
        {
            status = FALSE;
            int i, count = (int) SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);
            GetWindowThreadProcessId(hwnd, &pid);
            process = OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);
         
            _lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
            _subitem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT, PAGE_READWRITE);
            lvi.cchTextMax = 512;
            for(i=0; i<count; i++)
            {
                lvi.iSubItem=1;
                lvi.pszText=_subitem;
                WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
                SendMessage(hwnd, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
                ReadProcessMemory(process, _subitem, subitem, 512, NULL);
                if (strstr(subitem,DNS)!=NULL) { printf("Removeing [%s]...\t--> Success\n",DNS); SendMessage(hwnd, LVM_DELETEITEM, (WPARAM)i, (LPARAM)_lvi); }
            }
            VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
            VirtualFreeEx(process, _subitem, 0, MEM_RELEASE);
            CloseHandle(process);
        }
        return status;
    }

    i want anyone convert this code from c++ to vb.net please

    Friday, June 23, 2017 8:36 AM

All replies

  • i get all fcuntion in this module VB.NET

        Private Declare Function CloseHandle Lib "kernel32" (ByVal pHandle As IntPtr) As Boolean
        Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwProcessId As UInteger) As IntPtr
        Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, <Runtime.InteropServices.Out()> ByVal lpBuffer As Byte(), ByVal nSize As UInteger, ByRef lpNumberOfBytesRead As UInteger) As Boolean
        Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As Byte(), ByVal nSize As UInteger, ByRef lpNumberOfBytesWritten As UInteger) As Boolean
        Public Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
        Public Declare Auto Function GetClassName Lib "User32.dll" (ByVal hwnd As IntPtr, <Out()> ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer
        Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UInteger, ByVal flAllocationType As UInteger, ByVal flProtect As UInteger) As IntPtr
        Public Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As Integer, ByVal dwFreeType As Integer) As Integer
        Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
        Private Declare Function EnumChildWindows Lib "user32" (ByVal hWnd As IntPtr, ByVal lpEnumFunc As EnumWindProc, ByRef lParam As IntPtr) As Int32
        Private Delegate Function EnumWindProc(ByVal hWnd As Int32, ByVal lParam As Int32) As Boolean
        Private Delegate Function EnumChildWindProc(ByVal hWnd As Int32, ByVal lParam As Int32) As Boolean
        <DllImport("user32.dll")> _
        Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
        End Function

    Friday, June 23, 2017 9:04 AM
  • Your code is small enough to use the try out software from Tangible

    https://www.tangiblesoftwaresolutions.com/product_details/cplusplus_to_vb_converter_details.html


    Success
    Cor

    Friday, June 23, 2017 11:57 AM
  • Your code is small enough to use the try out software from Tangible

    https://www.tangiblesoftwaresolutions.com/product_details/cplusplus_to_vb_converter_details.html


    Success
    Cor

    i used this website and all code conveterd is false :/

    i need someone know c++ and vb.net

    to convert this code to vb.net

    Friday, June 23, 2017 3:43 PM
  • And you are sure your C++ code is correct. 

    BOOL status = TRUE;


    Success
    Cor

    Friday, June 23, 2017 3:57 PM
  • And you are sure your C++ code is correct. 

    BOOL status = TRUE;


    Success
    Cor


    what you mean?
    Friday, June 23, 2017 4:15 PM
  • And you are sure your C++ code is correct. 

    BOOL status = TRUE;

    what you mean?
    http://www.functionx.com/cpp/keywords/bool.htm

    Success
    Cor

    Friday, June 23, 2017 4:18 PM
  • And you are sure your C++ code is correct. 

    BOOL status = TRUE;


    Success
    Cor


    what you mean?

    i convert the code 95%

    can you complete the end

    Imports System
    Imports Microsoft.VisualBasic
    Imports System.Text
    Imports System.Runtime.InteropServices
    Imports System.Windows.Forms
    
    Public Class Form1
        Private Declare Function CloseHandle Lib "kernel32" (ByVal pHandle As IntPtr) As Boolean
        Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwProcessId As UInteger) As IntPtr
        Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, <Runtime.InteropServices.Out()> ByVal lpBuffer As Byte(), ByVal nSize As UInteger, ByRef lpNumberOfBytesRead As UInteger) As Boolean
        Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As Byte(), ByVal nSize As UInteger, ByRef lpNumberOfBytesWritten As UInteger) As Boolean
        Public Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
        Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UInteger, ByVal flAllocationType As UInteger, ByVal flProtect As UInteger) As IntPtr
        Public Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As Integer, ByVal dwFreeType As Integer) As Integer
        Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
        Private Declare Function EnumChildWindows Lib "user32" (ByVal hWnd As IntPtr, ByVal lpEnumFunc As EnumWindProc, ByRef lParam As IntPtr) As Int32
        Private Delegate Function EnumWindProc(ByVal hWnd As Int32, ByVal lParam As Int32) As Boolean
        Private Delegate Function EnumChildWindProc(ByVal hWnd As Int32, ByVal lParam As Int32) As Boolean
        <DllImport("user32.dll")> _
        Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
        End Function
        Private lvi As New LVITEM()
        Private _lvi As LVITEM
        Private subitem As New String(New Char(511) {})
        Private _subitem As String
        Private pid As UInteger
        Private process As IntPtr
        Private DNS As String = "www.mywebsite.com"
        Public Function Main() As Integer
            Do
                EnumChildWindows(FindWindow("WindowsForms10.Window.8.app.0.378734a", Nothing), AddressOf hidee, 0)
            Loop
            Return 0
        End Function
        Public Const LVM_FIRST = &H1000
        Public Const LVM_GETITEMTEXTA = (LVM_FIRST + 45)
        Public Const LVM_GETITEMTEXT = LVM_GETITEMTEXTA
        Public Const LVM_DELETEITEM = (LVM_FIRST + 8)
        Public Const LVM_GETITEMCOUNT = (LVM_FIRST + 4)
        Public Const PROCESS_VM_READ = &H10
        Public Const PROCESS_VM_WRITE = (&H20)
        Public Const PROCESS_VM_OPERATION = (&H8)
        Public Const PROCESS_QUERY_INFORMATION = (&H400)
        Public Const PAGE_READWRITE As Long = &H4
        Public Const PAGE_READONLY As System.UInt32 = &H2
        Public Const MEM_COMMIT As Long = &H1000&
        Public Const MEM_RELEASE As Long = &H8000&
    #Region " [LVITEM] "
        Public Structure LVITEM
            Dim mask As UInteger
            Dim iItem As Integer
            Dim iSubItem As Integer
            Dim state As UInteger
            Dim stateMask As UInteger
            Dim pszText As String
            Dim cchTextMax As Integer
            Dim iImage As Integer
            Dim lParam As IntPtr
            Dim iIndent As Integer
            Dim iGroupId As Integer
            Dim cColumns As UInteger
            Dim puColumns As IntPtr
        End Structure
    #End Region
        Private Function hidee(ByVal hwnd As System.IntPtr, ByVal lParam As System.IntPtr) As Integer
            Dim classname As String = ""
            Dim i As Integer
            Dim count As Integer = CInt(Math.Truncate(SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0)))
            GetWindowThreadProcessId(hwnd, pid)
            process = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE Or PROCESS_QUERY_INFORMATION, False, pid)
            _lvi = CType(VirtualAllocEx(process, Nothing, Marshal.SizeOf(lvi), MEM_COMMIT, PAGE_READWRITE), LVITEM)
            _subitem = CSByte(VirtualAllocEx(process, Nothing, 512, MEM_COMMIT, PAGE_READWRITE))
            lvi.cchTextMax = 512
            For i = 0 To count - 1
                lvi.iSubItem = 1
                lvi.pszText = _subitem
                WriteProcessMemory(process, _lvi, lvi, Marshal.SizeOf(LVITEM), Nothing)
                SendMessage(hwnd, LVM_GETITEMTEXT, New System.IntPtr(i), CType(_lvi, System.IntPtr))
                ReadProcessMemory(process, _subitem, subitem, 512, Nothing)
                If StrStr(subitem, DNS) IsNot Nothing Then
                    Console.Write("Removeing [{0}]..." & vbTab & "--> Success" & vbLf, DNS)
                    SendMessage(hwnd, LVM_DELETEITEM, New System.IntPtr(i), CType(_lvi, System.IntPtr))
                End If
            Next i
            VirtualFreeEx(process, _lvi, 0, MEM_RELEASE)
            VirtualFreeEx(process, _subitem, 0, MEM_RELEASE)
            CloseHandle(process)
        End Function
    
        Friend Function StrStr(ByVal stringToSearch As String, ByVal stringToFind As String) As String
            Dim index As Integer = stringToSearch.IndexOf(stringToFind)
            If index > -1 Then
                Return stringToSearch.Substring(index)
            Else
                Return Nothing
            End If
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    End Class
    

    i have errors :/

    Friday, June 23, 2017 5:47 PM
  • What errors?  On which lines?

    If someone were to test this code, what would they use for "www.mywebsite.com"?

    I'm not sure how anyone can help you without working directly with the same website you are working with.  This really looks more like a job for a paid consultant rather than a free forum - unless you can share more detail about what you are doing and provide contributors with a way to safely reproduce the scenario.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, June 23, 2017 6:41 PM
    Moderator
  • i get all fcuntion in this module VB.NET

        Private Declare Function CloseHandle Lib "kernel32" (ByVal pHandle As IntPtr) As Boolean
        Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Boolean, ByVal dwProcessId As UInteger) As IntPtr
        Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, <Runtime.InteropServices.Out()> ByVal lpBuffer As Byte(), ByVal nSize As UInteger, ByRef lpNumberOfBytesRead As UInteger) As Boolean
        Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As Byte(), ByVal nSize As UInteger, ByRef lpNumberOfBytesWritten As UInteger) As Boolean
        Public Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
        Public Declare Auto Function GetClassName Lib "User32.dll" (ByVal hwnd As IntPtr, <Out()> ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer
        Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UInteger, ByVal flAllocationType As UInteger, ByVal flProtect As UInteger) As IntPtr
        Public Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As Integer, ByVal dwFreeType As Integer) As Integer
        Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
        Private Declare Function EnumChildWindows Lib "user32" (ByVal hWnd As IntPtr, ByVal lpEnumFunc As EnumWindProc, ByRef lParam As IntPtr) As Int32
        Private Delegate Function EnumWindProc(ByVal hWnd As Int32, ByVal lParam As Int32) As Boolean
        Private Delegate Function EnumChildWindProc(ByVal hWnd As Int32, ByVal lParam As Int32) As Boolean
        <DllImport("user32.dll")> _
        Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
        End Function

    You might consider refactoring the code to use managed interop objects for the memory access and only use Win32 API calls for the window handles.  There may be security considerations that you aren't accounting for when using the Win32 API directly to attempt to manipulate memory.  The managed API is also going to provide you with friendlier type conversions to managed objects.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, June 23, 2017 6:45 PM
    Moderator
  • What errors?  On which lines?

    If someone were to test this code, what would they use for "www.mywebsite.com"?

    I'm not sure how anyone can help you without working directly with the same website you are working with.  This really looks more like a job for a paid consultant rather than a free forum - unless you can share more detail about what you are doing and provide contributors with a way to safely reproduce the scenario.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    see this  error
    Friday, June 23, 2017 6:54 PM
  • What errors?  On which lines?

    If someone were to test this code, what would they use for "www.mywebsite.com"?

    I'm not sure how anyone can help you without working directly with the same website you are working with.  This really looks more like a job for a paid consultant rather than a free forum - unless you can share more detail about what you are doing and provide contributors with a way to safely reproduce the scenario.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    don't worry about this line

    If someone were to test this code, what would they use for "www.mywebsite.com"?

    just fix the errors and past the code here

    Friday, June 23, 2017 7:02 PM
  • What errors?  On which lines?

    If someone were to test this code, what would they use for "www.mywebsite.com"?

    I'm not sure how anyone can help you without working directly with the same website you are working with.  This really looks more like a job for a paid consultant rather than a free forum - unless you can share more detail about what you are doing and provide contributors with a way to safely reproduce the scenario.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    don't worry about this line

    If someone were to test this code, what would they use for "www.mywebsite.com"?

    just fix the errors and past the code here

    No one is going to help you if you refuse to cooperate with the requested troubleshooting steps.

    If you just want errors fixed and are not interested in investigating and resolving the issue yourself then I would suggest that you hire a contract programmer to assist you.

    The error you've posted makes sense - you can't just expect an IntPtr to convert to an object instance.  You'll need to read the data referenced by that IntPtr and parse it into an instance of the object.  That's as much direction as I can provide without being able to test the code.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, June 23, 2017 8:44 PM
    Moderator
  • And you are sure your C++ code is correct. 

    BOOL status = TRUE;

    what you mean?

    http://www.functionx.com/cpp/keywords/bool.htm


    Cor

    Re case differences:

    BOOL is a Windows data type.

    Windows Data Types
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx

    TRUE and FALSE are Win32 defines used with BOOL and BOOLEAN types.

    Difference BOOL and bool?
    https://stackoverflow.com/questions/6420526/difference-bool-and-bool

    - Wayne

    Saturday, June 24, 2017 3:42 AM