patch windows registry

Ein kleines C/C++ Programm bestimmt die MAC Adresse (die eindeutige Nummer der Ethernetkarte) und erzeugt damit eine Datei zum Patchen der Registry; beim start von windows kann man diese Datei via regedit in die registry einfügen

card.cpp - erzeugt Rechnerabhängige Dateien

aufruf:
   card data     oder
   card data -l
     gibt folgendes aus:
         Username  

   card n
     ersetzt die Zeichenfolge %u, %i, %j in der Eingabe durch
     %i --> index in der Tabelle (Array in card.cpp)
     %j --> i+50
     %u --> Username

Im Programmtext oder im Datenfile muss das Array mit den Daten ausgefüllt 
werden:
   3 Zahlen - MAC Adresse (die eindeutige Nummer der Karte)             
   Name - Username/Rechnername

Beispiele:

Datenfile

0x0040 0x1234 0x617b w95_a 
0x0040 0x1234 0x6265 w95_b 
0x0040 0x1234 0x9ed0 w95_c 

Automatisches logon - anonym aber abhängig vom Rechner

card data -l > login.txt
autokey login.txt
net use H: \\FS0001\PRGNEW
Achtung: die Datei logon.txt wird angelegt - Schreibrechte
autokey schreibt eine Datei in den Tastaturbuffer - gibts im simtel archiv

IP Konfiguration (setzen der IP Adresse + Rechnername)

Anmerkung: IP Adresse kann auch mittels DHCP gesetzt werden, der Rechnername nicht
rem must be on c: (writeable)
rem dynamic ip
card data -n < h:\config\ip.reg > ip.reg
regedit ip.reg
h:\config\ip.reg enthaelt:
REGEDIT4

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans\0008]
"IPAddress"="10.4.1.%j"
"IPMask"="255.255.255.0"
"DefaultGateway"="10.4.1.1"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP]
"LMHostFile"="h:\\win95\\lmhosts"
"EnableDNS"="1"
"HostName"="%u"
"Domain"="ee.htlw1.ac.at"
"SearchList"=""
"NameServer"="10.1.1.1"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\VNETSUP]
"ComputerName"="%u"
"Workgroup"="HTLW1"
"Comment"="%u"

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\ComputerName\ComputerName]
"ComputerName"="%u"

Verbinden mit verschiedenen Laufwerken:

rem must be on c: (writeable)
card data -n < h:\config\i.txt > i.bat
call i.bat

h:\config\i.txt enthaelt:
net use i: \\fs0001\usr\local\%u
net use k: \\fs0001\prgnew\config\%u


card1.cpp


// © Copyright 1997-99 August Hörandl<hoerandl@elina.htlw1.ac.at>
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//    card data -l 
//      data        Datafile with MAC address
//      print the followingtext
//          username  
// 
//    card data -n 
//      replaces the string %u, %i, %j from stdin with
//      %i --> index of table (read from data)
//      %j --> i+50
//      %u --> username
// The datafile is line oriented:
//    3 numbers - MAC addresse
//    name - username/hostname
// example line
//   0x0040 0x1234 0x617b 

#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>


const int num_cards = 100;
struct cardinfo {
   unsigned int cx, bx, ax; // card number
   char     user[20]; // user name
};

cardinfo cards[num_cards] = {
	{ 0x0040, 0x3396, 0x617b, "w95_a" },
	{ 0x0040, 0x3396, 0x6265, "w95_b" },
};

// read data from file

void readfile(char* name)
{
  FILE* file = fopen(name,"r");
  if (! file) {
    cerr << "cannot open " << name << ": ";
    perror("");
    exit(99);
  }
  int i = 0;
  while (! feof(file) && i < num_cards) {
    fscanf(file, "%x %x %x %s",
	   &cards[i].cx, &cards[i].bx, &cards[i].ax, &cards[i].user);
    cerr << cards[i].cx << " " << cards[i].bx <<" "<< cards[i].ax 
	 << " " <<cards[i].user << endl;
    i++;
  }
  cerr << "read " << i << " cards from " << name << "\n";

  fclose(file);
}


// show text from cin using info card[i]
// %u -> user
// %i -> i (numeric)
// %j -> i+65 (numeric)


void show(int i)
{
    cin.unsetf(ios::skipws);
    while(cin && ! cin.eof()) {
       char ch = cin.get();
       if (ch == '%')
	 switch (cin.get()) {
	   case 'u': cout << cards[i].user; break;
	   case 'i': cout << i; break;
	   case 'j': cout << (i+65); break;
	 }
       else
	 cout << ch;
    }
}

/*
  options
    l      login: create login keys for autokey
    i      IP: create registry entry for network
*/

int main(int argc, char* argv[])
{
   union REGS regs;
   int ret, i;
   regs.h.ah = 0xEE;

   if (argc >= 2 && argv[1][0] != '-')
     readfile(argv[1]);

   ret = intdos(&regs, &regs);
   cerr << "NR: "<< hex
	<< regs.x.cx << ":" << regs.x.bx << ":" << regs.x.ax << '\n';
    for(i=0; i < num_cards; i++)
       if (regs.x.cx == cards[i].cx &&
	   regs.x.bx == cards[i].bx &&
	   regs.x.ax == cards[i].ax )
	 break;
    if (i == num_cards)
	cerr << "OOPS !\n";
    else
    if (argc >= 2 && argv[argc-1][0]=='-')
      switch(argv[argc-1][1]) {
      case 'l':
	cout << '"' << cards[i].user << "\" CR CR CR ";
	break;
      case 'n':
	show(i);
	break;
      }
    return ret;
}


© Copyright August Hörandl@elina.htlw1.ac.at/~hoerandl
Last modified: Tue Sep 14 14:39:06 CEST 1999