1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242:
| program decodefly; {$APPTYPE CONSOLE} uses windows, tlHelp32, classes, sysutils, messages;
function Encode(s: string): Integer; var a: Integer; b: Integer; i: Integer; begin s := s + #0; a := 0; for i := 2 to length(s) do begin b := Ord(s[i]) + a * $25; a := b; end; Result := a; end; var r: string = 'abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + '01234567890' + '!"§$%&/()=?' + 'ÖÄÜöüä' + '+*~#-_.:,;<>@€';
function GetPossible(a: int64; var b: int64): Boolean; begin Result := False; while ((a mod $25) <> 0) and (a < $25000000000) do inc(a, $100000000); if (a < $25000000000) then Result := True; b := (a div $25); end;
function decodebrute(a: int64; var s: string; tiefe: integer; maxdepth: integer): Boolean; var i: integer; b: int64; begin if (a = 0) then begin s := ''; Result := True; Exit; end; if (a > $25) and (a <= $FF) and (Pos(Char(a), r) > 0) then begin s := Char(a); Result := True; Exit; end; if (tiefe > maxdepth) then begin Result := False; Exit; end; i := 1; Result := False; while (i <= length(r)) and (not Result) do begin b := a - ord(r[i]); if (b > 0) and (b mod $25 = 0) then if decodebrute(b div $25, s, tiefe + 1, maxdepth) then begin s := s + char(r[i]); Result := True; end; inc(i); end; end;
function decode(a: integer): string; var s: string; b: int64; begin if GetPossible(a, b) then if decodebrute(b, s, 0, 6) then Result := '?' + s; end;
function GetEdit: HWND; var wnd: HWND; begin Result := 0; wnd := FindWindow('TForm1', nil); wnd := FindWindowEx(wnd, 0, 'TPanel', nil); wnd := FindWindowEx(wnd, 0, 'TPageControl', nil); wnd := FindWindowEx(wnd, 0, 'TTabSheet', nil); wnd := FindWindowEx(wnd, 0, 'TEdit', nil); if wnd <> 0 then Result := wnd; end;
function GetExecutableFromPID(dwProcessID: DWord): string; stdcall; var FSnapshotHandle: THandle; FModuleEntry32: TModuleEntry32; begin Result := ''; if (dwProcessID <> 0) then begin FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessID); if (fSnapshotHandle <> 0) then begin FModuleEntry32.dwSize := Sizeof(FModuleEntry32); Module32First(FSnapshotHandle, FModuleEntry32); Result := FModuleEntry32.szExePath; CloseHandle(FSnapshotHandle); end; end; end;
function ExtractEncodedPassword(ExeName: string): integer; var fm: TFileStream; f: string; i: integer; begx, endx: integer; begin Result := 0; fm := TFileStream.Create(ExeName, fmOpenRead); SetLength(f, fm.Size); fm.Read(f[1], fm.size); fm.free; begx := 0; endx := 0; for i := 1 to length(f) do begin if Copy(f, i, length('!#0005H3X¶')) = '!#0005H3X¶' then begx := i + 10; if Copy(f, i, length('EO!#0005H3XSO')) = 'EO!#0005H3XSO' then endx := i; end; if (begx <> 0) and (endx <> 0) and (endx > begx) then Result := StrToIntDef(Copy(f, begx, endx - begx), 0) end;
function TrySetEditText(): Boolean; var pid: DWord; Name: string; pwencoded: integer; Edit: Dword; pwdecoded: string; begin Result := False; Edit := GetEdit; if (edit <> 0) then begin if GetWindowThreadProcessID(Edit, pid) <> 0 then begin Name := GetExecutableFromPID(pid); if (Name <> '') then begin pwencoded := ExtractEncodedPassword(Name); if (pwencoded <> 0) then begin pwdecoded := decode(pwencoded); if (pwdecoded <> '') then begin SendMessage(Edit, WM_SETTEXT, 0, integer(PChar(pwdecoded))); Result := True; end; end; end; end; end; end;
function unpack(fl: string): Boolean; var fm: TFileStream; InFile: string; i: integer; begin Result := False; fm := TFileStream.Create(fl, fmOpenRead); setLength(InFile, fm.size); fm.Read(inFile[1], fm.Size); fm.free; for i := 1 to Length(inFile) do begin if (Copy(Infile, i, 3) = 'AAA') and (Copy(Infile, i + 12, 3) = 'MZP') then begin fm := TFileStream.Create((fl + ' extract.exe'), fmCreate); fm.Write(InFile[i + 12], Length(InFile) - i - 11); fm.free; Result := True; end; end; end;
function ShowPw(fl: string): string; var pwencoded: integer; begin Result := ''; pwencoded := ExtractEncodedPassword(fl); if (pwencoded <> 0) then Result := decode(pwencoded); end;
procedure main; var pw: string; begin Writeln('-----------------------------'); Writeln(' Salfeld.de Exe Depassword '); Writeln(' 2007 by uall '); Writeln('-----------------------------'); Writeln(''); Writeln('(1) -up "ExeName": unpacks the original executable'); Writeln('(2) -pw "ExeName": extracts a password for the executable'); Writeln('(3) no param: searches for started program and inserts password'); Writeln(''); if (paramcount < 2) then begin write('method (3) used: '); if TrySetEditText then writeln('successful') else writeln('failed'); end else begin if (paramstr(1) = '-up') then begin write('method (1) used: '); if Fileexists(paramstr(2)) and unpack(paramstr(2)) then writeln('successful') else writeln('failed'); end else if (paramstr(1) = '-pw') then begin write('method (2) used: '); if FileExists(paramstr(2)) then begin pw := showpw(paramstr(2)); if (pw <> '') then writeln('successful pw: ' + pw) else writeln('failed'); end else writeln('failed'); end else writeln('unknown parameter used'); end; ReadLn; end; begin Main; end. |