Re: C wizard, if you like a challenge here's your chance


[ Follow Ups ] [ Post Followup ] [ Build Your Own Arcade Controls message board ] [ FAQ ]

Posted by Wes on 29, 2001 at 10:58 AM:

In Reply to: C wizard, if you like a challenge here's your chance posted by Bugfinder on 28, 2001 at 6:05 PM:

if !strcmp(serialnumbervariable, "hardcodedser")
{
/* your hard drive here, do nothing */
}
else
{
/* anyone elses hard drive here */
/* this is an example, do what you wish */
printf("Operation Invalid 0x334fac332\n");
return 0;
}

: I asked EmuMannen (I think it was last year) how could I have a program to check the serial number of the hard drive it is running on and he was kind enough to reply me with this piece of code:

: #include
: #include

: struct DISKINFO {
: unsigned int InfoLevel;
: unsigned int HiSerialNumber;
: unsigned int LoSerialNumber;
: char VolumeLabel[11];
: char FileSystem[8];
: };

: int GetDiskInfo(int Drive, struct DISKINFO *di) {

: union REGS regs; // 8086 register union

: regs.h.ah = 0x69; // DOS function disk serial number
: regs.h.al = 0x00; // Subfunction get
: regs.h.bl = Drive; // Drive number (0=default, 1=A, 2=B, etc)
: regs.h.bh = 0x00; // Info level (only 00h for DOS)
: regs.x.dx = FP_OFF(di); // Offset of di
: int86(0x21, Žs, Žs); // Make interrupt call to DOS

: return(regs.x.cflag); // If carry flag is set, there was an error
: }

: int main(void) {

: struct DISKINFO DiskInfo;

: if (GetDiskInfo(0,&DiskInfo) == 0) {

: printf("\nDisk Information About Default Drive\n");
: printf("====================================\n");
: printf("Serial Number: %i-%i\n", DiskInfo.HiSerialNumber, DiskInfo.LoSerialNumber);
: printf("Disk Label : %11.11s\n", DiskInfo.VolumeLabel);
: printf("File System : %8.8s\n", DiskInfo.FileSystem);
: }

: return 0;
: }

: This is to puzzle some friends that come to my house almost every MAME release to copy the emulator on *my* diskettes and always "forget" to return them to me. They want to play MAME on their computers, but don't feel like downloading it by themselves so I'd like to make this joke with them.

: I don't know that much C, the little bit I know was learned by looking and changing into MAME source. I already have the code that gets the serial number; what would be the lines to hardcode the expected serial number, and compare with the one just got from the default HD? If they differ I want the program to shut down, possibly with a funny message, how to do? Maybe in src\msdos\msdos.c, after:

: /* put here anything you need to do when the program is started. Return 0 if */
: /* initialization was successful, nonzero otherwise. */

: I have no idea what would be the exact lines in C to do this, as I told I'm no programmer... If you could send me the few necessary lines, would be enough to make me very happy. Thank you for helping me to save my diskettes and have a good laugh at those "wise guys".

: Thank you for any help...

:
: Bugfinder





Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ Build Your Own Arcade Controls message board ] [ FAQ ]