Due to serious hardware failures, all my computers went down. Now it is only down to a live CD... Ubuntu here.
The USB is my only storage after all. It, however, did not appear at /dev/sda1 instead at /dev/sdd1 . How did I discover it? Simple, at first :
$sudo dmesg
However, that is not good enough.
$sudo fdisk -l
Device Boot Start End Blocks Id System
/dev/sdd1 * 1 1956 500720 e W95 FAT16 (LBA)
That's better. You can then :
$sudo mkdir /tmp/mnt
$sudo mount -t vfat /dev/sdd /tmp/mnt
You need to specify the USB virtual file system, which I found mine to be vfat ( some guessing only, unfortunately ). And that is all.
By the way, there is an auto-mount feature.
Saturday, February 24, 2007
Friday, February 23, 2007
Accelerated Death
Recently, all my 4 computers went down. I would like to share one of the death of my computers so as to alert you visitors.
One of my hard disk, which is ran on Debian Sarge, starts to pop error messages out unstoppingly.
The error probably came from extremely frequent random disk write on the hard disk 2 months ago. I wrote a crawler and save the contents to the hard disk directly at lightning speed for days. This probably inflicted a heavy load on the hard disk. Bad.
The correct way should have been putting them into memory and writing into the hard disk at a buffer, not piece by piece like what I do. ( I have been rushing the project within days, which drove me to do it the bad way )
Anyway, remember this is a bad style for coding. Now, are SQL databases different?
One of my hard disk, which is ran on Debian Sarge, starts to pop error messages out unstoppingly.
The error probably came from extremely frequent random disk write on the hard disk 2 months ago. I wrote a crawler and save the contents to the hard disk directly at lightning speed for days. This probably inflicted a heavy load on the hard disk. Bad.
The correct way should have been putting them into memory and writing into the hard disk at a buffer, not piece by piece like what I do. ( I have been rushing the project within days, which drove me to do it the bad way )
Anyway, remember this is a bad style for coding. Now, are SQL databases different?
Tuesday, February 6, 2007
GDB Argument Standard Input
There might be someone who just have trouble forcing in long arguments during hacking, and googling for hours without something useful. I asked myself "I don't think people are trying to put arguments into their program each time manually while gdbing? Even if the arguments are thousands of characters long..."
This is tested in GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Attempted Solution 1 :
#gdb ./a <>
Nope, this will fail definitely.
Attempted Solution 2 :
# gdb
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
(gdb) ./a <>
Nope, this will fail too.
So after asking for directions, thanks to Zekta and Tom, we have the 2 solutions below.
Solution 1 :
gdb -x args.in ./a
args.in is a file containing the gdb commands :
For example :
============================
set args args1 args2 args3 args4
============================
Solution 2 :
(gdb) r `cat arguments.in`
arguments.in is a file containing the arguments to be input
There is also a solution called xargs, but I have never tried. It's well worth a try, both of the ways are kind of bruteforce. Anyway, it works, that's it, and is automated.
This is tested in GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Attempted Solution 1 :
#gdb ./a <>
Nope, this will fail definitely.
Attempted Solution 2 :
# gdb
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
(gdb) ./a <>
Nope, this will fail too.
So after asking for directions, thanks to Zekta and Tom, we have the 2 solutions below.
Solution 1 :
gdb -x args.in ./a
args.in is a file containing the gdb commands :
For example :
============================
set args args1 args2 args3 args4
============================
Solution 2 :
(gdb) r `cat arguments.in`
arguments.in is a file containing the arguments to be input
There is also a solution called xargs, but I have never tried. It's well worth a try, both of the ways are kind of bruteforce. Anyway, it works, that's it, and is automated.
Escape Characters in Shellcode
> sh: unexpected EOF while looking for matching `''
sh: syntax error: unexpected end of file
> sh: unexpected EOF while looking for matching ``'
sh: syntax error: unexpected end of file
If you are passing some shellcode as arguments through a program in a predefined , you might encounter a problem as above. No big deal. This problem can be simulated by opening a /bin/sh and then entering a ` or ' character, then sending an EOF character ( CTRL + D ).
Now :
sh-2.05b# \`
sh: `: command not found
sh-2.05b# \'
sh: ': command not found
sh-2.05b#
Just locate the hexadecimal code for such characters, and escape it ( adding a backslash ). The problem will be solved.
sh: syntax error: unexpected end of file
> sh: unexpected EOF while looking for matching ``'
sh: syntax error: unexpected end of file
If you are passing some shellcode as arguments through a program in a predefined , you might encounter a problem as above. No big deal. This problem can be simulated by opening a /bin/sh and then entering a ` or ' character, then sending an EOF character ( CTRL + D ).
Now :
sh-2.05b# \`
sh: `: command not found
sh-2.05b# \'
sh: ': command not found
sh-2.05b#
Just locate the hexadecimal code for such characters, and escape it ( adding a backslash ). The problem will be solved.
Mixed Graph Euler Circuit
This is a graph orientation problem. Please search for the keyword for more details.
This problem determines whether a mixed graph has an eulerian circuit, and asks to print a solution.
1) Instantiate two graphs, G_undirected and G_directed. Storing undirected and directed edges independently.
2) First freely assign all undirected edges in the graph to be one direction
3) Then, calculate the in degree and out degree differences of each vertex.
4) Create two new vertices s, t.
For each vertex u , indegree[u] > outdegree[u] ,
Create an edge ( u , t ) = indegree[u] - outdegree[u] .
For each vertex u , indegree[u] < outdegree[u] , Create en edge ( s , u ) = outdegree[u] - indegree[u] . 5) Perform maximum flow from s to t. If total flow equals that going out from s or going into t , Euler Circuit exists. 6) Lastly, merge the flow graph with the directed graph portion. Perform a euler circuit ( DFS ) to print the euler circuit.
Pseudocode as follows : ================================================================ // Graph setup
Original Graph G ;
Hide all directed edges ;
Assign all undirected edges a single direction ;
For each vertex v :
{
if ( indegree[v] - outdegree[v] > 0 )
create an edge with ( v , tank ) of capacity ( (indegree[v]-outdegree[v]) / 2 )
if ( indegree[v] - outdegree[v] < face="courier new"> create an edge with ( source , v ) of capacity ( (outdegree[v]-indegree[v]) / 2 )
}
total_flow = maximum_flow(G);
if ( total_flow == out_flow(source) || total_flow == in_flow(tank) )
{
// there is eulerian circuit
Assign the directions of the undirected edges as in the flow graph and merge with the original directed edge only graph.
Circuit = get_euler_circuit(G);
print_path(Circuit);
}
================================================================
Follow ups :
I'll just update this with a more verbal explanation.
Actually, when you are forcing a direction in 2), you are trying to then link the vertices with uneven in and out indegrees, and trying to "dampen" the difference each iteration if a flow is possible by reversing the edges used to flow. ( so the in degree of a vertex - 1 and out degree of a vertice + 1 , making it more even ), eventually it reaches a state where all vertices in degree equals out degree.
All vertices in-degree == out-degree.
Done!
By the way, this graph is assumed to be connected.
Problem Source :
http://acm.uva.es/p/v107/10735.html
This problem determines whether a mixed graph has an eulerian circuit, and asks to print a solution.
1) Instantiate two graphs, G_undirected and G_directed. Storing undirected and directed edges independently.
2) First freely assign all undirected edges in the graph to be one direction
3) Then, calculate the in degree and out degree differences of each vertex.
4) Create two new vertices s, t.
For each vertex u , indegree[u] > outdegree[u] ,
Create an edge ( u , t ) = indegree[u] - outdegree[u] .
For each vertex u , indegree[u] < outdegree[u] , Create en edge ( s , u ) = outdegree[u] - indegree[u] . 5) Perform maximum flow from s to t. If total flow equals that going out from s or going into t , Euler Circuit exists. 6) Lastly, merge the flow graph with the directed graph portion. Perform a euler circuit ( DFS ) to print the euler circuit.
Pseudocode as follows : ================================================================ // Graph setup
Original Graph G ;
Hide all directed edges ;
Assign all undirected edges a single direction ;
For each vertex v :
{
if ( indegree[v] - outdegree[v] > 0 )
create an edge with ( v , tank ) of capacity ( (indegree[v]-outdegree[v]) / 2 )
if ( indegree[v] - outdegree[v] < face="courier new"> create an edge with ( source , v ) of capacity ( (outdegree[v]-indegree[v]) / 2 )
}
total_flow = maximum_flow(G);
if ( total_flow == out_flow(source) || total_flow == in_flow(tank) )
{
// there is eulerian circuit
Assign the directions of the undirected edges as in the flow graph and merge with the original directed edge only graph.
Circuit = get_euler_circuit(G);
print_path(Circuit);
}
================================================================
Follow ups :
I'll just update this with a more verbal explanation.
Actually, when you are forcing a direction in 2), you are trying to then link the vertices with uneven in and out indegrees, and trying to "dampen" the difference each iteration if a flow is possible by reversing the edges used to flow. ( so the in degree of a vertex - 1 and out degree of a vertice + 1 , making it more even ), eventually it reaches a state where all vertices in degree equals out degree.
All vertices in-degree == out-degree.
Done!
By the way, this graph is assumed to be connected.
Problem Source :
http://acm.uva.es/p/v107/10735.html
Subscribe to:
Posts (Atom)