Platform Builder: Replacing Files in an NK.BIN with BinMod.exe

<< Platform Builder: Problems with.NET CF 3.5 and Windows CE 6.0 | Home | Windows CE Live Chat Tueday May 26, 2009 >>

A friend and fellow MVP Jeff Arnett recently collaborated on a project to replace some DLL files in an existing NK.BIN file for testing.  Jeff tried to use BinMod.exe, but it didn’t work. When trying to extract or replace a DLL the following message was output to the console:

BinMod V1.0 built Apr 5 2006 11:32:47

Checking record #70 for potential TOC (ROMOFFSET = 0xFEC634B4)

Checking record #195 for potential TOC (ROMOFFSET = 0x00000000)

NOTICE! Record 195 looked like a TOC except DLL first = 0x4001C001, and DLL last = 0x4152C0A1

Error: File not found in image

Error: Extraction failed!

I did find with some further testing that this doesn’t happen with all files, but some.  It depends on the address of the DLL.  With some investigation we found that a bug in BinMod that causes this.

The following are the steps we followed to modify BinMod so that it could replace DLLs in the FILES section of an NK.BIN:

Build BinMod:

1.       Create empty console project in Visual Studio

2.       Copy source from C:\WINCE600\PRIVATE\WINCEOS\COREOS\NK\TOOLS\ROMIMAGE\BINMOD

3.       Add source to project

4.       In cbinmod.cpp change:      #include "..\compress\compress.h" to:     #include "compress.h"

5.       Add the following directories to the include path:      C:\WINCE600\PUBLIC\COMMON\OAK\INC      C:\WINCE600\PRIVATE\WINCEOS\COREOS\NK\TOOLS\ROMIMAGE\COMPRESS

6.     Set the Character Set to “Not Set”

Now that we can build binmod, we can modify it so that it can actually modify a bin file. The following steps will accomplish that:

1.       Modify lines 809 and 810 in cbinmod.cpp from:                if((DWORD)(HIWORD(pTOCLoc->dllfirst) << 16) <= pTOCLoc->dlllast &&                   (DWORD)(LOWORD(pTOCLoc->dllfirst) << 16) <= pTOCLoc->dlllast) to:               if((DWORD)pTOCLoc->dllfirst <= (DWORD)pTOCLoc->dlllast )

2.       Build the project

The new BinMod needs to load compress.dll from C:\program files\microsoft platform builder\6.00\cepb\idevs\imgutils, so that folder needs to be in your PATH. The easiest way to have it in your path is to use a Platform Builder build window when you test your BinMod.

Examples of using BinMod:

Extracting a DLL:

>>c:\SRC\binmod\debug\mybinmod.exe -i nk.bin -e amdnord.dll

BinMod V1.0 built May 16 2009 19:17:32

Checking record #70 for potential TOC (ROMOFFSET = 0xFEC634B4)

Checking record #195 for potential TOC (ROMOFFSET = 0x00000000)

Found pTOC = 0x8195fab4

rom offset = 0x00000000

Found 'amdnord.dll' in the image! - located at 819576b4, size 00008400 uncompressed

File extracted!

Replacing a DLL:

>>c:\SRC\binmod\debug\mybinmod.exe -i nk.bin -r amdnord.dll

BinMod V1.0 built May 16 2009 19:17:32

Checking record #70 for potential TOC (ROMOFFSET = 0xFEC634B4)

Checking record #195 for potential TOC (ROMOFFSET = 0x00000000)

Found pTOC = 0x8195fab4

rom offset = 0x00000000

Found 'amdnord.dll' in the image! - located at 819576b4, size 00008400 uncompressed

New file uncompressed = 00008400

Original record checksum: 0x2d7268

New record checksum: 0x2d7268

New data written to image!

Original record checksum: 0xd7f22

New record checksum: 0xd7f22

TOC updated!

Done!

Copyright © 2009 – Bruce Eitman

All Rights Reserved

Saturday, May 16, 2009 8:19 PM

This article is part of the GWB Archives. Original Author: Bruce Eitman

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.