NFC or RFID on Android - NFC Hacking

I have a Nexus5 with NFC reader and I tring to comunicate with RFID tags ISO14443B and ISO14443A, these tags don't respect ISO at 100% for example for ISO14443B not reply to REQB command so android don't detect it.
I tried to comunicate with tags directly with this code:
Code:
Bundle extras = new Bundle();
try {
Class cls = Class.forName("android.nfc.Tag");
Constructor c[] = cls.getConstructors();
Method tags = cls.getMethod("getTagService");
Object tagService = tags.invoke(tag);
Tag t = (Tag)c[0].newInstance(new byte[]{0x00},new int[] { 2 },new Bundle[] { extras },1,tagService);
Method setConnectedTechnology = cls.getMethod("setConnectedTechnology",new Class[]{int.class});
setConnectedTechnology.invoke(tag,2);
NfcB b = NfcB.get(t);
b.connect();
byte a[] = b.transceive(new byte[]{0x02,0x01,0x01,0x04});
}catch(Exception e){ }
but transceive give an error because android monitoring constantly the presence of tag. I tried to receive data with Proxmark3.
I'd like to patch android for implement also not standard protocols, but I don't understand where in source code this comunication is done. Where REQB or REQA are generated?
Someone can help me to find it?
Thank you

etmatrix said:
I have a Nexus5 with NFC reader and I tring to comunicate with RFID tags ISO14443B and ISO14443A, these tags don't respect ISO at 100% for example for ISO14443B not reply to REQB command so android don't detect it.
I tried to comunicate with tags directly with this code:
Code:
Bundle extras = new Bundle();
try {
Class cls = Class.forName("android.nfc.Tag");
Constructor c[] = cls.getConstructors();
Method tags = cls.getMethod("getTagService");
Object tagService = tags.invoke(tag);
Tag t = (Tag)c[0].newInstance(new byte[]{0x00},new int[] { 2 },new Bundle[] { extras },1,tagService);
Method setConnectedTechnology = cls.getMethod("setConnectedTechnology",new Class[]{int.class});
setConnectedTechnology.invoke(tag,2);
NfcB b = NfcB.get(t);
b.connect();
byte a[] = b.transceive(new byte[]{0x02,0x01,0x01,0x04});
}catch(Exception e){ }
but transceive give an error because android monitoring constantly the presence of tag. I tried to receive data with Proxmark3.
I'd like to patch android for implement also not standard protocols, but I don't understand where in source code this comunication is done. Where REQB or REQA are generated?
Someone can help me to find it?
Thank you
Click to expand...
Click to collapse
Hello, I have the same problem, has anyone found a solution?

Related

Call Log API

Does anyone knows how to read the Call Log DB?
Is there any API to do it?
Examples, links anything....
Tnx good people
just use the CeDatabase calls
fields are:
Code:
#define FIELDID(id, type) ((id)<<16 | (type))
enum DBSYSCALLLOG_FIELDS {
// 1 exists, but use is unknown FIELDID(1, CEVT_I2)
DBSYSCALLLOG_START_FIELD=FIELDID(2, CEVT_FILETIME),
DBSYSCALLLOG_END_FIELD=FIELDID(3, CEVT_FILETIME),
DBSYSCALLLOG_CALLTYPE_FIELD=FIELDID(4, CEVT_I4),
// 5 is not used
DBSYSCALLLOG_NUMBER_FIELD=FIELDID(6, CEVT_LPWSTR),
DBSYSCALLLOG_NAME_FIELD=FIELDID(7, CEVT_LPWSTR),
// 8 is not used
// 9 exists, but use is unknown FIELDID(9, CEVT_I4)
DBSYSCALLLOG_NUMBERTYPE_FIELD=FIELDID(10, CEVT_LPWSTR),
};
enum SysCallType {
SYSCALL_MISSED=4,
SYSCALL_OUTGOING=5,
SYSCALL_INCOMING=6,
SYSCALL_REJECTED=7,
};
you have all SDK for Call API inside of MS PPC2003SDK or Smartphone SDK

Problems with WindowsMobile.DirectX TextureLoader.FromFile

I'm trying to develop a simple application to my Omnia 2 in DirectX in VB.NET, but i stuck, really hard. I want to load a simple texture from a file, but the TextureLoader.FromFile gave me an InvalidCallException error. I don't know what to do, because the code is working on the emulator, but throw this error on the phone. I googled it, a lot, but found nothing.
I hope someone can help me in this.
Here's some code fragment. Please someone help me.
Code:
Function InitializeGraphics() As Boolean
Dim Parameters As PresentParameters = New PresentParameters()
Parameters.Windowed = True
Parameters.SwapEffect = SwapEffect.Discard
DeviceForm = New Device(0, DeviceType.Default, Me, CreateFlags.None, Parameters)
Me.OnCreateDevice(DeviceForm, Nothing)
Return True
End Function
Private Sub OnCreateDevice(ByVal sender As Object, _
ByVal e As EventArgs)
Dim dev As Device = CType(sender, Device)
spriteTexture = TextureLoader.FromFile(dev, "\Storage card\Picture.png")
Using s As Surface = spriteTexture.GetSurfaceLevel(0)
Dim desc As SurfaceDescription = s.Description
textureSize = New Rectangle(0, 0, desc.Width, desc.Height)
End Using
sprite = New Sprite(DeviceForm)
End Sub
Here's some picture from the exceptions details.
Nevermind. I solved it.

problem ServiceController

Lack of time has not to schedule time for WM. Right now I have begun to make an application in WM 5.0 but I have the following problem. I intend to retrieve a list of system services to fail to load the phone by the usb. For that I have something like this:
Imports System.ServiceProcess
[...]
Public Function ActivarCargaUSB(ByVal param As Integer) As Integer
Dim services() As ServiceController
services = ServiceController.GetServices()
End Function
But Visual Studio tells me that: We need a reference to assembly 'System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' containing the base class 'System.ComponentModel.Component'. Add one to your project.
Someone tells me how I can add that library? or some method to stop charging the battery by usb?
thanks
please help! As ServiceController declare the type correctly?
I need help please ...
amocu said:
Lack of time has not to schedule time for WM. Right now I have begun to make an application in WM 5.0 but I have the following problem. I intend to retrieve a list of system services to fail to load the phone by the usb. For that I have something like this:
Imports System.ServiceProcess
[...]
Public Function ActivarCargaUSB(ByVal param As Integer) As Integer
Dim services() As ServiceController
services = ServiceController.GetServices()
End Function
But Visual Studio tells me that: We need a reference to assembly 'System, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' containing the base class 'System.ComponentModel.Component'. Add one to your project.
Someone tells me how I can add that library? or some method to stop charging the battery by usb?
thanks
Click to expand...
Click to collapse
You can use registry key for control battery charge usb. If you need i post example code.

[Q] Standard and Professional

Newbie here. Maybe someone can give me some direction. I am writing an app for both standard and professional. I have 2 projects in my solution. One is for standard the othe is for professional. I am not sure if this is the right way or not but what I want to do is when the app opens it checks to see what platform is running and then runs the correct project. Any help would be greatly appreciated.
It is possible to create a single project that is capable of running on both platforms but there is quite a bit of groundwork you will have to do first.
Firstly, the main differences.
Standard : No touch screen i.e. No Mouse events. All user input is via the keyboard, buttons, D-PAD and ENTER. No Open/Save dialogboxes, you have to present the files to the user yourself. Message dialogs appear full screen.
Professional : None of the above limitations.
The are a few pointers here:
http://msdn.microsoft.com/en-us/library/bb985500.aspx
The following code will detect the platform and set the variable 'SmartPhone' to 1 (true) if the version is 'Standard'
Code:
#define MAX_LOADSTRING 100
int SmartPhone;
TCHAR szReturn[MAX_LOADSTRING];
SystemParametersInfo(SPI_GETPLATFORMTYPE,MAX_LOADSTRING,szReturn,false);
SmartPhone=wcscmp(TEXT("SmartPhone"),szReturn)^1;
Your processing code may have code such as:
Code:
if(SmartPhone)
{
........ Standard Stuff.......
}
else
{
......... Professional Stuff........
}
Note also that code dealing with a WM_LBUTTONDOWN message will never be executed on a smartphone, as WinMo Standard never generates this message.
It may seem a pain, but you only have one executable to deliver for both platforms.
As an example, here's one I prepared earlier.
http://forum.xda-developers.com/showthread.php?t=509413
more info
I am coding with VB. What I was thinking was creating a class project and making that the startup project. Within the class the VB would check the platform and then run the correct project.
Should work:
To get the Platform type in .NET CF have a look at:
http://msdn.microsoft.com/en-us/library/ms229660(VS.90).aspx
It's also listed in the VS Help.
I am using VS2008 TS and cf3.5. I have tried several methods and still can't get any to work. I must be missing a reference or something. Here is some code I can't get to work.
If SystemSettings.Platform = WinCEPlatform.PocketPC Then
txtDeviceType.Text = "Windows Mobile Professional"
ElseIf SystemSettings.Platform = WinCEPlatform.Smartphone Then
txtDeviceType.Text = "Windows Mobile Standard"
Else
txtDeviceType.Text = "Not Windows Mobile"
End If
Also tried this.
Public Enumeration WinCEPlatform
Dim instance As WinCEPlatform
I also tried getversionex but couldn't get it to work either.
I only code .NET in C# but there is virtually no difference.
Try this: You will have to add the reference to Microsoft.WindowsCE.Forms;
Right click on References in the Solution Explorer, click on Add Reference, in the .NET Tab, pick it out of the list.
Code:
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
WinCEPlatform Platform = new WinCEPlatform();
Platform = SystemSettings.Platform;
label1.Text = Platform.ToString();
}
}
}
Works a treat!
Let's let Red Gate's Reflector translate the IL into VB.
It also reveals that the compiler rips outs the middle variables and goes straight for :
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Me.label1.Text = SystemSettings.Platform.ToString
End Sub
I am getting an error on this InitializeComponent. Another question. Can I add a class project and use this code to point to the correct project?
Drop the InitialiseComponent function, that is only used used in C#
In VB in Form1 the only code you need is
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = Microsoft.WindowsCE.Forms.SystemSettings.Platform.ToString
End Sub
End Class
This code works and puts "YES" in the box if run on a PPC
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Microsoft.WindowsCE.Forms.SystemSettings.Platform = Microsoft.WindowsCE.Forms.WinCEPlatform.PocketPC Then
Label1.Text = "YES"
End If
End Sub
End Class
Ok. I got it to work with the following code. But I have another problem. My app is a very simple app. I want it to work on PPC2003 and smartphones. I have 2 different forms for standard and professional. Now the problem is that if I use .net compact framework 3.5 then the device has to have that installed. So if I want to the app to work on older devices it won't work without the .net compact framework. If I use .net compact framework 2.0 then I lose the ability to use the code to determine if its standard or professional. I was hoping there was a way to include the 3.5 CF into my app cab but I haven't seen it. I am currently using VS2008 whcih only allows you 2.0 CF and 3.5 CF. I was thinking about using VS2005 and use 1.0 CF so it would work on all Windows mobile devices. But then I would again lose the ability to use the code. Any ideas would be appreciated.
Shared Sub Main()
Dim Platform As New WinCEPlatform()
Platform = SystemSettings.Platform
If Platform = "1" Then
Application.Run(
New Pro())
ElseIf Platform = "2" Then
Application.Run(
New Standard())
End If
End Sub
Using VS2005 I started a new project and selected SmartDevice 1.0. Now I have some issues.
1. Trying to determine either standard or professional. I am trying to use the Pinvoke to do this. No luck so far. I get an error on ByVal nFolder As ceFolders.
2. The code I was using to play a .wav file no longer works.
Dim myplayer As New System.Media.SoundPlayer(New IO.MemoryStream(My.Resources.Dice))
myplayer.Play()
3. I had resource files for images and a wav file so my code to use these no longer work.
Me.PictureBox1.Image = My.Resources.red_die_1_th
1. I'll have a look at it. Watch this space.
2. The SoundPlayer object is only available from .net CF 3.5 onwards. To play sounds you my have to PInvoke PlaySound()
http://msdn.microsoft.com/en-us/library/ms229685(v=VS.80).aspx
3. Should work, but maybe there's a difference in the frameworks. Microsoft's catch-all is that not all methods, properties etc. are supported in all .NET or .NET CF. versions. You may end up doing it in two stages, create a bitmap image from the resource, then pass that to the picturebox.
The answer to 1 is below. This works in C# under VS2003 .NET CF 1.0 but it is only in C#, I do not have VB installed on this machine. You will have to reverse engineer it into VB yourself, not too difficult. The important code is the DLLImport definition, the SPI_GETPLATFORMTYPE definition, and the call of the function in Form1_Load().
On program start "PocketPC" appears in the label on screen.
Code:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace PInvTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MainMenu mainMenu1;
[DllImport("coredll.dll", EntryPoint="SystemParametersInfo", SetLastError=true)]
private static extern int SystemParametersInfo(
int uiAction, int uiParam, string pvParam, int fWinIni);
private const int SPI_GETPLATFORMTYPE = 257;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
string Platform = new string(' ',20);
SystemParametersInfo(SPI_GETPLATFORMTYPE,Platform.Length,Platform,0);
label1.Text=Platform;
}
}
}

Advice on strategy

I'm developing a WP7 app, working alongside a Windows (server) application. They are talking with each other using sockets.
As soon as the WP7 app opens, I wish to perform a network scan to find the server application.
I already found out how to get the IP address of the WP7. So let's say I know the server should be somewhere at 192.168.0.*. How do I go about scanning this network?
I tried many things, the last of which is the code below. The problem here is that somehow the TIMEOUT_MILLISECONDS parameter seems to be like playing roulette (tried everything in the range of 100-2000 with different success). In addition, if I sweep the whole subnet like in the code below the phone cannot seem to handle the work. I only get it to work if I set the timeout to 2000 (which is way to long) and by scanning up to 5 IP's in the for-loop, instead of the whole subnet.
Is there anyone that knows a better and much more efficient(!) way to do this?
Code:
string thisIP = "192.168.0.101"; // I normally get this from some other function
string[] arrIP = thisIP.ToString().Split('.');
string IPBase = arrIP[0] + "." + arrIP[1] + "." + arrIP[2] + ".";
//MessageBox.Show(address.ToString());
for (int i = 2; i < 254; i++) {
string IP = IPBase + i;
CheckConnection CheckConn = new CheckConnection();
string resultConnect = CheckConn.Connect(IP, int.Parse(Resource1.port));
if (resultConnect == "Success") {
CheckConn.Send("isAlive");
string result = CheckConn.Receive();
if (result.Contains("yes")) {
// We have found the server
break;
}
}
CheckConn.Close();
}
Code:
public class CheckConnection
{
// Cached Socket object that will be used by each call for the lifetime of this class
Socket _socket = null;
static ManualResetEvent _clientDone = new ManualResetEvent(false);
const int TIMEOUT_MILLISECONDS = 100;
const int MAX_BUFFER_SIZE = 2048;
public string Connect(string hostName, int portNumber) {
string result = string.Empty;
DnsEndPoint hostEntry = new DnsEndPoint(hostName, portNumber);
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = hostEntry;
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e) {
result = e.SocketError.ToString();
_clientDone.Set();
});
_clientDone.Reset();
_socket.ConnectAsync(socketEventArg);
_clientDone.WaitOne(TIMEOUT_MILLISECONDS);
return result;
}
public string Send(string data) {
string response = "Operation Timeout";
if (_socket != null) {
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint;
socketEventArg.UserToken = null;
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e) {
response = e.SocketError.ToString();
_clientDone.Set();
});
byte[] payload = Encoding.UTF8.GetBytes(data);
socketEventArg.SetBuffer(payload, 0, payload.Length);
_clientDone.Reset();
_socket.SendAsync(socketEventArg);
// Block the UI thread for a maximum of TIMEOUT_MILLISECONDS seconds.
// If no response comes back within this time then proceed
_clientDone.WaitOne(TIMEOUT_MILLISECONDS);
}
else {
response = "Socket is not initialized";
}
return response;
}
public string Receive() {
string response = "Operation Timeout";
if (_socket != null) {
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint;
socketEventArg.SetBuffer(new Byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e) {
if (e.SocketError == SocketError.Success) {
response = Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred);
response = response.Trim('\0');
}
else {
response = e.SocketError.ToString();
}
_clientDone.Set();
});
_clientDone.Reset();
_socket.ReceiveAsync(socketEventArg);
_clientDone.WaitOne(TIMEOUT_MILLISECONDS);
}
else {
response = "Socket is not initialized";
}
return response;
}
public void Close() {
if (_socket != null) {
_socket.Close();
}
}
}
Why you don't know the server IP?
I can't help you with your subnet scanning problem, don't have experience with that corner of WP7 programming.
But I do wonder what kind of arrangement leads to the problem that your app does not know the server address and therefore has to scan for it. Is neither a fixed IP available for your server nor some kind of DNS service up to tell you the current IP?
Even if there are multiple servers running and the phone has the job to somehow decide which one of those is responsible for it, you still could set up some kind of super-server that the phones could ask first which server they should address.
In any way, phones scanning subnets to find servers as some routine app startup action is a bad idea, if you ask me.
Please note that by 'server' I'm just revering to a software that accepts socket connections. This software is installed into a Windows computer that most likely has it's IP from DHCP.
The server software itself could present it's IP address so the end-user can type this address into the client on their WP7. Nice for tech-savvy folks, but that's not how software should be designed in my opinion. People don't need to know what an IP address is and shouldn't be force into typing 'weird numbers'. Properly designed software just have to work instantly and developers (again in my opinion) need to take care of a good design and that includes making things plug-and-play where they can.
Take a look at 'PC Remote' and you will see the kind of easy plug-and-play experience I'm looking for.
Did you check broadcast?
I'm really not network guy, but from Googling I got the impression that people use broadcast instead of IP range scanning for such IP number discovery tasks, and there seems to be a way to do broadcast on WP7 (albeit only using some tricks / hardly documented functionalilty):
E.g. see this thread:
http://stackoverflow.com/questions/8533471/udp-broadcasting-in-windows-phone-7
Which links to this:
http://forums.create.msdn.com/forums/t/88975.aspx
This makes sense to me after reading that broadcast is also the method how a client finds its DHCP server - isn't that the exact same scenario like yours?
Did you already check this way of looking at the problem, or maybe rule it out already for some reason?
It's better if you use a multicast group to send/receive packages. I had way better experience with it than using the Broadcast IP.
You need to join the multicast group with the phone and with the server app. I know there are multicast classes but I found it easier and mor convient to implement it with a socket...
And after you found the server, I'd use a persistent tcp connection which should improve your network performance (udp and wp7 is sometimes really strange...)
Thanks rbrunner7 and chabun for your comments, I appreciate your input!
rbrunner7 said:
Did you already check this way of looking at the problem, or maybe rule it out already for some reason?
Click to expand...
Click to collapse
I did, briefly, but abandoned this path after reading about the physical network equipment (switches etc.) having the need to support broadcasting which might not always be the case.
Anyway, your mentioned post describes 'limited broadcasting', which might be exactly what I should be looking for. Hopefully hardware limitations will not be applicable; I will look into this method further and will let you know how it works out!
roady001 said:
the physical network equipment (switches etc.) having the need to support broadcasting which might not always be the case.
Click to expand...
Click to collapse
I had the same doubts about that as it's also the case for multicasting. Most modern equipement supports it though and you can always provide the possibility to manually enter the server ip if you can't discover one via multicast/broadcast

Categories

Resources