Hi,
I woarked a lot (and still do) in the last 4-5 mounths, I have many posts I wish to publish but very little time.
In the next mounth I'll try to publish at least 1 post a week.
Monday, September 12, 2011
Wednesday, July 13, 2011
GUIDE: Installing PHP.
Hi,
Just start playing with PHP and I thought it might be usefull for others if i'll write my experiance with it.
Instalation guide
Just start playing with PHP and I thought it might be usefull for others if i'll write my experiance with it.
Instalation guide
- Download PHP (download the zip version / Thread safe)
- Unzip it to 'C:\PHP\'.
- Installing
- Open the file 'C:\PHP\php_manual_en.chm'
- Follow the instalation directions (best way i found).
Have fun!
Thursday, May 5, 2011
GUIDE: LUA unit testing and TDD
I've just uncovered this subject, here is my insights:
Fast start
Fast start
- Open LUA
- Start a new test file (let's call it 'my_code.tests.lua').
- Edit 'my_code.tests.lua' (example template below)
--- my_code.tests.lua Code --------------------------------------------
-- Some super function to test
function my_super_function( arg1, arg2 ) return arg1 + arg2 end
-- Unit testing starts
require('luaunit')
TestMyStuff = {} --class
function TestMyStuff:testWithNumbers()
a = 1
b = 2
result = my_super_function( a, b )
assertEquals( type(result), 'number' )
assertEquals( result, 3 )
end
function TestMyStuff:testWithRealNumbers()
a = 1.1
b = 2.2
result = my_super_function( a, b )
assertEquals( type(result), 'number' )
-- I would like the result to be always rounded to an integer
-- but it won't work with my simple implementation
-- thus, the test will fail
assertEquals( result, 3 )
end
-- class TestMyStuff
luaUnit:run()--- Code End -----------------------------------------------------------------------
- Execute the test code.
- Add your tests and assumption checking.
- Fix what's broken.
Understand more
Tuesday, May 3, 2011
LUA tutorial / newbie, nob getting started and advanced links.
NOB? here you go:
Fast start
Know your LUA
Reference cards
Fast start
- Download 'LUA For Windows' - A batteries included Lua installation on Windows.
- Write code in an online interpreter
Know your LUA
Reference cards
- Lua 5.1 Reference Manual
- http://www.tdistler.com/media/docs/luarefv51.pdf
- http://lua-users.org/wiki/
- http://www.lua.org/manual/5.1/
A bit more advanced stuff
- Dynamic invocation
- http://stackoverflow.com/questions/1791234/lua-call-function-from-a-string-with-function-name
- http://en.wikipedia.org/wiki/Eval#Lua
- BitwiseOperators
- http://lua-users.org/wiki/BitwiseOperators
- Recommended - http://bitop.luajit.org/
- Notes - Problems with unsigned numbers detected!
Integrating LUA with Eclipse
Hope this helps.
Labels:
Eclipse,
Guides,
LUA,
NOB,
opensource,
Programming,
Scripting,
Tutorial
Monday, May 2, 2011
GUIDE: Creating your own fast Wireshark plugin / dissector using LUA.
After hitting my head agains the keyboard to create my own LUA protocol, I've desided that none shall suffer anymore.
Some background to understand stuff
Creating LUA based plugin / dissector
More nice stuff that can help
Some background to understand stuff
- Wireshark reads PCAP file format for captured files.
- Wireshark can be extended using C code or, for fast development you can use LUA code (I'll explain later...).
PCAP File Format
- Know your Wireshark
- Download and install Wireshark.
- Create LUA dissector (let's save it as 'trivial.lua')
-- trivial protocol example
-- declare our protocol
trivial_proto = Proto("trivial","Trivial Protocol")
-- create a function to dissect it
function trivial_proto.dissector(buffer,pinfo,tree)
pinfo.cols.protocol = "TRIVIAL"
local subtree = tree:add(trivial_proto,buffer(),"Trivial Protocol Data")
subtree:add(buffer(0,2),"The first two bytes: " .. buffer(0,2):uint())
subtree = subtree:add(buffer(2,2),"The next two bytes")
subtree:add(buffer(2,1),"The 3rd byte: " .. buffer(2,1):uint())
subtree:add(buffer(3,1),"The 4th byte: " .. buffer(3,1):uint())
end
-- load the udp.port table
udp_table = DissectorTable.get("udp.port")
-- register our protocol to handle udp port 7777
udp_table:add(7777,trivial_proto)- Edit ...\Wireshark\init.lua file as follows
- disable_lua = false
- At the end of the file: dofile("trivial.lua")
- You can read more here - http://simplestcodings.com/2011/01/09/how-to-use-lua-to-create-wireshark-dissector/
- Open Wireshark
- Menu >> Edit >> Preferences >> Protocols >> DLT_USER >> Edit >> New:
- DLT: User 0 (147)
- Payload protocol: MyProtocolName
- Header size 0
- Trailer size: 0
- Press OK
- Create PCAP dumps for analyze.
- Using HEX-Editor (see below for nice hex-editor recomendations).
- If you can - ask the protocol team to provide their dumps.
- Open the PCAP dump for editing (binary mode).
- Change the dump's 'Global Header' section / 'data link type' (network) to 147 (LINKTYPE_USER0)
- Read more here - http://www.tcpdump.org/linktypes.html
- save it.
- Load the dump to Wireshark for analyses.
- Start changing the trivial.lua code to parse your protocol.
Hope this will bring you to a working point fast. In the process read related stuff to understand more, you can upgrade this solution to create better and better protocol sniffer using Wireshark.
- Related reference stuff
- http://simplestcodings.com/2011/01/09/how-to-use-lua-to-create-wireshark-dissector/
- http://delog.wordpress.com/2010/09/27/create-a-wireshark-dissector-in-lua/
- http://lua-users.org/wiki/TutorialDirectory
- http://wiki.wireshark.org/Lua
- http://wiki.wireshark.org/Lua/Dissectors
- http://wiki.wireshark.org/Lua/Examples
More nice stuff that can help
- You can use 'Hex Workshop' to simulate your protocol binary streams more easily (using it's feature Structure Editing).
- Wireshark tools
- bit-twist: Network Traffic Generator
GUIDE: dotNetInstaller - Free fast and easy installer for windows
In a nutshell
- Download dotNetInstaller: setup bootstrapper for Windows
- Great tutorials:
- Read this article if you're using 'Setup project using the Windows Installer'.
- Read this article if you'r using 'Install shield limited edition'.
- If using MSI file...
VB-Script macro to help you uninstall stuff
REM Option Explicit Dim exitcode : exitcode = 0 REM --- Functions ------------------------------------------------------------------ function readFromRegistry (strRegistryKey, strDefault ) Dim value Dim objFSO, WSHShell On Error Resume Next Set objFSO = CreateObject("Scripting.FileSystemObject") Set WSHShell = CreateObject("Wscript.Shell") value = WSHShell.RegRead( strRegistryKey ) if err.number <> 0 then readFromRegistry= strDefault else readFromRegistry=value end if set WSHShell = nothing end function function readDataFromMsiFile(file_path) Set objInstaller = CreateObject("WindowsInstaller.Installer") Set objProduct = objInstaller.SummaryInformation(file_path) Wscript.Echo "Code page: " &objProduct.Property(1) Wscript.Echo "Title: " & objProduct.Property(2) Wscript.Echo "Subject: " & objProduct.Property(3) Wscript.Echo "Author: " & objProduct.Property(4) Wscript.Echo "Keywords: " & objProduct.Property(5) Wscript.Echo "Comment: " & objProduct.Property(6) Wscript.Echo "Template: " & objProduct.Property(7) Wscript.Echo "Last Author: " & objProduct.Property(8) Wscript.Echo "Revision number: " & objProduct.Property(9) Wscript.Echo "Edit Time: " & objProduct.Property(10) Wscript.Echo "Last Printed: " & objProduct.Property(11) Wscript.Echo "Creation Date: " & objProduct.Property(12) Wscript.Echo "Last Saved: " & objProduct.Property(13) Wscript.Echo "Page Count: " & objProduct.Property(14) Wscript.Echo "Word Count: " & objProduct.Property(15) Wscript.Echo "Character Count: " & objProduct.Property(16) Wscript.Echo "Application Name: " & objProduct.Property(18) Wscript.Echo "Security: " & objProduct.Property(19) Set objProduct = Nothing Set objInstaller = Nothing end function function ProductVersion() ' SOURCE: http://stackoverflow.com/questions/815744/retrieving-version-of-an-msi-file-built-with-wix Dim installer, database, view, result Set installer = CreateObject("WindowsInstaller.Installer") Set database = installer.OpenDatabase (".\installer.msi", 0) Dim sumInfo : Set sumInfo = installer.SummaryInformation(".\installer.msi", 0) sPackageCode = sumInfo.Property(9) ' PID_REVNUMBER = 9, contains the package code. Set view = database.OpenView ("SELECT Value FROM Property WHERE Property='ProductVersion'") view.Execute Set result = view.Fetch ProductVersion = result.StringData(1) end function
REM --- Code -------------------------------------------------------------------
new_version = ProductVersion() installed_version = readFromRegistry ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{12345678-D8EF-4EE9-8DC4-FF5911256E0D}\DisplayVersion", "0.0.0" ) uninstall_user_result = MsgBox("About to install " + new_version + " instead of " + installed_version + ", continue?",3,"Please answer") Select Case uninstall_user_result Case 6 ' Yes exitcode = 0 Case Else exitcode = 1 End Select WScript.Quit exitcode REM return results
Executing VBScripts from command lineHope it helps.
Sunday, April 10, 2011
New blog: ProjectEuler solver
I've decided that if i'm going to solve 332 problem's it's best be in a separate blog, so i'm opening a new blog, i think i'll call it: 'ProjectEuler solver'
Here it goes... http://projecteulersolver.blogspot.com/
Here it goes... http://projecteulersolver.blogspot.com/
Labels:
CS,
General,
math,
Problems,
Programming,
Project Euler
Subscribe to:
Posts (Atom)