Archive

Archive for May, 2020

Car Registration #API for #Israel

Israel is a country with 2.9 Million vehicles, and a population of 8.8 million, giving a total car ownership percentage of 33%.

We have just launched an API in Israel, that allows uses to search for a vehicle by license plate (Registration Number), and will return technical details about that vehicle.

This API can be used to determine, the make, model, VIN, and other technical specifications of a vehicle registered in Israel from it’s registration number (license plate). The API applies to cars, motorbikes, and heavy vehicles.

The website is available in Hebrew here ; http://www.rechevapi.co.il/ but, equally, the API can be accessed via any of our other websites, such as here; https://carregistrationapi.com/api/reg.asmx – using the same account, and credits.

Here is an excerpt from our documentation:

Israel support

Offline data available
Car registration plates in Israel use the /CheckIsrael  endpoint and return the following information:

  • Make / Model
  • Age
  • VIN number
  • Fuel
  • Engine size
  • Representative image

Sample Registration Number: 

1011928

Sample Json:

{

  “Description”: “Porsche CAYENNE”,

  “Variant”: “PLATINUM”,

  “RegistrationYear”: 2017,

  “CarMake”: {

    “CurrentTextValue”: “Porsche”

  },

  “CarModel”: {

    “CurrentTextValue”: “CAYENNE”

  },

  “MakeDescription”: {

    “CurrentTextValue”: “Porsche”

  },

  “ModelDescription”: {

    “CurrentTextValue”: “CAYENNE”

  },

  “VehicleIdentificationNumber”: “WP1ZZZ92ZHLA32339”,

  “Fuel”: “Diesel”,

  “EngineSize”: “2967”,

  “Co2”: “179”,

  “HorsePower”: “262”,

  “IsAutomatic”: “1”,

  “Doors”: “5”,

  “Seats”: “5”,

  “Weight”: “2870”,

  “EngineCode”: “CVVA”,

  “VehicleUse”: “P”,

  “TestDate”: “02/01/2020 00:00:00”,

  “LicenseDate”: “11/01/2021 00:00:00”,

  “MakeHebrew”: “פורשה גרמניה”,

  “VehicleType”: “Car”,

  “ImageUrl”: “http://rechevapi.co.il/image.aspx/@UG9yc2NoZSBDQVlFTk5F”

}

Categories: Uncategorized

C# 300% #performance increase Dictionaries vs #Linq

Simple statment, if you are holding large (1M+) objects in memory, use a Dictionary, don’t use Linq on a Generic List. I saw a 300% improvement using this approach.

So, here is, in pseudocode what I’m talking about.

// SLOW!

List<SomeObject> myList = new List<SomeObject>()

.. Add 1M items to myList

var myObject = myList.FirstOrDefault(o => o.property==id);

Whereas, if you can do this:

// FAST!

Dictionary<int,SomeObject> dList = new Dictionary<int,SomeObject>();

.. Add 1M items to dList

var myObject = dList[id];

It is 300% faster.

My benchmarking code created a 1M item list, and a 1M item dictionary, and ran 100 lookups on each. The Linq approach took 7.6 Seconds, the dictionary took 2 seconds.

Of course, you lose the flexibility of writing filters on other properties, or more complex lookups other than equality.

Categories: Uncategorized

Extracting data from a running process #Windows / #WindowsSecurity

CreateDumpFile

In this particular instance, I had a long running EXE, that crashed, but didn’t terminate. I couldn’t restart it, but I see that it was still in- memory, so I wanted to see if I could rescue the data from it, or at least some of the data, there was about a 1GB memory footprint.

So, I opened task manager, and Right Click > Create memory dump, and it created a 1GB file. I opened this file in GLOGG, a large file viewer.

dump

And… lo and behold, amonst alot of binary data, there was plain text, that could be easily extracted. Like in this screenshot, where you can see HTML in plain text.

This also may serve as an alarm bell for any software that might hold passwords or sensitive information in memory. Make sure that passwords are not held in static variables, since this approach could be used to extract them.

Categories: Uncategorized

#OpenSource web crawler in C# based on #HTMLAgilityPack

crawler

TL; DR;

Here’s the Repo; https://github.com/infiniteloopltd/WebCrawler/

A Web Spider based using HTMLAgilityPack. This library will follow links within webpages in order to find more webpages, it works asynchronously, and will fire events every time a new page is encountered.

A few caveats, is that it’s single-threaded, so, it’s going to be rather slow. It holds it’s queue in memory, so it’s going to be a memory hog on really large websites. It also doesn’t obey Robots.txt.

Please feel free to fork this library, and improve upon it!

Sample Usage

  Spider.OnQueueUpdate = q =>
  {   
      Console.WriteLine("Crawler Queue updated : " + q);
      if (q == 0)
      {
          // when this reaches 0, then the crawl is complete
          Console.WriteLine("Crawl Complete");
      }
  };
  Spider.OnVisitedPage = (webpage,content) =>
  {
      Console.WriteLine("Crawler visited : " + webpage.Url);
  };
  Spider.OnCrawlError = (webpage, ex) =>
  {
      Console.WriteLine("Crawler hit error at : " + webpage.Url);
  };
  Spider.StartPage = new Uri("https://www.cloudansweringmachine.com/");
  Spider.Scope = "https://www.cloudansweringmachine.com/"; // Don't leave this domain.
  Spider.Start();
  Console.WriteLine("Crawl stated, press enter to stop.");
  Console.ReadLine();

httpsimage.com

 

Categories: Uncategorized

Decode an SSL Cert from a byte array in C#

en_ssl-header

This is more of a useful code snippet than any great revelation, however, if you ever needed to convert a byte array of a X509 cert into a X509 certificate object, then here’s how you do it using BouncyCastle

var certificateBase64 = File.ReadAllText(“cert.txt”);
var certData = Convert.FromBase64String(certificateBase64);
var parser = new X509CertificateParser();
var cert = parser.ReadCertificate(certData);

Really easy!; Here’s the project on GitHub – https://github.com/infiniteloopltd/CertificateDecoder

 

Categories: Uncategorized

First #Dart / #Flutter Package published

dart-package

https://pub.dev/packages/license_plate_api_uk

And, I’ve also set up a verified publisher here; https://pub.dev/publishers/infiniteloop.ie/packages

license_plate_api_uk 1.0.2

license_plate_api_uk

A Dart package for looking up technical details on vehicles registered in the UK by their license plate (VRM)

license_plate_api_uk provides a simple way to find vehicle details from a license plate (registration number) of a car, motorbike, or HGV registered in the United Kingdom.

This requires a username and password, which is available for free from https://www.regcheck.org.uk

Usage

A simple usage example:

import 'package:license_plate_api_uk/license_plate_api_uk.dart' as RegCheck;

void main(List<String> arguments) async {
  // Usage:
  // dart bin/main.dart *VRM* *USERNAME* *PASSWORD*
  // Where *VRM* is a UK vehicle registration mark (license plate)
  // *USERNAME* and *PASSWORD* are available from https://www.regcheck.org.uk
  var vehicle = await RegCheck.LicensePlateUK(arguments[0],arguments[1],arguments[2]);
  print('Description: ${vehicle['Description']}');
  print('Engine: ${vehicle['EngineSize']['CurrentTextValue']}');
  print('Fuel Type: ${vehicle['FuelType']['CurrentTextValue']}');
  print('Transmission: ${vehicle['Transmission']['CurrentTextValue']}');
  print('Image: ${vehicle['ImageUrl']}');  
  print('Body Style: ${vehicle['BodyStyle']['CurrentTextValue']}');
  print('Colour: ${vehicle['Colour']}');
  print('Registration Date: ${vehicle['RegistrationDate']}');
  print('Engine Number: ${vehicle['EngineNumber']}');
  print('VIN: ${vehicle['VehicleIdentificationNumber']}');
}

which produces the following:

Description: VAUXHALL MOKKA SE
Engine: 1364
Fuel Type: Petrol
Transmission: Automatic
Image: https://www.regcheck.org.uk/image.aspx/@VkFVWEhBTEwgTU9LS0EgU0U=
Body Style: Hatchback
Colour: BLUE
Registration Date: 01/06/2014
Engine Number: A14NET 140580075LUJ
VIN: W0LJD7E85EB690449

Features and bugs

Please file feature requests and bugs via the website http://www.regcheck.org.uk

Categories: Uncategorized

Call a JSON-based #API with basic authentication using #Dart / #Flutter

dart

TL;DR; 

The Github repo is here, for anyone to clone / fork : https://github.com/infiniteloopltd/DartLicensePlateAPI

What this does, is call a JSON based API, using basic authentication using the Dart programming language. The code is pretty simple, and it only requires ‘http’ as a dependency.

import ‘package:http/http.dart’ as http;
import ‘dart:convert’ as convert;

Future<dynamic> LicensePlateUK(String Reg, String Username, String Password) async {
String basicAuth = ‘Basic ‘ + convert.base64Encode(convert.utf8.encode(‘$Username:$Password’));
String url = ‘https://www.regcheck.org.uk/api/json.aspx/Check/$Reg&#8217;;
var response = await http.get(url,
headers: <String, String>{‘authorization’: basicAuth});
return convert.jsonDecode(response.body);
}

Which can be consumed as follows;

import ‘package:RegCheck/RegCheck.dart’ as RegCheck;

void main(List<String> arguments) async {
// Usage:
// dart bin/main.dart *VRM* *USERNAME* *PASSWORD*
// Where *VRM* is a UK vehicle registration mark (license plate)
// *USERNAME* and *PASSWORD* are available from https://www.regcheck.org.uk
var vehicle = await RegCheck.LicensePlateUK(arguments[0],arguments[1],arguments[2]);
print(‘Description: ${vehicle[‘Description’]}’);
print(‘Engine: ${vehicle[‘EngineSize’][‘CurrentTextValue’]}’);
print(‘Fuel Type: ${vehicle[‘FuelType’][‘CurrentTextValue’]}’);
print(‘Transmission: ${vehicle[‘Transmission’][‘CurrentTextValue’]}’);
print(‘Image: ${vehicle[‘ImageUrl’]}’);
print(‘Body Style: ${vehicle[‘BodyStyle’][‘CurrentTextValue’]}’);
print(‘Colour: ${vehicle[‘Colour’]}’);
print(‘Registration Date: ${vehicle[‘RegistrationDate’]}’);
print(‘Engine Number: ${vehicle[‘EngineNumber’]}’);
print(‘VIN: ${vehicle[‘VehicleIdentificationNumber’]}’);
}

I’m going to publish a package to pub.dev once I figure out how to do that!

Categories: Uncategorized

Push Notifications #iOS13 with Cordova PushPlugin

images

If you’re using phonegap-plugin-push 1.10.0 “PushPlugin” with Cordova and iOS13, then you will quickly notice, that in your callback, that the data.registrationId will be in the wrong format, something like:

{length=32,bytes=0x61a941c6799e63043d5366de0b865cbf...781fd5936a7efdc6}

as the device token, which will obviously not work.

So, there are solutions, like upgrading the push plugin, but for whatever reason, you can’t do that, here is the code change necessary to fix the plugin:

Open Plugins > PushPlugin.m

Scroll down to didRegisterForRemoteNotificationsWithDeviceToken

and remove this line of code:

    NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@”<“withString:@””]

stringByReplacingOccurrencesOfString:@”>” withString:@””]

stringByReplacingOccurrencesOfString: @” ” withString: @””];

and replace this with:

NSUInteger length = deviceToken.length;

const unsigned char *buffer = deviceToken.bytes;

NSMutableString *hexString= [NSMutableString stringWithCapacity:(length * 2)];

for (int i = 0; i < length; ++i) {

[hexString appendFormat:@”%02x”, buffer[i]];

}

NSString *token = [hexString copy];

This is from https://onesignal.com/blog/ios-13-introduces-4-breaking-changes-to-notifications/ – So credit due, and respect to George Deglin for this fix.

With this fix, the registrationId goes back to normal, and push notifications work as before.

 

Categories: Uncategorized

#APNS for #IOS13 in C#

1_yVRIJRb4z-F3ahDKsMVcpw

APNS, or apple’s push notification service has changed a bit in iOS 13, so you need to make some changes to your code to make it work again.

First off, I used to use MOON APNS (https://github.com/arashnorouzi/Moon-APNS/issues) but it seems to be no longer maintained. It used a raw TCP/IP mechanism, which I’m sure is ultra-performant, but it’s really hard to debug, so I decided to just change the framework to PushSharp (https://github.com/Redth/PushSharp)

Now, my code is very much a fire and forget, if it works, good, it it doesn’t – nevermind. I’m not catching or logging any exceptions, you might want to do this. I’m not getting into how to create the .P12 key, that’s a whole post on it’s own.

public static void Push(string message, string apns)
{
// Change p12 after acceptance!
var strP12 = HttpContext.Current.Server.MapPath(“~/certs/2020/sandbox.2020.p12”);
var config = new ApnsConfiguration (ApnsConfiguration.ApnsServerEnvironment.Sandbox,
strP12, “xxxxxx”);
var apnsBroker = new ApnsServiceBroker (config);
apnsBroker.Start ();
apnsBroker.OnNotificationSucceeded += (notification) =>
{
apnsBroker.Stop();
};
var oPayload = new
{
aps = new
{
alert = new
{
body = message
}
}
};
var payloadJson = JsonConvert.SerializeObject(oPayload);
apnsBroker.QueueNotification (new ApnsNotification {
DeviceToken = apns,
Payload = JObject.Parse(payloadJson)
});
}

It only sends a text message, it doesn’t have badges, sounds, or alerts, but that’s all I needed.

 

 

Categories: Uncategorized