After reading “Debugging with GDB” by RMS I’ve made this reference sheet, since I rarely program in Linux I’ve excluded everything Linux specific:
file a.out – Load the program a.out symbol-file symbol – Load symbol file symbol run – Run program continue – Execute program until the next breakpoint print i – Print variable i print i=3 – Change variable i to 3 x 0x200 – Print value at 0x200 break printf – Set breakpoint at function printf info breakpoints – List breakpoints delete 2 – Delete breakpoint 2 delete – Delete all breakpoints info locals – Show variables in stack backtrace – Show stack info frame – stack info list + – Show sourcecode before last printed list – – Show sourcecode before last printed list func – Show sourcecode around function name func list 30 – Show sourcecode around line 30 info line func – Get start and end memory addresses of function func info line 30 – Get start and end memory addresses of section around line 30 disassemble 0x300 0x400 – Disassemble between memory addresses 0x300 and 0x400 info registers – Display registers info all-registers – Display all registers set $rax = 0x5 – Set register rax to 0x5 info symbol printf – shows memory location of printf Continue reading “Unix GDB Cheat Sheet”
This year I have a number of personal projects to complete and textbooks to read so I’m using this post to keep track of them. If I stick with this then by the end of this year I should be a stronger developer with a lot more knowledge of operating system design, implementation, and troubleshooting.
☐ Write an assembler
☐ Write a file (de)compressor
☐ Find a kernel bug
☐ Find an application bug
☐ Create 3 websites and compromise them ☑ 1 ☐ 2 ☐ 3
☐ Send and detect a Christmas tree packet
☑ Debugging with GDB – Richard Stallman
☐ Assemblers and Loaders – David Salomon
☐ Expert C Programming: Deep C Secrets – Peter van der Linden
☐ Operating Systems: Design and Implementation – Andrew S Tanenbaum
☐ Designing BSD Rootkits – Joseph Kong
☐ Practical File-system Design – Dominic Giampaolo Continue reading “2018 Goals”
Recently I’ve been re-writing my web scrapers after a senior dev advised that using regex to parse HTML is just a terrible way to do it and I should really be using the language made for parsing XML that is XPath, so I’ve been busy with this and using what I’ve learnt written some C subroutines to easily parse web pages as it takes an awful lot of code to just download a web page to a string and run an XPath query on it. These subroutines are now working in my Arbitrage betting software.
To get the XPath queries the the easiest way I’ve found is to right click the bit of the web page I’m interested in grabbing in Chrome or Firefox then “Inspect element”, just below the source code in the new window it has the node we selected which we can then turn into a query.
I’ve also been working with the Perl module HTML::TreeBuilder::XPath for parsing web pages, in contrast to libxml this only requires 5 lines of code to return the results to an array from a web page. I’ve increased the storage for the server this website is hosted on and written a script using this module to automatically download videos from TempleOS.org and upload them here because Terry regularly deletes the videos and the Youtube re-uploaders have all stopped.
Another small script I originally wrote in C but then ported to Perl scrapes the website allkeyshop.com according to a config file and sends an email for any games which are selling for below a set price threshold.
Jun 3 22:42:27 Xavier /bsd: pppoe0: LCP keepalive timeout
Jun 3 22:48:16 Xavier /bsd: pppoe0: LCP keepalive timeout
Jun 3 22:54:04 Xavier /bsd: pppoe0: LCP keepalive timeout
Jun 3 22:59:52 Xavier /bsd: pppoe0: LCP keepalive timeout
Swapping this out for a different modem resolves the issue so it’s clearly an issue with the OpenReach modem, now lets see if we can fix it.
Connecting my laptop to Lan1 on the modem and restarting the network interface with
doas sh /etc/netstart em0
shows that it is not running dhcp, and
shows nothing in the arp table so it doesn’t look like this has an IP address meaning we can’t telnet/ssh in or access any web interface. Apart from maybe looking into the BTAgent I don’t see any attack vectors here.
When looking into racing arbitrage I came across one condition that worried me in which bookmakers will decimate the odds. Tattersalls Rule 4 (c) to give it it’s full title is applied when a horse is removed from the race after bets have been placed and ensures the bookies are still in pocket after refunding everyone who backed the non-runner. So how does this affect someone who backed all of the outcomes? I don’t see a quick way of doing this and I couldn’t find any tools online so I’m going to have to analyse a lot of horse races.
For the first example I will use today’s 14:50 @ Wincanton, we are betting on all outcomes with a total stake of £100, here are the best odds for the race today and the required stakes to get the same 95.24% (£4.76 loss) return regardless of the outcome:
Using this chart from Ladbrokes in which we are given the deductions with the odds in decimals I’ve written a script that is available on Github to create tables showing all of the resultant odds. The top row holds the odds of the horse which has dropped out and the left column holds the odds for the horses still running.
jon@OpenBsD:~/dev/asm;$ nasm -f elf64 -o helloworld.o helloworld.s
jon@OpenBsD:~/dev/asm;$ ld -o helloworld helloworld.o
ld: warning: creating a DT_TEXTREL in a shared object.
jon@OpenBsD:~/dev/asm;$ yasm -f elf64 -o helloworld.o helloworld.s
jon@OpenBsD:~/dev/asm;$ ld -o helloworld helloworld.o
ld: helloworld.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
helloworld.o: could not read symbols: Bad value
I did search /usr/src for any assembly files I could straight up copy and test, but I didn’t find anything suitable, however the code looks fine and as the assembler didn’t throw out any errors I’m thinking this to be an issue with the linker.
Running ld with the verbose flag we are shown the options for available architectures:
jon@OpenBsD:~>$ ld -V
GNU ld version 2.17
Something about using the black box my ISP provided to control my whole network just didn’t sit right with me, so I decided to ditch it and make my own using the industrie’s go-to firewall operating system: OpenBSD.
I started with an Alix2d2, a single board x86 machine with low power consumption, and a BT OpenReach modem. Both pre-owned and picked up on Ebay for very reasonable prices, I also had to buy a null modem cable to connect to the Alix, a Ralink RT2561T MiniPCI WLAN module and antenna for wireless connectivity.
The only way to install the operating system onto the Alix (apart from copying a snapshot onto the memory card) is a network install, so we will need to setup tftpd and dhcpd.
38400 in the default baud rate for the alix2d2 so I’ve set that in the boot.conf