int main(int argc, char *argv[]) { FILE *fin, *fout; if (argc < 4) ShowUsage(argv[0]); fin = fopen(argv[argc - 2], "rb"); fout = fopen(argv[argc - 1], "wb"); if (fin == NULL || fout == NULL) { fprintf(stderr, "File open failed\n"); return 1; } StdioSeqStream isss, osss; isss.f = fin; isss.is.Read = stdio_read; osss.f = fout; osss.os.Write = stdio_write; ICompressProgress prog; prog.Progress = show_progress; if (argv[1][0] == 'c') { CSCProps p; uint32_t dict_size = 64000000; uint64_t filesize = GetFileSize(fin); int level = 2; for(int i = 2; i < argc - 2; i++) { if (ParseBasicOpt(argv[i], &dict_size, &level) < 0) ShowUsage(argv[0]); } if (filesize < dict_size) dict_size = filesize; // init the default settings CSCEncProps_Init(&p, dict_size, level); // Then make extra settings for(int i = 2; i < argc - 2; i++) { if (ParseOpt(&p, argv[i]) < 0) ShowUsage(argv[0]); } printf("Estimated memory usage: %llu MB\n", CSCEnc_EstMemUsage(&p) / 1048576ull); unsigned char buf[CSC_PROP_SIZE]; CSCEnc_WriteProperties(&p, buf, 0); (void)(fwrite(buf, 1, CSC_PROP_SIZE, fout) + 1); CSCEncHandle h = CSCEnc_Create(&p, (ISeqOutStream*)&osss); CSCEnc_Encode(h, (ISeqInStream*)&isss, &prog); CSCEnc_Encode_Flush(h); CSCEnc_Destroy(h); } else { CSCProps p; unsigned char buf[CSC_PROP_SIZE]; (void)(fread(buf, 1, CSC_PROP_SIZE, fin) + 1); CSCDec_ReadProperties(&p, buf); CSCDecHandle h = CSCDec_Create(&p, (ISeqInStream*)&isss); CSCDec_Decode(h, (ISeqOutStream*)&osss, &prog); CSCDec_Destroy(h); } fclose(fin); fclose(fout); printf("\n"); return 0; }
EFI_STATUS EFIAPI ShellAppMain ( IN UINTN Argc, IN CHAR16 **Argv ) { EFI_STATUS Status; UINT16 *BootVariable; UINTN BootVariableSize; UINT16 LDAttr; CHAR16 *Name; UINTN NewNameSize; UINTN NameSize; UINTN i; UINT32 Attr; EFI_GUID VarGuid; ParseOpt(Argc, Argv); //------------Usage----------------------- if (opts.usage){ Usage(); return EFI_SUCCESS; } //----------Set BootOrder----------------- if (opts.set_bootorder){ BootVariable = mGetVariable(L"BootOrder", &gEfiGlobalVariableGuid, &BootVariableSize, &Attr); BootVariable[0]=opts.bootnum; Status = gRT->SetVariable(L"BootOrder", &gEfiGlobalVariableGuid, Attr, BootVariableSize, BootVariable); if (!EFI_ERROR(Status)) Print(L"Set first boot to Boot%04x\n", opts.bootnum); return Status; } //----------Show Boot UEFI variables-------- //get BootCurrent BootVariable = mGetVariable(L"BootCurrent", &gEfiGlobalVariableGuid, &BootVariableSize, NULL); if (BootVariable != NULL) Print(L"BootCurrent: %04x\n", *BootVariable); //get BootOrder BootVariable = mGetVariable(L"BootOrder", &gEfiGlobalVariableGuid, &BootVariableSize, &Attr); if (BootVariable != NULL){ Print(L"BootOrder: "); for(i=0; i<(BootVariableSize/2); i++){ Print(L" %04x ",BootVariable[i]); } Print(L"\n"); } //Print all BOOT#### Load Options NameSize = sizeof(CHAR16); Name = AllocateZeroPool(NameSize); for (i=0; ;i++ ){ NewNameSize = NameSize; //search all EFI variables Status = gRT->GetNextVariableName (&NewNameSize, Name, &VarGuid); if (Status == EFI_BUFFER_TOO_SMALL) { Name = ReallocatePool (NameSize, NewNameSize, Name); Status = gRT->GetNextVariableName (&NewNameSize, Name, &VarGuid); NameSize = NewNameSize; } // if (Status == EFI_NOT_FOUND) { break; } //skip if not Global variable if (!CompareGuid(&VarGuid, &gEfiGlobalVariableGuid)) continue; //check BOOT#### variable if(!StrnCmp(Name, L"Boot", 4) && IsCharDigit(Name[4]) && IsCharDigit(Name[5]) && IsCharDigit(Name[6]) && IsCharDigit(Name[7])) { Print(L"%s:", Name); //get BOOT#### BootVariable = mGetVariable(Name, &gEfiGlobalVariableGuid, &BootVariableSize, NULL); //print attribute LDAttr = BootVariable[0]; if (opts.show_verbose){ i = 6; //for adjust display if (LDAttr == 0) Print(L"CB*", i--); //category boot if (LDAttr & 1) Print(L"A* ", i--); //active if (LDAttr & 2) Print(L"FR*", i--); //force reconnect if (LDAttr & 8) Print(L"H* ", i--); //hidden if (LDAttr & 0x100) Print(L"CA*", i--); //category app //Print(L"\n"); while (i--){ Print(L" "); } } //print EFI_LOAD_OPTION description Print(L" %s",(CHAR16 *)(BootVariable+3)); Print(L"\n"); } } return Status; }