<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8104011599973168109</id><updated>2011-11-27T15:25:06.164-08:00</updated><category term='win32'/><category term='news'/><category term='friends'/><title type='text'>Kernel Drivers Ahoy!</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-3039296989507086366</id><published>2011-02-11T06:19:00.000-08:00</published><updated>2011-02-11T06:21:35.585-08:00</updated><title type='text'>cscript, or why life is dull</title><content type='html'>I'm busy doing WMI stuff these days, and I've had to play with js code within the microsoft command prompt. It's fun, but it can be a hassle to try and understand the code that's there.&lt;br /&gt;&lt;br /&gt;One thing that is usefull, is to make sure that all js output goes to the command prompt, so it makes it easier to read.&lt;br /&gt;&lt;br /&gt;to do that, type this in a command prompt!&lt;br /&gt;&lt;br /&gt;Cscript /H:CScript&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-3039296989507086366?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/3039296989507086366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=3039296989507086366' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/3039296989507086366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/3039296989507086366'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2011/02/cscript-or-why-life-is-dull.html' title='cscript, or why life is dull'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-3029272855460662597</id><published>2011-01-26T07:26:00.000-08:00</published><updated>2011-01-26T07:30:47.283-08:00</updated><title type='text'>Cmd, my best friend after all</title><content type='html'>Isn't it interesting that after all that GUI we are being thrown, we just end up going back to command prompts to get interesting stuff quickly?&lt;br /&gt;&lt;br /&gt;Just recently, I've had to figure out the ip address of my laptop to be able to add a route, and the easiest way to figure it out? cmd prompt!&lt;br /&gt;&lt;br /&gt;Here's how to get the ip address of a machine easily (all of them):&lt;br /&gt;&lt;br /&gt;netsh interface ip show addresses | find "IP Address" | find /v "127.0.0.1" | find /v "0.0.0.0"&lt;br /&gt;&lt;br /&gt;You can also get this into a variable, and specify the actual config you want&lt;br /&gt;&lt;br /&gt;Here's a batch file I use to get my "Canada" address ;)&lt;br /&gt;@echo off&lt;br /&gt;@netsh interface ip show addresses "Canada" | find "IP Address" | find /v "127.0.0.1" | find /v "0.0.0.0" &gt; %temp%\tempip.txt&lt;br /&gt;@FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a&lt;br /&gt;@del %temp%\TEMPIP.txt&lt;br /&gt;@set IP=%IP:~1%&lt;br /&gt;@set IP=%IP: =%&lt;br /&gt;@echo %IP% &gt;%temp%\ip.txt&lt;br /&gt;@echo The current Canada IP address is "%IP%"&lt;br /&gt;@echo press any key to set the address in the routing table&lt;br /&gt;pause&lt;br /&gt;route add 10.22.180.0 mask 255.255.255.0 %IP%&lt;br /&gt;&lt;br /&gt;I have other cmd tidbits I love, I'll add them later&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-3029272855460662597?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/3029272855460662597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=3029272855460662597' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/3029272855460662597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/3029272855460662597'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2011/01/cmd-my-best-friend-after-all.html' title='Cmd, my best friend after all'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-2985710057661458028</id><published>2009-07-21T18:46:00.001-07:00</published><updated>2009-07-21T18:50:05.543-07:00</updated><title type='text'>It's the parameters dummy!</title><content type='html'>You know you've been looking at the same code too much when one small parameter is all it takes to change the behaviour!&lt;br /&gt;&lt;br /&gt;I was looking at code where there was a KeWaitForSingleObject, but the alertable parameter was set to TRUE instead of the normal FALSE...&lt;br /&gt;&lt;br /&gt;Then I was failing to understand how this thread was continuing on, freeing the worker, and crashing the rest of the code...&lt;br /&gt;&lt;br /&gt;Well, it was all caused by this alertable set to TRUE.&lt;br /&gt;&lt;br /&gt;The calling app, which was terminating, caused the thread to be in an alertable state. Then obviously, the code didn't deal with it (that's what you get with inherited code that you people hand over to you)...&lt;br /&gt;&lt;br /&gt;Of course, since the worker was still in the queue, and was now freed, there had to be some other piece of code that would come along and try to signal the event that was part of said worker! DUH!&lt;br /&gt;&lt;br /&gt;Anyhow, now I've learned my lesson: always, always make sure you use the return code, and look at the value!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-2985710057661458028?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/2985710057661458028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=2985710057661458028' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/2985710057661458028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/2985710057661458028'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2009/07/its-parameters-dummy.html' title='It&apos;s the parameters dummy!'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-7160033655846611850</id><published>2009-06-19T05:20:00.001-07:00</published><updated>2009-06-19T05:24:34.179-07:00</updated><title type='text'>finding a leaked tag quickly!</title><content type='html'>Recently, I've been working on a file system driver, and unfortunatly something in it is increasing the memory foot print on every directory query.&lt;br /&gt;&lt;br /&gt;Now I wanted to see what was the call that was increasing the memory, but unfortunatly the tag that was leaking was not in my code.&lt;br /&gt;&lt;br /&gt;So, you can create a breakpoint that executes and checks the tag on exallocatepoolwithtag, but since memory is constantly allocated, that will take a while (execute and continue is slow).&lt;br /&gt;&lt;br /&gt;So here comes microsoft to the rescue!&lt;br /&gt;&lt;br /&gt;In fact there is a nice global variable that you can set, and it will break when that tag is allocated.&lt;br /&gt;&lt;br /&gt;nt!poolhittag&lt;br /&gt;&lt;br /&gt;You just do "ed nt!poolhittag 'looP'" to get a hit on tag "Pool" (yes you need to reverse the name)&lt;br /&gt;&lt;br /&gt;You can see the contents of it by doing "db nt!PoolHitTag L4"&lt;br /&gt;&lt;br /&gt;The debugger will now break every time that pool is allocated or freed with the "Pool" tag!&lt;br /&gt;&lt;br /&gt;Saved me a couple of hours of going nuts!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-7160033655846611850?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/7160033655846611850/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=7160033655846611850' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/7160033655846611850'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/7160033655846611850'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2009/06/finding-leaked-tag-quickly.html' title='finding a leaked tag quickly!'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-1414514499444519204</id><published>2009-05-15T11:08:00.000-07:00</published><updated>2009-05-15T11:09:52.561-07:00</updated><title type='text'>Enable Auto-Login</title><content type='html'>Another quick usefull tidbit, how to enable auto-login on 2008:&lt;br /&gt;&lt;br /&gt;do "run", then type : control userpasswords2&lt;br /&gt;&lt;br /&gt;Then simply deselect that the user needs to type a password and press OK...&lt;br /&gt;&lt;br /&gt;Then the system asks you for the user password, and it now will auto-login!!!&lt;br /&gt;&lt;br /&gt;Super ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-1414514499444519204?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/1414514499444519204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=1414514499444519204' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/1414514499444519204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/1414514499444519204'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2009/05/enable-auto-login.html' title='Enable Auto-Login'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-2052107767847061719</id><published>2009-05-15T07:28:00.001-07:00</published><updated>2009-05-15T07:33:32.960-07:00</updated><title type='text'>Enable Kernel Debugging on vista and better</title><content type='html'>Somehow, I always forget this, and have to google it...&lt;br /&gt;&lt;br /&gt;http://www.microsoft.com/whdc/driver/tips/Debug_Vista.mspx&lt;br /&gt;&lt;br /&gt;In a nutshell:&lt;br /&gt;&lt;br /&gt;1- bcdedit /copy {current} /d DebugEntry&lt;br /&gt;&lt;br /&gt;(this will give you the {ID} of your new entry, important for later)&lt;br /&gt;&lt;br /&gt;2- bcdedit /debug {ID} ON&lt;br /&gt;&lt;br /&gt;(this sets the entry to be debug enabled with default settings - com1/115200)&lt;br /&gt;&lt;br /&gt;3- bcdedit /default {ID}&lt;br /&gt;&lt;br /&gt;(this sets the newly created entry as being the default now)&lt;br /&gt;&lt;br /&gt;And reboot!!! Voila! Now, stop googling for it! (note to self)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-2052107767847061719?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/2052107767847061719/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=2052107767847061719' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/2052107767847061719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/2052107767847061719'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2009/05/enable-kernel-debugging-on-vista-and.html' title='Enable Kernel Debugging on vista and better'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-8710537678939229709</id><published>2009-04-03T07:32:00.000-07:00</published><updated>2009-04-03T07:36:06.684-07:00</updated><title type='text'>APCs</title><content type='html'>Whew, who knew APCs could be so complicated...&lt;br /&gt;&lt;br /&gt;After a small discussion with various team members, here is what we know:&lt;br /&gt;&lt;br /&gt;There are a couple of different APC types:&lt;br /&gt;&lt;br /&gt;user mode APC&lt;br /&gt;kernel mode APC&lt;br /&gt;special kernel mode APC&lt;br /&gt;&lt;br /&gt;To disable user/kernel mode APC for the CURRENT THREAD use KeEnterCriticalRegion&lt;br /&gt;To disable user/kernel/special kernel mode APC for the CURRENT THREAD use KeEnterGuardedRegion&lt;br /&gt;To disable user/kernel/special kernel mode APC for EVERYONE use KeRaiseIrql to APC_LEVEL&lt;br /&gt;&lt;br /&gt;Our main contention was that being at passive mode didn't tell you if those APCs would run or not... So they may not run... for the current thread... But unless you are at APC, they will always be enabled for other threads&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-8710537678939229709?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/8710537678939229709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=8710537678939229709' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/8710537678939229709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/8710537678939229709'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2009/04/apcs.html' title='APCs'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-6088600031131352673</id><published>2007-11-16T10:39:00.000-08:00</published><updated>2007-11-16T10:41:00.239-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='friends'/><title type='text'>Friends &amp; Family</title><content type='html'>Hi Friends &amp; Family.&lt;br /&gt;&lt;br /&gt;I know this blog is mostly about work related things, and for the forseable future it will stay that way. Note that I will create a family &amp; friends oriented blog in the near future, and I will update that regularly ;)&lt;br /&gt;&lt;br /&gt;In the mean time, don't hesitate to post comments on the posts available here!&lt;br /&gt;&lt;br /&gt;See you soon!&lt;br /&gt;&lt;br /&gt;S&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-6088600031131352673?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/6088600031131352673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=6088600031131352673' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/6088600031131352673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/6088600031131352673'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2007/11/friends-family.html' title='Friends &amp; Family'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-4923479050332803357</id><published>2007-10-19T12:38:00.000-07:00</published><updated>2007-10-19T12:41:28.165-07:00</updated><title type='text'>The answer!</title><content type='html'>After just a last look at the documentation for OpenFileById, I stumbled on the structure they point to at msdn:&lt;br /&gt;(http://msdn2.microsoft.com/en-us/library/aa364227.aspx)&lt;br /&gt;&lt;br /&gt;typedef struct FILE_ID_DESCRIPTOR {&lt;br /&gt;    DWORD dwSize;  // Size of the struct&lt;br /&gt;    FILE_ID_TYPE Type; // Describes the type of identifier passed in.&lt;br /&gt;    union {&lt;br /&gt;        LARGE_INTEGER FileId;&lt;br /&gt;        GUID ObjectId;&lt;br /&gt;    };&lt;br /&gt;} FILE_ID_DESCRIPTOR, *LPFILE_ID_DESCRIPTOR;&lt;br /&gt;&lt;br /&gt;I noticed a difference with the version declared in the shipping v1.1 version of fileext.h:&lt;br /&gt;&lt;br /&gt;typedef struct FILE_ID_DESCRIPTOR {&lt;br /&gt;    DWORD dwSize;  // Size of the struct&lt;br /&gt;    FILE_ID_TYPE Type; // Describes the type of identifier passed in.&lt;br /&gt;    union {&lt;br /&gt;        LARGE_INTEGER FileId;&lt;br /&gt;    };&lt;br /&gt;} FILE_ID_DESCRIPTOR, *LPFILE_ID_DESCRIPTOR;&lt;br /&gt;&lt;br /&gt;When using sizeof() with the msdn version, it correctly returns 24...&lt;br /&gt;&lt;br /&gt;I've sent microsoft an email about it...&lt;br /&gt;&lt;br /&gt;I'm guessing no one is using this :p&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-4923479050332803357?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/4923479050332803357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=4923479050332803357' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/4923479050332803357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/4923479050332803357'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2007/10/answer.html' title='The answer!'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-8829313886360869235</id><published>2007-10-19T12:08:00.000-07:00</published><updated>2007-10-19T12:22:09.097-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='win32'/><title type='text'>OpenFileById</title><content type='html'>A while back,&lt;br /&gt;&lt;br /&gt;I was trying to determine the file name for a given file ID, and had initially found the new win32 API to do this: OpenFileById.&lt;br /&gt;&lt;br /&gt;However, I never got it to work, and soon used some kernel code in usermode to get it.&lt;br /&gt;&lt;br /&gt;Recently, I've had to revisit this code to make an easier win32 app that can find a file's name.&lt;br /&gt;&lt;br /&gt;I was always getting an invalid parameter every time I called the function, so I finally traced in assembly...&lt;br /&gt;&lt;br /&gt;And behold! The function was checking my parameters, and the size of the structure I was passing (the dwSize parameter), which I had set to the sizeof(structure).&lt;br /&gt;&lt;br /&gt;When looking at the given size, it did not match what they were looking for. (I had 16)&lt;br /&gt;&lt;br /&gt;So I just changed my code to set the size to the value they were expecting (24), and made sure I allocated my structure inside a pointer that had at least that size as a backing (even if the structure really only is 16 bytes).&lt;br /&gt;&lt;br /&gt;All of a sudden it worked!&lt;br /&gt;&lt;br /&gt;Here is a tidbit:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   wsprintf(szVolumePath, TEXT("\\\\.\\%c:"), cDriveLetter[0]);&lt;br /&gt;   hDisk=CreateFile(szVolumePath,&lt;br /&gt;            GENERIC_READ,&lt;br /&gt;            FILE_SHARE_READ|FILE_SHARE_WRITE,&lt;br /&gt;            NULL,&lt;br /&gt;            OPEN_EXISTING,&lt;br /&gt;            0,&lt;br /&gt;            NULL);&lt;br /&gt;&lt;br /&gt;   if(hDisk!=INVALID_HANDLE_VALUE)&lt;br /&gt;   {&lt;br /&gt;      // This value was determined by looking at the assembly code&lt;br /&gt;      // and has no actual corresponance to the structure size which &lt;br /&gt;      // is 16. Might be related to 64bit version?&lt;br /&gt;      fileIDDesc.dwSize          = 24;          &lt;br /&gt;      fileIDDesc.FileId.QuadPart = index;&lt;br /&gt;      fileIDDesc.Type        = FileIdType;&lt;br /&gt;&lt;br /&gt;      hFile = OpenFileById ( hDisk, &lt;br /&gt;                  &amp;fileIDDesc,&lt;br /&gt;                  SYNCHRONIZE | FILE_READ_ATTRIBUTES,&lt;br /&gt;                  FILE_SHARE_READ|FILE_SHARE_WRITE,&lt;br /&gt;                  NULL,&lt;br /&gt;                  0 );&lt;br /&gt;&lt;br /&gt;      if (hFile != INVALID_HANDLE_VALUE)&lt;br /&gt;      {&lt;br /&gt;         PFILE_NAME_INFO pFileNameInfo = NULL;&lt;br /&gt;         pFileNameInfo = (PFILE_NAME_INFO)malloc(sizeof(FILE_NAME_INFO)+1000);&lt;br /&gt;         if (pFileNameInfo != NULL)&lt;br /&gt;         {&lt;br /&gt;            RtlZeroMemory(pFileNameInfo, sizeof(FILE_NAME_INFO) + 1000);&lt;br /&gt;            GetFileInformationByHandleEx(hFile, FileNameInfo, pFileNameInfo, sizeof(FILE_NAME_INFO) + 1000);&lt;br /&gt;&lt;br /&gt;            if (pFileNameInfo-&gt;FileNameLength &gt; 0)&lt;br /&gt;            {&lt;br /&gt;               if (*pLength &gt;= pFileNameInfo-&gt;FileNameLength)&lt;br /&gt;               {&lt;br /&gt;                    // copy your file, and return it!&lt;br /&gt;&lt;br /&gt;That's how simple it is, if you figure out that OpenFileById needs a 24bytes size structure :p&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-8829313886360869235?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/8829313886360869235/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=8829313886360869235' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/8829313886360869235'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/8829313886360869235'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2007/10/openfilebyid.html' title='OpenFileById'/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8104011599973168109.post-2501978407484407429</id><published>2007-10-19T11:18:00.000-07:00</published><updated>2007-10-19T11:19:58.696-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='news'/><title type='text'></title><content type='html'>Well!&lt;br /&gt;&lt;br /&gt;This is my new blog, the old one is located here:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://steve-goddyn.spaces.live.com/default.aspx"&gt;http://steve-goddyn.spaces.live.com/default.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Don't hesitate to give me a shout if you need to!&lt;br /&gt;&lt;br /&gt;S&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8104011599973168109-2501978407484407429?l=kerneldrivers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kerneldrivers.blogspot.com/feeds/2501978407484407429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8104011599973168109&amp;postID=2501978407484407429' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/2501978407484407429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8104011599973168109/posts/default/2501978407484407429'/><link rel='alternate' type='text/html' href='http://kerneldrivers.blogspot.com/2007/10/well-this-is-my-new-blog-old-one-is.html' title=''/><author><name>AirsoftSnake</name><uri>http://www.blogger.com/profile/11180821230231010452</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
