-
Notifications
You must be signed in to change notification settings - Fork 0
/
caseGenerator_trace_facebook_account.pas
217 lines (189 loc) · 7 KB
/
caseGenerator_trace_facebook_account.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
unit caseGenerator_trace_facebook_account;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.DateTimeCtrls, FMX.Calendar, FMX.Edit, FMX.StdCtrls, FMX.Layouts,
FMX.ListBox, FMX.Controls.Presentation, caseGenerator_util;
type
TformTraceFacebookAccount = class(TForm)
Label1: TLabel;
lbFacebookAccount: TListBox;
btnClose: TButton;
btnAddPhoneAccount: TButton;
btnDeletePhoneAccount: TButton;
btnCancel: TButton;
btnModifyTrace: TButton;
Label2: TLabel;
edIssuer: TEdit;
Label3: TLabel;
edID: TEdit;
Label4: TLabel;
Label5: TLabel;
edDisplayName: TEdit;
procedure btnAddPhoneAccountClick(Sender: TObject);
procedure btnDeletePhoneAccountClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnModifyTraceClick(Sender: TObject);
procedure lbFacebookAccountChange(Sender: TObject);
private
FuuidCase: string;
FpathCase: String;
procedure SetuuidCase(const Value: string);
procedure SetpathCase(const Value: String);
property uuidCase: string read FuuidCase write SetuuidCase;
property pathCase: String read FpathCase write SetpathCase;
function prepareTrace(operation: String): String;
{ Private declarations }
public
procedure ShowWithParamater(pathCase: String; uuidCase: String);
{ Public declarations }
end;
var
formTraceFacebookAccount: TformTraceFacebookAccount;
implementation
{$R *.fmx}
uses StrUtils;
{ TForm1 }
procedure TformTraceFacebookAccount.btnDeletePhoneAccountClick(Sender: TObject);
begin
lbFacebookAccount.Items.Delete(lbFacebookAccount.ItemIndex);
end;
procedure TformTraceFacebookAccount.btnModifyTraceClick(Sender: TObject);
begin
if lbFacebookAccount.ItemIndex > - 1 then
lbFacebookAccount.Items[lbFacebookAccount.ItemIndex] := prepareTrace('modify');
end;
procedure TformTraceFacebookAccount.lbFacebookAccountChange(Sender: TObject);
var
line: String;
begin
if lbFacebookAccount.ItemIndex > - 1 then
begin
line := lbFacebookAccount.Items[lbFacebookAccount.ItemIndex];
edID.Text := ExtractField(line, '"uco-observable:accountID":"');
edIssuer.Text := ExtractField(line, '"uco-observable:accountIssuer":"');
edDisplayName.Text:= ExtractField(line, '"uco-observable:displayName":"');
end;
end;
function TformTraceFacebookAccount.prepareTrace(operation: String): String;
var
line, recSep, indent, guidNoBraces: string;
Uid: TGUID;
idx: Integer;
begin
recSep := #30 + #30; // record separator, not printable
indent := ' ';
if (Trim(edID.Text) = '') then
ShowMessage('Account ID is missing!')
else
begin
line := '{' + recSep;
if operation = 'add' then
begin
CreateGUID(Uid);
guidNoBraces := ':' + Copy(GuidToString(Uid), 2, Length(GuidToString(Uid)) - 2);
end
else
guidNoBraces := ExtractField(lbFacebookAccount.Items[lbFacebookAccount.ItemIndex], '"@id":"');
line := line + indent + '"@id":"' + guidNoBraces + '", ' + recSep;
line := line + indent + '"@type":"uco-observable:CyberItem", ' + recSep;
line := line + indent + '"uco-core:name":"Facebook",' + recSep;
line := line + indent + '"uco-core:facets":[' + recSep;
line := line + indent + '{' + recSep;
line := line + RepeatString(indent, 2) + '"@type":""uco-observable:Account", ' + recSep;
line := line + RepeatString(indent, 2) + '""uco-observable:accountIssuer":"' + edIssuer.Text + '", ' + recSep;
line := line + RepeatString(indent, 2) + '""uco-observable:isActive":"true"' + recSep ;
line := line + indent + '},' + recSep;
line := line + indent + '{' + recSep;
line := line + RepeatString(indent, 2) + '"@type":"uco-observable:ApplicationAccount", ' + recSep;
line := line + RepeatString(indent, 2) + '"uco-observable:application":"NOT_SET"' + recSep;
line := line + indent + '},' + recSep;
line := line + indent + '{' + recSep;
line := line + RepeatString(indent, 2) + '"@type":"uco-observable:DigitalAccount", ' + recSep;
line := line + RepeatString(indent, 2) + '"uco-observable:displayName":"' + edDisplayName.Text + '"' + recSep;
line := line + indent + '}' + recSep;
line := line + indent + ']' + recSep + '}';
end;
Result := line;
end;
procedure TformTraceFacebookAccount.btnCancelClick(Sender: TObject);
begin
formTraceFacebookAccount.Close;
end;
procedure TformTraceFacebookAccount.btnCloseClick(Sender: TObject);
var
fileJSON: TextFile;
line:string;
idx: integer;
begin
//dir := GetCurrentDir;
// create file JSON uuidCase-phone_account.json
AssignFile(fileJSON, FpathCase + FuuidCase + '-traceFACEBOOK_ACCOUNT.json');
if lbFacebookAccount.Items.Count > 0 then
begin
idx := 0;
Rewrite(fileJSON); // create new file
WriteLn(fileJSON, '{');
line := #9 + '"OBJECTS_FACEBOOK_ACCOUNT":[';
WriteLn(fileJSON, line);
for idx:= 0 to lbFacebookAccount.Items.Count - 2 do
WriteLn(fileJSON, #9#9 + lbFacebookAccount.Items[idx] + ',');
WriteLn(fileJSON, #9#9 + lbFacebookAccount.Items[idx]);
WriteLn(fileJSON, #9#9 + ']');
Write(fileJSON,'}');
CloseFile(fileJSON);
end
else
deleteFile(FpathCase + FuuidCase + '-tracePHONE_ACCOUNT.json');
formTraceFacebookAccount.Close;
end;
procedure TformTraceFacebookAccount.btnAddPhoneAccountClick(Sender: TObject);
begin
lbFacebookAccount.Items.Add(prepareTrace('add'));
edID.Text := '';
edIssuer.Text := '';
end;
procedure TformTraceFacebookAccount.SetpathCase(const Value: String);
begin
FpathCase := Value;
end;
procedure TformTraceFacebookAccount.SetuuidCase(const Value: string);
begin
FuuidCase := Value;
end;
procedure TformTraceFacebookAccount.ShowWithParamater(pathCase: String; uuidCase: String);
var
fileJSON: TextFile;
line, subLine:string;
begin
SetUuidCase(uuidCase);
SetPathCase(pathCase);
//dir := GetCurrentDir;
// read file JSON uuidCase-tracePHONE_ACCOUNT.json
if FileExists(FpathCase + FuuidCase + '-traceFACEBOOK_ACCOUNT.json') then
begin
AssignFile(fileJSON, FpathCase + FuuidCase + '-traceFACEBOOK_ACCOUNT.json');
Reset(fileJSON);
lbFacebookAccount.Items.Clear;
while not Eof(fileJSON) do
begin
ReadLn(fileJSON, line);
line := Trim(line);
if (line = '{') or (line = '}') or (line = ']') or (AnsiContainsStr(line, 'OBJECTS_')) then // first or last line or root element
else
begin
subLine := Copy(line, Length(line), 1); // rule out of comma
if subLine = ',' then
line := Copy(line, 1, Length(line) - 1);
lbFacebookAccount.Items.Add(line);
end;
end;
CloseFile(fileJSON);
end;
// else
// ShowMessage(dir + uuidCase + '-identity.json' + ' doesn''t exist');
formTraceFacebookAccount.ShowModal;
end;
end.