<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>webstersprodigy.net &#187; C</title>
	<atom:link href="http://webstersprodigy.net/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://webstersprodigy.net</link>
	<description>Me trying to learn how to use a computer</description>
	<lastBuildDate>Sat, 04 Feb 2012 01:17:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Reverseme: Namegenme</title>
		<link>http://webstersprodigy.net/2010/06/reverseme-namegenme/</link>
		<comments>http://webstersprodigy.net/2010/06/reverseme-namegenme/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 03:31:45 +0000</pubDate>
		<dc:creator>webstersprodigy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[IDA]]></category>
		<category><![CDATA[reverseme]]></category>

		<guid isPermaLink="false">http://webstersprodigy.net/?p=680</guid>
		<description><![CDATA[This guy is here: http://crackmes.de/users/moofy/moofys_namegenme/ namegenme.zip I had a fairly hard time with this one for some reason, although the solution was right in front of my face&#8230; Most the logic for calculating the generation is in the function 00401852. The Serial is stored in a global variable, and the name is generated by taking [...]]]></description>
			<content:encoded><![CDATA[<p>This guy is here: http://crackmes.de/users/moofy/moofys_namegenme/</p>
<p><a href='http://webstersprodigy.net/wp-content/uploads/2010/06/namegenme.zip'>namegenme.zip</a></p>
<p>I had a fairly hard time with this one for some reason, although the solution was right in front of my face&#8230;</p>
<p>Most the logic for calculating the generation is in the function 00401852. The Serial is stored in a global variable, and the name is generated by taking certain bytes from the serial and doing addition on them.</p>
<p>Here is all the relevant logic, although finding it was sort of a pain.</p>
<pre class="brush: cpp; title: ; notranslate">

.text:004018FD                 lea     eax, [ebp+var_10]
.text:00401900                 add     dword ptr [eax], 4
.text:00401903                 lea     eax, [ebp+var_14]
.text:00401906                 sub     dword ptr [eax], 3
.text:00401909                 lea     eax, [ebp+var_18]
.text:0040190C                 sub     dword ptr [eax], 2
.text:0040190F                 lea     eax, [ebp+var_1C]
.text:00401912                 add     dword ptr [eax], 2
.text:00401915                 lea     eax, [ebp+var_20]
.text:00401918                 dec     dword ptr [eax]
.text:0040191A                 lea     eax, [ebp+var_24]
.text:0040191D                 add     dword ptr [eax], 3
.text:00401920                 lea     eax, [ebp+var_28]
.text:00401923                 sub     dword ptr [eax], 2
.text:00401926                 lea     eax, [ebp+var_2C]
.text:00401929                 sub     dword ptr [eax], 4
.text:0040192C                 lea     eax, [ebp+var_30]
.text:0040192F                 add     dword ptr [eax], 3
.text:00401932                 lea     eax, [ebp+var_34]
.text:00401935                 inc     dword ptr [eax]
</pre>
<p>Here is a keygen written in C</p>
<pre class="brush: cpp; title: ; notranslate">
void main(int argc, char* argv[]) {

  char Name [10];
  char* ser = argv[1];
  if (argc != 2 || strlen(argv[1]) &lt; 21) {
    printf(&quot;Invalid serial\n&quot;);
	return (-1);
  }

  Name[0] = ser[0] + 4;
  Name[1] = ser[1] - 3;
  Name[2] = ser[2] - 2;
  Name[3] = ser[6] + 2;
  Name[4] = ser[7] - 1;
  Name[5] = ser[8] + 3;
  Name[6] = ser[13] - 2;
  Name[7] = ser[14] - 4;
  Name[8] = ser[15] + 3;
  Name[9] = ser[20] + 1;
  Name[10] = &quot;&#92;&#48;&quot;;

  printf(&quot;Name: %s\n&quot;, Name);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://webstersprodigy.net/2010/06/reverseme-namegenme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>execv-like system call</title>
		<link>http://webstersprodigy.net/2009/06/execv-like-system-call/</link>
		<comments>http://webstersprodigy.net/2009/06/execv-like-system-call/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 15:54:38 +0000</pubDate>
		<dc:creator>webstersprodigy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://webstersprodigy.net/?p=569</guid>
		<description><![CDATA[From the system man page, it explicitely says: Do not use system() from a program with set-user-ID or set-group-ID privileges, because strange values for some environment variables might be used to subvert system integrity. Good advice, but sometimes you need to get stuff done anyway. This is experimenting with pam and execv from a stupid [...]]]></description>
			<content:encoded><![CDATA[<p>From the system man page, it explicitely says:</p>
<blockquote><p>Do not use <strong>system</strong>() from a program with set-user-ID or set-group-ID privileges, because strange values for some environment variables might be used to subvert system integrity.</p></blockquote>
<p>Good advice, but sometimes you need to get stuff done anyway. This is experimenting with pam and execv from a stupid google apps pam module I wrote</p>
<pre class="brush: cpp; title: ; notranslate">
  PID = fork();
  if (PID == 0) {
    //child
    char* argvarray[4] = {progarg0, username, newpass, (char *) 0};
    execv(netprog, argvarray);
    if (debug == 1)
      printf(&quot;forking failure\n&quot;);
    report_error(1);
    return PAM_CRED_ERR;
  }
  else if (PID &lt; 0) {
    if (debug == 1)
      printf(&quot;unexpected error\n&quot;);
    report_error(1);
    return PAM_CRED_ERR;
  }

  wait(&amp;amp;execreturn);
  //make sure this does exit properly and isn't killed
  if (WIFEXITED(execreturn)) {
    rc = WEXITSTATUS(execreturn);
  }
  else {
    report_error(1);
    return PAM_CRED_ERR;
  }
</pre>
<p>The first 18 lines emulate a system call. The rest is used to get the return value, which you would also need to do with a system call. Basically, it has close to the same functionality as if it were:</p>
<pre class="brush: cpp; title: ; notranslate">
  system(&quot;programcall&quot;);

  wait(&amp;amp;execreturn);
  //make sure this does exit properly and isn't killed
  if (WIFEXITED(execreturn)) {
    rc = WEXITSTATUS(execreturn);
  }
  else {
    report_error(1);
    return PAM_CRED_ERR;
  }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://webstersprodigy.net/2009/06/execv-like-system-call/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>playing a scale with the atmega16</title>
		<link>http://webstersprodigy.net/2009/05/playing-a-scale-with-the-atmega16/</link>
		<comments>http://webstersprodigy.net/2009/05/playing-a-scale-with-the-atmega16/#comments</comments>
		<pubDate>Mon, 04 May 2009 03:51:22 +0000</pubDate>
		<dc:creator>webstersprodigy</dc:creator>
				<category><![CDATA[Bits and Bytes]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[atmega]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://webstersprodigy.net/?p=526</guid>
		<description><![CDATA[A musical “note” is a waveform that has a certain fundamental frequency. A perfect sine wave consists only of the fundamental frequency, and sounds very “pure” or mellow, like a flute. For this project, you are to use interrupts to generate the notes of a musical scale, while at the same time using another interrupt to update a count. We will generate square waves by toggling a bit within a port on and off. Specifically, your program should play the notes from middle C to the next higher C, each of approximately one second in duration. These notes should be playing at the same time that an 8-bit binary count is being displayed in the LED’s, updating at approximately 1/4 second. ]]></description>
			<content:encoded><![CDATA[<p>The Specification:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>The purpose of this assignment is to get further practice using interrupts, particularly concurrent interrupts. A musical “note” is a waveform that has a certain fundamental frequency. For example, the “A” above middle C on a piano has a frequency of 440 Hz, and middle C itself is approximately 261 Hz. On an equally tempered scale, each of the twelve notes is related to each other by a factor of 2 12 . A note that is an octave above another note is double the frequency of the lower note. A perfect sine wave consists only of the fundamental frequency, and sounds very “pure” or mellow, like a flute. Most waveforms consist of a fundamental and harmonics or overtones, which are additional frequencies above the fundamental. For instance, a square wave consists of the fundamental and multiples of the fundamental in decreasing amplitude. The distinctive sound of a violin is mostly a sawtooth wave (created as the rosin on the bow catches the string, then releases it), with other overtones (called dissonant overtones, due to the fact that they are not multiples of the fundamental) created by resonances in the wood.</p>
<p>For this assignment, you are to use interrupts to generate the notes of a musical scale, while at the same time using another interrupt to update a count. We will generate square waves by toggling a bit within a port on and off. Specifically, your program should play the notes from middle C to the next higher C, each of approximately one second in duration. These notes should be playing at the same time that an 8-bit binary count is being displayed in the LED’s, updating at approximately 1/4 second. As before, determine the code sizes, and estimate the percentages of time your ISR’s and “main” program takes of the total execution time. Also, for each note, estimate its accuracy &#8211; that is, how close is the note your program plays to the calculated frequency for the note.</p>
<p><a href="http://webstersprodigy.net/wp-content/uploads/2009/05/sound_avrtar.gz">Download the source here</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>This code requires avrdude, avr-gcc, and objcopy are installed</p>
<p>To compile, type:</p>
<blockquote><p>make</p></blockquote>
<p>After it&#8217;s compiled, to install to a connected and powered on atmega16 board, type:</p>
<blockquote><p>make install</p></blockquote>
<p>Note Makefile may require some modification depending on your environment.</p>
<p>This program includes a demo called homework3_demo.avi, which should play on vlc.</p>
<p>Program Size<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
The ATmega16 provides 16K bytes of Programmable Flash Program Memory, 512 bytes eeprom, and 1K byte SRAM</p>
<p>make gives a 3982 byte executable. It contains the following headers:</p>
<blockquote><p>Section Headers:<br />
[Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al<br />
[ 0]                   NULL            00000000 000000 000000 00      0   0  0<br />
[ 1] .text             PROGBITS        00000000 000074 000248 00  AX  0   0  2<br />
[ 2] .data             PROGBITS        00800060 0002bc 000020 00  WA  0   0  1<br />
[ 3] .bss              NOBITS          00800080 0002dc 000002 00  WA  0   0  1<br />
[ 4] .stab             PROGBITS        00000000 0002dc 000378 0c      5   0  4<br />
[ 5] .stabstr          STRTAB          00000000 000654 000054 00      0   0  1<br />
[ 6] .shstrtab         STRTAB          00000000 0006a8 00003b 00      0   0  1<br />
[ 7] .symtab           SYMTAB          00000000 00084c 000450 10      8  17  4<br />
[ 8] .strtab           STRTAB          00000000 000c9c 0002f2 00      0   0  1</p></blockquote>
<p>#without space optimization<br />
Program: .text + .data + .bootloader == 618 bytes (3.8% Full)<br />
Data: .data + .bss + .noinit == 34 bytes (3.3% Full)</p>
<p>Here is most the code</p>
<pre class="brush: cpp; title: ; notranslate">
/* http://www.avrfreaks.net/index.php?name=PNphpBB2&amp;amp;file=viewtopic&amp;amp;t=50106
 * was a big help understanding the timer syntax
 *
 * also relied on the atmega16 manual and the #defines located in /usr/avr/include/avr */

#include &lt;avr/io.h&gt;
#include &lt;avr/interrupt.h&gt;

/*counter keeps track of how many overflows in timer0 = about a second */
int counter = 0;

/*number of ticks to make a note at 1 MHz*/

/*
At 1MHz, these are the number of ticks it takes to equal a given note

const int C_l = 3817/2;
const int D   = 3401/2;
const int E   = 3030/2;
const int F   = 2865/2;
const int G   = 2551/2;
const int A   = 2272/2;
const int B   = 2024/2;
const int C_h = 1912/2; */

//const long int notes[8] = {3817, 3401, 3030, 2865, 2551, 2272, 2024, 1912};
const long int notes[8] = {1908, 1700, 1515, 1432, 1275, 1136, 1012, 956};

void port_init() {
  /*PORTC is connected to the amplifier */
  /*PORTB is connected to the LEDs */
  DDRB  = 0xff;  /*11111111 for all output */
  DDRC  = 0xff;
  PORTC = 0xff;  /*all lights turned off   */
  PORTB = 0xff;  /*all lights turned off   */
}

void init_timer1() {
  /*setup timer1, this will measure the notes */
  TCCR1B |= (1 &lt;&lt; WGM12);
  /*Enable CTC interrupt */
  TIMSK |= (1 &lt;&lt; OCIE1A);
  /* OCR1A = 15625;*/
  OCR1A = notes[0]; /* Set CTC value to middle C to begin with */
  /*timer runs with a 1MHz resolution */
  TCCR1B |= (1 &lt;&lt; CS10);

}

void init_timer0() {
  /*prescaler/64*/
  TCCR0 |= ((1 &lt;&lt; CS01) | (1 &lt;&lt; CS00));
  /*overflow mode - about every 1/61 seconds */
  TIMSK |= (1 &lt;&lt; TOIE0);
}

void main (void) {
  port_init();
  init_timer0();
  init_timer1();

  /*Enable global interrupts */
  sei();

  while(1) {
    /*most logic is handled by the interrupts */
  }
}

/* toggle the LED for now, this is the musical note */
ISR(TIMER1_COMPA_vect) {
  /*toggle the output */
  PORTC = ~PORTC;
}

ISR(TIMER0_OVF_vect) {
  counter += 1;
  if (counter == 61) {
    /*count up to 8 for all 8 notes*/
    if (PORTB == 0xf8) {
      PORTB = 0xff;
    }
    else {
      PORTB--;
    }
    //OCR1A = notes[~PORTB];
    OCR1A = notes[~PORTB];
    counter = 0;
  }
}
</pre>
<p>Here is a short video demonstration:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/H6ew1qtbq9M&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/H6ew1qtbq9M&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://webstersprodigy.net/2009/05/playing-a-scale-with-the-atmega16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

