| 319 | |
| 320 | |
| 321 | int main(int argc, const char* argv[]) |
| 322 | { |
| 323 | Log::SetupAnsi(); |
| 324 | LogToStdout(WarningLog); |
| 325 | |
| 326 | if (argc != 2 && argc != 4) |
| 327 | { |
| 328 | Log::print<Log::Error>("usage: {} <debuggee_path>\n", argv[0]); |
| 329 | Log::print<Log::Error>("usage: {} <debuggee_path> --attach <debuggee_pid>\n", argv[0]); |
| 330 | Log::print<Log::Error>("usage: {} <debuggee_path> --connect <host:port>\n", argv[0]); |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | Log::SetupAnsi(); |
| 335 | |
| 336 | SetBundledPluginDirectory(GetBundledPluginDirectory()); |
| 337 | InitPlugins(); |
| 338 | |
| 339 | const char* fname = argv[1]; |
| 340 | if (!is_file(fname)) |
| 341 | { |
| 342 | cerr << "Error: " << fname << " is not a regular file" << endl; |
| 343 | exit(-1); |
| 344 | } |
| 345 | |
| 346 | SetBundledPluginDirectory(GetBundledPluginDirectory()); |
| 347 | InitPlugins(); |
| 348 | |
| 349 | Ref<BinaryData> bd = BinaryData::CreateFromFilename(new FileMetadata(argv[1]), argv[1]); |
| 350 | if (!bd) |
| 351 | { |
| 352 | fprintf(stderr, "Could not open input file.\n"); |
| 353 | return -1; |
| 354 | } |
| 355 | Ref<BinaryView> bv; |
| 356 | for (auto type : BinaryViewType::GetViewTypes()) |
| 357 | { |
| 358 | if (type->IsTypeValidForData(bd) && type->GetName() != "Raw") |
| 359 | { |
| 360 | bv = type->Create(bd); |
| 361 | break; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | if (!bv || bv->GetTypeName() == "Raw") |
| 366 | { |
| 367 | fprintf(stderr, "Input file does not appear to be an executable\n"); |
| 368 | return -1; |
| 369 | } |
| 370 | |
| 371 | bv->UpdateAnalysisAndWait(); |
| 372 | |
| 373 | DbgRef<DebuggerController> debugger = DebuggerController::GetController(bv); |
| 374 | if (!debugger) |
| 375 | LogError("Failed to create a debugger for the BinaryView\n"); |
| 376 | |
| 377 | if (argc == 2) |
| 378 | { |
nothing calls this directly
no test coverage detected