WordCram using the names of Malware

36 views
Skip to first unread message

jag...@gmail.com

unread,
Nov 26, 2014, 1:25:04 PM11/26/14
to word...@googlegroups.com
I'd like to make an SVG showing growing malware threat names. A quick way to visually track what's fresh and emerging and what's not.

Problem is, when I load the malware names into a "word", anything with numerics, punctuation or spaces, gets tossed out of the resulting image. Is there any ways to change the behaviour of "Word word = new Word(name, frequency);" to allow the name to have weird-ish characters? I'm looking to use something like:

F-UPA-AAH_(ED)    0.81    f
BrowseFox.e    0.54    m
Adware-BrowseFox    0.49    m
PUP-FNK    0.48    f
PUP-FPS    0.47    m
Downloader-FSH!432718827A11    0.03    m
RDN/Generic_PWS.y!bbt    0.03    m
RDN/Generic.dx!dh3    0.02    m
Generic.Tra!7b7c92f2255a_(ED)    0.01    m
VBS/Autorun.worm.aadd!lnk    0.01    f

Needless to say, I hacked the firstnamesUsingWordPresets sample. The Solution is probably newbie error and I probably need  to switch to UTF8 or the like but I'm clueless on how to do that. :-)

Thanks

Jacques


Dan Bernier

unread,
Nov 26, 2014, 4:09:33 PM11/26/14
to word...@googlegroups.com
It's hard to say what's going wrong - this should work.

I know that the firstnamesUsingWordPresets example strips off the numbers and the "m" or "f" (denoting gender), so it might be that that's your problem.

Could you paste in your code?

jag...@gmail.com

unread,
Dec 1, 2014, 8:49:58 AM12/1/14
to word...@googlegroups.com

It is just a clone of the sample code. The ParseNames routines split the input record on TAB characters. It does look however, like the internal code does a regex on the NAME passed to it and removes all non-word characters.

Thanks for any hints you can throw my way.

Jacques

names.txt is just:
BrowseFox    1.00    m
T-UPA-AAH_(ED)    0.81    f

BrowseFox.e    0.54    m
Adware-BrowseFox    0.49    m
PUP-FNK    0.48    f
PUP-FPS    0.47    m
Downloader-FSH!432718827A11    0.03    m
RDN/Generic_PWS.y!bbt    0.03    m
RDN/Generic.dx!dh3    0.02    m
Generic.Tra!7b7c92f2255a_(ED)    0.01    m
VBS/Autorun.worm.aadd!lnk    0.01    f
Other    0.17    f
Artemis_Contribution    0.05    f


here's the code (nothing new or special here):

import wordcram.*;

WordCram wc;
Word[] names;

void setup() {
  colorMode(HSB);
  size(800, 600);
  background(255);
 
  loadNames();
  makeWordCram();
}

void loadNames() {
  String[] nameData = loadStrings("names.txt");
  names = new Word[nameData.length];
  for (int i = 0; i < names.length; i++) {
    names[i] = parseName(nameData[i]);
  }
}

void makeWordCram() {
   try {
      new WordCram(this).
      fromWords(names).
      toSvg("test.svg", width, height).
      drawAll();
  }
  catch (java.io.FileNotFoundException x) {
    println(x.getMessage());
  }

}

void draw() {
  while(wc.hasMore()) {
    wc.drawNext();
  }
    println("done");
    /* noLoop();*/
  
}

void mouseClicked() {
  background(255);
  makeWordCram();
  loop();
}


// Each row looks like:
// Mary\t1.0\tf
// ...or:
// {name} {tab} {frequency} {tab} {'f' for females, 'm' for males}
Word parseName(String data) {
  String[] parts = split(data, '\t');
 
  String name = parts[0];
  float frequency = float(parts[1]);
  boolean isFemale = "f".equals(parts[2]);
  println(name,frequency,isFemale);

 
  Word word = new Word(name, frequency);
 
  if (isFemale) {
    word.setColor(#f36d91); // pink
  }
  else {
    word.setColor(#476dd5); // blue
  }
 
  return word;
}

Dan Bernier

unread,
Dec 2, 2014, 9:16:12 AM12/2/14
to word...@googlegroups.com
I don't think the problem is the regex in the internal code - that's only for when WordCram parses your text for you; here, you're creating your words, so it shouldn't come into play.

You have a lot of parts here that aren't all coming together correctly, and I think that's probably where your trouble lies. I was able to fix a few things, and got it to run, with the numbers included.

The things I changed are:
* removed the toSvg("test.svg") stuff
* in makeWordCram, it's instantiating a WordCram, calling drawAll on it, and then throwing it away; then, draw() tries to use the global wc instance. Instead, I took the drawAll() out of makeWordCram(), and had it set wc, so the draw() method would work.
* Many of your words were weighted very low, so they wouldn't come out - I weighted them all at 1 (just to test), and used sizedByWeight(15, 15) to draw them all at 15pt.

Here's the code I used:

import wordcram.*;

WordCram wc;
Word[] names;

void setup() {
  colorMode(HSB);
  size(800, 600);
  background(255);
  
  loadNames();
  makeWordCram();
}

void loadNames() { 
  String[] nameData = loadStrings("../../names.txt");
  names = new Word[nameData.length];
  for (int i = 0; i < names.length; i++) {
    names[i] = parseName(nameData[i]);
  }
}

void makeWordCram() {
      wc = new WordCram(this).
      sizedByWeight(15, 15).
      fromWords(names);
      //toSvg("test.svg", width, height); //.
      //drawAll();

}

void draw() {
  while(wc.hasMore()) {
    wc.drawNext();
  }
    /* noLoop();*/
   
}

void mouseClicked() {
  background(255);
  makeWordCram();
  loop();
}


// Each row looks like:
// Mary\t1.0\tf
// ...or:
// {name} {tab} {frequency} {tab} {'f' for females, 'm' for males}
Word parseName(String data) {
  String[] parts = split(data, '\t');
  
  String name = parts[0];
  float frequency = float(parts[1]); frequency = 1.0;
  boolean isFemale = "f".equals(parts[2]);
  println(name,frequency,isFemale);
  
  Word word = new Word(name, frequency);
  
  if (isFemale) {
    word.setColor(#f36d91); // pink
  }
  else {
    word.setColor(#476dd5); // blue
  }
  
  return word;
}

malware-cram.png
Reply all
Reply to author
Forward
0 new messages