{"id":572,"date":"2013-11-05T23:31:46","date_gmt":"2013-11-05T23:31:46","guid":{"rendered":"http:\/\/www.gironsec.com\/blog\/?p=572"},"modified":"2013-11-05T23:31:46","modified_gmt":"2013-11-05T23:31:46","slug":"i","status":"publish","type":"post","link":"https:\/\/www.gironsec.com\/blog\/2013\/11\/i\/","title":{"rendered":"I <3 C"},"content":{"rendered":"<p>I love C. It was my first language I learned. Any other security professional will tell you, C is the bomb, but on the same token, a source for a lot of head ache.<\/p>\n<p>To anyone out there aspiring to be a security professional, get to know C and assembly. C lets you inline assembly which makes it awesome. The key is to practice your programming and practice often. Its too easy to forget. <\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #557799\">#include &lt;windows.h&gt;<\/span>\r\n<span style=\"color: #557799\">#include &lt;stdio.h&gt;<\/span>\r\n<span style=\"color: #333399; font-weight: bold\">char<\/span> <span style=\"color: #333333\">*<\/span><span style=\"color: #0066BB; font-weight: bold\">ppt<\/span>(<span style=\"color: #333399; font-weight: bold\">char<\/span> <span style=\"color: #333333\">*<\/span>);\r\n<span style=\"color: #333399; font-weight: bold\">long<\/span> <span style=\"color: #0066BB; font-weight: bold\">GetFS<\/span>(<span style=\"color: #333399; font-weight: bold\">FILE<\/span> <span style=\"color: #333333\">*<\/span>);\r\n<span style=\"color: #333399; font-weight: bold\">int<\/span> <span style=\"color: #0066BB; font-weight: bold\">main<\/span>(<span style=\"color: #333399; font-weight: bold\">int<\/span> argc, <span style=\"color: #333399; font-weight: bold\">char<\/span> <span style=\"color: #333333\">*<\/span>argv[])\r\n{\r\n\t<span style=\"color: #008800; font-weight: bold\">if<\/span>(argc <span style=\"color: #333333\">&lt;<\/span> <span style=\"color: #0000DD; font-weight: bold\">3<\/span>)\r\n\t{\r\n\tprintf(<span style=\"background-color: #fff0f0\">&quot;Usage is %s filename xorcount&quot;<\/span>,argv[<span style=\"color: #0000DD; font-weight: bold\">0<\/span>]); \r\n\t<span style=\"color: #008800; font-weight: bold\">return<\/span> <span style=\"color: #0000DD; font-weight: bold\">0<\/span>;\r\n\t}\r\n\t<span style=\"color: #008800; font-weight: bold\">const<\/span> <span style=\"color: #333399; font-weight: bold\">int<\/span> xorcount <span style=\"color: #333333\">=<\/span> atoi(argv[<span style=\"color: #0000DD; font-weight: bold\">2<\/span>]);\r\n\t<span style=\"color: #333399; font-weight: bold\">char<\/span> <span style=\"color: #333333\">*<\/span>derp <span style=\"color: #333333\">=<\/span> ppt(argv[<span style=\"color: #0000DD; font-weight: bold\">1<\/span>]);\r\n\t<span style=\"color: #333399; font-weight: bold\">FILE<\/span>  <span style=\"color: #333333\">*<\/span>pFile <span style=\"color: #333333\">=<\/span> fopen ( argv[<span style=\"color: #0000DD; font-weight: bold\">1<\/span>] , <span style=\"background-color: #fff0f0\">&quot;rb&quot;<\/span> );\r\n\t<span style=\"color: #333399; font-weight: bold\">unsigned<\/span> <span style=\"color: #333399; font-weight: bold\">int<\/span> fsg <span style=\"color: #333333\">=<\/span> GetFS(pFile);\r\n\tfclose(pFile);\r\n\t<span style=\"color: #333399; font-weight: bold\">int<\/span> x;\r\n\t<span style=\"color: #008800; font-weight: bold\">for<\/span>(x<span style=\"color: #333333\">=<\/span><span style=\"color: #0000DD; font-weight: bold\">0<\/span>;x<span style=\"color: #333333\">&lt;<\/span>fsg;x<span style=\"color: #333333\">++<\/span>)\r\n\t{\r\n\t\t<span style=\"color: #333399; font-weight: bold\">int<\/span> vg <span style=\"color: #333333\">=<\/span> derp[x];\r\n\t\t\r\n\t\t<span style=\"color: #008800; font-weight: bold\">__asm<\/span>\r\n\t\t{\r\n\t\t\tmov eax,xorcount\r\n\t\t\txor vg,eax\r\n\t\t}\r\n\t\tprintf(<span style=\"background-color: #fff0f0\">&quot;Hex pos: %d <\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\t<\/span><span style=\"background-color: #fff0f0\">Hex Value: %2X<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\t<\/span><span style=\"background-color: #fff0f0\">Ascii Char Value: %c<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\t<\/span><span style=\"background-color: #fff0f0\">Xor&#39;d value of char: %d<\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n<\/span><span style=\"background-color: #fff0f0\">&quot;<\/span>,x,derp[x],derp[x],vg);\r\n\t\tvg<span style=\"color: #333333\">=<\/span><span style=\"color: #0000DD; font-weight: bold\">0<\/span>;\r\n\t}\r\n\t<span style=\"color: #008800; font-weight: bold\">__asm<\/span>\r\n\t{\r\n\tsar fsg,<span style=\"color: #0000DD; font-weight: bold\">3<\/span>\r\n\t}\r\n\tprintf(<span style=\"background-color: #fff0f0\">&quot;File size shifted right 3: %i <\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n<\/span><span style=\"background-color: #fff0f0\">&quot;<\/span>,fsg);\r\n\t<span style=\"color: #008800; font-weight: bold\">__asm<\/span>\r\n\t{\r\n\tsal fsg,<span style=\"color: #0000DD; font-weight: bold\">3<\/span>\r\n\tmov eax,<span style=\"color: #0000DD; font-weight: bold\">1024<\/span>\r\n\tcrc32 eax,fsg\r\n\t}\r\n\tprintf(<span style=\"background-color: #fff0f0\">&quot;File size shifted left 3: %i <\/span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n<\/span><span style=\"background-color: #fff0f0\">&quot;<\/span>,fsg);\r\n}\r\n<span style=\"color: #333399; font-weight: bold\">char<\/span><span style=\"color: #333333\">*<\/span> <span style=\"color: #0066BB; font-weight: bold\">ppt<\/span>(<span style=\"color: #333399; font-weight: bold\">char<\/span> <span style=\"color: #333333\">*<\/span>filename) <span style=\"color: #888888\">\/\/ load file into buffer and return<\/span>\r\n{\r\n  <span style=\"color: #333399; font-weight: bold\">FILE<\/span> <span style=\"color: #333333\">*<\/span> pFile;\r\n  <span style=\"color: #333399; font-weight: bold\">long<\/span> lSize;\r\n  <span style=\"color: #333399; font-weight: bold\">char<\/span> <span style=\"color: #333333\">*<\/span> buffer;\r\n  <span style=\"color: #333399; font-weight: bold\">size_t<\/span> result;\r\n  pFile <span style=\"color: #333333\">=<\/span> fopen ( filename , <span style=\"background-color: #fff0f0\">&quot;rb&quot;<\/span> );\r\n  <span style=\"color: #008800; font-weight: bold\">if<\/span> (pFile<span style=\"color: #333333\">==<\/span><span style=\"color: #007020\">NULL<\/span>) {fputs (<span style=\"background-color: #fff0f0\">&quot;File error&quot;<\/span>,stderr); exit (<span style=\"color: #0000DD; font-weight: bold\">1<\/span>);}\r\n  fseek (pFile , <span style=\"color: #0000DD; font-weight: bold\">0<\/span> , SEEK_END);\r\n  lSize <span style=\"color: #333333\">=<\/span> ftell (pFile);\r\n  rewind (pFile);\r\n  buffer <span style=\"color: #333333\">=<\/span> (<span style=\"color: #333399; font-weight: bold\">char<\/span><span style=\"color: #333333\">*<\/span>) malloc (<span style=\"color: #008800; font-weight: bold\">sizeof<\/span>(<span style=\"color: #333399; font-weight: bold\">char<\/span>)<span style=\"color: #333333\">*<\/span>lSize);\r\n  <span style=\"color: #008800; font-weight: bold\">if<\/span> (buffer <span style=\"color: #333333\">==<\/span> <span style=\"color: #007020\">NULL<\/span>) {fputs (<span style=\"background-color: #fff0f0\">&quot;Memory error&quot;<\/span>,stderr); exit (<span style=\"color: #0000DD; font-weight: bold\">2<\/span>);}\r\n  result <span style=\"color: #333333\">=<\/span> fread (buffer,<span style=\"color: #0000DD; font-weight: bold\">1<\/span>,lSize,pFile);\r\n  <span style=\"color: #008800; font-weight: bold\">if<\/span> (result <span style=\"color: #333333\">!=<\/span> lSize) {fputs (<span style=\"background-color: #fff0f0\">&quot;Reading error&quot;<\/span>,stderr); exit (<span style=\"color: #0000DD; font-weight: bold\">3<\/span>);}\r\n  fclose (pFile);\r\n  <span style=\"color: #008800; font-weight: bold\">return<\/span> buffer;\r\n}\r\n<span style=\"color: #333399; font-weight: bold\">long<\/span> <span style=\"color: #0066BB; font-weight: bold\">GetFS<\/span>(<span style=\"color: #333399; font-weight: bold\">FILE<\/span> <span style=\"color: #333333\">*<\/span>lol) <span style=\"color: #888888\">\/\/ get file size<\/span>\r\n{\r\n  <span style=\"color: #333399; font-weight: bold\">long<\/span> lSize <span style=\"color: #333333\">=<\/span> <span style=\"color: #0000DD; font-weight: bold\">0<\/span>;\r\n  fseek (lol , <span style=\"color: #0000DD; font-weight: bold\">0<\/span> , SEEK_END);\r\n  lSize <span style=\"color: #333333\">=<\/span> ftell (lol);\r\n  rewind (lol);\r\n  <span style=\"color: #008800; font-weight: bold\">return<\/span> lSize;\r\n}\r\n<\/pre>\n<\/div>\n<p>This is kind of a filler post. I just feel like updating the blog with something. On that note, I&#8217;m split on what i want to do next. Was thinking of making a segway into hardware hacking for a little while as I had a project in mind, but we shall see. <a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/11\/iwHX6.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/11\/iwHX6.jpg\" alt=\"iwHX6\" width=\"765\" height=\"711\" class=\"alignnone size-full wp-image-573\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/11\/iwHX6.jpg 765w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/11\/iwHX6-300x278.jpg 300w\" sizes=\"(max-width: 765px) 100vw, 765px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I love C. It was my first language I learned. Any other security professional will tell you, C is the bomb, but on the same token, a source for a lot of head ache. To anyone out there aspiring to be a security professional, get to know C and assembly. C lets you inline assembly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/572"}],"collection":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/comments?post=572"}],"version-history":[{"count":1,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/572\/revisions"}],"predecessor-version":[{"id":574,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/572\/revisions\/574"}],"wp:attachment":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/media?parent=572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/categories?post=572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/tags?post=572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}