Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
<pre>public void comboBox1_TextChanged(object sender, EventArgs e)
        {
            if (this.comboBox1.Text == "Chrome")
            {
                int pid = browser.Chrome();
                if (pid > 0)
                {
                    Aobscan.OpenProcessid(pid);
                    label1.Text = "Attached To Chrome Pid :" + pid;
                }
                else
                {
                    label1.Text = "Failed To Attached";
                    Aobscan.processhandle = IntPtr.Zero;
                }
            }


What I have tried:

Hello guys. I would like to be able to have it appear on a label if the browser that found the PID is a 32bit chrome or a 64bit chrome. How can I do this?
Something like

If PID browser is 64bits label1.text = ("chrome 64bits")
Else label1.text = ("chrome 32bits")Thank you very much for the help
Posted
Updated 30-May-17 16:40pm
Comments
Dave Kreskowiak 30-May-17 22:42pm    
That's not what the OP is looking for. Your code is asking if the current O/S is 64-bit or not and if the process this code is in is running as 64-bit or not. It does nothing to determine if an external Chrome process is 64-bit.

1 solution

The PID is a Process ID. It's just a number and doesn't tell you anything at all about the process.

You have to get a Process object using Process.GetProcessById Method (Int32) (System.Diagnostics)[^]. When you've got the Process object you call the below code to determine if it's 64-bit or not.

You'll need a bit of code to make the call to Windows...
C#
internal static class NativeMethods
{
    // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms684139%28v=vs.85%29.aspx
    public static bool Is64Bit(Process process)
    {
        if (Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") == "x86")
            return false;

        bool isWow64;
        if (!IsWow64Process(process.Handle, out isWow64))
            throw new Win32Exception();
        return !isWow64;
    }

    [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
}


And you call it like this:
C#
int pid = browser.Chrome();
Process process = Process.GetProcessById(pid);
bool is64Bit = NativeMethods.Is64Bit(process);
 
Share this answer
 
Comments
HemersonKl 31-May-17 7:18am    
Hi Dave. I have this function in Aobscaner.cs How do I call it in form1.cs? So that when finding the browser it shows in a label that the browser is 32x or 64x. Sorry for ignorance I'm an apprentice.

<pre>[DllImport("kernel32.dll")]
        static extern int VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer, uint dwLength);

        private static IntPtr OpenProcess(Process proc, ProcessAccessFlags flags)
        {
            return OpenProcess(ProcessAccessFlags.All, false, proc.Id);
        }

        public static bool Is64Bit(Process process)
        {
            if (Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") == "x86")
                return false;

            bool isWow64;
            if (!IsWow64Process(process.Handle, out isWow64))
                throw new System.ComponentModel.Win32Exception();
            return !isWow64;
        }

        [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);

        public void ReadAOB(string Scancode)
        {
            if ((int)processhandle > 0)
            {
                IntPtr bytesRead = IntPtr.Zero;
                long MaxAddress = 0;
                if(isbit64)
                     MaxAddress = 0x7fffffffffffffff;
                else
                    MaxAddress = 0x7fffffff;
                long address = 0;
                addresses.Clear();
                do
                {
                    MEMORY_BASIC_INFORMATION m;
                    int result = VirtualQueryEx(processhandle, (IntPtr)address, out m, (uint)Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION)));

                    if (m.Protect == AllocationProtectEnum.PAGE_READWRITE)
                    {
                        byte[] buffer = new byte[(int)m.RegionSize];
                        // IntPtr buffer = IntPtr.Zero;
                        ReadProcessMemory(processhandle, m.BaseAddress, buffer, (int)m.RegionSize, out bytesRead);
                        BoyerAlgo(m.BaseAddress, buffer, Scancode, ref addresses);
                    }
                    if (address == (long)m.BaseAddress + (long)m.RegionSize)
                        break;
                    address = (long)m.BaseAddress + (long)m.RegionSize;
                } while (address <= MaxAddress);
            }
        }
Dave Kreskowiak 31-May-17 10:05am    
Not enough information to tell, but I already gave you an example of how to do something very similar.

This is why you shouldn't be copying and pasting code from the internet. You don't have the knowledge to understand what the code does, how it does it, how to integrate it into your own code and use it, and most importantly, how to debug it.
HemersonKl 31-May-17 10:21am    
Hello. I have the source running right. With classes and everything. I just need this to be complete. Make appear if the browser is 32x or 64x.
Dave Kreskowiak 31-May-17 10:28am    
And I already told you how to call the methods in that code. I don't know if this code sits in another project in your solution, what class it's in, ..., nothing.

I don't care how many times you repeat "I need make appear if the browser is 32x or 64x". It will never change my answer. You're not providing enough information to answer the question of "how to call it".

Like I said, I already gave you an example on how to call static methods in a class. You're just choosing to ignore it.

Oh, and it's "x86" or "x64", not "32x" or "64x".
HemersonKl 31-May-17 10:31am    
I understand. I do not know how to explain myself better. Is that the example you gave already has it in the source of my program, just do not know how to use it for what I want. = /

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900