bool NBFFileOsImageWriter::Close() { if (m_bootloaderBytes!=0x40000) { g_err.Set("erased target file because I could not find a bootloader to add"); // make sure file cannot be used, when no bootloader found ClearFile(); LinearFileImageWriter::Close(); DeleteFile(); return false; } // todo: calculate checksum const char*header= "PW10A1-ENG-3.16-007"; UpdateNBFChecksum(m_checksum, ByteVector(header, header+strlen(header))); string headercheck=stringformat("%s-%04x------------", header, m_checksum&0xffff); if (!LinearFileImageWriter::WriteData(0x7fffffe0, ByteVector(headercheck.begin(), headercheck.begin()+0x20))) { g_err.Set("error writing nbf header"); return false; } if (!LinearFileImageWriter::Close()) return false; return true; }
bool NBFFileOsImageWriter::Open() { NB0ImageReader nb0(g_cfg.BootloaderName); m_checksum=0; if (!nb0.Open()) { g_err.Set(stringformat("error opening source bootloader from %s", g_cfg.BootloaderName.c_str())); return false; } ByteVector bootloader; if (!nb0.ReadData(0x80000000, 0x40000, bootloader)) { g_err.Set("error reading bootloader"); return false; } nb0.Close(); if (!LinearFileImageWriter::Open()) return false; if (!WriteData(0x80000000, bootloader)) return false; return true; }
string Registry::DwordValueToString(const ByteVector& value) { DWORD dw; if (!ValueToDword(value, dw)) return "error"; return stringformat("%08lx", dw); }
bool LinearFileImageWriter::WriteData(DWORD dwOffset, const ByteVector& buffer) { if (INVALID_SET_FILE_POINTER==SetFilePointer(m_h, m_baseoffset+dwOffset-m_filestart, NULL, FILE_BEGIN)) { g_err.Set(stringformat("error seeking to %08lx: %s", m_baseoffset+dwOffset-m_filestart, LastError().c_str())); return false; } DWORD bytes_written; if (!WriteFile(m_h, vectorptr(buffer), (DWORD)buffer.size(), &bytes_written, NULL) || bytes_written!=buffer.size()) { g_err.Set(stringformat("error writing %08lx bytes to %08lx: %s", buffer.size(), dwOffset, LastError().c_str())); return false; } return true; }
string Registry::ValueToString(DWORD dwType, const ByteVector& value) { switch(dwType) { case REG_SZ: return StringValueToString(value); case REG_MULTI_SZ: return StringListValueToString(value); case REG_DWORD: return DwordValueToString(value); default: return stringformat("hex(%d):%s", dwType, hexdump(vectorptr(value), (int)value.size(), 1).c_str()); } }
string Registry::StringListValueToString(const ByteVector& value) { StringList list; if (!ValueToStringList(value, list)) return "error"; string result; result.reserve(list.size()*4+value.size()); for (StringList::iterator i= list.begin() ; i!=list.end(); ++i) { if (result.size()) result += ", "; result += stringformat("'%s'", (*i).c_str()); } return result; }
bool RunApplication(const char *szAppname, const char *szCommandLine) { SHELLEXECUTEINFO exec; memset(&exec, 0, sizeof(SHELLEXECUTEINFO)); exec.cbSize= sizeof(SHELLEXECUTEINFO); exec.lpFile= szAppname; exec.lpParameters= szCommandLine; exec.lpVerb= "open"; exec.lpDirectory= g_cfg.ApplicationRoot.c_str(); exec.nShow= SW_SHOW; exec.fMask= SEE_MASK_FLAG_NO_UI|SEE_MASK_NOCLOSEPROCESS; if (!ShellExecuteEx(&exec)) { g_err.Set(stringformat("error executing %s: %s", szAppname, LastError().c_str())); return false; } return true; }
bool cbInstrLog(int argc, char* argv[]) { if(argc == 1) //just log newline { dputs_untranslated(""); return true; } if(argc == 2) //inline logging: log "format {rax}" { dputs_untranslated(stringformatinline(argv[1]).c_str()); } else //log "format {0} string", arg1, arg2, argN { FormatValueVector formatArgs; for(auto i = 2; i < argc; i++) formatArgs.push_back(argv[i]); dputs_untranslated(stringformat(argv[1], formatArgs).c_str()); } return true; }
bool SdOsImageWriter::CheckSpace() { // ( we don't know yet how large the target is, assume it is ok. if (m_sd->GetTotalBlocks()==0) return true; /* // otherwise, it must be able to hold an os image if (m_sd->GetTotalBlocks() < 2+(0x81f00000-0x80040000)/m_sd->GetBlockSize()) { g_err.Set("target device is too small to hold os image"); return false; } */ // and not be larger than 2G if (m_sd->GetTotalBlocks() > 0x7fffffff/m_sd->GetBlockSize()) { return IDYES==MessageBox(0, stringformat("Are you sure you want to write to this device:\n%s", m_sd->GetFriendlyName().c_str()).c_str(), "WARNING", MB_YESNO); } return true; }