Guest User

regedith

a guest
Apr 3rd, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 2.60 KB | None | 0 0
  1. #!/usr/bin/awk -f
  2.  
  3. function pathclose(s, v) {
  4.     if (length(s)) {
  5.     script=script "setval " v "\n" s;
  6.     }
  7. }
  8.  
  9. BEGIN {
  10.     err=0;
  11.     if (ARGC!=3) {
  12.     print("regedith regfile(text) hivefile(bin)") >"/dev/stderr";
  13.     err=1;
  14.     exit 1;
  15.     }
  16.     hivefile=ARGV[2];
  17.     ARGC=2;
  18.     FS="";
  19.     inkey=0;
  20.     script="";
  21. }
  22.  
  23. FNR==1 && $0 != "Windows Registry Editor Version 5.00" {
  24.     err=1;
  25.     exit 1;
  26. }
  27.  
  28. !inkey && /^\[HKEY_LOCAL_MACHINE\\SYSTEM\\.*\]$/ {
  29.     inkey=1;
  30.     testcommand="cd \\";
  31.     pth=substr($0, 2, length($0)-2);
  32.     cnt=split(pth, dirs, "\\");
  33.     for (i=3; i<cnt; i++) {
  34.     if (i!=3) {
  35.         testcommand=testcommand "\\"
  36.     }
  37.     testcommand=testcommand dirs[i];
  38.     }
  39.     testcommand=testcommand " \n"
  40.     script=script testcommand;
  41.     testcommand=testcommand "cd " dirs[cnt] "\nclose\nexit\n";
  42.     if (system("echo '" testcommand "' | /usr/bin/hivexsh " hivefile " &>/dev/null")) {
  43.     script=script "add " dirs[cnt] "\n";
  44.     }
  45.     script=script "cd " dirs[cnt] "\n";
  46.     valnum=0;
  47.     escape=0;
  48.     s="";
  49. }
  50.  
  51. inkey {
  52.     if(!escape) {
  53.     if (!length($0)) {
  54.         inkey=0;
  55.         pathclose(s, valnum);
  56.         s="";
  57.         next;
  58.     }
  59.     quote=0;
  60.     key=1;
  61.     value=0;
  62.     }
  63.     escape=0;
  64.     for (i=1; i<=NF; i++) {
  65.     if (!escape && $i=="\\") {
  66.         escape=1;
  67.         continue;
  68.     }
  69.     if (!quote && !escape && $i=="\"") {
  70.         quote=1;
  71.         if (!key) {
  72.         value=1;
  73.         type="string";
  74.         s=s "string:"
  75.         valnum++;
  76.         }
  77.         continue;
  78.     }
  79.     if (quote) {
  80.         if (!escape && $i=="\"") {
  81.         if (key) {
  82.             s=s "\n";
  83.         }
  84.         quote=0;
  85.         continue;
  86.         }
  87.         s=s $i;
  88.         escape=0;
  89.         continue;
  90.     }
  91.     if (!quote && !value) {
  92.         switch($i) {
  93.         case "=": {
  94.             key=0;
  95.             type="";
  96.             break;
  97.         }
  98.         case ":": {
  99.             value=1;
  100.             valnum++;
  101.             switch (type) {
  102.             case "none": {
  103.                 s=s "none";
  104.                 break;
  105.             }
  106.             case "dword": {
  107.                 s=s "dword:0x";
  108.                 break;
  109.             }
  110.             case "qword": {
  111.                 s=s "qword:0x";
  112.                 break;
  113.             }
  114.             case "hex(1)": {
  115.                 s=s "hex:1:";
  116.                 break;
  117.             }
  118.             case "hex(2)": {
  119.                 s=s "hex:2:";
  120.                 break;
  121.             }
  122.             }
  123.             break;
  124.         }
  125.         default: {
  126.             type=type $i;
  127.         }
  128.         }
  129.         escape=0;
  130.         continue;
  131.     }
  132.     if (!quote && value) {
  133.         s=s $i;
  134.         escape=0;
  135.     }
  136.     }
  137.     if (!escape && value) {
  138.     s=s "\n";
  139.     }
  140. }
  141.  
  142. END {
  143.     if (err) {
  144.     exit 1;
  145.     }
  146.     pathclose(s, valnum);
  147.     script=script "commit\nclose\nexit\n";
  148.     system("echo '" script "' | /usr/bin/hivexsh -w " hivefile " &>/dev/null");
  149. #    print("echo '" script "' | /usr/bin/hivexsh -w " hivefile " &>/dev/null");
  150. }
Advertisement
Add Comment
Please, Sign In to add comment