View Full Version : VB p2k source code
swampsucka247
05-27-2007, 08:05 AM
Is anyone here into p2kapi programming with VisualBasic.NET? I can't seem to find many examples to learn from. Know of any good places to start or have a link to share?
MstrSteve
06-01-2007, 07:18 AM
I know a lil something about visual basic. What exactly are you asking about? If it's api code specific, I'll need to know 3 things:
1) What version of Visual Studio you are using as many things are different between 2003 and 2005.
2) What you are trying to do. (just the general idea)
3) Where you got the P2kapi so I can Download it to see how it was coded. ie: variable names, array lists, parameters, database type(if any),etc.
-MstrSteve
swampsucka247
06-02-2007, 04:19 AM
1) I have Visual Basic 2005 Express
2) I'm really not trying to reinvent the wheel or anything, I just have a love of this sort of thing.. I really would like to have a better understanding of how the p2kapi.dll is used to communicate with, and manipulate the device. I realize that there is a program out there that can do anything that I need to do to my phones, but being able to see the code, that I wrote, running, just gets me all excited because I am a nerd :cool: I have some experience programming smart cards,and a *little* PLC programming and that sort of thing - kind of a hobby, I guess you could say.
3) If you want, I will PM you a link to my *massive* :lol:(it's like 60kb, zipped) stash of code and maybe you can find something useful in there! Or I guess I can post it for all, if anyone else is interested.
This includes code by Vilko, dwALX, s5vi, & motoprogger.
swampsucka247
06-02-2007, 08:10 AM
As promised... here is the link to the file http://www.mediafire.com/?0lz0xmydyw1
This File Has Not Been Tested Or Inspected By The MotoModding.US Staff - Do Not Use These Files Unless You Are Absolutley Sure You Know What You Are Doing! I, nor MotoModding.US Can Be Held Responsible For any Damages!
8) - peace
MstrSteve
06-03-2007, 03:30 PM
Thanx. I'll have a look at it and see what is what. Give me a day or 2 to get my bearings in the code and do a few tests.
swampsucka247
06-03-2007, 10:12 PM
so far all i've been brave enough to do to my phone was to reboot it and get the status didn't want to get into the seem functions just yet... all i've got is this one v3i right now... hindsight - see post here -> doh! (http://motomodding.us/viewtopic.php?t=678&highlight=) :bang: intrested to see what you find
swampsucka247
06-03-2007, 10:23 PM
just a thought
I guess it ain't all Hee-Haw and Larry the Cable Guy out here in the sticks anymore, but i haven't found anyone else in the State of Arkansas who would be into using .NET to mod thier cell phone - lol
MstrSteve
06-05-2007, 06:41 PM
How did you go about figuring what parameters to send to the p2kapi2.dll or what functions to call? I had to get an external decompiler to get into the .dll source code. I'm finding the .txt files rather unhelpful as they seem rather thrown together rather than laid out in a way that encapsulates individual processes. I understand your confusion entirely. lol
Free Decompiler found here (http://www.aisto.com/roeder/dotnet).
Add-ins for Decompiler here (http://www.codeplex.com/reflectoraddins).
swampsucka247
06-06-2007, 02:15 AM
...I'm finding the .txt files rather unhelpful as they seem rather thrown together rather than laid out in a way that encapsulates individual processes...
lol good so it's not just me, then! I'm gonna check out that decompiler tonight - thanks for the link!
Re: Reboot was done with a bas that I had, and cannot find at this moment - will try to locate 4 you - peace
swampsucka247
06-06-2007, 06:57 AM
This ones a little neater
Dynamically linked library for Motorola P2K phones
Copyright Vilko :)
Version 2.8
Functions:
P2K_SendCMD (DWORD Cmd, void* SendBuff, DWORD SendSize, void* RecvBuff,
DWORD* RecvSize);
this function only for advanced users
File_ListEx(ptr Buffer, dword Count,ProgressFuncPtr)
First parameter as in File_List
ProgressFuncPtr - pointer to function:
void __stdcall TestFunc(FILELIST* fl, int CurIndex, int TotalCount)
fl - pointer to FILELIST structures File_listEx
CurIndex - index of last file name
TotalCount - count of records
Example:
void __stdcall TestFunc(FILELIST* fl, int CurIndex, int TotalCount)
{
if (!TotalCount) return;
float f = ((float)CurIndex/TotalCount) * 100;
Log(clBlack,"p2kapi.GetFileListEx: completed %2.0f%% - %s",f,fl[CurIndex].FileName);
}
...
// somewhere, when we want to get filelist
int FileCount = p2k->GetFileCountEx("/a/*");
FILELIST *fl = new FILELIST[FileCount];
p2k->GetFileListEx(FileList,FileCount,TestFunc);
Mode_SwitchToP2k(StatusProc)
Switch phone from AT mode to P2K
if not called P2K_Init, it's will be called with StatusProc parameter
(no return value)
Mode_SwitchToAT()
Switch phone from P2K mode to AT
(no return value)
P2K_Init(StatusProc);
Library initialization, phone status monitor starting.
StatusProc - pointer to a procedure, that will be called on phone detect/disconect (or 0, if procedure call is not needing).
Returns 0 on initialization success or 1 on failure.
Library calls StatusProc procedure with one parameter:
1 - if phone detected; 0 - if phone not detected.
P2K_Restart();
Restart a phone.
P2K_Suspend();
Switch phone to suspended mode
P2K_GetStatus();
Gets connection status.
Returns 0 if phone not found or 1 if phone found.
File_CreateDir(lpstr FileName, byte Attribute);
Creates new directory
lpstr DirName - pointer to string containing a directory name
byte Attribute - new attribute for a created dir
Attribute is combination of 3 bits:
bit0 - readonly
bit1 - hidden
bit2 - system
Returns always 0.
File_DeleteDir(lpstr DirName);
Deleting a directory
lpstr FileName - pointer to a string containing directory name
Returns 0 if success or -1 on error.
File_Create(lpstr FileName, byte Attribute);
Creates new or opens existing file
lpstr FileName - pointer to string containing a file name (in case of nested filesystem - full path with directories)
byte Attribute - new attribute for a created/opened file
Attribute is combination of 3 bits:
bit0 - readonly
bit1 - hidden
bit2 - system
Phone not allows to open more than 1 file simultaneously.
Returns 0 if opening was success or -1 on error.
(advanced error codes - :) please wait for next version)
File_Close();
Closes previously opened file.
Returns 0 if closing was success or -1 on error.
File_Read(ptr Buffer, dword Size);
Reading data from file.
Reads data from BOF or from position, what was setted by File_SetPointer function.
ptr Buffer - pointer to a buffer for receiving data from a file.
dword Size - data size to read. Buffer size couldn't be less then this size.
Returns 0 if reading was success or -1 on error.
File_Write(ptr Buffer, dword Size);
Writing data to a file.
Writes data from BOF or from position, what was setted by File_SetPointer function.
ptr Buffer - pointer to a buffer containing data to write.
dword Size - data size to write.
Returns 0 if writing was success or -1 on error.
ATTENTION! This function not checks a free space for writing.
But phone needs for a some free space for temporary files created by phone.
File_SetPointer(dword Offset, byte MoveMethod);
Set pointer to file reading/writing
dword Offset - new position of pointer
byte MoveMethod - pointer setting method:
0 - offset from BOF
1 - offset from current position of pointer
2 - offset from EOF
Returns 0 if success or -1 on error.
File_Delete(lpstr FileName);
Deleting a file
lpstr FileName - pointer to a string containing file name (in case of nested filesystem - full path with directories) to delete.
Returns 0 if success or -1 on error.
File_VolInfo(ptr Buffer);
Receiving an information about free space and volume name.
ptr Buffer - pointer to a buffer for volume name receiving (must be >= 128 bytes)
Returns free space size in bytes or -1 on error.
File_GetFreeSpace(lpstr disk)
Receiving an information about free space
lpstr disk - name of idsk ("/c/")
File_CountEx(lpstr disk_and_mask);
Receiving an information about files count in phone.
Returns files count or -1 on error.
lpstr disk_and_mask) - pointer to disk name and mask ("/c/*.mp3").
File_Count();
Receiving an information about files count in phone.
Returns files count or -1 on error.
File_List(ptr Buffer, word Count);
Receiving a file list from phone. File_Count() function must be called directly before this function.
ptr Buffer - pointer to a buffer for files list receiving
files list is saved as:
dd file size
dw attribute 1
dw attribute 2
string of 1F8h length - file name.
Record size per 1 file is 200h bytes
Records count is equivalent to files count in phone (result of File_Count() function)
According to this, size of buffer for files list must be File_Count*200h
word Count - files count to read (result of File_Count() function)
Returns a maximum length of file name for current phone model or -1 on error..
Seem_Read(word SeemNo, word RecordNo,word StartOffset,word Bytes, ptr Data);
Reading of seem cell
SeemNo - Seem cell number
RecordNo - Seem record number
StartOffset - Offset for seem reading from (0 - from cell beginning)
Bytes - Bytes count for reading (0 - read from beginning to end)
ptr Data - pointer to a buffer for receiving seem cell data
If "Bytes" parameter not specified, then buffer length must be >= 2710h bytes
Returns count of readed bytes or -1 on error.
Seem_Write(word SeemNo, word RecordNo, word StartOffset, word Bytes, ptr Data);
Writing seem cell
SeemNo - Seem cell number
RecordNo - Seem record number
StartOffset - Offset for seem writing from (0 - from cell beginning)
Bytes - Bytes count for writing (0 - write from beginning to end)
ptr Data - pointer to a buffer containing seem cell data for writing
Returns 0 if writing was success or -1 on error.
btw code was made public @ Motofan.ru by Vilko - post here (http://forum.motofan.ru/index.php?s=3cb47ba9d250b118e7b157070dc7b65f&showtopic=11780)
swampsucka247
06-06-2007, 07:05 AM
guess i'll be brushing up on my C/C++ after all :wink:
swampsucka247
06-13-2007, 04:40 AM
Is This Correct?
Module p2kapi
Public Declare Function P2K_SendCMD Lib "p2kapi2.dll" (ByVal Cmd As String, ByVal SendBuff As String, ByVal SendSize As Integer, ByVal RecvBuff As Integer, ByVal RecvSize As Integer()) As Integer
Public Declare Function P2K_Init Lib "p2kapi2.dll" (ByVal StatusProc As IntPtr) As Integer
Public Declare Function P2K_GetStatus Lib "p2kapi2.dll" () As Integer
Public Declare Function P2K_Restart Lib "p2kapi2.dll" () As Integer
Public Declare Function Seem_Read Lib "p2kapi2.dll" (ByVal SeemNo As Integer, ByVal RecordNo As Integer, ByVal StartOffset As Integer, ByVal Bytes As Integer, ByVal data As Byte()) As Integer
Public Declare Function Seem_Write Lib "p2kapi2.dll" (ByVal SeemNo As Integer, ByVal RecordNo As Integer, ByVal StartOffset As Integer, ByVal Bytes As Integer, ByVal data As Byte()) As Integer
Public Declare Function Mode_SwitchToAT Lib "p2kapi2.dll" () As Integer
Public Declare Function Mode_SwitchToP2k Lib "p2kapi2.dll" (ByVal StatusProc As IntPtr) As Integer
Public Declare Function File_CreateDir Lib "p2kapi2.dll" (ByVal FileName As String, ByVal Attribute As Byte)
Public Declare Function File_DeleteDir Lib "p2kapi2.dll" (ByVal DirName As String)
Public Declare Function File_Create Lib "p2kapi2.dll" (ByVal FileName As String, ByVal Attribute As Byte)
Public Declare Function File_Close Lib "p2kapi2.dll" ()
Public Declare Function File_Write Lib "p2kapi2.dll" (ByVal Buffer As String, ByVal Size As Integer)
Public Declare Function File_SetPointer Lib "p2kapi2.dll" (ByVal Offset As String, ByVal MoveMethod As Byte)
Public Declare Function File_Delete Lib "p2kapi2.dll" (ByVal FileName As String)
Public Declare Function File_VolInfo Lib "p2kapi2.dll" (ByVal Buffer As String)
Public Declare Function File_GetFreeSpace Lib "p2kapi2.dll" (ByVal disk As String) As Integer
Public Declare Function File_CountEx Lib "p2kapi2.dll" (ByVal disk_and_mask As String) As Integer
Public Declare Function File_Count Lib "p2kapi2.dll" () As Integer
Public Declare Function File_List Lib "p2kapi2.dll" (ByVal Buffer As String, ByVal Count As Integer)
Public connect As Integer
End Module
MstrSteve
06-16-2007, 06:48 AM
If those are the variable designations for functions, then yes it looks about right.
I'm not really sure what you're asking me. If your asking if they will work the way you want them to.... lol you know what I mean.
Remember you have to instanciate(sp?) them up top b4 the page load event but under the auto generated code section in VB.
swampsucka247
06-16-2007, 08:13 AM
If those are the variable designations for functions, then yes it looks about right. 8) - yeah that's what i was asking about! - thought i'd ask you about it thought maybe i had missed something in the desiginations - thanks again MstrSteve - :wink:
vermsky
07-21-2007, 07:28 AM
Just a suggestion, but you may want to check the How to create FB3 profiles in the guides section for additional info about the structure of the flashfile. I do think that it's helpful.
swampsucka247
07-23-2007, 03:50 AM
Thanks vermsky i will check it out!
btw a woodchuck would chuck as much wood as a woodchuck could chuck, if a woodchuck could chuck wood.
vBulletin® v3.7.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.