news

Hello C# 8, goodbye null reference!

Hello C# 8, goodbye null reference!

Say hello to C# 8.0 and goodbye to those nasty little null-reference exceptions!   That’s right, Microsoft is getting ready to release yet another major version of the language!  This has been common knowledge for a little while now, so I may be slightly behind.  Behind or not, I still wanted to bring it up.  I am excited about all of the changes and features coming in the new C#.  I don’t have the time or the space here to cover all of them but I will touch on some of the most drastic and useful features being added in.

 

Null references

Brace Yourself, NullRef Exception incoming

Let’s face it, we’ve all been there.  Everything compiles, we run our program eagerly awaiting it’s output.  Then BAM!  A big nope screen is thrown in your face, saying something about a NullReferenceException.  Believe it or not Null References were suppose to be a thing of the past a long time ago.  Thankfully the C# designers have finally gotten around to trying to get rid of them.   Currently by default all reference types as well as variable types are nullable, this is all about to change.

Non-nullable by default

Starting with C# 8.0 reference types, by default, will be non-nullable.  Now this isn’t to say that you can’t make them that if you so choose, but again this is by default.  The C# compiler is also going to help you on this quest by throwing some helpful warnings if you forget to check for nulls or forget to make them nullable.   Take a look at the example below:

 

1
2
3
4
5
ISomeType notNull;
ISomeType? mayBeNull;

notNull = null; //This will throw a compile warning
mayBeNull = null; //This won't

Another nice aspect about this is now it will also throw a warning if you forget to check if a nullable is actually null. This is a feature I believe is going to come in very handy. Take a look below:

1
2
3
4
5
6
7
8
9
ISomeType notNull = GetSomeType();
ISomeType? mayBeNull; = GetSomeType();

mayBeNull.Execute(); //This will throw a warning (we didn't make sure it wasn't null!)
notNull.Execute(); //This will run fine

if(mayBeNull !=null){
  mayBeNull.Execute(); //This won't throw a warning (because we checked)
}

 

Records

I’m sure most of us have worked with POCOs, creating numerous classes that are simply just going to be used to define a data structure and hold it.  Traditionally this meant writing out a whole new class and defining it’s properties.  Thanks to C# 8.0 we now have records!  With records you can easily and quickly create these “container classes” with one line of code!  For example, instead of having to type of this:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class Person: IEquatable<Person>{
  public string FirstName { get; }
  public string LastName { get; }

  public Person(string firstName, string lastName){
    this.FirstName = firstName;
    this.LastName = lastName;
  }

  public bool Equals (Person other){
    return Equals(FirstName, other.FirstName) && Equals(LastName, other.LastName);
  }

  public override bool Equals(object obj){
    return (obj as Person)?.Equals(this) == true;
  }

  public override int GetHashCode(){
    return FirstName.GetHashCode() + LastName.GetHashCode();
  }

  public void Deconstruct(out string FirstName, out string LastName){
    FirstName = this.FirstName;
    LastName = this.LastName;
  }
}

 

Now you can just do this and get the same results!

1
public class Person(string FirstName, string LastName);

Now, I don’t know about you but this is definitely one of the more helpful features that I’ve seen.

 

And many more!

 

These are just two examples that I decided to speak on simply because I find them fascinating but there are many other features in C# 8.0!  Check out the links below to find out more!

3 New C# 8 Features We Are Excited About

Posted by DCCoder in News, Programming, 0 comments
Microsoft buys GitHub

Microsoft buys GitHub

As of June 4, 2018 Microsoft has officially announced it’s aqcuisition of GitHub for the sum of $7.5 billion. Yes, you read that right, Microsoft paid out Billions for the massive source code repository GitHub.

Although this is a very smart business move many saw it coming, with GitHub on stage at Microsoft’s developer conference and the Git 2.0 inclusion in the new visual studio update. While this doesn’t seem to phase some, many are not happy about it. GitLab has been devoting a lot of time marketing to GitHub users with some 13,000 projects already abandoning GitHub as of Monday for it’s competitor.

But why are so many developers fleeing from their long time repository provider?  Shouldn’t everyone be excited about such a large leader in the tech industry, with it’s vast resources, acquiring GitHub?  Well this stems primarly from distrust of Microsoft.  Microsoft has long a long history of being against open source works.  Even Steve Ballmer (yes, developers developers developers developers) went as far as to say that open source was a “cancer”.

Continue reading →

Posted by DCCoder in News, 0 comments
Hackers gainaccess to US power grid

Hackers gainaccess to US power grid

In a time of hacker attacks on critical infrastructure, even a run-of-the-mill malware infection on an electric utility’s network is enough to raise alarm bells. But the latest collection of power grid penetrations went far deeper: Security firm Symantec is warning that a series of recent hacker attacks not only compromised energy companies in the US and Europe but also resulted in the intruders gaining hands-on access to power grid operations—enough control that they could have induced blackouts on American soil at will. Continue reading →

Posted by DCCoder in News, 0 comments

OnionScanner – A TOR Link Checker

Well last night I got an idea.  I like to checkout the TOR Hidden Services from time to time but it’s a pain in the tail just trying to find a link that actually works.  So I cooked up the OnionScanner!  It’s basically just a TOR link checker.  But feel free to check it out on the home site or on GitHub and let me know what you think.  If you have some ways to improve on it feel free to put in a request.  Even if you just want to port it to another language to make it cross-platform I would greatly appreciate it!

https://github.com/DCCoder90/onionscanner

Posted by DCCoder in Posts from old site, Projects, 0 comments

Fun with Keyfobs!

Anyways, just like I said I would I got into trying to actually demodulate the signal for that fan remote…well as it turns out, after tons of research it seems like the method I posted about in my last entry was the easiest way to “demod” a PWM signal, just doing it by hand.  So I’ve moved on to other stuff.  So, been working on attacks against Keyfobs today (that little button you use to unlock/lock your car) and so far so good. Here’s a screenshot of a little program I’m working on to make IDR (intercept, disrupt, replay) attacks on keyfobs a little easier. When it’s done it will basically sit there and listen for you to push a button, when you do it will jam the signal and save the signal to a file. Then when you push it again it will jam that signal, save the second one to a file, the replay the first one (causing your vehicle to lock/unlock as expected). Continue reading →

Posted by DCCoder in Posts from old site, RF, 0 comments

Decoding fan remote RF signal

It’s been quite a while since I’ve last posted here so I figured I’d do a little experiment.  I haven’t even touched my SDRs in a few months, but I recently purchased a HackRF and WIFI Pineapple (they haven’t arrived yet) so I figured I’d pull out my old dongles and brush up some on SDR and DSA.  Well, I wanted to start with the simplest thing I could think of so I grabbed a remote control for our ceiling fans and decided I’d try to decode the signal. Continue reading →

Posted by DCCoder in Posts from old site, RF, 0 comments