|
Welcome to the GSM-Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. Only registered members may post questions, contact other members or search our database of over 8 million posts. Registration is fast, simple and absolutely free so please - Click to REGISTER! If you have any problems with the registration process or your account login, please contact contact us . |
|
Register | FAQ | Donate | Forum Rules | Root any Device | ★iPhone Unlock★ | ★ Direct Codes ★ | Direct Unlock Source |
GSM Programming & Reverse Engineering Here you can post all Kind of GSM Programming and Reverse Engineering tools and Secrets. |
| LinkBack | Thread Tools | Display Modes |
11-23-2010, 11:51 | #1 (permalink) |
No Life Poster Join Date: Jul 2006 Location: ..::DZ-25::..
Posts: 529
Member: 315181 Status: Offline Sonork: 100.1593455 Thanks Meter: 301 | LG Sgold USB comminication in c# here my source in c# When phone is connected without battery, it will be in Flash interface for a short time ==> phone is connected with path : \\.\USB1 1- Import windows dll's SETUPAPI.dll and KERNEL32.dll Code: //*********************** API ********************** public const uint DIGCF_PRESENT = 0x00000002; public const uint DIGCF_INTERFACE_DEVICE = 0x00000010; public const int FILE_FLAG_OVERLAPPED = 0x40000000; public static IntPtr INVALID_HANDLE = new IntPtr(-1); SafeFileHandle deviceHandle; int numberOfBytesWritten = 0; int numberOfBytesRead = 0; IntPtr unManagedBuffer; IntPtr unManagedOverlapped; Boolean success; //______________setupapi_______________ [DllImport("setupapi.dll", SetLastError = true)] public static extern IntPtr SetupDiGetClassDevs(ref Guid ClassGuid, uint Enumerator, IntPtr hwndParent, uint Flags); [DllImport("setupapi.dll", SetLastError = true)] public static extern bool SetupDiEnumDeviceInterfaces(IntPtr DeviceInfoList, uint DeviceInfoData, ref Guid InterfaceClassGuid, uint MemberIndex, SP_DEVICE_INTERFACE_DATA DevInterfaceData); [DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Ansi)] public static extern bool SetupDiGetDeviceInterfaceDetail (IntPtr DeviceInfoSet, SP_DEVICE_INTERFACE_DATA DevInterfaceData, byte[] DetailData, int DataSize, ref int RequiredSize, SP_DEVINFO_DATA DeviceInfoData); [DllImport("setupapi.dll", SetLastError = true)] public static extern bool SetupDiDestroyDeviceInfoList (IntPtr DeviceInfoSet); //______________endsetupapi____________ //______________kernel32_____________ [DllImport("Kernel32.dll")] static extern SafeFileHandle CreateFile(string filename, [MarshalAs(UnmanagedType.U4)]FileAccess fileaccess, [MarshalAs(UnmanagedType.U4)]FileShare fileshare, int securityattributes, [MarshalAs(UnmanagedType.U4)]FileMode creationdisposition, int flags, IntPtr template); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool CloseHandle(IntPtr hObject); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool DeviceIoControl( IntPtr hDevice, uint IoControlCode, byte[] InBuffer, int InBufSize, byte[] OutBuffer, int OutBufSize, ref int BytesReturned, OVERLAPPED OverLapped); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool WriteFile(SafeFileHandle hFile, byte[] lpBuffer, Int32 nNumberOfBytesToWrite, ref Int32 lpNumberOfBytesWritten, IntPtr lpOverlapped); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool ReadFile(SafeFileHandle hFile, IntPtr lpBuffer, Int32 nNumberOfBytesToWrite, ref Int32 lpNumberOfBytesWritten, IntPtr lpOverlapped); //______________endkernel32__________ Code: //___________________________________ [StructLayout(LayoutKind.Sequential, Pack = 1)] public class SP_DEVINFO_DATA { public int cbSize; public Guid ClassGuid; public uint DevInst; public uint Reserved; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public class SP_DEVICE_INTERFACE_DATA { public int cbSize; public Guid InterfaceClassGuid; public uint Flags; public uint Reserved; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public class OVERLAPPED { public uint Internal; public uint InternalHigh; public uint Offset; public uint OffsetHigh; public IntPtr hEvent; } //___________________________________ Code: public string read_write_hex1(SafeFileHandle devicehandle, byte[] command, int commandlenght, byte[] inputReportBuffer) { unManagedBuffer = Marshal.AllocHGlobal(inputReportBuffer.Length); numberOfBytesRead = 0; numberOfBytesWritten = 0; success = WriteFile(devicehandle, command, commandlenght, ref numberOfBytesWritten, unManagedOverlapped); Thread.Sleep(5); success = ReadFile(devicehandle, unManagedBuffer, inputReportBuffer.Length, ref numberOfBytesRead, IntPtr.Zero); Marshal.Copy(unManagedBuffer, inputReportBuffer, 0, numberOfBytesRead); byte[] tempReDim = new byte[inputReportBuffer.Length]; if (inputReportBuffer != null) { System.Array.Copy(inputReportBuffer, tempReDim, System.Math.Min(inputReportBuffer.Length, tempReDim.Length)); inputReportBuffer = tempReDim; } string hex = ""; string h = ""; foreach (byte inputReportBuffer_element in inputReportBuffer) { h = inputReportBuffer_element.ToString("X"); if (h.Length < 2) { hex = hex + "0" + h; } else { hex = hex + h; } } return hex; } //_____________end readwrite_hex1________ Code: public string read_write_str(SafeFileHandle devicehandle, byte[] command, int commandlenght, byte[] inputReportBuffer) { unManagedBuffer = Marshal.AllocHGlobal(inputReportBuffer.Length); numberOfBytesRead = 0; numberOfBytesWritten = 0; success = WriteFile(devicehandle, command, commandlenght, ref numberOfBytesWritten, IntPtr.Zero); Thread.Sleep(5); success = ReadFile(devicehandle, unManagedBuffer, inputReportBuffer.Length, ref numberOfBytesRead, unManagedOverlapped); Marshal.Copy(unManagedBuffer, inputReportBuffer, 0, numberOfBytesRead); byte[] tempReDim = new byte[inputReportBuffer.Length]; if (inputReportBuffer != null) { System.Array.Copy(inputReportBuffer, tempReDim, System.Math.Min(inputReportBuffer.Length, tempReDim.Length)); inputReportBuffer = tempReDim; } string rest = ""; string hex = ""; int n = 0; foreach (byte inputReportBuffer_element in inputReportBuffer) { if (n > commandlenght - 1) { hex = hex + inputReportBuffer_element.ToString("X"); if (inputReportBuffer_element <= 0x20) { rest = rest + " "; } else { rest = rest + Convert.ToChar(inputReportBuffer_element); } } n += 1; } return rest.Trim(); } //_____________end readwrite_str________ as I said the phone is connected with path \\.\USB1, we need to open this path with CreateFile function : part of my code : Code: string devpath = "\\\\.\\USB1"; int i = 0; progressBar1.Visible = true; progressBar1.Value = 0; progressBar1.Maximum = 100; while (i <= 2000000) //waiting for phone connexion { deviceHandle = CreateFile(devpath, FileAccess.ReadWrite, FileShare.ReadWrite, 0, FileMode.Open, 128, IntPtr.Zero); if (deviceHandle.IsInvalid == false) { break; } progressBar1.Value = i / 20000; i = i + 1; } Code: byte[] iRB = new byte[20]; SR = read_write_hex1(deviceHandle, pr2, pr2.Length, iRB); phone response is readed as hex and returned in SR; iRB: our buffer; PS: we can use separated functions to read/write (one for read and one for write), it's better I think, in my soft I use a separated functions for more infos about windows api's : pinvoke.net: the interop wiki! ./wbr |
The Following 4 Users Say Thank You to angel25dz For This Useful Post: |
08-29-2011, 13:21 | #4 (permalink) |
No Life Poster Join Date: Mar 2006 Location: .: India :. Heaven on Earth
Posts: 2,496
Member: 238812 Status: Offline Sonork: 100.1602669 Thanks Meter: 1,443 | So I can use function posted for BB5 by frensis but only change GUID to \\\\.\\USB1 ? I am out of my place so cant check anything. Br, Shadab Ahmad |
Bookmarks |
| |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to add a language in 51xx/61xx | tati | Nokia Legacy Phones ( DCT-1 ,2 ,3 ,L ) | 8 | 05-21-2013 19:20 |
imei in 6110 | PIOTRS | Nokia Legacy Phones ( DCT-1 ,2 ,3 ,L ) | 0 | 11-16-1999 18:01 |
blue Display in Nokia Cellphones | TheDon | Nokia Hardware & Hardware Repair | 0 | 10-29-1999 18:28 |
New menu item in 5110 | GeoMan | Nokia Legacy Phones ( DCT-1 ,2 ,3 ,L ) | 3 | 09-23-1999 20:24 |
Lock 2 in nokia 51xx/61xx | Pablo | Nokia Legacy Phones ( DCT-1 ,2 ,3 ,L ) | 1 | 07-31-1999 04:35 |
|